From 3d320e393c12bade1043c19fd4ed078850fe1d7f Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Thu, 22 Feb 2018 17:32:42 +0000 Subject: [PATCH] Rewrite parsing of source mapping info --- mythril/ether/soliditycontract.py | 16 ++++++++-------- mythril/support/truffle.py | 17 ++++++----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/mythril/ether/soliditycontract.py b/mythril/ether/soliditycontract.py index 84a0f1b0..a15eabe0 100644 --- a/mythril/ether/soliditycontract.py +++ b/mythril/ether/soliditycontract.py @@ -49,16 +49,16 @@ class SolidityContract(ETHContract): for item in srcmap: - m = re.search(r"^(\d+):(\d+)", item) + mapping = item.split(":") - if (m): - offset = int(m.group(1)) - length = int(m.group(2)) + if len(mapping) > 0 and len(mapping[0]) > 0: + offset = int(mapping[0]) - m = re.search(r"^\d+:\d+:(\d+)", item) - - if (m): - idx = int(m.group(1)) + if len(mapping) > 1 and len(mapping[1]) > 0: + length = int(mapping[1]) + + if len(mapping) > 2 and len(mapping[2]) > 0: + idx = int(mapping[2]) self.mappings.append(SourceMapping(idx, offset, length)) diff --git a/mythril/support/truffle.py b/mythril/support/truffle.py index 33a48ba3..0127348a 100644 --- a/mythril/support/truffle.py +++ b/mythril/support/truffle.py @@ -57,23 +57,18 @@ def analyze_truffle_project(): mappings = [] i = 0 - while(i < len(deployedSourceMap)): + for item in deployedSourceMap: - m = re.search(r"^(\d+):*(\d+)", deployedSourceMap[i]) + mapping = item.split(":") - if (m): - offset = m.group(1) - length = m.group(2) - else: - m = re.search(r"^:(\d+)", deployedSourceMap[i]) + if len(mapping) > 0 and len(mapping[0]) > 0: + offset = int(mapping[0]) - if m: - length = m.group(1) + if len(mapping) > 1 and len(mapping[1]) > 0: + length = int(mapping[1]) mappings.append((int(offset), int(length))) - i += 1 - for issue in issues: index = helper.get_instruction_index(disassembly.instruction_list, issue.pc)