📄 cwd-ovl.asm
字号:
mov cx,_EXCEP
mov edx,offset Exc12Handler
sys SetEVect
;
;Patch exception 13 interupt.
;
mov bl,13
sys GetEVect
test SystemFlags,1
jz @@v32_5
movzx edx,dx
@@v32_5: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldExc13+4],cx
mov d[OldExc13],edx
assume ds:DGROUP
pop ds
mov bl,13
mov cx,_EXCEP
mov edx,offset Exc13Handler
sys SetEVect
;
;Patch exception 14 interupt.
;
mov bl,14
sys GetEVect
test SystemFlags,1
jz @@v32_6
movzx edx,dx
@@v32_6: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldExc14+4],cx
mov d[OldExc14],edx
assume ds:DGROUP
pop ds
mov bl,14
mov cx,_EXCEP
mov edx,offset Exc14Handler
sys SetEVect
;
;Patch CTRL-C handler.
;
mov bl,23h
sys GetVect
test SystemFlags,1
jz @@v32_7
movzx edx,dx
@@v32_7: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldInt23+4],cx
mov d[OldInt23],edx
assume ds:DGROUP
pop ds
mov bl,23h
mov cx,_EXCEP
mov edx,offset Int23Handler
sys SetVect
;
;Patch terminate interrupt.
;
mov bl,21h
sys GetVect
test SystemFlags,1
jz @@Use32_0
movzx edx,dx
@@Use32_0: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldInt21+4],cx
mov d[OldInt21],edx
assume ds:DGROUP
pop ds
mov bl,21h
mov cx,_EXCEP
mov edx,offset Int21Handler
sys SetVect
;
;Store current vector settings to ensure a clean exit.
;
call SaveVectors
;
;Work out length of EXE file name and then open a window with "loading" message.
;
mov esi,offset EXEFileName
mov ch,0
@@escan0: lodsb
inc ch
or al,al
jnz @@escan0
cmp ch,14
jnc @@escanok
mov ch,14
@@escanok: dec ch
add ch,10+1 ;loading:
add ch,2+1 ;border etc.
mov al,ch
shr al,1
mov cl,b[VideoColumns]
shr cl,1
sub cl,al
mov bl,b[VideoRows]
shr bl,1
sub bl,(3+1)/2
mov bh,3+1
mov ax,WindowClear+WindowBox+WindowShad
mov dl,31h
mov dh,3fh
mov esi,0
mov ebp,0
call OpenWindow
mov TempHandle,bp
mov ebx,offset LoadingText
call PrintWindow
mov ebx,offset EXEFileName
call PrintWindow
;
;Ask CW32 to load target program ready for debugging.
;
mov edx,offset EXEFileName
mov esi,80h
mov es,PSPSegment
xor cx,cx
mov ax,0fffdh
int 31h
pushm ds,ds,ds
popm es,fs,gs
jnc @@6
;
;Some sort of error occured so display a message.
;
mov ErrorNumber,ax
movzx ebx,ErrorNumber
or ebx,ebx
jz @@NoE1
shl ebx,2
mov ebx,[ErrorList+ebx]
call WindowPopup
@@NoE1: mov ErrorNumber,0
mov bp,TempHandle
call CloseWindow
jmp System
;
;Setup initial register values.
;
@@6: mov DebugSegs,ebp
mov DebugCS,cx
mov OldDebugCS,cx
mov DebugEIP,edx
mov OldDebugEIP,edx
mov DebugSS,bx
mov OldDebugSS,bx
mov DebugESP,eax
mov OldDebugESP,eax
mov DebugPSP,si
mov DebugDS,di
mov OldDebugDS,di
mov DebugES,si
mov OldDebugES,si
pushfd
pop eax
mov DebugEFL,eax
mov OldDebugEFL,eax
;
;Setup a new transfer buffer to stop CWD interfering.
;
mov bx,8192/16
sys GetMemDOS
jc @@NoBigBuffer
push eax
mov bx,DebugPSP
mov ah,50h
int 21h
pop eax
mov bx,ax
mov ecx,8192
sys SetDOSTrans
mov bx,PSPSegment
mov ah,50h
int 21h
@@NoBigBuffer: ;
;
;Fetch symbols from somewhere.
;
call FetchSymbols
;
;Check if another error message is needed.
;
@@se0: movzx ebx,ErrorNumber
or ebx,ebx
jz @@NoE2
shl ebx,2
mov ebx,[ErrorList+ebx]
call WindowPopup
@@NoE2: mov ErrorNumber,0
mov bp,TempHandle
call CloseWindow
;
;Init disasembly engine.
;
mov ebx,SymbolList
call InitDisas
mov ax,DebugCS
mov DisplayCS,ax
mov DisasCS,ax
mov eax,DebugEIP
mov DisplayEIP,eax
mov DisasEIP,eax
mov DisasStartEIP,-1
mov DisasEndEIP,0
;
;Open the register display window.
;
mov cl,59+5+2
mov bl,0+1
mov ch,14
mov bh,23
mov ax,WindowClear+WindowBox+WindowStatic
mov dl,30h
mov dh,3fh
mov esi,0
mov ebp,offset RegsHandler
call OpenWindow ;open main display window.
mov RegsHandle,bp
mov ebx,offset RegsTitle
mov ax,WindowJCent+WindowBox
call TitleWindow
;
;Open the default data watch window.
;
mov al,Watch_DS ;seg type.
mov ah,Watch_Abs ;offset type.
mov ebx,0 ;offset
call OpenDataWatch
;
;Open the disasembly window.
;
mov eax,SourceTABSettings+0
add eax,4-1
mov WindowTabG1,ax
mov eax,SourceTABSettings+4
add eax,4-1
mov WindowTabG2,ax
mov eax,SourceTABSettings+8
add eax,4-1
mov WindowTabG3,ax
mov eax,SourceTABSettings+12
add eax,4-1
mov WindowTabG4,ax
mov eax,SourceTABSettings+16
add eax,4-1
mov WindowTabG5,ax
mov eax,SourceTABSettings+20
add eax,4-1
mov WindowTabG6,ax
mov eax,SourceTABSettings+24
add eax,4-1
mov WindowTabG7,ax
mov eax,SourceTABSettings+28
add eax,4-1
mov WindowTabG8,ax
mov cl,0
mov bl,0+1
mov ch,59+5+2
mov bh,23-6
mov ax,WindowClear+WindowBox+WindowStatic+WindowXOff
mov dl,30h
mov dh,3fh
mov esi,0
mov ebp,offset DisasHandler
call OpenWindow
mov DisasHandle,bp
;
;See if the default debug start point symbol is defined.
;
cmp AssemblerMode,0
jnz @@NoEntryError
cmp EntryGotoText,0
jnz @@nocseip
mov esi,offset CW_DEBUG_ENTRY_CS_EIP
call GetSymbolValue ;get the value
jc @@nocseip
push es
mov es,dx
movzx edx,es:w[ecx+4]
mov ecx,es:[ecx]
pop es
mov d[EvaluateBuffer+0],ecx
mov d[EvaluateBuffer+4],edx
mov eax,edi
mov edi,SymbolList
cmp edi,eax
jnz @@findsym
add edi,SymbolNext[edi]
mov SymbolList,edi
jmp @@gotcseip
@@findsym: mov esi,edi
add edi,SymbolNext[edi]
cmp edi,eax
jnz @@findsym
mov eax,SymbolNext[edi]
cmp eax,-1
jz @@endsym
add eax,SymbolNext[esi]
@@endsym: mov SymbolNext[esi],eax
jmp @@gotcseip
;
;See if we need to do a GOTO
;
@@nocseip: cmp EntryGotoText,0
jz @@NormalEntry
mov esi,offset EntryGotoText
mov edi,offset EvaluateBuffer
@@eg1: movsb
cmp b[esi-1],0
jnz @@eg1
mov EntryGotoOK,-1
mov VarSizeMask,0
mov VarSizeMask+4,0
call EvaluateData
jc @@NormalEntry
@@gotcseip: mov EntryGotoText,0
mov eax,d[EvaluateBuffer]
mov DisplayEIP,eax
mov ax,DebugCS
cmp d[EvaluateBuffer+4],0
jz @@eg2
mov eax,d[EvaluateBuffer+4]
@@eg2: mov DisplayCS,ax
mov bx,DisplayCS ;Need segment linear base address
sys GetSelDet
shl ecx,16
mov cx,dx
mov edx,ecx
add edx,DisplayEIP ;real linear address.
mov al,BreakType_exec
call SetBreakPoint
call CopyDebugRegs
push ax
mov al,2
call ExecuteInst
pop ax
call RelBreakPoint ;release it then.
mov ax,DebugCS
mov DisplayCS,ax
mov eax,DebugEIP
mov DisplayEIP,eax
call DisasPart
call RegisterDisplay ;Display current register values.
call UpdateWatches
;
@@NormalEntry: cmp EntryGotoText,0
jz @@NoEntryError
cmp EntryGotoOK,0
jnz @@NoEntryError
mov ebx,offset BadEntryExpresion
call WindowPopup
;
@@NoEntryError:
;
@@0: ;The main loop.
;
mov ax,Message_Control
call WindowMain
jmp @@0
Main endp
;==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
System proc near
cmp MousePresent,0
jz @@NoRelM
call MouseOFF
mov ax,0
int 33h ;reset mouse to lose event handler.
@@NoRelM: ;
call RestoreVectors
;
cmp ResetTimer,0
jz @@notimer
xor ax,ax
call LoadTimer
@@notimer: ;
push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
cmp w[OldInt23+4],0
jz @@9
mov edx,d[OldInt23]
mov cx,w[OldInt23+4]
mov bl,23h
sys SetVect
@@9: ;
cmp w[OldInt21+4],0
jz @@0
mov edx,d[OldInt21]
mov cx,w[OldInt21+4]
mov bl,21h
sys SetVect
@@0: ;
cmp w[OldInt01+4],0
jz @@10
mov cx,w[OldInt01+4]
mov edx,d[OldInt01]
mov bl,1
sys SetVect
@@10: ;
cmp w[OldEInt01+4],0
jz @@20
mov cx,w[OldEInt01+4]
mov edx,d[OldEInt01]
mov bl,1
sys SetEVect
@@20: ;
cmp w[OldEInt03+4],0
jz @@30
mov cx,w[OldEInt03+4]
mov edx,d[OldEInt03]
mov bl,3
sys SetVect
@@30: ;
cmp w[OldInt03+4],0
jz @@1
mov cx,w[OldInt03+4]
mov edx,d[OldInt03]
mov bl,3
sys SetVect
;
@@1: cmp w[OldExc12+4],0
jz @@2
mov cx,w[OldExc12+4]
mov edx,d[OldExc12]
mov bl,12
sys SetEVect
;
@@2: cmp w[OldExc13+4],0
jz @@3
mov cx,w[OldExc13+4]
mov edx,d[OldExc13]
mov bl,13
sys SetEVect
@@3: ;
cmp w[OldExc14+4],0
jz @@4
mov cx,w[OldExc14+4]
mov edx,d[OldExc14]
mov bl,14
sys SetEVect
@@4: ;
cmp w[OldInt00+4],0
jz @@8
mov cx,w[OldInt00+4]
mov edx,d[OldInt00]
mov bl,0
sys SetVect
;
@@8: assume ds:DGROUP
pop ds
cmp w[OldInt10+4],0
jz @@7
mov edx,d[OldInt10]
mov cx,w[OldInt10+4]
mov bl,10h
sys SetVect
;
@@7: cmp WindowsOpened,0
jz @@5
call CloseWindows
;
cmp MonoSwap,0
jz @@NoMono
;
mov esi,VideoUserBuffer
mov edx,[esi]
mov ecx,[esi+4]
mov bx,VideoSwapSel
sys SetSelDet32
add esi,4+4
xor edi,edi
push es
mov es,VideoSwapSel
rep_movsb
pop es
;
push es
mov ax,40h
mov es,ax
and es:b[10h],11001111b
or es:b[10h],00100000b
pop es
@@NoMono: ;
mov al,UserOldMode
xor ah,ah
int 10h
;
;Force font.
;
cmp UserOld50,0
jz @@U_Not50
mov ax,1112h
xor bx,bx
int 10h
@@U_Not50: ;
mov ebx,VideoOldUserState
mov ax,1c02h
mov cx,1+2+4
int 10h
;
mov esi,VideoOldUserBuffer
mov edx,[esi]
mov ecx,[esi+4]
mov bx,VideoSwapSel
sys SetSelDet32
add esi,4+4
xor edi,edi
push es
mov es,VideoSwapSel
rep_movsb
pop es
;
mov ah,5
mov al,UserOldPage
int 10h
@@5: ;
@@done: assume ds:nothing
cmp cs:w[OldInt31+4],0
jz @@noi31
mov edx,cs:d[OldInt31]
mov cx,cs:w[OldInt31+4]
mov bl,31h
sys SetVect
assume ds:DGROUP
;
@@noi31: assume ds:nothing
cmp cs:w[OldInt09+4],0
jz @@noi9
mov edx,cs:d[OldInt09]
mov cx,cs:w[OldInt09+4]
mov bl,9
sys SetVect
assume ds:DGROUP
@@noi9: ;
cmp SystemError,0
jz @@6
movzx edx,SystemError
mov edx,[SErrorList+edx*4]
call StringPrint
;
@@6: movzx eax,SystemError
mov ah,4ch
int 21h
System endp
;==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
;
;This should recieve ALL keyboard interrupts before anything else gets to see
;them.
;
BreakChecker proc near
pushm eax,ebx,ebp,ds
mov ax,DGROUP
mov ds,ax
inc InInt09
;
;Update the key table.
;
in al,60h ;get the scan code.
mov bl,al
and ebx,127 ;isolate scan code.
add ebx,offset KeyTable
and al,128
xor al,128
mov [ebx],al ;set key state.
;
;Check we havn't already been here.
;
cmp InInt09,2
jnc @@old
;
;Check if anything is running.
;
cmp Executing,0
jz @@old
;
;Check if our break combination is set.
;
mov ebx,offset BreakKeyList
cmp d[ebx],0 ;check if any keys in the list.
jz @@old
@@6: cmp d[ebx],0 ;End of the list?
jz @@7
mov eax,d[ebx] ;Get scan code.
cmp b[KeyTable+eax],0
jz @@old
add ebx,4
jmp @@6
;
;Check if return CS:EIP & stack belong to the program we're running.
;
@@7: pushad
test SystemFlags,1
jz @@0
movzx ebp,sp
add ebp,4+4+4+4+(4*8)+2+2+2
movzx ecx,w[ebp+2] ;return CS
movzx edx,w[ebp] ;return EIP
jmp @@1
;
@@0: mov ebp,esp
add ebp,4+4+4+4+(4*8)+4+4+4
mov ecx,d[ebp+4] ;return CS
mov edx,d[ebp]
;
@@1: push es
mov es,DebugPSP
mov ax,es:[EPSP_SegBase]
pop es
cmp cx,ax
jc @@nope
mov DebugEIP,edx
mov DebugCS,cx
;
;Want to break into the program so swollow this key press.
;
in al,61h
mov ah,al
or al,1 shl 7
out 61h,al ;say comming back.
xchg ah,al
out 61h,al ;code we got.
;
mov al,32
out 20h,al ;re-enable interupts.
;
;Swap the return address for our own.
;
test SystemFlags,1
jz @@2
movzx ebp,sp
add ebp,4+4+4+4+(4*8)+2+2+2
mov eax,offset @@3
mov w[ebp+2],cs ;return CS
mov w[ebp],ax ;return EIP
popad
popm eax,ebx,ebp,ds
iret
;
@@2: mov ebp,esp
add ebp,4+4+4+4+(4*8)+4+4+4
mov w[ebp+4],cs ;return CS
mov d[ebp],offset @@3
popad
popm eax,ebx,ebp,ds
iretd
;
;We should be running on the applications stack with the applications registers
;now.
;
@@3: pushfd
pushm eax,ebp,ds
mov ax,DGROUP
mov ds,ax
mov ebp,esp
test SystemFlags,1
jz @@4
movzx ebp,bp
@@4: mov eax,[ebp+4+4]
mov DebugEAX,eax
mov DebugEBX,ebx
mov DebugECX,ecx
mov DebugEDX,edx
mov DebugESI,esi
mov DebugEDI,edi
mov eax,[ebp+4]
mov DebugEBP,eax
mov eax,[ebp]
mov DebugDS,ax
mov DebugES,es
mov DebugFS,fs
mov DebugGS,gs
mov eax,[ebp+4+4+4]
mov DebugEFL,eax
mov DebugSS,ss
mov DebugESP,esp
add DebugESP,4+4+4+4
;
;Return to the debugger exec routine.
;
mov ax,DGROUP
mov es,ax
mov fs,ax
mov gs,ax
dec InInt09
lss esp,f[DebuggerESP]
test SystemFlags,1
jz @@5
db 66h
@@5: retf
;
@@nope: popad
;
;Pass control to the origional handler.
;
@@old: dec InInt09
popm eax,ebx,ebp,ds
assume ds:nothing
jmp cs:f[OldInt09]
assume ds:DGROUP
OldInt09 df 0
BreakChecker endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;This must be just before cwAPIpatch
;
cwIdentity db "CAUSEWAY"
cwMajorVersion db 0
cwMinorVersion db 0
;==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
;
;This intercepts get/set int 9 vector stuff and makes sure BreakChecker stays
;first in the chain. Also monitor exec calls.
;
Int31Intercept proc near
cmp ax,0205h ;Set vector?
jnz @@notset
cmp bl,9 ;INT 9?
jnz @@old
pushm eax,edx,ds
mov ax,DGROUP
mov ds,ax
test SystemFlags,1
jz @@0
movzx edx,dx
@@0: mov ds,CodeSegAlias
assume ds:_TEXT
mov d[OldInt09],edx
mov w[OldInt09+4],cx
assume ds:DGROUP
popm eax,edx,ds
jmp @@ret
;
@@notset: cmp ax,0204h ;Get vector?
jnz @@old
cmp bl,9 ;INT 9?
jnz @@old
assume ds:nothing
mov edx,cs:d[OldInt09]
mov cx,cs:w[OldInt09+4]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -