Kotani bald collection
-
Today we are going to focus on logic like if, do-while, while, for, etc.
-
This time will not always look at the source, the introduction of a reverse is commonly used tool ————Hopper
1. Hopper
The use of
This brothers use free ~, after all can save point is saving point ~ ha ha ha
-
- This tool is smart and simple. Take a look at its icon first. (Don’t download it wrong)
-
- Open it and turn it on
Binary file
Dragged in. With respect to OK ~
- Open it and turn it on
-
- I just downloaded it online
ipa
(I don’t know whose ~), as shown below
- I just downloaded it online
2. The judge
2.1. Global variables
-
- The preparation has been finished. Let’s have a look
The global variable
(This is used in a lot of places ~)
- The preparation has been finished. Let’s have a look
-
- Same old rules
int g = 10;
int funcIfLogic(int a, int b){
return a+b+g;
}
int main(int argc, char * argv[]) {
int c = funcIfLogic(1.2);
printf("%d",c);
}
Copy the code
-
- see
Compile and analyze logic
- see
As you can see from the analysis, the global function is evaluated by address offset
0 x104b1e1f8 – (
If you move three to the right, you're essentially wiping out the last three
) – > 0 x104b1e – (Add the offset value (7) and move it three places to the left
) – > 0 x104b25000 – (Plus the offset address 0x554
) – > 0 x104b25554
2.2. if
judge
- Change the code a little bit
if
)
int g = 10;
int funcIfLogic(int a, int b){
if (a > b) {
return a+g;
}else{
returnb+g; }}int main(int argc, char * argv[]) {
int c = funcIfLogic(1.2);
printf("%d",c);
}
Copy the code
- Feels like assembly has a little more:
2.2.1. Judgment extension (B instruction)
- Up there, I see it
b.le
isLess than or equal to
The meaning of. I made a list of common commands and meanings for my brothers
2.3. assembly
Turn to the seniorPseudo code
~
Now that we’ve introduced tools above, let’s use tools to write logical pseudocode ~
-
- First drag the binary to
hopper
And then find a way ~
- First drag the binary to
-
- Then the brothers looked at me
Analysis process
- Then the brothers looked at me
The reason I find assembly hard is because it’s boring, so you guys have to pull up your pants.
3. The cycle
- Next, brothers look at the cycle ~
3.1. do-while
cycle
- As usual, research this thing and I’ll see how it works
void funcLoop(a){
int i = 1;
do {
i++;
} while (i<10);
printf("i==%d",i);
}
int main(int argc, char * argv[]) {
funcLoop();
}
Copy the code
assembly
Analysis of the
This is add, then judge, then jump
This time and brothers line by line read, are about the same. (I took out the key points.)
3.2. while
cycle
- We look at the
while
the
void funcLoop2(a){
int i = 1;
while (i<10) {
i++;
}
printf("i==%d",i);
}
Copy the code
Let’s see what the similarities and differences are between them
while
The loop is judged first, then added, before jumping
3.3. for
cycle
for
Loops look a little bit more high-end. Let’s see
void funcLoop3(a){
int i;
for (i = 1; i < 10; i++) {
}
printf("i==%d",i);
}
Copy the code
- Continue to
assembly
This logic is the same as the while loop, it all looks the same. Both are, judge first, add value after jump ~
4. To summarize
It’s time for summing up again
-
- I didn’t figure it out this time
switch
Statement, I figured out must make a blog, let brothers point at 😆
- I didn’t figure it out this time
-
- This is the study
Restore pseudocode
, will really work hard, mainly more boring, I cheer for the brothers
- This is the study
-
- Finally, I hope to make progress together with my brothers. ⛽️ (this is the gas station 😆)