吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 362|回复: 6
收起左侧

[求助] 外部.exe可不可以和x64dbg(*.dp32【动态链接库】共享内存?为啥一给信号就炸了??

[复制链接]
冥界3大法王 发表于 2025-3-13 16:10
本帖最后由 冥界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.


为什么一发送信号就崩了呢?

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 冥界3大法王 发表于 2025-3-13 16:15
几经折腾是编译通过三回(AI修改+自己琢磨的)
但是一给信号就炸了马蜂窝了。
百思不解啊。。。所以还是来求助吧。因为高人很多。
linsixi 发表于 2025-3-13 16:33
m_h 发表于 2025-3-14 15:48
forum.tuts4you.com/topic/43648-x64dbg-plugin-in-delphi/
能把这个帖子的所有附件打包吗? 我没账号。
 楼主| 冥界3大法王 发表于 2025-3-14 17:21
本帖最后由 冥界3大法王 于 2025-3-14 17:36 编辑
m_h 发表于 2025-3-14 15:48
forum.tuts4you.com/topic/43648-x64dbg-plugin-in-delphi/
能把这个帖子的所有附件打包吗? 我没账号。

@m_h

https://gitee.com/suxuss/DELPHI-x96dbg-Plugins-SDK

原来帐号忘了,你要下载的是残疾版本的,修复的是上面这个。
x64dbg插件主页上的那个out了,作者不再更新了,最后的那个好像是三年前的我弄的这个。
m_h 发表于 2025-3-14 19:21
冥界3大法王 发表于 2025-3-14 17:21
@m_h

https://gitee.com/suxuss/DELPHI-x96dbg-Plugins-SDK

大佬啊。。怎么不用ai翻译插件部分?。。12.3出了 我刚装上 哈哈。! 捕获.PNG



 楼主| 冥界3大法王 发表于 2025-3-14 19:27
m_h 发表于 2025-3-14 19:21
大佬啊。。怎么不用ai翻译插件部分?。。12.3出了 我刚装上 哈哈。!

@m_h
因为QQ群里有Delphi中英文界面一键切换的
再说我都认识不需要那玩意啊。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-3-25 07:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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