def testVoidPtr(self): self.assertEqual(4, pykd.typeBuilder(4).VoidPtr.size()) self.assertEqual(8, pykd.typeBuilder(8).VoidPtr.size()) self.assertEqual(pykd.ptrSize(), pykd.typeBuilder().VoidPtr.size()) self.assertEqual(4, pykd.typeBuilder(4).UInt1B.ptrTo().size()) self.assertEqual(8, pykd.typeBuilder(8).UInt1B.ptrTo().size()) self.assertEqual(pykd.ptrSize(), pykd.typeBuilder().UInt1B.ptrTo().size())
def testSize(self): ti1 = target.module.type("structTest") self.assertEqual(16 + pykd.ptrSize(), ti1.size()) self.assertEqual(pykd.ptrSize(), target.module.type("structTest**").size()) self.assertEqual(pykd.sizeof("structTest"), target.module.type("structTest").size()) self.assertEqual(pykd.sizeof("structTest**"), target.module.type("structTest**").size()) self.assertEqual(pykd.sizeof("Int1B"), pykd.typeInfo("Int1B").size())
def testPtrToCustomType(self): tb = pykd.typeBuilder() mySubStruct = tb.createStruct("MySubCustomStruct") mySubStruct.append("m_uint1", tb.UInt1B) mySubStruct.append("m_uint2", tb.UInt2B) mySubStructPtr = mySubStruct.ptrTo() self.assertEqual(pykd.ptrSize(), mySubStructPtr.size())
def testGetSize( self ): tv1 = target.module.typedVar( "structTest", target.module.g_structTest ) self.assertEqual( 16 + pykd.ptrSize(), tv1.sizeof() ) tv2 = target.module.typedVar( "structTest[2]", target.module.g_testArray ) self.assertEqual( tv1.sizeof()*2, tv2.sizeof() ) self.assertEqual( pykd.sizeof("g_structTest"), tv1.sizeof() ) self.assertEqual( pykd.sizeof("g_testArray"), tv2.sizeof() ) self.assertEqual( pykd.sizeof("g_ucharValue"), 1 )
def getCurrentEprocess(): arc = pykd.ptrSize() list = pykd.dbgCommand(".process") if arc == 4: ret = list[len(list) - 1 - 8:len(list) - 1] return "0x" + ret else: ret = list[len(list) - 1 - 16:len(list) - 1] return "0x" + ret return ""
def getEprocessByName(name): arc = pykd.ptrSize() list = pykd.dbgCommand("!dml_proc") list = list.split("\n") list = list[1:len(list) - 1] for item in list: if name in item: if arc == 4: ret = item[0:8] return "0x" + ret else: ret = item[0:16] return "0x" + ret return ""
def testPtrToCustomType(self): mySubStruct = pykd.createStruct("MySubCustomStruct") mySubStruct.append("m_uint1", baseTypes.UInt1B) mySubStruct.append("m_uint2", baseTypes.UInt2B) mySubStructPtr = mySubStruct.ptrTo() self.assertEqual(pykd.ptrSize(), mySubStructPtr.size())
def ptrSize(): return pykd.ptrSize()
# -*- coding: UTF-8 -*- #重新封装的pykd import pykd #4表示32位架构,8表示64位架构 arc = pykd.ptrSize() def Hex(arg): #-->str ret = hex(arg) return ret.replace('L', '') def go(): pykd.go() def dbgCommand(cmd): return pykd.dbgCommand(cmd) def reg(register): return pykd.reg(register) def loadBytes(addr, len): return pykd.loadBytes(addr, len) def compareMemory(addr1, addr2, len): return pykd.compareMemory(addr1, addr2, len)