@@ -384,9 +384,9 @@ TfrmAutoInject = class(TForm)
384384
385385procedure Getjumpandoverwrittenbytes (address,addressto: ptrUINT; jumppart,originalcodepart: tstrings);
386386procedure generateAPIHookScript (script: tstrings; address: string; addresstogoto: string; addresstostoreneworiginalfunction: string=' ' ; nameextension:string=' 0' ; targetself: boolean=false);
387- procedure GenerateCodeInjectionScript (script: tstrings; addressstring: string);
388- procedure GenerateAOBInjectionScript (script: TStrings; address: string; symbolname: string; commentradius: integer=10 );
389- procedure GenerateFullInjectionScript (Script: tstrings; address: string; commentradius: integer=10 );
387+ procedure GenerateCodeInjectionScript (script: tstrings; addressstring: string; farjmp: boolean=false );
388+ procedure GenerateAOBInjectionScript (script: TStrings; address: string; symbolname: string; commentradius: integer=10 ; farjmp: boolean=false );
389+ procedure GenerateFullInjectionScript (Script: tstrings; address: string; commentradius: integer=10 ; farjmp: boolean=false );
390390
391391function registerAutoAssemblerTemplate (name : string; m: TAutoAssemblerTemplateCallback; shortcut: TShortCut=0 ): integer;
392392procedure unregisterAutoAssemblerTemplate (id: integer);
@@ -984,7 +984,7 @@ procedure TfrmAutoInject.FormClose(Sender: TObject;
984984{ $endif}
985985end ;
986986
987- procedure GenerateCodeInjectionScript (script: tstrings; addressstring: string);
987+ procedure GenerateCodeInjectionScript (script: tstrings; addressstring: string; farjmp: boolean=false );
988988function inttostr (i:int64):string;
989989begin
990990 if i=0 then result:=' ' else result:=sysutils.IntToStr(i);
@@ -1005,7 +1005,13 @@ function inttostr(i:int64):string;
10051005 disablepos: integer;
10061006 enablecode: tstringlist;
10071007 disablecode: tstringlist;
1008+ jmpsize: integer;
10081009begin
1010+ if not processhandler.is64Bit then
1011+ farjmp:=false;
1012+
1013+ jmpsize:=ifthen(farjmp, 14 , 5 );
1014+
10091015 try
10101016 a:=StrToQWordEx(' $' +addressstring);
10111017 except
@@ -1020,7 +1026,7 @@ function inttostr(i:int64):string;
10201026 setlength(originalcode,0 );
10211027 codesize:=0 ;
10221028
1023- while codesize<5 do
1029+ while codesize<jmpsize do
10241030 begin
10251031 setlength(originalcode,length(originalcode)+1 );
10261032 originalcode[length(originalcode)-1 ]:=disassemble(c,x);
@@ -1038,7 +1044,7 @@ function inttostr(i:int64):string;
10381044 try
10391045 with enablecode do
10401046 begin
1041- if processhandler.is64bit then
1047+ if processhandler.is64bit and ( not farjmp) then
10421048 add(' alloc(newmem' +inttostr(injectnr)+' ,2048,' +addressstring+' ) ' )
10431049 else
10441050 add(' alloc(newmem' +inttostr(injectnr)+' ,2048)' );
@@ -1059,11 +1065,14 @@ function inttostr(i:int64):string;
10591065
10601066 add(' ' );
10611067 add(addressstring+' :' );
1062- add(' jmp newmem' +inttostr(injectnr)+' ' );
1063- if codesize>5 then
1068+ if farjmp then
1069+ add(' jmp far newmem' +inttostr(injectnr)+' ' )
1070+ else
1071+ add(' jmp newmem' +inttostr(injectnr)+' ' );
1072+ if codesize>jmpsize then
10641073 begin
1065- if codesize-5 >1 then
1066- add(' nop ' +inttohex(codesize-5 ,1 ))
1074+ if codesize-jmpsize >1 then
1075+ add(' nop ' +inttohex(codesize-jmpsize ,1 ))
10671076 else
10681077 add(' nop' );
10691078 end ;
@@ -1134,7 +1143,7 @@ procedure TfrmAutoInject.Codeinjection1Click(Sender: TObject);
11341143 address:=symhandler.getNameFromAddress(a);
11351144
11361145 if inputquery(rsCodeInjectTemplate, rsOnWhatAddressDoYouWantTheJump, address) then
1137- GenerateCodeInjectionScript(assemblescreen.lines, address);
1146+ GenerateCodeInjectionScript(assemblescreen.lines, address, ssCtrl in GetKeyShiftState );
11381147end ;
11391148
11401149procedure TfrmAutoInject.Panel1Resize (Sender: TObject);
@@ -2839,7 +2848,7 @@ function GetNextAllocNumber(Script: TStrings): integer;
28392848end ;
28402849
28412850// \/ http://forum.cheatengine.org/viewtopic.php?t=566415 (jgoemat and some mods by db)
2842- procedure GenerateFullInjectionScript (Script: tstrings; address: string; commentRadius: integer=10 );
2851+ procedure GenerateFullInjectionScript (Script: tstrings; address: string; commentRadius: integer=10 ; farjmp: boolean=false );
28432852var
28442853 originalcode: array of string;
28452854 originalbytes: array of byte;
@@ -2874,7 +2883,12 @@ procedure GenerateFullInjectionScript(Script: tstrings; address: string; comment
28742883 ddBytes: string;
28752884
28762885 mi: TModuleInfo;
2886+ jmpsize: integer;
28772887begin
2888+ if not processhandler.is64Bit then
2889+ farjmp:=false;
2890+
2891+ jmpsize:=ifthen(farjmp, 14 , 5 );
28782892
28792893 try
28802894 a:=StrToQWordEx(' $' +address);
@@ -2896,7 +2910,7 @@ procedure GenerateFullInjectionScript(Script: tstrings; address: string; comment
28962910 setlength(originalcode,0 );
28972911 codesize:=0 ;
28982912
2899- while codesize<5 do
2913+ while codesize<jmpsize do
29002914 begin
29012915 setlength(originalcode,length(originalcode)+1 );
29022916 originalcode[length(originalcode)-1 ]:=disassemble(c,x);
@@ -2954,7 +2968,7 @@ procedure GenerateFullInjectionScript(Script: tstrings; address: string; comment
29542968 with enablecode do
29552969 begin
29562970 add(' assert(address' +nr+' ,bytes' +nr+' )' );
2957- if processhandler.is64bit then
2971+ if processhandler.is64bit and ( not farjmp) then
29582972 add(' alloc(newmem' + nr + ' ,$1000,' + address + ' )' )
29592973 else
29602974 add(' alloc(newmem' + nr + ' ,$1000)' );
@@ -2972,11 +2986,14 @@ procedure GenerateFullInjectionScript(Script: tstrings; address: string; comment
29722986
29732987 add(' ' );
29742988 add(' address' +nr+' :' );
2975- add(' jmp newmem' +nr+' ' );
2976- if codesize>5 then
2989+ if farjmp then
2990+ add(' jmp far newmem' +nr+' ' )
2991+ else
2992+ add(' jmp newmem' +nr+' ' );
2993+ if codesize>jmpsize then
29772994 begin
2978- if codesize-5 >1 then
2979- add(' nop ' +inttohex(codesize-5 ,1 ))
2995+ if codesize-jmpsize >1 then
2996+ add(' nop ' +inttohex(codesize-jmpsize ,1 ))
29802997 else
29812998 add(' nop' );
29822999 end ;
@@ -3058,7 +3075,7 @@ procedure TfrmAutoInject.menuFullInjectionClick(Sender: TObject);
30583075 address:=inttohex(a,8 );
30593076
30603077 if inputquery(rsCodeInjectTemplate, rsOnWhatAddressDoYouWantTheJump, address) then
3061- generateFullInjectionScript(assemblescreen.Lines, address);
3078+ generateFullInjectionScript(assemblescreen.Lines, address, 10 , ssCtrl in GetKeyShiftState );
30623079end ;
30633080
30643081
@@ -3127,7 +3144,7 @@ procedure TfrmAutoInject.MenuItem1Click(Sender: TObject);
31273144 frmHighlighterEditor.free;
31283145end ;
31293146
3130- procedure GenerateAOBInjectionScript (script: TStrings; address: string; symbolname: string; commentradius: integer=10 );
3147+ procedure GenerateAOBInjectionScript (script: TStrings; address: string; symbolname: string; commentradius: integer=10 ; farjmp: boolean=false );
31313148var
31323149 a,a2: ptrUint; // pointer to injection point
31333150 originalcode: array of string; // disassembled code we're replacing
@@ -3168,8 +3185,12 @@ procedure GenerateAOBInjectionScript(script: TStrings; address: string; symbolna
31683185 resultAOB: String;
31693186 resultOffset: Integer;
31703187 symbolNameWithOffset: String;
3188+ jmpsize: integer;
31713189begin
3172- // now heavily modified code from "Code injection" menu
3190+ if not processhandler.is64Bit then
3191+ farjmp:=false;
3192+
3193+ jmpsize:=ifthen(farjmp, 14 , 5 );
31733194
31743195 try
31753196 a:=StrToQWordEx(' $' +address);
@@ -3190,7 +3211,7 @@ procedure GenerateAOBInjectionScript(script: TStrings; address: string; symbolna
31903211 setlength(originalcode,0 );
31913212 codesize:=0 ;
31923213
3193- while codesize<5 do
3214+ while codesize<jmpsize do
31943215 begin
31953216 setlength(originalcode,length(originalcode)+1 );
31963217 originalcode[length(originalcode)-1 ]:=disassemble(c,x);
@@ -3253,7 +3274,7 @@ procedure GenerateAOBInjectionScript(script: TStrings; address: string; symbolna
32533274 else
32543275 add(' aobscan(' + symbolName + ' ,' + resultAOB + ' ) // should be unique' );
32553276
3256- if processhandler.is64bit then
3277+ if processhandler.is64bit and ( not farjmp) then
32573278 add(' alloc(newmem' + nr + ' ,$1000,' + symbolname + ' )' )
32583279 else
32593280 add(' alloc(newmem' + nr + ' ,$1000)' );
@@ -3271,11 +3292,14 @@ procedure GenerateAOBInjectionScript(script: TStrings; address: string; symbolna
32713292
32723293 add(' ' );
32733294 add(symbolNameWithOffset + ' :' );
3274- add(' jmp newmem' + nr + ' ' );
3275- if codesize>5 then
3295+ if farjmp then
3296+ add(' jmp far newmem' + nr + ' ' )
3297+ else
3298+ add(' jmp newmem' + nr + ' ' );
3299+ if codesize>jmpsize then
32763300 begin
3277- if codesize-5 >1 then
3278- add(' nop ' +inttohex(codesize-5 ,1 ))
3301+ if codesize-jmpsize >1 then
3302+ add(' nop ' +inttohex(codesize-jmpsize ,1 ))
32793303 else
32803304 add(' nop' );
32813305 end ;
@@ -3370,7 +3394,7 @@ procedure TfrmAutoInject.menuAOBInjectionClick(Sender: TObject);
33703394 symbolname:=' INJECT' +nr;
33713395
33723396 if inputquery(rsCodeInjectTemplate, rsWhatIdentifierDoYouWantToUse, symbolName) then
3373- GenerateAOBInjectionScript(assemblescreen.Lines, address, symbolname);
3397+ GenerateAOBInjectionScript(assemblescreen.Lines, address, symbolname, 10 , ssCtrl in GetKeyShiftState );
33743398 end ;
33753399end ;
33763400
0 commit comments