-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.asm
290 lines (234 loc) · 6.82 KB
/
Main.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
; Template for 32 MASM assembly.
; Links to Irvine32.lib
.686
.MMX
.XMM
.model flat,stdcall
.stack 4096
option casemap:none
ifndef __UNICODE__
__UNICODE__ equ 1
endif
include C:\masm32\include\windows.inc
include C:\masm32\include\user32.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\comdlg32.inc
include C:\masm32\include\masm32.inc
include C:\masm32\include\msvcrt.inc
include C:\masm32\macros\macros.asm
includelib C:\masm32\lib\masm32.lib
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\comdlg32.lib
includelib C:\masm32\lib\gdi32.lib
includelib C:\masm32\lib\ole32.lib
includelib C:\masm32\lib\gdiplus.lib
includelib C:\masm32\lib\shlwapi.lib ; For PathRemoveFileSpec and PathCombine
includelib C:\masm32\lib\msvcrt.lib
include CFile.asm
include CSplashScreen.asm
; https://stackoverflow.com/questions/2595550/detecting-architecture-at-compile-time-from-masm-masm64
IFDEF RAX
POINTER TYPEDEF QWORD
ELSE
POINTER TYPEDEF DWORD
ENDIF
;_CloseFile PROTO :DWORD
;_OpenFile PROTO
;_Dispose PROTO :DWORD
; https://www.madwizard.org/programming/toolarchive OOP in MASM32
; https://stackoverflow.com/questions/22677608/including-files-in-assembly-80x86
; https://stackoverflow.com/questions/56506869/how-to-initialize-a-local-struct-in-masm-assembly
; http://www.asmcommunity.net/forums/topic/?id=4739
;CFile STRUCT
; Name WORD L"Z:\Visual Studio 2015\Projects\SplashScreen\ASM x86\Debug\settings.txt",0
; EndOfFile WORD 0
; handle DWORD 0
; ptrHeapText POINTER 0
; bytes DWORD 0
; CloseFile DWORD ?
; OpenFile DWORD ?
; Dispose DWORD ?
;CFile ENDS
;Splash STRUCT
; handle DWORD ?
; AppPath DWORD ?
; ImagePath DWORD ?
; TimeFadeOut DWORD ?
;Splash ENDS
.const
MAXSIZE equ 260
MEMSIZE equ 65535
.data
;UCSTR fileName, "C:\Users\Arthurit\Documents\Visual Studio 2017\Projects\SplashScreen\ASM x86\Debug\prueba.txt",0
;UCSTR fileName, "C:\Users\AlfredoA\Documents\Visual Studio 2015\Projects\SplashScreen\ASM x86\Debug\prueba2.txt",0
UCSTR fileName, "C:\Users\Arthurit\Documents\Visual Studio 2017\Projects\SplashScreen\ASM x86\Debug\settings.txt",0
fileSize LARGE_INTEGER <>
.data?
lpModuleName LPCSTR ?
CommandLine LPSTR ?
hwndEdit HWND ? ; Handle to the edit control
hFile HANDLE ? ; File handle
hMemory HANDLE ? ; handle to the allocated memory block
pMemory DWORD ? ; pointer to the allocated memory block
pMemoryW DWORD ?
SizeReadWrite DWORD ? ; number of bytes actually read or write
file DWORD ?
splash DWORD ?
nFadeoutTime DWORD ?
lpszImagePath LPCTSTR ?
lpszPrefix LPCTSTR ?
lpszAppFileName LPCTSTR ?
.code
main proc
;LOCAL file:CFile
;mov file.Dispose, OFFSET CFile_Dispose
;mov file.CloseFile, OFFSET CFile_CloseFile
;mov file.OpenFile, OFFSET CFile_OpenFile
; Create CFile instance
mov eax, SIZEOF CFile
invoke GetProcessHeap
invoke HeapAlloc, eax, NULL, SIZEOF CFile
mov file, eax
push eax
call CFile_Init
;invoke CFile_Init, eax
lea esp, [esp-4]
mov [esp], OFFSET fileName
lea esp, [esp-4]
mov eax, file
mov [esp], eax
call (CFile PTR [eax]).OpenFile
;invoke (CFile PTR [eax]).OpenFile, eax
;lea esp, [esp+4]
mov eax, file
invoke MessageBox, NULL, (CFile PTR [eax]).ptrHeapText, NULL, MB_OK
lea esp, [esp-4]
mov eax, file
mov [esp], eax
call (CFile PTR [eax]).ConvertToLine
;invoke (CFile PTR [eax]).OpenFile, eax
;lea esp, [esp+4]
salto:
lea esp, [esp-4]
mov eax, file
mov [esp], eax
call (CFile PTR [eax]).GetLine
;invoke (CFile PTR [eax]).OpenFile, eax
;lea esp, [esp+4]
.IF eax!=0
;invoke MessageBox, NULL, eax, NULL, MB_OK
mov lpszImagePath, eax
;jmp salto
.ENDIF
lea esp, [esp-4]
mov eax, file
mov [esp], eax
call (CFile PTR [eax]).GetLine
.IF eax!=0
mov lpszAppFileName, eax
.ENDIF
lea esp, [esp-4]
mov eax, file
mov [esp], eax
call (CFile PTR [eax]).GetLine
.IF eax!=0
mov nFadeoutTime, eax
.ENDIF
; Destroy CFile instance
mov eax, file
push eax
call DWORD PTR [eax]
push eax
invoke GetProcessHeap
invoke HeapFree, eax, NULL, file
pop eax
invoke GetModuleHandle,NULL
mov lpModuleName, eax
.IF (eax==NULL)
jmp exit_main
.ENDIF
; Create CSplashScreen instance
mov eax, SIZEOF CSplashScreen
invoke GetProcessHeap
invoke HeapAlloc, eax, NULL, SIZEOF CSplashScreen
mov splash, eax
push nFadeoutTime
push lpszAppFileName
push lpszImagePath
push lpModuleName
push eax
call CSplashScreen_Init
push splash
call (CSplashScreen PTR [eax]).Show
;invoke MessageBox, NULL, NULL, NULL, MB_OK
jmp exit_main
invoke CreateFile, ADDR fileName,\
GENERIC_READ or GENERIC_WRITE ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile,eax
invoke GetFileSizeEx, hFile, ADDR fileSize
mov eax, fileSize.LowPart
inc eax
mov ebx,eax
invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, eax
mov hMemory, eax
invoke GlobalLock, hMemory
mov pMemory,eax
invoke ReadFile, hFile, pMemory, fileSize.LowPart, ADDR SizeReadWrite, NULL
invoke CloseHandle,hFile
mov eax, ebx
shl eax, 1
invoke GlobalAlloc, GMEM_ZEROINIT, eax
mov pMemoryW,eax
invoke MultiByteToWideChar, CP_UTF8, 0, pMemory, -1, pMemoryW, 0
invoke MultiByteToWideChar, CP_UTF8, 0, pMemory, -1, pMemoryW, ebx
invoke MessageBox, NULL, pMemoryW, pMemory, MB_OK
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
invoke GlobalFree, pMemoryW
mov ebx, "a"
.Repeat
push ebx
print esp, " "
inc ebx
pop eax
.Until ebx>"z"
exit_main:
invoke ExitProcess,0
main endp
end main
; http://masm32.com/board/index.php?topic=6259.0
UnicodeString MACRO ansiArg, ucArg
pushad
mov esi, ansiArg
mov edi, ucArg
xor eax, eax
.Repeat
lodsb
stosw
.Until !eax
popad
EXITM <ucArg>
ENDM
; Read line by line
; http://forums.codeguru.com/showthread.php?391564-Read-line-from-a-file
; http://www.interq.or.jp/chubu/r6/masm32/tute/tute012.html
; https://www.daniweb.com/programming/software-development/threads/31282/windows-api-functions-to-read-and-write-files-in-c
; OOP in ASM
; https://stackoverflow.com/questions/7487031/how-to-invoke-a-pointer-to-a-function-in-masm
; https://zsmith.co/OOA.php
; https://archive.org/details/dr_dobbs_journal_vol_15/page/n215
; Visual Studio setup for MASM
; http://www.deconflations.com/2011/masm-assembly-in-visual-studio-2010/
; https://resources.infosecinstitute.com/assembly-programming-visual-studio-net/
; Push / pop alternativas
; https://stackoverflow.com/questions/4584089/what-is-the-function-of-the-push-pop-instructions-used-on-registers-in-x86-ass
; push reg <= same as => sub $8,%rsp # subtract 8 from rsp
; mov reg,(%rsp) # store, using rsp as the address
; lea rsp, [rsp-8]
; pop reg <= same as=> mov (%rsp),reg # load, using rsp as the address
; add $8,%rsp # add 8 to the rsp
; lea rsp, [rsp+8]