Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2783 clevermous 1
format PE GUI 4.0
2
section '.text' code readable executable
3
entry start
4
start:
5
	xor	ebx, ebx
6
	push	ebx	; lpParam
7
	push	400000h	; hInstance
8
	push	ebx	; hMenu
9
	push	ebx	; hWndParent
10
	push	100	; nHeight
11
	push	200	; nWidth
12
	mov	eax, 80000000h
13
	push	eax	; y
14
	push	eax	; x
15
	push	10EF0140h	; dwStyle
16
	push	WndName
17
	push	ClassName
18
	push	388h	; dwExStyle
19
	call	[CreateWindowExA]
20
	mov	edi, eax
21
	push	0Ah	; OEM_FIXED_FONT
22
	call	[GetStockObject]
23
	push	ebx
24
	push	eax
25
	push	30h	; WM_SETFONT
26
	push	edi
27
	call	[SendMessageA]
28
	call	CollectDrivesInfo
29
	push	MyWndProc
30
	push	-4	; GWL_WNDPROC
31
	push	edi
32
	call	[SetWindowLongA]
33
	mov	[OldWndProc], eax
34
	sub	esp, 20h
35
	mov	esi, esp
36
@@:
37
	push	ebx
38
	push	ebx
39
	push	ebx
40
	push	esi
41
	call	[GetMessageA]
42
	test	eax, eax
43
	jz	@f
44
	push	esi
45
	call	[TranslateMessage]
46
	push	esi
47
	call	[DispatchMessageA]
48
	jmp	@b
49
@@:
50
	add	esp, 20h
51
	ret
52
 
53
MyWndProc:
54
	push	edi
55
	mov	edi, [esp+8]
56
	cmp	dword [esp+12], 2	; WM_DESTROY
57
	jnz	@f
58
	push	0
59
	call	[PostQuitMessage]
60
@@:
61
	cmp	dword [esp+12], 219h	; WM_DEVICECHANGE
62
	jnz	w
63
	cmp	dword [esp+16], 8000h	; DBT_DEVICEARRIVAL
64
	jz	@f
65
	cmp	dword [esp+16], 8004h	; DBT_DEVICEREMOVECOMPLETE
66
	jnz	w
67
@@:
68
	call	UpdateDrivesInfo
69
w:
70
	cmp	dword [esp+12], 203h	; WM_LBUTTONDBLCLK
71
	jnz	@f
72
	push	0
73
	push	0
74
	push	188h	; LB_GETCURSEL
75
	push	edi
76
	call	[SendMessageA]
77
	cmp	eax, -1
78
	jz	@f
79
	push	n+4
80
	push	eax
81
	push	189h	; LB_GETTEXT
82
	push	edi
83
	call	[SendMessageA]
84
	mov	dword [n], '\\.\'
85
	mov	byte [n+4+aPhysicalDrive.sz], 0
86
	call	install
87
@@:
88
	pop	edi
89
	pop	eax
90
	push	[OldWndProc]
91
	push	eax
92
	jmp	[CallWindowProcA]
93
 
94
UpdateDrivesInfo:
95
	push	0
96
	push	0
97
	push	184h	; LB_RESETCONTENT
98
	push	edi
99
	call	[SendMessageA]
100
 
101
CollectDrivesInfo:
102
	xor	eax, eax
103
	mov	ecx, 32
104
	push	edi
105
	mov	edi, PhysicalDrives
106
	rep	stosd
107
	pop	edi
108
	push	esi
109
	call	[GetLogicalDrives]
110
	mov	esi, eax
111
	mov	[a], 'A'
112
l:
113
	shr	esi, 1
114
	jnc	d
115
	mov	[a+2], 0
116
	push	a
117
	call	[GetDriveTypeA]
118
; Uncomment following lines to allow hard drives
119
;	cmp	eax, 3	; DRIVE_FIXED
120
;	jz	@f
121
	cmp	eax, 2	; DRIVE_REMOVABLE
122
	jnz	d
123
@@:
124
	push	0	; hTemplateFile
125
	push	0	; dwFlagsAndAttributes
126
	push	3	; dwCreationDisposition = OPEN_EXISTING
127
	push	0	; lpSecurityAttributes
