Skip to content

Commit

Permalink
Implement variable definition.
Browse files Browse the repository at this point in the history
Implement function call.
Implement label defintion.
  • Loading branch information
charlesbetros committed Apr 14, 2019
1 parent fcab998 commit a176159
Show file tree
Hide file tree
Showing 43 changed files with 3,203 additions and 31 deletions.
11 changes: 11 additions & 0 deletions playground/AsmBreak.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
; Location where INT3 has been injected.
; 0 if no INT3 is active.
; var AsmBreakEIP
DebugStub_AsmBreakEIP dd 0

; Old byte before INT3 was injected.
; Only 1 byte is used.
; var AsmOrigByte
DebugStub_AsmOrigByte dd 0

; function DoAsmBreak {
DebugStub_DoAsmBreak:
; Since our Int3 is temp, we need to adjust return EIP to return to it, not after it.
; ESI = .CallerESP
Mov ESI, DWORD [DebugStub_Var_CallerESP]
Expand All @@ -18,13 +21,18 @@
Mov DWORD [ESI - 12], EAX

; ClearAsmBreak()
Call DebugStub_ClearAsmBreak
; Break()
Call DebugStub_Break
; }

; function SetAsmBreak {
DebugStub_SetAsmBreak:
; ClearAsmBreak()
Call DebugStub_ClearAsmBreak

; ComReadEAX()
Call DebugStub_ComReadEAX
; Save EIP of the break
; .AsmBreakEIP = EAX
Mov DWORD [DebugStub_Var_AsmBreakEIP], EAX
Expand All @@ -46,6 +54,7 @@
; }

; function ClearAsmBreak {
DebugStub_ClearAsmBreak:
; EDI = .AsmBreakEIP
Mov EDI, DWORD [DebugStub_Var_AsmBreakEIP]
; If 0, we don't need to clear an older one.
Expand All @@ -62,6 +71,7 @@
; }

; function SetINT1_TrapFLAG {
DebugStub_SetINT1_TrapFLAG:
; Push EAX to make sure whatever we do below doesn't affect code afterwards
; +EBP
Push EBP
Expand Down Expand Up @@ -93,6 +103,7 @@
; }

; function ResetINT1_TrapFLAG {
DebugStub_ResetINT1_TrapFLAG:
; Push EAX to make sure whatever we do below doesn't affect code afterwards
; +EBP
Push EBP
Expand Down
4 changes: 4 additions & 0 deletions playground/CmdMisc.asm
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
; namespace DebugStub

; function Ping {
DebugStub_Ping:
; Ds2Vs.Pong
; AL = 13
Mov AL, 0xD
; ComWriteAL()
Call DebugStub_ComWriteAL
; }

; function TraceOn {
DebugStub_TraceOn:
; Tracing.On
; .TraceMode = 1
Mov DWORD [DebugStub_Var_TraceMode], 0x1
; }

; function TraceOff {
DebugStub_TraceOff:
; Tracing.Off
; .TraceMode = 0
Mov DWORD [DebugStub_Var_TraceMode], 0x0
Expand Down
35 changes: 35 additions & 0 deletions playground/CmdProcess.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
; Modifies: AL, DX (ComReadAL)
; Returns: AL
; function ProcessCommand {
DebugStub_ProcessCommand:
; ComReadAL()
Call DebugStub_ComReadAL
; Some callers expect AL to be returned, so we preserve it
; in case any commands modify AL.
; We push EAX to keep stack aligned.
Expand All @@ -18,6 +20,7 @@
; EAX = 0
Mov EAX, 0x0
; ComReadAL()
Call DebugStub_ComReadAL
; .CommandID = EAX
Mov DWORD [DebugStub_Var_CommandID], EAX

Expand All @@ -27,88 +30,114 @@

; if AL = #Vs2Ds_TraceOff {
; TraceOff()
Call DebugStub_TraceOff
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_TraceOn {
; TraceOn()
Call DebugStub_TraceOn
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_Break {
; Ack command for a break must be done first
; Otherwise we Break then ProcessCommands and get stuck because we don't send this Ack until execution continues
; AckCommand()
Call DebugStub_AckCommand
; Break()
Call DebugStub_Break
; return
Ret
; }
; if AL = #Vs2Ds_BreakOnAddress {
; BreakOnAddress()
Call DebugStub_BreakOnAddress
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_SendMethodContext {
; SendMethodContext()
Call DebugStub_SendMethodContext
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_SendMemory {
; SendMemory()
Call DebugStub_SendMemory
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_SendRegisters {
; SendRegisters()
Call DebugStub_SendRegisters
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_SendFrame {
; SendFrame()
Call DebugStub_SendFrame
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_SendStack {
; SendStack()
Call DebugStub_SendStack
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_Ping {
; Ping()
Call DebugStub_Ping
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_SetINT3 {
; SetINT3()
Call DebugStub_SetINT3
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }
; if AL = #Vs2Ds_ClearINT3 {
; ClearINT3()
Call DebugStub_ClearINT3
; AckCommand()
Call DebugStub_AckCommand
; return
Ret
; }


; Exit:
DebugStub_Exit:
; Restore AL for callers who check the command and do
; further processing, or for commands not handled by this function.
; -EAX
Pop EAX
; }

; function AckCommand {
DebugStub_AckCommand:
; We acknowledge receipt of the command AND the processing of it.
; -In the past the ACK only acknowledged receipt.
; We have to do this because sometimes callers do more processing.
Expand All @@ -124,20 +153,26 @@
; AL = #Ds2Vs_CmdCompleted
Mov AL, DebugStub_Const_Ds2Vs_CmdCompleted
; ComWriteAL()
Call DebugStub_ComWriteAL
; EAX = .CommandID
Mov EAX, DWORD [DebugStub_Var_CommandID]
; ComWriteAL()
Call DebugStub_ComWriteAL
; }

; function ProcessCommandBatch {
DebugStub_ProcessCommandBatch:
; Begin:
DebugStub_Begin:
; ProcessCommand()
Call DebugStub_ProcessCommand

; See if batch is complete
; Loop and wait
; Vs2Ds.BatchEnd
; if AL != 8 goto Begin

; AckCommand()
Call DebugStub_AckCommand
; }
Loading

0 comments on commit a176159

Please sign in to comment.