Last active
December 3, 2015 23:09
-
-
Save ruslo/04d8993800ee78513d1c to your computer and use it in GitHub Desktop.
Example of impossibility of patching C++ string literal after compiler do his job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> cat boo.cpp | |
// function will return some enum with information about resources | |
int have_resources_in_install() { | |
// want to patch this string AFTER compile stage done | |
const char* path = "non empty string"; | |
if (path[0] != '\0') { | |
return 0x123; | |
} | |
else { | |
// expecting move to this branch after patching | |
return 0xabc; | |
} | |
} | |
> g++ -O3 ./boo.cpp -c -o boo | |
> objdump -d ./boo | |
0000000000000000 <_Z25have_resources_in_installv>: | |
0: b8 23 01 00 00 mov $0x123,%eax // as you can see branch with '0xabc' optimized away and will | |
// never be executed even if you patch literal | |
5: c3 retq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment