简体   繁体   English

开始逆向工程OS X?

[英]Getting started reverse-engineering OS X?

What is a good place to learn reverse engineering, specifically as it applies to Mac OS X? 什么是学习逆向工程的好地方,特别是它适用于Mac OS X? Two apps that I admire in terms of this subject: 关于这个主题我钦佩的两个应用程序:

Hyperspaces – http://thecocoabots.com/hyperspaces/ 超空间 - http://thecocoabots.com/hyperspaces/

and

Orbit – http://www.steventroughtonsmith.com/orbit/ 轨道 - http://www.steventroughtonsmith.com/orbit/

Thanks guys. 多谢你们。

You should grab a copy of Mac OS X Internals which is an awesome book about everything that Apple does not tell you. 您应该获取一份Mac OS X Internals的副本,这是一本关于Apple没有告诉您的所有内容的精彩书籍。 Not only is this great if you are interested in reverse engineering, it will also make you a better OS X programmer in general. 如果您对逆向工程感兴趣,它不仅非常棒,它还可以使您成为更好的OS X程序员。

Apple releases a ton of the foundation of OS X as open source. Apple发布了大量OS X作为开源的基础。 See here . 看到这里

In addition, F-Script Anywhere will help a ton with dissecting the Finder and/or any other closed source application. 此外, F-Script Anywhere将帮助解析Finder和/或任何其他封闭源应用程序。

Use class-dump-x / -z to get the private Objective-C headers for OS X/iPhone OS system frameworks. 使用class-dump-x / -z获取OS X / iPhone OS系统框架的私有Objective-C头。 There are a lot of classes/methods hidden from the public (some rightly so) 公众隐藏了很多类/方法(有些是正确的)

For iPhoneOS specifically, class-dump-z is a great way to dump headers. 对于iPhoneOS,class-dump-z是转储标头的好方法。 The only problem, of course, is that you can't actually see what is going on inside of each method. 当然,唯一的问题是你实际上无法看到每个方法内部发生了什么。 IDA Pro and a few scripts make it possible to see the assembly instructions for these system frameworks. IDA Pro和一些脚本可以查看这些系统框架的汇编指令。 (example picture: http://grab.by/1Vn6 ). (示例图片: http//grab.by/1Vn6 )。

The most handy IDC scripts are fixobjc2 and dyldinfo. 最方便的IDC脚本是fixobjc2和dyldinfo。 You can find each of these linked from this blog post: http://networkpx.blogspot.com/2010/01/two-ida-pro-5x-scripts-for-iphoneos.html 您可以在以下博文中找到以下链接: http//networkpx.blogspot.com/2010/01/two-ida-pro-5x-scripts-for-iphoneos.html

But, what good is this information if you can't use it? 但是,如果您不能使用它,这些信息有什么用呢? iPhone developer saurik has written something called MobileSubstrate that enables hooking onto any method. iPhone开发人员saurik编写了一个名为MobileSubstrate的东西,可以挂钩到任何方法。 http://svn.saurik.com/repos/menes/trunk/mobilesubstrate/ http://svn.saurik.com/repos/menes/trunk/mobilesubstrate/

Others have already mentioned class-dump, which is an excellent tool for retrieving the class definitions from a compiled executable. 其他人已经提到了class-dump,它是从编译的可执行文件中检索类定义的优秀工具。 On a related note, you should also take a look at otx , which is provides very nice (readable), disassembled output. 在相关的说明中,您还应该看看otx ,它提供了非常好的(可读的)反汇编输出。

If you need a way to quickly test snippets of code, use F-Script (mentioned by others), Nu or MacRuby . 如果您需要一种快速测试代码片段的方法,请使用F-Script(由其他人提及), NuMacRuby Of these, I've mainly used Nu. 其中,我主要使用Nu。 It has the capability to define bridged functions on the fly, and can handle pointers, both of which are pretty handy if you need to call arbitrary C functions. 它具有动态定义桥接函数的能力,并且可以处理指针,如果您需要调用任意C函数,这两个指针都非常方便。

Since you mentioned being interesting in Spaces and other screen managers, you should also read A brief tutorial on reverse engineering OS X . 既然你提到了Spaces和其他屏幕管理器的兴趣,你也应该阅读逆向工程OS X的简要教程 It's an old article by Rich Wareham (author of the pre-Spaces multi-desktop app: 'Desktop Manager') on how he figured out the call syntax for few private CoreGraphics methods in order to do nice desktop transitions. 这是Rich Wareham(前Spaces多桌面应用程序的作者:'桌面管理器')的一篇旧文章,讲述了他如何找出少数私有CoreGraphics方法的调用语法,以便进行漂亮的桌面转换。 The source code for Desktop Manager is also available, which might be useful to you. 桌面管理器源代码也可用,这可能对您有用。

This site shows how to patch an existing Objective C program: http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering 该站点展示了如何修补现有的Objective C程序: http//www.culater.net/wiki/moin.cgi/CocoaReverseEngineering

Namely posing: 即冒充:

[[B class] poseAsClass:[A class]];

and method swizzling: 和方法混合:

 /**
 * Renames the selector for a given method.
 * Searches for a method with _oldSelector and reassigned _newSelector to that
 * implementation.
 * @return NO on an error and the methods were not swizzled
 */
BOOL DTRenameSelector(Class _class, SEL _oldSelector, SEL _newSelector)
{
        Method method = nil;

        // First, look for the methods
        method = class_getInstanceMethod(_class, _oldSelector);
        if (method == nil)
                return NO;

        method->method_name = _newSelector;
        return YES;
}

// *** Example ***


// never implemented, just here to silence a compiler warning
@interface WebInternalImage (PHWebInternalImageSwizzle)
- (void) _webkit_scheduleFrame;
@end

@implementation WebInternalImage (PHWebInternalImage)

+ (void) initialize
{
        DTRenameSelector([self class], @selector(scheduleFrame), @selector (_webkit_scheduleFrame));
        DTRenameSelector([self class], @selector(_ph_scheduleFrame), @selector(scheduleFrame));
}

- (void) _ph_scheduleFrame
{
        // do something crazy...
        ...
        // call the "super" method - this method doesn't exist until runtime
        [self _webkit_scheduleFrame];
}

@end

(code copied from http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering ) (从http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering复制的代码)

作为其他答案的补充,您将要查看DYLD_INSERT_LIBRARIES以将代码注入Cocoa程序。

You should definitely consider using DTrace. 你绝对应该考虑使用DTrace。 There is an excellent BlackHat presentation on using DTrace for reverse engineering on OS X entitled, "DTRACE: The Reverse Engineer's Unexpected Swiss Army Knife". 在OS X上使用DTrace进行逆向工程有一个很好的BlackHat演示文稿,名为“DTRACE:逆向工程师的意外瑞士军刀”。

You can get a copy and view the video presentation here . 您可以在此处获取副本并查看视频演示文稿。

There are also some excellent papers at www.uninformed.org on reverse engineering OS X. 关于逆向工程OS X,www.uninformed.org上也有一些优秀的论文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM