zoukankan      html  css  js  c++  java
  • 给 IDA 增加导出单个汇编函数的功能

    IDA 中只能导出全部函数的汇编代码,导出速度很慢,导出的asm文件很大,不方便阅读。
    我们在逆向过程中,有时只需要导出单个函数的代码,方便分析。

    我用IDC脚本来实现,代码逻辑很简单:

    1. 首先是把光标放在函数体中的任意位置
    2. 找到函数体开始以及结束的位置
    3. 导入这个函数的代码


     1 #include <idc.idc>
     2 
     3 static get_idb_dir() {
     4   auto file_full_path = get_idb_path();  
     5   auto idbdir = qdirname(file_full_path);
     6   return idbdir;
     7 }
     8 
     9 static main() {
    10   auto cea = ScreenEA();
    11   msg("ea = 0x08%x
    ", cea);
    12 
    13   auto addr_func_start = get_func_attr(cea, FUNCATTR_START);
    14   auto addr_func_end = get_func_attr(cea, FUNCATTR_END);
    15   if (addr_func_start != -1 && addr_func_end != -1) {
    16     if (addr_func_start >= addr_func_end) {
    17       msg("ERR: start addr <= end addr");
    18       return;    
    19     }
    20 
    21     msg("func start: %08x
    ", addr_func_start);
    22     msg("func end  : %08x
    ", addr_func_end);
    23 
    24     auto filepath = sprintf("%s\func_%08x.asm", get_idb_dir(), addr_func_start);
    25     msg("path: %s
    ", filepath);
    26     auto hf = fopen(filepath, "w");
    27     if (hf != 0) {
    28       auto f = gen_file(OFILE_LST, hf, addr_func_start, addr_func_end, 0);
    29       if (f != -1) {
    30         msg("make asm file ok.
    ");
    31       } else {        
    32         msg("ERR: gen_file error.
    ");
    33       }
    34     } else {
    35       msg("ERR: fopen %s error.
    ", filepath);
    36     }
    37   } else {
    38     msg("ERR: find func error.
    ");
    39   }
    40 }

    使用方法:

    1. 将上面的文件保存为 func.idc
    2. 在IDA上面将光标放在要导出的函数体内
    3. 按下快捷键 Alt+F7, 然后选择上面的IDC文件
    4. 导出的文件放在IDB文件目录下,func_XXXX.idc


    上面的代码,我在IDA Pro 7.3 上测试通过。

    image

  • 相关阅读:
    【LeetCode OJ】Remove Element
    【LeetCode OJ】Remove Duplicates from Sorted Array
    【LeetCode OJ】Swap Nodes in Pairs
    【LeetCode OJ】Merge Two Sorted Lists
    【LeetCode OJ】Remove Nth Node From End of List
    【LeetCode OJ】Two Sum
    【LeetCode OJ】Majority Element
    最长公共子序列问题
    php fopen与file_get_contents的区别
    PHP 技巧集合
  • 原文地址:https://www.cnblogs.com/russinovich/p/13974897.html
Copyright © 2011-2022 走看看