__INCLUDE_LEVEL__表示包含深度,和#include"cpp.c"构成递归,这个递归用处不大,只是在一次次根据S的值执行不同代码,可以不管他
通过对每个#if分析可得知每个块的功能
S相当于loc,然后对RZX等等做运算,根据结果进行跳转到不同S
得到主要逻辑:

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
42
43
44
45
46
47
48
49
50
51
52
53
I = 0;
M = 0;
N = 1;
P = 0;
Q = 0;
while (1)
{
B = 0xE5;//1110 0101
B = B + I;
if (B == 0) break;//if(Q==0) success
B = 0x80;//1000 0000
B = B + I;
L = B;
A = RAM[B];
L = I; B = RAM[I];
R = 1;
X = 1;
Y = 0;
while (1)
{
if (X == 0)
break;
Z = X;
Z = Z & B;
if (Z != 0)
Y = Y + A;
X = X + X;
A = A + A;
}
A = Y;

R = ~R;
Z = 1;
R += Z;
R += Z;

O = M;
O += N;
M = N;
N = O;
A += M;
B = 0x20;//0010 0000
B += I;
L = B; C = RAM[L];
A = A ^ C;
P = P + A;
B = 0x40;//0100 0000
B = B + I;
L = B; A = RAM[L];
A = A ^ P;
Q |= A;
I += 1;
}

由前面的宏定义知flag长度为26,并且在上面的主要逻辑中可以看到flag是一位一位验证的,因此可以直接暴力跑。

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include<stdio.h>
unsigned char RAM0[][8] = { {1,1,0,1,1,1,0,1},
{1,0,1,0,1,0,1,0},
{1,1,0,1,0,1,0,1},
{1,0,1,0,0,0,1,1},
{1,0,0,1,1,1,0,1},
{1,0,1,1,1,0,0,1},
{1,0,0,1,0,0,1,1},
{1,0,0,1,0,1,1,0},
{1,1,0,1,1,1,0,1},
{1,1,1,0,1,1,0,0},
{1,0,0,1,1,0,1,1},
{1,0,1,1,0,0,1,1},
{1,0,0,0,0,1,0,0},
{1,1,0,0,1,1,0,1},
{1,1,1,1,0,0,1,1},
{1,1,1,1,0,0,1,1},
{1,1,1,1,1,0,0,1},
{1,0,0,1,0,0,0,0},
{1,0,1,0,1,1,0,1},
{1,0,1,1,1,1,0,0},
{1,1,0,1,0,1,1,1},
{1,1,1,1,1,1,1,0},
{1,1,1,0,1,0,1,0},
{1,0,0,0,0,1,0,1},
{1,1,0,1,0,1,1,1},
{1,1,1,0,0,0,0,1},
{1,1,1,0,0,1,1,0},
{1,1,0,0,0,1,0,0},
{1,1,1,0,1,0,0,0},
{1,0,1,0,0,1,0,0},
{1,0,0,0,1,0,1,1},
{1,1,0,1,1,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,1,0,0,1,1,0},
{0,0,1,0,0,1,1,0},
{1,0,1,0,1,1,0,0},
{1,0,0,0,1,0,0,1},
{0,0,1,0,0,1,1,0},
{1,1,1,0,0,1,1,1},
{0,0,0,0,0,1,0,1},
{0,1,1,0,0,0,0,0},
{0,1,0,1,0,1,0,1},
{1,0,1,1,1,0,1,1},
{1,0,1,0,1,1,1,0},
{1,1,1,0,1,0,0,0},
{1,0,1,1,1,0,0,1},
{1,0,1,1,0,1,1,0},
{0,0,1,1,1,0,1,0},
{0,1,1,1,1,0,1,0},
{1,0,0,1,1,0,0,0},
{1,0,1,1,1,1,1,1},
{1,0,0,1,0,1,1,1},
{0,0,1,1,0,0,0,0},
{1,0,0,1,1,1,1,1},
{0,0,1,0,1,1,0,1},
{1,1,0,0,0,0,0,1},
{0,1,1,0,0,0,0,1},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,0,1,0},
{0,1,1,1,1,0,0,0},
{1,1,1,0,1,0,1,0},
{1,0,0,0,0,1,0,1},
{0,0,0,1,0,1,0,0},
{0,1,0,0,0,1,1,0},
{0,1,0,1,1,1,1,1},
{1,1,0,1,1,1,1,0},
{1,1,0,1,1,0,0,0},
{0,1,0,1,1,1,0,1},
{0,1,1,1,1,0,0,0},
{0,0,1,0,1,1,0,1},
{1,1,0,0,1,1,0,1},
{0,0,0,1,1,0,1,0},
{0,1,1,0,0,0,1,1},
{1,1,0,0,1,1,1,1},
{0,0,1,1,0,0,0,1},
{0,0,0,0,1,0,0,1},
{1,1,0,1,1,1,0,0},
{0,1,0,1,1,1,0,1},
{1,0,0,1,1,0,0,0},
{0,1,1,1,0,1,1,0},
{0,1,1,1,0,0,1,1},
{1,1,1,1,1,0,1,1},
{1,0,0,0,1,1,1,1},
{1,0,1,0,0,1,0,0},
{1,0,1,1,0,0,0,1},
{0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,1},
{0,0,0,0,1,1,1,0},
{0,0,0,0,0,1,1,1},
{1,0,1,1,0,0,1,0},
{0,0,1,1,1,0,0,0} };
unsigned char RAM[0xFF] = {0};
void change()
{
for (int i = 0; i < 91; i++)
{
RAM[i] = RAM0[i][7] * 128 + RAM0[i][6] * 64 + RAM0[i][5] * 32 + RAM0[i][4] * 16 + RAM0[i][3] * 8 + RAM0[i][2] * 4 + RAM0[i][1] * 2 + RAM0[i][0] * 1;
}
}
unsigned char A, B, C, I, L, M, N, O, P, X, Y, Z, Q, R;
unsigned char a, b, c, i, l, m, n, o, p, x, y, z, q, r;
void push()
{
a = A;
b = B;
c = C;
i = I;
l = L;
m = M;
n = N;
o = O;
p = P;
x = X;
y = Y;
z = Z;
q = Q;
r = R;
}
void pop()
{
A = a;
B = b;
C = c;
I = i;
L = l;
M = m;
N = n;
O = o;
P = p;
X = x;
Y = y;
Z = z;
Q = q;
R = r;
}
int main()
{
change();
I = 0;
M = 0;
N = 1;
P = 0;
Q = 0;
while (1)
{
B = 0xE5;//1110 0101
B = B + I;
if (B == 0) break;//if(Q==0) success
B = 0x80;//1000 0000
B = B + I;
for (int j = 48; j < 127; j++)
{
push();
L = B;
A = j;
L = I; B = RAM[I];
R = 1;
X = 1;
Y = 0;
while (1)
{
if (X == 0)
break;
Z = X;
Z = Z & B;
if (Z != 0)
Y = Y + A;
X = X + X;
A = A + A;
}
A = Y;

R = ~R;
Z = 1;
R += Z;
R += Z;

O = M;
O += N;
M = N;
N = O;
A += M;
B = 0x20;//0010 0000
B += I;
L = B; C = RAM[L];
A = A ^ C;
P = P + A;
B = 0x40;//0100 0000
B = B + I;
L = B; A = RAM[L];
A = A ^ P;
Q |= A;
if (Q == 0)
{
putchar(j);
break;
}
pop();
}
I += 1;
}
}

即可得flag:CTF{pr3pr0cess0r_pr0fe5sor}