forked from AgileEhsan/winasm-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modMisc.asm
462 lines (392 loc) · 9.01 KB
/
modMisc.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
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
.386
.MODEL FLAT, STDCALL ;32 bit memory model
OPTION CASEMAP:NONE ;Case sensitive
Include WINDOWS.INC
Include gdi32.inc
Include kernel32.inc
Include user32.inc
IncludeLib user32.lib
IncludeLib kernel32.lib
IncludeLib gdi32.lib
;Structure for storing data unique to each child window
CHILDWINDOWDATA STRUCT
hEditor DWORD ?
hCombo DWORD ?
hTreeItem DWORD ?
dwTypeOfFile DWORD ?
FileName DB MAX_PATH DUP(?)
fNotOnDisk DWORD ? ;This is 1 for new files not saved on any media
fTimer DWORD ?
bSelection DWORD ? ;In NewEditorProc it is set if there is selection
;In ChildWndProc if it is set, fTimer is set so that
;in TimerUpdateProcedures the Procedure List is updated
CHILDWINDOWDATA ENDS
.CODE
;BinToDec Proc dwValue:DWORD, lpBuffer:DWORD
;
; ; -------------------------------------------------------------
; ; convert DWORD to ascii string
; ; dwValue is value to be converted
; ; lpBuffer is the address of the receiving buffer
; ; Uses: eax, ecx, edx.
; ; -------------------------------------------------------------
;
; PUSH EBX
; PUSH ESI
; PUSH EDI
;
; MOV EAX, dwValue
; MOV EDI, [lpBuffer]
;
; OR EAX,EAX
; JNZ Sign
;
; Zero:
; MOV WORD PTR [EDI],30H
; RET
;
; Sign:
; JNS Pos
; MOV BYTE PTR [EDI],'-'
; NEG EAX
; INC EDI
;
; Pos:
; MOV ECX, 3435973837
; MOV ESI, EDI
;
; .WHILE (EAX > 0)
; MOV EBX,EAX
; MUL ECX
; SHR EDX, 3
; MOV EAX,EDX
; LEA EDX,[EDX*4+EDX]
; ADD EDX,EDX
; SUB EBX,EDX
; ADD BL,'0'
; MOV [EDI],BL
; INC EDI
; .ENDW
;
; MOV BYTE PTR [EDI], 0 ; terminate the string
;
; ; We now have all the digits, but in reverse order.
;
; .WHILE (ESI < EDI)
; DEC EDI
; MOV AL, [ESI]
; MOV AH, [EDI]
; MOV [EDI], AL
; MOV [ESI], AH
; INC ESI
; .ENDW
;
; POP EDI
; POP ESI
; POP EBX
; RET
;
;BinToDec EndP
BinToDec Proc dwVal:DWORD,lpAscii:DWORD
PUSH EBX
PUSH ESI
PUSH EDI
MOV EAX,dwVal
MOV EDI,lpAscii
OR EAX,EAX
JNS pos
MOV BYTE PTR [EDI],'-'
NEG EAX
INC EDI
pos:
MOV ECX,429496730
MOV ESI,EDI
@@:
MOV EBX,EAX
MUL ECX
MOV EAX,EDX
LEA EDX,[EDX*4+EDX]
ADD EDX,EDX
SUB EBX,EDX
ADD BL,'0'
MOV [EDI],BL
INC EDI
OR EAX,EAX
JNE @B
MOV BYTE PTR [EDI],AL
.While ESI<EDI
DEC EDI
MOV AL,[ESI]
MOV AH,[EDI]
MOV [EDI],AL
MOV [ESI],AH
INC ESI
.EndW
POP EDI
POP ESI
POP EBX
RET
BinToDec EndP
IsThereSuchAClass Proc lpClassName:DWORD
Local wc:WNDCLASSEX
Invoke GetClassInfoEx,NULL,lpClassName,ADDR wc
RET
IsThereSuchAClass EndP
ReplaceBackSlashWithSlash Proc lpString:DWORD
MOV EAX,lpString
.While BYTE PTR [EAX]!=0
.If BYTE PTR [EAX]=="\"
MOV BYTE PTR [EAX],"/"
.EndIf
INC EAX
.EndW
RET
ReplaceBackSlashWithSlash EndP
;Delete all Files in the specified directory
DeleteFiles Proc lpPath:DWORD, lpFindString:DWORD
Local FindFileData :WIN32_FIND_DATA
Local hFindFile :HANDLE
Local Buffer[256] :BYTE
Invoke lstrcpy, ADDR Buffer, lpPath
Invoke lstrcat, ADDR Buffer, lpFindString
Invoke FindFirstFile,ADDR Buffer,ADDR FindFileData
MOV hFindFile, EAX
.If hFindFile!=INVALID_HANDLE_VALUE
Invoke lstrcpy, ADDR Buffer, lpPath
Invoke lstrcat, ADDR Buffer, ADDR FindFileData.cFileName
Invoke DeleteFile, ADDR Buffer
@@:
Invoke FindNextFile, hFindFile, ADDR FindFileData
.If EAX!=0
Invoke lstrcpy, ADDR Buffer, lpPath
Invoke lstrcat, ADDR Buffer, ADDR FindFileData.cFileName
Invoke DeleteFile, ADDR Buffer
JMP @B
.EndIf
.EndIf
Invoke FindClose, hFindFile
RET
DeleteFiles EndP
;fCaseChange=0 To Upper Case
;fCaseChange=1 To Lower Case
;fCaseChange=2 Toggle Case
ChangeCase Proc Uses EBX hChild:HWND, fCaseChange:DWORD
Local chrg :CHARRANGE
Local hMem :DWORD
Invoke GetWindowLong,hChild,0
MOV EBX,CHILDWINDOWDATA.hEditor[EAX]
Invoke SendMessage,EBX,EM_EXGETSEL,0,addr chrg
;Get size
MOV EAX,chrg.cpMax
SUB EAX,chrg.cpMin
;Allow room for terminating zero
INC EAX
;Allocate memory for the selected text
Invoke GlobalAlloc,GMEM_FIXED or GMEM_ZEROINIT,EAX
MOV hMem,EAX
Invoke GlobalLock,hMem
;Get the selected text
Invoke SendMessage,EBX,EM_GETSELTEXT,0,hMem
PUSH EDI
;Start
MOV EDI,hMem
@@:
MOV AL,[EDI]
.If AL>='A' && AL<='Z'
.If fCaseChange
OR BYTE PTR [EDI],20h
.EndIf
.ElseIf AL>='a' && AL<='z' && fCaseChange!=1
AND BYTE PTR [EDI],5Fh
.EndIf
INC EDI
OR AL,AL
JNE @B
POP EDI
;Replace selected text
Invoke SendMessage,EBX,EM_REPLACESEL,TRUE,hMem
;Restore selection
Invoke SendMessage,EBX,EM_EXSETSEL,0,ADDR chrg
;Free the memory
Invoke GlobalUnlock,hMem
Invoke GlobalFree,hMem
RET
ChangeCase EndP
;Returns lParam of List Item
SetItemParameter Proc hList:HWND, nItem:DWORD, lParam:DWORD
Local lvi:LVITEM
PUSH nItem
POP lvi.iItem
MOV lvi.iSubItem,0
MOV lvi.imask, LVIF_PARAM
PUSH lParam
POP lvi.lParam
Invoke SendMessage,hList,LVM_SETITEM,0,ADDR lvi
RET
SetItemParameter EndP
;Returns lParam of List Item
GetItemParameter Proc hList:HWND, nItem:DWORD
Local lvi:LVITEM
PUSH nItem
POP lvi.iItem
;M2M lvi.iItem,nItem
;PUSH nSubItem
;POP lvi.iSubItem
MOV lvi.iSubItem,0
MOV lvi.imask, LVIF_PARAM
Invoke SendMessage,hList,LVM_GETITEM,0,ADDR lvi
MOV EAX,lvi.lParam
RET
GetItemParameter EndP
RemoveFileExt Proc lpFileName:DWORD
Invoke lstrlen,lpFileName
MOV EDX,lpFileName
.While EAX
DEC EAX
.If BYTE PTR [EDX+EAX]=='.'
MOV BYTE PTR [EDX+EAX],0
.Break
.EndIf
.EndW
RET
RemoveFileExt EndP
GetFilePath Proc lpFileName:DWORD, lpFilePath:DWORD
Invoke lstrcpy,lpFilePath,lpFileName
Invoke lstrlen,lpFilePath
MOV EDX,lpFilePath
.While EAX
DEC EAX
.If BYTE PTR [EDX+EAX]!='\'
;INC EAX ;i.e. leave \ in the returned string
MOV BYTE PTR [EDX+EAX],0
.Else
.Break
.EndIf
.EndW
RET
GetFilePath EndP
ClearPendingMessages Proc hWnd:HWND,wMsgFilterMin:DWORD,wMsgFilterMax:DWORD
Local msg :MSG
.While TRUE
Invoke PeekMessage,ADDR msg,hWnd,wMsgFilterMin,wMsgFilterMax,PM_REMOVE
.Break .If !EAX
.EndW
RET
ClearPendingMessages EndP
GetFileName Proc lpFullPathFileName:DWORD, lpFileName:DWORD
Invoke lstrlen, lpFullPathFileName
MOV EDX,lpFullPathFileName
.While EAX
DEC EAX
MOV CL,BYTE PTR [EDX+EAX]
.If CL=='\' || CL=='/'
ADD EAX,EDX
INC EAX
Invoke lstrcpy, lpFileName, EAX
JMP Ex
.EndIf
.EndW
Invoke lstrcpy, lpFileName, lpFullPathFileName
Ex:
RET
GetFileName EndP
GetFilesTitle Proc lpFullPathFileName:DWORD, lpFileTitle:DWORD
Invoke lstrlen, lpFullPathFileName
MOV EDX,lpFullPathFileName
.While EAX
DEC EAX
MOV CL,BYTE PTR [EDX+EAX]
.If CL=='\'
ADD EAX,EDX
INC EAX
Invoke lstrcpy, lpFileTitle, EAX
JMP Ex
.EndIf
.EndW
Invoke lstrcpy, lpFileTitle, lpFullPathFileName
Ex:
RET
GetFilesTitle EndP
DrawFocusRectangle Proc Uses EBX hWnd:HWND, lpRect:DWORD
Local hDC:HDC
MOV EBX,lpRect
Invoke GetDC,hWnd
MOV hDC,EAX
Invoke SetROP2,hDC,R2_NOTXORPEN
Invoke CreatePen,PS_DOT,1,0
PUSH EAX
Invoke SelectObject,hDC,EAX
PUSH EAX
Invoke GetStockObject,NULL_BRUSH
Invoke SelectObject,hDC,EAX
PUSH EAX
Invoke Rectangle,hDC,[EBX].RECT.left,[EBX].RECT.top,[EBX].RECT.right,[EBX].RECT.bottom
POP EAX
Invoke SelectObject,hDC,EAX
POP EAX
Invoke SelectObject,hDC,EAX
POP EAX
Invoke DeleteObject,EAX
Invoke ReleaseDC,hWnd,hDC
RET
DrawFocusRectangle EndP
;Draws a 2 pixel thick rectangle
DrawRectangle Proc Uses EBX hWnd:HWND, lpRect:DWORD
Local hDC:HDC
MOV EBX,lpRect
Invoke GetDC,hWnd
MOV hDC,EAX
Invoke GetStockObject,GRAY_BRUSH
;Invoke CreateSolidBrush,0C0C0C0h
;PUSH EAX
Invoke SelectObject,hDC,EAX
PUSH EAX
;Left Line
MOV EDX,[EBX].RECT.top
ADD EDX,2
MOV ECX,[EBX].RECT.bottom
SUB ECX,2
SUB ECX,[EBX].RECT.top
Invoke PatBlt,hDC,[EBX].RECT.left,EDX,2,ECX,PATINVERT
;Right Line
MOV EDX,[EBX].RECT.right
SUB EDX,2
MOV ECX,[EBX].RECT.top
ADD ECX,2
MOV EAX,[EBX].RECT.bottom
SUB EAX,2
SUB EAX,[EBX].RECT.top
Invoke PatBlt,hDC,EDX,ECX,2,EAX,PATINVERT
;Top Line
MOV ECX,[EBX].RECT.right
SUB ECX,[EBX].RECT.left
Invoke PatBlt,hDC,[EBX].RECT.left,[EBX].RECT.top,ECX,2,PATINVERT
;Bottom Line
MOV ECX,[EBX].RECT.left
ADD ECX,2
MOV EAX,[EBX].RECT.bottom
SUB EAX,2
MOV EDX,[EBX].RECT.right
SUB EDX,ECX
SUB EDX,2
Invoke PatBlt,hDC,ECX,EAX,EDX,2,PATINVERT
POP EAX
Invoke SelectObject,hDC,EAX
;POP EAX
;Invoke DeleteObject,eax
Invoke ReleaseDC,hWnd,hDC
RET
DrawRectangle EndP
GetTextRange Proc hEdit:DWORD, lpBuffer:DWORD, BufferSize:DWORD, lpchrg:DWORD
Local txtrange:TEXTRANGE
PUSH lpBuffer
POP txtrange.lpstrText
MOV ECX,lpchrg
PUSH [ECX].CHARRANGE.cpMin
POP txtrange.chrg.cpMin
PUSH [ECX].CHARRANGE.cpMax
POP txtrange.chrg.cpMax
Invoke SendMessage,hEdit,EM_GETTEXTRANGE,0,ADDR txtrange
RET
GetTextRange EndP
End