在Mac中创建软件修补程序 [英] Creating a software patcher in mac

查看:75
本文介绍了在Mac中创建软件修补程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IOS开发人员,我了解目标C.我想创建一个独立的Mac应用程序,其唯一功能是修补同一Mac中可用的另一个应用程序.

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.

让我们说我的应用程序文件夹中有一个名为X的应用程序.该应用程序X具有某些不良行为.因此,我尝试修改此行为.我在Hopper反汇编程序的帮助下分析了该应用程序的可执行文件,我知道我必须更改从00000001003e3790开始的汇编指令.我更改了这些汇编指令并生成了新的可执行文件.然后,我用新的可执行文件替换了旧文件,然后这种不希望有的行为现在似乎消失了.

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.

那么我该如何修改修补程序应用X的可执行文件中可用的汇编指令,然后用修改后的版本替换原始指令?

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. 通常,您应该向用户询问应用程序包的位置,以防在/Applications/中找不到该应用程序包.
  2. 您需要检查该捆绑包中的目标可执行文件是否具有与修补程序之前的可执行文件相同的哈希值(可能是CRC,MD5,SHA-您将其命名).
  3. 如果哈希匹配,那么您将打开文件进行写入,并寻找预先存储了错误指令的硬编码位置;您可以通过在十六进制编辑器中搜索修补文件中从修补字节开始的足够长的字节字符串来确定该位置.
  4. 最后,您将用自己的目标字节重写(也称为补丁)并关闭文件.
  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.] [3]的示例代码.

[UPD.] Example code for [3].

这不需要任何与ObjC相关的机制,并且只能使用普通的libc构建和运行:

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;
}

其中:

  • name是要修补的文件的名称
  • data是要写入的数据
  • offs是应放置数据的文件偏移量
  • size是数据大小;文件中的旧字节中的size完全会被重写
  • 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

这篇关于在Mac中创建软件修补程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