Reverse Engineering for Beginners

(avery) #1

CHAPTER 18. ARRAYS CHAPTER 18. ARRAYS


for (y=0; y<4; y++)
a[x][y]=0;

// fill second row by 0..3:
for (y=0; y<4; y++)
a[1][y]=y;
};


All three rows are marked with red. We see that second row now has values 0, 1, 2 and 3:


Figure 18.7:OllyDbg: array is filled

Column filling example


Let’s fill the third column with values: 0..2:


Listing 18.21: Column filling example

#include <stdio.h>


char a[3][4];


int main()
{
int x, y;


// clear array
for (x=0; x<3; x++)
for (y=0; y<4; y++)
a[x][y]=0;

// fill third column by 0..2:
for (x=0; x<3; x++)
a[x][2]=x;
};


The three rows are also marked in red here. We see that in each row, at third position these values are written: 0, 1 and 2.


Figure 18.8:OllyDbg: array is filled

18.6.2 Access two-dimensional array as one-dimensional


We can be easily assured that it’s possible to access a two-dimensional array as one-dimensional array in at least two ways:


#include <stdio.h>


char a[3][4];


char get_by_coordinates1 (char array[3][4], int a, int b)
{
return array[a][b];

Free download pdf