问题
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:
- In general, you should ask the user for the location of the app bundle, in case it can`t be found in
/Applications/
. - 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.
- 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.
- 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 patchdata
is the data to be writtenoffs
is the file offset where the data shall be putsize
is the data size; exactlysize
of the old bytes in the file would get rewritten
来源:https://stackoverflow.com/questions/44858288/creating-a-software-patcher-in-mac