Welcome to the iOS Reverse series.
- IOS reverse RSA theory
- IOS reverse hash theory
- IOS reverse application re-signature + wechat re-signature combat
- IOS reverse Shell script + script re-signature
- IOS reverse code injection +Hook
- IOS reverse MachO file
- IOS reverse dyLD process
- IOS reverse HOOK principle of Fishhook
- IOS reverse LLDB debugging
Writing in the front
LLDB debugging is often used in daily development. Po is probably the most commonly used command. In the reverse world, it is impossible to debug your code with breakpoints, so LLDB becomes a very important tool
A, LLDB
LLDB (Low Lever Debug) is a dynamic debugging tool built into XCode by default. It exists in the console at the bottom of the main window together with the LLVM compiler, bringing us richer process control and data detection debugging functions
The standard LLDB provides an extensive set of commands designed to be compatible with older versions of GDB commands. In addition to using standard configurations, you can easily customize the LLDB to suit your needs
LLDB command
1. LLDB syntax
<command> [<subcommand> [<subcommand>...]] <action> [-options [option-value]] [argument[argument...]]
Copy the code
<command>
(Command) and<subcommand>
Subcommand: name of the LLDB debugging command<action>
: Executing a command<options>
: Command options<arguement>
: Command parameter[]
: Indicates that the command is optional
Such as breakpoint set -n test
command
Breakpoint: breakpoint commandaction
: set Sets a breakpointoption
-n sets a breakpoint according to method namearguement
: test Indicates that the method name is test
2. LLDB primary use
The LLDB command takes effect only when you enter the LLDB state (click Pause symbol in the running state)
- Viewing the breakpoint list
where
Is where the breakpoint isaddress
Is the breakpoint addressoption disable
Breakpoints disabled
(lldb) breakpoint list
Copy the code
- Setting a single breakpoint
Breakpoint set -n "[ViewController ocMethod1]" breakpoint set -n"Copy the code
- Set a set of breakpoints
(lldb) breakpoint set -n "[ViewController ocMethod1]" -n "[ViewController ocMethod2]" -n "[ViewController ocMethod3]"
Copy the code
- Disable/enable a set of breakpoints
// Disable (LLDB) breakPoint disable 1 // Enable (LLDB) breakpoint enable 1Copy the code
- Disable/enable a breakpoint
// Disable breakPoint disable 1.1 // Enable breakPoint enable 1.1Copy the code
- Delete all breakpoints
(lldb) breakpoint delete
Copy the code
- “Delete” a set of breakpoints (cannot delete a breakpoint, can only disable a breakpoint)
(lldb) breakpoint delete 1.1
Copy the code
- Set a breakpoint for a method
(lldb) breakpoint set --selector touchesBegan:withEvent:
Copy the code
- Sets a breakpoint for a method in a file
(lldb) breakpoint set --file ViewController.m --selector touchesBegan:withEvent:
Copy the code
- Set breakpoints for all matching method names
(lldb) breakpoint set -r ocMethod
Copy the code
- Exit the LLDB mode
(lldb) c
Copy the code
- See the help
Breakpoint help (LLDB) breakpoint help (LLDB) breakpoint help (LLDBCopy the code
3. Summary of LLDB primary use
- Manual breakpoints will also appear
LLDB
The breakpoint list, butLLDB
The breakpoint does not appear in Xcode’s breakpoint list - Manually set breakpoints can be disabled/cancelled by clicking/holding down, or can pass
LLDB
Command to operate, butLLDB
A breakpoint can only be passedLLDB
To operate - The deleted breakpoints are not in the list, but the new breakpoints are sorted after the previous breakpoints
The command | meaning | shorthand |
---|---|---|
breakpoint list | Viewing the breakpoint list | breakpoint l |
breakpoint set -n cMethod | Setting a single breakpoint | b -n cMethod |
breakpoint set -n “[ViewController ocMethod1]” -n “[ViewController ocMethod2]” |
Set a set of breakpoints | b -n “[ViewController ocMethod1]” -n “[ViewController ocMethod2]” |
breakpoint set –selector touchesBegan:withEvent: | Set a breakpoint for a method | b -selector touchesBegan:withEvent: |
breakpoint set –file ViewController.m –selector touchesBegan:withEvent: | Sets a breakpoint for a method in a file | b -f ViewController.m –selector touchesBegan:withEvent: |
breakpoint set -r ocMethod | Set breakpoints for all matching method names | b -r ocMethod |
breakpoint enable 1 | Enable a set of breakpoints | breakpoint en 1 |
breakpoint disable 1 | Disable a set of breakpoints | breakpoint dis 1 |
Breakpoint enable 1.1 | Enable a breakpoint | Breakpoint en 1.1 |
Breakpoint disable 1.1 | Disable a breakpoint | Breakpoint dis 1.1 |
breakpoint delete | Delete all breakpoints | breakpoint d |
continue | Exit the LLDB mode | c |
next | Step by step, executing the subfunctions together as a whole | n |
stpe | Step by step, executing the subfunctions together as a whole | s |
About abbreviations:
b
:breakpoint set
l
:list
-n
:--name
-f
:--file
dis
:disable
en
:enable
LLDB execution code
Print-out expression –object- Expression is the most commonly used Po instruction in development
p
: as aexpression
An abbreviation for “express execution.o
Is:object
The abbreviation of “pass”help expression
View command)po
: Execute object – outputs information about this object
Now that we know that the p instruction has the function of executing code, let’s play with it
-
Changing background color dynamically (I was not successful on machOS 10.15.5+Xcode11)
- Enter manual breakpoint (do not click pause symbol or self will not be retrieved)
- Console input
p self.view.backgroundColor = [UIColor redColor];
- You can go over the break point and see the effect
-
Dynamically create objects and assign values
- Set a global variable
FXPerson *p
- Also enter the manual breakpoint
- Console input
p self.p = [FXPerson new]; self.p.name = @"Felix";
- See the effect
- Set a global variable
Function call stack
Next debug in the following code, click on the screen to call test, test1, test2, and set a breakpoint at test2
- (void)testWithStr:(NSString *)str {
NSLog(@"test");
[self test1WithStr:str];
}
- (void)test1WithStr:(NSString *)str {
NSLog(@"test1");
[self test2WithStr:str];
}
- (void)test2WithStr:(NSString *)str {
NSLog(@"test2");
NSLog(@ "% @", str);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self testWithStr:@"test"];
}
Copy the code
bt
View the function call stack to see the order of function calls
up/down
Move function calls up and down
Frame the select digital
— Jump function call (0 means current method, 2 means before 2 methods)
frame variable
View the current function properties: memory address, method name, parameters
thread return
End the current function call, jump back to the next step on the previous call stack (currently jump back to line 30, ready to execute line 31)
From this, you can try to modify the parameter’s value in the call to print the new value
Up Modifies the parameters of a function that has already been called
- use
up
The command goes back to the previous step and usesp str = @"F";
modified
- use
– Over the breakpoint, still print the original value
Modify function parameters ahead of time
- Set a breakpoint ahead of the last function call to modify it
– The breakpoint is crossed, and the new value is printed
Summary: Code that has already been executed can not be rolled back to change the value arbitrarily, should be set in advance to change the breakpoint
5. Memory breakpoints
Memory breakpoints, as the name implies, are breakpoints for memory
throughwatchpoint set variable self->_p->_name
Breakpoints can be placed on the corresponding property memory
- Addr: indicates the memory address
- Size: memory bytes occupied
- State: Indicates whether the current state is available
Changing the value of the memory address brings you to the breakpoint (equivalent to the KVO mechanism at this point) and the function call stack
- Memory breakpoints can also pass
watchpoint list
To view the list of memory outages - Also through
watchpoint delete
To delete
Breakpoint add command
Similar to adding script commands to a program, breakpoint execution can also add commands
- through
breakpoint command add 1
You can add commands to a specified breakpoint - through
DONE
End the breakpoint command
When the breakpoint arrives, the previous command is executed
Seven, target stop – hook
target stop-hook
Breakpoint (watchpoint) – breakpoint (watchpoint) – breakpoint (watchpoint) – breakpoint (watchpoint)
As long astarget stop-hook add
Any breakpoint will trigger the command to add
A single command can be abbreviated astarget stop-hook add -o "frame variable"
(-o
Represents a single command.
Similarly, it can be usedtarget stop-hook list
Check the list
target stop-hook disable
To disable
target stop-hook delete
/undisplay 1
To disable
Next, a higher-order operation is introducedCopy the code
When the LLDB starts, it loads a file called.lldbinit
The document, in/ Users/username
directory
If not, you can passvi .lldbinit
Create, and then add commands to the filetarget stop-hook add -o "frame variable"
Restart the xcode. lldbinit file to run the command will be loaded, a very convenient debugging tool!
Eight, ASLR
ASLR (Address Space Layout Randomization) is called Address space configuration random loading, which is a computer security technology to prevent memory damage vulnerability from being used. It has been applied in various platforms
ASLR makes use of functions by randomly placing the address space of a process’s critical data area to prevent an attacker from reliably jumping to a specific location in memory
Physical address = ASLR + virtual address
Let’s get to know this guy by example
- (void)fxTest {
NSLog(@"%s", __func__);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self fxTest];
}
Copy the code
cmd+B
Compile the generatedMachO file
, the use ofHopperOpen, findfxTest
methods
0x1340 is a virtual address — it’s an offset from the MachO file (the 1 before it means the empty segment, so it doesn’t affect the address).
We just said that the physical address is equal to ASLR plus the virtual address, so what is the ASLR?
throughimage list
I can print it out0x000000010301e000
That’s the processASLR
(See dLYD source code to know that the ASLR value is different every time run)
Physical address =0x000000010ae85000
+ 0x1340
= 0x10AE86340
Write in the back
LLDB these commands like Xcode shortcut keys, not just as well, master is the icing on the cake, more than a debugging idea, can let you open the gap between peers