[Pascal] 纯文本查看 复制代码
library MoreTool进阶版;
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
{$WEAKLINKRTTI ON}
uses
Windows,
Messages,
SysUtils,
Vcl.Dialogs,
IniFiles,
bridgemain in 'plugin\bridgemain.pas',
_plugins in 'plugin\_plugins.pas';
// 根据平台选择DLL名称
{$IFDEF WIN64}
const
X64DBG_CORE_DLL = 'x64dbg.dll';
{$ELSE}
const
X64DBG_CORE_DLL = 'x32dbg.dll';
{$ENDIF}
{$ALIGN 1}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CAST OFF}
{$IFDEF WIN64}
{$E dp64}
{$ELSE}
{$E dp32}
{$ENDIF}
var
SaveDLLProc: TDLLProc;
g_pluginHandle: THandle = 0;
g_hMenu: Cardinal = 0;
g_hMenuDisasm: Cardinal = 0;
g_Inst: Cardinal = 0;
g_hWnD: Cardinal = 0;
g_loadedname: array[0..8] of PAnsiChar;
function ShellExecuteA(hWnd: hWnd; Operation, FileName, Parameters, Directory: PAnsiChar; ShowCmd: Integer): HINST; stdcall; external 'shell32.dll' name 'ShellExecuteA';
function _plugin_gethmenu(pluginHandle: THandle): HMENU; cdecl; external X64DBG_CORE_DLL;
function _plugin_gethmenudisasm(pluginHandle: THandle): HMENU; cdecl; external X64DBG_CORE_DLL;
function _plugin_gethmenudump(pluginHandle: THandle): HMENU; cdecl; external X64DBG_CORE_DLL;
function _plugin_gethmenustack(pluginHandle: THandle): HMENU; cdecl; external X64DBG_CORE_DLL;
const
PLUGIN_NAME: PAChar = PAnsiChar(UTF8String('牛二'));
PLUGIN_AUTH: PAChar = PAnsiChar(UTF8String('冥界3大法王'));
PLUGIN_VERS: Integer = 01;
MENU_CALC = 1;
MENU_NOTEPAD = 2;
MENU_DISASM_CALC = 3;
MENU_DISASM_NOTEPAD = 4;
MENU_LOAD_EXTERNAL_PLUGINS = 5;
MENU_DISASM_LOAD_EXTERNAL_PLUGINS = 6;
{$R MoreTool.res}
type
TPlugInit = function(PlugInitInfo: PPLUG_INITSTRUCT): Boolean; cdecl;
procedure RegisterInitProc(cbType: cbType; callbackInfo: Pointer); cdecl;
var
info: PPLUG_CB_INITDEBUG;
begin
ZeroMemory(@g_loadedname, SizeOf(g_loadedname));
info := PPLUG_CB_INITDEBUG(callbackInfo);
g_loadedname[0] := info^.szFileName;
BridgeSettingSet('Last File', 'Last', g_loadedname[0]);
end;
procedure RegisterMenuProc(cbType: cbType; callbackinfo: Pointer); cdecl;
var
info: PPLUG_CB_MENUENTRY;
IniFilePath: string;
PluginDir: string;
SearchRec: TSearchRec;
PluginName: string;
PluginHandle: THandle;
PlugInit: TPlugInit;
pInitStruct: PPLUG_INITSTRUCT;
Ini: TIniFile;
// 重新声明这些变量,确保没有语法问题
hMainWindow: THandle; // 使用THandle替代HWND,它们在Windows API中是等价的
hMenu: THandle;
hMenuDisasm: THandle;
hMenuDump: THandle;
hMenuStack: THandle;
PlugSetupFunc: function(PlugSetupInfo: PPLUG_SETUPSTRUCT): Boolean; cdecl;
pSetupStruct: PPLUG_SETUPSTRUCT;
begin
info := PPLUG_CB_MENUENTRY(callbackinfo);
case (info^.hEntry) of
MENU_LOAD_EXTERNAL_PLUGINS, MENU_DISASM_LOAD_EXTERNAL_PLUGINS:
begin
hMainWindow := GuiGetWindowHandle();
hMenu := _plugin_gethmenu(g_pluginHandle);
hMenuDisasm := _plugin_gethmenudisasm(g_pluginHandle);
hMenuDump := _plugin_gethmenudump(g_pluginHandle);
hMenuStack := _plugin_gethmenustack(g_pluginHandle);
IniFilePath := InputBox('加载外部插件', '请输入.ini文件的完整路径:', '');
if IniFilePath <> '' then
begin
try
if FileExists(IniFilePath) then
begin
Ini := TIniFile.Create(IniFilePath);
try
PluginDir := Ini.ReadString('Your_Plugins_Folder', 'Path', '');
if PluginDir <> '' then
begin
if (PluginDir <> '') and (PluginDir[Length(PluginDir)] <> '\') then
PluginDir := PluginDir + '\';
if not DirectoryExists(PluginDir) then
begin
_plugin_logprintf('[MoreTool] 插件目录不存在: %s', PAnsiChar(UTF8String(PluginDir)));
end
else
begin
if FindFirst(PluginDir + '*.dp32', faAnyFile, SearchRec) = 0 then
begin
repeat
if (SearchRec.Attr and faDirectory) = 0 then
begin
PluginName := PluginDir + SearchRec.Name;
PluginHandle := LoadLibrary(PChar(PluginName));
if PluginHandle <> 0 then
begin
@PlugInit := GetProcAddress(PluginHandle, 'pluginit');
if Assigned(PlugInit) then
begin
GetMem(pInitStruct, SizeOf(PLUG_INITSTRUCT));
try
ZeroMemory(pInitStruct, SizeOf(PLUG_INITSTRUCT));
pInitStruct^.pluginHandle := PluginHandle;
pInitStruct^.sdkVersion := PLUG_SDKVERSION;
pInitStruct^.pluginVersion := 1;
StrPLCopy(pInitStruct^.pluginName, ExtractFileName(SearchRec.Name), 256);
if PlugInit(pInitStruct) then
begin
_plugin_logprintf('[MoreTool] 成功加载插件: %s', PAnsiChar(UTF8String(SearchRec.Name)));
@PlugSetupFunc := GetProcAddress(PluginHandle, 'plugsetup');
if Assigned(PlugSetupFunc) then
begin
GetMem(pSetupStruct, SizeOf(PLUG_SETUPSTRUCT));
try
ZeroMemory(pSetupStruct, SizeOf(PLUG_SETUPSTRUCT));
pSetupStruct^.hwndDlg := hMainWindow;
pSetupStruct^.hMenu := hMenu;
pSetupStruct^.hMenuDisasm := hMenuDisasm;
pSetupStruct^.hMenuDump := hMenuDump;
pSetupStruct^.hMenuStack := hMenuStack;
PlugSetupFunc(pSetupStruct);
finally
FreeMem(pSetupStruct);
end;
end;
end
else
begin
_plugin_logprintf('[MoreTool] 插件初始化失败: %s', PAnsiChar(UTF8String(SearchRec.Name)));
FreeLibrary(PluginHandle);
end;
finally
FreeMem(pInitStruct);
end;
end
else
begin
_plugin_logprintf('[MoreTool] 找不到插件初始化函数: %s', PAnsiChar(UTF8String(SearchRec.Name)));
FreeLibrary(PluginHandle);
end;
end
else
_plugin_logprintf('[MoreTool] 加载插件失败: %s, 错误: %d', PAnsiChar(UTF8String(SearchRec.Name)), GetLastError());
end;
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
{$IFDEF WIN64}
if FindFirst(PluginDir + '*.dp64', faAnyFile, SearchRec) = 0 then
begin
repeat
if (SearchRec.Attr and faDirectory) = 0 then
begin
PluginName := PluginDir + SearchRec.Name;
PluginHandle := LoadLibrary(PChar(PluginName));
if PluginHandle <> 0 then
begin
@PlugInit := GetProcAddress(PluginHandle, 'pluginit');
if Assigned(PlugInit) then
begin
GetMem(pInitStruct, SizeOf(PLUG_INITSTRUCT));
try
ZeroMemory(pInitStruct, SizeOf(PLUG_INITSTRUCT));
pInitStruct^.pluginHandle := PluginHandle;
pInitStruct^.sdkVersion := PLUG_SDKVERSION;
pInitStruct^.pluginVersion := 1;
StrPLCopy(pInitStruct^.pluginName, ExtractFileName(SearchRec.Name), 256);
if PlugInit(pInitStruct) then
begin
_plugin_logprintf('[MoreTool] 成功加载插件: %s', PAnsiChar(UTF8String(SearchRec.Name)));
@PlugSetupFunc := GetProcAddress(PluginHandle, 'plugsetup');
if Assigned(PlugSetupFunc) then
begin
GetMem(pSetupStruct, SizeOf(PLUG_SETUPSTRUCT));
try
ZeroMemory(pSetupStruct, SizeOf(PLUG_SETUPSTRUCT));
pSetupStruct^.hwndDlg := hMainWindow;
pSetupStruct^.hMenu := hMenu;
pSetupStruct^.hMenuDisasm := hMenuDisasm;
pSetupStruct^.hMenuDump := hMenuDump;
pSetupStruct^.hMenuStack := hMenuStack;
PlugSetupFunc(pSetupStruct);
finally
FreeMem(pSetupStruct);
end;
end;
end
else
begin
_plugin_logprintf('[MoreTool] 插件初始化失败: %s', PAnsiChar(UTF8String(SearchRec.Name)));
FreeLibrary(PluginHandle);
end;
finally
FreeMem(pInitStruct);
end;
end
else
begin
_plugin_logprintf('[MoreTool] 找不到插件初始化函数: %s', PAnsiChar(UTF8String(SearchRec.Name)));
FreeLibrary(PluginHandle);
end;
end
else
_plugin_logprintf('[MoreTool] 加载插件失败: %s, 错误: %d', PAnsiChar(UTF8String(SearchRec.Name)), GetLastError());
end;
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
{$ENDIF}
end;
end
else
begin
_plugin_logprintf('[MoreTool] INI文件中未找到[Your_Plugins_Folder]节或Path键');
end;
finally
Ini.Free;
end;
end
else
begin
_plugin_logprintf('[MoreTool] INI文件不存在: %s', PAnsiChar(UTF8String(IniFilePath)));
end;
except
on E: Exception do
_plugin_logprintf('[MoreTool] 加载插件时发生错误: %s', PAnsiChar(UTF8String(E.Message)));
end;
end;
end;
end;
end;
function calc(argc: Integer; argv: PPAnsiChar): Boolean; cdecl;
begin
ShellExecuteA(GuiGetWindowHandle, 'OPEN', 'calc.exe', '', 'C:\Windows\system32', SW_SHOWNORMAL);
end;
function notepad(argc: Integer; argv: PPAnsiChar): Boolean; cdecl;
begin
ShellExecuteA(GuiGetWindowHandle, 'OPEN', 'notepad.exe', '', 'C:\Windows\system32', SW_SHOWNORMAL);
end;
function x_dbg_Plugininit(PlugInitInfo: PPLUG_INITSTRUCT): Boolean; cdecl;
begin
g_pluginHandle := PlugInitInfo^.pluginHandle;
PlugInitInfo^.sdkVersion := PLUG_SDKVERSION;
PlugInitInfo^.pluginVersion := PLUGIN_VERS;
lstrcpyA(PlugInitInfo^.pluginName, PLUGIN_NAME);
_plugin_registercallback(g_pluginHandle, CB_MENUENTRY, RegisterMenuProc);
_plugin_registercallback(g_pluginHandle, CB_INITDEBUG, RegisterInitProc);
Result := True;
end;
procedure x_dbg_Pluginsetup(PlugSetupInfo: PPLUG_SETUPSTRUCT); cdecl;
begin
g_hMenu := PlugSetupInfo^.hMenu;
g_hMenuDisasm := PlugSetupInfo^.hMenuDisasm;
_plugin_menuaddentry(g_hMenuDisasm, MENU_DISASM_NOTEPAD, 'Open Notepad');
_plugin_menuaddentry(g_hMenuDisasm, MENU_DISASM_CALC, 'Open Calc');
_plugin_menuaddseparator(g_hMenuDisasm);
_plugin_menuaddentry(g_hMenuDisasm, MENU_DISASM_LOAD_EXTERNAL_PLUGINS, PAnsiChar(UTF8String('加载外部插件')));
_plugin_menuaddentry(g_hMenu, MENU_CALC, 'Open Calc');
_plugin_menuaddentry(g_hMenu, MENU_NOTEPAD, 'Open Notepad');
_plugin_menuaddseparator(g_hMenu);
_plugin_menuaddentry(g_hMenu, MENU_LOAD_EXTERNAL_PLUGINS, PAnsiChar(UTF8String('加载外部插件')));
if not (_plugin_registercommand(g_pluginHandle, 'Calc', calc, false)) then
_plugin_logputs('[MapMaster] ErroR Registering The "Calc" command! ');
if not (_plugin_registercommand(g_pluginHandle, 'Notepad', notepad, false)) then
_plugin_logputs('[MapMaster] ErroR Registering The "Notepad" command! ');
_plugin_logprintf('[***] %s Plugin v%i by %s '#10, PLUGIN_NAME, PLUGIN_VERS, PLUGIN_AUTH);
end;
function x_dbg_plugstop(): Boolean; cdecl;
begin
_plugin_unregistercallback(g_pluginHandle, CB_MENUENTRY);
_plugin_unregistercallback(g_pluginHandle, CB_INITDEBUG);
Result := True;
end;
exports
x_dbg_Plugininit name 'pluginit',
x_dbg_Pluginsetup name 'plugsetup',
x_dbg_plugstop name 'plugstop';
procedure DLLEntryPoint(dwReason: DWORD);
var
szPluginName: array[0..MAX_PATH - 1] of ACHAR;
begin
if (dwReason = DLL_PROCESS_DETACH) then
begin
lstrcatA(szPluginName, PLUGIN_NAME);
lstrcatA(szPluginName, ' Unloaded By DLL_PROCESS_DETACH');
OutputDebugStringA(szPluginName);
end;
if Assigned(SaveDLLProc) then
SaveDLLProc(dwReason);
end;
begin
g_Inst := HInstance;
SaveDLLProc := @DLLProc;
DLLProc := @DLLEntryPoint;
end.