fixes + logger

pull/202/head
ggrieco-tob 6 years ago
parent 43fa9c73df
commit 32f2f6f0d1
  1. 4
      utils/similarity/__main__.py
  2. 11
      utils/similarity/encode.py
  3. 2
      utils/similarity/info.py
  4. 5
      utils/similarity/test.py
  5. 2
      utils/similarity/train.py

@ -5,13 +5,11 @@ import logging
import sys
import traceback
import operator
import numpy as np
from .info import info
from .test import test
from .train import train
logging.basicConfig()
logger = logging.getLogger("Slither")
@ -19,7 +17,7 @@ slither_simil_usage = "USAGE" # TODO
modes = ["info", "test", "train"]
def parse_args():
parser = argparse.ArgumentParser(description='',
parser = argparse.ArgumentParser(description='Code similarity detection tool',
usage=slither_simil_usage)
parser.add_argument('mode',

@ -11,6 +11,8 @@ from slither.solc_parsing.variables.state_variable import *
from slither.solc_parsing.variables.local_variable import *
from slither.solc_parsing.variables.local_variable_init_from_tuple import *
logger = logging.getLogger("Slither-simil")
def load_contracts(dirname, ext=None):
r = []
walk = list(os.walk(dirname))
@ -121,7 +123,6 @@ def encode_ir(ir):
# default
else:
print(type(ir),"is missing encoding!")
#sys.exit(1)
return ''
def encode_contract(filename, solc):
@ -131,7 +132,7 @@ def encode_contract(filename, solc):
try:
slither = Slither(filename, solc=solc)
except:
print("Compilation failed")
logger.error("Compilation failed")
return r
# Iterate over all the contracts
@ -152,17 +153,11 @@ def encode_contract(filename, solc):
# Iterate over the nodes of the function
for node in function.nodes:
# Print the Solidity expression of the nodes
# And the SlithIR operations
if node.expression:
#print('\tSolidity expression: {}'.format(node.expression))
#print('\tSlithIR:')
for ir in node.irs:
#print(ir)
r[x].append(encode_ir(ir))
#print('\t\t\t{}'.format(ir))
return r

@ -6,7 +6,7 @@ from fastText import load_model
from .encode import encode_contract
logging.basicConfig()
logger = logging.getLogger("Slither")
logger = logging.getLogger("Slither-simil")
def info(args):

@ -10,7 +10,7 @@ from .encode import encode_contract, load_contracts
from .cache import load_cache, save_cache
from .similarity import similarity
logger = logging.getLogger("crytic-pred")
logger = logging.getLogger("Slither-simil")
def test(args):
@ -28,6 +28,9 @@ def test(args):
sys.exit(-1)
irs = encode_contract(filename,solc=solc)
if len(irs) == 0:
sys.exit(-1)
x = "-".join([filename,contract,fname])
y = " ".join(irs[x])

@ -7,7 +7,7 @@ import operator
from fastText import train_unsupervised
from .encode import encode_contract, load_contracts
logger = logging.getLogger("crytic-pred")
logger = logging.getLogger("Slither-simil")
def train(args):

Loading…
Cancel
Save