forked from Plexcalibur/sizecoding-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashmem.asm
355 lines (313 loc) · 5.46 KB
/
hashmem.asm
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
[org 100h]
VERSION equ '1.3'
DEFAULTCHAR equ '.'
SEPCHAR equ ':'
pusha
push ds
push es
mov ax,0x1112
int 0x10
; print Version and registers
mov eax, 'Vers'
call printStringInEAX
mov eax, 'ion'
call printStringInEAX
mov eax, VERSION
call printStringInEAX
call printCRLF
call printRegisters
call printCRLF
; Print Byte per Chat
mov eax, '(1 '
call printStringInEAX
mov eax, 'char'
call printStringInEAX
mov eax, ' = 1'
call printStringInEAX
mov eax, 'kb)'
call printStringInEAX
call printCRLF
; print Header line
mov bx, cs
call printBX
mov ax, ' '
call printStringInEAX
mov bx, 0
mov cx, 16
loopHeader:
call printBX12Bit
add bx, 0x100
loop loopHeader
mov eax, ' las'
call printStringInEAX
mov eax, 't4By'
call printStringInEAX
mov eax, 'te'
call printStringInEAX
call printCRLF
; real start
loopOverview:
mov ds, cx
call hash64k
mov cx, ds
add cx, 0x1000
jnz loopOverview
; empty separation line
call printCRLF
; print explanation for details
mov eax, 'Deta'
call printStringInEAX
mov eax, 'ils:'
call printStringInEAX
mov eax, ' (1 '
call printStringInEAX
mov eax, 'char'
call printStringInEAX
mov eax, ' = 6'
call printStringInEAX
mov eax, '4b)'
call printStringInEAX
call printCRLF
xor cx, cx
loopDetails:
mov ds, cx
call hash64kDetails
mov cx, ds
add cx, 0x1000
jnz loopDetails
pop es
pop ds
popa
ret ; exit back to DOS
hash64kDetails:
pusha
; 4k hashes
xor si, si
mov bp, 16
loop4kHashesDetails:
mov cx, 4096
call hash
cmp al, DEFAULTCHAR
jz skipDetails
; show details for 4kb segment
sub si, 4096
mov bx, si
shr bx, 4
mov ax, ds
add bx, ax
call printBX
mov ax, ' '
call printStringInEAX
; makeHashes for 64 bytes
push bp
mov bp, 64 ; 64 chars on screen
loop64bHashes:
mov cx, 64
call hash
mov dl, al
cmp dl, DEFAULTCHAR
jnz printHashDetails
test bp, 3
jnz printHashDetails
mov dl, SEPCHAR
printHashDetails:
call printDL
dec bp
jnz loop64bHashes
call printLast4Bytes
pop bp
call printCRLF
; end of inner Loop
skipDetails:
dec bp
jnz loop4kHashesDetails
popa
ret
printLast4Bytes:
pusha
mov eax, ' '
call printStringInEAX
mov bl, [ds:si - 4]
call printBL
mov bl, [ds:si - 3]
call printBL
mov bl, [ds:si - 2]
call printBL
mov bl, [ds:si - 1]
call printBL
popa
ret
hash64k:
pusha
mov bx, ds
call printBX
mov dl, ' '
call printDL
; 1k hashes
xor si, si
mov bp, 64
loop1kHashes:
mov cx, 1024
call hash
mov dl, al
cmp dl, DEFAULTCHAR
jnz printHash
test bp, 3
jnz printHash
mov dl, SEPCHAR
printHash:
call printDL
dec bp
jnz loop1kHashes
call printLast4Bytes
call printCRLF
popa
ret
hash:
xor dx, dx
xor ax, ax
xor di, di
mov bx, 37
hashLoop:
mul bx
xor ax, dx
movzx dx, byte[ds:si]
or di, dx
add ax, dx
inc si
loop hashLoop
or di, di ; was there any non-zero byte in the block?
jz defaultChar
xor al, ah
xor ah, ah
add ax, 62
modulo:
inc ax
sub ax, 62
cmp ax, 62
jae modulo
add al, '0'
cmp al, '9'
jbe endHash
add al, 'A' - '9' - 1
cmp al, 'Z'
jle endHash
add al, 'a' - 'Z' - 1
jmp endHash
defaultChar:
mov al, DEFAULTCHAR
endHash:
ret
printDL:
pusha
mov ah, 2
int 21h
popa
ret
printBXorSpaces:
or bx, bx
jnz printBX
pusha
mov eax, ':...'
call printStringInEAX
popa
ret
printBL:
pusha
mov cx, 2 ; char count to print
rol bx, 8
jmp printLoop ; reuse second part of printBX
printBX12Bit:
pusha
mov dl, '_'
call printDL
mov cx, 3 ; char count to print
rol bx, 4
jmp printLoop ; reuse second part of printBX
printBX:
pusha
mov cx, 4 ; char count to print
printLoop:
mov ah, 2
rol bx, 4
mov dl, bl
and dl, 15
add dl, '0'
cmp dl, '9'
jna skip
add dl, 7 ; "A" -> "F"
skip:
int 21h
loop printLoop
popa
ret
printRegisters:
pusha
push bx
mov bx, ax
mov ax, 'AX'
call printRegInAXBX
pop bx
mov ax, 'BX'
call printRegInAXBX
mov ax, 'CX'
mov bx, cx
call printRegInAXBX
mov ax, 'DX'
mov bx, dx
call printRegInAXBX
mov ax, 'SI'
mov bx, si
call printRegInAXBX
mov ax, 'DI'
mov bx, di
call printRegInAXBX
mov ax, 'BP'
mov bx, bp
call printRegInAXBX
mov ax, 'SP'
mov bx, sp
call printRegInAXBX
call printCRLF
mov ax, 'CS'
mov bx, cs
call printRegInAXBX
mov ax, 'DS'
mov bx, ds
call printRegInAXBX
mov ax, 'ES'
mov bx, es
call printRegInAXBX
call printCRLF
popa
ret
printRegInAXBX:
pusha
call printStringInEAX
mov dl, ':'
call printDL
call printBX
mov dl, ' '
call printDL
popa
ret
printCRLF:
pusha
mov ax, 0x0a0d
call printStringInEAX
popa
ret
printStringInEAX:
pusha
mov cx, 4
printEAXLoop:
mov dl, al
or dl, dl
jz skipEAXPrint
call printDL
skipEAXPrint:
ror eax, 8
loop printEAXLoop
popa
xor eax, eax
ret