-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinter9.asm
204 lines (177 loc) · 2.7 KB
/
inter9.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
.386p
stacksg SEGMENT PARA stack 'STACK'
stack db 100h dup(?)
stacksg ENDS
datasg SEGMENT PARA USE16 'DATA'
inter9seg dw 0
inter9off dw 0
datasg ENDS
extcodesg SEGMENT PARA USE16 'CODE'
_begin = $
forwardoffset dw 0
forwardsegment dw 0
counter dw 0
outcolor db 7Ch
outputbuff db '0x1234',0
intercept PROC far
push ax
push bx
push cx
push dx
push ds
push es
push si
push di
mov ax, cs
mov ds, ax
; increase counter
mov ax, [counter]
inc ax
mov [counter], ax
; outputd
call fillBuff
push ax
mov bx, 0b800h
mov es, bx
mov bx, 148
push bx
mov bp, sp
mov cx, 6h
output:
; current index
mov ax, 6h
sub ax, cx
mov si, ax
; form symbol
mov ah, outcolor
lea bx, outputbuff
mov al, [bx+si]
mov [bp+2], ax ; save symbol
mov dh, ah
and dh, 0fh
cmp dh, 0fh
je only_one_inc
add ah, 10h
only_one_inc:
inc ah
mov outcolor, ah
; send in video
mov ax, si
shl ax, 1
mov si, ax
mov ax, [bp+2]
mov bx, [bp]
mov es:[bx+si], ax
loop output
pop bx
pop ax
; prepare stack
pushf
lea bx,[forwardoffset]
call far ptr[bx]
pop di
pop si
pop es
pop ds
pop dx
pop cx
pop bx
pop ax
iret
intercept ENDP
fillBuff PROC near
push bp
push ax
mov bp, sp
lea si, outputbuff+1
mov cx, 4h
cycle:
; get number for conversion
mov ax, [bp]
and ax, 0fh
xor ax, 30h
cmp ax, 39h
jbe end_conversion
add ax, 7h
end_conversion:
; write in buff
mov bx, cx
mov [si+bx], al
; shift number
mov bx, [bp]
shr bx, 4h
mov [bp], bx
loop cycle
pop ax
mov bp, sp
pop bp
ret
fillBuff ENDP
_end = $
_size = _end - _begin
extcodesg ENDS
codesg SEGMENT PARA USE16 'CODE'
main:
ASSUME SS:stacksg, ES:datasg, CS:codesg
mov bx, datasg
mov es, bx
xor bx, bx
mov ds, bx
; save original int 9h address
mov ax, 9h
mov bx, 4h
mul bx
mov bx, ax
mov ax, [bx]
mov [es:inter9off], ax
add bx, 2h
mov ax, [bx]
mov [es:inter9seg], ax
; write in segment variables
mov bx, seg extcodesg
mov ds, bx
mov ax, [es:inter9off]
mov [ds:forwardoffset], ax
mov ax, [es:inter9seg]
mov [ds:forwardsegment], ax
; compute rest size
mov ax, _size
test ax, 400h-1
jz e1
add ax, 400h
e1:
shr ax, 10
mov dx, ax
; write rest size
int 12h
xor bx, bx
mov ds, bx
sub ax, dx
mov bx, 413h
mov [bx], ax
; segment in memory
cld
shl ax, 6h
mov cx, seg extcodesg
mov ds, cx
xor si, si
mov es, ax
xor di, di
mov cx, _size
rep movsb
; change int 9h
xor bx, bx
mov ds, bx
mov ax, 9h
mov bx, 4h
mul bx
mov bx, ax
cli
mov [bx], offset intercept
mov [bx+2], seg extcodesg
sti
exit_from_app:
mov ax,4c00h
int 21h
codesg ENDS
END main