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
1ae52e14
Commit
1ae52e14
authored
May 29, 2019
by
swift_gan
Committed by
swift_gan
May 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NativeHook]add inst msr mrs
parent
eacc71d2
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
136 additions
and
10 deletions
+136
-10
assembler_arm64.cpp
...rc/main/cpp/archs/arm/arm64/assembler/assembler_arm64.cpp
+8
-0
assembler_arm64.h
.../src/main/cpp/archs/arm/arm64/assembler/assembler_arm64.h
+3
-0
hook_arm64.cpp
nativehook/src/main/cpp/archs/arm/arm64/hook/hook_arm64.cpp
+5
-1
hook_arm64.h
nativehook/src/main/cpp/archs/arm/arm64/hook/hook_arm64.h
+3
-0
inst_arm64.cpp
nativehook/src/main/cpp/archs/arm/arm64/inst/inst_arm64.cpp
+22
-0
inst_arm64.h
nativehook/src/main/cpp/archs/arm/arm64/inst/inst_arm64.h
+35
-6
inst_code_arm64.h
...ehook/src/main/cpp/archs/arm/arm64/inst/inst_code_arm64.h
+2
-1
inst_struct_aarch64.h
...k/src/main/cpp/archs/arm/arm64/inst/inst_struct_aarch64.h
+7
-1
register_arm64.h
...ok/src/main/cpp/archs/arm/arm64/register/register_arm64.h
+37
-0
register_list_arm64.cpp
...main/cpp/archs/arm/arm64/register/register_list_arm64.cpp
+3
-0
register_list_arm64.h
...c/main/cpp/archs/arm/arm64/register/register_list_arm64.h
+6
-0
hook.h
nativehook/src/main/cpp/includes/hook.h
+5
-1
No files found.
nativehook/src/main/cpp/archs/arm/arm64/assembler/assembler_arm64.cpp
View file @
1ae52e14
...
...
@@ -231,6 +231,14 @@ void AssemblerA64::Subs(RegisterA64 &rd, const Operand &operand) {
Emit
(
reinterpret_cast
<
Unit
<
Base
>
*>
(
new
INST_A64
(
ADD_SUB_IMM
)(
INST_A64
(
ADD_SUB_IMM
)
::
SUB
,
INST_A64
(
ADD_SUB_IMM
)
::
Sign
,
rd
,
operand
)));
}
void
AssemblerA64
::
Mrs
(
SystemRegister
&
sysReg
,
RegisterA64
&
rt
)
{
Emit
(
reinterpret_cast
<
Unit
<
Base
>
*>
(
new
INST_A64
(
MSR_MRS
)(
INST_A64
(
MSR_MRS
)
::
MRS
,
sysReg
,
rt
)));
}
void
AssemblerA64
::
Msr
(
SystemRegister
&
sysReg
,
RegisterA64
&
rt
)
{
Emit
(
reinterpret_cast
<
Unit
<
Base
>
*>
(
new
INST_A64
(
MSR_MRS
)(
INST_A64
(
MSR_MRS
)
::
MSR
,
sysReg
,
rt
)));
}
nativehook/src/main/cpp/archs/arm/arm64/assembler/assembler_arm64.h
View file @
1ae52e14
...
...
@@ -83,6 +83,9 @@ namespace SandHook {
void
Sub
(
RegisterA64
&
rd
,
const
Operand
&
operand
);
void
Subs
(
RegisterA64
&
rd
,
const
Operand
&
operand
);
void
Msr
(
SystemRegister
&
sysReg
,
RegisterA64
&
rt
);
void
Mrs
(
SystemRegister
&
sysReg
,
RegisterA64
&
rt
);
public
:
CodeContainer
codeContainer
=
CodeContainer
(
nullptr
);
...
...
nativehook/src/main/cpp/archs/arm/arm64/hook/hook_arm64.cpp
View file @
1ae52e14
...
...
@@ -49,4 +49,8 @@ void *InlineHookArm64Android::inlineHook(void *origin, void *replace) {
//commit inline trampoline
assemblerInline
.
finish
();
return
backup
;
}
\ No newline at end of file
}
bool
InlineHookArm64Android
::
breakPoint
(
void
*
point
,
void
(
*
callback
)(
REG
regs
[],
void
*
sp
))
{
return
false
;
}
nativehook/src/main/cpp/archs/arm/arm64/hook/hook_arm64.h
View file @
1ae52e14
...
...
@@ -18,6 +18,9 @@ namespace SandHook {
delete
hookLock
;
}
void
*
inlineHook
(
void
*
origin
,
void
*
replace
)
override
;
bool
breakPoint
(
void
*
point
,
void
(
*
callback
)(
REG
[],
void
*
))
override
;
protected
:
std
::
mutex
*
hookLock
;
};
...
...
nativehook/src/main/cpp/archs/arm/arm64/inst/inst_arm64.cpp
View file @
1ae52e14
...
...
@@ -844,6 +844,8 @@ void A64_STP_LDP::assembler() {
case
AddrMode
:
:
PreIndex
:
get
()
->
addrmode
=
PreIndex
;
break
;
default
:
valid
=
false
;
}
get
()
->
imm7
=
TruncateToUint7
(
operand
.
offset
>>
(
rt1
->
isX
()
?
3
:
2
));
}
...
...
@@ -895,3 +897,23 @@ void A64_ADD_SUB_IMM::assembler() {
valid
=
false
;
}
}
A64_MSR_MRS
::
A64_MSR_MRS
(
A64_STRUCT_MSR_MRS
&
inst
)
:
InstructionA64
(
&
inst
)
{
decode
(
&
inst
);
}
A64_MSR_MRS
::
A64_MSR_MRS
(
OP
op
,
SystemRegister
&
systemRegister
,
RegisterA64
&
rt
)
:
op
(
op
),
systemRegister
(
&
systemRegister
),
rt
(
&
rt
)
{}
void
A64_MSR_MRS
::
decode
(
A64_STRUCT_MSR_MRS
*
inst
)
{
DECODE_OP
;
DECODE_RT
(
XReg
);
//TODO
}
void
A64_MSR_MRS
::
assembler
()
{
SET_OPCODE
(
MSR_MRS
);
ENCODE_OP
;
ENCODE_RT
;
get
()
->
sysreg
=
systemRegister
->
value
();
}
nativehook/src/main/cpp/archs/arm/arm64/inst/inst_arm64.h
View file @
1ae52e14
...
...
@@ -36,6 +36,8 @@ inline U32 instCode() override { \
return ENUM_VALUE(InstCodeA64, InstCodeA64::X); \
}
#define DEFINE_INST(X) class INST_A64(X) : public InstructionA64<STRUCT_A64(X)>
using
namespace
SandHook
::
RegistersA64
;
using
namespace
SandHook
::
Asm
;
...
...
@@ -471,7 +473,7 @@ namespace SandHook {
};
class
INST_A64
(
BR_BLR_RET
)
:
public
InstructionA64
<
STRUCT_A64
(
BR_BLR_RET
)
>
{
DEFINE_INST
(
BR_BLR_RET
)
{
public
:
enum
OP
{
...
...
@@ -573,7 +575,7 @@ namespace SandHook {
};
class
INST_A64
(
MOV_REG
)
:
public
InstructionA64
<
STRUCT_A64
(
MOV_REG
)
>
{
DEFINE_INST
(
MOV_REG
)
{
public
:
A64_MOV_REG
();
...
...
@@ -596,7 +598,7 @@ namespace SandHook {
};
class
INST_A64
(
SUB_EXT_REG
)
:
public
InstructionA64
<
STRUCT_A64
(
SUB_EXT_REG
)
>
{
DEFINE_INST
(
SUB_EXT_REG
)
{
public
:
A64_SUB_EXT_REG
();
...
...
@@ -623,7 +625,7 @@ namespace SandHook {
};
class
INST_A64
(
EXCEPTION_GEN
)
:
public
InstructionA64
<
STRUCT_A64
(
EXCEPTION_GEN
)
>
{
DEFINE_INST
(
EXCEPTION_GEN
)
{
public
:
enum
OP
{
...
...
@@ -740,7 +742,7 @@ namespace SandHook {
};
class
INST_A64
(
STP_LDP
)
:
public
InstructionA64
<
STRUCT_A64
(
STP_LDP
)
>
{
DEFINE_INST
(
STP_LDP
)
{
public
:
enum
OP
{
STP
=
0
b0
,
...
...
@@ -778,7 +780,7 @@ namespace SandHook {
};
class
INST_A64
(
ADD_SUB_IMM
)
:
public
InstructionA64
<
STRUCT_A64
(
ADD_SUB_IMM
)
>
{
DEFINE_INST
(
ADD_SUB_IMM
)
{
public
:
enum
OP
{
...
...
@@ -817,6 +819,33 @@ namespace SandHook {
Operand
operand
;
};
DEFINE_INST
(
MSR_MRS
)
{
public
:
enum
OP
{
MSR
=
0
,
MRS
=
1
};
A64_MSR_MRS
(
A64_STRUCT_MSR_MRS
&
inst
);
A64_MSR_MRS
(
OP
op
,
SystemRegister
&
systemRegister
,
RegisterA64
&
rt
);
DEFINE_INST_CODE
(
MSR_MRS
)
DEFINE_IS
(
MSR_MRS
)
void
decode
(
A64_STRUCT_MSR_MRS
*
inst
)
override
;
void
assembler
()
override
;
public
:
OP
op
;
SystemRegister
*
systemRegister
;
RegisterA64
*
rt
;
};
}
}
...
...
nativehook/src/main/cpp/archs/arm/arm64/inst/inst_code_arm64.h
View file @
1ae52e14
...
...
@@ -28,7 +28,8 @@ enum class InstCodeA64 {
EXCEPTION_GEN
,
SVC
,
STP_LDP
,
ADD_SUB_IMM
ADD_SUB_IMM
,
MSR_MRS
};
#endif //SANDHOOK_NH_INST_CODE_ARM64_H
nativehook/src/main/cpp/archs/arm/arm64/inst/inst_struct_aarch64.h
View file @
1ae52e14
...
...
@@ -227,6 +227,12 @@ DEFINE_STRUCT_A64(ADD_SUB_IMM) {
InstA64
sf
:
1
;
};
DEFINE_OPCODE_A64
(
MSR_MRS
,
0
b1101010100
)
DEFINE_STRUCT_A64
(
MSR_MRS
)
{
InstA64
rt
:
WideReg
;
InstA64
sysreg
:
16
;
InstA64
op
:
1
;
InstA64
opcode
:
10
;
};
#endif //SANDHOOK_NH_INST_AARCH64_H
nativehook/src/main/cpp/archs/arm/arm64/register/register_arm64.h
View file @
1ae52e14
...
...
@@ -87,6 +87,43 @@ namespace SandHook {
static
WRegister
*
registers
[];
};
class
SystemRegister
{
public
:
struct
SystemReg
{
U16
op2
:
3
;
U16
CRm
:
4
;
U16
CRn
:
4
;
U16
op1
:
3
;
U16
op0
:
2
;
};
SystemRegister
(
U16
op0
,
U16
op1
,
U16
crn
,
U16
crm
,
U16
op2
)
{
reg
.
op0
=
op0
;
reg
.
op1
=
op1
;
reg
.
CRn
=
crn
;
reg
.
CRm
=
crm
;
reg
.
op2
=
op2
;
}
U16
value
()
{
union
{
U16
raw
;
SystemReg
reg
;
}
ret
;
ret
.
reg
=
reg
;
return
ret
.
raw
;
}
public
:
SystemReg
reg
;
};
}
}
...
...
nativehook/src/main/cpp/archs/arm/arm64/register/register_list_arm64.cpp
View file @
1ae52e14
...
...
@@ -22,5 +22,8 @@ namespace SandHook {
XRegister
XZR
=
X31
;
WRegister
WZR
=
W31
;
RegisterA64
UnknowRegiser
=
RegisterA64
(
38
);
SystemRegister
NZCV
=
SystemRegister
(
3
,
3
,
4
,
2
,
0
);
SystemRegister
FPCR
=
SystemRegister
(
3
,
3
,
4
,
4
,
0
);
}
}
\ No newline at end of file
nativehook/src/main/cpp/archs/arm/arm64/register/register_list_arm64.h
View file @
1ae52e14
...
...
@@ -48,6 +48,12 @@ namespace SandHook {
return
&
WZR
;
}
}
// System/special register names.
// This information is not encoded as one field but as the concatenation of
// multiple fields (Op0<0>, Op1, Crn, Crm, Op2).
extern
SystemRegister
NZCV
;
extern
SystemRegister
FPCR
;
}
}
...
...
nativehook/src/main/cpp/includes/hook.h
View file @
1ae52e14
...
...
@@ -12,6 +12,8 @@
#include "assembler.h"
#include "code_relocate.h"
typedef
Addr
REG
;
namespace
SandHook
{
namespace
Hook
{
...
...
@@ -19,7 +21,9 @@ namespace SandHook {
public
:
//return == backup method
virtual
void
*
inlineHook
(
void
*
origin
,
void
*
replace
)
=
0
;
virtual
bool
breakPoint
(
void
*
point
,
void
(
*
callback
)(
REG
[],
void
*
))
{
return
false
;
};
protected
:
static
AndroidCodeBuffer
*
backupBuffer
;
public
:
...
...
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