2

I have an existing executable for which a small amount of source code has been lost. In particular, the executable uses a few functions from a static library, and the source code for that library is missing. I do have an older version of that library's code, but the executable uses three or four methods that aren't in the old version. I have a header file for the new version of the code, which includes prototypes of the missing functions, but the .c file containing the actual function definitions is missing.

Since the executable is statically linked, I wonder if there is a way to rebuild the static library by extracting the object code from it. I can find the symbols I need using nm and objdump, but I don't know if there's a way to extract those functions and re-package them into object files or a static library.

As an example, it looks something like this:

$ nm ./theApplication
<a bunch of stuff>
001721dc T _missingFunction1
<more stuff>
00171ed8 T _missingFunction2
<more stuff>

$ objdump --disassemble-all ./theApplication
<a bunch of stuff>
00171ed8 <_missingFunction2>:
  171ed8:       1a e5 f8 14     P2 = [P3 + 0x53e0];
<more stuff>
001721dc <_missingFunction1>:
  1721dc:       c5 04           [--SP] = (P5:5);
<more stuff>

I'd like to pull missingFunction1() and missingFunction2() out into a static library or object files so I can link against them in other executables. Is that possible, and if so, how can it be done?

maldata
  • 145
  • 5
  • I just found [this post](https://stackoverflow.com/q/32372992/3684433), which is kind of similar and seems to imply that it's not possible. I don't think I understand the linking process well enough though. Why wouldn't the relocation process be reversible? Wouldn't you basically just clear the address and put in an arbitrary placeholder? – maldata Nov 29 '19 at 15:58
  • "for which a small amount of source code has been lost"?the simplest way is to ask the author to replace the missing source. if you cant ask them, you are stealing it. – robert Feb 06 '20 at 01:47
  • @robert I agree that that's the simplest solution. But if the author is dead, I still need to figure this out. Some clients don't take great care of their IP. I'm just trying to help here. – maldata Feb 06 '20 at 19:15

0 Answers0