📄 gpkernel.pas
字号:
{
name:(1999.12.1 -jhx1)
江湖行 II jhx2
2002.10.13 renamed to 'GamePaladin II'
CopyRight:XuGanQuan gqxunet#163.com
Description:A game cheat tool
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
unit GPKernel;
interface
uses Windows,StdCtrls,Classes,SysUtils,dialogs,tlhelp32,forms,
ComCtrls,Controls,math,Shellapi,CommCtrl;
resourcestring
String_GetProcesses='枚举进程出错.请检查Windows系统或者重新启动' ;
String_CreateToolhelp32Snapshot='发生错误(不支持WindowNT 4.0及其以下)'#13#10'请用应用程序列表选择任务';
String_InvalidInput='不合法的输入,请检查.';
String_InvalidByte='%s 不是合法的 Byte 数据类型,请检查';
String_InvalidWord='%s 不是合法的 Word 数据类型,请检查';
String_InvalidDword='%s 不是合法的 Dword 数据类型,请检查';
String_InvalidInt64='%s 不是合法的 Int64 数据类型,请检查';
String_InvalidSingle='%s 不是合法的 Single 数据类型,请检查';
String_InvalidDouble='%s 不是合法的 Double 数据类型,请检查';
String_InvalidString='%s 不是合法的 Text 数据类型,请检查';
String_TaskResult='任务: %s '#13#10'找到 %d 个地址,'#13#10'用时 %f 秒.';
String_TaskResultTitle='搜索结果';
String_Nomemory='找不到该进程中可用内存!请检查!' ;
String_InitialLowLevel='任务:%s'#13#10'低阶搜索初始化完成.';
procedure InittheTask(theID:Integer);
Procedure GetProcessList(ProcessList: TListView;ImageList,HeadImageList:TimageList);
procedure GetWindowList(ProcessList: TListView;ImageList,HeadImageList:TimageList);
Function GetScanTypeAndTempVar(InputValue:String;theTaskIndex:integer):Integer;
Function HexIntChange(inStr:string):String;
Function GetVarTypeAndVarValue(InputValue:String;theTaskIndex:integer):Integer;
Procedure GetMemoryRanges(theTaskIndex:integer);
function AnalyseScan(theIndex:Integer):integer;
Function ReadMemory(theProcessID,StartAddress:Dword;ValueAddressPointer:Pointer;ValueType:Integer):boolean;
Function ReadMemory_Array(theProcessID,StartAddress:DWORD):boolean;
Function WriteMemory(theProcessID,StartAddress:Dword;ValueAddressPointer:pointer;ValueType,ValueLen:Integer):boolean;
Type
TFirstScanThread=class(TThread)
private
TheTaskIndex:integer;
protected
procedure Execute; override;
public
constructor Create(theIndex:Integer);
end;
type
TNextScanThread=class(TThread)
private
TheTaskIndex:integer;
protected
procedure Execute; override;
public
constructor Create(theIndex:Integer);
end;
const
Auto_value=0;
Byte_value=1;
word_value=2;
Dword_value=3;
int64_value=4;
Single_value=5;
Double_Value=6;
String_Value=7;
CommonLevel_Value=10;
Number_Scan = 101;
String_Scan=102;
LowLevel_Value=20;
InitialLowLevel_Scan =201;
Increased_Scan =202;
Decreased_Scan = 203;
Changed_Scan = 204;
Unchanged_Scan = 205;
Type TMemoryRegion = record
BaseAddress: Dword;
MemorySize: Dword;
end;
type
TProcesstask =record
Applyed:Boolean; ///是否占用
Name:String; //名字
Index:integer; //task array
ProcessID:Dword; //对应进程id
ProcessHandle:Dword; //对应进程句柄
ScanType:integer; //scan type
OldScanType:integer; //上一次扫描类型
VarType:integer;
OldVarType:integer; ///应付自动类型
ScanValue:String;
FromAddress:Dword; ///from
ToAddress:Dword; //to
TotalProcess:Dword; ///应扫描总的地指数shr
NowProcess:Dword; ////扫描数量
InSearchProcess:Boolean; ///是否正在扫描,防止多次点击
SearchTimes:Integer; //扫描次数
AttachedNum:DWORD; //匹配数目
MemoryFileName:String; ///低阶内存映射文件
MemoryFileNameNew:String; ///低阶内存映射文件
AddressMemStream:TMemoryStream; //几下每个符合的地址
AdvancedAddressMemStream:TMemoryStream; //几下低阶符合的地址范围及大小
MemoryRegions: array [0..20000] of TMemoryRegion; ///内存范围
MemoryRegionsIndex:Integer; // 内存范围序号
MBI:_MEMORY_BASIC_INFORMATION; //内存信息变量
end;
Const maxTaskNUm=256;
var TaskNUm:Integer=0; ///任务个数
thetask:array[1..maxTaskNUm] of TProcessTask;
ListToTaskIndex:array[1..maxTaskNUm] of Integer; //listview 对应任务Index
CurrentTaskIndex:Integer;
CurrentProcessID:DWord;
DefaultFromAddress:DWORD=$00010000;
DeFaultToAddress:DWORD=$86500000;
var MemReadStartAddress:DWORD;
MemReaddata:array[1..256] of Integer;
MemWriteStartAddress:Dword;
{ 转变成每一个任务的私有成员变量
var MemoryRegions: array [0..20000] of TMemoryRegion;
MemoryRegionsIndex:Integer;
MBI:_MEMORY_BASIC_INFORMATION;
转变成每一个进程的私有变量
ReadMemory_ArrayByte: Array[0..$FFFF] of Byte;
ReadMemory_ArrayWord: Array[0..$7FFF] of Word;
ReadMemory_ArrayDWord: Array[0..$3FFF] of Dword;
ReadMemory_ArrayInt64: Array[0..$1FFF] of Int64;
ReadMemory_ArraySingleDword:Array[0..$3FFF] of Dword; //single length is same to dowrd
ReadMemory_ArrayDoubleInt64: Array[0..$1FFF] of int64; //Double length is same to int64
ReadMemory_ArrayStringByte:Array[0..$FF] of Byte;
AdvancedReadMemory_ArrayByte:Array[0..$FFFF] of Byte;
AdvancedReadFile_ArrayByte:Array[0..$FFFF] of Byte;
///数组过大将无法读出
}
type
TLockRecord = record
Applyed:Boolean;
Description : string[40];
Address : Dword;
valueStr:String[20];
VarType : integer;
ProcessID:DWord;
Frozen : boolean;
end;
Const maxLockNUm=256;
var LockNUm:Integer=0; ///锁定个数
ListToLockIndex:array[1..maxLockNUm]of integer;
MemLockRecord:Array[1..maxLockNUm]of TLockRecord;
CopyLockRecord:TLockRecord;
CanPasteLockRecord:boolean=false;
const MaxShow=1000;
SplitValue=$FFFE; ///max stream =$FFFe never error
var CanUpdateTask:Integer=-999; ///防止更新闪烁,
implementation
//////////////初始化任务//////////////////////////////////
procedure Initthetask(theID:Integer);
begin
with theTask[theId] do
begin
Applyed:=True;
Name:='XGQ Game Paladin';
//index:=1;
ProcessID:=0; //进程id
ProcessHandle:=0; //对应进程句柄 实际中需要判断是否存在
ScanType:=Number_Scan; //Number_Scan:= ]
OldScanType:=ScanType;
VarType:=Auto_value; //选择某一类型后,实际搜索类型auto
OldVarType:=Auto_value;
ScanValue:='';
TotalProcess:=0;
NowProcess:=0;
FromAddress:=DefaultFromAddress;
ToAddress:=DeFaultToAddress;
SearchTimes:=0;
AttachedNum:=0;
InSearchProcess:=False;
MemoryFileName:='';
MemoryFileNameNew:='';
if Assigned(AddressmemStream)then
AddressMemStream.SetSize(0) else
AddressMemStream:=TmemoryStream.Create;
if Assigned(AdvancedAddressMemStream)then
AdvancedAddressMemStream.SetSize(0) else
AdvancedAddressMemStream:=TmemoryStream.Create;
end;
end;
///////////////////获取进程列表////////////////////////
procedure GetProcessList(ProcessList: TListView;ImageList,headImageList:TimageList);
var lppe: TProcessEntry32;
Foundlppe: boolean;
SnapHandle: THandle;
HAppIcon:Hicon;
FWinIcon:HIcon;
begin
ProcessList.Items.BeginUpdate;
ProcessList.Items.Clear;
processlist.SmallImages:=nil;
ImageList.Clear;
HappIcon:=0;
FWinIcon:=LoadIcon(0,IDI_WINLOGO);
SnapHandle:= CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
if SnapHandle>0 then
begin
lppe.dwSize:=Sizeof(lppe);
Foundlppe:= Process32First(SnapHandle,lppe);
if (not Foundlppe) then Raise Exception.Create(String_GetProcesses);
ImageList.AddImages(headImageList);
while Foundlppe do
begin
HAppIcon:=ExtractIcon(HAppIcon,lppe.szExeFile,0);
if HappIcon=0 then HAppIcon:=FWinIcon;
with ProcessList.Items.Add do
begin
Caption:=lppe.szExeFile;
Subitems.Add(intToStr(lppe.th32ProcessID));
ImageIndex:=ImageList_AddIcon(ImageList.Handle,HappICon);
end;
Foundlppe:=Process32Next(SnapHandle,lppe);
end;
end else Raise Exception.Create(String_CreateToolhelp32Snapshot);
ProcessList.SmallImages:=Imagelist;
CloseHandle(SnapHandle);
DestroyIcon(HappIcon);
DestroyIcon(FWinICon);
ProcessList.Items.EndUpdate;
end;
////////////////////获取窗口列表////////////////////////////
procedure GetWindowList(ProcessList: TListView;ImageList,headImageList:TimageList);
var winhandle: Hwnd;
winprocess: Dword;
title:pchar;
HAppIcon:Hicon;
FWinIcon:HIcon;
begin
ProcessList.Items.BeginUpdate;
HappIcon:=0;
processlist.Items.clear;
processlist.SmallImages:=nil;
ImageList.Clear;
FWinIcon:=LoadIcon(0,IDI_WINLOGO);
Getmem(title,255);
winhandle:=GetWindow(GetForeGroundWindow,GW_HWNDFIRST);
ImageList.AddImages(headImageList);
while winhandle<>0 do
begin
if (isWindowvisible(winhandle) and IsWindowEnabled(winhandle) and IsWindow(winhandle)) then
begin
GetWindowThreadProcessId(winhandle,@winprocess);
GetWindowText(winhandle,title,255);
if Length(title)<>0 then
begin
HAppIcon:=GetClassLong(winHandle,GCL_HICON);
if HappIcon=0 then HAppIcon:=FWinIcon;
With ProcessList.Items.Add do
begin
Caption:=title;
Subitems.Add(intToStr(winprocess));
ImageIndex:=ImageList_AddIcon(ImageList.Handle,HappICon);
end;
end;
end;
winhandle:=GetWindow(winhandle,GW_HWNDNEXT);
end;
ProcessList.SmallImages:=Imagelist;
Freemem(title);
CloseHandle(winHandle);
DestroyIcon(HappIcon);
DestroyIcon(FWinICon);
ProcessList.Items.EndUpdate;
end;
///////////根据输入的值判断scantype//////////////////////////////////////////////////
Function GetScanTypeAndTempVar(InputValue:String;thetaskIndex:integer):Integer;
var Len:integer;
begin
Result:=-999;
with thetask[theTaskIndex] do
begin
Len:=length(inputValue);
if InputValue='' then
Exit
else if inputvalue[1]='?' then
begin
VarType:=LowLevel_value;
Result:=InitialLowLevel_Scan;
end
else if InputValue[1]='!' then
begin
VarType:=LowLevel_value;
Result:=Changed_Scan;
end
else if InputValue[1]='=' then
begin
VarType:=LowLevel_value;
Result:=UnChanged_Scan;
end
else if InputValue[1]='+' then
begin
VarType:=LowLevel_value;
Result:=Increased_scan;
end
else if InputValue[1]='-' then
begin
VarType:=LowLevel_value;
Result:=Decreased_scan ;
end
else if (
((Len>2) and ( Len<255) ) and
(
((InputValue[1]='"') and (InputValue[Len]='"')) or
((InputValue[1]='''') and (InputValue[Len]=''''))
)
)
then
begin
ScanValue:=Copy(inputValue,2,Len-2);
VarType:=CommonLevel_value;
Result:=String_Scan;
end
else begin
ScanValue:=inputValue;
/////Vartype必须考虑Combobox的选择
Result:=Number_Scan;
end;
end; ///with end;
end;
/////////////hex to int///////////////////////////////////////////////////////////////////////////////
Function HexIntChange(inStr:string):String;
var Len:integer;
TempString:String;
begin
Len:=Length(inStr);
if (Len>2) and ( UpperCase(instr[1])+UpperCase(instr[2])='0X' )then
begin
TempString:='$'+Copy(Instr,3,Len-2);
try
Result:=inttoStr(Strtoint(TempString));
except
showmessage(String_InvalidInput);
end;
Exit;
end;
if (Len>1) and (instr[1]='$') then
begin
try
Result:=inttoStr(Strtoint(instr));
except
showmessage(String_InvalidInput);
end;
Exit;
end;
result:=instr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -