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
09f7d702
Commit
09f7d702
authored
Jan 28, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tweak so name & add custom classloader
parent
b55f58e4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
9 deletions
+21
-9
CMakeLists.txt
hooklib/CMakeLists.txt
+3
-3
sandhooklib.cpp
hooklib/src/main/cpp/sandhooklib.cpp
+0
-0
SandHook.java
hooklib/src/main/java/com/swift/sandhook/SandHook.java
+5
-1
HookWrapper.java
...src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
+13
-5
No files found.
hooklib/CMakeLists.txt
View file @
09f7d702
...
...
@@ -11,13 +11,13 @@ cmake_minimum_required(VERSION 3.4.1)
# Gradle automatically packages shared libraries with your APK.
add_library
(
# Sets the name of the library.
native-lib
lib-sandhook
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/
native-
lib.cpp
src/main/cpp/
sandhook
lib.cpp
src/main/cpp/trampoline/trampoline.cpp
src/main/cpp/trampoline/trampoline_manager.cpp
src/main/cpp/utils/fake_dlfcn.cpp
...
...
@@ -43,7 +43,7 @@ find_library( # Sets the name of the path variable.
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries
(
# Specifies the target library.
native-lib
lib-sandhook
# Links the target library to the log library
# included in the NDK.
...
...
hooklib/src/main/cpp/
native-
lib.cpp
→
hooklib/src/main/cpp/
sandhook
lib.cpp
View file @
09f7d702
File moved
hooklib/src/main/java/com/swift/sandhook/SandHook.java
View file @
09f7d702
...
...
@@ -24,7 +24,7 @@ public class SandHook {
public
static
int
testAccessFlag
;
static
{
System
.
loadLibrary
(
"
native-lib
"
);
System
.
loadLibrary
(
"
lib-sandhook
"
);
init
();
}
...
...
@@ -47,6 +47,10 @@ public class SandHook {
HookWrapper
.
addHookClass
(
hookWrapperClass
);
}
public
static
void
addHookClass
(
ClassLoader
classLoader
,
Class
...
hookWrapperClass
)
throws
HookErrorException
{
HookWrapper
.
addHookClass
(
hookWrapperClass
);
}
public
static
boolean
hook
(
Member
target
,
Method
hook
,
Method
backup
)
{
if
(
target
==
null
||
hook
==
null
)
return
false
;
...
...
hooklib/src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
View file @
09f7d702
...
...
@@ -24,13 +24,17 @@ public class HookWrapper {
static
Map
<
Member
,
HookEntity
>
globalHookEntityMap
=
new
ConcurrentHashMap
<>();
public
static
void
addHookClass
(
Class
<?>...
classes
)
throws
HookErrorException
{
addHookClass
(
null
,
classes
);
}
public
static
void
addHookClass
(
ClassLoader
classLoader
,
Class
<?>...
classes
)
throws
HookErrorException
{
for
(
Class
clazz:
classes
)
{
addHookClass
(
clazz
);
addHookClass
(
cla
ssLoader
,
cla
zz
);
}
}
public
static
void
addHookClass
(
Class
<?>
clazz
)
throws
HookErrorException
{
Class
targetHookClass
=
getTargetHookClass
(
clazz
);
public
static
void
addHookClass
(
Class
Loader
classLoader
,
Class
<?>
clazz
)
throws
HookErrorException
{
Class
targetHookClass
=
getTargetHookClass
(
cla
ssLoader
,
cla
zz
);
if
(
targetHookClass
==
null
)
throw
new
HookErrorException
(
"error hook wrapper class :"
+
clazz
.
getName
());
Map
<
Member
,
HookEntity
>
hookEntityMap
=
getHookMethods
(
targetHookClass
,
clazz
);
...
...
@@ -194,14 +198,18 @@ public class HookWrapper {
private
static
Class
getTargetHookClass
(
Class
<?>
hookWrapperClass
)
{
private
static
Class
getTargetHookClass
(
Class
Loader
classLoader
,
Class
<?>
hookWrapperClass
)
{
HookClass
hookClass
=
hookWrapperClass
.
getAnnotation
(
HookClass
.
class
);
HookReflectClass
hookReflectClass
=
hookWrapperClass
.
getAnnotation
(
HookReflectClass
.
class
);
if
(
hookClass
!=
null
)
{
return
hookClass
.
value
();
}
else
if
(
hookReflectClass
!=
null
)
{
try
{
return
Class
.
forName
(
hookReflectClass
.
value
());
if
(
classLoader
==
null
)
{
return
Class
.
forName
(
hookReflectClass
.
value
());
}
else
{
return
Class
.
forName
(
hookReflectClass
.
value
(),
true
,
classLoader
);
}
}
catch
(
ClassNotFoundException
e
)
{
return
null
;
}
...
...
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