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
2d5579fd
Commit
2d5579fd
authored
May 12, 2019
by
swift_gan
Committed by
swift_gan
May 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init code relocate
parent
8cabbbda
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
20 deletions
+83
-20
assembler_a64.cpp
...hook/src/main/cpp/archs/arm64/assembler/assembler_a64.cpp
+16
-11
assembler_a64.h
...vehook/src/main/cpp/archs/arm64/assembler/assembler_a64.h
+3
-1
code_relocate_a64.cpp
...k/src/main/cpp/archs/arm64/relocate/code_relocate_a64.cpp
+45
-4
code_relocate_a64.h
...ook/src/main/cpp/archs/arm64/relocate/code_relocate_a64.h
+17
-2
code_relocate.h
nativehook/src/main/cpp/includes/code_relocate.h
+2
-2
No files found.
nativehook/src/main/cpp/archs/arm64/assembler/assembler_a64.cpp
View file @
2d5579fd
...
...
@@ -8,11 +8,27 @@ SandHook::Assembler::AssemblerA64::AssemblerA64(CodeBuffer* codeBuffer) {
codeContainer
.
setCodeBuffer
(
codeBuffer
);
}
void
*
SandHook
::
Assembler
::
AssemblerA64
::
getPC
()
{
return
reinterpret_cast
<
void
*>
(
codeContainer
.
curPc
);
}
void
*
SandHook
::
Assembler
::
AssemblerA64
::
getStartPC
()
{
return
reinterpret_cast
<
void
*>
(
codeContainer
.
startPc
);
}
void
SandHook
::
Assembler
::
AssemblerA64
::
allocBufferFirst
(
U32
size
)
{
codeContainer
.
allocBufferFirst
(
size
);
}
void
*
SandHook
::
Assembler
::
AssemblerA64
::
finish
()
{
codeContainer
.
commit
();
return
reinterpret_cast
<
void
*>
(
codeContainer
.
startPc
);
}
void
SandHook
::
Assembler
::
AssemblerA64
::
Emit
(
Unit
<
Base
>
*
unit
)
{
codeContainer
.
append
(
unit
);
}
void
SandHook
::
Assembler
::
AssemblerA64
::
MoveWide
(
RegisterA64
&
rd
,
INST_A64
(
MOV_WIDE
)
::
OP
op
,
U64
imme
,
INST_A64
(
MOV_WIDE
)
::
Shift
shift
)
{
...
...
@@ -54,14 +70,3 @@ void SandHook::Assembler::AssemblerA64::Movn(RegisterA64 &rd, U64 imme,
MoveWide
(
rd
,
INST_A64
(
MOV_WIDE
)
::
MOV_WideOp_N
,
imme
,
shift
);
}
void
SandHook
::
Assembler
::
AssemblerA64
::
Emit
(
Unit
<
Base
>
&
unit
)
{
codeContainer
.
append
(
&
unit
);
}
void
*
SandHook
::
Assembler
::
AssemblerA64
::
getPC
()
{
return
reinterpret_cast
<
void
*>
(
codeContainer
.
curPc
);
}
void
*
SandHook
::
Assembler
::
AssemblerA64
::
getStartPC
()
{
return
reinterpret_cast
<
void
*>
(
codeContainer
.
startPc
);
}
nativehook/src/main/cpp/archs/arm64/assembler/assembler_a64.h
View file @
2d5579fd
...
...
@@ -16,12 +16,14 @@ namespace SandHook {
public
:
AssemblerA64
(
CodeBuffer
*
codeBuffer
);
void
allocBufferFirst
(
U32
size
);
void
*
getStartPC
();
void
*
getPC
();
void
*
finish
();
void
Emit
(
Unit
<
Base
>
&
unit
);
void
Emit
(
Unit
<
Base
>
*
unit
);
void
MoveWide
(
RegisterA64
&
rd
,
INST_A64
(
MOV_WIDE
)
::
OP
op
,
U64
imme
,
INST_A64
(
MOV_WIDE
)
::
Shift
shift
);
...
...
nativehook/src/main/cpp/archs/arm64/relocate/code_relocate_a64.cpp
View file @
2d5579fd
...
...
@@ -6,15 +6,56 @@
#define __ assemblerA64->
#define IMPL_RELOCATE(X) void CodeRelocateA64::relocate_##X (INST_A64(X)* inst, void* toPc) throw(ErrorCodeException)
#define CASE(X) \
case InstCodeA64::X: \
relocate_##X(reinterpret_cast<INST_A64(X)*>(instruction), toPc); \
break;
CodeRelocateA64
::
CodeRelocateA64
(
AssemblerA64
&
assembler
)
:
CodeRelocate
(
assembler
.
codeContainer
)
{
this
->
assemblerA64
=
&
assembler
;
}
bool
CodeRelocateA64
::
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
{
void
CodeRelocateA64
::
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
{
__
finish
();
return
false
;
}
bool
CodeRelocateA64
::
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
{
return
false
;
void
CodeRelocateA64
::
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
{
if
(
!
instruction
->
pcRelate
())
{
__
Emit
(
instruction
);
return
;
}
switch
(
instruction
->
instCode
())
{
CASE
(
B_BL
)
CASE
(
B_COND
)
CASE
(
TBZ_TBNZ
)
CASE
(
CBZ_CBNZ
)
CASE
(
LDR_LIT
)
CASE
(
ADR_ADRP
)
}
}
IMPL_RELOCATE
(
B_BL
)
{
}
IMPL_RELOCATE
(
B_COND
)
{
}
IMPL_RELOCATE
(
TBZ_TBNZ
)
{
}
IMPL_RELOCATE
(
CBZ_CBNZ
)
{
}
IMPL_RELOCATE
(
LDR_LIT
)
{
}
IMPL_RELOCATE
(
ADR_ADRP
)
{
}
nativehook/src/main/cpp/archs/arm64/relocate/code_relocate_a64.h
View file @
2d5579fd
...
...
@@ -11,6 +11,8 @@
using
namespace
SandHook
::
Assembler
;
using
namespace
SandHook
::
Decoder
;
#define DEFINE_RELOCATE(X) void relocate_##X (INST_A64(X)* inst, void* toPc) throw(ErrorCodeException);
namespace
SandHook
{
namespace
Asm
{
...
...
@@ -18,9 +20,22 @@ namespace SandHook {
public
:
CodeRelocateA64
(
AssemblerA64
&
assembler
);
bool
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
override
;
void
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
override
;
void
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
override
;
DEFINE_RELOCATE
(
B_BL
)
DEFINE_RELOCATE
(
B_COND
)
DEFINE_RELOCATE
(
TBZ_TBNZ
)
DEFINE_RELOCATE
(
CBZ_CBNZ
)
DEFINE_RELOCATE
(
LDR_LIT
)
DEFINE_RELOCATE
(
ADR_ADRP
)
bool
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
override
;
private
:
AssemblerA64
*
assemblerA64
;
...
...
nativehook/src/main/cpp/includes/code_relocate.h
View file @
2d5579fd
...
...
@@ -21,8 +21,8 @@ namespace SandHook {
CodeRelocate
(
CodeContainer
&
codeContainer
)
:
codeContainer
(
&
codeContainer
)
{}
virtual
bool
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
=
0
;
virtual
bool
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
=
0
;
virtual
void
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
=
0
;
virtual
void
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
=
0
;
private
:
CodeContainer
*
codeContainer
;
...
...
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