-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPublic.inc
864 lines (811 loc) · 20 KB
/
Public.inc
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
;----------------------------------------------------------------------------------------
; Public Masm32 Library
;
; Copyright 2007 Veria Kalantary
; https://github.com/veriak
;
;----------------------------------------------------------------------------------------
method0Proto typedef proto :DWORD
method1Proto typedef proto :DWORD
method2Proto typedef proto :DWORD, :DWORD
method3Proto typedef proto :DWORD, :DWORD, :DWORD
method4Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD
method5Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method6Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method7Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method8Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method9Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method10Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method11Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method12Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method13Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method14Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method15Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method16Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method17Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method18Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method19Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method20Proto typedef proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
method0 typedef ptr method0Proto
method1 typedef ptr method1Proto
method2 typedef ptr method2Proto
method3 typedef ptr method3Proto
method4 typedef ptr method4Proto
method5 typedef ptr method5Proto
method6 typedef ptr method6Proto
method7 typedef ptr method7Proto
method8 typedef ptr method8Proto
method9 typedef ptr method9Proto
method10 typedef ptr method10Proto
method11 typedef ptr method11Proto
method12 typedef ptr method12Proto
method13 typedef ptr method13Proto
method14 typedef ptr method14Proto
method15 typedef ptr method15Proto
method16 typedef ptr method16Proto
method17 typedef ptr method17Proto
method18 typedef ptr method18Proto
method19 typedef ptr method19Proto
method20 typedef ptr method20Proto
LPPCSTR typedef ptr LPCSTR
PVARIANT typedef ptr VARIANT
HRESULT typedef DWORD
memcpy PROTO :DWORD, :DWORD, :DWORD
memset PROTO :DWORD, :BYTE, :DWORD
memcmp PROTO :DWORD, :DWORD, :DWORD
stol PROTO :DWORD, :DWORD, :BYTE
Swap16 PROTO :WORD
Swap32 PROTO :DWORD
lstrAllocAndCpy PROTO :LPPCSTR, :LPCSTR
lstrcpyCRLF PROTO :LPCSTR, :LPCSTR
lstrcatCRLF PROTO :LPCSTR, :LPCSTR
ShowMessage PROTO :LPCSTR
ShowErrorMessage PROTO :HANDLE
CompareStructVar PROTO :DWORD, :DWORD, :DWORD
StrToBstr PROTO :LPCSTR
BstrToStr PROTO :BSTR
FreeBstr PROTO :DWORD
BstrStrCmp PROTO :BSTR, :LPCSTR
SetLength PROTO :DWORD, :DWORD, :DWORD
StrCmp PROTO :LPCSTR, :LPCSTR, :DWORD
StrPos PROTO :LPCSTR, :LPCSTR
DeleteStr PROTO :LPCSTR, :DWORD, :DWORD
CopyStr PROTO :LPCSTR, :LPCSTR, :DWORD, :DWORD
ByteToStr PROTO :DWORD, :DWORD, :LPCSTR
HexStr PROTO :DWORD, :DWORD
Swap PROTO :DWORD, :DWORD
ReversHexStr PROTO :DWORD, :DWORD
Hex2WideStr PROTO :DWORD, :DWORD
NumToStr PROTO :DWORD, :DWORD
memshift PROTO :DWORD, :DWORD, :DWORD, :DWORD
MinMaxElementSearch PROTO :DWORD, :DWORD, :DWORD, :DWORD
WriteFileCRLF PROTO :HANDLE, :DWORD
Rand PROTO :DWORD, :DWORD
LogErrorMessage PROTO :LPCSTR, :LPCSTR
HandlesList struct
dwHandlesCount dd ?
pHandles dd ?
HandlesList ends
.const
szCR db 13, 0
szLF db 10, 0
szCRLF db 13, 10, 0
szDot db ".", 0
szVirgol db ",", 0
.data?
seh dd 6 dup (?)
.code
memcpy proc uses ecx esi edi ptrSrc:DWORD, ptrDest:DWORD, dwSize:DWORD
mov ecx, dwSize
mov esi, ptrSrc
mov edi, ptrDest
cld
rep movsb
ret
memcpy endp
memset proc uses ecx edi pMem:DWORD, dwVal:BYTE, dwSize:DWORD
mov edi, pMem
mov al, dwVal
mov ecx, dwSize
cld
rep stosb
ret
memset endp
memcmp proc uses esi edi ecx p1:DWORD, p2:DWORD, dwSize:DWORD
mov esi, p1
mov edi, p2
mov ecx, dwSize
repz cmpsb
jz @F
mov eax, 1
ret
@@:
mov eax, 0
ret
memcmp endp
stol proc uses ebx ecx edi lpMem:DWORD, dwSize:DWORD, chr:BYTE
mov edi, lpMem
mov ebx, edi
mov al, 0
mov ecx, dwSize
repne scasb
std
mov al, chr
mov ecx, edi
sub ecx, ebx
repne scasb
inc edi
cld
mov eax, edi
ret
stol endp
Swap16 proc uses ebx s:WORD
xor eax, eax
mov ax, s
and ax, 00FFh
shl eax, 8
xor ebx, ebx
mov bx, s
shr bx, 8
and bx, 00FFh
or ax, bx
ret
Swap16 endp
Swap32 proc uses ebx s:DWORD
xor eax, eax
mov eax, s
and eax, 0FF000000h
shr eax, 24
xor ebx, ebx
mov ebx, s
and ebx, 00FF0000h
shr ebx, 8
or eax, ebx
mov ebx, s
and ebx, 0000FF00h
shl ebx, 8
or eax, ebx
mov ebx, s
and ebx, 000000FFh
shl ebx, 24
or eax, ebx
ret
Swap32 endp
lstrcpyCRLF proc lpString1:LPCSTR, lpString2:LPCSTR
invoke lstrcpy, lpString1, lpString2
invoke lstrcat, lpString1, addr szCRLF
ret
lstrcpyCRLF endp
lstrcatCRLF proc lpString1:LPCSTR, lpString2:LPCSTR
invoke lstrcat, lpString1, lpString2
invoke lstrcat, lpString1, addr szCRLF
ret
lstrcatCRLF endp
lstrAllocAndCpy proc lppszDest:LPPCSTR, lpszSrc:LPCSTR
invoke lstrlen, lpszSrc
invoke GlobalAlloc, GPTR, eax
mov ebx, lppszDest
mov [ebx], eax
invoke lstrcpy, dword ptr [ebx], lpszSrc
ret
lstrAllocAndCpy endp
ShowMessage proc lpMessage:LPSTR
pushad
invoke MessageBox, 0, lpMessage, StrM("Information"), MB_OK or MB_ICONINFORMATION
popad
ret
ShowMessage endp
ShowErrorMessage proc uses ebx ecx edx hDlg:DWORD
LOCAL pErrorMessage: DWORD
invoke GetLastError
mov ebx, eax
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, NULL, ebx,\
0, addr pErrorMessage, 0, 0
invoke MessageBox, hDlg, pErrorMessage, NULL, MB_OK
invoke LocalFree, pErrorMessage
ret
ShowErrorMessage endp
CompareStructVar proc uses esi edi ecx pStructVarA: DWORD, pStructVarB: DWORD, dwSize: DWORD
mov esi, pStructVarA
mov edi, pStructVarB
mov ecx, dwSize
@@:
mov eax, dword ptr [esi]
add esi, 4
sub eax, dword ptr [edi]
jnz @F
add edi, 4
sub ecx, 4
cmp ecx, 0
jne @B
xor eax, eax
@@:
ret
CompareStructVar endp
StrToBstr proc uses ecx edx lpStrBuff:LPCSTR
LOCAL bstr: DWORD
LOCAL dwBuffSize: DWORD
invoke lstrlen, lpStrBuff
.if eax
shl eax, 1
mov dwBuffSize, eax
inc eax
invoke SysAllocStringByteLen, 0, eax
mov bstr, eax
invoke MultiByteToWideChar, CP_ACP, 0, lpStrBuff, -1, bstr, dwBuffSize
mov eax, bstr
.endif
ret
StrToBstr endp
BstrToStr proc uses ecx edx bs:BSTR
LOCAL pszBuff: DWORD
LOCAL lenBuff: DWORD
invoke WideCharToMultiByte, CP_ACP, 0, bs, -1, pszBuff, 0, NULL, NULL
.if eax > 0
mov lenBuff, eax
invoke GlobalAlloc, GPTR, eax
mov pszBuff, eax
invoke WideCharToMultiByte, CP_ACP, 0, bs, -1, pszBuff, lenBuff, NULL, NULL
mov eax, pszBuff
.endif
ret
BstrToStr endp
FreeBstr proc uses ecx edx pBstr:DWORD
mov eax, pBstr
mov eax, [eax]
invoke SysFreeString, eax
mov eax, pBstr
m2m [eax], NULL
ret
FreeBstr endp
BstrStrCmp proc uses ebx pbstr1:BSTR, lpstr:LPCSTR
LOCAL bstr2: BSTR
invoke StrToBstr, lpstr
mov bstr2, eax
mov ebx, pbstr1
invoke lstrcmpW, dword ptr [ebx], bstr2
push eax
invoke FreeBstr, pbstr1
invoke FreeBstr, addr bstr2
pop eax
ret
BstrStrCmp endp
SetLength proc uses ebx ecx edx ppBuff:DWORD, dwElementSize:DWORD, dwCount:DWORD
LOCAL hHeap: DWORD
LOCAL dwSize: DWORD
LOCAL pBuff: DWORD
invoke GetProcessHeap
mov hHeap, eax
mov ebx, ppBuff
m2m pBuff, dword ptr [ebx]
.if dwCount == 0
invoke HeapFree, hHeap, NULL, pBuff
mov dword ptr [ebx], NULL
.else
mov eax, dwCount
mul dwElementSize
mov dwSize, eax
.if pBuff == NULL
invoke HeapAlloc, hHeap, HEAP_ZERO_MEMORY, dwSize
.else
invoke HeapReAlloc, hHeap, HEAP_ZERO_MEMORY, pBuff, dwSize
.endif
mov [ebx], eax
.endif
ret
SetLength endp
StrCmp proc uses ecx esi edi pString1:LPCSTR, pString2:LPCSTR, dwCmpLen:DWORD
mov esi, pString1
mov edi, pString2
mov ecx, dwCmpLen
repz cmpsb
jz @F
mov eax, 1
ret
@@:
mov eax, 0
ret
StrCmp endp
PosStr proc uses ebx ecx edx esi edi _pStr:LPCSTR, _pSubStr:LPCSTR
LOCAL pStr: LPVOID
LOCAL pSubStr: LPVOID
LOCAL dwStrLen: DWORD
LOCAL dwSubStrLen: DWORD
invoke lstrlen, _pStr
mov dwStrLen, eax
inc eax
invoke GlobalAlloc, GPTR, eax
mov pStr, eax
invoke lstrlen, _pSubStr
mov dwSubStrLen, eax
inc eax
invoke GlobalAlloc, GPTR, eax
mov pSubStr, eax
mov esi, _pStr
mov edi, pStr
xor ecx, ecx
.while ecx < dwStrLen
mov al, byte ptr [esi]
.if al >= 'A'
.if al <= 'Z'
add al, 32
.endif
.endif
mov byte ptr [edi], al
inc ecx
inc esi
inc edi
.endw
mov esi, _pSubStr
mov edi, pSubStr
xor ecx, ecx
.while ecx < dwSubStrLen
mov al, byte ptr [esi]
.if al >= 'A'
.if al <= 'Z'
add al, 32
.endif
.endif
mov byte ptr [edi], al
inc ecx
inc esi
inc edi
.endw
xor ecx, ecx
mov esi, pStr
dec esi
dec esi
@@Next:
inc esi
inc ecx
.if ecx <= dwStrLen
xor edx, edx
mov edi, pSubStr
dec edi
@@Scan:
inc edx
.if edx <= dwSubStrLen
mov al, [esi + edx]
mov bl, [edi + edx]
.if al == bl
.if edx == dwSubStrLen
mov ebx, ecx
jmp @@Exit
.else
jmp @@Scan
.endif
.else
jmp @@Next
.endif
.else
jmp @@Next
.endif
.else
xor ebx, ebx
.endif
@@Exit:
invoke GlobalFree, pStr
invoke GlobalFree, pSubStr
mov eax, ebx
ret
PosStr endp
DeleteStr proc uses ebx esi edi pStr:LPCSTR, dwIndex:DWORD, dwCount:DWORD
LOCAL dwStrLen: DWORD
invoke lstrlen, pStr
mov dwStrLen, eax
mov ebx, dwIndex
add ebx, dwCount
dec ebx
.if (dwIndex <= eax) && (dwIndex > 0) && (ebx <= eax)
mov esi, pStr
add esi, dwIndex
dec esi
mov edi, esi
add edi, dwCount
sub dwStrLen, ebx
@@:
.if dwStrLen > 0
mov al, [edi]
mov [esi], al
inc esi
inc edi
dec dwStrLen
jmp @B
.endif
mov byte ptr [esi], 0
mov eax, pStr
.else
mov eax, 0
.endif
ret
DeleteStr endp
CopyStr proc uses ebx esi edi pDestStr:LPCSTR, pSrcStr:LPCSTR, dwIndex:DWORD, dwCount:DWORD
LOCAL dwSrcStrLen: DWORD
invoke lstrlen, pSrcStr
mov ebx, dwIndex
add ebx, dwCount
dec ebx
.if (dwIndex <= eax) && (dwIndex > 0) && (ebx <= eax)
mov esi, pSrcStr
add esi, dwIndex
dec esi
mov edi, pDestStr
mov ebx, dwCount
@@:
.if ebx > 0
mov al, [esi]
mov [edi], al
inc esi
inc edi
dec ebx
jmp @B
.endif
mov byte ptr [edi], 0
mov eax, pDestStr
.else
mov eax, 0
.endif
ret
CopyStr endp
ByteToStr proc uses ecx esi edi Len:DWORD, pArray:DWORD, pStr:LPCSTR
mov ecx, Len
mov esi, pArray
mov edi, pStr
@@:
mov al, byte ptr [esi]
and al, 0F0h
shr al, 4
.if al <= 9
add al, "0"
mov byte ptr [edi], al
.else
sub al, 10
add al, "A"
mov byte ptr [edi], al
.endif
inc edi
mov al, byte ptr [esi]
and al, 0Fh
.if al <= 9
add al,"0"
mov byte ptr [edi], al
.else
sub al, 10
add al, "A"
mov byte ptr [edi], al
.endif
inc edi
inc esi
dec ecx
cmp ecx, 0
jnz @B
mov byte ptr [edi], 0
xor eax, eax
ret
ByteToStr endp
HexStr proc uses esi edi ecx edx pstr:DWORD, pstrlen:DWORD
mov eax, pstrlen
mov ecx, 2
mul ecx
inc eax
invoke GlobalAlloc, GPTR, eax
mov edi, eax
mov esi, pstr
push edi
WriteHex:
xor eax, eax
lodsb
invoke wsprintf, edi, StrM('%02X'), eax
add edi, 2
dec pstrlen
jnz WriteHex
pop eax
ret
HexStr endp
ReversHexStr proc uses esi edi ebx ecx edx pstr:DWORD, pstrlen:DWORD
LOCAL temp[2]:BYTE
LOCAL flag:DWORD
mov eax, pstrlen
mov cl, 2
div cl
inc eax
invoke GlobalAlloc, GPTR, eax
mov edi, eax
mov esi, pstr
push edi
mov flag, 0
WriteStr:
xor eax, eax
lodsb
mov temp[0], al
mov temp[1], 0
cmp al, 'A'
jne BB
mov al, 0Ah
jmp @F
BB:
cmp al, 'B'
jne CC
mov al, 0Bh
jmp @F
CC:
cmp al, 'C'
jne @DD
mov al, 0Ch
jmp @F
@DD:
cmp al, 'D'
jne EE
mov al, 0Dh
jmp @F
EE:
cmp al, 'E'
jne FF
mov al, 0Eh
jmp @F
FF:
cmp al, 'F'
jne @NO
mov al, 0Fh
jmp @F
@NO:
invoke atodw, addr temp
@@:
cmp flag, 1
je @F
inc flag
mov bl, al
jmp WriteStr
@@:
mov flag, 0
shl bl, 4
or al, bl
mov byte ptr [edi], al
inc edi
dec pstrlen
dec pstrlen
jnz WriteStr
pop eax
ret
ReversHexStr endp
Hex2WideStr proc uses esi edi ebx ecx pstr:DWORD, pdestlen:DWORD
LOCAL temp[2]:BYTE
LOCAL flag:DWORD
LOCAL pstrlen:DWORD
invoke lstrlen, pstr
mov pstrlen, eax
mov cl, 2
div cl
inc eax
invoke GlobalAlloc, GPTR, eax
mov edi, eax
mov esi, pstr
push edi
mov flag, 0
xor ebx, ebx
WriteStr:
xor eax, eax
lodsb
mov temp[0], al
mov temp[1], 0
cmp al, 'A'
jne BB
mov al, 0Ah
jmp @F
BB:
cmp al, 'B'
jne CC
mov al, 0Bh
jmp @F
CC:
cmp al, 'C'
jne @DD
mov al, 0Ch
jmp @F
@DD:
cmp al, 'D'
jne EE
mov al, 0Dh
jmp @F
EE:
cmp al, 'E'
jne FF
mov al, 0Eh
jmp @F
FF:
cmp al, 'F'
jne @NO
mov al, 0Fh
jmp @F
@NO:
invoke atodw, addr temp
@@:
shl bx, 4
or bx, ax
inc flag
cmp flag, 4
je @F
jmp WriteStr
@@:
mov word ptr [edi], bx
xor ebx, ebx
mov flag, 0
add edi, 2
sub pstrlen, 4
jnz WriteStr
pop eax
mov esi, eax
sub edi, esi
push pdestlen
pop ebx
mov dword ptr [ebx], edi
ret
Hex2WideStr endp
Swap proc uses esi ecx edx ebx lpBuff:DWORD, dwLen:DWORD
mov ecx, dwLen
mov edx, eax
xor edx, edx
mov esi, lpBuff
@@:
mov bl, byte ptr [esi]
inc esi
mov bh, byte ptr [esi]
dec esi
mov byte ptr [esi], bh
inc esi
mov byte ptr [esi], bl
add edx, 2
.if edx < ecx
inc esi
jmp @B
.endif
ret
Swap ENDP
NumToStr proc dwNum:DWORD, lpBuff:DWORD
local tmpNum[32]:BYTE
local nf:NUMBERFMT
invoke wsprintf, addr tmpNum, StrM("%u"), dwNum
and nf.NumDigits, 0
and nf.LeadingZero, FALSE
mov nf.Grouping, 3
mov nf.lpDecimalSep, offset szDot
mov nf.lpThousandSep, offset szVirgol
and nf.NegativeOrder, 0
invoke GetNumberFormat, LOCALE_USER_DEFAULT, 0, addr tmpNum, addr nf, lpBuff, 32
ret
NumToStr endp
memshift proc uses esi edi ebx ecx edx lpBuff:DWORD, dwBuffSize:DWORD, dwElementsSize:DWORD, dwShiftDir:DWORD
LOCAL lpTempBuff: DWORD
LOCAL dwi: DWORD
invoke GlobalAlloc, GPTR, dwBuffSize
mov lpTempBuff, eax
invoke memcpy, lpBuff, lpTempBuff, dwBuffSize
mov esi, lpTempBuff
mov edi, lpBuff
mov ebx, edi
.if !dwShiftDir
add edi, dwElementsSize
.else
add ebx, dwBuffSize
sub ebx, dwElementsSize
add esi, dwElementsSize
.endif
.if dwElementsSize == 1
mov BYTE ptr [ebx], 0
.elseif dwElementsSize == 2
mov WORD ptr [ebx], 0
.elseif dwElementsSize == 4
mov DWORD ptr [ebx], 0
.endif
mov eax, dwBuffSize
xor edx, edx
mov ebx, dwElementsSize
div ebx
dec eax
mov dwi, eax
.while dwi > 0
.if dwElementsSize == 1
mov al, BYTE ptr [esi]
mov BYTE ptr [edi], al
.elseif dwElementsSize == 2
mov ax, WORD ptr [esi]
mov WORD ptr [edi], ax
.elseif dwElementsSize == 4
mov eax, DWORD ptr [esi]
mov DWORD ptr [edi], eax
.endif
add esi, dwElementsSize
add edi, dwElementsSize
dec dwi
.endw
invoke GlobalFree, lpTempBuff
ret
memshift endp
MinMaxElementSearch proc uses esi ebx edx lpBuff:DWORD, dwBuffSize:DWORD, dwElementsSize:DWORD, dwFlag:DWORD
LOCAL dwi: DWORD
xor edx, edx
mov eax, dwBuffSize
mov ebx, dwElementsSize
div ebx
mov dwi, eax
dec dwi
xor eax, eax
mov esi, lpBuff
.if dwElementsSize == 1
mov al, byte ptr [esi]
.elseif dwElementsSize == 2
mov ax, word ptr [esi]
.elseif dwElementsSize == 4
mov eax, dword ptr [esi]
.endif
xor ebx, ebx
.while dwi > 0
add esi, dwElementsSize
.if dwElementsSize == 1
mov bl, byte ptr [esi]
.elseif dwElementsSize == 2
mov bx, word ptr [esi]
.elseif dwElementsSize == 4
mov ebx, dword ptr [esi]
.endif
.if dwFlag
.if ebx > eax
mov eax, ebx
.endif
.else
.if ebx < eax
mov eax, ebx
.endif
.endif
dec dwi
.endw
ret
MinMaxElementSearch endp
WriteFileCRLF proc hFile:HANDLE, lpBuff:DWORD
LOCAL dwByteCount: DWORD
invoke lstrlen, lpBuff
mov ebx, eax
invoke WriteFile, hFile, lpBuff, ebx, addr dwByteCount, 0
invoke WriteFile, hFile, addr szCRLF, 2, addr dwByteCount, 0
ret
WriteFileCRLF endp
Rand proc uses ecx edx first:DWORD, second:DWORD
invoke GetTickCount
mov ecx, 23
mul ecx
add eax, 7
mov ecx, second
sub ecx, first
inc ecx
xor edx, edx
div ecx
add edx, first
mov eax, edx
ret
Rand endp
LogErrorMessage proc uses ebx ecx edx esi edi lpszAppName:LPCSTR, lpszMessage:LPCSTR
LOCAL tempbuff[512]: BYTE
LOCAL pErrorMessage: DWORD
LOCAL Strings[2]: DWORD
LOCAL hEventSrc: HANDLE
invoke GetLastError
mov ebx, eax
invoke wsprintf, addr tempbuff, StrM("%s error: %d"), lpszAppName, ebx
invoke FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, NULL, ebx,\
0, addr pErrorMessage, 0, 0
invoke lstrcat, addr tempbuff, pErrorMessage
invoke LocalFree, pErrorMessage
invoke RegisterEventSource, NULL, lpszAppName
.if eax
mov hEventSrc, eax
lea ebx, Strings
lea eax, tempbuff
mov (dword ptr [ebx]), eax
add ebx, sizeof DWORD
m2m (dword ptr [ebx]), lpszMessage
invoke ReportEvent, hEventSrc, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 2, 0, addr Strings, NULL
invoke DeregisterEventSource, hEventSrc
.endif
ret
LogErrorMessage endp