Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify a PE import table so that instead of linking to foo.dll it links to bar.dll?

I have a file plugin.dll whose import table links to several symbols in foo.dll. I want to make a new file plugin-modified.dll, such that plugin-modified.dll is identical to plugin.dll, except that instead of linking to these symbols in foo.dll, its import table imports those same symbols from bar.dll. Can anyone suggest a tool that will rewrite PE files in this way? Ideally command-line/scriptable and open-source, but I'm willing to consider alternatives...

(The real use case is that I want to replace the reference to foo.dll with foo-unique-id-934019384.dll, so as to be able to ship plugin.dll and foo.dll together while avoiding name collisions, just in case someone else also distributes some other plugin that links to its own, different version of foo.dll.

On Linux this can be done with the patchelf tool, and on OS X it can be done with install_name_tool; I'm looking for a Windows equivalent.

I'm aware that SxS assemblies may be able to solve this problem in a different way, but they have their own limitations so I want to explore both approaches before deciding.)

like image 760
Nathaniel J. Smith Avatar asked Oct 29 '25 08:10

Nathaniel J. Smith


1 Answers

Well, I got so annoyed at missing this tool that I wrote it :-)

https://github.com/njsmith/machomachomangler

like image 132
Nathaniel J. Smith Avatar answered Oct 31 '25 04:10

Nathaniel J. Smith