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
5ac8c414
Commit
5ac8c414
authored
Feb 19, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrap callOrigin
parent
02ff063d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
12 deletions
+23
-12
SandHook.java
hooklib/src/main/java/com/swift/sandhook/SandHook.java
+5
-5
HookerDexMaker.java
...swift/sandhook/xposedcompat/methodgen/HookerDexMaker.java
+18
-7
No files found.
hooklib/src/main/java/com/swift/sandhook/SandHook.java
View file @
5ac8c414
...
@@ -165,13 +165,13 @@ public class SandHook {
...
@@ -165,13 +165,13 @@ public class SandHook {
ensureMethodDeclaringClass
(
hookEntity
.
target
,
backupMethod
);
ensureMethodDeclaringClass
(
hookEntity
.
target
,
backupMethod
);
}
}
public
static
boolean
ensureBackupDelaringClassByOrigin
(
Member
originMethod
)
{
public
static
void
ensureBackupDelaringClassByOrigin
(
Member
originMethod
)
{
if
(
originMethod
==
null
)
if
(
originMethod
==
null
)
return
false
;
return
;
HookWrapper
.
HookEntity
hookEntity
=
globalHookEntityMap
.
get
(
originMethod
);
HookWrapper
.
HookEntity
hookEntity
=
globalHookEntityMap
.
get
(
originMethod
);
if
(
hookEntity
==
null
||
hookEntity
.
backup
==
null
)
if
(
hookEntity
==
null
||
hookEntity
.
backup
==
null
)
return
false
;
return
;
return
ensureMethodDeclaringClass
(
originMethod
,
hookEntity
.
backup
);
ensureMethodDeclaringClass
(
originMethod
,
hookEntity
.
backup
);
}
}
...
@@ -286,7 +286,7 @@ public class SandHook {
...
@@ -286,7 +286,7 @@ public class SandHook {
public
static
native
void
ensureMethodCached
(
Method
hook
,
Method
backup
);
public
static
native
void
ensureMethodCached
(
Method
hook
,
Method
backup
);
public
static
native
boolean
ensureMethodDeclaringClass
(
Member
originMethod
,
Method
backupMethod
);
public
static
native
void
ensureMethodDeclaringClass
(
Member
originMethod
,
Method
backupMethod
);
@FunctionalInterface
@FunctionalInterface
public
interface
HookModeCallBack
{
public
interface
HookModeCallBack
{
...
...
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/methodgen/HookerDexMaker.java
View file @
5ac8c414
...
@@ -210,8 +210,8 @@ public class HookerDexMaker {
...
@@ -210,8 +210,8 @@ public class HookerDexMaker {
}
else
{
}
else
{
generateBackupMethod
();
generateBackupMethod
();
}
}
generateHookMethod
();
generateCallBackupMethod
();
generateCallBackupMethod
();
generateHookMethod
();
ClassLoader
loader
;
ClassLoader
loader
;
if
(
TextUtils
.
isEmpty
(
mDexDirPath
))
{
if
(
TextUtils
.
isEmpty
(
mDexDirPath
))
{
...
@@ -284,7 +284,7 @@ public class HookerDexMaker {
...
@@ -284,7 +284,7 @@ public class HookerDexMaker {
Local
<
Member
>
method
=
code
.
newLocal
(
memberTypeId
);
Local
<
Member
>
method
=
code
.
newLocal
(
memberTypeId
);
Map
<
TypeId
,
Local
>
resultLocals
=
createResultLocals
(
code
);
Map
<
TypeId
,
Local
>
resultLocals
=
createResultLocals
(
code
);
MethodId
<?,
?>
errLogMethod
=
TypeId
.
get
(
DexLog
.
class
).
getMethod
(
TypeId
.
get
(
Void
.
TYPE
),
"printCallOriginError"
,
TypeId
.
get
(
Member
.
class
)
);
MethodId
<?,
?>
errLogMethod
=
TypeId
.
get
(
DexLog
.
class
).
getMethod
(
TypeId
.
get
(
Void
.
TYPE
),
"printCallOriginError"
,
memberTypeId
);
//very very important!!!!!!!!!!!
//very very important!!!!!!!!!!!
...
@@ -309,7 +309,7 @@ public class HookerDexMaker {
...
@@ -309,7 +309,7 @@ public class HookerDexMaker {
private
void
generateBackupAndCallOriginCheckMethod
()
{
private
void
generateBackupAndCallOriginCheckMethod
()
{
mBackupMethodId
=
mHookerTypeId
.
getMethod
(
mReturnTypeId
,
METHOD_NAME_BACKUP
,
mParameterTypeIds
);
mBackupMethodId
=
mHookerTypeId
.
getMethod
(
mReturnTypeId
,
METHOD_NAME_BACKUP
,
mParameterTypeIds
);
mSandHookCallOriginMethodId
=
TypeId
.
get
(
ErrorCatch
.
class
).
getMethod
(
TypeId
.
get
(
Object
.
class
),
"callOriginError"
,
memberTypeId
,
methodTypeId
,
TypeId
.
get
(
Object
.
class
),
TypeId
.
get
(
Object
[].
class
));
mSandHookCallOriginMethodId
=
TypeId
.
get
(
ErrorCatch
.
class
).
getMethod
(
TypeId
.
get
(
Object
.
class
),
"callOriginError"
,
memberTypeId
,
methodTypeId
,
TypeId
.
get
(
Object
.
class
),
TypeId
.
get
(
Object
[].
class
));
MethodId
<?,
?>
errLogMethod
=
TypeId
.
get
(
DexLog
.
class
).
getMethod
(
TypeId
.
get
(
Void
.
TYPE
),
"printCallOriginError"
,
TypeId
.
get
(
Member
.
class
)
);
MethodId
<?,
?>
errLogMethod
=
TypeId
.
get
(
DexLog
.
class
).
getMethod
(
TypeId
.
get
(
Void
.
TYPE
),
"printCallOriginError"
,
methodTypeId
);
Code
code
=
mDexMaker
.
declare
(
mBackupMethodId
,
Modifier
.
PUBLIC
|
Modifier
.
STATIC
);
Code
code
=
mDexMaker
.
declare
(
mBackupMethodId
,
Modifier
.
PUBLIC
|
Modifier
.
STATIC
);
...
@@ -398,9 +398,20 @@ public class HookerDexMaker {
...
@@ -398,9 +398,20 @@ public class HookerDexMaker {
mCallBackupMethodId
=
mHookerTypeId
.
getMethod
(
mReturnTypeId
,
METHOD_NAME_CALL_BACKUP
,
mParameterTypeIds
);
mCallBackupMethodId
=
mHookerTypeId
.
getMethod
(
mReturnTypeId
,
METHOD_NAME_CALL_BACKUP
,
mParameterTypeIds
);
Code
code
=
mDexMaker
.
declare
(
mCallBackupMethodId
,
Modifier
.
PUBLIC
|
Modifier
.
STATIC
);
Code
code
=
mDexMaker
.
declare
(
mCallBackupMethodId
,
Modifier
.
PUBLIC
|
Modifier
.
STATIC
);
// just call backup and return its result
// just call backup and return its result
Local
localOrigin
=
code
.
newLocal
(
memberTypeId
);
Local
localBackup
=
code
.
newLocal
(
methodTypeId
);
Local
[]
allArgsLocals
=
createParameterLocals
(
code
);
Local
[]
allArgsLocals
=
createParameterLocals
(
code
);
Map
<
TypeId
,
Local
>
resultLocals
=
createResultLocals
(
code
);
Map
<
TypeId
,
Local
>
resultLocals
=
createResultLocals
(
code
);
code
.
sget
(
mMethodFieldId
,
localOrigin
);
code
.
sget
(
mBackupMethodFieldId
,
localBackup
);
MethodId
methodId
=
TypeId
.
get
(
SandHook
.
class
).
getMethod
(
TypeId
.
get
(
Void
.
TYPE
),
"ensureMethodDeclaringClass"
,
memberTypeId
,
methodTypeId
);
code
.
invokeStatic
(
methodId
,
null
,
localOrigin
,
localBackup
);
if
(
mReturnTypeId
.
equals
(
TypeId
.
VOID
))
{
if
(
mReturnTypeId
.
equals
(
TypeId
.
VOID
))
{
code
.
invokeStatic
(
mBackupMethodId
,
null
,
allArgsLocals
);
code
.
invokeStatic
(
mBackupMethodId
,
null
,
allArgsLocals
);
code
.
returnVoid
();
code
.
returnVoid
();
...
@@ -579,12 +590,12 @@ public class HookerDexMaker {
...
@@ -579,12 +590,12 @@ public class HookerDexMaker {
}
}
// get pre-created Local with a matching typeId
// get pre-created Local with a matching typeId
if
(
mReturnTypeId
.
equals
(
TypeId
.
VOID
))
{
if
(
mReturnTypeId
.
equals
(
TypeId
.
VOID
))
{
code
.
invokeStatic
(
mBackupMethodId
,
null
,
allArgsLocals
);
code
.
invokeStatic
(
m
Call
BackupMethodId
,
null
,
allArgsLocals
);
// TODO maybe keep preset result to do some magic?
// TODO maybe keep preset result to do some magic?
code
.
invokeVirtual
(
setResultMethodId
,
null
,
param
,
nullObj
);
code
.
invokeVirtual
(
setResultMethodId
,
null
,
param
,
nullObj
);
}
else
{
}
else
{
Local
returnedResult
=
resultLocals
.
get
(
mReturnTypeId
);
Local
returnedResult
=
resultLocals
.
get
(
mReturnTypeId
);
code
.
invokeStatic
(
mBackupMethodId
,
returnedResult
,
allArgsLocals
);
code
.
invokeStatic
(
m
Call
BackupMethodId
,
returnedResult
,
allArgsLocals
);
// save returnedResult to resultObj as a Object
// save returnedResult to resultObj as a Object
autoBoxIfNecessary
(
code
,
resultObj
,
returnedResult
);
autoBoxIfNecessary
(
code
,
resultObj
,
returnedResult
);
// save resultObj to param
// save resultObj to param
...
@@ -665,11 +676,11 @@ public class HookerDexMaker {
...
@@ -665,11 +676,11 @@ public class HookerDexMaker {
// call backup and return
// call backup and return
code
.
mark
(
noHookReturn
);
code
.
mark
(
noHookReturn
);
if
(
mReturnTypeId
.
equals
(
TypeId
.
VOID
))
{
if
(
mReturnTypeId
.
equals
(
TypeId
.
VOID
))
{
code
.
invokeStatic
(
mBackupMethodId
,
null
,
allArgsLocals
);
code
.
invokeStatic
(
m
Call
BackupMethodId
,
null
,
allArgsLocals
);
code
.
returnVoid
();
code
.
returnVoid
();
}
else
{
}
else
{
Local
result
=
resultLocals
.
get
(
mReturnTypeId
);
Local
result
=
resultLocals
.
get
(
mReturnTypeId
);
code
.
invokeStatic
(
mBackupMethodId
,
result
,
allArgsLocals
);
code
.
invokeStatic
(
m
Call
BackupMethodId
,
result
,
allArgsLocals
);
code
.
returnValue
(
result
);
code
.
returnValue
(
result
);
}
}
}
}
...
...
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