128
	push	3	; dwShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE
129
	push	0	; dwDesiredAccess
130
	push	a2
131
	call	[CreateFileA]
132
	cmp	eax, -1
133
	jz	d
134
	push	eax
135
	push	0
136
	mov	ecx, esp
137
	push	0	; lpOverlapped
138
	push	ecx	; lpBytesReturned
139
	push	12	; nOutBufferSize
140
	push	sdn	; lpOutBuffer
141
	push	0
142
	push	0
143
	push	2D1080h	; IOCTL_STORAGE_GET_DEVICE_NUMBER
144
	push	eax
145
	call	[DeviceIoControl]
146
	pop	ecx
147
	pop	edx
148
	push	eax
149
	push	edx
150
	call	[CloseHandle]
151
	pop	eax
152
	test	eax, eax
153
	jz	d	; probably it is floppy
154
	mov	eax, [sdn+4]
155
	cmp	eax, 32
156
	jae	d
157
	movzx	ecx, byte [a]
158
	sub	cl, 'A'
159
	bts	[PhysicalDrives+eax*4], ecx
160
d:
161
	inc	[a]
162
	test	esi, esi
163
	jnz	l
164
	xor	esi, esi
165
.physloop:
166
	push	esi
167
	mov	esi, [PhysicalDrives+esi*4]
168
	test	esi, esi
169
	jz	.physnext
170
	push	edi esi
171
	mov	esi, aPhysicalDrive
172
	mov	edi, n
173
@@:
174
	lodsb
175
	stosb
176
	test	al, al
177
	jnz	@b
178
	pop	esi
179
	dec	edi
180
	mov	eax, [esp+4]
181
	cmp	al, 10
182
	jb	.1dig
183
	aam
184
	add	ah, '0'
185
	mov	byte [edi], ah
186
	inc	edi
187
.1dig:
188
	add	al, '0'
189
	stosb
190
	mov	al, ':'
191
	stosb
192
	mov	cl, 'A'-1
193
.logloop:
194
	mov	al, ' '
195
	stosb
196
	mov	al, cl
197
	stosb
198
@@:
199
	inc	byte [edi-1]
200
	shr	esi, 1
201
	jnc	@b
202
	mov	cl, [edi-1]
203
	mov	al, ':'
204
	stosb
205
	mov	al, '\'
206
	stosb
207
	test	esi, esi
208
	jnz	.logloop
209
	mov	al, 0
210
	stosb
211
	pop	edi
212
	push	n
213
	push	0
214
	push	180h	; LB_ADDSTRING
215
	push	edi
216
	call	[SendMessageA]
217
.physnext:
218
	pop	esi
219
	inc	esi
220
	cmp	esi, 32
221
	jb	.physloop
222
	pop	esi
223
	ret
224
 
225
install:
226
	push	0	; hTemplateFile
227
	push	0	; dwFlagsAndAttributes
228
	push	3	; dwCreationDisposition = OPEN_EXISTING
229
	push	0	; lpSecurityAttributes
230
	push	3	; dwShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE
231
	push	0C0000000h	; dwDesiredAccess = GENERIC_READ|GENERIC_WRITE
232
	push	n
233
	call	[CreateFileA]
234
	cmp	eax, -1
235
	jnz	@f
236
deverre:
237
	push	10h
238
	push	0
239
	push	deverr
240
	push	edi
241
	call	[MessageBoxA]
242
	ret
243
@@:
244
	push	esi
245
	mov	esi, eax
246
	push	eax
247
	mov	eax, esp
248
	push	0
249
	push	eax
250
	push	512
251
	push	mbr_dev
252
	push	esi
253
	call	[ReadFile]
254
	test	eax, eax
255
	jnz	@f
256
deverrl:
257
	push	esi
258
	call	[CloseHandle]
259
	pop	eax
260
	pop	esi
261
	jmp	deverre
262
@@:
263
	push	esi edi
264
	mov	esi, mbr_new
265
	mov	edi, mbr_dev
266
	mov	ecx, 1B8h
267
	rep	movsb
268
	mov	al, [edi+6]
269
	or	al, [edi+16h]
270
	or	al, [edi+26h]
271
	or	al, [edi+36h]
272
	test	al, al
273
	js	@f
