首页
社区
课程
招聘
关于在IDA插件中调用windows API 以及 实现消息循环机制
发表于: 2008-4-8 00:13 7769

关于在IDA插件中调用windows API 以及 实现消息循环机制

2008-4-8 00:13
7769
我的想法是自己编写一个IDA的插件,在插件中调用windows的API来实现框架和界面 当启动该插件的时候 就弹出我写的界面 并在该界面中可以调用IDA SDK的接口实现相应的功能.
我现在不清楚的有:
(1)能不能在IDA中调用windows的API? 以及实现windows的消息循环机制?
(2)能不能调用自己编写的dll? 用来通过调用外部的模块实现其他的功能(比如病毒扫描模块实现病毒扫描)?

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (7)
雪    币: 254
活跃值: (15)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
BeQuick,你的想法很不错,以前参考过一篇用
Win API编写插件的文档,但现在怎么也找不到了,
好像看雪论坛里面的朋友翻译过这篇文章,里面的
示例代码还调用了CreateThread函数。
   方法如下:
   在所有#include IDA的头文件预编译指令
之前,加上#include <windows.h>,不这样
做,可能会出现一些编译错误。

比如下面这些插件常用到的预编译包含指令,

#include <windows.h> //这里最好是把windows.h放到最前面,

#include <ida.hpp>
#include <idp.hpp>
#include <expr.hpp>
#include <bytes.hpp>
#include <loader.hpp>
#include <kernwin.hpp>

附件是一份修改自IDA SDK中vcsample的源代码,
运行效果如下图,



这份代码很简单地调用了MessageBox显示一个对话框。
vcsample.rar
上传的附件:
2008-4-10 16:18
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
学习。。。。
2008-4-10 16:22
0
雪    币: 208
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
谢谢terren的热心回复。这个问题我几经解决了,并且测试成功。

实际上,IDA Plug-in本身就是一个DLL, 只不过要用到IDA SDK提供的头文件和.lib库。所以在IDA Plug-in中完全可以像其他的DLL一样调用windows的DLL、实现windows消息循环。

你的回复中提到了一点:#include <windows.h>这条语句必须放在最前面。这点非常重要,否则,编译会报许多头文件的错误(我是用VS2005编译的)。具体是什么原因,我想这可能与windows.h里定义的宏有关,需要将这些宏放在最前面。

还有一点需要注意的,在插件中实现消息循环不同于普通的VC/VC++程序,因为在普通的VC/VC++程序(非MFC)实现消息循环,要定义WinMain()函数,而WinMain()函数是由操作系统调用的,就像C程序中的main()函数一样; 而在插件中,需要在IDA Plug-in的IDAP_run()中自己编写程序调用。 解决的方法是自己编写类似于WinMain()的函数,然后在IDAP_run()种调用,如下:
......
HINSTANCE hInstance;  //全局变量,用来存放该进程模块的句柄
......
void IDAP_run(int arg)

        ......

        HINSTANCE hInstance = LoadLibrary(NULL);
        MyWinMain(hInstance,  NULL, 1);

        ......

......
int WINAPI MyWinMain(HINSTANCE hInstance, LPSTR lpCmdLine, int nShowCmd)
{
//实现普通的VC/VC++程序中WinMain()实现的功能
}
......

然后在自己编写的类似于WinMain()的函数中实现消息循环。

~~以上我的经验,欢迎分享~~
~~再次感谢楼上的热心回复!~~
2008-4-11 20:13
0
雪    币: 254
活跃值: (15)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
5
祝贺你实验成功,:)
   你用IDA插件实现Windows消息循环怎么样了?
