Skip to content

Commit

Permalink
semi template for code injection on aarch64 (got to pick an unused re…
Browse files Browse the repository at this point in the history
…gister yourself)
  • Loading branch information
cheat-engine committed Nov 29, 2023
1 parent 341516c commit 7b7b4ea
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions Cheat Engine/frmautoinjectunit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,17 @@ function inttostr(i:int64):string;
if not processhandler.is64Bit then
farjmp:=false;



if jmp1 then
jmpsize:=1
if processhandler.SystemArchitecture=archArm then
begin
jmpsize:=16;
end
else
jmpsize:=ifthen(farjmp, 14, 5);
begin
if jmp1 then
jmpsize:=1
else
jmpsize:=ifthen(farjmp, 14, 5);
end;

try
a:=StrToQWordEx('$'+addressstring);
Expand Down Expand Up @@ -1346,10 +1351,11 @@ function inttostr(i:int64):string;
try
with enablecode do
begin
if processhandler.is64bit and (not farjmp) then
if (processhandler.SystemArchitecture=archX86) and processhandler.is64bit and (not farjmp) then
add('alloc(newmem'+inttostr(injectnr)+',2048,'+addressstring+') ')
else
add('alloc(newmem'+inttostr(injectnr)+',2048)');

add('label(returnhere'+inttostr(injectnr)+')');
add('label(originalcode'+inttostr(injectnr)+')');
add('label(exit'+inttostr(injectnr)+')');
Expand All @@ -1363,18 +1369,43 @@ function inttostr(i:int64):string;
add(originalcode[i]);
add('');
add('exit'+inttostr(injectnr)+':');
add('jmp returnhere'+inttostr(injectnr)+'');
if processhandler.SystemArchitecture=archArm then
begin
if processhandler.is64Bit then
begin
add('ldr r#,returnhereaddress //you have to replace # with an unused register');
add('br r#');
add('returnhereaddress:');
add('dq returnhere');
end
else
add('b returnhere');
end
else
add('jmp returnhere'+inttostr(injectnr)+'');

add('');
add(addressstring+':');
if jmp1 then
add('jmp1 newmem')

if processhandler.SystemArchitecture=archArm then
begin
add('ldr r#,newmemaddress //you have to replace # with an unused register');
add('br r#');
add('newmemaddress:');
add('dq newmem');
end
else
begin
if farjmp then
add('jmp far newmem'+inttostr(injectnr)+'')

if jmp1 then
add('jmp1 newmem')
else
add('jmp newmem'+inttostr(injectnr)+'');
begin
if farjmp then
add('jmp far newmem'+inttostr(injectnr)+'')
else
add('jmp newmem'+inttostr(injectnr)+'');
end;
end;

if codesize>jmpsize then
Expand Down

0 comments on commit 7b7b4ea

Please sign in to comment.