Run Mach-O executable with static lib?

Suppose you have

  • pre-installed executable iOS application (for simulator or device).
  • A built-in static library of a static archive library, which, among other things, contains C ++ static initializers.

Now it should be possible to combine the two built-in products to create a new iOS executable that looks like the old one, except that it is now also linked to an additional static library, and when executed, the static library static initializers will be launched.

What tool (if any) can help solve this merge problem?

Edit: An acceptable solution is also to dynamically load the library using dlopen. The whole purpose of this is to test applications, so a re-connected application will never see the application store.

+7
source share
1 answer

How the compiler works (in a simple explanation)

The most popular C ++ compilers (e.g. GCC) work by translating all C ++ codes (and Obj-C, C, etc.) into ASM.

Then it calls the appropriate assembler for the target processor and creates the binary files of the objects.

He then calls the linker, which looks in these binaries for symbols that explain what links are with what. The general optimization that linkers can perform is also a strip of final binary code from statically linked libraries that were not used, another general optimization does not try to link libraries that are not used at all.

Finally, the linker removes everything you need.

What does this mean in your case

You have a library, the library has anchor characters. You also have an executable file that has its associated characters removed, in fact, depending on how it was optimized, internal transitions can be just a couple of jmp commands for arbitrary addresses in the code. There is no machine, you can do what you want automatically, because you do not have the necessary information about the executable file.

How to do it anyway

You need to parse the executable file, independently indicate where the function calls are located, and then manually assemble it with your library, instead these functions will cause a transition to the addresses in your library.

This process is sometimes used by game mods to change the video drivers of old games (for example, to update the OpenGL version or to force the use of Glide games to use some newer drivers, etc.).

So, if you still want to do this (I warn you: this is absurd madness, though ...) ask these guys :) I don’t remember anyone pointing to you now, but they exist.

Analogy

When you are in the normal linking phase, the compiled object files are similar to the source code, which the machine understands, and makes function calls if necessary.

After compilation, all function calls became goto.

So, if you are a linker who is tasked with doing what you want to do, imagine that you will read the source code filled with goto in random places in the code (sometimes even inside loops) and somehow you need to draw some of you want to change them to go to the new part that you are trying to insert there.

+1
source

All Articles