forked from dshikashio/Pybag
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c33994
commit 5ae110a
Showing
4 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
python -m tests.test_idebugclient | ||
python -m tests.test_target | ||
REM discovery doesn't work well due to: | ||
REM need to split dbgeng instances into different processe | ||
REM until its clear how to properly release all references to objects | ||
|
||
REM python -m unittest discover | ||
|
||
python -m tests.test_idebugclient | ||
python -m tests.test_target TestBasic | ||
python -m tests.test_target TestTargetCreate | ||
python -m tests.test_target TestTargetAttach1 | ||
python -m tests.test_target TestTargetAttach2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <Windows.h> | ||
#include <stdio.h> | ||
|
||
PVOID ADDRESS = (PVOID)0x222000; | ||
|
||
int wmain(int argc, wchar_t **argv) | ||
{ | ||
PVOID ptr = NULL; | ||
|
||
ptr = VirtualAlloc(ADDRESS, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); | ||
if (ptr == NULL) | ||
{ | ||
printf("VirtualAlloc Failed: %08x\n", GetLastError()); | ||
return -1; | ||
} | ||
|
||
printf("%S: Hello : %p\n", argv[0], ptr); | ||
|
||
PDWORD stop = (PDWORD)ptr; | ||
|
||
while (*stop == 0) | ||
{ | ||
printf("Sleep\n"); | ||
Sleep(2000); | ||
} | ||
|
||
// | ||
// set registers | ||
// end with 0xcc | ||
// | ||
// execute buffer | ||
|
||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,81 @@ | ||
import unittest | ||
import os | ||
import pprint | ||
import subprocess | ||
|
||
from pybag import DbgEng, UserDbg | ||
|
||
target = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'target', 'target.exe') | ||
target1 = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'target', 'target.exe') | ||
target2 = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'target', 'target2.exe') | ||
|
||
class TestTarget(unittest.TestCase): | ||
def test_init(self): | ||
class TestTargetCreate(unittest.TestCase): | ||
def setUp(self): | ||
dbg = UserDbg() | ||
dbg.create(target) | ||
dbg.r() | ||
dbg.create(target1) | ||
self.dbg = dbg | ||
|
||
def tearDown(self): | ||
self.dbg.terminate() | ||
self.dbg = None | ||
|
||
def test_base_functions(self): | ||
self.dbg.r() | ||
self.dbg.address() | ||
self.dbg.disasm() | ||
self.dbg.handles() | ||
self.dbg.threads() | ||
self.dbg.teb() | ||
self.dbg.peb() | ||
self.dbg.backtrace() | ||
self.dbg.lm() | ||
self.dbg.imports('target') | ||
self.dbg.exports('kernel32') | ||
self.assertEqual(self.dbg.bitness(), '64') | ||
|
||
class TestTargetAttach1(unittest.TestCase): | ||
def setUp(self): | ||
self.dbg = UserDbg() | ||
self.proc = subprocess.Popen([target2]) | ||
|
||
def tearDown(self): | ||
self.proc.terminate() | ||
self.dbg = None | ||
|
||
def test_attach_detach(self): | ||
self.dbg.attach(self.proc.pid) | ||
self.assertEqual(self.dbg.pid, self.proc.pid) | ||
self.assertEqual(self.dbg.exec_status(), 'BREAK') | ||
self.dbg.detach() | ||
|
||
class TestTargetAttach2(unittest.TestCase): | ||
def setUp(self): | ||
self.dbg = UserDbg() | ||
self.proc = subprocess.Popen([target2]) | ||
|
||
def tearDown(self): | ||
self.proc.terminate() | ||
self.dbg = None | ||
|
||
def test_attach_terminate(self): | ||
self.dbg.attach(self.proc.pid) | ||
self.dbg.terminate() | ||
|
||
class TestBasic(unittest.TestCase): | ||
def setUp(self): | ||
self.dbg = UserDbg() | ||
|
||
def tearDown(self): | ||
self.dbg = None | ||
|
||
def test_ps(self): | ||
self.dbg.ps() | ||
|
||
def test_pids_by_name(self): | ||
pids = self.dbg.pids_by_name("svchost.exe") | ||
pprint.pprint(pids) | ||
|
||
def test_exec_status(self): | ||
self.assertEqual(self.dbg.exec_status(), 'NO_DEBUGGEE') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |