这个半反编译代码做了什么(C)
What does this Semi-Decompiled Code do (C)
我已将一个 objdump 文件翻译成临时的 C 代码,我正试图弄清楚它的作用。特别是,我被困在一次部分。我会先给出较大的部分,然后是我坚持的部分。
更大的代码部分:
while (true) {
bool v3 = v2 == 5 | v2 < 5 ^ (4 - v2 & v2) < 0; // 0x8048600
// branch -> 0x80485a7
while (true) {
// 0x80485a7
if ((int32_t)file == g1) {
// 0x80485af
printf("guess %d (of 5)? ", v2);
// branch -> 0x80485bf
}
// 0x80485bf
int32_t str2;
char * str = fgets((char *)&str2, 512, file); // 0x80485d2
if (str == NULL) {
// 0x80485fd
if (!v3) {
// break -> 0x8048602
break;
}
// continue -> 0x80485a7
continue;
} else {
int32_t str3 = *(int32_t *)(4 * v2 + 0x80498ec); // 0x80485db
if (strcmp(str, (char *)str3) != 0) {
// 0x80485ee
bomb();
// branch -> 0x80485f3
}
int32_t v4 = v2 + 1; // 0x80485f3
if (v4 >= 6) {
// break (via goto) -> 0x8048602
goto lab_0x8048602;
}
v2 = v4;
// continue (via goto) -> 0x80485a7
goto lab_0x80485a7;
}
// 0x8048602
success();
return 0;
}
lab_0x8048602:
// 0x8048602
success();
return 0;
}
特别让我烦恼的部分:
int32_t str3 = *(int32_t *)(4 * v2 + 0x80498ec); // 0x80485db
if (strcmp(str, (char *)str3) != 0) {
// 0x80485ee
bomb();
// branch -> 0x80485f3
}
我明白strcmp returns 1,0,-1,但是这条语句到底在测试什么?我不完全确定 str3 的值是什么:*(int32_t *)(4 * v2 + 0x80498ec);
。我知道这会将该地址的值转换为某物,但我不确定是什么。
显然,0x80498ec 是一个指向 char 的指针数组
char *msg [] = {"One", "two", "three", "four", "five"};
和v2是这个指针数组的索引。
该行可能最初已读
if (strcmp (str, msg[v2]) != 0)
bomb ();
我已将一个 objdump 文件翻译成临时的 C 代码,我正试图弄清楚它的作用。特别是,我被困在一次部分。我会先给出较大的部分,然后是我坚持的部分。
更大的代码部分:
while (true) {
bool v3 = v2 == 5 | v2 < 5 ^ (4 - v2 & v2) < 0; // 0x8048600
// branch -> 0x80485a7
while (true) {
// 0x80485a7
if ((int32_t)file == g1) {
// 0x80485af
printf("guess %d (of 5)? ", v2);
// branch -> 0x80485bf
}
// 0x80485bf
int32_t str2;
char * str = fgets((char *)&str2, 512, file); // 0x80485d2
if (str == NULL) {
// 0x80485fd
if (!v3) {
// break -> 0x8048602
break;
}
// continue -> 0x80485a7
continue;
} else {
int32_t str3 = *(int32_t *)(4 * v2 + 0x80498ec); // 0x80485db
if (strcmp(str, (char *)str3) != 0) {
// 0x80485ee
bomb();
// branch -> 0x80485f3
}
int32_t v4 = v2 + 1; // 0x80485f3
if (v4 >= 6) {
// break (via goto) -> 0x8048602
goto lab_0x8048602;
}
v2 = v4;
// continue (via goto) -> 0x80485a7
goto lab_0x80485a7;
}
// 0x8048602
success();
return 0;
}
lab_0x8048602:
// 0x8048602
success();
return 0;
}
特别让我烦恼的部分:
int32_t str3 = *(int32_t *)(4 * v2 + 0x80498ec); // 0x80485db
if (strcmp(str, (char *)str3) != 0) {
// 0x80485ee
bomb();
// branch -> 0x80485f3
}
我明白strcmp returns 1,0,-1,但是这条语句到底在测试什么?我不完全确定 str3 的值是什么:*(int32_t *)(4 * v2 + 0x80498ec);
。我知道这会将该地址的值转换为某物,但我不确定是什么。
显然,0x80498ec 是一个指向 char 的指针数组
char *msg [] = {"One", "two", "three", "four", "five"};
和v2是这个指针数组的索引。
该行可能最初已读
if (strcmp (str, msg[v2]) != 0)
bomb ();