吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1219|回复: 27
上一主题 下一主题
收起左侧

[IDA Plugin] WingMan - IDA 逆向分析 AI 插件

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



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







C++ 代码

[C++] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#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"
};





WingMan.rar

359.04 KB, 下载次数: 52, 下载积分: 吾爱币 -1 CB

售价: 1 CB吾爱币  [记录]

免费评分

参与人数 7吾爱币 +5 热心值 +7 收起 理由
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-14 12:02
The IDA Feeds plugin (D:/2025/IDA/plugins/ida_feeds/ida_feeds.py) requires the IDA library for full functionality. Without the library, multi-core analysis will not be available. For setup instructions, please refer to the README.txt file located in the idalib directory within your IDA installation folder.
D:\2025\IDA\plugins\libcurl.dll: 不是 IDA DLL 文件

加载库(D:\2025\IDA\plugins\WingMan.dll) 错误: 找不到指定的模块。
D:\2025\IDA\plugins\WingMan.dll: 无法加载文件
D:\2025\IDA\plugins\zlib1.dll: 不是 IDA DLL 文件
3#
ciker_li 发表于 2025-3-13 19:47
为啥我的阿里百炼只有100万token
4#
lizhuowu 发表于 2025-3-13 20:02
阿里百炼1000万tokens 怎么嫖的?
5#
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

为啥会这样
6#
qqycra 发表于 2025-3-13 20:57
很多大厂都有免费tokens额度,我是来回切着用
7#
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订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-3-14 18:09

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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