首页
社区
课程
招聘
[原创] ida脚本开发环境配置idapython&idacpp三端环境(win,mac,linux)
2023-12-7 14:11 9852

[原创] ida脚本开发环境配置idapython&idacpp三端环境(win,mac,linux)

2023-12-7 14:11
9852

写ida脚本也有一段时间了,一直有个痛点是找不到比较好的方法热重载脚本来实时改动生效,导致开发效率老慢了。固总结下比较友好的环境搭配

ida脚本开发,使用ida热加载插件让你开发脚本更高效

github地址: https://github.com/0xeb/ida-qscripts, 这位老外是个知名视频网站小博主,挺多小妙招的

1.下载源码:

1
2
3
4
5
6
7
//1.下载 ida-cmake
cd /path/to/ida/idasdk/plugins && git clone  https://github.com/0xeb/ida-cmake
//2.下载 ida-qscripts
cd /path/to/ida/idasdk/plugins && git clone https://github.com/0xeb/ida-qscripts
//3.下载idax
cd /path/to/ida/idasdk/plugins/ida-qscripts &&
git clone https://github.com/0xeb/idax

2.编译:

  • mac or linux 环境

    1
    2
    3
    4
    5
    6
    //1.环境变量添加 IDASDK
    //mac or linux
    export IDASDK=/path/to/ida/idasdk
    //2.clion 直接打开 ida-qscripts
    //3.clion -- settings -- build,execution,deployment 中 新增配置,并设置 cmake ida插件变量(64位的需要)
    //4.将编译出来的 qscripts.dylib qscripts64.dylib or qscripts.so qscripts.so 手动复制到 /path/to/ida/plugins 中,重启ida即生效

    图片描述

  • windows 环境

    1
    2
    3
    4
    //1.设置环境变量
    setx IDASDK /path/to/ida/idasdk
    //2.使用visual studio打开,测试环境为vs2022,打开后在cmakefile中看情况设置
    //3.vs 点击 项目--> qscripts的 CMake设置,在下面设置才能编译64位的dll

    图片描述

    1
    //4.将 qscripts.dll qscripts64.dll 复制到 /path/to/ida/plugins

3.运行图:

  • ida 运行图
    • mac or linux
      • 图片描述
    • windows
      • 图片描述

4.pycharm 配置 idapython开发环境

  • 代码提示配置
    • 打开pycharm的setting --> python interpreter --> showall
      • 图片描述
    • 点击这个图标
      • 图片描述
    • 添加ida目录下的python3
      • 图片描述
    • 验证
      • 图片描述
  • 动态调试
    • pycharm 新增一个remote debug
      • 图片描述
    • 点击pycharm debug按钮,此时pycharm会循环监听目标端口
    • ida打开qscripts进行加载和监听
      • 图片描述
    • 命中断点
      • 图片描述
  • 热加载
    • ida-qscripts勾选指定idapython脚本后,当修改脚本后,会触发插件reload实现重新载入脚本,自动更新上去了

5.clion 配置 idacpp开发环境(这里三个端一样)

选择cpp插件的原因肯定是性能了,毕竟开发起来麻烦,但是c++默认比py快20倍,在某些场景很难不用吧,比如一个混淆代码的块有上千个,测试用python的d810跑这种大型函数+单规则处理,耗时5分多钟,电脑cpu i9了

  • 代码提示配置
    • camkefile中添加ida目录
      • 图片描述
      • 这边导入就不报错了
        • 图片描述
  • 简单的插件模板
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <ida.hpp>
#include <idp.hpp>
#include <loader.hpp>
#include <kernwin.hpp>
 
plugmod_t *idaapi init(void)
{
  msg("Plugin initialized!\n");
  return PLUGIN_OK;
}
 
void idaapi term(void)
{
  msg("Plugin term()\n");
}
 
bool idaapi run(size_t arg)
{
  msg("Plugin run()\n");
  return true;
}
 
plugin_t PLUGIN =
{
  IDP_INTERFACE_VERSION,
  PLUGIN_UNL,    //需要这个标记,否则不触发qscripts
  init,
  term,
  run,
  "",
  "",
  "Sample plugin",
  ""
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//cmakefile 配置
cmake_minimum_required(VERSION 3.26)
project(ByeObf)
set(CMAKE_CXX_STANDARD 20)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY /Applications/IDAPro8.3/ida.app/Contents/MacOS/plugins)
 
