Add mocks

This commit is contained in:
Gulshan Singh 2022-10-13 21:45:28 -07:00
parent 8eabec5541
commit 8a417091b5
5 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,9 @@
import types
class Amd64Arch(types.ModuleType):
def __init__(self, module_name):
super(Amd64Arch, self).__init__(module_name)
self.ptrsize = 8
self.endian = "little"

View File

@ -0,0 +1,18 @@
import types
class Config(types.ModuleType):
def __init__(self, module_name):
super(Config, self).__init__(module_name)
def trigger(self, *args):
def wrapper(func):
return func
return wrapper
def add_param(self, *args):
pass
def init_params(self):
pass

View File

@ -0,0 +1,12 @@
import sys
from unittest.mock import MagicMock
module_name = "gdb"
module = MagicMock()
sys.modules[module_name] = module
import gdb
gdb.PARAM_BOOLEAN = 0
gdb.PARAM_ZINTEGER = 4
gdb.PARAM_STRING = 8

View File

@ -0,0 +1,36 @@
import sys
import types
from unittest.mock import MagicMock
from mocks.arch import Amd64Arch
from mocks.config import Config
from mocks.typeinfo import Amd64TypeInfo
class GdbLib(types.ModuleType):
def __init__(self, module_name):
super().__init__(module_name)
self.config_mod = Config(module_name + ".config")
self.arch = Amd64Arch(module_name + ".arch")
self.typeinfo = Amd64TypeInfo(module_name + ".typeinfo")
self.regs = MagicMock(__name__=module_name + ".regs")
self.prompt = MagicMock()
sys.modules[self.config_mod.__name__] = self.config_mod
sys.modules[self.arch.__name__] = self.arch
sys.modules[self.typeinfo.__name__] = self.typeinfo
sys.modules[self.regs.__name__] = self.regs
def load_gdblib(self):
pass
module_name = "pwndbg.gdblib"
module = GdbLib(module_name)
sys.modules[module_name] = module
import pwndbg
pwndbg.gdblib = sys.modules["pwndbg.gdblib"]

View File

@ -0,0 +1,7 @@
import types
class Amd64TypeInfo(types.ModuleType):
def __init__(self, module_name):
super(Amd64TypeInfo, self).__init__(module_name)
self.ptrsize = 8