參考論文
Scalable graph-based bug search for firmware images
https://github.com/qian-feng/Gencoding
windows
1.1 安裝python2.7
https://www.python.org/downloads/release/python-2716/ 選擇32位python 。並設置環境變量。
注意,如果之前安裝過python3,只需要在環境變量上移到3之上 (where python)
1.2安裝ida.
參考 https://www.cnblogs.com/CoBrAMG/p/9198113.html 安裝。
最好按照對應版本的ida,如6.8. 注意,Genius源碼是python2寫的,需要環境為IDA6.8+PYTHON2.7(32位)
若安裝idapython7.0以上,自帶idapython,可以跳過下面1.3-----但是只能用python3的腳本。而https://github.com/qian-feng/Gencoding提供的Genius源碼是python2的,所以需要自己更改
1.3 安裝idapython
ida6.8
https://github.com/idapython/bin
idapython-1.7.2_ida6.8_py2.7_win32.zip
- 將IDAPython解壓后的Python文件夾內的所有內容覆蓋掉IDA原有Python文件夾(IDA安裝目錄下)下面的內容。
- 將IDAPython解壓后的Plugins文件夾的python.plw和python.p64拷貝到IDA原有Plugins文件夾(自定義,一般IDA安裝目錄下)下。
- 將IDAPython解壓后的python.cfg文件拷貝到IDA原有cfg文件夾(IDA安裝目錄下)下。
解決:
參考以下兩個博客,沒有解決問題
http://spd.dropsec.xyz/2016/10/04/%E5%85%B3%E4%BA%8EIDA%E6%89%BE%E4%B8%8D%E5%88%B0%E6%8C%87%E5%AE%9A%E7%9A%84%E6%A8%A1%E5%9D%97%E7%9A%84%E6%83%85%E5%86%B5/
https://hex-rays.com/blog/ida-and-common-python-issues/
更換為安裝版idapro6.8、添加dll高ida目錄等,都沒有解決問題
最后解決問題參照的方法:
https://blog.csdn.net/sdutstudent/article/details/116197661
https://zhuanlan.zhihu.com/p/102655828
idapython-1.7.2_ida6.8_py2.7_win32.zip
其實idapython寫的很清楚了,就是需要安裝32位python。之前1.1中安裝python時因為系統是64位win10,所以想當然的安裝了64位python導致錯誤。更換為32位 python2.7即可
注意更換后別忘了設置path,替換idapython/bin文件
之后就完美運行了。和是不是安裝版沒有關系、
1.4 安裝相關python庫
可能還需要安裝一些python的包。參考Genius的源碼需要哪些庫 https://github.com/qian-feng/Gencoding
如 需要為python2.7 安裝networkx
首先安裝pip
因為安裝的是2.7.16版本的python,自帶pip,只需要添加相關系統變量即可
注意如果安裝了其他版本的python,需要將2.7對應的環境變量上移
然后安裝networkx。
法一:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple networkx 目前采用法一
法二:http://www.doczj.com/doc/6ad0e24976c66137ee06196c.html
1.5 pycharm+ida 解決No module named _idaapi //嘗試運行Genius Extractor
https://github.com/qian-feng/Gencoding下載源碼。ida打開一個binary文件,file->script file,運行相關腳本,有報錯。分析后是沒有傳參
直接用ida-file-script file,除非寫死,不然不能傳參,故用pycharm 調試 dapython
https://www.programmerall.com/article/99121641505/
interpreter選擇之前安裝的python2.7.復制相關文件到pycharm項目
問題:
報錯
解決思路:
思路1:.嘗試 使用ida命令行,提供ida上下文 // linux ida運行
思路2:https://blog.csdn.net/lichao890427/article/details/52133712
使用ida都知道idapython插件,提供idc.py idaapi.py idautils.py,可以直接import進來,可以在ida運行時使用內部python插件運行 然而這幾個函數在不使用ida上下文的時候是無法使用的,會提示找不到_idaapi模塊,那么_idaapi又是哪里來的呢, 通過搜索可以發現是ida\plugin\python.plw中聲明的,因此把該文件放到%PYTHONROOT%\Lib\下面, 同時把導入的ida.wll和pytho27.dll放到%PYTHONROOT%\下,即可使用import _idaapi了,這樣,上述幾個py就可以工作了 ———————————————— 版權聲明:本文為CSDN博主「lichao890427」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。 原文鏈接:https://blog.csdn.net/lichao890427/article/details/52133712
https://answerrrrrrrrr.github.io/2016/09/20/idapython-commandline/
http://h4ck.org.cn/2012/03/ida-batch-mode/
思路三:
看ida/python/idaapi.py的源代碼
from sys import version_info if version_info >= (2,6,0): def swig_import_helper(): from os.path import dirname import imp fp = None try: fp, pathname, description = imp.find_module('_idaapi', [dirname(__file__)]) //尋找_idaapi.py except ImportError: import _idaapi return _idaapi
目前采用思路一:
在pycharmternminal
E:\BaiduNetdiskDownload\IDA_Pro_v6.8\IDA_Pro_v6.8/idaq.exe -c -S"raw-feature-extractor/preprocessing_ida.py" hpcenter (hpcenter為固件,放在pycharm項目文件夾)
還是報錯但是至少可以跑了
對應代碼
下一步就是 E:\BaiduNetdiskDownload\IDA_Pro_v6.8\IDA_Pro_v6.8/idaq.exe -c -S"raw-feature-extractor/preprocessing_ida.py --path XXX" hpcenter
這樣添加適當的參數即可
1.6 IDA命令行執行 IDApython 腳本傳參 // pycharm運行genius extractor
使用命令行,執行:
D:\IDA_Pro_68\idaq.exe -c -S"raw-feature-extractor/preprocessing_ida.py --path D:\pycharmproject\Genius\storefile" hpcenter
報錯和上面一樣
查了下 https://stackoverflow.com/questions/35591455/python-os-path-join-typeerror-object-of-type-nonetype-has-no-len
查看splitdrive函數的原型。沒解決問題
添加打印信息
發現binary_name成功識別,但是path 為None。沒輸入成功
測試代碼
import os import argparse def parse_command(): parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument("--path", type=str, help="The directory where to store the generated .ida file") args = parser.parse_args() return args if __name__ == '__main__': args = parse_command() path = args.path print path
輸出
PS D:\pycharmproject\Genius> python main.py --path "D:\pycharmproject\Genius\storefile" D:\pycharmproject\Genius\storefile PS D:\pycharmproject\Genius> python main.py --path D:\pycharmproject\Genius\storefile D:\pycharmproject\Genius\storefile
可以正常讀取參數。說明命令行格式沒問題,只是IDApython的問題導致不能讀取參數
D:\IDA_Pro_68\idaq.exe -c -S"raw-feature-extractor/preprocessing_ida.py --path D:\pycharmproject\Genius\storefile" hpcenter
解決:
思路一,沒有解決問題,但是有些幫助:
google ida的命令行模式。
idapython batch mode
找到:
https://hex-rays.com/products/ida/support/idadoc/417.shtml
IDA的官方help。得到參數的輸入格式
It is possible to pass command line arguments after the script name. For example: -S"myscript.idc argument1 \"argument 2\" argument3"
思路二:
又參考 idapython arguments
https://reverseengineering.stackexchange.com/questions/8428/idapro-the-arguments-could-not-be-passed-to-the-python-script
https://reverseengineering.stackexchange.com/questions/13286/executing-an-idapython-script-with-arguments-within-ida-pro
命令行輸入:
PS C:\Program1\pycharmproject\Genius3> E:\BaiduNetdiskDownload\IDA_Pro_v6.8\IDA_Pro_v6.8\idaq.exe -c -S"raw-feature-extractor/preprocessing_ida.py --path C:\Program1\py charmproject\Genius3\new" hpcenter
添加打印信息:
print str(sys.argv) #['raw-feature-extractor/preprocessing_ida.py'] print str(idc.ARGV) #['raw-feature-extractor/preprocessing_ida.py', '--path', 'C:\\Program1\\pycharmproject\\Genius3\\new']
輸出:
所以修改下代碼對argv的引用:
原: path = args.path 改為: path = idc.ARGV[2]
之后可以運行。對固件hpcenter提取信息如圖