Creating a software patcher in mac

北城以北 提交于 2019-12-11 07:37:37

问题


I'm an IOS developer and I know objective C. I wanna to create a stand alone mac app whose sole functionality is to patch another app available in same mac.

Lets say I have an app called X in my applications folder. This app X has some undesired behaviour. So I tried to modify this behaviour. I analysed the app's executable with the help of Hopper disassembler, I came to know that I have to change assembly instructions starting at 00000001003e3790. I changed those assembly instructions and produced the new executable. Then I replaced the old one with new executable and then that undesired behaviour now seems to be gone.

As most people would love to remove this undesired behaviour, I decided to write a patcher and distribute that patcher to them.

So how can I modify assembly instructions available inside the executable of app X in my patcher app then replace the original one with my modified version ?

It would be great if someone help me in right direction.


回答1:


  1. In general, you should ask the user for the location of the app bundle, in case it can`t be found in /Applications/.
  2. You need to check whether the target executable inside that bundle has the same hash (it may be CRC, MD5, SHA — you name it) as the executable you had before patching it.
  3. If the hashes match, then you are to open the file for writing and seek for the pre-hardcoded place where the wrong instructions are stored; you can determine that place by searching the patched file in a hex-editor for a long enough byte string beginning with your patched bytes.
  4. And finally, you are to rewrite (a.k.a. patch) the target bytes with yours and close the file.

[UPD.] Example code for [3].

This does not require any ObjC-related mechanisms, and can be built and run using only the plain libc:

long PatchSomething(char *name, char *data, size_t offs, size_t size) {
    long file = open(name, O_WRONLY);
    if (file != -1) {
        lseek(file, offs, SEEK_SET);
        write(file, data, size);
        close(file);
    }
    return file != -1;
}

where:

  • name is the name of the file to patch
  • data is the data to be written
  • offs is the file offset where the data shall be put
  • size is the data size; exactly size of the old bytes in the file would get rewritten


来源:https://stackoverflow.com/questions/44858288/creating-a-software-patcher-in-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!