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
8cabbbda
Commit
8cabbbda
authored
May 12, 2019
by
swift_gan
Committed by
swift_gan
May 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweak framework
parent
9bdcf2b6
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
121 additions
and
12 deletions
+121
-12
CMakeLists.txt
nativehook/CMakeLists.txt
+1
-0
assembler_a64.cpp
...hook/src/main/cpp/archs/arm64/assembler/assembler_a64.cpp
+8
-0
assembler_a64.h
...vehook/src/main/cpp/archs/arm64/assembler/assembler_a64.h
+3
-2
code_relocate_a64.cpp
...k/src/main/cpp/archs/arm64/relocate/code_relocate_a64.cpp
+20
-0
code_relocate_a64.h
...ook/src/main/cpp/archs/arm64/relocate/code_relocate_a64.h
+32
-0
assembler.cpp
nativehook/src/main/cpp/assembler/assembler.cpp
+13
-2
code_buffer.cpp
nativehook/src/main/cpp/buffer/code_buffer.cpp
+15
-0
code_buffer.h
nativehook/src/main/cpp/buffer/code_buffer.h
+13
-1
assembler.h
nativehook/src/main/cpp/includes/assembler.h
+3
-0
code_relocate.h
nativehook/src/main/cpp/includes/code_relocate.h
+13
-7
No files found.
nativehook/CMakeLists.txt
View file @
8cabbbda
...
...
@@ -24,6 +24,7 @@ add_library( # Sets the name of the library.
src/main/cpp/archs/arm64/register/register_a64.cpp
src/main/cpp/archs/arm64/register/register_list_a64.cpp
src/main/cpp/archs/arm64/decoder/decoder_arm64.cpp
src/main/cpp/archs/arm64/relocate/code_relocate_a64.cpp
src/main/cpp/archs/arm32/inst/inst_arm32.cpp
src/main/cpp/archs/arm32/register/register_a32.cpp
src/main/cpp/relocate/code_relocate.cpp
...
...
nativehook/src/main/cpp/archs/arm64/assembler/assembler_a64.cpp
View file @
8cabbbda
...
...
@@ -57,3 +57,11 @@ void SandHook::Assembler::AssemblerA64::Movn(RegisterA64 &rd, U64 imme,
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 @
8cabbbda
...
...
@@ -16,6 +16,8 @@ namespace SandHook {
public
:
AssemblerA64
(
CodeBuffer
*
codeBuffer
);
void
*
getStartPC
();
void
*
getPC
();
void
*
finish
();
...
...
@@ -33,8 +35,7 @@ namespace SandHook {
void
Mov
(
XRegister
&
rd
,
U64
imme
);
private
:
public
:
CodeContainer
codeContainer
=
CodeContainer
(
nullptr
);
};
...
...
nativehook/src/main/cpp/archs/arm64/relocate/code_relocate_a64.cpp
0 → 100644
View file @
8cabbbda
//
// Created by swift on 2019/5/12.
//
#include "code_relocate_a64.h"
#define __ assemblerA64->
CodeRelocateA64
::
CodeRelocateA64
(
AssemblerA64
&
assembler
)
:
CodeRelocate
(
assembler
.
codeContainer
)
{
this
->
assemblerA64
=
&
assembler
;
}
bool
CodeRelocateA64
::
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
{
__
finish
();
return
false
;
}
bool
CodeRelocateA64
::
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
{
return
false
;
}
nativehook/src/main/cpp/archs/arm64/relocate/code_relocate_a64.h
0 → 100644
View file @
8cabbbda
//
// Created by swift on 2019/5/12.
//
#ifndef SANDHOOK_NH_CODE_RELOCATE_A64_H
#define SANDHOOK_NH_CODE_RELOCATE_A64_H
#include "code_relocate.h"
#include "assembler_a64.h"
using
namespace
SandHook
::
Assembler
;
using
namespace
SandHook
::
Decoder
;
namespace
SandHook
{
namespace
Asm
{
class
CodeRelocateA64
:
public
CodeRelocate
{
public
:
CodeRelocateA64
(
AssemblerA64
&
assembler
);
bool
relocate
(
Instruction
<
Base
>
*
instruction
,
void
*
toPc
)
throw
(
ErrorCodeException
)
override
;
bool
relocate
(
void
*
startPc
,
void
*
toPc
,
Addr
len
)
throw
(
ErrorCodeException
)
override
;
private
:
AssemblerA64
*
assemblerA64
;
};
}
}
#endif //SANDHOOK_NH_CODE_RELOCATE_A64_H
nativehook/src/main/cpp/assembler/assembler.cpp
View file @
8cabbbda
...
...
@@ -16,6 +16,7 @@ void CodeContainer::setCodeBuffer(CodeBuffer *codeBuffer) {
void
CodeContainer
::
append
(
Unit
<
Base
>
*
unit
)
{
units
.
push_back
(
unit
);
unit
->
setVPC
(
curPc
);
switch
(
unit
->
unitType
())
{
case
UnitLabel
:
labels
.
push_back
((
Label
*
)
unit
);
...
...
@@ -23,12 +24,17 @@ void CodeContainer::append(Unit<Base> *unit) {
default
:
curPc
+=
unit
->
size
();
}
unit
->
setVPC
(
curPc
);
}
void
CodeContainer
::
commit
()
{
U32
bufferSize
=
static_cast
<
U32
>
(
curPc
-
startPc
);
void
*
bufferStart
=
codeBuffer
->
getBuffer
(
bufferSize
);
void
*
bufferStart
;
if
(
startPc
>
0
)
{
bufferStart
=
reinterpret_cast
<
void
*>
(
startPc
);
codeBuffer
->
resetLastBufferSize
(
bufferSize
);
}
else
{
bufferStart
=
codeBuffer
->
getBuffer
(
bufferSize
);
}
Addr
pcNow
=
reinterpret_cast
<
Addr
>
(
bufferStart
);
//commit to code buffer & assembler inst
...
...
@@ -59,3 +65,8 @@ void CodeContainer::commit() {
curPc
=
pcNow
;
}
void
CodeContainer
::
allocBufferFirst
(
U32
size
)
{
startPc
=
reinterpret_cast
<
Addr
>
(
codeBuffer
->
getBuffer
(
size
));
curPc
=
startPc
;
}
nativehook/src/main/cpp/buffer/code_buffer.cpp
View file @
8cabbbda
...
...
@@ -46,3 +46,18 @@ void *StaticCodeBuffer::getBuffer(U32 bufferSize) {
memUnprotect
(
pc
,
bufferSize
);
return
reinterpret_cast
<
void
*>
(
pc
);
}
void
AndroidRellocBufferUnsafe
::
resetLastBufferSize
(
U32
size
)
{
if
(
executePageOffset
+
(
size
-
lastAllocSize
)
<=
currentExecutePageSize
)
{
executePageOffset
+=
size
-
lastAllocSize
;
lastAllocSize
=
size
;
}
}
void
*
AndroidRellocBufferUnsafe
::
getBuffer
(
U32
bufferSize
)
{
void
*
res
=
AndroidCodeBuffer
::
getBuffer
(
bufferSize
);
if
(
res
)
{
lastAllocSize
=
bufferSize
;
}
return
res
;
}
nativehook/src/main/cpp/buffer/code_buffer.h
View file @
8cabbbda
...
...
@@ -14,13 +14,25 @@ namespace SandHook {
public
:
void
*
getBuffer
(
U32
bufferSize
)
override
;
pr
ivate
:
pr
otected
:
std
::
list
<
void
*>
executeSpaceList
=
std
::
list
<
void
*>
();
std
::
mutex
allocSpaceLock
;
Addr
executePageOffset
=
0
;
U32
currentExecutePageSize
=
0
;
};
//thread unsafe
class
AndroidRellocBufferUnsafe
:
public
AndroidCodeBuffer
{
public
:
public
:
void
resetLastBufferSize
(
U32
size
)
override
;
void
*
getBuffer
(
U32
bufferSize
)
override
;
private
:
U32
lastAllocSize
;
};
class
StaticCodeBuffer
:
public
CodeBuffer
{
public
:
...
...
nativehook/src/main/cpp/includes/assembler.h
View file @
8cabbbda
...
...
@@ -22,6 +22,7 @@ namespace SandHook {
class
CodeBuffer
{
public
:
virtual
void
*
getBuffer
(
U32
size
)
=
0
;
virtual
void
resetLastBufferSize
(
U32
size
){};
};
class
CodeContainer
{
...
...
@@ -31,6 +32,8 @@ namespace SandHook {
void
setCodeBuffer
(
CodeBuffer
*
codeBuffer
);
//allow code relocate to get new pc first
void
allocBufferFirst
(
U32
size
);
void
append
(
Unit
<
Base
>*
unit
);
void
commit
();
...
...
nativehook/src/main/cpp/includes/code_relocate.h
View file @
8cabbbda
...
...
@@ -7,19 +7,25 @@
#include "exception.h"
#include "instruction.h"
#include "assembler.h"
#include "decoder.h"
using
namespace
SandHook
::
Assembler
;
using
namespace
SandHook
::
Decoder
;
namespace
SandHook
{
namespace
Asm
{
template
<
typename
Raw
>
class
CodeRelocateCallback
{
class
CodeRelocate
:
public
InstVisitor
{
public
:
virtual
bool
result
(
Unit
<
Raw
>*
unit
,
bool
end
)
throw
(
ErrorCodeException
)
=
0
;
};
template
<
typename
Raw
>
class
CodeRelocate
{
virtual
bool
relocate
(
Addr
toPc
,
CodeRelocateCallback
<
Raw
>&
callback
)
throw
(
ErrorCodeException
)
=
0
;
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
;
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