274
	or	byte [edi+6], 80h
275
@@:
276
	pop	edi esi
277
	push	0
278
	push	0
279
	push	0
280
	push	esi
281
	call	[SetFilePointer]
282
	test	eax, eax
283
	jnz	deverrl
284
	mov	eax, esp
285
	push	0
286
	push	eax
287
	push	512
288
	push	mbr_dev
289
	push	esi
290
	call	[WriteFile]
291
	test	eax, eax
292
	jz	deverrl
293
	cmp	dword [esp], 512
294
	jnz	deverrl
295
; done!
296
done_succ:
297
	push	40h
298
	push	ok
299
	push	succ
300
	push	edi
301
	call	[MessageBoxA]
302
	push	0
303
	call	[PostQuitMessage]
304
r:
305
	pop	eax
306
	push	esi
307
	call	[CloseHandle]
308
	pop	esi
309
	ret
310
 
311
section '.data' data readable writable
312
data resource from 'rsrc.res'
313
end data
314
 
315
ClassName db	'LISTBOX',0
316
WndName	db	'Select drive',0
317
deverr	db	'Cannot open physical device or device error (no administrator rights?)',0
318
ok	db	'Success',0
319
succ	db	'Standard MBR has been installed',0
320
a2	db	'\\.\'
321
a	db	'?:',0,0
322
aPhysicalDrive	db	'PhysicalDrive',0
323
.sz = $ - aPhysicalDrive
324
 
325
data import
326
macro thunk a
327
{a#_thunk:dw 0
328
db `a,0}
329
	dd	0,0,0, rva kernel32_name, rva kernel32_thunks
330
	dd	0,0,0, rva user32_name, rva user32_thunks
331
	dd	0,0,0, rva gdi32_name, rva gdi32_thunks
332
	dd	0,0,0,0,0
333
kernel32_name	db	'kernel32.dll',0
334
user32_name	db	'user32.dll',0
335
gdi32_name	db	'gdi32.dll',0
336
kernel32_thunks:
337
GetLogicalDrives	dd	rva GetLogicalDrives_thunk
338
GetDriveTypeA		dd	rva GetDriveTypeA_thunk
339
CreateFileA		dd	rva CreateFileA_thunk
340
ReadFile		dd	rva ReadFile_thunk
341
WriteFile		dd	rva WriteFile_thunk
342
SetFilePointer		dd	rva SetFilePointer_thunk
343
CloseHandle		dd	rva CloseHandle_thunk
344
DeviceIoControl		dd	rva DeviceIoControl_thunk
345
	dw	0
346
thunk GetLogicalDrives
347
thunk GetDriveTypeA
348
thunk CreateFileA
349
thunk ReadFile
350
thunk WriteFile
351
thunk SetFilePointer
352
thunk CloseHandle
353
thunk DeviceIoControl
354
user32_thunks:
355
CreateWindowExA		dd	rva CreateWindowExA_thunk
356
GetMessageA		dd	rva GetMessageA_thunk
357
TranslateMessage	dd	rva TranslateMessage_thunk
358
DispatchMessageA	dd	rva DispatchMessageA_thunk
359
PostQuitMessage		dd	rva PostQuitMessage_thunk
360
CallWindowProcA		dd	rva CallWindowProcA_thunk
361
SetWindowLongA		dd	rva SetWindowLongA_thunk
362
SendMessageA		dd	rva SendMessageA_thunk
363
MessageBoxA		dd	rva MessageBoxA_thunk
364
	dw	0
365
thunk CreateWindowExA
366
thunk GetMessageA
367
thunk TranslateMessage
368
thunk DispatchMessageA
369
thunk PostQuitMessage
370
thunk CallWindowProcA
371
thunk SetWindowLongA
372
thunk SendMessageA
373
thunk MessageBoxA
374
gdi32_thunks:
375
GetStockObject		dd	rva GetStockObject_thunk
376
	dw	0
377
thunk GetStockObject
378
end data
379
 
380
align 4
381
mbr_new:
382
	file	'mbr'
383
 
384
align 4
385
OldWndProc	dd	?
386
PhysicalDrives	rd	32
387
sdn		rd	3
388
n		rb	1024
389
mbr_dev		rb	512