Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symbol import in lldb #2

Open
reverseXiang opened this issue May 31, 2023 · 7 comments
Open

symbol import in lldb #2

reverseXiang opened this issue May 31, 2023 · 7 comments
Labels
good first issue Good for newcomers

Comments

@reverseXiang
Copy link

I would like to ask you how to solve the problem of symbol import in lldb, when I use it, I get an error like this "use of undeclared identifier 'xxxxxx'", and it seems to be very time consuming to import the required system headers one by one, because one system header file may depend on another system header file.

@chenhuimao
Copy link
Owner

1.frame.EvaluateExpression('@import Foundation;@import UIKit;@import ObjectiveC;')
(example: https://github.com/chenhuimao/HMLLDB/blob/master/commands/HMLLDBHelpers.py, evaluate_expression_value)

2.Use common APIs.Use "id" to represent specific objective-c types.

3.Use typedef.
(example: https://github.com/chenhuimao/HMLLDB/blob/master/commands/HMExpressionPrefix.py)

4.The variable identifies the type when used. The return value also identifies the type.
❌Class inputClass = objc_lookUpClass([clsName UTF8String]);
✅Class inputClass = (Class)objc_lookUpClass((char *)[(NSString *)clsName UTF8String]);

5.Sometimes it is necessary to use the objc_msgSend function.
(example: https://github.com/chenhuimao/HMLLDB/blob/master/commands/HMSandbox.py)

6.Get the address of the function and call it with a function pointer.
(I wrote a function to get the address of a function, but haven't actually used it yet. https://github.com/chenhuimao/HMLLDB/blob/master/commands/HMLLDBHelpers.py, get_function_address)

@chenhuimao chenhuimao added the good first issue Good for newcomers label Jul 28, 2023
@reverseXiang
Copy link
Author

老哥,你太强了。我这里还有一种简化脚本逻辑的方法,自己把复杂的oc调用写入三方库注入到应用里,lldb可以直接调用注入的三方库里的OC方法,这样就不需要在python里面写那些蹩脚的OC语法了

@chenhuimao
Copy link
Owner

老哥,你太强了。我这里还有一种简化脚本逻辑的方法,自己把复杂的oc调用写入三方库注入到应用里,lldb可以直接调用注入的三方库里的OC方法,这样就不需要在python里面写那些蹩脚的OC语法了

我的这个库有几个原则,一个是支持真机,二是任何项目可以直接使用,工程不用做任何修改。
好处是方便大家上手,而且主要是为了debug而不是reverse,不对原有项目做任何侵入。
类似的方案我也想过,就是提前写好framework,模拟器倒是可以直接dlopen电脑本地framework,而真机需要访问电脑本地文件,有点麻烦。
你的方案恐怕不支持真机,或者需要改工程配置?

@reverseXiang
Copy link
Author

reverseXiang commented Jul 28, 2023

我主要是为了reverse,做的mac逆向。对于上面你提的问题,如果是在越狱设备的话问题不大

@reverseXiang
Copy link
Author

reverseXiang commented Jul 28, 2023

目前在尝试一种大批量指令的trace功能,做到汇编级别的监控,通过lldb实现trace功能,因为监控大量汇编指令的同时加了各种条件过滤和符号解析,所以难免遇到各种问题。我在python里调用一些三方库写好的符号解析逻辑,第一次调用经常会失败,报错,调用成功一次以后,后面就又可以正常运行了。

@chenhuimao
Copy link
Owner

可以看一下我写的tracefunction和traceinstruction命令,也许能给你提供一点思路?通过lldb实现指令级别的监控太耗时了,我的方案还没能解决耗时问题。

@reverseXiang
Copy link
Author

reverseXiang commented Aug 22, 2023

我第一次看见lldb还有thread step-scripted这种命令,这些指令都好小众(涨见识了)。我的指令级监控基本实现了,选择的方案是下断点,但只能实现对单个线程的监控,同时将其它线程都挂起,不然会变得非常慢。这个方案整体下来,目前上万条指令是跑通过的,印象中耗时2-3分钟吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants