// d.cpp : 定义 DLL 应用程序的导出函数。
//
#include "stdafx.h"
//工程添加plugin.h和Ollydbg.lib,选项中添加"/j"使char为unsigned//OD约定
#include "Plugin.h"
static HINSTANCE g_hModule=NULL;//DllMain()中将dll模块句柄保存至此全局变量,也是Registerpluginclass()的参数
static char g_szPluginName[]="MyPlugin'sName";//ODBG_Plugindata()中用到插件名
static HWND g_hWndMain=NULL;//ODBG_Plugininit()中将hw赋给此全局变量
static char g_szClassName[32];//Registerpluginclass()的参数,也是CreatWindow()的参数
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM);//Registerpluginclass()的参数
//BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved);
BOOL APIENTRY DllMain(HINSTANCE hModule,DWORD fdwReason,LPVOID lpReserved)
{
if(DLL_PROCESS_ATTACH==fdwReason)
g_hModule=hModule;
return TRUE;
}
extc int _export cdecl ODBG_Plugindata(char shortname[32])
{
strcpy_s(shortname,sizeof(shortname),g_szPluginName);
return PLUGIN_VERSION;//返回插件版本号,如110
}
extc int _export cdecl ODBG_Plugininit(int ollydbgversion,HWND hw,ulong *features)
{
if(ollydbgversion<PLUGIN_VERSION)//OD无法支持插件
return -1;
g_hWndMain=hw;
//此处做一些初始化工作如注册窗口类,若失败则释放资源并返回-1
Registerpluginclass(g_szClassName,NULL,g_hModule,WndProc);//此时hbrBackground=NULL了
Addtolist(0,0,"my PluginName.v1.00");//输出到log窗口,第二个参数-1:低亮,0:正常,1:高亮
Addtolist(0,-1," Copyright (C) 2010 Claud");
//if(Plugingetvalue(VAL_RESTOREWINDOWPOS)!=0 && Pluginreadintfromini(hinst,"Restore Our Plugin Window",0)!=0)
//如果恢复窗口位置的标志非0且OD配置文件中有恢复插件窗口的语句
//在此CreateOurPluginWindow();
return 0;
}
//可选回调_________________________________________________________________________________
extc int _export cdecl ODBG_Pluginmenu(int origin, char data[4096],void *item)
{
//origin标示在哪个窗口创建菜单,data定义菜单项目和显示格式,item指向选定元素或数据窗口的描述符
t_dump *pd;
switch(origin)
{
case PM_MAIN:
strcpy_s(data,sizeof(data),"0 &菜单项0字符串,1 &菜单项1字符串|2 &菜单项2字符串,");
//strcpy_s(data,"#弹出式菜单名{0 &菜单项0字符串,1 &菜单项1字符串|2 &菜单项2字符串}");
return 1;//成功则返回1
case PM_DISASM:
pd=(t_dump *)item;
if(NULL==pd)
return 0;//失败则返回0
//if(pd->某某 pd->某)
//sprintf 某某某
return 1;//成功则返回1
//case ...
}
return 0;//若都未返回成功则默认返回失败
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
//窗口过程回调函数位于CreateWindow(g_szClassName,...)前
RECT rc;
PAINTSTRUCT ps;
HBRUSH hbr;
HDC dc;
switch(msg)
{
case WM_PAINT:
dc=BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rc);
hbr=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
FillRect(dc,&rc,hbr);
TextOut(dc,100,60,"Hello,world!",strlen("Hello,world!"));
DeleteObject(hbr);
EndPaint(hWnd,&ps);
break;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
return 0;
}
extc void _export cdecl ODBG_Pluginaction(int origin,int action,void *item)
{
//origin标示在哪个窗口创建菜单,action菜单项索引,item指向选定元素或数据窗口的描述符
if(origin!=PM_MAIN)
return;
switch(action)
{
case 0://菜单项0
HWND hw=CreateWindow(g_szClassName,"标题",WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,400,400,300,200,
NULL,NULL,(HINSTANCE)Plugingetvalue(VAL_HINST),NULL);//假设菜单项0为产生窗口
ShowWindow(hw,SW_SHOWNORMAL);
UpdateWindow(hw);
break;
case 1://菜单项1
WinHelp(g_hWndMain,"ourplugin.hlp",HELP_CONTENTS,0);//假设菜单项1为帮助
break;
case 2://菜单项2
MessageBox(g_hWndMain,"Some Plugin v0.10\n Written by Claud","About",MB_OK|MB_ICONINFORMATION);//假设菜单项2为关于
break;
default:
break;
}
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!