BinDiff

import subprocess
import sys
import os

BINDIFF_PATH = "C:\\Program Files\\zynamics\\BinDiff 4.2\\bin\\differ.exe"
IDAQ_PATH = "C:\\Program Files\\IDA 6.9\\idaq.exe"

if len(sys.argv) < 3:
	print "Usage: python diff_binaries.py $bin1 $bin2"
	sys.exit(1)

bindiff_script_path = os.getcwd() + os.sep + "bindiff_export.idc"

dir_path = os.getcwd() + os.sep

name_one = dir_path + sys.argv[1].split('.')[0]
name_two = dir_path + sys.argv[2].split('.')[0]


subprocess.call([IDAQ_PATH,"-B","-P+",sys.argv[1]])
subprocess.call([IDAQ_PATH,"-OExporterModule:" + name_one,"-S\"" + bindiff_script_path +"\"", name_one + ".idb"])
subprocess.call([IDAQ_PATH,"-B","-P+",sys.argv[2]])
subprocess.call([IDAQ_PATH,"-OExporterModule:" + name_two,"-S\"" + bindiff_script_path +"\"", name_two + ".idb"])

subprocess.call([BINDIFF_PATH,"-log_format", "--primary", name_one + ".BinExport", "--secondary", name_two + ".BinExport"])

-log_format加上的话输出.txt格式,不加输出.BInDiff格式。后者实质是一个sqlite3数据库。

BinExport可以在IDA中通过插件获取,也可以在IDA的Output window中输入load_and_run_plugin("binexport10", 1)

获取bindiff比较结果

sqllink = sqlite3.connect(bindiff_path)
#获取数据库中的表
table=sqllink.execute("select name from sqlite_master where type='table' order by name")
print table.fetchall()
algorithm=sqllink.execute("PRAGMA table_info(functionalgorithm)")

print algorithm.fetchall()
functioninfo = sqllink.execute('select address1,address2,similarity,confidence,algorithm from function')
#获取函数匹配使用的匹配算法类型
algorithm=sqllink.execute('select * from functionalgorithm')
function_algorithm=[]
for alg in algorithm:
    item_list_buf = list(alg)
    function_algorithm.append(item_list_buf[1])
#获取函数匹配信息,函数1,函数2,相似度,置信度,算法类型
for each_item in functioninfo:
    item_list_buf = list(each_item)
    similarity = "%.2f" % item_list_buf[2]
    confidence= "%.2f" % item_list_buf[3]
    algorithm=function_algorithm[int(item_list_buf[4])-1]#算法从下标1开始
    item_list = [hex(item_list_buf[0]),hex(item_list_buf[1]),similarity,confidence,str(algorithm)]
    result_list.append(item_list)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值