好友
阅读权限40
听众
最后登录1970-1-1
|
本帖最后由 冥界3大法王 于 2025-3-14 17:40 编辑
顶上是【外部.exe】的部分,意在外部控制 与 接收数据。
[Asm] 纯文本查看 复制代码 unit Unit2;
interface
uses
bridgemain, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, _scriptapi_debug, Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TForm2 = class(TForm)
Timer1: TTimer;
Button1: TButton; // 添加一个定时器组件
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject); // 定时器事件
private
{ Private declarations }
hMapFile: THandle; // 共享内存句柄
pSharedMem: Pointer; // 共享内存指针
procedure InitSharedMemory; // 初始化共享内存
procedure ReadAndExecuteCommands; // 读取并执行命令
procedure WriteCommand(const Command: string); // 写入命令到共享内存
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
const
SHARED_MEM_NAME = 'x64dbg_plugin_shared_mem'; // 共享内存名称
SHARED_MEM_SIZE = 1024; // 共享内存大小
procedure TForm2.InitSharedMemory;
begin
hMapFile := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, SHARED_MEM_NAME);
// 打开或创建共享内存
if hMapFile = 0 then
hMapFile := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0,
SHARED_MEM_SIZE, SHARED_MEM_NAME);
if hMapFile <> 0 then
pSharedMem := MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0,
SHARED_MEM_SIZE)
else
OutputDebugString('8888888888888888888888888888');
end;
procedure TForm2.ReadAndExecuteCommands;
var
Command: string;
begin
if pSharedMem = nil then Exit;
// 读取共享内存中的命令
Command := PChar(pSharedMem);
if Command <> '' then
begin
// 记录日志
// 执行命令
if Command = 'StepOver' then
DbgCmdExec('StepOver')
else if Command = 'StepInto' then
DbgCmdExec('StepInto')
else if Command = 'Run' then
DbgCmdExec('Run');
// 清空共享内存
ZeroMemory(pSharedMem, SHARED_MEM_SIZE);
end;
end;
procedure TForm2.WriteCommand(const Command: string);
begin
if pSharedMem = nil then Exit;
// 将命令写入共享内存
StrPCopy(PChar(pSharedMem), Command);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
WriteCommand('StepOver'); // 可以替换为 'StepInto' 或 'Run'
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
// 初始化共享内存
InitSharedMemory;
// 启动定时器,定期读取共享内存
Timer1.Interval := 100; // 每 100 毫秒检查一次
Timer1.Enabled := True;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
// 清理共享内存
if pSharedMem <> nil then
UnmapViewOfFile(pSharedMem);
if hMapFile <> 0 then
CloseHandle(hMapFile);
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
// 定时读取并执行命令
ReadAndExecuteCommands;
end;
end.
下面提DPR(DLL部分),意在共享数据 ,譬如x64dbg的【状态栏、日志输出窗口】
[Asm] 纯文本查看 复制代码 library 学习;
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
{$WEAKLINKRTTI ON}
uses
Windows,
Messages,
bridgemain in 'plugin\bridgemain.pas',
_plugins in 'plugin\_plugins.pas',
_dbgfunctions in 'plugin\Other\_dbgfunctions.pas',
_scriptapi_argument in 'plugin\Other\_scriptapi_argument.pas',
_scriptapi_assembler in 'plugin\Other\_scriptapi_assembler.pas',
_scriptapi_bookmark in 'plugin\Other\_scriptapi_bookmark.pas',
_scriptapi_comment in 'plugin\Other\_scriptapi_comment.pas',
_scriptapi_debug in 'plugin\Other\_scriptapi_debug.pas',
_scriptapi_flag in 'plugin\Other\_scriptapi_flag.pas',
_scriptapi_function in 'plugin\Other\_scriptapi_function.pas',
_scriptapi_gui in 'plugin\Other\_scriptapi_gui.pas',
_scriptapi_label in 'plugin\Other\_scriptapi_label.pas',
_scriptapi_memory in 'plugin\Other\_scriptapi_memory.pas',
_scriptapi_misc in 'plugin\Other\_scriptapi_misc.pas',
_scriptapi_module in 'plugin\Other\_scriptapi_module.pas',
_scriptapi_pattern in 'plugin\Other\_scriptapi_pattern.pas',
_scriptapi_register in 'plugin\Other\_scriptapi_register.pas',
_scriptapi_stack in 'plugin\Other\_scriptapi_stack.pas',
_scriptapi_symbol in 'plugin\Other\_scriptapi_symbol.pas',
TitanEngine in 'plugin\Other\TitanEngine.pas';
{$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;
// 共享内存相关变量
hMapFile: THandle = 0; // 共享内存句柄
pSharedMem: Pointer = nil; // 共享内存指针
function ShellExecuteA(hWnd: hWnd; Operation, FileName, Parameters,
Directory: PAnsiChar; ShowCmd: Integer): HINST; stdcall;
external 'shell32.dll' name 'ShellExecuteA';
const
PLUGIN_NAME: PAChar ='Study';
PLUGIN_VERS: Integer = 01;
MENU_CALC = 1;
MENU_NOTEPAD = 2;
MENU_DISASM_CALC = 3;
MENU_DISASM_NOTEPAD = 4;
MENU_MYFORM = 5;
// 共享内存常量
SHARED_MEM_NAME = 'x64dbg_plugin_shared_mem'; // 共享内存名称
SHARED_MEM_SIZE = 1024; // 共享内存大小
{$R MoreTool.res}
// 初始化共享内存
procedure InitSharedMemory;
begin
hMapFile := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, SHARED_MEM_NAME);
if hMapFile = 0 then
hMapFile := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0,
SHARED_MEM_SIZE, SHARED_MEM_NAME);
if hMapFile <> 0 then
pSharedMem := MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0,
SHARED_MEM_SIZE)
else
_plugin_logputs('[Study] Failed to create or open shared memory.');
end;
// 读取并执行共享内存中的命令
procedure ReadAndExecuteCommands;
var
Command: string;
begin
if pSharedMem = nil then
Exit;
// 读取共享内存中的命令
Command := PChar(pSharedMem);
if Command <> '' then
begin
// 执行命令
if Command = 'StepOver' then
DbgCmdExec('StepOver')
else if Command = 'StepInto' then
DbgCmdExec('StepInto')
else if Command = 'Run' then
DbgCmdExec('Run');
// 清空共享内存
ZeroMemory(pSharedMem, SHARED_MEM_SIZE);
end;
end;
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;
begin
info := PPLUG_CB_MENUENTRY(callbackInfo);
case (info^.hEntry) of
MENU_CALC:
begin
ShellExecuteA(GuiGetWindowHandle, 'OPEN', 'calc.exe', '',
'C:\Windows\system32', SW_SHOWNORMAL);
end;
MENU_NOTEPAD:
begin
ShellExecuteA(GuiGetWindowHandle, 'OPEN', 'notepad.exe', '',
'C:\Windows\system32', SW_SHOWNORMAL);
end;
MENU_DISASM_CALC:
begin
ShellExecuteA(GuiGetWindowHandle, 'OPEN', 'calc.exe', '',
'C:\Windows\system32', SW_SHOWNORMAL);
end;
MENU_DISASM_NOTEPAD:
begin
ShellExecuteA(GuiGetWindowHandle, 'OPEN', 'notepad.exe', '',
'C:\Windows\system32', SW_SHOWNORMAL);
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; // Address: 0043E7DC
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_CALC, 'Open Calc');
_plugin_menuaddseparator(g_hMenuDisasm);
_plugin_menuaddentry(g_hMenuDisasm, MENU_DISASM_NOTEPAD, 'Open Notepad');
_plugin_menuaddentry(g_hMenu, MENU_CALC, 'Open Calc');
_plugin_menuaddseparator(g_hMenu);
_plugin_menuaddentry(g_hMenu, MENU_NOTEPAD, 'Open Notepad');
_plugin_menuaddentry(g_hMenu, MENU_MYFORM, 'Show My Form');
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! ');
// Add Plugin info
_plugin_logprintf('[***] %s Plugin v%i by %s '#10, PLUGIN_NAME, PLUGIN_VERS,
PLUGIN_AUTH);
// 初始化共享内存
InitSharedMemory;
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
// Uninitialize code here
lstrcatA(szPluginName, PLUGIN_NAME);
lstrcatA(szPluginName, ' Unloaded By DLL_PROCESS_DETACH');
OutputDebugStringA(szPluginName);
end;
// Call saved entry point procedure
if Assigned(SaveDLLProc) then
SaveDLLProc(dwReason);
end;
begin
// Initialize code here
g_Inst := HInstance;
SaveDLLProc := @DLLProc;
DLLProc := @DLLEntryPoint;
end.
为什么一发送信号就崩了呢?   |
|