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
9179864a
Commit
9179864a
authored
Apr 23, 2019
by
swift_gan
Committed by
swift_gan
Apr 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ForceProcessProfiles & clear hotness_count
parent
a4947cef
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
77 additions
and
6 deletions
+77
-6
art_method.cpp
hooklib/src/main/cpp/art/art_method.cpp
+8
-0
cast_art_method.cpp
hooklib/src/main/cpp/casts/cast_art_method.cpp
+20
-2
arch.h
hooklib/src/main/cpp/includes/arch.h
+2
-2
art_method.h
hooklib/src/main/cpp/includes/art_method.h
+2
-0
cast.h
hooklib/src/main/cpp/includes/cast.h
+5
-1
cast_art_method.h
hooklib/src/main/cpp/includes/cast_art_method.h
+1
-0
hide_api.h
hooklib/src/main/cpp/includes/hide_api.h
+2
-0
sandhook.h
hooklib/src/main/cpp/includes/sandhook.h
+3
-0
sandhook.cpp
hooklib/src/main/cpp/sandhook.cpp
+22
-1
hide_api.cpp
hooklib/src/main/cpp/utils/hide_api.cpp
+12
-0
No files found.
hooklib/src/main/cpp/art/art_method.cpp
View file @
9179864a
...
@@ -113,6 +113,10 @@ GCRoot ArtMethod::getDeclaringClass() {
...
@@ -113,6 +113,10 @@ GCRoot ArtMethod::getDeclaringClass() {
return
CastArtMethod
::
declaringClass
->
get
(
this
);
return
CastArtMethod
::
declaringClass
->
get
(
this
);
}
}
uint16_t
ArtMethod
::
getHotnessCount
()
{
return
CastArtMethod
::
hotnessCount
->
get
(
this
);
}
void
ArtMethod
::
setQuickCodeEntry
(
void
*
entry
)
{
void
ArtMethod
::
setQuickCodeEntry
(
void
*
entry
)
{
CastArtMethod
::
entryPointQuickCompiled
->
set
(
this
,
entry
);
CastArtMethod
::
entryPointQuickCompiled
->
set
(
this
,
entry
);
}
}
...
@@ -136,6 +140,10 @@ void ArtMethod::setDeclaringClass(GCRoot classPtr) {
...
@@ -136,6 +140,10 @@ void ArtMethod::setDeclaringClass(GCRoot classPtr) {
CastArtMethod
::
declaringClass
->
set
(
this
,
classPtr
);
CastArtMethod
::
declaringClass
->
set
(
this
,
classPtr
);
}
}
void
ArtMethod
::
setHotnessCount
(
uint16_t
count
)
{
CastArtMethod
::
hotnessCount
->
set
(
this
,
count
);
}
bool
ArtMethod
::
compile
(
JNIEnv
*
env
)
{
bool
ArtMethod
::
compile
(
JNIEnv
*
env
)
{
if
(
isCompiled
())
if
(
isCompiled
())
return
true
;
return
true
;
...
...
hooklib/src/main/cpp/casts/cast_art_method.cpp
View file @
9179864a
...
@@ -141,8 +141,11 @@ namespace SandHook {
...
@@ -141,8 +141,11 @@ namespace SandHook {
class
CastDexMethodIndex
:
public
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>
{
class
CastDexMethodIndex
:
public
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>
{
protected
:
protected
:
Size
calOffset
(
JNIEnv
*
jniEnv
,
art
::
mirror
::
ArtMethod
*
p
)
override
{
Size
calOffset
(
JNIEnv
*
jniEnv
,
art
::
mirror
::
ArtMethod
*
p
)
override
{
if
(
SDK_INT
>=
ANDROID_P
)
if
(
SDK_INT
>=
ANDROID_P
)
{
return
getParentSize
()
+
1
;
return
CastArtMethod
::
accessFlag
->
getOffset
()
+
CastArtMethod
::
accessFlag
->
size
()
+
sizeof
(
uint32_t
);
}
int
offset
=
0
;
int
offset
=
0
;
jint
index
=
getIntFromJava
(
jniEnv
,
"com/swift/sandhook/SandHookMethodResolver"
,
jint
index
=
getIntFromJava
(
jniEnv
,
"com/swift/sandhook/SandHookMethodResolver"
,
"dexMethodIndex"
);
"dexMethodIndex"
);
...
@@ -156,6 +159,17 @@ namespace SandHook {
...
@@ -156,6 +159,17 @@ namespace SandHook {
}
}
};
};
class
CastHotnessCount
:
public
IMember
<
art
::
mirror
::
ArtMethod
,
uint16_t
>
{
protected
:
Size
calOffset
(
JNIEnv
*
jniEnv
,
mirror
::
ArtMethod
*
p
)
override
{
if
(
SDK_INT
<=
ANDROID_N
)
return
getParentSize
()
+
1
;
return
CastArtMethod
::
dexMethodIndex
->
getOffset
()
+
CastArtMethod
::
dexMethodIndex
->
size
()
+
sizeof
(
uint16_t
);
}
};
void
CastArtMethod
::
init
(
JNIEnv
*
env
)
{
void
CastArtMethod
::
init
(
JNIEnv
*
env
)
{
//init ArtMethodSize
//init ArtMethodSize
...
@@ -187,6 +201,9 @@ namespace SandHook {
...
@@ -187,6 +201,9 @@ namespace SandHook {
declaringClass
=
new
CastShadowClass
();
declaringClass
=
new
CastShadowClass
();
declaringClass
->
init
(
env
,
m1
,
size
);
declaringClass
->
init
(
env
,
m1
,
size
);
hotnessCount
=
new
CastHotnessCount
();
hotnessCount
->
init
(
env
,
m1
,
size
);
jclass
neverCallTestClass
=
env
->
FindClass
(
"com/swift/sandhook/ClassNeverCall"
);
jclass
neverCallTestClass
=
env
->
FindClass
(
"com/swift/sandhook/ClassNeverCall"
);
...
@@ -240,6 +257,7 @@ namespace SandHook {
...
@@ -240,6 +257,7 @@ namespace SandHook {
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>
*
CastArtMethod
::
dexMethodIndex
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>
*
CastArtMethod
::
dexMethodIndex
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>
*
CastArtMethod
::
accessFlag
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>
*
CastArtMethod
::
accessFlag
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
GCRoot
>
*
CastArtMethod
::
declaringClass
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
GCRoot
>
*
CastArtMethod
::
declaringClass
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
uint16_t
>
*
CastArtMethod
::
hotnessCount
=
nullptr
;
void
*
CastArtMethod
::
quickToInterpreterBridge
=
nullptr
;
void
*
CastArtMethod
::
quickToInterpreterBridge
=
nullptr
;
void
*
CastArtMethod
::
genericJniStub
=
nullptr
;
void
*
CastArtMethod
::
genericJniStub
=
nullptr
;
void
*
CastArtMethod
::
staticResolveStub
=
nullptr
;
void
*
CastArtMethod
::
staticResolveStub
=
nullptr
;
...
...
hooklib/src/main/cpp/includes/arch.h
View file @
9179864a
...
@@ -7,12 +7,12 @@
...
@@ -7,12 +7,12 @@
#define BYTE_POINT sizeof(void*)
#define BYTE_POINT sizeof(void*)
typedef
size_t
Size
;
//32bit
//32bit
#if defined(__i386__) || defined(__arm__)
#if defined(__i386__) || defined(__arm__)
#define Size uint32_t
//64bit
//64bit
#elif defined(__aarch64__) || defined(__x86_64__)
#elif defined(__aarch64__) || defined(__x86_64__)
#define Size uint64_t
#else
#else
#endif
#endif
...
...
hooklib/src/main/cpp/includes/art_method.h
View file @
9179864a
...
@@ -61,12 +61,14 @@ public:
...
@@ -61,12 +61,14 @@ public:
void
setDexCacheResolveList
(
void
*
list
);
void
setDexCacheResolveList
(
void
*
list
);
void
setDexCacheResolveItem
(
uint32_t
index
,
void
*
item
);
void
setDexCacheResolveItem
(
uint32_t
index
,
void
*
item
);
void
setDeclaringClass
(
GCRoot
classPtr
);
void
setDeclaringClass
(
GCRoot
classPtr
);
void
setHotnessCount
(
uint16_t
count
);
void
*
getQuickCodeEntry
();
void
*
getQuickCodeEntry
();
void
*
getInterpreterCodeEntry
();
void
*
getInterpreterCodeEntry
();
uint32_t
getAccessFlags
();
uint32_t
getAccessFlags
();
uint32_t
getDexMethodIndex
();
uint32_t
getDexMethodIndex
();
GCRoot
getDeclaringClass
();
GCRoot
getDeclaringClass
();
uint16_t
getHotnessCount
();
bool
compile
(
JNIEnv
*
env
);
bool
compile
(
JNIEnv
*
env
);
bool
deCompile
();
bool
deCompile
();
...
...
hooklib/src/main/cpp/includes/cast.h
View file @
9179864a
...
@@ -37,6 +37,10 @@ namespace SandHook {
...
@@ -37,6 +37,10 @@ namespace SandHook {
offset
=
calOffset
(
jniEnv
,
p
);
offset
=
calOffset
(
jniEnv
,
p
);
}
}
Size
size
()
{
return
sizeof
(
MType
);
}
virtual
Size
getOffset
()
{
virtual
Size
getOffset
()
{
return
offset
;
return
offset
;
}
}
...
@@ -54,7 +58,7 @@ namespace SandHook {
...
@@ -54,7 +58,7 @@ namespace SandHook {
virtual
void
set
(
PType
*
p
,
MType
t
)
{
virtual
void
set
(
PType
*
p
,
MType
t
)
{
if
(
offset
>
parentSize
)
if
(
offset
>
parentSize
)
return
;
return
;
memcpy
(
reinterpret_cast
<
void
*>
((
Size
)
p
+
getOffset
()),
&
t
,
size
of
(
MType
));
memcpy
(
reinterpret_cast
<
void
*>
((
Size
)
p
+
getOffset
()),
&
t
,
size
(
));
};
};
template
<
typename
T
>
template
<
typename
T
>
...
...
hooklib/src/main/cpp/includes/cast_art_method.h
View file @
9179864a
...
@@ -19,6 +19,7 @@ namespace SandHook {
...
@@ -19,6 +19,7 @@ namespace SandHook {
static
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>*
dexMethodIndex
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>*
dexMethodIndex
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>*
accessFlag
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>*
accessFlag
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
GCRoot
>*
declaringClass
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
GCRoot
>*
declaringClass
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
uint16_t
>*
hotnessCount
;
static
void
*
quickToInterpreterBridge
;
static
void
*
quickToInterpreterBridge
;
static
void
*
genericJniStub
;
static
void
*
genericJniStub
;
static
void
*
staticResolveStub
;
static
void
*
staticResolveStub
;
...
...
hooklib/src/main/cpp/includes/hide_api.h
View file @
9179864a
...
@@ -35,6 +35,8 @@ extern "C" {
...
@@ -35,6 +35,8 @@ extern "C" {
bool
replaceUpdateCompilerOptionsQ
();
bool
replaceUpdateCompilerOptionsQ
();
bool
forceProcessProfiles
();
}
}
#endif //SANDHOOK_HIDE_API_H
#endif //SANDHOOK_HIDE_API_H
hooklib/src/main/cpp/includes/sandhook.h
View file @
9179864a
...
@@ -10,4 +10,7 @@
...
@@ -10,4 +10,7 @@
extern
"C"
extern
"C"
JNIEXPORT
bool
nativeHookNoBackup
(
void
*
origin
,
void
*
hook
);
JNIEXPORT
bool
nativeHookNoBackup
(
void
*
origin
,
void
*
hook
);
extern
"C"
JNIEXPORT
void
*
findSym
(
const
char
*
elf
,
const
char
*
sym_name
);
#endif //SANDHOOK_SANDHOOK_H
#endif //SANDHOOK_SANDHOOK_H
hooklib/src/main/cpp/sandhook.cpp
View file @
9179864a
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include "includes/cast_compiler_options.h"
#include "includes/cast_compiler_options.h"
#include "includes/log.h"
#include "includes/log.h"
#include "includes/native_hook.h"
#include "includes/native_hook.h"
#include "includes/elf_util.h"
#include <jni.h>
#include <jni.h>
...
@@ -69,6 +70,14 @@ bool doHookWithReplacement(JNIEnv* env,
...
@@ -69,6 +70,14 @@ bool doHookWithReplacement(JNIEnv* env,
hookMethod
->
disableCompilable
();
hookMethod
->
disableCompilable
();
}
}
if
(
SDK_INT
>
ANDROID_N
)
{
forceProcessProfiles
();
}
if
((
SDK_INT
>=
ANDROID_N
&&
SDK_INT
<=
ANDROID_P
)
||
(
SDK_INT
>=
ANDROID_Q
&&
!
originMethod
->
isAbstract
()))
{
originMethod
->
setHotnessCount
(
0
);
}
if
(
backupMethod
!=
nullptr
)
{
if
(
backupMethod
!=
nullptr
)
{
originMethod
->
backup
(
backupMethod
);
originMethod
->
backup
(
backupMethod
);
backupMethod
->
disableCompilable
();
backupMethod
->
disableCompilable
();
...
@@ -113,6 +122,13 @@ bool doHookWithInline(JNIEnv* env,
...
@@ -113,6 +122,13 @@ bool doHookWithInline(JNIEnv* env,
}
}
originMethod
->
disableCompilable
();
originMethod
->
disableCompilable
();
if
(
SDK_INT
>
ANDROID_N
)
{
forceProcessProfiles
();
}
if
((
SDK_INT
>=
ANDROID_N
&&
SDK_INT
<=
ANDROID_P
)
||
(
SDK_INT
>=
ANDROID_Q
&&
!
originMethod
->
isAbstract
()))
{
originMethod
->
setHotnessCount
(
0
);
}
originMethod
->
flushCache
();
originMethod
->
flushCache
();
SandHook
::
HookTrampoline
*
hookTrampoline
=
trampolineManager
.
installInlineTrampoline
(
originMethod
,
hookMethod
,
backupMethod
);
SandHook
::
HookTrampoline
*
hookTrampoline
=
trampolineManager
.
installInlineTrampoline
(
originMethod
,
hookMethod
,
backupMethod
);
...
@@ -352,7 +368,6 @@ Java_com_swift_sandhook_test_TestClass_jni_1test(JNIEnv *env, jobject instance)
...
@@ -352,7 +368,6 @@ Java_com_swift_sandhook_test_TestClass_jni_1test(JNIEnv *env, jobject instance)
}
}
//native hook
//native hook
extern
"C"
extern
"C"
JNIEXPORT
bool
nativeHookNoBackup
(
void
*
origin
,
void
*
hook
)
{
JNIEXPORT
bool
nativeHookNoBackup
(
void
*
origin
,
void
*
hook
)
{
...
@@ -365,6 +380,12 @@ JNIEXPORT bool nativeHookNoBackup(void* origin, void* hook) {
...
@@ -365,6 +380,12 @@ JNIEXPORT bool nativeHookNoBackup(void* origin, void* hook) {
}
}
extern
"C"
JNIEXPORT
void
*
findSym
(
const
char
*
elf
,
const
char
*
sym_name
)
{
SandHook
::
ElfImg
elfImg
(
elf
);
return
reinterpret_cast
<
void
*>
(
elfImg
.
getSymbAddress
(
sym_name
));
}
static
JNINativeMethod
jniSandHook
[]
=
{
static
JNINativeMethod
jniSandHook
[]
=
{
{
{
"initNative"
,
"initNative"
,
...
...
hooklib/src/main/cpp/utils/hide_api.cpp
View file @
9179864a
...
@@ -27,6 +27,8 @@ extern "C" {
...
@@ -27,6 +27,8 @@ extern "C" {
//for Android Q
//for Android Q
void
(
**
origin_jit_update_options
)(
void
*
)
=
nullptr
;
void
(
**
origin_jit_update_options
)(
void
*
)
=
nullptr
;
void
(
*
profileSaver_ForceProcessProfiles
)()
=
nullptr
;
const
char
*
art_lib_path
;
const
char
*
art_lib_path
;
const
char
*
jit_lib_path
;
const
char
*
jit_lib_path
;
...
@@ -97,6 +99,10 @@ extern "C" {
...
@@ -97,6 +99,10 @@ extern "C" {
origin_jit_update_options
=
reinterpret_cast
<
void
(
**
)(
void
*
)
>
(
getSymCompat
(
art_lib_path
,
"_ZN3art3jit3Jit20jit_update_options_E"
));
origin_jit_update_options
=
reinterpret_cast
<
void
(
**
)(
void
*
)
>
(
getSymCompat
(
art_lib_path
,
"_ZN3art3jit3Jit20jit_update_options_E"
));
}
}
if
(
SDK_INT
>
ANDROID_N
)
{
profileSaver_ForceProcessProfiles
=
reinterpret_cast
<
void
(
*
)()
>
(
getSymCompat
(
art_lib_path
,
"_ZN3art12ProfileSaver20ForceProcessProfilesEv"
));
}
}
}
bool
canCompile
()
{
bool
canCompile
()
{
...
@@ -214,5 +220,11 @@ extern "C" {
...
@@ -214,5 +220,11 @@ extern "C" {
*
origin_jit_update_options
=
fake_jit_update_options
;
*
origin_jit_update_options
=
fake_jit_update_options
;
}
}
bool
forceProcessProfiles
()
{
if
(
profileSaver_ForceProcessProfiles
==
nullptr
)
return
false
;
profileSaver_ForceProcessProfiles
();
}
}
}
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