滴水逆向 03-03 指针6
指针数组
指针数组就是元素类型为指针的数组,即带 * 的类型,因此指针数组一个元素占 4 字节
1 | char* arr[5] = {0}; //占4*5=20字节 |

最常用的指针数组:
1 | char* p1 = "if"; |
等价于:
1 | char* keyword[] = { |
就是存的地址嘛,同理可以知道这个 keyword 的大小为 16
结构体指针
探测结构体指针的特性:
1 | struct Arg { |
通过结构体指针读取、修改:
1 | struct Arg { |
课后作业
-
创建一个
int* arr[5]数组,并为数组赋值(使用&)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main(int argc,char* argv[]) {
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int* arr[5] = {0};
arr[0] = &a;
arr[1] = &b;
arr[2] = &c;
arr[3] = &d;
arr[4] = &e;
return 0;
} -
创建一个字符指针数组,存储所有的 C 的关键词(查资料找),并全部打印出来
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
int main(int argc,char* argv[]) {
char* keyword[] = {
"auto",
"break",
"case",
"char",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"extern",
"float",
"for",
"goto",
"if",
"int",
"long",
"register",
"return",
"short",
"signed",
"sizeof",
"static",
"struct",
"switch",
"typedef",
"union",
"unsigned",
"void",
"volatile",
"while"
};
for (int i = 0; i <32; i++) {
printf("%s\n", *(keyword + i));
}
return 0;
} -
查找这些数据中,有几个
id=1 level=8的结构体信息1
2
3
4
5
6
7
8
9
100x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,
0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,
0x00,0x33,0x01,0x00,0x00,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,
0x00,0x00,0x64,0x01,0x00,0x00,0x00,0x08,0x00,0x00,
0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,
0x00,0x02,0x57,0x4F,0x57,0x00,0x06,0x08,0x00,0x00,
0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,
0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00结构体定义如下:
1
2
3
4typedef struct TagPlayer {
int id;
int level;
}Player;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
char data[100] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x07,0x09,
0x00,0x20,0x10,0x03,0x03,0x0C,0x00,0x00,0x44,0x00,
0x00,0x33,0x01,0x00,0x00,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x64,0x00,0x00,0x00,0xAA,0x00,
0x00,0x00,0x64,0x01,0x00,0x00,0x00,0x08,0x00,0x00,
0x00,0x00,0x02,0x00,0x74,0x0F,0x41,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0A,0x00,
0x00,0x02,0x57,0x4F,0x57,0x00,0x06,0x08,0x00,0x00,
0x00,0x00,0x00,0x64,0x00,0x0F,0x00,0x00,0x0D,0x00,
0x00,0x00,0x23,0x00,0x00,0x64,0x00,0x00,0x64,0x00
};
typedef struct TagPlayer {
int id;
int level;
} Player;
int func(int id, int level) {
int cnt = 0;
for (int i = 0; i < 100 - 7; i++) {
Player* pdata = (Player*)(data + i);
if (pdata->id == id && pdata->level == level) cnt++;
}
return cnt;
}
int main(int argc,char* argv[]) {
int num = func(1, 8);
printf("%d\n", num);
return 0;
}