Fix incorrect SFLIB include path for Windows x86-32 in rz-gg
Your checklist for this pull request
- [ ] I've read the guidelines for contributing to this repository.
- [ ] I made sure to follow the project's coding style.
- [ ] I've documented every
RZ_APIfunction and struct this PR changes. - [ ] I've added tests that prove my changes are effective (required for changes to
RZ_API). - [ ] I've updated the Rizin book with the relevant information (if needed).
- [ ] I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.
Summary
rz-gg attempts to include a non-existent SFLIB directory when targeting
Windows x86-32:
include/librz/sflib/windows-x86-32/sflib.h
This directory does not exist in the Rizin include tree, causing rz-gg to fail with a missing-header error when building 32-bit Windows payloads.
Fix
A small fallback is added in egg_Cfile.c so that the nonexistent
windows-x86-32 directory is mapped to the existing windows-x86 directory:
if (!strcmp(cEnv->TRIPLET, "windows-x86-32")) {
free(cEnv->TRIPLET);
cEnv->TRIPLET = rz_str_dup("windows-x86");
}
This ensures that rz-gg includes the correct file:
include/librz/sflib/windows-x86/sflib.h
and avoids failing due to the missing windows-x86-32 directory.
Test Plan
Tested by running the following command:
./build/binrz/rz-gg/rz-gg -a x86 -b32 -k windows test.c
The generated compiler command now includes:
.../sflib/windows-x86/sflib.h
instead of the incorrect:
.../sflib/windows-x86-32/sflib.h
Warnings from clang on macOS are expected because Windows 32-bit binaries cannot be compiled without MinGW. These warnings are unrelated to the fix. The key part—the SFLIB include path—is now correct.
Closing issues
closes #5519
Codecov Report
:x: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 46.56%. Comparing base (1e1d096) to head (0f17041).
:warning: Report is 87 commits behind head on dev.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| librz/egg/egg_Cfile.c | 40.00% | 2 Missing and 1 partial :warning: |
Additional details and impacted files
| Files with missing lines | Coverage Δ | |
|---|---|---|
| librz/egg/egg_Cfile.c | 55.45% <40.00%> (-0.80%) |
:arrow_down: |
... and 6 files with indirect coverage changes
Continue to review full report in Codecov by Sentry.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 1e1d096...0f17041. Read the comment docs.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
I can't find include/librz/sflib/windows-x86/sflib.h either
@dotslashinit-sh
I can't find
include/librz/sflib/windows-x86/sflib.heither
windows-x86 and windows-x86-32 SFLIB directories don’t exist on non-Windows builds only inside the Windows SDK. The PR only fixes the incorrect TRIPLET mapping so that rz-gg stops referencing the nonexistent windows-x86-32 directory. The missing files on macOS/Linux are expected.
@Rohankaf
windows-x86 and windows-x86-32 SFLIB directories don’t exist on non-Windows builds only inside the Windows SDK.
sflib directories don't exist in the windows sdk, or maybe I can't find them. They don't seem to exist anywhere in the source either.
@dotslashinit-sh
sflib directories don't exist in the windows sdk, or maybe I can't find them. They don't seem to exist anywhere in the source either.
You're right SFLIB doesn’t exist for Windows at all, not in the SDK and not in the source.
Thanks for pointing that out.
The purpose of this PR is only to fix the wrong windows-x86-32 triplet that caused rz-gg to generate an invalid include path.
It doesn't attempt to add missing Windows SFLIB support that's a separate issue.
So the fix here is just to prevent rz-gg from building a path to a directory that never existed in the first place. 😃
i don't think we ever supported sflib for windows stuff.. check librz/include/sflib
Seems like radare2 does not support windows either. Wouldn't it be better to not include rz-gg with the releases for windows until we get proper support?
It's not a problem of radare2 nor rizin. it's shellforge that never supported it. i would still build rz-gg for windows.
@notxvilka & @Rot127 what do you think?
sflib.h is needed to allow for syscalls in shell code?
Then we need new sflib.h for Windows, right? I don't think this is done quickly.
So simply removing sflib.h when rz-gg is build on Windows seems the simplest way.
sflib.his needed to allow for syscalls in shell code? Then we need newsflib.hfor Windows, right? I don't think this is done quickly. So simply removingsflib.hwhen rz-gg is build on Windows seems the simplest way.
There is an issue to track better option than sflib but it's way harder: https://github.com/rizinorg/rizin/issues/4939 For now just making sure that it works for Linux binaries when on Windows platform is good enough.
@wargio Thanks for the feedback!
Just to confirm what I should implement in this PR:
– Remove the sflib.h include when rz-gg is built on Windows
– Keep the Linux behavior unchanged
– Apply the suggested path join fix from @wargio
Please let me know if this is correct, and I will push the update.
I think the best is not to remove windows sflib but instead fail if the file does not exists. @Rot127 @notxvilka
Maybe an error like sflib.h is not available for 'windows-x86-32' so this behavior also applies to all the archs & os that also do not support it.
@Rohankaf please check the checklist in the first post (i have edited it since you removed it) and tick everything that you did till now.
but instead fail if the file does not exists.
I would not fail but just print a warning. Otherwise it won't be able to work on Windows by default, even if the shell code doesn't use any syscalls. Right?
but then, does rz-gg work on an unsupported os?
I never used rz-gg so far. But according to the docs it is meant to compile code for injection later.
So it should also compile code which uses non of the OS API. E.g. if you need to exploit just a certain vulnerability in a user land process. So I think making rz-gg fully Windows compatible is more of a separated issue.
yes indeed. so i would add a check if the file exists, if not, then throw a warning and do not include it
@Rohankaf ping