include_directories(/Applications/IDAPro/ida.app/Contents/MacOS/plugins/hexrays_sdk/include/)
include_directories(/Applications/IDAPro/ida.app/Contents/MacOS/idasdk_pro/include/)
 
 
#导入idaapi的目录
set(PLUGIN_NAME byeobf)
set(PLUGIN_SOURCES library.h library.cpp)
set(PLUGIN_OUTPUT_NAME ${PLUGIN_NAME})
set(PLUGIN_RUN_ARGS "-t")
 
include($ENV{IDASDK}/ida-cmake/addons.cmake)
1
编译64位插件定义EA64即可
  • 修改ida-cmake的addons.cmake改编译后的插件生成目录
    • 修改 LIBRARY_OUTPUT_DIRECTORY 、RUNTIME_OUTPUT_DIRECTORY_${cfg} 属性,改为/path/to/ida/plugins
  • 热重载
    • 1.模板定义了插件名byeobf,需要创建两个文件 byeobf.py 和 byeobf.py.deps.qscripts,确保插件名要一样
    • 2.byeobf.py内容
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      import time
      import idaapi
       
      # Give the linker time to finish flushing the binary
      time.sleep(1)
       
      # Optionally clear the screen:
      #idaapi.msg_clear()
       
      # Load your plugin and pass any arg value you want
      idaapi.load_and_run_plugin('byeobf', 0)
       
      # Optionally, do post work, etc.
    • 3.deps.qscripts内容
      • 改为你要触发的插件绝对路径
      1
      /triggerfile /keep /Applications/IDAPro/ida.app/Contents/MacOS/plugins/byeobf64.dylib
    • 4.将byeobf.py 和 byeobf.py.deps.qscripts 放到 /path/to/ida/plugins
    • 5.重启ida打开qscripts,导入并双击 byeobf.py,此时你每次重新编译idacpp改动都会被自动载入到ida中了
    • 6.效果图请看 ida-qscripts项目
  • 搭配热重载动态调试
    • 1.clion --> run --> Attach to Process --> 选择你的ida进程号, 后续这个附加不用关闭
    • 2.设置断点
    • 3.触发等待命中,开始愉快的带着debug环境开发吧!

6.vs 配置 idacpp开发环境 idapython环境

1
- 这里大差不差都参考上述改动即可

ida-win 7.7下载: https://bbs.kanxue.com/thread-276531.htm


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2023-12-26 11:06 被初恒编辑 ,原因: 1.修改clion 热重载的文件配置名,之前打错字了。2.验证了该插件在idacpp + clion开发的时候是可以热重载并且一直附加调试的,就是可以带着debug信息修改插件逻辑,而不是通过日志一直使劲猜,我没那么多头发可以掉。
收藏
点赞15
打赏
分享
最新回复 (8)
雪    币: 407
活跃值: (965)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
初恒 2023-12-7 14:51
2
0
这敏感词到底是哪个噢
雪    币: 121
活跃值: (1517)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
xxRea 2023-12-12 20:56
3
0
感谢分享
雪    币: 864
活跃值: (606)
能力值: ( LV6,RANK:80 )
在线值:
发帖
回帖
粉丝
八岛 1 2024-1-30 17:24
4
0
感谢,非常有用
雪    币: 19539
活跃值: (29224)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
秋狝 2024-1-31 09:35
5
1
感谢分享
雪    币: 2097
活跃值: (3802)
能力值: ( LV6,RANK:80 )
在线值:
发帖
回帖
粉丝
st0ne 1 2024-1-31 09:48
6
0
感谢分享
雪    币: 18
活跃值: (891)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
bullyxy 2024-2-27 16:09
7
0

用 pycharm 来调试 ida 脚本,在代码中插入下面代码连接 pycharm

```

if DEBUG:
    import pydevd_pycharm
    pydevd_pycharm.settrace('localhost', port=2222, stdoutToServer=True, stderrToServer=True)

```

就会显示这个

我明明是同一个文件,为啥会这样呢?

最后于 2024-2-27 16:10 被bullyxy编辑 ,原因:
雪    币: 18
活跃值: (891)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
bullyxy 2024-2-27 16:11
8
0
配置也是一样的
雪    币: 407
活跃值: (965)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
初恒 2024-2-27 16:37
9
0
这个是python弹了异常,但是pycharm调试的时候跳不到源码那里吧,就弹这个错。 自己调试的时候记住触发这个错的那一行,不让他触发就好了。
游客
登录 | 注册 方可回帖
返回