IDA脚本——输出所有函数名称和地址

本博客由闲散白帽子胖胖鹏鹏胖胖鹏潜力所写,仅仅作为个人技术交流分享,不得用做商业用途。转载请注明出处,未经许可禁止将本博客内所有内容转载、商用。      

我们在使用IDA的时候,经常要对分析好的函数结果进行导出,结合其他软件比如OD或者其他二进制分析工具使用,这里我提供一个python脚本,能够将IDA中所有的函数名称和地址提取出来,并且输出成sqlite3数据库,这样即使是函数数量比较多的情况下,也能够轻松导入。

# -*- coding: utf-8 -*-
"""
Transfer ida function name text file to database.
We can use this to store our function name information.
So we can save time when we recogenize function in Angr.
"""
import os
import sqlite3

from idaapi import *
from idautils import *
from idc import *

def main(filename):
    if os.path.exists(filename):
        try :
            os.remove(filename)
            Message("Previous Database %s has removed\n" % filename)
        except:
            Message("Error! Can not remove file.")
    
    # create new database
    db = sqlite3.connect(filename)
    cur = db.cursor()
    sql_create = """create table if not exists functions(
                            id integer primary key,
                            address text unique,
                            name varchar(255))"""
    cur.execute(sql_create)
    
    sql_insert = "insert into functions (address, name) values (?, ?)"
    # enum functions
    func_list = Functions()
    
    for func in func_list:
        name = GetFunctionName(func)
        cur.execute(sql_insert,(func,name))
    Message("We have handled %d functions. " % len(list(Functions())))
    db.commit()
    db.close()

if __name__=="__main__":
    f = AskFile(1,"*.sqlite","Select the output file")
    if BADADDR == f :
        Warning("AskFile Failed!")
    else:
        main(f)

猜你喜欢

转载自blog.csdn.net/zhuzhuzhu22/article/details/81084355