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
217cb801
Commit
217cb801
authored
Jan 16, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix offset
parent
92f2647b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
6 deletions
+56
-6
CastArtMethod.h
app/src/main/cpp/casts/CastArtMethod.h
+39
-4
utils.h
app/src/main/cpp/includes/utils.h
+14
-0
MainActivity.java
app/src/main/java/com/swift/sandhook/MainActivity.java
+2
-1
HookWrapper.java
...src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
+1
-1
No files found.
app/src/main/cpp/casts/CastArtMethod.h
View file @
217cb801
...
@@ -18,9 +18,6 @@ namespace SandHook {
...
@@ -18,9 +18,6 @@ namespace SandHook {
if
(
offset
>=
0
)
{
if
(
offset
>=
0
)
{
return
static_cast
<
Size
>
(
offset
);
return
static_cast
<
Size
>
(
offset
);
}
}
}
switch
(
SDK_INT
)
{
}
}
return
getParentSize
()
+
1
;
return
getParentSize
()
+
1
;
}
}
...
@@ -39,7 +36,22 @@ namespace SandHook {
...
@@ -39,7 +36,22 @@ namespace SandHook {
class
CastEntryPointQuickCompiled
:
public
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>
{
class
CastEntryPointQuickCompiled
:
public
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>
{
protected
:
protected
:
Size
calOffset
(
JNIEnv
*
jniEnv
,
art
::
mirror
::
ArtMethod
p
)
override
{
Size
calOffset
(
JNIEnv
*
jniEnv
,
art
::
mirror
::
ArtMethod
p
)
override
{
return
getParentSize
()
-
BYTE_POINT
;
if
(
SDK_INT
>=
ANDROID_L2
)
{
return
getParentSize
()
-
BYTE_POINT
;
}
else
{
return
getParentSize
()
-
8
*
2
-
4
*
4
;
}
}
};
class
CastEntryPointFromJni
:
public
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>
{
protected
:
Size
calOffset
(
JNIEnv
*
jniEnv
,
art
::
mirror
::
ArtMethod
p
)
override
{
if
(
SDK_INT
>=
ANDROID_L2
&&
SDK_INT
<=
ANDROID_N
)
{
return
getParentSize
()
-
2
*
BYTE_POINT
;
}
else
{
return
getParentSize
()
-
8
*
2
-
4
*
4
;
}
}
}
};
};
...
@@ -56,6 +68,24 @@ namespace SandHook {
...
@@ -56,6 +68,24 @@ namespace SandHook {
};
};
class
CastDexMethodIndex
:
public
IMember
<
art
::
mirror
::
ArtMethod
,
uint32_t
>
{
protected
:
Size
calOffset
(
JNIEnv
*
jniEnv
,
art
::
mirror
::
ArtMethod
p
)
override
{
if
(
SDK_INT
>=
ANDROID_P
)
return
getParentSize
()
+
1
;
int
offset
=
0
;
jint
index
=
getIntFromJava
(
jniEnv
,
"com/swift/sandhook/SandHookMethodResolver"
,
"dexMethodIndex"
);
if
(
index
!=
0
)
{
offset
=
findOffset
(
&
p
,
getParentSize
(),
2
,
static_cast
<
uint32_t
>
(
index
));
if
(
offset
>=
0
)
{
return
static_cast
<
Size
>
(
offset
);
}
}
return
getParentSize
()
+
1
;
}
};
class
CastArtMethod
{
class
CastArtMethod
{
...
@@ -64,6 +94,7 @@ namespace SandHook {
...
@@ -64,6 +94,7 @@ namespace SandHook {
static
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
entryPointQuickCompiled
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
entryPointQuickCompiled
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
entryPointFormInterpreter
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
entryPointFormInterpreter
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
dexCacheResolvedMethods
;
static
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
dexCacheResolvedMethods
;
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
void
init
(
JNIEnv
*
env
)
{
static
void
init
(
JNIEnv
*
env
)
{
...
@@ -89,6 +120,9 @@ namespace SandHook {
...
@@ -89,6 +120,9 @@ namespace SandHook {
dexCacheResolvedMethods
=
new
CastDexCacheResolvedMethods
();
dexCacheResolvedMethods
=
new
CastDexCacheResolvedMethods
();
dexCacheResolvedMethods
->
init
(
env
,
m1
,
size
);
dexCacheResolvedMethods
->
init
(
env
,
m1
,
size
);
dexMethodIndex
=
new
CastDexMethodIndex
();
dexMethodIndex
->
init
(
env
,
m1
,
size
);
// //test
// //test
// art::mirror::ArtMethod** mArray = reinterpret_cast<art::mirror::ArtMethod**>(m1.dex_cache_resolved_methods_);
// art::mirror::ArtMethod** mArray = reinterpret_cast<art::mirror::ArtMethod**>(m1.dex_cache_resolved_methods_);
//
//
...
@@ -107,6 +141,7 @@ namespace SandHook {
...
@@ -107,6 +141,7 @@ namespace SandHook {
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
CastArtMethod
::
entryPointQuickCompiled
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
CastArtMethod
::
entryPointQuickCompiled
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
CastArtMethod
::
entryPointFormInterpreter
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
CastArtMethod
::
entryPointFormInterpreter
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
CastArtMethod
::
dexCacheResolvedMethods
=
nullptr
;
IMember
<
art
::
mirror
::
ArtMethod
,
void
*>*
CastArtMethod
::
dexCacheResolvedMethods
=
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
;
...
...
app/src/main/cpp/includes/utils.h
View file @
217cb801
...
@@ -136,6 +136,20 @@ Size getAddressFromJava(JNIEnv* env, char* className, char* fieldName) {
...
@@ -136,6 +136,20 @@ Size getAddressFromJava(JNIEnv* env, char* className, char* fieldName) {
return
env
->
GetStaticLongField
(
clazz
,
id
);
return
env
->
GetStaticLongField
(
clazz
,
id
);
}
}
jint
getIntFromJava
(
JNIEnv
*
env
,
char
*
className
,
char
*
fieldName
)
{
jclass
clazz
=
env
->
FindClass
(
className
);
if
(
clazz
==
NULL
){
printf
(
"find class error !"
);
return
0
;
}
jfieldID
id
=
env
->
GetStaticFieldID
(
clazz
,
fieldName
,
"I"
);
if
(
id
==
NULL
){
printf
(
"find field error !"
);
return
0
;
}
return
env
->
GetStaticIntField
(
clazz
,
id
);
}
#endif //SANDHOOK_UTILS_H
#endif //SANDHOOK_UTILS_H
app/src/main/java/com/swift/sandhook/MainActivity.java
View file @
217cb801
...
@@ -68,8 +68,9 @@ public class MainActivity extends AppCompatActivity {
...
@@ -68,8 +68,9 @@ public class MainActivity extends AppCompatActivity {
//
//
// methods[dexMethodIndex] = artMethod;
// methods[dexMethodIndex] = artMethod;
SandHook
.
init
();
initHook
();
initHook
();
// SandHook.init();
tv
.
setText
(
""
+
calArtSize
(
method1
,
method2
));
tv
.
setText
(
""
+
calArtSize
(
method1
,
method2
));
}
catch
(
NoSuchMethodException
e
)
{
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
app/src/main/java/com/swift/sandhook/wrapper/HookWrapper.java
View file @
217cb801
...
@@ -24,7 +24,7 @@ public class HookWrapper {
...
@@ -24,7 +24,7 @@ public class HookWrapper {
Map
<
Member
,
HookEntity
>
hookEntityMap
=
getHookMethods
(
targetHookClass
,
clazz
);
Map
<
Member
,
HookEntity
>
hookEntityMap
=
getHookMethods
(
targetHookClass
,
clazz
);
for
(
HookEntity
entity:
hookEntityMap
.
values
())
{
for
(
HookEntity
entity:
hookEntityMap
.
values
())
{
if
(
entity
.
target
!=
null
&&
entity
.
hook
!=
null
)
{
if
(
entity
.
target
!=
null
&&
entity
.
hook
!=
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