Skip to content

Commit

Permalink
another attempt at cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dshikashio committed Oct 16, 2022
1 parent 7e51439 commit 524fb02
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 28 deletions.
6 changes: 4 additions & 2 deletions pybag/dbgeng/idebugadvanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def __init__(self, advanced):
exception.wrap_comclass(self._adv)

def Release(self):
self._adv.Release()
self._adv = None
cnt = self._adv.Release()
if cnt == 0:
self._adv = None
return cnt

# IDebugAdvanced

Expand Down
7 changes: 5 additions & 2 deletions pybag/dbgeng/idebugclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def __init__(self, client=None):
self._proc_server_hndl = 0

def Release(self):
self._cli.Release()
self._cli = None
return
cnt = self._cli.Release()
if cnt == 0:
self._cli = None
return cnt

# Convenience Methods

Expand Down
6 changes: 4 additions & 2 deletions pybag/dbgeng/idebugcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def __init__(self, controlobj):
exception.wrap_comclass(self._ctrl)

def Release(self):
self._ctrl.Release()
self._ctrl = None
cnt = self._ctrl.Release()
if cnt == 0:
self._ctrl = None
return cnt

# IDebugControl

Expand Down
6 changes: 4 additions & 2 deletions pybag/dbgeng/idebugdataspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ def __init__(self, data):
exception.wrap_comclass(self._data)

def Release(self):
self._data.Release()
self._data = None
cnt = self._data.Release()
if cnt == 0:
self._data = None
return cnt

# IDebugDataSpaces

Expand Down
6 changes: 6 additions & 0 deletions pybag/dbgeng/idebugregisters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def __init__(self, reg):
self._reg = reg
exception.wrap_comclass(self._reg)

def Release(self):
cnt = self._reg.Release()
if cnt == 0:
self._reg = None
return cnt

# IDebugRegisters

def GetNumberRegisters(self):
Expand Down
6 changes: 4 additions & 2 deletions pybag/dbgeng/idebugsymbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def __init__(self, symbols):
exception.wrap_comclass(self._sym)

def Release(self):
self._sym.Release()
self._sym = None
cnt = self._sym.Release()
if cnt == 0:
self._sym = None
return cnt

# IDebugSymbols

Expand Down
6 changes: 4 additions & 2 deletions pybag/dbgeng/idebugsystemobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ def __init__(self, systemobj):
exception.wrap_comclass(self._sys)

def Release(self):
self._sys.Release()
self._sys = None
cnt = self._sys.Release()
if cnt == 0:
self._sys = None
return cnt

# IDebugSystemObjects

Expand Down
34 changes: 28 additions & 6 deletions pybag/pydbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,39 @@ def InitComObjects(Dbg):


def FiniComObjects(Dbg):
#Dbg.breakpoints.remove_all()
Dbg._client.SetOutputCallbacks(None)
Dbg._client.SetEventCallbacks(None)
#Dbg._advanced.Release()
#Dbg._control.Release()
#Dbg._dataspaces.Release()
#Dbg._symbols.Release()
#Dbg._systems.Release()
Dbg.callbacks = None
Dbg.reg = None
Dbg.mod = None
Dbg.events = None
Dbg.breakpoints = None
Dbg.callbacks = None

"""
x = Dbg._advanced.Release()
print(f"{x=}")
x = Dbg._control.Release()
print(f"{x=}")
x = Dbg._registers.Release()
print(f"{x=}")
x = Dbg._dataspaces.Release()
print(f"{x=}")
x = Dbg._symbols.Release()
print(f"{x=}")
x = Dbg._systems.Release()
print(f"{x=}")
x = Dbg._client.Release()
print(f"{x=}")
"""
Dbg._advanced = None
Dbg._control = None
Dbg._registers = None
Dbg._dataspaces = None
Dbg._symbols = None
Dbg._systems = None
Dbg._client = None


def EventThread(Dbg, Ev, WorkQ):
Dbg._client = DebugClient()
Expand Down Expand Up @@ -126,6 +147,7 @@ def Release(self):
self._thread = None
else:
pass

FiniComObjects(self)

def _reset_callbacks(self):
Expand Down
15 changes: 5 additions & 10 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ def test_processes(self):
pprint.pprint(pids)


def breakin(dbg,bp):
return pybag.dbgeng.core.DEBUG_STATUS_BREAK
def breakin(bp, dbg):
pass

def go(dbg,bp):
return pybag.dbgeng.core.DEBUG_STATUS_GO
def go(bp, dbg):
return pybag.DbgEng.DEBUG_STATUS_GO

class TestDataCommands(unittest.TestCase):
class TestStringCmd(unittest.TestCase):
def setUp(self):
self.dbg = UserDbg()
self.dbg.cmd(".sympath SRV*c:\\sym")
Expand All @@ -100,7 +100,6 @@ def setUp(self):

def tearDown(self):
self.dbg.terminate()
self.dbg.wait()
self.dbg.Release()

def test_string(self):
Expand All @@ -119,9 +118,5 @@ def test_string(self):
wstring = self.dbg.symbol("target!wArray")
self.assertEqual(self.dbg.readstr(wstring, True), 'wide array')

def test_disasm(self):
self.dbg.disasm()
self.dbg.disasm(self.dbg.symbol("target!add"))

if __name__ == '__main__':
unittest.main()

0 comments on commit 524fb02

Please sign in to comment.