Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::out_of_range is thrown when loading specific 64-bit executables #37

Open
1ecram opened this issue Jun 28, 2022 · 0 comments
Open

Comments

@1ecram
Copy link

1ecram commented Jun 28, 2022

Hello,

Loading an x64 executable with a base address that doesn't fit in 32 bits will make the code throw an std::out_of_range exception during the call to std::stoi in raw_gadgets_from_file, particularly in the following line:

raw.addr = std::stoi(addr_str, 0, 16);

This happens because std::stoi does not support converting integers that are larger than 32 bits. When parsing executables mentioned above, the gadget addresses won't fit into 32 bits and will cause the exception to be thrown.

I have fixed the issue locally by replacing the std::stoi call with std::stoll or std::stoull. Given that the destination operand is a uint64_t type, I believe using std::stoull would be more correct.

-                    raw.addr = std::stoi(addr_str, 0, 16);
+                    raw.addr = std::stoull(addr_str, 0, 16);

Attached is an excerpt from the .ropium_raw_gadgets.0 temporary file that's generated by ropium during gadget processing. To reproduce the issue, one can make a test with the following line:

raw_gadgets_from_file("ropium_raw_gadgets.txt");

ropium_raw_gadgets.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant