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
03d6721e
Commit
03d6721e
authored
Jun 05, 2019
by
swift_gan
Committed by
swift_gan
Jun 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NativeHook]fix ldr align of arm32
parent
71e2bf79
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
7 deletions
+31
-7
assembler_arm32.cpp
...rc/main/cpp/archs/arm/arm32/assembler/assembler_arm32.cpp
+4
-0
assembler_arm32.h
.../src/main/cpp/archs/arm/arm32/assembler/assembler_arm32.h
+7
-0
hook_arm32.cpp
nativehook/src/main/cpp/archs/arm/arm32/hook/hook_arm32.cpp
+12
-4
code_relocate_arm32.cpp
...main/cpp/archs/arm/arm32/relocate/code_relocate_arm32.cpp
+4
-0
code_buffer.cpp
nativehook/src/main/cpp/buffer/code_buffer.cpp
+4
-3
No files found.
nativehook/src/main/cpp/archs/arm/arm32/assembler/assembler_arm32.cpp
View file @
03d6721e
...
...
@@ -57,6 +57,10 @@ void AssemblerA32::Mov(RegisterA32 &rd, U32 imm32) {
Movt
(
rd
,
immH
);
}
void
AssemblerA32
::
Ldr
(
RegisterA32
&
rt
,
Off
offset
)
{
Emit
(
reinterpret_cast
<
Unit
<
Base
>*>
(
new
INST_T32
(
LDR_LIT
)(
INST_T32
(
LDR_LIT
)
::
LDR
,
INST_T32
(
LDR_LIT
)
::
UnSign
,
rt
,
offset
)));
}
void
AssemblerA32
::
Ldr
(
RegisterA32
&
rt
,
Label
*
label
)
{
Emit
(
reinterpret_cast
<
Unit
<
Base
>*>
(
new
INST_T32
(
LDR_LIT
)(
INST_T32
(
LDR_LIT
)
::
LDR
,
INST_T32
(
LDR_LIT
)
::
UnSign
,
rt
,
*
label
)));
}
...
...
nativehook/src/main/cpp/archs/arm/arm32/assembler/assembler_arm32.h
View file @
03d6721e
...
...
@@ -10,6 +10,11 @@
#include "inst_t16.h"
#include "inst_t32.h"
#define ALIGN_FOR_LDR \
if ((Addr) __ getPC() % 4 != 0) { \
__ Nop16(); \
}
using
namespace
SandHook
::
AsmA32
;
namespace
SandHook
{
...
...
@@ -35,6 +40,8 @@ namespace SandHook {
void
Mov
(
RegisterA32
&
rd
,
U32
imm32
);
void
Mov
(
RegisterA32
&
rd
,
RegisterA32
&
rm
);
void
Ldr
(
RegisterA32
&
rt
,
Off
offset
);
void
Ldr
(
RegisterA32
&
rt
,
Label
*
label
);
void
Ldrb
(
RegisterA32
&
rt
,
Label
*
label
);
void
Ldrh
(
RegisterA32
&
rt
,
Label
*
label
);
...
...
nativehook/src/main/cpp/archs/arm/arm32/hook/hook_arm32.cpp
View file @
03d6721e
...
...
@@ -41,6 +41,7 @@ void *InlineHookArm32Android::inlineHook(void *origin, void *replace) {
#define __ assemblerInline.
if
(
!
changeMode
)
{
Label
*
target_addr_label
=
new
Label
();
ALIGN_FOR_LDR
__
Ldr
(
PC
,
target_addr_label
);
__
Emit
(
target_addr_label
);
__
Emit
((
Addr
)
replace
);
...
...
@@ -55,8 +56,11 @@ void *InlineHookArm32Android::inlineHook(void *origin, void *replace) {
CodeRelocateA32
relocate
=
CodeRelocateA32
(
assemblerBackup
);
backup
=
relocate
.
relocate
(
origin
,
codeContainerInline
->
size
(),
nullptr
);
#define __ assemblerBackup.
__
Mov
(
IP
,(
Addr
)
getThumbPC
(
reinterpret_cast
<
void
*>
((
Addr
)
originCode
+
relocate
.
curOffset
)));
__
Bx
(
IP
);
Label
*
origin_addr_label
=
new
Label
();
ALIGN_FOR_LDR
__
Ldr
(
PC
,
origin_addr_label
);
__
Emit
(
origin_addr_label
);
__
Emit
((
Addr
)
getThumbPC
(
reinterpret_cast
<
void
*>
(
reinterpret_cast
<
Addr
>
(
originCode
)
+
relocate
.
curOffset
)));
__
finish
();
#undef __
...
...
@@ -92,8 +96,11 @@ bool InlineHookArm32Android::breakPoint(void *origin, void (*callback)(REG *)) {
CodeRelocateA32
relocate
=
CodeRelocateA32
(
assemblerBackup
);
backup
=
relocate
.
relocate
(
origin
,
changeMode
?
(
4
*
2
+
2
)
:
(
4
*
2
),
nullptr
);
#define __ assemblerBackup.
__
Mov
(
IP
,(
Addr
)
getThumbPC
(
reinterpret_cast
<
void
*>
((
Addr
)
originCode
+
relocate
.
curOffset
)));
__
Bx
(
IP
);
Label
*
origin_addr_label
=
new
Label
();
ALIGN_FOR_LDR
__
Ldr
(
PC
,
origin_addr_label
);
__
Emit
(
origin_addr_label
);
__
Emit
((
Addr
)
getThumbPC
(
reinterpret_cast
<
void
*>
(
reinterpret_cast
<
Addr
>
(
originCode
)
+
relocate
.
curOffset
)));
__
finish
();
#undef __
...
...
@@ -106,6 +113,7 @@ bool InlineHookArm32Android::breakPoint(void *origin, void (*callback)(REG *)) {
#define __ assemblerInline.
if
(
!
changeMode
)
{
Label
*
target_addr_label
=
new
Label
();
ALIGN_FOR_LDR
__
Ldr
(
PC
,
target_addr_label
);
__
Emit
(
target_addr_label
);
__
Emit
((
Addr
)
trampoline
);
...
...
nativehook/src/main/cpp/archs/arm/arm32/relocate/code_relocate_arm32.cpp
View file @
03d6721e
...
...
@@ -103,6 +103,7 @@ IMPL_RELOCATE(T16, B_COND) {
if
(
inst
->
condition
==
al
)
{
Label
*
target_label
=
new
Label
;
ALIGN_FOR_LDR
__
Ldr
(
PC
,
target_label
);
__
Emit
(
target_label
);
__
Emit
(
targetAddr
);
...
...
@@ -113,6 +114,7 @@ IMPL_RELOCATE(T16, B_COND) {
__
B
(
inst
->
condition
,
true_label
);
__
B
(
false_label
);
__
Emit
(
true_label
);
ALIGN_FOR_LDR
__
Ldr
(
PC
,
target_label
);
__
Emit
(
target_label
);
__
Emit
(
targetAddr
);
...
...
@@ -131,6 +133,7 @@ IMPL_RELOCATE(T16, B) {
Addr
targetAddr
=
inst
->
getImmPCOffsetTarget
();
Label
*
target_label
=
new
Label
();
ALIGN_FOR_LDR
__
Ldr
(
PC
,
target_label
);
__
Emit
(
target_label
);
__
Emit
((
Addr
)
getThumbPC
(
reinterpret_cast
<
void
*>
(
targetAddr
)));
...
...
@@ -162,6 +165,7 @@ IMPL_RELOCATE(T16, CBZ_CBNZ) {
__
Emit
(
reinterpret_cast
<
Instruction
<
Base
>*>
(
inst
));
__
B
(
false_label
);
__
Emit
(
true_label
);
ALIGN_FOR_LDR
__
Ldr
(
PC
,
target_label
);
__
Emit
(
target_label
);
__
Emit
((
Addr
)
getThumbPC
(
reinterpret_cast
<
void
*>
(
targetAddr
)));
...
...
nativehook/src/main/cpp/buffer/code_buffer.cpp
View file @
03d6721e
...
...
@@ -17,12 +17,13 @@ void *AndroidCodeBuffer::getBuffer(U32 size) {
Addr
exeSpace
=
0
;
if
(
executeSpaceList
.
size
()
==
0
)
{
goto
label_alloc_new_space
;
}
else
if
(
executePageOffset
+
size
>
currentExecutePageSize
)
{
}
else
if
(
executePageOffset
+
size
+
4
>
currentExecutePageSize
)
{
goto
label_alloc_new_space
;
}
else
{
exeSpace
=
reinterpret_cast
<
Addr
>
(
executeSpaceList
.
back
());
Addr
retSpace
=
exeSpace
+
executePageOffset
;
executePageOffset
+=
size
;
//4 字节对齐
Addr
retSpace
=
RoundUp
(
exeSpace
+
executePageOffset
,
4
);
executePageOffset
=
retSpace
+
size
-
exeSpace
;
return
reinterpret_cast
<
void
*>
(
retSpace
);
}
label_alloc_new_space
:
...
...
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