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
b685a174
Commit
b685a174
authored
Jul 16, 2019
by
swift_gan
Committed by
swift_gan
Jul 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SingleInstHook]tweak code
parent
7a2b7b8f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
144 deletions
+31
-144
MyApp.java
app/src/main/java/com/swift/sandhook/MyApp.java
+0
-3
elf.cpp
nativehook/src/main/cpp/elf/elf.cpp
+5
-5
elf.h
nativehook/src/main/cpp/includes/elf.h
+3
-3
sandhook_native.cpp
nativehook/src/main/cpp/sandhook_native.cpp
+17
-133
sandhook_native.h
nativehook/src/main/cpp/sandhook_native.h
+6
-0
No files found.
app/src/main/java/com/swift/sandhook/MyApp.java
View file @
b685a174
...
...
@@ -5,7 +5,6 @@ import android.app.Application;
import
android.os.Build
;
import
android.util.Log
;
import
com.swift.sandhook.nativehook.NativeHook
;
import
com.swift.sandhook.test.TestClass
;
import
com.swift.sandhook.testHookers.ActivityHooker
;
import
com.swift.sandhook.testHookers.CtrHook
;
...
...
@@ -37,8 +36,6 @@ public class MyApp extends Application {
SandHookConfig
.
SDK_INT
=
29
;
}
NativeHook
.
test
();
SandHook
.
disableVMInline
();
SandHook
.
tryDisableProfile
(
getPackageName
());
SandHook
.
disableDex2oatInline
(
false
);
...
...
nativehook/src/main/cpp/elf/elf.cpp
View file @
b685a174
...
...
@@ -90,7 +90,7 @@ ElfImg::ElfImg(const char *elf) {
}
//load module rang
baseInRam
=
g
etModuleBase
(
elf
);
baseInRam
=
G
etModuleBase
(
elf
);
}
ElfImg
::~
ElfImg
()
{
...
...
@@ -105,7 +105,7 @@ ElfImg::~ElfImg() {
}
}
Elf_Addr
ElfImg
::
getSymb
Offset
(
const
char
*
name
)
{
Elf_Addr
ElfImg
::
GetSym
Offset
(
const
char
*
name
)
{
Elf_Addr
_offset
=
0
;
//search dynmtab
...
...
@@ -139,8 +139,8 @@ Elf_Addr ElfImg::getSymbOffset(const char *name) {
return
0
;
}
Elf_Addr
ElfImg
::
getSymb
Address
(
const
char
*
name
)
{
Elf_Addr
offset
=
getSymb
Offset
(
name
);
Elf_Addr
ElfImg
::
GetSym
Address
(
const
char
*
name
)
{
Elf_Addr
offset
=
GetSym
Offset
(
name
);
if
(
offset
>
0
&&
baseInRam
!=
nullptr
)
{
return
static_cast
<
Elf_Addr
>
((
size_t
)
baseInRam
+
offset
-
bias
);
}
else
{
...
...
@@ -148,7 +148,7 @@ Elf_Addr ElfImg::getSymbAddress(const char *name) {
}
}
void
*
ElfImg
::
g
etModuleBase
(
const
char
*
name
)
{
void
*
ElfImg
::
G
etModuleBase
(
const
char
*
name
)
{
FILE
*
maps
;
char
buff
[
256
];
off_t
load_addr
;
...
...
nativehook/src/main/cpp/includes/elf.h
View file @
b685a174
...
...
@@ -44,11 +44,11 @@ namespace SandHook {
ElfImg
(
const
char
*
elf
);
Elf_Addr
getSymbOffset
(
const
char
*
name
);
Elf_Addr
GetSymOffset
(
const
char
*
name
);
static
void
*
getModuleBase
(
const
char
*
name
);
static
void
*
GetModuleBase
(
const
char
*
name
);
Elf_Addr
getSymbAddress
(
const
char
*
name
);
Elf_Addr
GetSymAddress
(
const
char
*
name
);
~
ElfImg
();
...
...
nativehook/src/main/cpp/sandhook_native.cpp
View file @
b685a174
...
...
@@ -3,8 +3,6 @@
//
#include <jni.h>
#include <sys/mman.h>
#include <log.h>
#include "sandhook_native.h"
#include "hook.h"
#include "elf.h"
...
...
@@ -12,139 +10,10 @@
using
namespace
SandHook
::
Hook
;
using
namespace
SandHook
::
Elf
;
int
m1
=
5
;
int
m3
=
1036
;
int
m2
=
1035
;
int
m4
=
5
;
void
(
*
dosth3Backup
)(
int
,
int
)
=
nullptr
;
void
(
*
dosth4Backup
)()
=
nullptr
;
void
(
*
dosth4Backup2
)()
=
nullptr
;
void
(
*
innerSuspendVM
)()
=
nullptr
;
static
void
(
*
heapPreForkBackup
)(
void
*
)
=
nullptr
;
static
void
myHeapPreFork
(
void
*
heap
)
{
heapPreForkBackup
(
heap
);
}
void
SuspendVMReplace
()
{
LOGE
(
"VM Suspend!"
);
innerSuspendVM
();
}
void
do2
()
{
int
a
=
1
+
1
;
int
b
=
1
+
1
;
int
c
=
1
+
1
;
int
d
=
1
+
1
;
}
void
do3
(
int
x
,
int
y
)
{
do2
();
int
a
=
1
+
1
;
int
b
=
1
+
1
;
int
c
=
1
+
1
;
int
d
=
a
+
b
+
c
;
LOGE
(
"do3 = %d"
,
y
);
}
void
do5
()
{
LOGE
(
"x = %d"
,
5
);
}
void
do4
()
{
int
a
=
1
+
1
;
int
b
=
a
+
1
;
int
d
=
a
+
1
;
int
e
=
a
+
1
;
LOGE
(
"x = %d"
,
7
);
}
void
do4replace
()
{
int
a
=
1
+
1
;
int
b
=
1
+
1
;
int
c
=
1
+
1
;
int
d
=
1
+
1
;
dosth4Backup
();
}
void
do4replace2
()
{
int
a
=
1
+
1
;
int
c
=
1
+
1
;
int
d
=
1
+
1
;
dosth4Backup2
();
}
void
do3replace
(
int
x
,
int
y
)
{
int
a
=
1
+
1
;
int
b
=
1
+
1
;
int
c
=
1
+
1
;
int
d
=
1
+
1
;
dosth3Backup
(
x
,
y
);
}
void
do1
()
{
do2
();
}
void
breakCallback
(
REG
regs
[])
{
LOGE
(
"breakCallback = %d SP = %d"
,
regs
[
0
],
regs
);
}
class
Visitor
:
public
InstVisitor
{
bool
Visit
(
Unit
<
Base
>
*
unit
,
void
*
pc
)
override
{
BaseInst
*
instruction
=
reinterpret_cast
<
BaseInst
*>
(
unit
);
instruction
->
Assemble
();
return
true
;
}
};
extern
"C"
JNIEXPORT
void
JNICALL
Java_com_swift_sandhook_nativehook_NativeHook_test
(
JNIEnv
*
env
,
jclass
jclass1
)
{
dosth4Backup
=
reinterpret_cast
<
void
(
*
)()
>
(
InlineHook
::
instance
->
SingleInstHook
(
reinterpret_cast
<
void
*>
(
do4
),
reinterpret_cast
<
void
*>
(
do4replace
)));
do4
();
if
(
sizeof
(
void
*
)
==
8
)
{
heapPreForkBackup
=
reinterpret_cast
<
void
(
*
)(
void
*
)
>
(
SandInlineHookSym
(
"/system/lib64/libart.so"
,
"_ZN3art2gc4Heap13PreZygoteForkEv"
,
reinterpret_cast
<
void
*>
(
myHeapPreFork
)));
innerSuspendVM
=
reinterpret_cast
<
void
(
*
)()
>
(
SandInlineHookSym
(
"/system/lib64/libart.so"
,
"_ZN3art3Dbg9SuspendVMEv"
,
reinterpret_cast
<
void
*>
(
SuspendVMReplace
)));
}
else
{
heapPreForkBackup
=
reinterpret_cast
<
void
(
*
)(
void
*
)
>
(
SandInlineHookSym
(
"/system/lib/libart.so"
,
"_ZN3art2gc4Heap13PreZygoteForkEv"
,
reinterpret_cast
<
void
*>
(
myHeapPreFork
)));
innerSuspendVM
=
reinterpret_cast
<
void
(
*
)()
>
(
SandInlineHookSym
(
"/system/lib/libart.so"
,
"_ZN3art3Dbg9SuspendVMEv"
,
reinterpret_cast
<
void
*>
(
SuspendVMReplace
)));
}
void
*
do3P
=
reinterpret_cast
<
void
*>
(
do3
);
InlineHook
::
instance
->
BreakPoint
(
reinterpret_cast
<
void
*>
((
Addr
)
do3
),
breakCallback
);
LOGE
(
"ok"
);
do3
(
100
,
2
);
}
extern
"C"
EXPORT
void
*
SandGetSym
(
const
char
*
so
,
const
char
*
symb
)
{
ElfImg
elfImg
(
so
);
return
reinterpret_cast
<
void
*>
(
elfImg
.
getSymb
Address
(
symb
));
return
reinterpret_cast
<
void
*>
(
elfImg
.
GetSym
Address
(
symb
));
}
extern
"C"
...
...
@@ -155,13 +24,28 @@ EXPORT void* SandInlineHook(void* origin, void* replace) {
extern
"C"
EXPORT
void
*
SandInlineHookSym
(
const
char
*
so
,
const
char
*
symb
,
void
*
replace
)
{
ElfImg
elfImg
(
so
);
void
*
origin
=
reinterpret_cast
<
void
*>
(
elfImg
.
getSymb
Address
(
symb
));
void
*
origin
=
reinterpret_cast
<
void
*>
(
elfImg
.
GetSym
Address
(
symb
));
if
(
origin
==
nullptr
)
return
nullptr
;
return
InlineHook
::
instance
->
Hook
(
origin
,
replace
);
}
extern
"C"
EXPORT
void
*
SandSingleInstHook
(
void
*
origin
,
void
*
replace
)
{
return
InlineHook
::
instance
->
SingleInstHook
(
origin
,
replace
);
}
extern
"C"
EXPORT
void
*
SandSingleInstHookSym
(
const
char
*
so
,
const
char
*
symb
,
void
*
replace
)
{
ElfImg
elfImg
(
so
);
void
*
origin
=
reinterpret_cast
<
void
*>
(
elfImg
.
GetSymAddress
(
symb
));
if
(
origin
==
nullptr
)
return
nullptr
;
return
InlineHook
::
instance
->
SingleInstHook
(
origin
,
replace
);
}
extern
"C"
EXPORT
bool
SandBreakpoint
(
void
*
origin
,
void
(
*
callback
)(
REG
[]))
{
return
InlineHook
::
instance
->
BreakPoint
(
origin
,
callback
);
...
...
nativehook/src/main/cpp/sandhook_native.h
View file @
b685a174
...
...
@@ -17,5 +17,11 @@ EXPORT void* SandInlineHook(void* origin, void* replace);
extern
"C"
EXPORT
void
*
SandInlineHookSym
(
const
char
*
so
,
const
char
*
symb
,
void
*
replace
);
extern
"C"
EXPORT
void
*
SandSingleInstHook
(
void
*
origin
,
void
*
replace
);
extern
"C"
EXPORT
void
*
SandSingleInstHookSym
(
const
char
*
so
,
const
char
*
symb
,
void
*
replace
);
extern
"C"
EXPORT
bool
SandBreakpoint
(
void
*
origin
,
void
(
*
callback
)(
REG
[]));
\ No newline at end of file
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