Skip to content

Commit 9a93220

Browse files
authored
Merge pull request #89 from netanelc305/feature/extend_configs_mode
libvmi: libvmi_cdef: Add `JSON` and `FILE_PATH` config options
2 parents c4105af + 5f854c8 commit 9a93220

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

libvmi/libvmi.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ def __setitem__(self, index, value):
139139
raise_from(RuntimeError('Unknown field {} in regs.x86'
140140
.format(index.name.lower())), e)
141141

142+
def __str__(self):
143+
# Heuristic to determine the architecture
144+
if hasattr(self.cffi_regs.x86, 'rip') or hasattr(self.cffi_regs.x86, 'eip'):
145+
regs_to_print = self.cffi_regs.x86
146+
elif hasattr(self.cffi_regs.arm, 'pc'):
147+
regs_to_print = self.cffi_regs.arm
148+
else:
149+
raise RuntimeError("Unable to determine architecture")
150+
attributes = []
151+
for attr in dir(regs_to_print):
152+
if not attr.startswith('_'):
153+
value = getattr(regs_to_print, attr)
154+
attributes.append(f"{attr.lower()} = {value:#x}")
155+
156+
return '\n'.join(attributes)
157+
142158

143159
class VMIMode(Enum):
144160
XEN = lib.VMI_XEN
@@ -150,6 +166,8 @@ class VMIConfig(Enum):
150166
GLOBAL_FILE_ENTRY = lib.VMI_CONFIG_GLOBAL_FILE_ENTRY
151167
STRING = lib.VMI_CONFIG_STRING
152168
DICT = lib.VMI_CONFIG_GHASHTABLE
169+
JSON_PATH = lib.VMI_CONFIG_JSON_PATH
170+
FILE_PATH = lib.VMI_CONFIG_FILE_PATH
153171

154172

155173
class VMIStatus(Enum):
@@ -318,8 +336,8 @@ def __init__(self, domain, init_flags=INIT_DOMAINNAME, init_data=None,
318336
# from str to bytes
319337
if init_flags & INIT_DOMAINNAME or init_flags & INIT_DOMAINID:
320338
domain = domain.encode()
321-
# same for VMI_CONFIG_STRING
322-
if config_mode == VMIConfig.STRING:
339+
# same for VMI_CONFIG_STRING | VMI_CONFIG_FILE_PATH | VMI_CONFIG_JSON_PATH
340+
if config_mode in [VMIConfig.STRING, VMIConfig.FILE_PATH, VMIConfig.JSON_PATH]:
323341
config = config.encode()
324342
elif config_mode == VMIConfig.DICT:
325343
# need to convert config to a GHashTable

libvmi/libvmi_cdef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ typedef enum vmi_config {
122122
VMI_CONFIG_STRING, /**< config string provided */
123123

124124
VMI_CONFIG_GHASHTABLE, /**< config GHashTable provided */
125+
126+
VMI_CONFIG_JSON_PATH, /**< config in json file at the location provided */
127+
128+
VMI_CONFIG_FILE_PATH, /**< config file path provided */
125129
} vmi_config_t;
126130

127131
// vmi_mode

0 commit comments

Comments
 (0)