1
0
mirror of https://github.com/bitdefender/bddisasm.git synced 2024-11-21 23:18:09 +00:00

Merge pull request #104 from akisari/master

Fix the text parser used for tests.
This commit is contained in:
vlutas 2024-09-17 18:07:53 +03:00 committed by GitHub
commit 7bc007069d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 22 deletions

View File

@ -150,7 +150,10 @@ class Core(object):
ldiff = list()
diffobj = diff.Diff()
for it in range(0, len(outresult)):
ldiff.append(diffobj.diffobj(outresult[it], outtest[it]))
td = diffobj.diffobj(outresult[it], outtest[it])
ldiff.append(td[:])
td = diffobj.diffobj(outtest[it], outresult[it])
ldiff.append(td[:])
result = result.replace("\r", "")
subprocess = subresult.replace("\r", "")

View File

@ -25,7 +25,8 @@ class Diff(object):
]
self._diff.append(result)
else:
result = [" - KEY %s : " % (key), " + KEY %s : " % (key)]
result = [" - KEY %s : %s" % (key, dict1[key]), " + KEY %s : " % (key)]
self._diff.append(result)
def diffobj(self, actual: object, expected: object) -> list:
"""
@ -33,11 +34,11 @@ class Diff(object):
"""
self._diff.clear()
if len(actual) != len(expected):
self._diff.append("invalid dimensions")
return None
for it in range(0, len(actual)):
self.diff(actual[it]._data, expected[it]._data)
result = [" - ACTUAL DIM = %d" % (len(actual)), "+ EXPECTED DIM = %d" % (len(expected))]
self._diff.append(result)
else:
for it in range(0, len(actual)):
self.diff(actual[it]._data, expected[it]._data)
if self._diff:
for elem in self._diff:

View File

@ -105,31 +105,58 @@ class ShemuInstrux(DecodeShemuParser):
"""
Parses the emulation result generated by disasmtool and stores it in a dictionary as key:value pair as follows:
{
"AX": "0x0000000000000000",
"CX": "0x0000000000000000",
"DX": "0x0000000000000000",
"BX": "0x0000000000000000",
"BP": "0x0000000000000000",
"SI": "0x0000000000000000",
"RAX": "0x0000000000000000",
"RCX": "0x0000000000000000",
"RDX": "0x0000000000000000",
"RBX": "0x0000000000000000",
"RBP": "0x0000000000000000",
"RSI": "0x0000000000000000",
...
"28": "0x0000000000000000",
"29": "0x0000000000000000",
"30": "0x0000000000000000",
"31": "0x0000000000000000",
"IP": "0x0000000000200000",
"GS": "0x0000000000000202"
"R28": "0x0000000000000000",
"R29": "0x0000000000000000",
"R30": "0x0000000000000000",
"R31": "0x0000000000000000",
"RIP": "0x0000000000200000",
"RFLAGS": "0x0000000000000202"
}
"""
self._obj = self._obj.split("\n")
line = self.rdline()
cnt = 0
while line:
# X0 = 0x0000000000000000 X1 = 0x0000000000000000 X2 = 0x0000000000000000 X3 = 0x0000000000000000
if " = " in line:
tokens = re.findall(r"\w\w\s*=\s*0x\d{16}", line)
tokens = re.findall(r"\w+\s*=\s*[0x]*[\da-f]{4,16}", line)
for token in tokens:
key = token.lstrip().rstrip().split("=")[0].lstrip().rstrip()
val = token.lstrip().rstrip().split("=")[1].lstrip().rstrip()
self._data[key] = val
if "IP: " in line or "PC: " in line:
tokens = re.findall(r"\w\w\s*:\s*0x[\da-f]{16}", line)
key = tokens[0].lstrip().rstrip().split(":")[0].lstrip().rstrip()
val = tokens[0].lstrip().rstrip().split(":")[1].lstrip().rstrip()
self._data["%s-%s" % (key, "INFO")] = val
tokens = line.split(' ')
key = "InstructionBytes"
val = tokens[1].lstrip().rstrip()
self._data[key] = val
key = "InstructionText"
val = " ".join(tokens[2:]).lstrip().rstrip()
self._data[key] = val
elif "Detection: " in line:
tokens = re.findall(r"\w+\s*:\s*0x\d{16}", line)
key = tokens[0].lstrip().rstrip().split(":")[0].lstrip().rstrip()
val = tokens[0].lstrip().rstrip().split(":")[1].lstrip().rstrip()
self._data["%s-%d" % (key, cnt)] = val
cnt += 1
elif ":" in line:
tokens = re.findall(r"\w\w\s*:\s*\d{1}", line)
for token in tokens:
key = token.lstrip().rstrip().split(":")[0].lstrip().rstrip()
val = token.lstrip().rstrip().split(":")[1].lstrip().rstrip()
self._data[key] = val
line = self.rdline()

View File

@ -100,7 +100,7 @@ class OutputShemu(OutputParser):
for line in data.split("\n"):
if line.startswith("Emulation ") or "SHEMU" in line:
continue
if re.search("^PC:", line) or re.search("^IP:", line):
if re.search(r"^\s*\wAX =", line) or re.search("^\s*X0\s*= ", line):
if local:
local = local.replace("\r", "")
ostr.append(local)