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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
;here where the routine starts, magic input 00000000000000000000000000000000000000000000000000000000000000001111111211211122121112121221122211111112112111221211121212211222
f_key_generator proc near ; CODE XREF: sub_4003E4+4A↓p
0000000000400368 sub rsi, 30h
000000000040036C jz short loc_40037A ; if RSI = 0
000000000040036E RSI > 0
000000000040036E dec rsi ; RSI -=1
0000000000400371 jz short loc_400397 ; if RSI = 1
0000000000400373 if RSI > 1
0000000000400373 dec rsi
0000000000400376 jz short loc_4003B8 ; if ((RSI > 1) - 1) - 1 = 0
0000000000400378 jmp short f_exit
000000000040037A ; ---------------------------------------------------------------------------
000000000040037A IF RSI = 0
000000000040037A
000000000040037A loc_40037A: ; CODE XREF: f_key_generator+4↑j
.000000000040037A mov ecx, [rdi+8]
000000000040037D jecxz f_exit ; The jecxz (or jne) instruction is a conditional jump that follows a test.
000000000040037D ; It jumps to the specified location if ECX=0 (f_exit)
0000000000400380 Sets bit in CL position to ZERO and DECREMENTS CL for reading next bit (going from 0x40f to 0)
0000000000400380
0000000000400380 EXC = 0x40
0000000000400380 RSI = 0 -> read char "0"
0000000000400380 rax = x
0000000000400380 mov rax, [rdi] ; x = DEADFACEDEADBEEF
0000000000400383 rol rax, cl ; x <<< cl -> ror rax of cl
0000000000400386
0000000000400386 setting the LSB to 0
0000000000400386 eg.
0000000000400386
0000000000400386 01111 -> initial LSB = 1
0000000000400386 shr 1 -> 00111
0000000000400386 shl 1 -> 01110 -> LSB is now 0
0000000000400386
0000000000400386
0000000000400386 shr rax, 1 ; x = x/2 -> divide rax by 2^1 -> rax/2
0000000000400389 shl rax, 1 ; x = x * 2 -> multiply rax by 2^1 -> rax *2
000000000040038C ror rax, cl ; x >>> cl -> rol rax of cl
000000000040038F mov [rdi], rax ; copy x value at RDI memory location (RAX - 1)
0000000000400392 dec dword ptr [rdi+8] ; decremente x040f value
0000000000400395 jmp short loc_4003DB
0000000000400397 ; ---------------------------------------------------------------------------
0000000000400397 if RSI = 1
0000000000400397
0000000000400397 loc_400397: ; CODE XREF: f_key_generator+9↑j
0000000000400397 mov ecx, [rdi+8]
000000000040039A cmp ecx, 40h
000000000040039D jnb short f_exit ; if exc >= 0x40
000000000040039F ;Sets bit in CL position to ZERO and INCREMENTS CL for reading next bit ;(going from 0 to 0x40f)
000000000040039F
000000000040039F RSI = 1 -> read_char ("1")
000000000040039F ECX < 0x40
000000000040039F mov rax, [rdi]
00000000004003A2 inc ecx
00000000004003A4 rol rax, cl
00000000004003A7
00000000004003A7 setting the LSB to 0
00000000004003A7 eg.
00000000004003A7
00000000004003A7 01111 -> initial LSB = 1
00000000004003A7 shr 1 -> 00111
00000000004003A7 shl 1 -> 01110 -> LSB is now 0
00000000004003A7
00000000004003A7
00000000004003A7 shr rax, 1
00000000004003AA shl rax, 1
00000000004003AD ror rax, cl
00000000004003B0 mov [rdi], rax
00000000004003B3 mov [rdi+8], ecx
00000000004003B6 jmp short loc_4003DB
00000000004003B8 ; ---------------------------------------------------------------------------
00000000004003B8 RSI = 2 -> read_char("2")
00000000004003B8
00000000004003B8 loc_4003B8: ; CODE XREF: f_key_generator+E↑j
00000000004003B8 mov ecx, [rdi+8]
00000000004003BB cmp ecx, 40h
00000000004003BE jnb short f_exit
00000000004003C0 Sets bit in CL position to ONE and INCREMENTS CL for reading next bit (going from 0 to 0x40f)
00000000004003C0
00000000004003C0 RSI = 2 -> read_char ("2")
00000000004003C0 mov rax, [rdi]
00000000004003C3 inc ecx
00000000004003C5 rol rax, cl
00000000004003C8 set LSB to 1
00000000004003C8
00000000004003C8 eg.
00000000004003C8
00000000004003C8 01110 -> initial LSB = 0
00000000004003C8 shr 1 -> 00111
00000000004003C8 shl 1 -> 01110
00000000004003C8 or 1 -> 00001
00000000004003C8 -------
00000000004003C8 01111
00000000004003C8
00000000004003C8 shr rax, 1
00000000004003CB shl rax, 1
00000000004003CE or rax, 1
00000000004003D2 ror rax, cl
00000000004003D5 mov [rdi], rax
00000000004003D8 mov [rdi+8], ecx
00000000004003DB
00000000004003DB loc_4003DB: ; CODE XREF: f_key_generator+2D↑j
00000000004003DB ; f_key_generator+4E↑j
00000000004003DB xor eax, eax
00000000004003DD jmp short locret_4003E3
00000000004003DF ; ---------------------------------------------------------------------------
00000000004003DF exit
00000000004003DF
00000000004003DF f_exit: ; CODE XREF: f_key_generator+10↑j
00000000004003DF ; f_key_generator+15↑j ...
00000000004003DF or rax, 0FFFFFFFFFFFFFFFFh
00000000004003E3
00000000004003E3 locret_4003E3: ; CODE XREF: f_key_generator+75↑j
00000000004003E3 retn
00000000004003E3 f_key_generator endp
00000000004003E3
00000000004003E4
00000000004003E4 ; =============== S U B R O U T I N E =======================================
00000000004003E4
00000000004003E4
00000000004003E4 sub_4003E4 proc near ; CODE XREF: _start+64↑p
00000000004003E4
00000000004003E4 qword_x = qword ptr -38h
00000000004003E4 dword_y = dword ptr -30h
00000000004003E4
00000000004003E4 push r12
00000000004003E6 push r13
00000000004003E8 push r14
00000000004003EA push r15
00000000004003EC push rbp
00000000004003ED sub rsp, 10h
00000000004003F1 mov [rsp+38h+qword_x], rsi ; x = 0DEADFACEDEADBEEFh (QWORD)
00000000004003F5 mov [rsp+38h+dword_y], 40h ; y = 0x40(64) (DWORD)
00000000004003FD mov r12, rdi ; r12 = a -> a = fd
0000000000400400 mov r13, rdx ; r13 = b -> b = 123456701234567h
0000000000400403 mov r14, rcx ; r14 = i -> i = 80h (for loop)
0000000000400406 mov r15, r8 ; r15 = data_buff
0000000000400409 loop for 80h(128) time
0000000000400409
0000000000400409 loop_for_128_decR14: ; CODE XREF: sub_4003E4+5F↓j
0000000000400409 mov rdi, r12 ; rdi = a -> rdi = fd
000000000040040C call reads_char_file_content_
0000000000400411 mov rbp, rax ; rpb = read_char(one byte)
0000000000400414 or rax, 0FFFFFFFFFFFFFFFFh ; setting RAX with 16 bits , RAX = -1
0000000000400418 cmp rbp, rax ; check if rbp is = -1 (if thechar was read)
000000000040041B jz short loc_400449 ;
000000000040041B ; cmp dst, src ZF CF
000000000040041B ; dst = src 1 0
000000000040041B ; dst < src 0 1
000000000040041B ; dst > src 0 0
000000000040041B ;
000000000040041B ;
000000000040041B ; if (rbp != rax) then carry on ELSE exit and also return RAX = -1
000000000040041D mov rdi, r15 ; rdi = data_buff
0000000000400420 mov rsi, rbp ; rsi = x = read_char(one byte)
0000000000400423 call sub_4004F0
0000000000400428 mov rdi, rsp ; rdi = buffer
000000000040042B mov rsi, rbp ; rsi = x = read_char(one byte)
000000000040042E call f_key_generator
0000000000400433 test rax, rax ;
0000000000400433 ; set ZF to 1 if rax == 0
0000000000400433 ; IF rax == 0 carry on ELSE exit
0000000000400436 jnz short loc_400449
0000000000400438 xor eax, eax
000000000040043A cmp [rsp+38h+qword_x], r13 ;
000000000040043A ; cmp dst, src ZF CF
000000000040043A ; dst = src 1 0
000000000040043A ; dst < src 0 1
000000000040043A ; dst > src 0 0
000000000040043A ;
000000000040043A ;
000000000040043A ; if (rsp+38h+qword_x != r13(0123456701234567)) then carry on ELSE exit
000000000040043E jz short loc_400449
0000000000400440 dec r14 ; decrement i
0000000000400443 jnz short loop_for_128_decR14
0000000000400445 or rax, 0FFFFFFFFFFFFFFFFh
0000000000400449
0000000000400449 loc_400449: ; CODE XREF: sub_4003E4+37↑j
0000000000400449 ; sub_4003E4+52↑j ...
0000000000400449 add rsp, 10h
000000000040044D pop rbp
000000000040044E pop r15
0000000000400450 pop r14
0000000000400452 pop r13
0000000000400454 pop r12
0000000000400456 retn
0000000000400456 sub_4003E4 endp
0000000000400456
0000000000400457
0000000000400457 ; =============== S U B R O U T I N E =======================================
0000000000400457
0000000000400457
0000000000400457 xoring_32bitRAX_zero_buff proc near ; CODE XREF: _start+37↑p
0000000000400457 xor eax, eax
0000000000400459 mov rcx, 20h
0000000000400460 rep stosb
0000000000400462 retn
0000000000400462 xoring_32bitRAX_zero_buff endp
0000000000400462
0000000000400463
0000000000400463 ; =============== S U B R O U T I N E =======================================
0000000000400463
0000000000400463
0000000000400463 char_from_rax_dil_manipulitaion proc near
0000000000400463 ; CODE XREF: rsi_bits_modification+1F↓p
0000000000400463 ; rsi_bits_modification+33↓p
0000000000400463 movzx rax, dil ; movzx -> with Zero-Extend dil -> low 8 bit of RDI
0000000000400467 and al, 0Fh ; and AL with F (1111) / dil & 0x0f
0000000000400469 cmp al, 0Ah ; check if it's the end of buffer, hex value A (1010) = 10
0000000000400469 ; cmp if (dil & 0x0f = 0x0a)
0000000000400469 ;
0000000000400469 ; cmp (dst, src) ZF CF
0000000000400469 ; dst = src 1 0
0000000000400469 ; dst < src 0 1
0000000000400469 ; dst > src 0 0
0000000000400469 ;
0000000000400469 ; if (dil & 0x0f = 0A) -> CF 0
0000000000400469 ; if (dil & 0x0f > 0A) -> CF 0
0000000000400469 ; if (dil & 0x0f < 0A) -> CF 1
000000000040046B
000000000040046B
000000000040046B sbb dil, dil ; Destination = Destination - (Source + CF);
000000000040046B ; dil = dil - (dil + CF)
000000000040046B ; if CF = 1 -> dil = -1
000000000040046B ; if CF = 0 -> dil = 0
000000000040046B ;
000000000040046B ; if (dil & 0x0f = 0A) -> CF 0 -> dil = 0
000000000040046B ; if (dil & 0x0f > 0A) -> CF 0 -> dil = 0
000000000040046B ; if (dil & 0x0f < 0A) -> CF 1 -> dil = -1
000000000040046E not dil ; reverts bits in dil
0000000000400471
0000000000400471
0000000000400471 and dil, 7 ; if dil =-1 -> dil = 7
0000000000400471 ; if dil = 0 -> dil = 0
0000000000400475 add al, 30h ; add 30h(0) to al
0000000000400477 add al, dil ; Generating char -> al + 30h (48)("o") + 7
000000000040047A retn
000000000040047A char_from_rax_dil_manipulitaion endp
000000000040047A
|