Skip to content

Commit

Permalink
fix a bunch more disassembler issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cheat-engine committed Mar 9, 2022
1 parent 5848876 commit 3cffc04
Showing 1 changed file with 49 additions and 32 deletions.
81 changes: 49 additions & 32 deletions Cheat Engine/disassemblerarm64.pas
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ implementation
);

ArmInstructionsUnconditionalBranchImm: array of TOpcode= (
(mnemonic:'B'; params:((ptype:pt_label; offset:0; maxval: $7FFFFFF )); mask:%11111100000000000000000000000000; value: %00010100000000000000000000000000),
(mnemonic:'BL'; params:((ptype:pt_label; offset:0; maxval: $7FFFFFF )); mask:%11111100000000000000000000000000; value: %10010100000000000000000000000000)
(mnemonic:'B'; params:((ptype:pt_label; offset:0; maxval: $3FFFFFF )); mask:%11111100000000000000000000000000; value: %00010100000000000000000000000000),
(mnemonic:'BL'; params:((ptype:pt_label; offset:0; maxval: $3FFFFFF )); mask:%11111100000000000000000000000000; value: %10010100000000000000000000000000)
);


Expand Down Expand Up @@ -529,30 +529,30 @@ implementation
);

ArmInstructionsLoadStoreRegisterUnsignedImmediate: array of TOpcode=(
(mnemonic:'STRB'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111001000000000000000000000000),
(mnemonic:'STRH'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111001000000000000000000000000),
(mnemonic:'LDRB'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111001010000000000000000000000),
(mnemonic:'LDRH'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111001010000000000000000000000),
(mnemonic:'LDRSB'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %00111001110000000000000000000000),
(mnemonic:'LDRSB'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %00111001100000000000000000000000),
(mnemonic:'LDRSH'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %01111001110000000000000000000000),
(mnemonic:'LDRSH'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %01111001100000000000000000000000),
(mnemonic:'LDRSW'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %10111001100000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111001000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111001000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_breg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_hreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_sreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_dreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_qreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101100000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111001010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111001010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_breg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_hreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_sreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_dreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_qreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101110000000000000000000000),
(mnemonic:'PRFM'; params:((ptype:pt_prfop; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 12; maxval:$fff; extra:0; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %11111001100000000000000000000000)
(mnemonic:'STRB'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:1; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111001000000000000000000000000),
(mnemonic:'STRH'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:2; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111001000000000000000000000000),
(mnemonic:'LDRB'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:1; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111001010000000000000000000000),
(mnemonic:'LDRH'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:2; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111001010000000000000000000000),
(mnemonic:'LDRSB'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:1; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %00111001110000000000000000000000),
(mnemonic:'LDRSB'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:1; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %00111001100000000000000000000000),
(mnemonic:'LDRSH'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:2; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %01111001110000000000000000000000),
(mnemonic:'LDRSH'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:2; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %01111001100000000000000000000000),
(mnemonic:'LDRSW'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:4; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %10111001100000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:4; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111001000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:8; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111001000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_breg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:1; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_hreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:2; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_sreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:4; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_dreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:8; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111101000000000000000000000000),
(mnemonic:'STR'; params:((ptype:pt_qreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:16; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101100000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_wreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:4; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111001010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_xreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:8; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111001010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_breg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:1; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_hreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:2; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %01111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_sreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:4; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %10111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_dreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:8; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %11111101010000000000000000000000),
(mnemonic:'LDR'; params:((ptype:pt_qreg; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:16; optional:false; defvalue:0; index: ind_stop)); mask: %11111111110000000000000000000000; value: %00111101110000000000000000000000),
(mnemonic:'PRFM'; params:((ptype:pt_prfop; offset:0),(ptype:pt_xreg; offset: 5; maxval:31; extra:0; optional:false; defvalue:0; index: ind_index),(ptype:pt_pimm; offset: 10; maxval:$fff; extra:8; optional:false; defvalue:0; index: ind_stop)); mask:%11111111110000000000000000000000; value: %11111001100000000000000000000000)

);

Expand Down Expand Up @@ -2922,7 +2922,7 @@ function TArm64Instructionset.ParseParametersForDisassembler(plist: TAParameters
var
i: integer;
v,v2,v3: dword;
qv: qword;
qv,qv2: qword;

p,s: string;

Expand Down Expand Up @@ -3181,9 +3181,8 @@ function TArm64Instructionset.ParseParametersForDisassembler(plist: TAParameters
begin
v:=(opcode shr plist[i].offset) and plist[i].maxval;
v:=v shl 2;
qv:=address+SignExtend(v,highestbit(plist[i].maxval)+2);


qv2:=SignExtend(v,highestbit(plist[i].maxval)+2);
qv:=address+qv2;

p:=inttohex(qv,8);
end;
Expand Down Expand Up @@ -3323,8 +3322,10 @@ function TArm64Instructionset.ParseParametersForDisassembler(plist: TAParameters
v:=(opcode shr plist[i].offset) and plist[i].maxval;
if plist[i].optional and (plist[i].defvalue=v) then continue;

if plist[i].extra<>0 then
v:=v*plist[i].extra;

p:='#'+inttohex(Int16(v),1);
p:='#'+inttohex(v,1);
end;

pt_fpimm8:
Expand Down Expand Up @@ -4629,7 +4630,7 @@ function TArm64Instructionset.ParseParameterForAssembler(param:TAParameters; par
opcode:=opcode or (v shl param.offset);
end;

pt_simm, pt_pimm:
pt_simm:
begin
if paramstr[1]<>'#' then exit;
s:=paramstr.Substring(1);
Expand All @@ -4643,6 +4644,22 @@ function TArm64Instructionset.ParseParameterForAssembler(param:TAParameters; par
opcode:=opcode or (v shl param.offset);
end;

pt_pimm:
begin
if paramstr[1]<>'#' then exit;
s:=paramstr.Substring(1);
v:=strtoint('$'+s);
if param.extra=0 then exit; //not implemented properly

if (v mod param.extra)<>0 then exit;

v:=v div param.extra;
if (v and (not param.maxval))<>0 then exit;

opcode:=opcode or (v shl param.offset);
end;


pt_fpimm8:
begin
if paramstr[1]<>'#' then exit;
Expand Down

0 comments on commit 3cffc04

Please sign in to comment.