Pyx64dbg 自動化反彙編插件手冊

一個 X64dbg 自動化控制插件,通過Python控制X64dbg的行爲,實現遠程調試,你可以將x64dbg扔到虛擬機內,然後在外面通過pycharm編程,控制內部虛擬機中的x64DBG反彙編分析或者執行各種操作,該插件我暫時將其命名爲LyScript.dp32吧。

  • 插件由兩部分組成,需要安裝使用C開發的lyscript.dp32組件,python則需要安裝對應的接口調用包。
正在開發中,開發完畢即公開成品,敬請期待。

LyScript插件通過建立遠程套接字,與python連接,每次執行命令之前,需要通過dbg.connect()函數連接到對端,連接後會建立一個持久會話,在該會話內可執行你想要得到的所有參數,在執行結束後需要使用dbg.close()關閉該會話。

connect() 函數建立會話: 建立會話很簡單,首先初始化是傳入服務端IP地址,也就是x64dbg的地址,然後連接即可。

from Lydbg import MyDebug

if __name__ == "__main__":
    dbg = MyDebug(address="127.0.0.1",port=6666)
    connect_flag = dbg.connect()
    print("連接狀態: {}".format(connect_flag))

    dbg.close()

連接成功返回1


get_register() 函數獲取寄存器: 該函數主要用於實現,對特定寄存器的獲取操作,用戶需傳入需要獲取的寄存器名字即可。

  • 參數1範圍:eax,ebx,ecx,edx,ebp,esp,esi,edi,eip,cflags,dr0-dr7
from Lydbg import MyDebug

if __name__ == "__main__":
    dbg = MyDebug(address="127.0.0.1",port=6666)
    connect_flag = dbg.connect()
    print("連接狀態: {}".format(connect_flag))

    eax = dbg.get_register("eax")
    ebx = dbg.get_register("ebx")

    print("eax = {}".format(hex(eax)))
    print("ebx = {}".format(hex(ebx)))

    dbg.close()


set_register() 函數設置寄存器: 該函數實現設置指定寄存器參數。

  • 參數1:寄存器名稱 eax,ebx,ecx,edx,ebp,esp,esi,edi,eip,cflags,dr0-dr7
  • 參數2:十進制數值
from Lydbg import MyDebug

if __name__ == "__main__":
    dbg = MyDebug(address="127.0.0.1",port=6666)
    connect_flag = dbg.connect()
    print("連接狀態: {}".format(connect_flag))

    eax = dbg.get_register("eax")
    
    dbg.set_register("eax",100)

    print("eax = {}".format(hex(eax)))

    dbg.close()

運行後效果如下:


get_flag_register() 獲取標誌函數: 用於獲取某個標誌位參數,返回值只有真或者假。

  • 參數範圍:ZF,PF,AF,OF,SF,DF,CF,TF,IF
from Lydbg import MyDebug

if __name__ == "__main__":
    dbg = MyDebug(address="127.0.0.1",port=6666)
    connect_flag = dbg.connect()
    print("連接狀態: {}".format(connect_flag))

    cf = dbg.get_flag_register("cf")
    print("標誌: {}".format(cf))
    
    dbg.close()


set_debug() 函數設置調試狀態: 用於影響調試器,例如前進一次,後退一次,暫停調試,終止等。

  • 參數範圍:Pause,Run,StepIn,StepOut,StepOver,Stop,Wait
from Lydbg import MyDebug

if __name__ == "__main__":
    dbg = MyDebug(address="127.0.0.1",port=6666)
    connect_flag = dbg.connect()
    print("連接狀態: {}".format(connect_flag))

    while True:
        dbg.set_debug("StepIn")
        
        eax = dbg.get_register("eax")
        
        if eax == 0:
            print("找到了")
            break
        
    dbg.close()

此外該函數還有一個自動步過次數控制功能,例如dbg.set_debug_count("StepIn",100) 則代表自動步進100次。


set_breakpoint() 函數實現下斷點: 該函數可實現在指定內存區域內下斷點操作,有兩個參數需要傳入。

  • 參數1:需要設置斷點的地址
  • 參數2:True = 取消斷點 False = 設置斷點
from Lydbg import MyDebug

if __name__ == "__main__":
    dbg = MyDebug(address="127.0.0.1",port=6666)
    connect_flag = dbg.connect()

    for index in range(0,10):
        eip = dbg.get_register("eip")

        ref = dbg.set_breakpoint(eip,True)
        print("斷點設置狀態: {}".format(ref))

        dbg.set_debug("StepIn")
        time.sleep(0.3)

    dbg.close()


get_disasm_code() 反彙編函數: 該函數主要用於對特定內存地址進行反彙編,傳入兩個參數。

  • 參數1:需要反彙編的地址(十進制)
  • 參數2:需要向下反彙編的長度
from Lydbg import MyDebug

if __name__ == "__main__":
    dbg = MyDebug(address="127.0.0.1",port=6666)
    connect_flag = dbg.connect()
    print("連接狀態: {}".format(connect_flag))

    # 得到EIP位置
    eip = dbg.get_register("eip")

    # 反彙編前100行
    disasm_dict = dbg.get_disasm_code(eip,100)

    for ds in disasm_dict:
        print("地址: {} 反彙編: {}".format(hex(ds.get("addr")),ds.get("opcode")))

    dbg.close()

反彙編後,輸出如下:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章