9

I'm looking for a Windows equivalent of the GNU tool objcopy. I'm looking to implement the suggestion posted here to my problem, however I need to do it cross-platform (Windows, Linux and Mac). I couldn't find the answer on my google friend, so perhaps the solution needs to be implemented differently. Thank you!

Community
  • 1
  • 1
Deathicon
  • 1,259
  • 1
  • 16
  • 31
  • For use on Visual C++ built files, or on e.g. MinGW/Cygwin built files? In the latte case there should be an `objcopy` that you can use straight off. – Some programmer dude Nov 18 '13 at 16:06
  • Its Visual C++ built files. – Deathicon Nov 18 '13 at 16:22
  • I don't know if this is an option for you, but you could just start from ELF linux version, use objcopy and then try the conversion to COFF/PE with the tool released here: agner.org/optimize. – Jekyll Nov 18 '13 at 17:39

2 Answers2

5

Part of the default MSVC tooling: LIB /EXTRACT extracts a copy of an object; LIB /REMOVE then removes it from the library.

I think LIB /DEF /EXPORT:externalName=internalName also would be beneficial to you, when you put the object file back in.

MSalters
  • 159,923
  • 8
  • 140
  • 320
0

If you don't mind a hack, replacing all the instances of the conflicting name by a different name of the same length in one of the library bin file can work. Do this at your own risks.

Example

// a.h
void doSomething();

// b.h
void doSomething();

We can replace doSomething by doSomethink

In python it would be something like:

f = open('b.lib',"rb")
s = f.read()
f.close()
s = s.replace(b'doSomething',b'doSomethink')
f = open('b.lib',"wb")
f.write(s)
f.close()

And modify b header accordingly

// b.h
void doSomethink();

Note that here I used the plain function name as defined in the header to match the symbol in the binary but you might want to use the full mangled name instead to prevent unwanted replacements.

Guillaume Gris
  • 1,720
  • 14
  • 28