- Mastering Reverse Engineering
- Reginald Wong
- 321字
- 2021-06-10 19:40:32
MOV and LEA
MOV is used to read the value at a given address, while LEA (Load Effective Address) is used to get the address instead:
mov eax, dword ptr [00000060] ; stores 63626160h to eax
mov eax, dword ptr [00000060] ; stores 00000060h to eax
So, how is the LEA instruction helpful if you can calculate the address by yourself? Let's take the following C code as an example:
struct Test {
int x;
int y;
} test[10];
int value;
int *p;
// some code here that fills up the test[] array
for (int i=0; i<10, i++) {
value = test[i].y;
p = &test[i].y;
}
The C code starts with defining test[10], an array of struct Test, which contains two integers, x and y. The for-loop statement takes the value of y and the pointer address of y in a struct test element.
Let's say the base of the test array is in EBX, the for-loop counter, i, is in ECX, the integers are DWORD values, and so struct Test will contain two DWORD values. Knowing that a DWORD has 4 bytes, the equivalent of value = test[i].y; in assembly language will look like mov edx, [ebx+ecx*8+4]. Then, the equivalent of p = &test[i].y; in assembly language will look like lea esi, [ebx+ecx*8+4]. Indeed, without using LEA, the address can still be calculated with arithmetic instructions. However, calculating for the address could be done much more easily using LEA:
; using MUL and ADD
mov ecx, 1111h
mov ebx, 2222h
mov eax, 2 ; eax = 2
mul ecx ; eax = 2222h
add eax, ebx ; eax = 4444h
add eax, 1 ; eax = 4445h
; using LEA
mov ecx, 1111h
mov ebx, 2222h
lea eax, [ecx*2+ebx+1] ; eax = 4445h
The preceding code shows that the six lines of code can be optimized to three lines using the LEA instruction.
- Securing Blockchain Networks like Ethereum and Hyperledger Fabric
- 網絡安全意識導論
- Web安全與攻防入門很輕松(實戰超值版)
- Preventing Digital Extortion
- 硬黑客:智能硬件生死之戰
- Building a Home Security System with BeagleBone
- 數據安全領域指南
- Instant Java Password and Authentication Security
- Learning Pentesting for Android Devices
- 網絡關鍵設備安全檢測實施指南
- 網絡服務安全與監控
- 隱私計算:推進數據“可用不可見”的關鍵技術
- Kali Linux高級滲透測試(原書第4版)
- 功能型密碼算法設計與分析
- Kali Linux無線網絡滲透測試詳解