Commit d7f76b4b authored by SND\kernelnet_cp's avatar SND\kernelnet_cp
Browse files

[samples] added: a very simple debugger

git-svn-id: https://pykd.svn.codeplex.com/svn@70215 9b283d60-5439-405e-af05-b73fd8c4d996
parent 071ae4e1
......@@ -384,7 +384,7 @@ BOOST_PYTHON_MODULE( pykd )
.def( boost::python::init<>( "constructor" ) )
.def( boost::python::init<ULONG64>( boost::python::args("offset"), "constructor" ) )
.def( "disasm", &disasm::disassemble, "Disassemble next instruction" )
.def( "sasm", &disasm::assembly, "Insert assemblied instuction to current offset" )
.def( "asm", &disasm::assembly, "Insert assemblied instuction to current offset" )
.def( "begin", &disasm::begin, "Return begin offset" )
.def( "current", &disasm::current, "Return current offset" )
.def( "length", &disasm::length, "Return current instruction length" )
......
......@@ -6,7 +6,7 @@ from PySide.QtCore import *
from PySide.QtGui import *
import pykd
import widgets
class UpdateEvent( QEvent ):
def __init__(self):
......@@ -26,78 +26,6 @@ class GoThread( QThread ):
self.exit()
class DisasmWidget( QDockWidget ):
def __init__( self ):
QDockWidget.__init__( self )
self.setWindowTitle( "Disassembler" )
self.textArea = QTextEdit()
self.textArea.setReadOnly( True )
self.setWidget( self.textArea )
def onUpdate( self ):
disasm = pykd.disasm()
disasmStr = disasm.instruction() + "\n"
for i in xrange(50):
disasmStr += disasm.next() + "\n"
self.textArea.setPlainText( disasmStr )
class RegistersWidget( QDockWidget ):
def __init__( self ):
QDockWidget.__init__( self )
self.setWindowTitle( "Registers" )
self.textArea = QTextEdit()
self.setWidget( self.textArea )
def onUpdate( self ):
s = ""
for reg in self.getRegisterSet():
s += "%s %x ( %d )\r\n" % ( reg.name(), reg.value(), reg.value() )
self.textArea.setPlainText( s )
def getRegisterSet(self):
regSet=[]
try:
i = 0
while True:
reg = pykd.cpuReg(i)
regSet.append(reg)
i += 1
except pykd.BaseException:
pass
return regSet
class StackWidget( QDockWidget ):
def __init__( self ):
QDockWidget.__init__( self )
self.setWindowTitle( "Stack" )
self.textArea = QTextEdit()
self.setWidget( self.textArea )
def onUpdate( self ):
s = ""
stackFrames = pykd.getCurrentStack()
for frame in stackFrames:
s += pykd.findSymbol( frame.instructionOffset ) + " (%x)" % frame.instructionOffset + "\n"
self.textArea.setPlainText( s )
class MainForm( QMainWindow ):
updated = Signal()
......@@ -112,42 +40,25 @@ class MainForm( QMainWindow ):
self.goThread = None
fileMenu = QMenu( "&File" )
fileMenu.addAction( "Open process...", self.onOpenProcess )
fileMenu.addAction( "Exit", self.onExit )
self.menuBar().addMenu( fileMenu )
debugMenu = QMenu( "Debug" )
debugMenu.addAction( "Break", self.onBreak )
debugMenu.addAction( "Go", self.onGo )
debugMenu.addAction( "Step", self.onStep )
self.menuBar().addMenu( debugMenu )
self.fileMenu = QMenu( "&File" )
self.fileMenu.addAction( "Open process...", self.onOpenProcess )
self.fileMenu.addAction( "Exit", self.onExit )
self.menuBar().addMenu( self.fileMenu )
viewMenu = QMenu( "View" )
viewMenu.addAction( "Disasm", self.onDisasmShow )
viewMenu.addAction( "Regsiters", self.onRegistersShow )
viewMenu.addAction( "Stack", self.onStackShow )
self.menuBar().addMenu( viewMenu )
self.debugMenu = QMenu( "Debug" )
self.debugMenu.addAction( "Break", self.onBreak )
self.debugMenu.addAction( "Go", self.onGo )
self.debugMenu.addAction( "Step", self.onStep )
self.menuBar().addMenu( self.debugMenu )
self.disasmWidget = DisasmWidget()
self.disasmWidget.setVisible( False )
self.addDockWidget( Qt.LeftDockWidgetArea, self.disasmWidget )
self.updated.connect(self.disasmWidget.onUpdate )
self.registersWidget = RegistersWidget()
self.registersWidget.setVisible( False )
self.addDockWidget( Qt.LeftDockWidgetArea, self.registersWidget )
self.updated.connect(self.registersWidget.onUpdate )
self.stackWidget = StackWidget()
self.stackWidget.setVisible( False )
self.addDockWidget( Qt.LeftDockWidgetArea, self.stackWidget )
self.updated.connect(self.stackWidget.onUpdate )
self.viewMenu = QMenu( "View" )
self.menuBar().addMenu( self.viewMenu )
self.resize( 800, 600 )
widgets.register( self )
def stopGoThread( self ):
......@@ -190,16 +101,6 @@ class MainForm( QMainWindow ):
def onExit( self ):
self.close()
def onDisasmShow( self ):
self.disasmWidget.setVisible( not self.disasmWidget.isVisible() )
def onRegistersShow( self ):
self.registersWidget.setVisible( not self.registersWidget.isVisible() )
def onStackShow( self ):
self.stackWidget.setVisible( not self.stackWidget.isVisible() )
def onUpdate( self ):
self.updated.emit()
......
import regs
import disasm
import stack
import cmd
def register( mainFrame ):
cmd.CmdWidget( mainFrame )
regs.RegistersWidget( mainFrame )
disasm.DisasmWidget( mainFrame )
stack.StackWidget( mainFrame )
\ No newline at end of file
from PySide.QtCore import *
from PySide.QtGui import *
import pykd
class CmdWidget( QDockWidget ):
def __init__( self, parent ):
QDockWidget.__init__( self )
self.setWindowTitle( "Commands" )
self.inCmd = QLineEdit()
self.inCmd.returnPressed.connect( self.onCommandInput )
self.outCmd = QTextEdit()
self.outCmd.setReadOnly( True )
layout = QVBoxLayout()
layout.addWidget( self.outCmd )
layout.addWidget( self.inCmd )
layoutWidget = QWidget()
layoutWidget.setLayout( layout )
self.setWidget( layoutWidget )
self.setVisible( False )
parent.addDockWidget( Qt.LeftDockWidgetArea, self )
parent.viewMenu.addAction( "Commands", self.onCommandsShow )
def onCommandsShow( self ):
self.setVisible( not self.isVisible() )
def onCommandInput( self ):
self.inCmd.setReadOnly( True )
cmdLine = self.inCmd.text()
self.inCmd.setText( "running %s" % cmdLine )
self.outCmd.append( pykd.dbgCommand( cmdLine ) )
self.inCmd.setText( "" )
self.inCmd.setReadOnly( False )
from PySide.QtCore import *
from PySide.QtGui import *
import pykd
class DisasmWidget( QDockWidget ):
def __init__( self, parent ):
QDockWidget.__init__( self )
self.setWindowTitle( "Disassembler" )
self.textArea = QTextEdit()
self.setWidget( self.textArea )
self.setVisible( False )
parent.addDockWidget( Qt.LeftDockWidgetArea, self )
parent.updated.connect(self.onUpdate )
parent.viewMenu.addAction( "Disassembler", self.onDisassemblerShow )
def onUpdate( self ):
disasm = pykd.disasm()
self.textArea.setPlainText( "\n".join( [ disasm.disasm() for i in xrange(50) ] ) )
def onDisassemblerShow( self ):
self.setVisible( not self.isVisible() )
\ No newline at end of file
from PySide.QtCore import *
from PySide.QtGui import *
import pykd
class RegistersWidget( QDockWidget ):
def __init__( self, parent ):
QDockWidget.__init__( self )
self.setWindowTitle( "Registers" )
self.textArea = QTextEdit()
self.setWidget( self.textArea )
self.setVisible( False )
parent.addDockWidget( Qt.LeftDockWidgetArea, self )
parent.updated.connect(self.onUpdate )
parent.viewMenu.addAction( "Regsiters", self.onRegistersShow )
def onUpdate( self ):
s = ""
for reg in self.getRegisterSet():
s += "%s %x ( %d )\r\n" % ( reg.name(), reg.value(), reg.value() )
self.textArea.setPlainText( s )
def getRegisterSet(self):
regSet=[]
try:
i = 0
while True:
reg = pykd.cpuReg(i)
regSet.append(reg)
i += 1
except pykd.BaseException:
pass
return regSet
def onRegistersShow( self ):
self.setVisible( not self.isVisible() )
from PySide.QtCore import *
from PySide.QtGui import *
import pykd
class StackWidget( QDockWidget ):
def __init__( self, parent ):
QDockWidget.__init__( self )
self.setWindowTitle( "Stack" )
self.textArea = QTextEdit()
self.setWidget( self.textArea )
self.setVisible( False )
parent.addDockWidget( Qt.LeftDockWidgetArea, self )
parent.updated.connect(self.onUpdate )
parent.viewMenu.addAction( "Stack", self.onStackShow )
def onUpdate( self ):
s = ""
stackFrames = pykd.getCurrentStack()
for frame in stackFrames:
s += pykd.findSymbol( frame.instructionOffset ) + " (%x)" % frame.instructionOffset + "\n"
self.textArea.setPlainText( s )
def onStackShow( self ):
self.setVisible( not self.isVisible() )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment