吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8820|回复: 42
上一主题 下一主题
收起左侧

[IDA Plugin] 【修复】WingMan - IDA 逆向分析 AI 插件

  [复制链接]
跳转到指定楼层
楼主
Niuer 发表于 2025-3-13 19:19 回帖奖励
本帖最后由 Niuer 于 2025-3-15 14:47 编辑



IDAWingMan

IDAWingMan 是一个 IDA Pro 插件,宗旨在于对接Ai协助反汇编和分析任务。

SettingJson.json

使用插件时,请确保 <Your_IDA_Path>\plugins 目录下的 SettingJson 文件配置正确。

接入DeepSeek json:

{
    "Base_URL": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
    "Headers": {
        "Content-Type": "application/json",
        "Accept":"application/json",
        "Authorization": "Bearer <Your Apikey>"
    },
    "Payload": {
        "model": "deepseek-r1",
        "frequency_penalty": 0,
        "max_tokens": 512,
        "stream": false,
        "messages": []
    }
}

自行修改或扩展

快捷键:

Ctrl + Q

参考文献

https://github.com/allthingsida/ida-cmake

https://vaclive.party/software/ida-pro/releases/

https://docs.hex-rays.com/9.0




依赖没有选择静态编译版,给兄弟们道歉,
这次不收费了,自行下载吧
测试支持IDA Pro 9.0 Rc1 ,IDA Pro 9.0 Sp1
低于9.0版本请稍息,最新9.1我没还测试 如果能用反馈一下


成品: WingMan.rar (1.92 MB, 下载次数: 140)



C++ 代码

[C++] 纯文本查看 复制代码
#include <ida.hpp>
#include <idp.hpp>
#include <loader.hpp>
#include <kernwin.hpp>
#include <diskio.hpp>

#include <string>
#include <iostream>
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <curl/curl.h>
#include <thread>
#include <mutex>

using namespace rapidjson;
using namespace std;

mutex mtx;

Document Read_SettingJson() {
    char plugin_dir[QMAXPATH];
    getsysfile(plugin_dir, sizeof(plugin_dir), "plugins/SettingJson.json", nullptr);

    linput_t* file = open_linput(plugin_dir, false);
    if (!file) {
        msg("WingMan Error: Failed to open configuration file: %s\n", plugin_dir);
        return Document();
    }

    qoff64_t fileSize = qlsize(file);
    if (fileSize == 0) {
        close_linput(file);
        msg("WingMan Error: Configuration file is empty.\n");
        return Document();
    }

    string content;
    content.resize(fileSize);
    lread(file, &content[0], fileSize);
    close_linput(file);

    Document document;
    ParseResult result = document.Parse(content.c_str());
    if (!result) {
        msg("WingMan Error: Failed to parse JSON file. Error code: %u\n", result.Code());
        return Document();
    }

    msg("WingMan Configuration file loaded successfully.\n");
    msg(u8R"(
---------------------------------------------------------------------
|        __        __ _                 __  __                      |
|        \ \      / /(_) _ __    __ _  |  \/  |  __ _  _ __         |
|         \ \ /\ / / | || '_ \  / _` | | |\/| | / _` || '_ \        |
|          \ V  V /  | || | | || (_| | | |  | || (_| || | | |       |
|           \_/\_/   |_||_| |_| \__, | |_|  |_| \__,_||_| |_|       |
|                               |___/                               |
|-------------------------------------------------------------------|
|      Author      :  81NewArk81                                    |
|-------------------------------------------------------------------|
|                                                                   |
|      GitHub      :  https://github.com/81NewArk/IDAWingMAN        |
|                                                                   |
|-------------------------------------------------------------------|
|      Description                                                  |
|-------------------------------------------------------------------|
|          WingMan is an IDA Pro plugin designed to assist with     |
|      disassembly and analysis tasks.                              |
|          Using the plugin, please ensure that the SettingJson.    |
|      file in the plugins directory is properly configured.        |
|          Support the POST method for integrating with large       |
|      models that comply with the OpenAI SDK.                      |
|           Hotkey: Ctrl + Q .                                      |
---------------------------------------------------------------------
)");
    return document;
}

string Get_BaseURL(const Document& settings) {
    if (!settings.HasMember("Base_URL") || !settings["Base_URL"].IsString()) {
        msg("WingMan Error: Missing or invalid 'Base_URL' in configuration\n");
        return "";
    }
    return settings["Base_URL"].GetString();
}

string Get_Headers(const Document& settings) {
    if (!settings.HasMember("Headers") || !settings["Headers"].IsObject()) {
        msg("WingMan Error: Missing or invalid 'Headers' in configuration\n");
        return "";
    }
    StringBuffer buffer;
    Writer<StringBuffer> writer(buffer);
    settings["Headers"].Accept(writer);
    return buffer.GetString();
}

string Get_Payload(const Document& settings) {
    if (!settings.HasMember("Payload") || !settings["Payload"].IsObject()) {
        msg("WingMan Error: Missing or invalid 'Payload' in configuration\n");
        return "";
    }
    StringBuffer buffer;
    Writer<StringBuffer> writer(buffer);
    settings["Payload"].Accept(writer);
    return buffer.GetString();
}

Value Construct_Payload_Messages(const string& message, Document::AllocatorType& allocator) {
    Value messages(kArrayType);

    Value systemMessage(kObjectType);
    systemMessage.AddMember("role", "system", allocator);
    systemMessage.AddMember("content", "You are a helpful assistant.", allocator);
    messages.PushBack(systemMessage, allocator);

    Value userMessage(kObjectType);
    userMessage.AddMember("role", "user", allocator);
    userMessage.AddMember("content", StringRef(message.c_str()), allocator);
    messages.PushBack(userMessage, allocator);

    return messages;
}

string Construct_Payload(const string& message, const Document& settings) {
    string payload = Get_Payload(settings);
    if (payload.empty()) {
        return "";
    }
    Document document;
    document.Parse(payload.c_str());

    if (!document.HasMember("messages") || !document["messages"].IsArray()) {
        msg("WingMan Error: 'messages' field not found in payload\n");
        return "";
    }

    Document::AllocatorType& allocator = document.GetAllocator();
    document["messages"] = Construct_Payload_Messages(message, allocator);

    StringBuffer buffer;
    Writer<StringBuffer> writer(buffer);
    document.Accept(writer);
    return buffer.GetString();
}

string Extract_Content(const string& jsonContent) {
    Document document;
    ParseResult result = document.Parse(jsonContent.c_str());
    if (!result) {
        msg("WingMan Error: Failed to parse response JSON. Error code: %u\n", result.Code());
        return "WingMan Error: Failed to parse response JSON.";
    }
    if (!document.HasMember("choices") || !document["choices"].IsArray() || document["choices"].Empty()) {
        msg("WingMan Error: Invalid response format\n");
        return "WingMan Error: Invalid response format";
    }
    const Value& choices = document["choices"];
    if (!choices[0].HasMember("message") || !choices[0]["message"].HasMember("content")) {
        msg("WingMan Error: Missing 'message' or 'content' field in response\n");
        return "WingMan Error: Missing 'message' or 'content' field in response";
    }
    return choices[0]["message"]["content"].GetString();
}

size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
    ((string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

string Send_Post(const string& url, const string& payload, const string& headers) {
    CURL* curl;
    CURLcode res;
    string readBuffer;

    curl_global_init(CURL_GLOBAL_DEFAULT);
    curl = curl_easy_init();
    if (curl) {
        struct curl_slist* headers_list = nullptr;
        Document headersDoc;
        headersDoc.Parse(headers.c_str());
        for (Value::ConstMemberIterator itr = headersDoc.MemberBegin(); itr != headersDoc.MemberEnd(); ++itr) {
            string header = itr->name.GetString();
            header += ": ";
            header += itr->value.GetString();
            headers_list = curl_slist_append(headers_list, header.c_str());
        }

        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload.c_str());
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers_list);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
        res = curl_easy_perform(curl);

        if (res != CURLE_OK) {
            lock_guard<mutex> guard(mtx);
            msg("WingMan Error: Failed to send POST request. CURL error: %s\n", curl_easy_strerror(res));
        }
        else {
            lock_guard<mutex> guard(mtx);
        }

        curl_slist_free_all(headers_list);
        curl_easy_cleanup(curl);
    }
    else {
        lock_guard<mutex> guard(mtx);
        msg("WingMan Error: Failed to initialize CURL.\n");
    }

    curl_global_cleanup();
    return readBuffer;
}

void Process_Request(const string& url, const string& payload, const string& headers) {
    string response_json = Send_Post(url, payload, headers);
    lock_guard<mutex> guard(mtx);
    msg("\n------------------------------------------------------------------\n\n\nWingMan  Response:\n------------------------------------------------------------------\n%s\n\n", Extract_Content(response_json).c_str());
}

struct plugin_ctx_t : public plugmod_t {
    bool idaapi run(size_t) override {
        msg("WingMan Loading configuration...\n");

        Document settings = Read_SettingJson();
        if (settings.IsNull()) {
            msg("WingMan Error: Configuration loading failed.\n");
            return false;
        }

        string url = Get_BaseURL(settings);
        if (url.empty()) {
            msg("WingMan Error: Failed to get Base URL from configuration.\n");
            return false;
        }

        string headers = Get_Headers(settings);
        if (headers.empty()) {
            msg("WingMan Error: Failed to get Headers from configuration.\n");
            return false;
        }

        qstring disasm_code;
        ea_t start_ea, end_ea;
        bool has_selection = read_range_selection(nullptr, &start_ea, &end_ea);
        if (has_selection) {
            for (ea_t ea = start_ea; ea < end_ea; ea = next_head(ea, end_ea)) {
                qstring disasm_line;
                if (generate_disasm_line(&disasm_line, ea, GENDSM_REMOVE_TAGS)) {
                    tag_remove(&disasm_line);
                    disasm_code.cat_sprnt("%a: %s\n", ea, disasm_line.c_str());
                }
            }

            if (disasm_code.empty()) {
                msg("WingMan Error: No code selected.\n");
                return false;
            }
        }

        qstring input_qstr;
        if (ask_text(&input_qstr, 2048, "", "Enter Prompt:")) {
            string user_input = input_qstr.c_str();
            string prompt = has_selection ? "Disassembly:\n" + string(disasm_code.c_str()) + "\n" + user_input : user_input;

            msg("\nPrompt:\n------------------------------------------------------------------\n%s\n\n", prompt.c_str());

            string payload = Construct_Payload(prompt, settings);
            msg("------------------------------------------------------------------\nPlease wait for Ai to think......");
            thread request_thread(Process_Request, url, payload, headers);
            request_thread.detach();
        }
        else {
            msg("WingMan No prompt entered\n");
        }

        return true;
    }
};


plugin_t PLUGIN = {
    IDP_INTERFACE_VERSION,
    PLUGIN_UNL | PLUGIN_MULTI,
    []()->plugmod_t* { return new plugin_ctx_t; },
    nullptr,
    nullptr,
    nullptr,
    nullptr,
    "WingMan",
    "Ctrl+Q"
};





免费评分

参与人数 10吾爱币 +8 热心值 +8 收起 理由
lsc987 + 1 谢谢@Thanks!
zhishenghuanxia + 1 + 1 用心讨论,共获提升!
yp17792351859 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
taylorchen + 1 + 1 谢谢@Thanks!
xiaoweng + 1 + 1 我很赞同!
kuiur0810 + 1 + 1 我很赞同!
st0rm + 1 + 1 谢谢 @Thanks!
niu1995 + 1 热心回复!
cns1rius + 1 谢谢@Thanks!
lizhuowu + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

来自 2#
 楼主| Niuer 发表于 2025-3-13 19:22 |楼主
本帖最后由 Niuer 于 2025-3-13 19:27 编辑

忘了说了 基于IDA 9.0 sdk开发的,ida版本 >=9.0  低于这个版本的请稍息,
还有就是api key,我嫖的阿里百炼1000万tokens
推荐
qwer6595123 发表于 2025-3-13 22:14
推荐
大宇_ 发表于 2025-3-15 15:31
Niuer 发表于 2025-3-15 14:46
已经修复 欢迎测试

D:\Working\IDA\plugins\ida_feeds\ida_feeds.py: name 'IdaPluginForm' is not defined
Traceback (most recent call last):
  File "D:\Working\IDA\python\ida_idaapi.py", line 574, in IDAPython_ExecScript
    exec(code, g)
    ~~~~^^^^^^^^^
  File "D:/Working/IDA/plugins/ida_feeds/ida_feeds.py", line 45, in <module>
    class IdaMainWindow(IdaPluginForm):
                        ^^^^^^^^^^^^^
NameError: name 'IdaPluginForm' is not defined


加载库(D:\Working\IDA\plugins\libcurl.dll) 错误: 找不到指定的模块。
D:\Working\IDA\plugins\libcurl.dll: 无法加载文件

  字节   页面 大小 说明
--------- ----- ---- --------------------------------------------
30523392  3726 8192 为 b-tree 分配内存...
19685376  2403 8192 为虚拟数组分配内存...
   262144    32 8192 为名称指针分配内存...
-----------------------------------------------------------------
50470912            分配的总内存

正在加载处理器模块 D:\Working\IDA\procs\pc.dll for metapc...正在初始化处理器模块 metapc...OK
正在加载类型库...
自动分析子系统已初始化。
D:\Working\IDA\plugins\ida_feeds\ida_feeds.py: name 'IdaPluginForm' is not defined
Traceback (most recent call last):
  File "D:\Working\IDA\python\ida_idaapi.py", line 574, in IDAPython_ExecScript
    exec(code, g)
    ~~~~^^^^^^^^^
  File "D:/Working/IDA/plugins/ida_feeds/ida_feeds.py", line 45, in <module>
    class IdaMainWindow(IdaPluginForm):
                        ^^^^^^^^^^^^^
NameError: name 'IdaPluginForm' is not defined


加载库(D:\Working\IDA\plugins\libcurl.dll) 错误: 找不到指定的模块。
D:\Working\IDA\plugins\libcurl.dll: 无法加载文件
已加载文件 'Neuz.exe' 的数据库
Hex-Rays Decompiler plugin has been loaded (v9.0.0.240925)
  The hotkeys are F5: decompile, Ctrl-F5: decompile all.

  Please check the Edit/Plugins menu for more information.
D:\Working\IDA\plugins\ida_feeds\ida_feeds.py: name 'IdaPluginForm' is not defined
Traceback (most recent call last):
  File "D:\Working\IDA\python\ida_idaapi.py", line 574, in IDAPython_ExecScript
    exec(code, g)
    ~~~~^^^^^^^^^
  File "D:/Working/IDA/plugins/ida_feeds/ida_feeds.py", line 45, in <module>
    class IdaMainWindow(IdaPluginForm):
                        ^^^^^^^^^^^^^
NameError: name 'IdaPluginForm' is not defined

Hex-rays version 9.0.0.240925 has been detected, gooMBA plugin ready to use
D:\Working\IDA\plugins\ida_feeds\ida_feeds.py: name 'IdaPluginForm' is not defined
Traceback (most recent call last):
  File "D:\Working\IDA\python\ida_idaapi.py", line 574, in IDAPython_ExecScript
    exec(code, g)
    ~~~~^^^^^^^^^
  File "D:/Working/IDA/plugins/ida_feeds/ida_feeds.py", line 45, in <module>
    class IdaMainWindow(IdaPluginForm):
                        ^^^^^^^^^^^^^
NameError: name 'IdaPluginForm' is not defined


加载库(D:\Working\IDA\plugins\libcurl.dll) 错误: 找不到指定的模块。
D:\Working\IDA\plugins\libcurl.dll: 无法加载文件
608E3D: restored microcode from idb
608E3D: restored pseudocode from idb
---------------------------------------------------------------------------------------------
Python 3.13.2 (tags/v3.13.2:4f8bb39, Feb  4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)]
IDAPython 64-bit v9.0.0 final (serial 0) (c) The IDAPython Team <idapython@googlegroups.com>
---------------------------------------------------------------------------------------------
4#
ciker_li 发表于 2025-3-13 19:47
为啥我的阿里百炼只有100万token
5#
lizhuowu 发表于 2025-3-13 20:02
阿里百炼1000万tokens 怎么嫖的?
6#
Dahl 发表于 2025-3-13 20:03
LoadLibrary(E:\IDA9.0\plugins\WingMan.dll) error: 找不到指定的模块。
E:\IDA9.0\plugins\WingMan.dll: can't load file
E:\IDA9.0\plugins\zlib1.dll: not IDA DLL file

为啥会这样
7#
qqycra 发表于 2025-3-13 20:57
很多大厂都有免费tokens额度,我是来回切着用
8#
jrtz 发表于 2025-3-13 21:37
非常NB,赞!
9#
Say 发表于 2025-3-13 23:45
libcurl.dll  error: %1 不是有效的 Win32 应用程序。

WingMan.dll error: 找不到指定的模块。






10#
 楼主| Niuer 发表于 2025-3-14 00:31 |楼主
Say 发表于 2025-3-13 23:45
libcurl.dll  error: %1 不是有效的 Win32 应用程序。

WingMan.dll error: 找不到指定的模块。

哪个版本
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-11-16 12:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表