Reverse Engineering for Beginners

(avery) #1
CHAPTER 18. ARRAYS CHAPTER 18. ARRAYS

Chapter 18


Arrays


An array is just a set of variables in memory that lie next to each other and that have the same type^1.

18.1 Simple example


#include <stdio.h>

int main()
{
int a[20];
int i;

for (i=0; i<20; i++)
a[i]=i*2;

for (i=0; i<20; i++)
printf ("a[%d]=%d\n", i, a[i]);

return 0;
};

18.1.1 x86


MSVC

Let’s compile:

Listing 18.1: MSVC 2008
_TEXT SEGMENT
_i$ = -84 ; size = 4
_a$ = -80 ; size = 80
_main PROC
push ebp
mov ebp, esp
sub esp, 84 ; 00000054H
mov DWORD PTR _i$[ebp], 0
jmp SHORT $LN6@main
$LN5@main:
mov eax, DWORD PTR _i$[ebp]
add eax, 1
mov DWORD PTR _i$[ebp], eax
$LN6@main:
cmp DWORD PTR _i$[ebp], 20 ; 00000014H
jge SHORT $LN4@main
mov ecx, DWORD PTR _i$[ebp]
shl ecx, 1

(^1) AKA (^2) “homogeneous container”

Free download pdf