It is currently Fri Jan 19, 2018 2:50 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: *Pb assembly debugger..
PostPosted: Wed Jan 10, 2018 10:58 pm 
Offline
User
User
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 38
hi all

I am a beginner in assembly and I created a debugger for assembly in pb

correct me if I'm wrong!

*Update
Code:
EnableExplicit

CompilerIf #PB_Compiler_Debugger = 1 
  Procedure _Dasm_Debug(__asmDebug, Type,Size)
    Select Type
      Case 1
        Debug __asmDebug
      Case 2
        Debug PeekA(@__asmDebug)
      Case 3
        Debug PeekU(@__asmDebug)
      Case 4
        Debug PeekS(__asmDebug)
      Case 5
        Debug PeekS(__asmDebug,-1,#PB_Ascii)
      Case 6
        ShowMemoryViewer(__asmDebug,Size)
      Case 7
        Protected Flags.s = RSet(Bin(__asmDebug,#PB_Long), 32, "0")
        Protected AllFlags.s = ";;;;;;;;;;ID;VIP;VIF;AC;VM;RF;;NT;IOPL_h;IOPL_l;OF;DF;IF;TF;SF;ZF;;AF;;PF;;CF"
        Protected s,sf.s,rets.s
        For s = 1 To 32
          If Mid(Flags,s,1) = "1"
            sf = StringField(AllFlags,s,";")
            If sf
              rets = "[" + sf + "]"  + " " + rets
            EndIf
          EndIf
        Next
        Debug "Flags : " + rets
      Case 8
       
        EnableASM
        SUB eax, eax
        MOV eax, CS
        MOV dword [p.v___asmDebug] , eax
        Debug "[CS = " + Hex(__asmDebug) + "]"
        MOV eax, DS
        MOV dword [p.v___asmDebug] , eax
        Debug "[DS = " + Hex(__asmDebug) + "]"
        MOV eax, SS
        MOV dword [p.v___asmDebug] , eax
        Debug "[SS = " + Hex(__asmDebug) + "]"
        MOV eax, ES
        MOV dword [p.v___asmDebug] , eax
        Debug "[ES = " + Hex(__asmDebug) + "]"
        MOV eax, FS
        MOV dword [p.v___asmDebug] , eax
        Debug "[FS = " + Hex(__asmDebug) + "]"
        MOV eax, GS
        MOV dword [p.v___asmDebug] , eax
        Debug "[GS = " + Hex(__asmDebug) + "]"
        DisableASM
       
      Case 9
        Debug "Point code : "  + Str(__asmDebug)
    EndSelect
  EndProcedure
 
  Global __Dasm_Debug = @_Dasm_Debug()
CompilerEndIf

Macro Dasm_Save_SFPU_MXCSR_SSE
  PUSH    ebp
  MOV     ebp,esp
  SUB     esp,512
  AND     esp,-16
  !fxsave  [esp] ;saves the current state of the FPU, MXCSR register, and all the FPU AND SSE registers
EndMacro

Macro Dasm_Reload_SFPU_MXCSR_SSE
  !fxrstor [esp]
  MOV     esp,ebp
  POP     ebp
EndMacro

Macro Dasm_Debug(reg,Type,Size=0)
  CompilerIf #PB_Compiler_Debugger = 1 
    PUSHFD
    PUSHA
    MOV eax, reg
    PUSH dword Size
    PUSH dword Type
    PUSH eax
    CALL [v___Dasm_Debug]
    POPA
    POPFD
  CompilerEndIf
EndMacro

Macro Dasm_ShowAssembly()
  CompilerIf #PB_Compiler_Debugger = 1
    PUSHFD
    PUSHA
    EnableDebugger
    ShowAssemblyViewer()
    DisableDebugger
    POPA
    POPFD
  CompilerEndIf
EndMacro   ;call ShowAssembly

Macro Dasm_Pause()
  CompilerIf #PB_Compiler_Debugger = 1 
    PUSHFD
    PUSHA
    EnableDebugger
    CallDebugger
    DisableDebugger
    POPA
    POPFD
  CompilerEndIf
EndMacro  ;CallDebugger

Macro Dasm_Flags()
  CompilerIf #PB_Compiler_Debugger = 1 
    PUSHFD
    PUSHA
    MOV eax,[esp + 4*8]
    PUSH dword 0
    PUSH dword 7
    PUSH eax
    CALL [v___Dasm_Debug]
    POPA
    POPFD
  CompilerEndIf
EndMacro

Macro Dasm_ShowText(Txt)
  CompilerIf #PB_Compiler_Debugger = 1 
    PUSHFD
    PUSHA
    EnableDebugger
    Debug Txt
    DisableDebugger
    POPA
    POPFD
  CompilerEndIf
EndMacro

Macro Dasm_SegmentRegisters()
  CompilerIf #PB_Compiler_Debugger = 1 
    PUSHA
    PUSH dword 0
    PUSH dword 8
    PUSH dword 0
    CALL [v___Dasm_Debug]
    POPA
  CompilerEndIf
EndMacro

Macro Dasm_NextInstructionPointer() ;EIP
  CompilerIf #PB_Compiler_Debugger = 1 
    PUSH eax
    MOV eax , @f
   
    PUSHA
    PUSH dword 0
    PUSH dword 9
    PUSH eax
    CALL [v___Dasm_Debug]
    POPA
   
    POP eax
    !@@:
  CompilerEndIf
EndMacro

Macro Dasm_Byte(reg):Dasm_Debug(reg,2):EndMacro    ;debug byte
Macro Dasm_Word(reg):Dasm_Debug(reg,3):EndMacro    ;debug word
Macro Dasm_long(reg):Dasm_Debug(reg,1):EndMacro    ;debug long
Macro Dasm_StringU(reg):Dasm_Debug(reg,4):EndMacro ;debug string unicode
Macro Dasm_StringA(reg):Dasm_Debug(reg,5):EndMacro ;debug ascii
Macro Dasm_ShowMemory(reg,Size):Dasm_Debug(reg,6,Size):EndMacro   ;call ShowMemory


Procedure __test(par) 
  EnableASM
  DisableDebugger ;Très important
 
  Dasm_ShowText("Asm code debugging started.")
 
  Dasm_ShowText("Asm Segment Registers:")
  Dasm_SegmentRegisters()
 
  MOV ecx, esp
 
  MOV eax ,[ecx + 4]
 
  PUSH eax
  XOR eax,eax
 
  ADD eax,2147483647
 
  Dasm_ShowText("Asm Next Instruction Pointer:")
  Dasm_NextInstructionPointer()
  ADD eax,1
 
  Dasm_ShowText("Asm Show Flags:")
  Dasm_Flags() ;overflow!
 
  Dasm_ShowAssembly()
  Dasm_ShowText(">> (Asm Pause) <<")
  Dasm_Pause()
 
  Dasm_ShowText("Asm Show EAX:")
  Dasm_long(eax)
 
  POP eax
  Dasm_ShowText("Asm Show 'STRING ASCII' EAX:")
  Dasm_StringA(eax) 
 
  Dasm_ShowText("Asm Dump Stack.")
  Dasm_ShowMemory(ecx,16)
 
  DisableASM
  EnableDebugger
EndProcedure

__test(Ascii("celtic"))


_________________
yes, stack overflow ;)


Last edited by CELTIC88 on Tue Jan 16, 2018 5:38 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Pb assembly debugger..
PostPosted: Thu Jan 11, 2018 9:17 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13183
Location: France
You can also use the 'assembler' debug window in the debug IDE menu, when you are breaked, it should show all register content and flags


Top
 Profile  
Reply with quote  
 Post subject: Re: Pb assembly debugger..
PostPosted: Sun Jan 14, 2018 7:04 pm 
Offline
User
User
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 38
thank you @Fred :)

_________________
yes, stack overflow ;)


Top
 Profile  
Reply with quote  
 Post subject: Re: *Pb assembly debugger..
PostPosted: Tue Jan 16, 2018 5:38 pm 
Offline
User
User
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 38
update.

_________________
yes, stack overflow ;)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye