Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SandHook
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
SandHook
Commits
c178fa97
Commit
c178fa97
authored
May 10, 2019
by
swift_gan
Committed by
swift_gan
May 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweak code
parent
30c986ac
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
128 additions
and
64 deletions
+128
-64
inst_arm64.cpp
nativehook/src/main/cpp/archs/arm64/inst/inst_arm64.cpp
+33
-22
inst_arm64.h
nativehook/src/main/cpp/archs/arm64/inst/inst_arm64.h
+49
-29
inst_struct_aarch64.h
...ehook/src/main/cpp/archs/arm64/inst/inst_struct_aarch64.h
+11
-2
instruction.h
nativehook/src/main/cpp/asm/instruction.h
+16
-2
base.h
nativehook/src/main/cpp/includes/base.h
+16
-6
code_relocate.h
nativehook/src/main/cpp/includes/code_relocate.h
+1
-1
decoder.h
nativehook/src/main/cpp/includes/decoder.h
+2
-2
No files found.
nativehook/src/main/cpp/archs/arm64/inst/inst_arm64.cpp
View file @
c178fa97
...
@@ -23,8 +23,8 @@ template<typename Inst>
...
@@ -23,8 +23,8 @@ template<typename Inst>
A64_INST_PC_REL
<
Inst
>::
A64_INST_PC_REL
()
{}
A64_INST_PC_REL
<
Inst
>::
A64_INST_PC_REL
()
{}
template
<
typename
Inst
>
template
<
typename
Inst
>
A
DDR
A64_INST_PC_REL
<
Inst
>::
getImmPCOffsetTarget
()
{
A
ddr
A64_INST_PC_REL
<
Inst
>::
getImmPCOffsetTarget
()
{
return
reinterpret_cast
<
ADDR
>
(
this
->
getImmPCOffset
()
+
(
ADDR
)
this
->
getPC
());
return
this
->
getImmPCOffset
()
+
reinterpret_cast
<
Addr
>
(
this
->
getPC
());
}
}
//ADR ADRP
//ADR ADRP
...
@@ -35,26 +35,22 @@ A64_ADR_ADRP::A64_ADR_ADRP(STRUCT_A64(ADR_ADRP) *inst) : A64_INST_PC_REL(inst) {
...
@@ -35,26 +35,22 @@ A64_ADR_ADRP::A64_ADR_ADRP(STRUCT_A64(ADR_ADRP) *inst) : A64_INST_PC_REL(inst) {
decode
(
inst
);
decode
(
inst
);
}
}
ADDR
A64_ADR_ADRP
::
getImmPCOffset
()
{
Off
A64_ADR_ADRP
::
getImmPCOffset
()
{
U32
hi
=
get
()
->
immhi
;
U32
hi
=
get
()
->
immhi
;
U32
lo
=
get
()
->
immlo
;
U32
lo
=
get
()
->
immlo
;
ADDR
offset
=
signExtend64
(
12
,
COMBINE
(
hi
,
lo
,
IMM_LO_W
));
Off
offset
=
signExtend64
(
IMM_LO_W
+
IMM_HI_W
,
COMBINE
(
hi
,
lo
,
IMM_LO_W
));
if
(
isADRP
())
{
if
(
isADRP
())
{
offset
*=
PAGE_SIZE
;
offset
*=
PAGE_SIZE
;
}
}
return
offset
;
return
offset
;
}
}
A
DDR
A64_ADR_ADRP
::
getImmPCOffsetTarget
()
{
A
ddr
A64_ADR_ADRP
::
getImmPCOffsetTarget
()
{
void
*
base
=
AlignDown
(
getPC
(),
PAGE_SIZE
);
void
*
base
=
AlignDown
(
getPC
(),
PAGE_SIZE
);
return
reinterpret_cast
<
ADDR
>
(
getImmPCOffset
()
+
(
ADDR
)
base
);
return
getImmPCOffset
()
+
reinterpret_cast
<
Addr
>
(
base
);
}
}
int
A64_ADR_ADRP
::
getImm
()
{
A64_ADR_ADRP
::
A64_ADR_ADRP
(
A64_ADR_ADRP
::
OP
op
,
RegisterA64
*
rd
,
S64
imme
)
:
op
(
op
),
rd
(
rd
),
return
getImmPCOffset
();
}
A64_ADR_ADRP
::
A64_ADR_ADRP
(
A64_ADR_ADRP
::
OP
op
,
RegisterA64
*
rd
,
int
imme
)
:
op
(
op
),
rd
(
rd
),
imme
(
imme
)
{
imme
(
imme
)
{
assembler
();
assembler
();
}
}
...
@@ -111,11 +107,11 @@ A64_B_BL::A64_B_BL(STRUCT_A64(B_BL) *inst) : A64_INST_PC_REL(inst) {
...
@@ -111,11 +107,11 @@ A64_B_BL::A64_B_BL(STRUCT_A64(B_BL) *inst) : A64_INST_PC_REL(inst) {
decode
(
inst
);
decode
(
inst
);
}
}
A64_B_BL
::
A64_B_BL
(
A64_B_BL
::
OP
op
,
ADDR
offset
)
:
op
(
op
),
offset
(
offset
)
{
A64_B_BL
::
A64_B_BL
(
A64_B_BL
::
OP
op
,
Off
offset
)
:
op
(
op
),
offset
(
offset
)
{
assembler
();
assembler
();
}
}
ADDR
A64_B_BL
::
getImmPCOffset
()
{
Off
A64_B_BL
::
getImmPCOffset
()
{
return
signExtend64
(
26
+
2
,
COMBINE
(
get
()
->
imm26
,
0
b00
,
2
));
return
signExtend64
(
26
+
2
,
COMBINE
(
get
()
->
imm26
,
0
b00
,
2
));
}
}
...
@@ -140,13 +136,13 @@ A64_CBZ_CBNZ::A64_CBZ_CBNZ(STRUCT_A64(CBZ_CBNZ) *inst) : A64_INST_PC_REL(inst) {
...
@@ -140,13 +136,13 @@ A64_CBZ_CBNZ::A64_CBZ_CBNZ(STRUCT_A64(CBZ_CBNZ) *inst) : A64_INST_PC_REL(inst) {
decode
(
inst
);
decode
(
inst
);
}
}
A64_CBZ_CBNZ
::
A64_CBZ_CBNZ
(
A64_CBZ_CBNZ
::
OP
op
,
ADDR
offset
,
RegisterA64
*
rt
)
:
op
(
op
),
A64_CBZ_CBNZ
::
A64_CBZ_CBNZ
(
A64_CBZ_CBNZ
::
OP
op
,
Off
offset
,
RegisterA64
*
rt
)
:
op
(
op
),
offset
(
offset
),
offset
(
offset
),
rt
(
rt
)
{
rt
(
rt
)
{
assembler
();
assembler
();
}
}
ADDR
A64_CBZ_CBNZ
::
getImmPCOffset
()
{
Off
A64_CBZ_CBNZ
::
getImmPCOffset
()
{
return
signExtend64
(
19
+
2
,
COMBINE
(
get
()
->
imm19
,
0
b00
,
2
));
return
signExtend64
(
19
+
2
,
COMBINE
(
get
()
->
imm19
,
0
b00
,
2
));
}
}
...
@@ -177,11 +173,11 @@ A64_B_COND::A64_B_COND(STRUCT_A64(B_COND) *inst) : A64_INST_PC_REL(inst) {
...
@@ -177,11 +173,11 @@ A64_B_COND::A64_B_COND(STRUCT_A64(B_COND) *inst) : A64_INST_PC_REL(inst) {
decode
(
inst
);
decode
(
inst
);
}
}
A64_B_COND
::
A64_B_COND
(
Condition
condition
,
ADDR
offset
)
:
condition
(
condition
),
offset
(
offset
)
{
A64_B_COND
::
A64_B_COND
(
Condition
condition
,
Off
offset
)
:
condition
(
condition
),
offset
(
offset
)
{
assembler
();
assembler
();
}
}
ADDR
A64_B_COND
::
getImmPCOffset
()
{
Off
A64_B_COND
::
getImmPCOffset
()
{
return
signExtend64
(
19
+
2
,
COMBINE
(
get
()
->
imm19
,
0
b00
,
2
));
return
signExtend64
(
19
+
2
,
COMBINE
(
get
()
->
imm19
,
0
b00
,
2
));
}
}
...
@@ -205,14 +201,14 @@ A64_TBZ_TBNZ::A64_TBZ_TBNZ(STRUCT_A64(TBZ_TBNZ) *inst) : A64_INST_PC_REL(inst) {
...
@@ -205,14 +201,14 @@ A64_TBZ_TBNZ::A64_TBZ_TBNZ(STRUCT_A64(TBZ_TBNZ) *inst) : A64_INST_PC_REL(inst) {
decode
(
inst
);
decode
(
inst
);
}
}
A64_TBZ_TBNZ
::
A64_TBZ_TBNZ
(
A64_TBZ_TBNZ
::
OP
op
,
RegisterA64
*
rt
,
U32
bit
,
ADDR
offset
)
:
op
(
op
),
A64_TBZ_TBNZ
::
A64_TBZ_TBNZ
(
A64_TBZ_TBNZ
::
OP
op
,
RegisterA64
*
rt
,
U32
bit
,
Off
offset
)
:
op
(
op
),
rt
(
rt
),
rt
(
rt
),
bit
(
bit
),
bit
(
bit
),
offset
(
offset
)
{
offset
(
offset
)
{
assembler
();
assembler
();
}
}
ADDR
A64_TBZ_TBNZ
::
getImmPCOffset
()
{
Off
A64_TBZ_TBNZ
::
getImmPCOffset
()
{
return
signExtend64
(
14
+
2
,
COMBINE
(
get
()
->
imm14
,
0
b00
,
2
));
return
signExtend64
(
14
+
2
,
COMBINE
(
get
()
->
imm14
,
0
b00
,
2
));
}
}
...
@@ -247,12 +243,12 @@ A64_LDR_LIT::A64_LDR_LIT(STRUCT_A64(LDR_LIT) *inst) : A64_INST_PC_REL(inst) {
...
@@ -247,12 +243,12 @@ A64_LDR_LIT::A64_LDR_LIT(STRUCT_A64(LDR_LIT) *inst) : A64_INST_PC_REL(inst) {
}
}
A64_LDR_LIT
::
A64_LDR_LIT
(
A64_LDR_LIT
::
OP
op
,
RegisterA64
*
rt
,
ADDR
offset
)
:
op
(
op
),
rt
(
rt
),
A64_LDR_LIT
::
A64_LDR_LIT
(
A64_LDR_LIT
::
OP
op
,
RegisterA64
*
rt
,
Off
offset
)
:
op
(
op
),
rt
(
rt
),
offset
(
offset
)
{
offset
(
offset
)
{
assembler
();
assembler
();
}
}
ADDR
A64_LDR_LIT
::
getImmPCOffset
()
{
Off
A64_LDR_LIT
::
getImmPCOffset
()
{
return
signExtend64
(
19
+
2
,
COMBINE
(
get
()
->
imm19
,
0
b00
,
2
));
return
signExtend64
(
19
+
2
,
COMBINE
(
get
()
->
imm19
,
0
b00
,
2
));
}
}
...
@@ -282,7 +278,12 @@ A64_STR_IMM::A64_STR_IMM(STRUCT_A64(STR_IMM) *inst) : InstructionA64(inst) {
...
@@ -282,7 +278,12 @@ A64_STR_IMM::A64_STR_IMM(STRUCT_A64(STR_IMM) *inst) : InstructionA64(inst) {
decode
(
inst
);
decode
(
inst
);
}
}
A64_STR_IMM
::
A64_STR_IMM
(
RegisterA64
*
rt
,
const
MemOperand
&
operand
)
:
rt
(
rt
),
operand
(
operand
)
{
A64_STR_IMM
::
A64_STR_IMM
(
RegisterA64
&
rt
,
const
MemOperand
&
operand
)
:
rt
(
&
rt
),
operand
(
operand
)
{
assembler
();
}
A64_STR_IMM
::
A64_STR_IMM
(
Condition
condition
,
RegisterA64
&
rt
,
const
MemOperand
&
operand
)
:
condition
(
condition
),
rt
(
&
rt
),
operand
(
operand
)
{
assembler
();
assembler
();
}
}
...
@@ -294,6 +295,16 @@ AddrMode A64_STR_IMM::decodeAddrMode() {
...
@@ -294,6 +295,16 @@ AddrMode A64_STR_IMM::decodeAddrMode() {
}
else
if
(
get
()
->
P
==
1
&&
get
()
->
W
==
1
)
{
}
else
if
(
get
()
->
P
==
1
&&
get
()
->
W
==
1
)
{
return
PreIndex
;
return
PreIndex
;
}
else
{
}
else
{
valid
=
false
;
return
NonAddrMode
;
return
NonAddrMode
;
}
}
}
}
void
A64_STR_IMM
::
decode
(
STRUCT_A64
(
STR_IMM
)
*
inst
)
{
Instruction
::
decode
(
inst
);
}
void
A64_STR_IMM
::
assembler
()
{
INST_DCHECK
(
condition
,
Condition
::
nv
)
}
nativehook/src/main/cpp/archs/arm64/inst/inst_arm64.h
View file @
c178fa97
...
@@ -26,6 +26,18 @@ inst_test.raw = inst; \
...
@@ -26,6 +26,18 @@ inst_test.raw = inst; \
return inst_test.inst.opcode == OPCODE_A64(X); \
return inst_test.inst.opcode == OPCODE_A64(X); \
}
}
#define DEFINE_IS_EXT(X, EXT_COND) \
inline static bool is(InstA64& inst) { \
union { \
InstA64 raw; \
STRUCT_A64(X) inst; \
} inst_test; \
inst_test.raw = inst; \
return inst_test.inst.opcode == OPCODE_A64(X) && EXT_COND; \
}
#define TEST_INST_FIELD(F,V) inst_test.inst.F == V
namespace
SandHook
{
namespace
SandHook
{
namespace
Asm
{
namespace
Asm
{
...
@@ -48,9 +60,12 @@ namespace SandHook {
...
@@ -48,9 +60,12 @@ namespace SandHook {
return
value
<<
(
32
-
bits
);
return
value
<<
(
32
-
bits
);
}
}
static
inline
U64
signExtend64
(
unsigned
int
bits
,
U64
value
)
{
static
inline
S64
signExtend64
(
unsigned
int
bits
,
U64
value
)
{
U64
C
=
(
U64
)
((
-
1
)
<<
(
bits
-
(
U64
)
1
));
return
ExtractSignedBitfield64
(
bits
-
1
,
0
,
value
);
return
static_cast
<
U64
>
((
value
+
C
)
^
C
);
}
static
inline
S32
signExtend32
(
unsigned
int
bits
,
U32
value
)
{
return
ExtractSignedBitfield32
(
bits
-
1
,
0
,
value
);
}
}
bool
isPCRelAddressing
()
{
bool
isPCRelAddressing
()
{
...
@@ -151,9 +166,9 @@ namespace SandHook {
...
@@ -151,9 +166,9 @@ namespace SandHook {
A64_INST_PC_REL
(
Inst
*
inst
);
A64_INST_PC_REL
(
Inst
*
inst
);
virtual
ADDR
getImmPCOffset
()
=
0
;
virtual
Off
getImmPCOffset
()
=
0
;
virtual
A
DDR
getImmPCOffsetTarget
();
virtual
A
ddr
getImmPCOffsetTarget
();
};
};
...
@@ -171,7 +186,7 @@ namespace SandHook {
...
@@ -171,7 +186,7 @@ namespace SandHook {
A64_ADR_ADRP
(
STRUCT_A64
(
ADR_ADRP
)
*
inst
);
A64_ADR_ADRP
(
STRUCT_A64
(
ADR_ADRP
)
*
inst
);
A64_ADR_ADRP
(
OP
op
,
RegisterA64
*
rd
,
int
imme
);
A64_ADR_ADRP
(
OP
op
,
RegisterA64
*
rd
,
S64
imme
);
DEFINE_IS
(
ADR_ADRP
)
DEFINE_IS
(
ADR_ADRP
)
...
@@ -183,11 +198,9 @@ namespace SandHook {
...
@@ -183,11 +198,9 @@ namespace SandHook {
return
get
()
->
op
==
OP
::
ADRP
;
return
get
()
->
op
==
OP
::
ADRP
;
}
}
ADDR
getImmPCOffset
()
override
;
Off
getImmPCOffset
()
override
;
ADDR
getImmPCOffsetTarget
()
override
;
int
getImm
()
;
Addr
getImmPCOffsetTarget
()
override
;
void
decode
(
STRUCT_A64
(
ADR_ADRP
)
*
decode
)
override
;
void
decode
(
STRUCT_A64
(
ADR_ADRP
)
*
decode
)
override
;
...
@@ -196,7 +209,7 @@ namespace SandHook {
...
@@ -196,7 +209,7 @@ namespace SandHook {
public
:
public
:
OP
op
;
OP
op
;
RegisterA64
*
rd
;
RegisterA64
*
rd
;
int
imme
;
S64
imme
;
};
};
...
@@ -278,11 +291,11 @@ namespace SandHook {
...
@@ -278,11 +291,11 @@ namespace SandHook {
A64_B_BL
(
STRUCT_A64
(
B_BL
)
*
inst
);
A64_B_BL
(
STRUCT_A64
(
B_BL
)
*
inst
);
A64_B_BL
(
OP
op
,
ADDR
offset
);
A64_B_BL
(
OP
op
,
Off
offset
);
DEFINE_IS
(
B_BL
)
DEFINE_IS
(
B_BL
)
inline
ADDR
getOffset
()
{
inline
Off
getOffset
()
{
return
offset
;
return
offset
;
}
}
...
@@ -294,7 +307,7 @@ namespace SandHook {
...
@@ -294,7 +307,7 @@ namespace SandHook {
return
op
==
B
?
UnconditionalBranchOp
::
B
:
UnconditionalBranchOp
::
BL
;
return
op
==
B
?
UnconditionalBranchOp
::
B
:
UnconditionalBranchOp
::
BL
;
};
};
ADDR
getImmPCOffset
()
override
;
Off
getImmPCOffset
()
override
;
void
decode
(
STRUCT_A64
(
B_BL
)
*
decode
)
override
;
void
decode
(
STRUCT_A64
(
B_BL
)
*
decode
)
override
;
...
@@ -303,7 +316,7 @@ namespace SandHook {
...
@@ -303,7 +316,7 @@ namespace SandHook {
public
:
public
:
OP
op
;
OP
op
;
ADDR
offset
;
Off
offset
;
};
};
...
@@ -319,7 +332,7 @@ namespace SandHook {
...
@@ -319,7 +332,7 @@ namespace SandHook {
A64_CBZ_CBNZ
(
STRUCT_A64
(
CBZ_CBNZ
)
*
inst
);
A64_CBZ_CBNZ
(
STRUCT_A64
(
CBZ_CBNZ
)
*
inst
);
A64_CBZ_CBNZ
(
OP
op
,
ADDR
offset
,
RegisterA64
*
rt
);
A64_CBZ_CBNZ
(
OP
op
,
Off
offset
,
RegisterA64
*
rt
);
DEFINE_IS
(
CBZ_CBNZ
)
DEFINE_IS
(
CBZ_CBNZ
)
...
@@ -327,7 +340,7 @@ namespace SandHook {
...
@@ -327,7 +340,7 @@ namespace SandHook {
return
op
==
CBZ
?
CompareBranchOp
::
CBZ
:
CompareBranchOp
::
CBNZ
;
return
op
==
CBZ
?
CompareBranchOp
::
CBZ
:
CompareBranchOp
::
CBNZ
;
}
}
ADDR
getImmPCOffset
()
override
;
Off
getImmPCOffset
()
override
;
void
decode
(
STRUCT_A64
(
CBZ_CBNZ
)
*
inst
)
override
;
void
decode
(
STRUCT_A64
(
CBZ_CBNZ
)
*
inst
)
override
;
...
@@ -335,7 +348,7 @@ namespace SandHook {
...
@@ -335,7 +348,7 @@ namespace SandHook {
public
:
public
:
OP
op
;
OP
op
;
ADDR
offset
;
Off
offset
;
RegisterA64
*
rt
;
RegisterA64
*
rt
;
};
};
...
@@ -346,7 +359,7 @@ namespace SandHook {
...
@@ -346,7 +359,7 @@ namespace SandHook {
A64_B_COND
(
STRUCT_A64
(
B_COND
)
*
inst
);
A64_B_COND
(
STRUCT_A64
(
B_COND
)
*
inst
);
A64_B_COND
(
Condition
condition
,
ADDR
offset
);
A64_B_COND
(
Condition
condition
,
Off
offset
);
DEFINE_IS
(
B_COND
)
DEFINE_IS
(
B_COND
)
...
@@ -354,7 +367,7 @@ namespace SandHook {
...
@@ -354,7 +367,7 @@ namespace SandHook {
return
B_cond
;
return
B_cond
;
}
}
ADDR
getImmPCOffset
()
override
;
Off
getImmPCOffset
()
override
;
void
decode
(
STRUCT_A64
(
B_COND
)
*
inst
)
override
;
void
decode
(
STRUCT_A64
(
B_COND
)
*
inst
)
override
;
...
@@ -362,7 +375,7 @@ namespace SandHook {
...
@@ -362,7 +375,7 @@ namespace SandHook {
public
:
public
:
Condition
condition
;
Condition
condition
;
ADDR
offset
;
Off
offset
;
};
};
...
@@ -378,7 +391,7 @@ namespace SandHook {
...
@@ -378,7 +391,7 @@ namespace SandHook {
A64_TBZ_TBNZ
(
STRUCT_A64
(
TBZ_TBNZ
)
*
inst
);
A64_TBZ_TBNZ
(
STRUCT_A64
(
TBZ_TBNZ
)
*
inst
);
A64_TBZ_TBNZ
(
OP
op
,
RegisterA64
*
rt
,
U32
bit
,
ADDR
offset
);
A64_TBZ_TBNZ
(
OP
op
,
RegisterA64
*
rt
,
U32
bit
,
Off
offset
);
DEFINE_IS
(
TBZ_TBNZ
)
DEFINE_IS
(
TBZ_TBNZ
)
...
@@ -386,7 +399,7 @@ namespace SandHook {
...
@@ -386,7 +399,7 @@ namespace SandHook {
return
op
==
TBZ
?
TestBranchOp
::
TBZ
:
TestBranchOp
::
TBNZ
;
return
op
==
TBZ
?
TestBranchOp
::
TBZ
:
TestBranchOp
::
TBNZ
;
};
};
ADDR
getImmPCOffset
()
override
;
Off
getImmPCOffset
()
override
;
void
decode
(
STRUCT_A64
(
TBZ_TBNZ
)
*
inst
)
override
;
void
decode
(
STRUCT_A64
(
TBZ_TBNZ
)
*
inst
)
override
;
...
@@ -396,7 +409,7 @@ namespace SandHook {
...
@@ -396,7 +409,7 @@ namespace SandHook {
OP
op
;
OP
op
;
RegisterA64
*
rt
;
RegisterA64
*
rt
;
U32
bit
;
U32
bit
;
ADDR
offset
;
Off
offset
;
};
};
...
@@ -414,7 +427,7 @@ namespace SandHook {
...
@@ -414,7 +427,7 @@ namespace SandHook {
A64_LDR_LIT
(
STRUCT_A64
(
LDR_LIT
)
*
inst
);
A64_LDR_LIT
(
STRUCT_A64
(
LDR_LIT
)
*
inst
);
A64_LDR_LIT
(
OP
op
,
RegisterA64
*
rt
,
ADDR
offset
);
A64_LDR_LIT
(
OP
op
,
RegisterA64
*
rt
,
Off
offset
);
DEFINE_IS
(
LDR_LIT
)
DEFINE_IS
(
LDR_LIT
)
...
@@ -431,7 +444,7 @@ namespace SandHook {
...
@@ -431,7 +444,7 @@ namespace SandHook {
}
}
}
}
ADDR
getImmPCOffset
()
override
;
Off
getImmPCOffset
()
override
;
void
decode
(
STRUCT_A64
(
LDR_LIT
)
*
inst
)
override
;
void
decode
(
STRUCT_A64
(
LDR_LIT
)
*
inst
)
override
;
...
@@ -440,7 +453,7 @@ namespace SandHook {
...
@@ -440,7 +453,7 @@ namespace SandHook {
public
:
public
:
OP
op
;
OP
op
;
RegisterA64
*
rt
;
RegisterA64
*
rt
;
ADDR
offset
;
Off
offset
;
};
};
...
@@ -451,9 +464,15 @@ namespace SandHook {
...
@@ -451,9 +464,15 @@ namespace SandHook {
A64_STR_IMM
(
STRUCT_A64
(
STR_IMM
)
*
inst
);
A64_STR_IMM
(
STRUCT_A64
(
STR_IMM
)
*
inst
);
A64_STR_IMM
(
RegisterA64
*
rt
,
const
MemOperand
&
operand
);
A64_STR_IMM
(
RegisterA64
&
rt
,
const
MemOperand
&
operand
);
DEFINE_IS
(
STR_IMM
)
A64_STR_IMM
(
Condition
condition
,
RegisterA64
&
rt
,
const
MemOperand
&
operand
);
DEFINE_IS_EXT
(
STR_IMM
,
TEST_INST_FIELD
(
unkown1_0
,
0
)
&&
TEST_INST_FIELD
(
unkown2_0
,
0
))
void
decode
(
STRUCT_A64
(
STR_IMM
)
*
inst
)
override
;
void
assembler
()
override
;
AddrMode
getAddrMode
()
{
AddrMode
getAddrMode
()
{
return
operand
.
addr_mode
;
return
operand
.
addr_mode
;
...
@@ -463,6 +482,7 @@ namespace SandHook {
...
@@ -463,6 +482,7 @@ namespace SandHook {
AddrMode
decodeAddrMode
();
AddrMode
decodeAddrMode
();
public
:
public
:
Condition
condition
=
Condition
::
al
;
RegisterA64
*
rt
;
RegisterA64
*
rt
;
MemOperand
operand
=
MemOperand
(
nullptr
);
MemOperand
operand
=
MemOperand
(
nullptr
);
private
:
private
:
...
...
nativehook/src/main/cpp/archs/arm64/inst/inst_struct_aarch64.h
View file @
c178fa97
...
@@ -156,14 +156,23 @@ struct STRUCT_A64(STR_IMM) {
...
@@ -156,14 +156,23 @@ struct STRUCT_A64(STR_IMM) {
InstA64
cond
:
4
;
InstA64
cond
:
4
;
InstA64
opcode
:
3
;
InstA64
opcode
:
3
;
InstA64
P
:
1
;
InstA64
P
:
1
;
InstA64
unkown
:
1
;
InstA64
U
:
1
;
InstA64
unkown1_0
:
1
;
InstA64
W
:
1
;
InstA64
W
:
1
;
InstA64
unkown2
:
1
;
InstA64
unkown2
_0
:
1
;
InstA64
rn
:
4
;
InstA64
rn
:
4
;
InstA64
rt
:
4
;
InstA64
rt
:
4
;
InstA64
imm12
:
12
;
InstA64
imm12
:
12
;
};
};
DEFINE_OPCODE
(
BR
,
0
b00101
)
struct
STRUCT_A64
(
BR
)
{
InstA64
op
:
1
;
InstA64
opcode
:
5
;
InstA64
imm26
:
26
;
};
#endif //SANDHOOK_NH_INST_AARCH64_H
#endif //SANDHOOK_NH_INST_AARCH64_H
nativehook/src/main/cpp/asm/instruction.h
View file @
c178fa97
...
@@ -21,6 +21,13 @@ typedef U32 InstT32;
...
@@ -21,6 +21,13 @@ typedef U32 InstT32;
typedef
U32
InstRaw
;
typedef
U32
InstRaw
;
#endif
#endif
#define INST_CHECK(X,V) \
CHECK(X,V, valid = false;)
#define INST_DCHECK(X,V) \
DCHECK(X,V, valid = false;)
namespace
SandHook
{
namespace
SandHook
{
namespace
Asm
{
namespace
Asm
{
...
@@ -43,8 +50,8 @@ namespace SandHook {
...
@@ -43,8 +50,8 @@ namespace SandHook {
*
this
->
raw
=
raw
;
*
this
->
raw
=
raw
;
}
}
inline
void
*
getPC
()
const
{
virtual
void
*
getPC
()
{
return
raw
;
return
auto_alloc
?
nullptr
:
raw
;
}
}
inline
Raw
*
get
()
const
{
inline
Raw
*
get
()
const
{
...
@@ -106,9 +113,16 @@ namespace SandHook {
...
@@ -106,9 +113,16 @@ namespace SandHook {
return
false
;
return
false
;
}
}
inline
bool
isValid
()
const
{
return
valid
;
}
virtual
void
decode
(
Inst
*
inst
)
{}
virtual
void
decode
(
Inst
*
inst
)
{}
virtual
void
assembler
()
{}
virtual
void
assembler
()
{}
protected
:
bool
valid
=
true
;
};
};
template
<
typename
DType
>
template
<
typename
DType
>
...
...
nativehook/src/main/cpp/includes/base.h
View file @
c178fa97
...
@@ -19,7 +19,8 @@ typedef int16_t S16;
...
@@ -19,7 +19,8 @@ typedef int16_t S16;
typedef
int32_t
S32
;
typedef
int32_t
S32
;
typedef
int64_t
S64
;
typedef
int64_t
S64
;
typedef
size_t
ADDR
;
typedef
size_t
Addr
;
typedef
S64
Off
;
const
int
PTR_BYTE
=
sizeof
(
void
*
);
const
int
PTR_BYTE
=
sizeof
(
void
*
);
...
@@ -27,7 +28,7 @@ const int PTR_BYTE = sizeof(void*);
...
@@ -27,7 +28,7 @@ const int PTR_BYTE = sizeof(void*);
const
int
BITS_OF_BYTE
=
8
;
const
int
BITS_OF_BYTE
=
8
;
const
A
DDR
PAGE_SIZE
=
2
<<
PAGE_OFFSET
;
const
A
ddr
PAGE_SIZE
=
2
<<
PAGE_OFFSET
;
enum
Arch
{
enum
Arch
{
arm32
,
arm32
,
...
@@ -114,10 +115,10 @@ T AlignDown(T pointer,
...
@@ -114,10 +115,10 @@ T AlignDown(T pointer,
#endif
#endif
//只保留低N位
inline
uint64_t
TruncateToUintN
(
unsigned
n
,
uint64_t
x
)
{
inline
uint64_t
TruncateToUintN
(
unsigned
n
,
uint64_t
x
)
{
return
static_cast
<
uint64_t
>
(
x
)
&
((
UINT64_C
(
1
)
<<
n
)
-
1
);
return
static_cast
<
uint64_t
>
(
x
)
&
((
UINT64_C
(
1
)
<<
n
)
-
1
);
}
}
VIXL_DEPRECATED
(
"TruncateToUintN"
,
VIXL_DEPRECATED
(
"TruncateToUintN"
,
inline
uint64_t
truncate_to_intn
(
unsigned
n
,
int64_t
x
))
{
inline
uint64_t
truncate_to_intn
(
unsigned
n
,
int64_t
x
))
{
return
TruncateToUintN
(
n
,
x
);
return
TruncateToUintN
(
n
,
x
);
...
@@ -151,6 +152,7 @@ V(57) V(58) V(59) V(60) V(61) V(62) V(63)
...
@@ -151,6 +152,7 @@ V(57) V(58) V(59) V(60) V(61) V(62) V(63)
INT_1_TO_32_LIST
(
DECLARE_TRUNCATE_TO_UINT_32
)
INT_1_TO_32_LIST
(
DECLARE_TRUNCATE_TO_UINT_32
)
#undef DECLARE_TRUNCATE_TO_INT_N
#undef DECLARE_TRUNCATE_TO_INT_N
//位提取
// Bit field extraction.
// Bit field extraction.
inline
uint64_t
ExtractUnsignedBitfield64
(
int
msb
,
int
lsb
,
uint64_t
x
)
{
inline
uint64_t
ExtractUnsignedBitfield64
(
int
msb
,
int
lsb
,
uint64_t
x
)
{
if
((
msb
==
63
)
&&
(
lsb
==
0
))
return
x
;
if
((
msb
==
63
)
&&
(
lsb
==
0
))
return
x
;
...
@@ -158,7 +160,7 @@ inline uint64_t ExtractUnsignedBitfield64(int msb, int lsb, uint64_t x) {
...
@@ -158,7 +160,7 @@ inline uint64_t ExtractUnsignedBitfield64(int msb, int lsb, uint64_t x) {
}
}
inline
int64_t
ExtractSignedBitfield64
(
int
msb
,
int
lsb
,
int64_t
x
)
{
inline
int64_t
ExtractSignedBitfield64
(
int
msb
,
int
lsb
,
U64
x
)
{
uint64_t
temp
=
ExtractUnsignedBitfield64
(
msb
,
lsb
,
x
);
uint64_t
temp
=
ExtractUnsignedBitfield64
(
msb
,
lsb
,
x
);
// If the highest extracted bit is set, sign extend.
// If the highest extracted bit is set, sign extend.
if
((
temp
>>
(
msb
-
lsb
))
==
1
)
{
if
((
temp
>>
(
msb
-
lsb
))
==
1
)
{
...
@@ -169,7 +171,7 @@ inline int64_t ExtractSignedBitfield64(int msb, int lsb, int64_t x) {
...
@@ -169,7 +171,7 @@ inline int64_t ExtractSignedBitfield64(int msb, int lsb, int64_t x) {
return
result
;
return
result
;
}
}
inline
int32_t
ExtractSignedBitfield32
(
int
msb
,
int
lsb
,
int32_t
x
)
{
inline
int32_t
ExtractSignedBitfield32
(
int
msb
,
int
lsb
,
U32
x
)
{
uint32_t
temp
=
TruncateToUint32
(
ExtractSignedBitfield64
(
msb
,
lsb
,
x
));
uint32_t
temp
=
TruncateToUint32
(
ExtractSignedBitfield64
(
msb
,
lsb
,
x
));
int32_t
result
;
int32_t
result
;
memcpy
(
&
result
,
&
temp
,
sizeof
(
result
));
memcpy
(
&
result
,
&
temp
,
sizeof
(
result
));
...
@@ -207,7 +209,15 @@ inline int32_t BITS32H(int64_t value) {
...
@@ -207,7 +209,15 @@ inline int32_t BITS32H(int64_t value) {
#define SBITS(obj, st, fn) ((long)(BITS(obj, st, fn) | ((long)BIT(obj, fn) * ~SUB_MASK(fn - st))))
#define SBITS(obj, st, fn) ((long)(BITS(obj, st, fn) | ((long)BIT(obj, fn) * ~SUB_MASK(fn - st))))
//big little edd
#define DCHECK(X,V, ACTION) \
if (X == V) { \
ACTION \
}
#define CHECK(X,V, ACTION) \
if (X != V) { \
ACTION \
}
#endif //SANDHOOK_BASE_H
#endif //SANDHOOK_BASE_H
nativehook/src/main/cpp/includes/code_relocate.h
View file @
c178fa97
...
@@ -19,7 +19,7 @@ namespace SandHook {
...
@@ -19,7 +19,7 @@ namespace SandHook {
template
<
typename
Raw
>
template
<
typename
Raw
>
class
CodeRelocate
{
class
CodeRelocate
{
virtual
bool
relocate
(
A
DDR
toPc
,
CodeRelocateCallback
<
Raw
>&
callback
)
throw
(
ErrorCodeException
)
=
0
;
virtual
bool
relocate
(
A
ddr
toPc
,
CodeRelocateCallback
<
Raw
>&
callback
)
throw
(
ErrorCodeException
)
=
0
;
};
};
}
}
...
...
nativehook/src/main/cpp/includes/decoder.h
View file @
c178fa97
...
@@ -15,12 +15,12 @@ namespace SandHook {
...
@@ -15,12 +15,12 @@ namespace SandHook {
class
InstVisitor
{
class
InstVisitor
{
public
:
public
:
virtual
bool
visit
(
Instruction
<
void
>*
inst
,
A
DDR
offset
,
ADDR
length
)
=
0
;
virtual
bool
visit
(
Instruction
<
void
>*
inst
,
A
ddr
offset
,
Addr
length
)
=
0
;
};
};
class
InstDecoder
{
class
InstDecoder
{
public
:
public
:
virtual
void
decode
(
void
*
codeStart
,
A
DDR
codeLen
,
InstVisitor
*
visitor
)
=
0
;
virtual
void
decode
(
void
*
codeStart
,
A
ddr
codeLen
,
InstVisitor
*
visitor
)
=
0
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment