From 64343da44a4b80cc014de7014bcf226fd5e235b9 Mon Sep 17 00:00:00 2001 From: Josselin Date: Tue, 5 Feb 2019 06:50:36 -0500 Subject: [PATCH] Add support to solc json file where the non-json text was removed (fix #153) --- slither/solc_parsing/slitherSolc.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/slither/solc_parsing/slitherSolc.py b/slither/solc_parsing/slitherSolc.py index ee51e9f41..eb34ed73e 100644 --- a/slither/solc_parsing/slitherSolc.py +++ b/slither/solc_parsing/slitherSolc.py @@ -41,8 +41,18 @@ class SlitherSolc(Slither): def _parse_contracts_from_json(self, json_data): try: data_loaded = json.loads(json_data) - self._parse_contracts_from_loaded_json(data_loaded['ast'], data_loaded['sourcePath']) - return True + # Truffle AST + if 'ast' in data_loaded: + self._parse_contracts_from_loaded_json(data_loaded['ast'], data_loaded['sourcePath']) + return True + # solc AST, where the non-json text was removed + else: + if 'attributes' in data_loaded: + filename = data_loaded['attributes']['absolutePath'] + else: + filename = data_loaded['absolutePath'] + self._parse_contracts_from_loaded_json(data_loaded, filename) + return True except ValueError: first = json_data.find('{')