标题问题:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, tlhelp32;type
TForm1 = class(TForm)
WaitTimer: TTimer;
Status: TStaticText;
btn1: TButton;
btn2: TButton;
procedure WaitTimerTimer(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private public
{ Public declarations }
end;var
Form1: TForm1;
ReadWrite: Cardinal;
CodeCave: pointer;
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
PidHandle, PidID, Temp: Integer;
hThread: Cardinal;
hWin, PiD: DWORD;const
GameName = 'spider.exe';
Value1: Array [1..2] Of Byte = ($90,$90);
Value2: Array [1..2] Of Byte = ($89,$08);implementation{$R *.dfm}function GetProcessID(Const ExeFileName: string; var ProcessId: integer;Const ProcessNo :Integer = 1): boolean;
begin
result := false;
temp:=1;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if (StrIComp(PChar(ExtractFileName(FProcessEntry32.szExeFile)), PChar(ExeFileName)) = 0)
or (StrIComp(FProcessEntry32.szExeFile, PChar(ExeFileName)) = 0) then
begin
If Temp = ProcessNo then
begin
ProcessId:= FProcessEntry32.th32ProcessID;
result := true;
break;
end else inc(Temp);
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;procedure Poke(Address: Cardinal; ChangeValues: array of byte);
begin
if GetProcessID(GameName, PidID, 1) then
begin
GetWindowThreadProcessId(hWin, Pid);
PidHandle:= OpenProcess(PROCESS_ALL_ACCESS,False,PidId);
CodeCave := VirtualAllocEx(PidHandle, Pointer(Address), SizeOf(ChangeValues), MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(PidHandle, CodeCave, @ChangeValues, SizeOf(ChangeValues), ReadWrite);
hThread := CreateRemoteThread(PidHandle, nil, 0, CodeCave, nil, 0, ReadWrite);
WaitForSingleObject(hThread, INFINITE);
VirtualFreeEx(PidHandle, CodeCave, 1024, MEM_DECOMMIT);
CloseHandle(PidHandle);
end;
end;procedure TForm1.WaitTimerTimer(Sender: TObject);
begin
if GetProcessID(GameName, PidID, 1)then
begin
Status.Caption:='游戏已经运行';
btn1.Enabled:= true;
btn2.Enabled:= true;
end
else begin
Status.Caption:='请先运行游戏';
btn1.Enabled:= false;
btn2.Enabled:= false;
end;
end;procedure TForm1.btn1Click(Sender: TObject);
begin
Poke($010035D1,Value1);
end;procedure TForm1.btn2Click(Sender: TObject);
begin
Poke($010035D1,Value2);
end;
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, tlhelp32;type
TForm1 = class(TForm)
WaitTimer: TTimer;
Status: TStaticText;
btn1: TButton;
btn2: TButton;
procedure WaitTimerTimer(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private public
{ Public declarations }
end;var
Form1: TForm1;
ReadWrite: Cardinal;
CodeCave: pointer;
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
PidHandle, PidID, Temp: Integer;
hThread: Cardinal;
hWin, PiD: DWORD;const
GameName = 'spider.exe';
Value1: Array [1..2] Of Byte = ($90,$90);
Value2: Array [1..2] Of Byte = ($89,$08);implementation{$R *.dfm}function GetProcessID(Const ExeFileName: string; var ProcessId: integer;Const ProcessNo :Integer = 1): boolean;
begin
result := false;
temp:=1;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if (StrIComp(PChar(ExtractFileName(FProcessEntry32.szExeFile)), PChar(ExeFileName)) = 0)
or (StrIComp(FProcessEntry32.szExeFile, PChar(ExeFileName)) = 0) then
begin
If Temp = ProcessNo then
begin
ProcessId:= FProcessEntry32.th32ProcessID;
result := true;
break;
end else inc(Temp);
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;procedure Poke(Address: Cardinal; ChangeValues: array of byte);
begin
if GetProcessID(GameName, PidID, 1) then
begin
GetWindowThreadProcessId(hWin, Pid);
PidHandle:= OpenProcess(PROCESS_ALL_ACCESS,False,PidId);
CodeCave := VirtualAllocEx(PidHandle, Pointer(Address), SizeOf(ChangeValues), MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(PidHandle, CodeCave, @ChangeValues, SizeOf(ChangeValues), ReadWrite);
hThread := CreateRemoteThread(PidHandle, nil, 0, CodeCave, nil, 0, ReadWrite);
WaitForSingleObject(hThread, INFINITE);
VirtualFreeEx(PidHandle, CodeCave, 1024, MEM_DECOMMIT);
CloseHandle(PidHandle);
end;
end;procedure TForm1.WaitTimerTimer(Sender: TObject);
begin
if GetProcessID(GameName, PidID, 1)then
begin
Status.Caption:='游戏已经运行';
btn1.Enabled:= true;
btn2.Enabled:= true;
end
else begin
Status.Caption:='请先运行游戏';
btn1.Enabled:= false;
btn2.Enabled:= false;
end;
end;procedure TForm1.btn1Click(Sender: TObject);
begin
Poke($010035D1,Value1);
end;procedure TForm1.btn2Click(Sender: TObject);
begin
Poke($010035D1,Value2);
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货