2008-4-11 22:07
0
雪    币: 208
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
在IDA插件中可以实现和普通windows应用程序(Application)一样的消息循环机制。具体需要注意的我已经在上一个帖子中描述了。
2008-4-12 22:05
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
我正在写一个IDA的插件,也用SDK,基本思想是定义两个类,在run()函数中调用这两个类的公有接口来实现我所需要的功能,现在写好了,插件也在vs2005下编译,连接通过,生成了plw文件,将生成的plw文件导入IDA中后,运行此插件,报错如下:
acdess violation at address 04114106 in module 'connector.plw' ;read of address 000000

我的源文件如下:
plugin.cpp文件
#include<windows.h>

#include<string>
#include<vector>
using std::string;
using std::vector;

#include<ida.hpp>
#include<idp.hpp>
#include<ua.hpp>
#include <bytes.hpp>
#include <expr.hpp>
#include <frame.hpp>
#include <kernwin.hpp>
#include <loader.hpp>
#include <name.hpp>

#pragma warning (disable:4273)
#pragma warning (disable:4996)
#pragma warning (disable:4819)

#include "basic_block.h"
#include "proc.h"

////////////////////////////////////////////////////////////////////////////
//_connector_init()
int _connector_init(void)
{
        // this connector now only works with metapc (x86) CPU types.
    if(strcmp(inf.procName, "metapc") != 0)
    {
        msg("[!] Detected an incompatible non-metapc CPU type: %s\n", inf.procName);
        return PLUGIN_SKIP;
    }

    return PLUGIN_KEEP;
}

/////////////////////////////////////////////////////////////////////////////
//_connector_run(int arg)
void _connector_run(int arg)
{
        proc *procPointer;
        int pid;
        // ensure we are within the confines of a known function.
        //get_screen_ea()返回光标处的地址
    if ((pid = get_func_num(get_screen_ea())) == -1)  
    {
        warning("Current screen effective address:\n\n"
                "          0x%08x\n\n"                                                        //0x%08x是输出内存地址的格式标识
                "does not lie within a known function.",
                get_screen_ea());
        return;
    }

        procPointer=new proc(pid);
        procPointer->CFG_analysis();
        procPointer->CFG_result_print();

        delete procPointer;
}

/////////////////////////////////////////////////////////////////////////////
//_connector_term()
void _connector_term(void)
{
}

// include the data structures that describe the plugin to IDA.
#include "connector_info.h"

connector_info.h文件

#ifndef __CONNECTOR_INFO_H__
#define __CONNECTOR_INFO_H__

//
// These global data items are used by IDA to display information about
// the plugin.
//

char _connector_comment[] = "IDA的连接器";

char _connector_help[] =
    "[ 连接器 ]\n"
    "\n"
    "\n"
    "\n";

// This is the preferred name of the plugin module in the menu system.
// The preferred name may be overridden in the plugins.cfg file.

char _connector_wanted_name[] = "pCONNECTOR";

// This is the preferred hot key for the plugin module.
// The preferred hot key may be overridden in the plugins.cfg file.
// Note: IDA won't tell you if the hot key is not correct.
// It will just disable the hot key.

char _connector_wanted_hotkey[] = "Alt-3";

//
// PLUGIN DESCRIPTION BLOCK
//

extern "C" plugin_t PLUGIN =
{
    IDP_INTERFACE_VERSION,
    0,                  // plugin flags.
    _connector_init,          // initialize callback.
    _connector_term,          // terminate callback. this pointer may be NULL.
    _connector_run,           // invoke plugin routine.
    _connector_comment,       // long comment about the plugin.
                        // it could appear in the status line
                        // or as a hint.
    _connector_help,          // multiline help about the plugin.
    _connector_wanted_name,   // the preferred short name of the plugin.
    _connector_wanted_hotkey  // the preferred hot key to run the plugin.
};

#endif

其中proc是自己定义的类
2008-4-29 23:10
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
调了很久都还是报错,求助各位高手,帮忙解决一下,很急的,谢谢了。
另外,请问一下调试ida插件,有什么好的调试技巧
2008-4-29 23:11
0
游客
登录 | 注册 方可回帖
返回
//