吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1496|回复: 3
收起左侧

[求助] 请你跟我这样做,然后看饿错在哪?

[复制链接]
冥界3大法王 发表于 2025-3-14 09:17
本帖最后由 冥界3大法王 于 2025-3-14 09:18 编辑

我们先把x32dbg.exe按住Ctrl键复制一份,然后用这个副本加载x32dbg.exe
之后在这个x32dbg中,我们随便加载一个CrackMe.exe
Alt+L来到日志窗口中,Ctrl+L清空全部日志。
image.png

随便在命令行处输入:  log 【 {eax} 】
为了印证确实是在x32dbg内存中的
所以
image.png

Alt+M , Ctrl+B , 编码选择utf8的: 【
image.png

Alt+R查看结果

image.png

第一个引用,双击过去,果然就是它。。。
接下来,就引出了今天的题面:  搜索指定进程,并得到 【。。之间的字符串。。】



[Delphi] 纯文本查看 复制代码
unit Unit33;

interface

uses
  PsAPI, TlHelp32, Winapi.Windows, Winapi.Messages, System.SysUtils,
  System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
  Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm33 = class(TForm)
    Edit1: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function GetProcessIDByName(const ProcessName: string): DWORD;
    function SearchStringInProcessMemory(ProcessID: DWORD): TStringList;
  public
    { Public declarations }
  end;

var
  Form33: TForm33;

implementation

{$R *.dfm}

// 根据进程名获取进程 ID

function TForm33.GetProcessIDByName(const ProcessName: string): DWORD;
var
  hSnapshot: THandle;
  pe32: TProcessEntry32;
begin
  Result := 0;
  hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if hSnapshot <> INVALID_HANDLE_VALUE then
  try
    pe32.dwSize := SizeOf(TProcessEntry32);
    if Process32First(hSnapshot, pe32) then
    begin
      repeat
        if LowerCase(pe32.szExeFile) = LowerCase(ProcessName) then
        begin
          Result := pe32.th32ProcessID;
          Break;
        end;
      until not Process32Next(hSnapshot, pe32);
    end;
  finally
    CloseHandle(hSnapshot);
  end;
end;

function TForm33.SearchStringInProcessMemory(ProcessID: DWORD): TStringList;
var
  hProcess: THandle;
  ML: MODULEINFO;
  hModules: array[0..0] of HMODULE;
  BytesReadEnum: DWORD; // 用于 EnumProcessModules
  BytesReadMem: NativeUInt; // 用于 ReadProcessMemory
  Buffer: array of Byte;
  i: Integer;
  StartPos, EndPos: Integer;
  FoundString: string;
  UTF8Str: UTF8String;
begin
  Result := TStringList.Create;
  hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID);
  if hProcess = 0 then
  begin
    ShowMessage('无法打开进程!');
    Exit;
  end;
  try
    if EnumProcessModules(hProcess, @hModules[0], SizeOf(hModules), BytesReadEnum) then
    begin
      if GetModuleInformation(hProcess, hModules[0], @ML, SizeOf(ML)) then
      begin
        SetLength(Buffer, ML.SizeOfImage);
        if ReadProcessMemory(hProcess, ML.lpBaseOfDll, Pointer(Buffer), ML.SizeOfImage, BytesReadMem) then
        begin
          i := 0;
          while i < Length(Buffer) - 2 do
          begin
            // 查找 【(UTF-8 编码:0xE3 0x80 0x90)
            if (Buffer[i] = $E3) and (Buffer[i + 1] = $80) and (Buffer[i + 2] = $90) then
            begin
              StartPos := i + 3; // 跳过 【
              // 查找 】(UTF-8 编码:0xE3 0x80 0x91)
              while i < Length(Buffer) - 2 do
              begin
                if (Buffer[i] = $E3) and (Buffer[i + 1] = $80) and (Buffer[i + 2] = $91) then
                begin
                  EndPos := i - 1; // 结束位置
                  // 提取 UTF-8 字符串
                  SetLength(UTF8Str, EndPos - StartPos + 1);
                  Move(Buffer[StartPos], UTF8Str[1], EndPos - StartPos + 1);
                  FoundString := string(UTF8Str); // 转换为 Unicode 字符串
                  Result.Add(FoundString);
                  Break;
                end;
                Inc(i);
              end;
            end;
            Inc(i);
          end;
        end
        else
        begin
          ShowMessage('无法读取进程内存!');
        end;
      end
      else
      begin
        ShowMessage('无法获取模块信息!');
      end;
    end
    else
    begin
      ShowMessage('无法枚举进程模块!');
    end;
  finally
    CloseHandle(hProcess);
  end;
