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
c98a07b9
Commit
c98a07b9
authored
May 26, 2019
by
swift_gan
Committed by
swift_gan
May 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NativeHook]add fix inst add reg rdn
parent
29adbb4f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
4 deletions
+81
-4
decoder_arm32.cpp
...ok/src/main/cpp/archs/arm/arm32/decoder/decoder_arm32.cpp
+1
-0
inst_code_arm32.h
...ehook/src/main/cpp/archs/arm/arm32/inst/inst_code_arm32.h
+2
-1
inst_struct_t16.h
...ehook/src/main/cpp/archs/arm/arm32/inst/inst_struct_t16.h
+8
-0
inst_t16.cpp
nativehook/src/main/cpp/archs/arm/arm32/inst/inst_t16.cpp
+24
-1
inst_t16.h
nativehook/src/main/cpp/archs/arm/arm32/inst/inst_t16.h
+24
-0
code_relocate_arm32.cpp
...main/cpp/archs/arm/arm32/relocate/code_relocate_arm32.cpp
+19
-1
code_relocate_arm32.h
...c/main/cpp/archs/arm/arm32/relocate/code_relocate_arm32.h
+2
-0
register.h
nativehook/src/main/cpp/asm/register.h
+1
-1
No files found.
nativehook/src/main/cpp/archs/arm/arm32/decoder/decoder_arm32.cpp
View file @
c98a07b9
...
@@ -52,6 +52,7 @@ void Arm32Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, b
...
@@ -52,6 +52,7 @@ void Arm32Decoder::decode(void *codeStart, Addr codeLen, InstVisitor &visitor, b
CASE_T16
(
LDR_LIT
)
CASE_T16
(
LDR_LIT
)
CASE_T16
(
ADD_IMM_RDN
)
CASE_T16
(
ADD_IMM_RDN
)
CASE_T16
(
ADR
)
CASE_T16
(
ADR
)
CASE_T16
(
ADD_REG_RDN
)
if
(
!
onlyPcRelInst
)
{
if
(
!
onlyPcRelInst
)
{
CASE_T16
(
ADD_REG
)
CASE_T16
(
ADD_REG
)
CASE_T16
(
CMP_REG
)
CASE_T16
(
CMP_REG
)
...
...
nativehook/src/main/cpp/archs/arm/arm32/inst/inst_code_arm32.h
View file @
c98a07b9
...
@@ -29,7 +29,8 @@ enum class InstCodeT16 {
...
@@ -29,7 +29,8 @@ enum class InstCodeT16 {
MOV_IMM
,
MOV_IMM
,
MOV_REG
,
MOV_REG
,
POP
,
POP
,
PUSH
PUSH
,
ADD_REG_RDN
};
};
enum
class
InstCodeT32
{
enum
class
InstCodeT32
{
...
...
nativehook/src/main/cpp/archs/arm/arm32/inst/inst_struct_t16.h
View file @
c98a07b9
...
@@ -136,6 +136,14 @@ DEFINE_STRUCT_T16(ADD_REG) {
...
@@ -136,6 +136,14 @@ DEFINE_STRUCT_T16(ADD_REG) {
InstT16
opcode
:
7
;
InstT16
opcode
:
7
;
};
};
DEFINE_OPCODE_T16
(
ADD_REG_RDN
,
0
b01000100
)
DEFINE_STRUCT_T16
(
ADD_REG_RDN
)
{
InstT16
rdn
:
T16_REG_WIDE
;
InstT16
rm
:
4
;
InstT16
unknow
:
1
;
InstT16
opcode
:
8
;
};
DEFINE_OPCODE_T16
(
POP
,
0
b1011110
)
DEFINE_OPCODE_T16
(
POP
,
0
b1011110
)
DEFINE_STRUCT_T16
(
POP
)
{
DEFINE_STRUCT_T16
(
POP
)
{
InstT16
regs
:
8
;
InstT16
regs
:
8
;
...
...
nativehook/src/main/cpp/archs/arm/arm32/inst/inst_t16.cpp
View file @
c98a07b9
...
@@ -384,4 +384,27 @@ void T16_PUSH::assembler() {
...
@@ -384,4 +384,27 @@ void T16_PUSH::assembler() {
U16
regs
=
registerList
.
GetList
();
U16
regs
=
registerList
.
GetList
();
get
()
->
regs
=
BITS
(
regs
,
0
,
7
);
get
()
->
regs
=
BITS
(
regs
,
0
,
7
);
get
()
->
M
=
BIT
(
regs
,
14
);
get
()
->
M
=
BIT
(
regs
,
14
);
}
}
\ No newline at end of file
// Add reg rdn T2
T16_ADD_REG_RDN
::
T16_ADD_REG_RDN
(
T16_STRUCT_ADD_REG_RDN
*
inst
)
:
InstructionT16
(
inst
)
{
decode
(
inst
);
}
T16_ADD_REG_RDN
::
T16_ADD_REG_RDN
(
RegisterA32
&
rdn
,
RegisterA32
&
rm
)
:
rdn
(
&
rdn
),
rm
(
&
rm
)
{}
bool
T16_ADD_REG_RDN
::
pcRelate
()
{
return
*
rm
==
PC
;
}
void
T16_ADD_REG_RDN
::
decode
(
T16_STRUCT_ADD_REG_RDN
*
inst
)
{
DECODE_RM
(
Reg
);
rdn
=
Reg
(
inst
->
rdn
);
}
void
T16_ADD_REG_RDN
::
assembler
()
{
SET_OPCODE
(
ADD_REG_RDN
);
ENCODE_RM
;
get
()
->
rdn
=
rdn
->
getCode
();
}
nativehook/src/main/cpp/archs/arm/arm32/inst/inst_t16.h
View file @
c98a07b9
...
@@ -444,6 +444,30 @@ namespace SandHook {
...
@@ -444,6 +444,30 @@ namespace SandHook {
RegisterList
registerList
;
RegisterList
registerList
;
};
};
class
INST_T16
(
ADD_REG_RDN
)
:
public
InstructionT16
<
STRUCT_T16
(
ADD_REG_RDN
)
>
{
public
:
T16_ADD_REG_RDN
(
T16_STRUCT_ADD_REG_RDN
*
inst
);
T16_ADD_REG_RDN
(
RegisterA32
&
rdn
,
RegisterA32
&
rm
);
DEFINE_IS
(
ADD_REG_RDN
)
DEFINE_INST_CODE
(
ADD_REG_RDN
)
bool
pcRelate
()
override
;
void
decode
(
T16_STRUCT_ADD_REG_RDN
*
inst
)
override
;
void
assembler
()
override
;
public
:
RegisterA32
*
rdn
;
RegisterA32
*
rm
;
};
}
}
}
}
...
...
nativehook/src/main/cpp/archs/arm/arm32/relocate/code_relocate_arm32.cpp
View file @
c98a07b9
...
@@ -79,6 +79,7 @@ void* CodeRelocateA32::relocate(Instruction<Base> *instruction, void *toPc) thro
...
@@ -79,6 +79,7 @@ void* CodeRelocateA32::relocate(Instruction<Base> *instruction, void *toPc) thro
CASE
(
T16
,
CBZ_CBNZ
)
CASE
(
T16
,
CBZ_CBNZ
)
CASE
(
T16
,
ADR
)
CASE
(
T16
,
ADR
)
CASE
(
T16
,
LDR_LIT
)
CASE
(
T16
,
LDR_LIT
)
CASE
(
T16
,
ADD_REG_RDN
)
default
:
default
:
__
Emit
(
instruction
);
__
Emit
(
instruction
);
instruction
->
ref
();
instruction
->
ref
();
...
@@ -198,6 +199,23 @@ IMPL_RELOCATE(T16, ADR) {
...
@@ -198,6 +199,23 @@ IMPL_RELOCATE(T16, ADR) {
}
}
IMPL_RELOCATE
(
T16
,
ADD_REG_RDN
)
{
if
(
*
inst
->
rm
!=
PC
)
{
inst
->
ref
();
__
Emit
(
reinterpret_cast
<
Instruction
<
Base
>*>
(
inst
));
return
;
}
RegisterA32
&
tmpReg
=
*
inst
->
rdn
!=
R0
?
R0
:
R1
;
__
Push
(
tmpReg
);
__
Mov
(
tmpReg
,(
Addr
)
inst
->
getPC
());
__
Add
(
*
inst
->
rdn
,
*
inst
->
rdn
,
tmpReg
);
__
Pop
(
tmpReg
);
}
IMPL_RELOCATE
(
T32
,
B32
)
{
IMPL_RELOCATE
(
T32
,
B32
)
{
if
(
inRelocateRange
(
CODE_OFFSET
(
inst
),
sizeof
(
InstT16
)))
{
if
(
inRelocateRange
(
CODE_OFFSET
(
inst
),
sizeof
(
InstT16
)))
{
...
@@ -239,7 +257,7 @@ IMPL_RELOCATE(T32, B32) {
...
@@ -239,7 +257,7 @@ IMPL_RELOCATE(T32, B32) {
IMPL_RELOCATE
(
T32
,
LDR_LIT
)
{
IMPL_RELOCATE
(
T32
,
LDR_LIT
)
{
if
(
inRelocateRange
(
CODE_OFFSET
(
inst
),
sizeof
(
InstT16
)))
{
if
(
inRelocateRange
(
CODE_OFFSET
(
inst
),
sizeof
(
Addr
)))
{
inst
->
ref
();
inst
->
ref
();
inst
->
bindLabel
(
*
getLaterBindLabel
(
CODE_OFFSET
(
inst
)
+
curOffset
));
inst
->
bindLabel
(
*
getLaterBindLabel
(
CODE_OFFSET
(
inst
)
+
curOffset
));
__
Emit
(
reinterpret_cast
<
Instruction
<
Base
>*>
(
inst
));
__
Emit
(
reinterpret_cast
<
Instruction
<
Base
>*>
(
inst
));
...
...
nativehook/src/main/cpp/archs/arm/arm32/relocate/code_relocate_arm32.h
View file @
c98a07b9
...
@@ -41,6 +41,8 @@ namespace SandHook {
...
@@ -41,6 +41,8 @@ namespace SandHook {
DEFINE_RELOCATE
(
T16
,
ADR
)
DEFINE_RELOCATE
(
T16
,
ADR
)
DEFINE_RELOCATE
(
T16
,
ADD_REG_RDN
)
DEFINE_RELOCATE
(
T32
,
B32
)
DEFINE_RELOCATE
(
T32
,
B32
)
DEFINE_RELOCATE
(
T32
,
LDR_LIT
)
DEFINE_RELOCATE
(
T32
,
LDR_LIT
)
...
...
nativehook/src/main/cpp/asm/register.h
View file @
c98a07b9
...
@@ -62,7 +62,7 @@ namespace SandHook {
...
@@ -62,7 +62,7 @@ namespace SandHook {
}
}
bool
operator
!=
(
const
Register
&
rhs
)
const
{
bool
operator
!=
(
const
Register
&
rhs
)
const
{
return
!
(
rhs
==
*
this
)
;
return
code
!=
rhs
.
code
;
}
}
virtual
void
setData
(
Data
data
)
{
virtual
void
setData
(
Data
data
)
{
...
...
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