Skip to content

Commit

Permalink
Fixed multiple little errors and removed waste code
Browse files Browse the repository at this point in the history
  • Loading branch information
joxeankoret committed May 21, 2019
1 parent 5fe0cc0 commit e919031
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 30 deletions.
13 changes: 0 additions & 13 deletions diaphora.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,6 @@ def save_function(self, props):
except:
# key doesnt exist because it doesnt have forward references to any bb
log("Error: %s" % str(sys.exc_info()[1]))
pass

# And finally insert the functions to basic blocks relations
sql = "insert into main.function_bblocks (function_id, basic_block_id) values (?, ?)"
Expand Down Expand Up @@ -1196,10 +1195,6 @@ def check_ratio(self, ast1, ast2, pseudo1, pseudo2, asm1, asm2, md1, md2):
if self.relaxed_ratio or md1 > 10.0:
return 1.0
v4 = min((v1 + v2 + v3 + 3.0) / 4, 1.0)
elif md1 != 0 and md2 != 0 and False:
tmp1 = max(md1, md2)
tmp2 = min(md1, md2)
v4 = tmp2 * 1. / tmp1

r = max(v1, v2, v3, v4)
return r
Expand Down Expand Up @@ -1576,15 +1571,8 @@ def find_matches_in_hole(self, last, item, row):
select * from diff.functions where id = ? """ + postfix

thresold = min(0.6, float(item[5]))
done = False
for j in range(0, min(10, id1 - last)):
if done:
break

for i in range(0, min(10, id1 - last)):
if done:
break

cur.execute(sql, (id1+j, id2+i))
rows = cur.fetchall()
if len(rows) == 2:
Expand Down Expand Up @@ -1713,7 +1701,6 @@ def find_callgraph_matches_from(self, the_items, min_value):
match = the_items.pop()
ea1 = match[1]
name1 = match[2]
ea2 = match[3]
name2 = match[4]

if ea1 in dones:
Expand Down
1 change: 0 additions & 1 deletion diaphora_heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,6 @@ def check_heuristics_ratio():
#-------------------------------------------------------------------------------
def check_mandatory_fields():
mandatory = set(["name", "ratio", "category", "sql", "flags"])
fields = set()
for heur in HEURISTICS:
for field in mandatory:
if field not in heur.keys():
Expand Down
6 changes: 2 additions & 4 deletions diaphora_ida.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ def import_instruction(self, ins_data1, ins_data2):
tl.ea = ea1
tl.itp = mitp
comment = mcmt
ret = cfunc.set_user_cmt(tl, comment)
cfunc.set_user_cmt(tl, comment)
cfunc.save_user_cmts()

tmp_ea = None
Expand Down Expand Up @@ -1129,9 +1129,6 @@ def import_instruction_level(self, ea1, ea2, cur):
address1 = json.loads(diff_rows[0]["assembly_addrs"])
address2 = json.loads(diff_rows[1]["assembly_addrs"])

matches = {}
to_line = None
change_line = None
diff_list = difflib._mdiff(lines1.splitlines(1), lines2.splitlines(1))
for x in diff_list:
left, right, ignore = x
Expand Down Expand Up @@ -2413,3 +2410,4 @@ def main():

if __name__ == "__main__":
main()

1 change: 0 additions & 1 deletion jkutils/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Copyright (c) 2012-2015 Joxean Koret
"""

import sys
import random
import decimal

Expand Down
9 changes: 5 additions & 4 deletions jkutils/graph_hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def get_node_value(self, succs, preds):

def get_edges_value(self, bb, succs, preds):
ret = 1
for edge in succs:
for _ in succs:
ret *= EDGE_OUT_CONDITIONAL

for edge in preds:
for _ in preds:
ret *= EDGE_IN_CONDITIONAL

return ret
Expand Down Expand Up @@ -124,8 +124,9 @@ def calculate(self, f):
if is_call_insn(ea):
hash *= FEATURE_CALL

l = DataRefsFrom(ea)
hash *= FEATURE_DATA_REFS
l = list(DataRefsFrom(ea))
if len(l) > 0:
hash *= FEATURE_DATA_REFS

for xref in CodeRefsFrom(ea, 0):
tmp_func = get_func(xref)
Expand Down
9 changes: 2 additions & 7 deletions jkutils/kfuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def modsum(buf):
pass

class CFileStr(str):
fd = None

def __init__(self, fd):
self.fd = fd

Expand Down Expand Up @@ -85,7 +83,6 @@ def edit_distance(self, sign1, sign2):

def simplified(self, bytes, aggresive = False):
output_size = self.output_size
ignore_range = self.ignore_range
bsize = self.bsize
total_size = len(bytes)
size = (total_size/bsize) / output_size
Expand Down Expand Up @@ -113,7 +110,6 @@ def _hash(self, bytes, aggresive = False):
bsize = self.bsize
total_size = len(bytes)
rappend = ret.append
chunk_size = idx*bsize
reduce_errors = self.reduce_errors
# Calculate the sum of every block
while 1:
Expand Down Expand Up @@ -164,7 +160,6 @@ def _fast_hash(self, bytes, aggresive = False):
ret = set()

output_size = self.output_size
size = len(bytes) *1.00 / output_size
bsize = self.bsize
radd = ret.add

Expand Down Expand Up @@ -193,7 +188,6 @@ def _experimental_hash(self, bytes, aggresive = False):
bsize = self.bsize
output_size = self.output_size
size = len(bytes)
ignore_range = self.ignore_range
chunk_size = idx*self.bsize
byte = None

Expand Down Expand Up @@ -229,7 +223,6 @@ def mix_blocks(self, bytes):
ret = ""
size1 = 0
size2 = 0
total_size = len(bytes)

while 1:
size1 = idx*self.bsize
Expand Down Expand Up @@ -317,6 +310,7 @@ class kfha(kdha):
the standard python hashlib format. This is the Koret Fast Hashing Algorithm """

def __init__(self, bytes):
kdha.__init__(self)
self._bytes = bytes
self._kfd = CKoretFuzzyHashing()
self._kfd.algorithm = self._kfd._fast_hash
Expand All @@ -326,6 +320,7 @@ class ksha(kdha):
the standard python hashlib format. This is the Koret Simplified Hashing Algorithm """

def __init__(self, bytes):
kdha.__init__(self)
self._bytes = bytes
self._kfd = CKoretFuzzyHashing()
self._kfd.algorithm = self._kfd.simplified
Expand Down

0 comments on commit e919031

Please sign in to comment.