forked from cheat-engine/cheat-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CEFuncProc.pas
executable file
·3934 lines (3251 loc) · 108 KB
/
CEFuncProc.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright Cheat Engine. All Rights Reserved.
unit CEFuncProc;
{$MODE Delphi}
//This version of CEFuncProc has been COPIED to the server dir
//Cheat Engine regular WONT look at this
interface
uses
{$ifdef darwin}
mactypes, LCLType,macport,
{$endif}
{$ifdef windows}
jwawindows, windows,
{$endif}
zstream, LazUTF8, LCLIntf,StdCtrls,Classes,SysUtils,dialogs,{tlhelp32,}forms,messages,
Graphics,
ComCtrls,
{reinit, }
Assemblerunit,
{$ifdef windows}imagehlp,{$endif}
registry,
ExtCtrls,
LastDisassembleData,
{$ifdef netclient}
netapis,
{$else}
NewKernelHandler,
{$ifndef standalonetrainer}
{$ifndef netserver}
hypermode,
{$endif}
{$endif}
{$endif}
math,syncobjs, {$ifdef windows}shellapi,{$endif} ProcessHandlerUnit, controls, {$ifdef windows}shlobj, ActiveX,{$endif} strutils,
commontypedefs, {$ifdef windows}Win32Int,{$endif} maps, lua, lualib, lauxlib{$ifdef darwin},macportdefines{$endif}, betterControls;
const
EFLAGS_CF=(1 shl 0);
EFLAGS_PF=(1 shl 2);
EFLAGS_AF=(1 shl 4);
EFLAGS_ZF=(1 shl 6);
EFLAGS_SF=(1 shl 7);
EFLAGS_TF=(1 shl 8);
EFLAGS_IF=(1 shl 9);
EFLAGS_DF=(1 shl 10);
EFLAGS_OF=(1 shl 11);
EFLAGS_NT=(1 shl 14);
EFLAGS_RF=(1 shl 16);
EFLAGS_VM=(1 shl 17);
EFLAGS_AC=(1 shl 18);
EFLAGS_ID=(1 shl 21);
//function NewVarTypeToOldVarType(i: TVariableType):integer;
function VariableTypeToTranslatedString(variableType: TVariableType): string;
function OldVarTypeToNewVarType(i: integer):TVariableType;
function VariableTypeToString(variableType: TVariableType): string;
function StringToVariableType(s: string): TVariableType;
function isjumporcall(address: ptrUint; var addresstojumpto: ptrUint): boolean;
{
procedure quicksortmemoryregions(lo,hi: integer); //obsolete
}
function rewritecode(processhandle: thandle; address:ptrUint; buffer: pointer; var size:dword; force: boolean=false): boolean;
function rewritedata(processhandle: thandle; address:ptrUint; buffer: pointer; var size:dword): boolean;
function GetUserNameFromPID(ProcessId: DWORD): string;
//procedure GetProcessList(ProcessList: TListBox; NoPID: boolean=false); overload;
//procedure GetProcessList(ProcessList: TStrings; NoPID: boolean=false; noProcessInfo: boolean=false); overload;
procedure GetThreadList(threadlist: TStrings);
//procedure cleanProcessList(processlist: TStrings);
procedure GetWindowList2(ProcessList: TStrings; showInvisible: boolean=true);
procedure GetWindowList(ProcessList: TStrings; showInvisible: boolean=true); overload;
procedure GetWindowList(ProcessListBox: TListBox; showInvisible: boolean=true); overload;
procedure GetModuleList(ModuleList: TStrings; withSystemModules: boolean);
procedure cleanModuleList(ModuleList: TStrings);
function AvailMem:SIZE_T;
function isreadable(address:ptrUint):boolean;
function iswritable(address:ptrUint):boolean;
procedure RemoveAddress(address: Dword;bit: Byte; vartype: Integer);
function GetCEdir:string;
procedure Open_Process;
Procedure Shutdown;
function KeyToStr(key:word):string;
procedure EnableWindowsSymbols(warn: boolean=true);
function eflags_setCF(flagvalue: dword; value: integer): DWORD;
function eflags_setPF(flagvalue: dword; value: integer): DWORD;
function eflags_setAF(flagvalue: dword; value: integer): DWORD;
function eflags_setZF(flagvalue: dword; value: integer): DWORD;
function eflags_setSF(flagvalue: dword; value: integer): DWORD;
function eflags_setTF(flagvalue: dword; value: integer): DWORD;
function eflags_setIF(flagvalue: dword; value: integer): DWORD;
function eflags_setDF(flagvalue: dword; value: integer): DWORD;
function eflags_setOF(flagvalue: dword; value: integer): DWORD;
function eflags_setIOPL(flagvalue: dword; value: integer): DWORD;
function eflags_setNT(flagvalue: dword; value: integer): DWORD;
function eflags_setRF(flagvalue: dword; value: integer): DWORD;
function eflags_setVM(flagvalue: dword; value: integer): DWORD;
function eflags_setAC(flagvalue: dword; value: integer): DWORD;
function eflags_setVIF(flagvalue: dword; value: integer): DWORD;
function eflags_setVIP(flagvalue: dword; value: integer): DWORD;
function eflags_setID(flagvalue: dword; value: integer): DWORD;
function GetPageBase(address: ptruint): ptruint; inline; //return the pageboundary this address belongs to
function ByteStringToText(s: string;hex: boolean):string;
function ByteStringToDouble(s: string;hex: boolean):double;
function ByteStringToSingle(s: string;hex: boolean):single;
function ByteStringToInt(s: string;hex: boolean):int64;
function VarToBytes(v: pointer; size: integer): string;
function RawToString(const buf: array of byte; vartype: integer;showashex: boolean; bufsize: integer):string;
procedure decimal(var key: char);
procedure hexadecimal(var key: char);
function GetSystemType: Integer;
procedure ToggleOtherWindows;
Procedure InjectDll(dllname: string; functiontocall: string='');
Function GetRelativeFilePath(filename: string):string;
function GetCPUCount: integer;
function HasHyperthreading: boolean;
procedure SaveFormPosition(form: TCustomform; const extra: array of integer); overload;
procedure SaveFormPosition(form: TCustomform); overload;
function LoadFormPosition(form: TCustomform; var x: TWindowPosArray):boolean; overload;
function LoadFormPosition(form: TCustomform):boolean; overload;
function heapflagstostring(heapflags: dword): string;
function allocationtypetostring(alloctype: dword): string;
function allocationProtectToString(protect: dword): string;
function AllocationProtectToAccessRights(protect: dword): TAccessRights;
function AccessRightsToAllocationProtect(ar: TAccessRights): Dword;
function freetypetostring(freetype: dword):string;
function MinX(a, b: ptrUint): ptrUint;inline; overload; //fpc2.4.1 has no support for unsigned
function MaxX(a, b: ptrUint): ptrUint;inline; overload;
function InRangeX(const AValue, AMin, AMax: ptrUint): Boolean;inline;
function InRangeQ(const AValue, AMin, AMax: qword): Boolean;inline;
function getProcessnameFromProcessID(pid: dword): string;
function getProcessPathFromProcessID(pid: dword): string;
procedure getDriverList(list: tstrings);
function EscapeStringForRegEx(const S: string): string;
function getthreadCount(pid: qword): integer;
function GetStackStart(threadnr: integer=0): ptruint;
function getDiskFreeFromPath(path: string): int64;
procedure protectme(pid: dword=0);
procedure errorbeep;
{$ifndef net}
procedure SetLanguage;
function getathreadid(processid:dword):dword;
{$endif}
procedure DetachIfPossible;
{$ifdef windows}
procedure Log(s: string);
{$endif}
const
Exact_value = 0;
Increased_value = 1;
Increased_value_by = 2;
Decreased_value = 3;
Decreased_value_by = 4;
Changed_value = 5;
Unchanged_value = 6;
Advanced_Scan = 7;
String_Scan = 8;
SmallerThan = 9;
BiggerThan = 10;
Userdefined = 11; //not used
ValueBetween = 12;
SameAsFirst = 13;
splitvalue=400000;
number=600; //is my using the new value on my system arround 580000
PAGE_WRITECOMBINE=$400;
type
MemoryRecordcet3 = record
Description : string[50];
Address : dword;
VarType : byte;
Bit : Byte;
Frozen : boolean;
FrozenValue : Int64;
Group: Byte;
end;
type
MemoryRecord = record
Description : string;
Address : ptrUint;
interpretableaddress: string;
VarType : byte;
unicode : boolean;
IsPointer: Boolean;
pointers: array of TCEPointer;
Bit : Byte;
bitlength: integer;
Frozen : boolean;
FrozenValue : Int64;
OldValue: string; //not saved
Frozendirection: integer; //0=always freeze,1=only freeze when going up,2=only freeze when going down
Group: Byte;
ShowAsHex: boolean;
autoassemblescript: string;
allocs: TCEAllocArray;
end;
type
MemoryRecordOld = record
Description : string[50];
Address : ptrUint;
VarType : byte;
Frozen : boolean;
FrozenValue : Dword;
end;
type TScanSettings = record
UseHyperscan: boolean;
scanning: boolean;
CEProcessID: dword;
CEMainThreadID: Dword;
applicantionhandle: thandle;
mainformHandle: THandle;
formscanningHandle: THandle;
hyperscanwindow: Thandle;
StartAddress: Dword;
StopAddress: Dword;
Scantype: Integer;
ValueType: Integer;
roundingtype: tfloatscan;
scan:byte;
readonly: boolean;
FastScan: boolean;
Hexadecimal: boolean;
unicode: boolean;
percentage: boolean;
LowMemoryUsage: boolean;
Skip_PAGE_NOCACHE:boolean;
scan_mem_private:boolean;
scan_mem_image:boolean;
scan_mem_mapped: boolean;
scanvalue: string[255];
scanvalue2: string[255];
CheatEngineDir: string[255];
buffersize:dword;
priority:integer;
nrofbits:integer;
bitstring: string[255];
bitoffsetchange: integer;
asktocontinue: boolean;
HookDirect3d: boolean;
HookOpenGL: boolean;
PacketEditor: boolean;
Stealthed: boolean;
hooknewprocesses: boolean;
end;
type tspeedhackspeed=record
speed: single;
disablewhenreleased: boolean;
keycombo: TKeyCombo;
end;
function bintohexs(var buf; size: integer):string;
function ConvertKeyComboToString(x: tkeycombo):string;
{
ProcessID and ProcessHandle as functions untill all code has been converted to
make use of ProcessHandlerUnit
}
//function ProcessID: dword;
//function ProcessHandle: THandle;
//Global vars:
type
SYSTEM_INFO = record
case longint of
0 : ( dwOemId : DWORD;
dwPageSize : DWORD;
lpMinimumApplicationAddress : LPVOID;
lpMaximumApplicationAddress : LPVOID;
dwActiveProcessorMask : DWORD_PTR;
dwNumberOfProcessors : DWORD;
dwProcessorType : DWORD;
dwAllocationGranularity : DWORD;
wProcessorLevel : WORD;
wProcessorRevision : WORD;
);
1 : (
wProcessorArchitecture : WORD;
);
end;
var
systeminfo: SYSTEM_INFO;
implementation
uses disassembler,CEDebugger,debughelper, symbolhandler, symbolhandlerstructs,
frmProcessWatcherUnit, KernelDebugger, formsettingsunit, MemoryBrowserFormUnit,
savedscanhandler, networkInterface, networkInterfaceApi, vartypestrings,
processlist, Parsers, Globals, xinput, luahandler, LuaClass, LuaObject,
UnexpectedExceptionsHelper, LazFileUtils, autoassembler, Clipbrd, mainunit2, cpuidUnit;
resourcestring
rsNotSupportedInThisVersion = 'not supported in this version';
rsNotConvertable = 'Not convertable';
rsLeftMB = 'Left MB';
rsMiddleMB = 'Middle MB';
rsRightMB = 'Right MB';
rsBreak = 'Break';
rsBackspace = 'Backspace';
rsShift = 'Shift';
rsCtrl = 'Ctrl';
rsAlt = 'Alt';
rsTab = 'Tab';
rsClear = 'Clear';
rsEnter = 'Enter';
rsPause = 'Pause';
rsCapsLock = 'Caps Lock';
rsEsc = 'Esc';
rsSpaceBar = 'Space bar';
rsPageUp = 'Page Up';
rsPageDown = 'Page Down';
rsEnd = 'End';
rsHome = 'Home';
rsLeftArrow = 'Left Arrow';
rsUpArrow = 'Up Arrow';
rsRightArrow = 'Right Arrow';
rsDownArrow = 'Down Arrow';
rsSelect = 'Select';
rsPrint = 'Print';
rsExecute = 'Execute';
rsPrintScreen = 'Print Screen';
rsInsert = 'Insert';
rsDeleteKey = 'Delete '; //added a space so the translator will leave it alone for th delete line
rsHelp = 'Help';
rsLeftWindowsKey = 'Left Windows key';
rsRightWindowsKey = 'Right Windows key';
rsApplicationsKey = 'Applications key';
rsNumeric = 'numeric';
rsNumLock = 'Num Lock';
rsScrollLock = 'Scroll Lock';
rsGetProcAddressNotFound = 'GetProcAddress not found';
rsLoadLibraryANotFound = 'LoadLibraryA not found';
rsFailedToAllocateMemory = 'Failed to allocate memory';
rsFailedToInjectTheDllLoader = 'Failed to inject the dll loader';
rsFailedToExecuteTheDllLoader = 'Failed to execute the dll loader';
rsTheInjectionThreadTookLongerThan10SecondsToExecute = 'The injection thread took longer than 10 seconds to execute. Injection routine not freed';
rsFailedInjectingTheDLL = 'Failed injecting the DLL';
rsFailedExecutingTheFunctionOfTheDll = 'Failed executing the function of the dll';
rsUnknownErrorDuringInjection = 'Unknown error during injection';
rsICanTGetTheProcessListYouArePropablyUsingWindowsNT = 'I can''t get the process list. You are propably using windows NT. Use the window list instead!';
rsNoKernel32DllLoaded = 'No kernel32.dll loaded';
rsSeparator = 'Separator';
rsCEFPDllInjectionFailedSymbolLookupError = 'Dll injection failed: symbol lookup error';
rsCEFPICantGetTheProcessListYouArePropablyUseinWindowsNtEtc = 'I can''t get the process list. You are propably using windows NT. Use the window list instead!';
rsPosition = ' Position';
rsThisCanTakeSomeTime = 'This can take some time if you are missing the '
+'PDB''s and CE will look frozen. Are you sure?';
function ProcessID: dword;
begin
result:=ProcessHandler.Processid;
end;
function ProcessHandle: THandle;
begin
result:=ProcessHandler.ProcessHandle;
end;
procedure errorbeep;
begin
beep;
sleep(100);
beep;
sleep(100);
beep;
sleep(100);
end;
function isreadable(address:ptrUint):boolean;
var mbi: _MEMORY_BASIC_INFORMATION;
i: integer;
begin
i:=VirtualQueryEx(processhandle,pointer(address),mbi,sizeof(mbi));
result:=(i=sizeof(mbi)) and (mbi.State=mem_commit);
end;
function iswritable(address:ptrUint):boolean;
var mbi: _MEMORY_BASIC_INFORMATION;
i: integer;
begin
i:=VirtualQueryEx(processhandle,pointer(address),mbi,sizeof(mbi));
result:=(i=sizeof(mbi)) and (mbi.State=mem_commit);
if result then result:={$ifdef windows}
((mbi.Protect and PAGE_EXECUTE_READWRITE)=PAGE_EXECUTE_READWRITE) or
((mbi.Protect and PAGE_EXECUTE_WRITECOPY)=PAGE_EXECUTE_WRITECOPY) or
{$endif}
((mbi.Protect and PAGE_READWRITE)=PAGE_READWRITE);
end;
function RawToString(const buf: array of byte; vartype: integer;showashex: boolean; bufsize: integer):string;
var x: pchar;
i: integer;
begin
//buffsize has to match the type else error
if bufsize=0 then
begin
result:='???';
exit;
end;
try
case vartype of
0: if bufsize<>1 then result:='???' else if showashex then result:=inttohex(buf[0],2) else result:=inttostr(buf[0]);
1: if bufsize<>2 then result:='???' else if showashex then result:=inttohex(pshortint(@buf[0])^,2) else result:=inttostr(pshortint(@buf[0])^);
2: if bufsize<>4 then result:='???' else if showashex then result:=inttohex(pint(@buf[0])^,4) else result:=inttostr(pint(@buf[0])^);
3: if bufsize<>4 then result:='???' else result:=floattostr(psingle(@buf[0])^);
4: if bufsize<>8 then result:='???' else result:=floattostr(pdouble(@buf[0])^);
6: if bufsize<>4 then result:='???' else if showashex then result:=inttohex(pint64(@buf[0])^,8) else result:=inttostr(pint64(@buf[0])^);
7:
begin
getmem(x,bufsize+1);
x[bufsize]:=#0;
result:=x;
freememandnil(x);
end;
8: //array of bytes
begin
result:='';
for i:=0 to bufsize-1 do
result:=result+'-'+inttohex(buf[bufsize],2);
end;
else result:=rsNotSupportedInThisVersion;
end;
except
result:=rsNotConvertable;
end;
end;
function bintohexs(var buf; size: integer): string;
var hs: pchar;
begin
getmem(hs,size*2+1);
BinToHex(@buf,hs,size);
hs[size*2]:=#0;
result:=hs;
freemem(hs);
end;
function ConvertKeyComboToString(x: tkeycombo):string;
var i: integer;
newstr: string;
begin
result:='';
for i:=0 to 4 do
if x[i]=0 then
break
else
begin
newstr:='';
case x[i] of
vk_lbutton: newstr:=rsLeftMB;
vk_mbutton: newstr:=rsMiddleMB;
vk_rbutton: newstr:=rsRightMB;
VK_XBUTTON1: newstr:='MB 4';
VK_XBUTTON2: newstr:='MB 5';
VK_CANCEL: newstr:=rsBreak;
VK_BACK : newstr:=rsBackspace;
VK_SHIFT: newstr:=rsShift;
VK_CONTROL: newstr:=rsCtrl;
VK_MENU: newstr:=rsAlt;
VK_TAB : newstr:=rsTab;
VK_CLEAR : newstr:=rsClear;
VK_RETURN : newstr:=rsEnter;
VK_PAUSE : newstr:=rsPause;
VK_CAPITAL : newstr:=rsCapsLock;
VK_ESCAPE : newstr:=rsEsc;
VK_SPACE : newstr:=rsSpaceBar;
VK_PRIOR : newstr:=rsPageUp;
VK_NEXT : newstr:=rsPageDown;
VK_END : newstr:=rsEnd;
VK_HOME : newstr:=rsHome;
VK_LEFT : newstr:=rsLeftArrow;
VK_UP : newstr:=rsUpArrow;
VK_RIGHT : newstr:=rsRightArrow;
VK_DOWN : newstr:=rsDownArrow;
VK_SELECT : newstr:=rsSelect;
VK_PRINT : newstr:=rsPrint;
VK_EXECUTE : newstr:=rsExecute;
VK_SNAPSHOT : newstr:=rsPrintScreen;
VK_INSERT : newstr:=rsInsert;
VK_DELETE : newstr:=rsDeleteKey;
VK_HELP : newstr:=rsHelp;
VK_LWIN : newstr:=rsLeftWindowsKey;
VK_RWIN : newstr:=rsRightWindowsKey;
VK_APPS : newstr:=rsApplicationsKey;
VK_NUMPAD0 : newstr:=rsNumeric+' 0';
VK_NUMPAD1 : newstr:=rsNumeric+' 1';
VK_NUMPAD2 : newstr:=rsNumeric+' 2';
VK_NUMPAD3 : newstr:=rsNumeric+' 3';
VK_NUMPAD4 : newstr:=rsNumeric+' 4';
VK_NUMPAD5 : newstr:=rsNumeric+' 5';
VK_NUMPAD6 : newstr:=rsNumeric+' 6';
VK_NUMPAD7 : newstr:=rsNumeric+' 7';
VK_NUMPAD8 : newstr:=rsNumeric+' 8';
VK_NUMPAD9 : newstr:=rsNumeric+' 9';
VK_MULTIPLY : newstr:=rsNumeric+' *';
VK_ADD : newstr:=rsNumeric+' +';
VK_SEPARATOR : newstr:=rsNumeric+' Separator';
VK_SUBTRACT : newstr:=rsNumeric+' -';
VK_DECIMAL : newstr:=rsNumeric+' .';
VK_DIVIDE : newstr:=rsNumeric+' /';
VK_F1 : newstr:='F1';
VK_F2 : newstr:='F2';
VK_F3 : newstr:='F3';
VK_F4 : newstr:='F4';
VK_F5 : newstr:='F5';
VK_F6 : newstr:='F6';
VK_F7 : newstr:='F7';
VK_F8 : newstr:='F8';
VK_F9 : newstr:='F9';
VK_F10 : newstr:='F10';
VK_F11 : newstr:='F11';
VK_F12 : newstr:='F12';
VK_F13 : newstr:='F13';
VK_F14 : newstr:='F14';
VK_F15 : newstr:='F15';
VK_F16 : newstr:='F16';
VK_F17 : newstr:='F17';
VK_F18 : newstr:='F18';
VK_F19 : newstr:='F19';
VK_F20 : newstr:='F20';
VK_F21 : newstr:='F21';
VK_F22 : newstr:='F22';
VK_F23 : newstr:='F23';
VK_F24 : newstr:='F24';
VK_NUMLOCK : newstr:=rsNumLock;
VK_SCROLL : newstr:=rsScrollLock;
VK_OEM_PLUS : newstr:='=';
VK_OEM_MINUS : newstr:='-';
VK_OEM_PERIOD : newstr:='.';
VK_OEM_COMMA : newstr:=',';
VK_OEM_1 : newstr:=';';
VK_OEM_2 : newstr:='/';
VK_OEM_3 : newstr:='`';
VK_OEM_4 : newstr:='[';
VK_OEM_5 : newstr:='\';
VK_OEM_6 : newstr:=']';
VK_OEM_7 : newstr:='''';
{$ifdef windows}
VK_PAD_A : newstr:='[A]';
VK_PAD_B : newstr:='[B]';
VK_PAD_X : newstr:='[X]';
VK_PAD_Y : newstr:='[Y]';
VK_PAD_RSHOULDER : newstr:='[Right Shoulder]';
VK_PAD_LSHOULDER : newstr:='[Left Shoulder]';
VK_PAD_LTRIGGER : newstr:='[Left Trigger]';
VK_PAD_RTRIGGER : newstr:='[Right Trigger]';
VK_PAD_DPAD_UP : newstr:='[Up]';
VK_PAD_DPAD_DOWN : newstr:='[Down]';
VK_PAD_DPAD_LEFT : newstr:='[Left]';
VK_PAD_DPAD_RIGHT : newstr:='[Right]';
VK_PAD_START : newstr:='[Start]';
VK_PAD_BACK : newstr:='[Back]';
VK_PAD_LTHUMB_PRESS : newstr:='[Left Thumbstick]';
VK_PAD_RTHUMB_PRESS : newstr:='[Right Thumbstick]';
VK_PAD_LTHUMB_UP : newstr:='[Left: Up]';
VK_PAD_LTHUMB_DOWN : newstr:='[Left: Down]';
VK_PAD_LTHUMB_RIGHT : newstr:='[Left: Right]';
VK_PAD_LTHUMB_LEFT : newstr:='[Left: Left]';
VK_PAD_LTHUMB_UPLEFT : newstr:='[Left: Up Left]';
VK_PAD_LTHUMB_UPRIGHT : newstr:='[Left: Up Right]';
VK_PAD_LTHUMB_DOWNRIGHT : newstr:='[Left: Down Right]';
VK_PAD_LTHUMB_DOWNLEFT : newstr:='[Left: Down Left]';
VK_PAD_RTHUMB_UP : newstr:='[Right: Up]';
VK_PAD_RTHUMB_DOWN : newstr:='[Right: Down]';
VK_PAD_RTHUMB_RIGHT : newstr:='[Right: Right]';
VK_PAD_RTHUMB_LEFT : newstr:='[Right: Left]';
VK_PAD_RTHUMB_UPLEFT : newstr:='[Right: Up Left]';
VK_PAD_RTHUMB_UPRIGHT : newstr:='[Right: Up Right]';
VK_PAD_RTHUMB_DOWNRIGHT : newstr:='[Right: Down Right]';
VK_PAD_RTHUMB_DOWNLEFT : newstr:='[Right: Down Left]';
{$endif}
48..57 : newstr:=chr(x[i]);
65..90 : newstr:=chr(x[i]);
else newstr:='#'+inttostr(x[i]);
end;
result:=result+newstr+'+';
end;
result:=copy(result,1,length(result)-1);
end;
{$ifndef standalonetrainer}
procedure FillMemoryProcess(start:ptrUint;count:dword;fillvalue:byte);
var buf: array of byte;
original,actualwritten:dword;
begin
setlength(buf,count);
try
fillmemory(@buf[0],count,fillvalue);
rewritedata(processhandle,start,@buf[0],count);
finally
setlength(buf,0);
end;
end;
{$endif}
{$ifndef net}
procedure SetLanguage;
begin
{$ifdef DEU}if LoadNewResourceModule(LANG_GERMAN) <> 0 then ReinitializeForms{$endif}
{$ifdef RUS}if LoadNewResourceModule(LANG_RUSSIAN) <> 0 then ReinitializeForms{$endif}
{$ifdef NLD}if LoadNewResourceModule(LANG_DUTCH) <> 0 then ReinitializeForms{$endif}
end;
{$endif}
//Returns a random threadid owned by the target process
function getathreadid(processid:dword):dword;
var i: integer;
ths: thandle;
tE: threadentry32;
begin
{$ifdef windows}
if frmProcessWatcher<>nil then
begin
//first find a processid using the processwatcher
frmProcessWatcher.processesCS.Enter;
try
for i:=0 to length(frmProcessWatcher.processes)-1 do
if frmProcessWatcher.processes[i].processid=processid then
begin
if length(frmProcessWatcher.processes[i].threadlist)>0 then
begin
result:=frmProcessWatcher.processes[i].threadlist[0].threadid;
exit;
end;
end;
finally
frmProcessWatcher.processesCS.Leave;
end;
end;
{$endif}
//no exit yet, so use a enumeration of all threads and this processid
ths:=CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,processid);
if ths<>0 then
begin
te.dwSize:=sizeof(te);
if Thread32First(ths,te) then
begin
repeat
if te.th32OwnerProcessID=processid then
begin
result:=te.th32ThreadID;
closehandle(ths);
exit;
end;
until not thread32Next(ths,te);
end;
end;
closehandle(ths);
end;
procedure DetachIfPossible;
begin
if debuggerthread<>nil then
begin
debuggerthread.Terminate;
debuggerthread.WaitFor;
freeandnil(debuggerthread);
end;
memorybrowser.showDebugPanels:=false;
end;
procedure ForceLoadModule(dllname: string; functiontocall: string=''; callreason: string='');
var
s: string;
functionloc: ptruint;
tid: dword;
e: boolean;
begin
try
lua_getglobal(Luavm, 'loadModule');
lua_pushstring(Luavm,dllname);
lua_pushboolean(LuaVM,true);
lua_pushinteger(LuaVM,10000); //timeout of 10 secs
if (lua_pcall(Luavm,3,2,0)<>0) then
raise exception.create('didn''t even run');
if lua_isnil(Luavm,-2) then
begin
s:=Lua_ToString(Luavm,-1);
lua_pop(Luavm,2);
raise exception.create(s);
end
else
begin
lua_pop(Luavm,2);
if functiontocall<>'' then
begin
functionloc:=symhandler.getAddressFromName(functiontocall, false, e);
if not e then
CreateRemoteThread(processhandle,nil,0,pointer(functionloc),nil,0,tid);;
end;
end;
except
on e:exception do
begin
s:='Force load module failed:'+e.message;
if callreason<>'' then
raise exception.create(callreason+#13#10+s)
else
raise exception.create(s);
end;
end;
end;
{$ifdef darwin}
Procedure InjectDll(dllname: string; functiontocall: string='');
var s: tstringlist;
di: TDisableInfo;
//allocs: TCEAllocArray;
injector: qword;
returnvalue: qword;
i: integer;
x: ptruint;
r: dword;
erroraddress: qword;
a: qword;
errs: pchar;
errorstring: string;
tid: dword;
//el: TCEExceptionListArray;
begin
outputdebugstring('cefuncproc.InjectDLL('''+dllname+''','''+functiontocall+''')');
if MacIsArm64 then
begin
raise exception.create('module injection is not yet supported on m1');
end
else
begin
s:=tstringlist.create;
s.add('[enable]');
s.add('registersymbol(v1)');
s.add('registersymbol(v2)');
s.add('registersymbol(v3)');
s.add('registersymbol(injector)');
s.add('registersymbol(errorstr)');
if processhandler.is64bit then
begin
s.add('alloc(v1, 8)');
s.add('alloc(v2, 8)');
s.add('alloc(v3, 8)');
s.add('alloc(errorstr, 8)');
end
else
begin
s.add('alloc(v1, 4)');
s.add('alloc(v2, 4)');
s.add('alloc(v3, 4)');
s.add('alloc(errorstr, 4)');
end;
s.add('alloc(injector,512)');
s.add('alloc(returnvalue, 4)');
s.add('label(dllname)');
s.add('label(error)');
s.add('label(cleanup)');
s.add('');
s.add('injector:');
if processhandler.is64bit then
begin
//rsp=*8
s.add('mov rax,v1');
s.add('mov [rax],rsp');
s.add('push rbp');
//rsp=*0
s.add('mov rax,v2');
s.add('mov [rax],rsp');
end
else
begin
//esp=*c
s.add('mov [v1],esp');
s.add('push ebp');
//esp=*8
s.add('mov [v2],esp');
end;
if processhandler.is64Bit then
begin
s.add('mov rdi,dllname');
s.add('mov rsi,1');
end
else
begin
s.add('push 1'); //rtld lazy
//esp=*4
s.add('push dllname');
//esp=*0
end;
//64-bit: rsp=*0
//32-bit: esp=*0
if processhandler.is64Bit then
begin
s.add('mov rax,v3');
s.add('mov [rax],rsp');
end
else
s.add('mov [v3],esp');
s.add('call dlopen');
//s.add('xor eax,eax');
s.add('cmp eax,0');
s.add('je short error');
if processhandler.is64Bit then
begin
s.add('mov rax,returnvalue');
s.add('mov dword [rax],1');
s.adD('jmp short cleanup');
s.add('error:');
s.add('mov rax,returnvalue');
s.add('mov dword [rax],2');
s.add('call dlerror');
s.add('mov rsi,errorstr');
s.add('mov [rsi],rax');
end
else
begin
s.add('mov dword [returnvalue],1');
s.adD('jmp short cleanup');
s.add('error:');
s.add('mov dword [returnvalue],2');
s.add('call dlerror');
s.add('mov [errorstr],eax');
end;
s.add('cleanup:');
if processhandler.is64Bit then
begin
s.add('pop rbp');
end
else
begin
s.add('add esp,8'); //dlopen is a cdecl (64-bit has no pushed params)
s.add('pop ebp');
end;
s.add('ret');
s.add('');
s.add('dllname:');
s.add('db '''+dllname+''',0');
s.add('');
s.add('returnvalue:');
s.add('dd 0');
s.add('');
s.add('[disable]');
s.add('dealloc(injector)');
s.add('dealloc(returnvalue)');
end;
//clipboard.AsText:=s.Text;
// raise exception.create('copy to clipboard now');
di:=TDisableInfo.create;
//setlength(allocs,0);
if autoassemble(s,false, true, false, false, di) then
begin
injector:=0;
returnvalue:=0;
for i:=0 to length(di.allocs)-1 do
if di.allocs[i].varname='injector' then
injector:=di.allocs[i].address
else
if di.allocs[i].varname='returnvalue' then
returnvalue:=di.allocs[i].address
else
if di.allocs[i].varname='errorstr' then
erroraddress:=di.allocs[i].address;
//showmessage('injector='+inttohex(injector,8));
if (injector=0) or (returnvalue=0) then
raise exception.create('The dllloader script didn''t properly get injected');
if CreateRemoteThread(processhandle, nil, 0, pointer(injector),0, 0,tid)=0 then raise exception.Create('Creating the injector thread has failed');
r:=0;
i:=10000 div 50;
while r=0 do
begin
dec(i);
if i=0 then raise exception.create('Timeout on dll inject');
if readprocessmemory(processhandle, pointer(returnvalue), @r, 4, x)=false then
raise exception.create('The process has crashed');
if GetCurrentThreadID = MainThreadID then
CheckSynchronize; //handle sychronize calls while it's waiting
if r=0 then sleep(50);