We walked so fast that our souls couldn't keep up.
Small happiness is around, easy to meet is heaven.
In the reverse and blasting we often in Ida in contact with the assembly, generally do not too familiar with the Android VB, and so on, do not know the students can first look at the previous article "Android Arm Common Assembly instruction Collection" to continue our study, we first look at a picture.
There are push/ldr/sub/movs/blx/subs/beq/cmp in this view, which are almost common, but do not need to be understood, understand the instructions, and then we will analyze the role of these instructions respectively.
First introduce the concept of things, lest everyone behind be confused, that is why there will be s and! .
- S: The condition flag bit of the program status register after instruction execution will be refreshed, such as adds R1,r0, #2
- ! : The address expression in the directive contains! suffix, when the instruction executes, the address value in the base register changes, the result is: the value in the base register (after the instruction executes) = The value before execution of the instruction + address offset , such as LDR r3,[r0, #2]! After the instruction is executed, R0 = R0 + 2
The next step is to explain what each of the commands in this view does.
push, as the name implies, directly push into the stack. On the contrary, the pop is out of the stack.
? instruction Example:
- Push{cond} reglist Push registers the register to a full descending stack
- Push {R0,R4-R7} presses the R0,R4-R7 register contents into the stack
- Pop{cond} reglist pop pops data to register from full descending stack
- Pop {r0,r4-r7} pops the R0,R4-R7 register from the stack
LDR, instruction syntax:ldr{condition} destination register,< memory address >, LDR instructions are used to transfer a 32-bit word data from memory to the destination register. This instruction is usually used to read 32 bits of the word data from memory to the general register, and then processing the data, when the program counter PC as the purpose register, the instruction from memory read the Word data is treated as the destination address, thus can realize the program flow jump. This instruction is more commonly used in program design, and its addressing mode is flexible and diverse.
?? See the previous article in the Ctrl + F search for "Android arm Common Assembly Command Collection": Load/Store Instructions
? instruction Example:
- LDR R0,[R1]; reads the word data with a memory address of R1 into the register R0.
- LDR R0,[R1,R2]; reads the word data with a memory address of R1+R2 into the register R0.
MOVS, LDR These are jump instructions , directly to the program counter PC to write jump address value, by writing to the program counter PC jump address value, can achieve in the 4GB address space of any jump, that someone will ask, What is the implementation principle of a jump in the 32MB address space from the current instruction forward or backward? In fact, in the last article mentioned, they are b\bl\blx\bx Four directives, this we finally came to explain, in fact, they are a bit like we often say the branch structure, we choose from the image of the Fourth Directive as the view data.
You can see, R5 is the original address, in fact, 0xff8->0x104a, copy return address to the PC, to achieve the return of the child, do the classmate of Android may have a question, why there is a S, because the syntax is mov{condition}{s} The purpose of the Register + source operand .
See here everyone may be dizzy, how to feel is not understand the number, that other those, such as add, etc, to everyone to tidy up a form.
| Mnemonic |
instruction Function Description |
Mnemonic |
instruction Function Description |
| ADD |
Addition instructions |
MRS |
Transmitting the contents of a CPSR or SPSR to a general register instruction |
| Adc |
With carry addition instruction |
Mrc |
Data transfer instructions from the Coprocessor register to the ARM register |
| and |
Logic and instructions |
Msr |
Instructions for transmitting general-purpose registers to CPSR or SPSR |
| B |
Branch instructions |
MUL |
32-bit multiplication instruction |
| BL |
Branch instruction with return |
BIC |
Bit clear 0 Instructions |
| BLX |
Branch instructions with return and status switch |
MLA |
32-bit multiply plus instruction |
| Bx |
Branch instruction with status switch |
MVN |
Data Take back delivery instructions |
| TST |
Bit test Instruction |
ORR |
Logic or instruction |
| Cdp |
Coprocessor Data Operation Instructions |
Rsc |
Reverse subtraction instruction with dislocation |
| RSB |
Reverse subtraction Instruction |
Sbc |
With dislocation subtraction instruction |
| CMN |
Compare counter-value directives |
Cmp |
Compare directives |
| Stc |
Coprocessor Register Write memory instruction |
EOR |
XOR directive |
| Stm |
Bulk Memory Word Write instruction |
LDC |
Memory-to-coprocessor data transfer Instructions |
| Str |
Register-to-memory data store directives |
Ldm |
Loading multiple register directives |
| SUB |
Subtraction directives |
LDR |
Memory-to-register data loading instructions |
| Swi |
Software Interrupt Instructions |
Mcr |
Data transfer instructions from ARM registers to coprocessor registers |
| TEQ |
Equality Test Instruction |
MOV |
Data transfer Instructions |
SUBS can be seen from the table, sub is a subtraction instruction, such as sub r0,r1,r2 corresponds to R0 = R1-r2,sub r0,r1, #1 is R0 = r1-1, note that SUBS is a low 32-bit subtraction.
What about the BEQ ? Don't worry, look.
BEQ instruction is a jump instruction , but jump to meet certain conditions, meet the jump execution, look at the Red box section.
That leaves only CMP , CMP is the comparison instruction, instruction format: cmp{condition} operand 1, operand 2.
? instruction Example:
- such as CMP R1, #10, equals the comparison of R1 and 10, and sets the CPSR's flag bit.
- CMP r1,r0; Subtracts the value of the register R1 from the value of the register R0 and sets the CPSR flag bit based on the result
- CMP r1,#100; Subtracts the value of the register R1 from the immediate number 100 and sets the CPSR flag bit based on the result
- If you use the word with BEQ: CMP r1,#0 wraps BEQ Label; when the z-condition code in the CPSR register is set, the program jumps to the label label to execute
OK, from the first picture we see that followed by two bit, that if it is more complex than the two-bit how to see ?
? instruction Example:
- First look at MOV, such as mov r0,r1, LSL R3, this is what solution? In fact, it moves the value of R1 to the left R3 bit and then stores the result in R0.
- Again, LDR, Ldr R0,[r1],r2, what's the solution? It is the memory address of R1 read into the register R0, and the new address r1+r2 write to R1, remember, R1 is the final address of the landing.
Other more complex instruction examples are mentioned in the previous article, which is not quite clear about the "Android arm Common Assembly Command Collection" that can be found in the article, and then CTRL + F search: Data loading/storing instructions or searching data processing instructions , or searching the instructions they need .
|| Copyright Notice: This article for Bo Master Dujinyang original article, reproduced please indicate the source. http://blog.csdn.net/DJY1992/article/details/71404947
Android Graphics Reverse Engineering arm Common Assembly instructions (i)