end;


procedure TForm33.Button1Click(Sender: TObject);
var
  ProcessID: DWORD;
  FoundStrings: TStringList;
begin
  ProcessID := GetProcessIDByName(Edit1.Text); // 获取进程 ID
  if ProcessID = 0 then
  begin
    ShowMessage('未找到进程!');
    Exit;
  end;

  FoundStrings := SearchStringInProcessMemory(ProcessID); // 搜索字符串
  try
    Memo1.Lines.Clear;
    Memo1.Lines.AddStrings(FoundStrings); // 显示结果
  finally
    FoundStrings.Free;
  end;
end;

end.


image.png

最后点击咋就没效果呢?

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

苏紫方璇 发表于 2025-3-14 10:20
你输出一下读取内存的地址和大小,看看是否包含有字符串所在的块
 楼主| 冥界3大法王 发表于 2025-3-14 10:34
本帖最后由 冥界3大法王 于 2025-3-14 11:01 编辑
苏紫方璇 发表于 2025-3-14 10:20
你输出一下读取内存的地址和大小,看看是否包含有字符串所在的块
模块基地址: 0x2A0000
模块大小: 65536 字节
成功读取 65536 字节的内存数据
image.png

image.png

[Delphi] 纯文本查看 复制代码
function TForm2.SearchStringInProcessMemory(ProcessID: DWORD): TStringList;
var
  hProcess: THandle;
  ML: MODULEINFO;
  hModules: array[0..0] of HMODULE;
  BytesReadEnum: DWORD;     // 用于 EnumProcessModules
  BytesReadMem: NativeUInt; // 用于 ReadProcessMemory
  Buffer: array of Byte;
  i: Integer;
  StartPos, EndPos: Integer;
  FoundString: string;
  UTF8Str: UTF8String;
begin
  Result := TStringList.Create;
  hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID);
  if hProcess = 0 then
  begin
    ShowMessage('无法打开进程!');
    Exit;
  end;
  try
    if EnumProcessModules(hProcess, @hModules[0], SizeOf(hModules), BytesReadEnum) then
    begin
      if GetModuleInformation(hProcess, hModules[0], @ML, SizeOf(ML)) then
      begin
        // 输出模块的基地址和大小
        Memo1.Lines.Add(Format('模块基地址: 0x%x', [NativeUInt(ML.lpBaseOfDll)]));
        Memo1.Lines.Add(Format('模块大小: %d 字节', [ML.SizeOfImage]));

        SetLength(Buffer, ML.SizeOfImage);
        if ReadProcessMemory(hProcess, ML.lpBaseOfDll, Pointer(Buffer), ML.SizeOfImage, BytesReadMem) then
        begin
          // 输出读取的内存大小
          Memo1.Lines.Add(Format('成功读取 %d 字节的内存数据', [BytesReadMem]));

          i := 0;
          while i < Length(Buffer) - 2 do
          begin
            // 查找 【(UTF-8 编码:0xE3 0x80 0x90)
            if (Buffer[i] = $E3) and (Buffer[i + 1] = $80) and (Buffer[i + 2] = $90) then
            begin
              StartPos := i + 3; // 跳过 【
              // 查找 】(UTF-8 编码:0xE3 0x80 0x91)
              while i < Length(Buffer) - 2 do
              begin
                if (Buffer[i] = $E3) and (Buffer[i + 1] = $80) and (Buffer[i + 2] = $91) then
                begin
                  EndPos := i - 1; // 结束位置
                  // 提取 UTF-8 字符串
                  SetLength(UTF8Str, EndPos - StartPos + 1);
                  Move(Buffer[StartPos], UTF8Str[1], EndPos - StartPos + 1);
                  FoundString := string(UTF8Str); // 转换为 Unicode 字符串
                  Result.Add(FoundString);
                  Memo1.Lines.Add(Format('找到字符串:%s', [FoundString])); // 调试信息
                  Break;
                end;
                Inc(i);
              end;
            end;
            Inc(i);
          end;
        end
        else
        begin
          ShowMessage('无法读取进程内存!');
        end;
      end
      else
      begin
        ShowMessage('无法获取模块信息!');
      end;
    end
    else
    begin
      ShowMessage('无法枚举进程模块!');
    end;
  finally
    CloseHandle(hProcess);
  end;
end;


 楼主| 冥界3大法王 发表于 2025-3-14 11:29
这次可以成功的读取到字符串的一部分了。

[Pascal] 纯文本查看 复制代码
function TForm2.SearchStringInProcessMemory(ProcessID: DWORD): TStringList;
var
  hProcess: THandle;
  Buffer: array of Byte;
  i: Integer;
  StartPos, EndPos: Integer;
  FoundString: string;
  UTF8Str: UTF8String;
  MemoryInfo: MEMORY_BASIC_INFORMATION;
  BaseAddress: Pointer;
  BytesReadMem: NativeUInt;
  LastError: DWORD;
begin
  Result := TStringList.Create;
  hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID);
  if hProcess = 0 then
  begin
    LastError := GetLastError;
    ShowMessage(Format('无法打开进程!错误代码: %d', [LastError]));
    Exit;
  end;
  try
    BaseAddress := nil;
    while VirtualQueryEx(hProcess, BaseAddress, MemoryInfo, SizeOf(MemoryInfo)) > 0 do
    begin
      // 检查内存区域是否可读
      if (MemoryInfo.State = MEM_COMMIT) and
         ((MemoryInfo.Protect and PAGE_READONLY <> 0) or
          (MemoryInfo.Protect and PAGE_READWRITE <> 0) or
          (MemoryInfo.Protect and PAGE_EXECUTE_READ <> 0) or
          (MemoryInfo.Protect and PAGE_EXECUTE_READWRITE <> 0)) then
      begin
        // 输出内存区域信息
        Memo1.Lines.Add(Format('内存区域: 0x%x - 0x%x (大小: %d 字节)', [
          NativeUInt(MemoryInfo.BaseAddress),
          NativeUInt(MemoryInfo.BaseAddress) + MemoryInfo.RegionSize,
          MemoryInfo.RegionSize
        ]));

        // 分配缓冲区
        SetLength(Buffer, MemoryInfo.RegionSize);

        // 读取内存
        if ReadProcessMemory(hProcess, MemoryInfo.BaseAddress, Pointer(Buffer), MemoryInfo.RegionSize, BytesReadMem) then
        begin
          // 输出读取的内存大小
          Memo1.Lines.Add(Format('成功读取 %d 字节的内存数据', [BytesReadMem]));

          // 搜索字符串
          i := 0;
          while i < Length(Buffer) - 2 do
          begin
            // 查找 【(UTF-8 编码:0xE3 0x80 0x90)
            if (Buffer[i] = $E3) and (Buffer[i + 1] = $80) and (Buffer[i + 2] = $90) then
            begin
              StartPos := i + 3; // 跳过 【
              // 查找 】(UTF-8 编码:0xE3 0x80 0x91)
              while i < Length(Buffer) - 2 do
              begin
                if (Buffer[i] = $E3) and (Buffer[i + 1] = $80) and (Buffer[i + 2] = $91) then
                begin
                  EndPos := i - 1; // 结束位置
                  // 提取 UTF-8 字符串
                  SetLength(UTF8Str, EndPos - StartPos + 1);
                  Move(Buffer[StartPos], UTF8Str[1], EndPos - StartPos + 1);
                  FoundString := string(UTF8Str); // 转换为 Unicode 字符串
                  Result.Add(FoundString);
                  Memo1.Lines.Add(Format('找到字符串:%s (地址: 0x%x)', [
                    FoundString,
                    NativeUInt(MemoryInfo.BaseAddress) + i
                  ])); // 调试信息
                  Break;
                end;
                Inc(i);
              end;
            end;
            Inc(i);
          end;
        end
        else
        begin
          LastError := GetLastError;
          Memo1.Lines.Add(Format('无法读取内存区域!错误代码: %d', [LastError]));
        end;
      end;

      // 移动到下一个内存区域
      BaseAddress := Pointer(NativeUInt(MemoryInfo.BaseAddress) + MemoryInfo.RegionSize);
    end;
  finally
    CloseHandle(hProcess);
  end;
end;
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

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

GMT+8, 2026-10-22 18:37

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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