forked from WindowsNT/asm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vdisplay.asm
769 lines (587 loc) · 7.76 KB
/
vdisplay.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
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
disp64:
push rax
shr rax,32
call disp32
pop rax
disp32:
push rax
shr eax,16
call disp16
pop rax
disp16:
push ax
mov al,ah
call disp8
pop ax
disp8:
push ax
push cx
mov cl,4
shr al,cl
call disp4
pop cx
pop ax
disp4:
and al,0fh
cmp al,0xA
jae .hdisp4
add al,0x30
stosb
ret
.hdisp4:
sub al,0xA
add al,0x41
stosb
ret
mmhelp db 'Commands: ',0xd,0xa,' (? or h) - help',0xd,0xa,' (g) - go',0xd,0xa,' (r) - registers',0xd,0xa,' (t) - trace',0xd,0xa, ' (q) - quit',0xd,0xa, "$"
mmj db 40,0
db 50 dup (0)
show dq 4096 dup (0)
bbb2 LoadX 0,0,0,0,0,0,0
rx db "d:\dism.exe",0
guestmode:
vmr rax,0x6800 ; Guest CR0
bt rax,1
jz .noreal
mov ax,0
ret
.noreal:
mov ax,0x0100
ret
guestlinear:
call guestmode
vmr rax,0x681E ; Guest RIP
vmr rbx,0x802 ; Guest CS
shl rbx,4
add rbx,rax
mov rax,rbx
ret
bytecount dd 0
ShowDism:
push rdi
; rdi = where to store info
;mov ax,dismdata2
linear rsi,dismpos,DATA16
xor ecx,ecx
xor edx,edx
mov dx,[rsi]
mov cx,[rsi + 2]
xor rdi,rdi
mov di,cx
shl edi,4
add edi,edx
; EDI = output
push rdi
call guestlinear
; mode, 16 bit for now
; The following is bad, we must check CS selector
; but test for now
push rax
call guestmode
cmp al,01
jnz .nmx1
mov byte [rdi],32
jmp .ax1
.nmx1:
mov byte [rdi],16
.ax1:
pop rax
; Check Mode actually
; VMCALL
linear rcx,exitreason,STACK64
push rax
mov al,[rcx]
cmp al,18
pop rax
jnz .novmcall
pop rdi
pop rdi
mov rax,'vmcall';
stosq
ret; nothing
.novmcall:
push rax
mov rcx,15
mov byte [rdi + 1],15
add rdi,2
.jlpp:
mov bl,[rax]
mov [rdi],bl
inc rax
inc rdi
dec rcx
jrcxz .jlppf
jmp .jlpp
.jlppf:
; call dism.exe
mov bx,bbb2
mov dx,rx
mov bp,0x4B00
mov si,CODE64
shl esi,16
mov edi,esi
mov ax,0x421
int 0xF0
pop rax
pop rdi
mov rsi,rdi ; RSI now points to dissm bytes
pop rdi ; RDI now to output buffer
push rax
.jlp:
mov al,[rsi]
cmp al,0
jz .end
stosb
inc rsi
jmp .jlp
.end:
pop rax
; also the # of bytes
push rdi
linear rsi,dismposcount,DATA16
xor ecx,ecx
xor edx,edx
mov dx,[rsi]
mov cx,[rsi + 2]
xor rdi,rdi
mov di,cx
shl edi,4
add edi,edx
mov esi,[edi]
pop rdi
; ESI = Count of bytes to transfer
mov byte [rdi],' '
mov byte [rdi+1],'('
add rdi,2
.jb1:
cmp esi,0
jz .jb2
dec esi
push rax
mov al,[rax]
call disp8
pop rax
inc rax
jmp .jb1
.jb2:
mov byte [rdi],')'
add rdi,1
ret
ShowCRs:
;rax - rdx
mov eax,'CR0 ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'CR3 ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'CR4 ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov ax,0x0D0A
stosw
vmr rax,0x6800
call disp32
mov al,' '
stosb
vmr rax,0x6802
call disp32
mov al,' '
stosb
vmr rax,0x6804
call disp32
mov al,' '
stosb
mov ax,0x0D0A
stosw
ret
ShowSegs:
;DS
mov eax,'DS ';
stosd
mov al,' '
stosb
mov eax,'ES ';
stosd
mov al,' '
stosb
mov eax,'FS ';
stosd
mov al,' '
stosb
mov eax,'GS ';
stosd
mov al,' '
stosb
mov eax,'SS ';
stosd
mov al,' '
stosb
mov ax,0x0D0A
stosw
vmr rax,0x806
call disp16
mov al,' '
stosb
vmr rax,0x800
call disp16
mov al,' '
stosb
vmr rax,0x808
call disp16
mov al,' '
stosb
vmr rax,0x80A
call disp16
mov al,' '
stosb
vmr rax,0x804
call disp16
mov al,' '
stosb
mov ax,0x0D0A
stosw
ret
DisplayGuestMode:
call guestmode
cmp ah,0
jnz .noreal
mov eax,'RM ';
stosd
jmp .afterm
.noreal:
cmp ah,1
jnz .noprot
mov eax,'PM ';
stosd
jmp .afterm
.noprot:
.afterm:
ret
ShowRegs64:
push64
linear r15,vregs,STACK64
linear rdi,show,CODE64
cld
call ShowCRs
call ShowSegs
;rax - rdx
mov eax,'RAX ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov eax,'RBX ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov eax,'RCX ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov eax,'RDX ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov ax,0x0D0A
stosw
mov rax,[r15 + 0x00]
call disp64
mov al,' '
stosb
mov rax,[r15 + 0x08]
call disp64
mov al,' '
stosb
mov rax,[r15 + 0x10]
call disp64
mov al,' '
stosb
mov rax,[r15 + 0x18]
call disp64
mov al,' '
stosb
mov ax,0x0D0A
stosw
; RSI RDI RBP RSP
mov eax,'RSI ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov eax,'RDI ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov eax,'RBP ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov eax,'RSP ';
stosd
mov rcx,13
mov al,' '
rep stosb
mov ax,0x0D0A
stosw
mov rax,[r15 + 0x20]
call disp64
mov al,' '
stosb
mov rax,[r15 + 0x28]
call disp64
mov al,' '
stosb
mov rax,[r15 + 0x30]
call disp64
mov al,' '
stosb
vmr rax,0x681C ; Guest RSP
call disp64
mov al,' '
stosb
mov ax,0x0D0A
stosw
; Mode
call DisplayGuestMode
; RIP
mov rax,'CS:RIP ';
stosq
vmr rax,0x802 ; Guest CS
call disp16
mov al,':'
stosb
vmr rax,0x681E ; Guest RIP
call disp64
mov al,' '
stosb
mov rax,'LINEAR ';
stosq
call guestlinear
call disp64
mov al,' '
stosb
mov al,' '
stosb
call ShowDism
mov ax,0x0D0A
stosw
mov al,'$'
stosb
mov dx,show
mov si,CODE64
shl esi,16
mov ebp,0x900
mov ax,0x421
int 0xF0
pop64
ret
ShowRegs:
push64
linear r15,vregs,STACK64
linear rdi,show,CODE64
cld
call ShowCRs
call ShowSegs
;rax - rdx
mov eax,'EAX ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'EBX ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'ECX ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'EDX ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'ESI ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'EDI ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'EBP ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov eax,'ESP ';
stosd
mov rcx,5
mov al,' '
rep stosb
mov ax,0x0D0A
stosw
mov rax,[r15 + 0x00]
call disp32
mov al,' '
stosb
mov rax,[r15 + 0x08]
call disp32
mov al,' '
stosb
mov rax,[r15 + 0x10]
call disp32
mov al,' '
stosb
mov rax,[r15 + 0x18]
call disp32
mov al,' '
stosb
mov rax,[r15 + 0x20]
call disp32
mov al,' '
stosb
mov rax,[r15 + 0x28]
call disp32
mov al,' '
stosb
mov rax,[r15 + 0x30]
call disp32
mov al,' '
stosb
vmr rax,0x681C ; Guest RSP
call disp32
mov al,' '
stosb
mov ax,0x0D0A
stosw
; Mode
call DisplayGuestMode
; RIP
mov rax,'CS:EIP ';
stosq
vmr rax,0x802 ; Guest CS
call disp16
mov al,':'
stosb
vmr rax,0x681E ; Guest RIP
call disp32
mov al,' '
stosb
mov rax,'LINEAR ';
stosq
call guestlinear
call disp32
mov al,' '
stosb
mov al,' '
stosb
call ShowDism
mov ax,0x0D0A
stosw
mov al,'$'
stosb
mov dx,show
mov si,CODE64
shl esi,16
mov ebp,0x900
mov ax,0x421
int 0xF0
pop64
ret
ShowPrompt:
push64
linear rdi,show,CODE64
cld
mov ax,0x0D0A
stosw
mov al,'*'
stosb
mov al,' '
stosb
mov al,'$'
stosb
mov dx,show
mov si,CODE64
shl esi,16
mov ebp,0x900
mov ax,0x421
int 0xF0
pop64
ret
WaitForInput:
call ShowPrompt
mov dx,mmj
mov si,CODE64
shl esi,16
mov ebp,0xa00
mov ax,0x421
int 0xF0
linear rdx,mmj,CODE64
mov al,[rdx + 1]
cmp al,0 ; nothing entered?
jz WaitForInput
; Single Byte Commands
cmp byte [rdx + 2],'?'
jz .CmdHelp
cmp byte [rdx + 2],'h'
jz .CmdHelp
cmp byte [rdx + 2],'r'
jz .CmdRegs
cmp byte [rdx + 2],'g'
jz .CmdGo
cmp byte [rdx + 2],'t'
jz .CmdTrace
cmp byte [rdx + 2],'q'
jz .CmdQuit
jmp WaitForInput
.CmdRegs:
call ShowRegs
jmp WaitForInput
.CmdHelp:
mov dx,mmhelp
mov si,CODE64
shl esi,16
mov ebp,0x900
mov ax,0x421
int 0xF0
jmp WaitForInput
.CmdGo:
; Clear Trap
vmw32 0x4004,0x0 ; trap exception 0x06
vmr rax,0x6820
btr rax,8
vmw64 0x6820,rax
jmp .InputEnd
.CmdTrace:
; Set Trap
vmw32 0x4004,0x2 ; trap exception 0x06 and 0x01
vmr rax,0x6820
bts rax,8
vmw64 0x6820,rax
jmp .InputEnd
.CmdQuit:
; Abort all
jmp VmFinalCall
.InputEnd:
ret
ShowDisplay:
call ShowRegs
call WaitForInput
ret