TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Adding code to an existing ELF file

103 pointsby dropbear3about 3 years ago

7 comments

nneonneoabout 3 years ago
I&#x27;ve had great success using Frida (<a href="https:&#x2F;&#x2F;frida.re&#x2F;" rel="nofollow">https:&#x2F;&#x2F;frida.re&#x2F;</a>) to do stuff like this recently. Frida injects a V8 runtime into the target process, enabling you to use JavaScript to dynamically patch&#x2F;inspect&#x2F;modify code and data, with all of the JavaScript running inside the target process so there&#x27;s minimal impact on performance. They provide a nice Python API for remotely controlling the process.<p>It works on rooted devices, debuggable apps, and can also be added to an existing APK with minimal effort (just patch a single Java class and add a native library - there are scripts to do it for you).
评论 #31319755 未加载
garaetjjteabout 3 years ago
When I needed to &quot;destatify&quot; executable, to patch statically compiled library functions to shared imports I used LIEF library: <a href="https:&#x2F;&#x2F;milek7.pl&#x2F;.stuff&#x2F;galdocs&#x2F;destaticizer.py" rel="nofollow">https:&#x2F;&#x2F;milek7.pl&#x2F;.stuff&#x2F;galdocs&#x2F;destaticizer.py</a>
eatonphilabout 3 years ago
Very neat! Less hacky than I expected. It looks like it all just reads in the ELF file, makes the change to the ELF data structures in memory and then writes back out a new ELF file?
OnlyMortalabout 3 years ago
Code can also be added to mach-o binaries. An old OSX copy protection system did this.
Diggseyabout 3 years ago
That&#x27;s cool :) I think it would be a lot easier to inject the payload at runtime though - the only problem I had when doing this was I got the wrong instruction set initially (thumb vs non-thumb).
评论 #31361651 未加载
randomhodler84about 3 years ago
This is a great write up dropbear, I learned a few things! Please keep blogging, this is some quality content!
sim7c00about 3 years ago
looks like a neat way around the hell of patching relocations. though, if you&#x27;d want to modify the binary arbitrarily and not hijack sections or such things, it might be nice to look into that.