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
a9debfed
Commit
a9debfed
authored
Feb 21, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add gen stubs script
parent
93372c42
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5305 additions
and
84 deletions
+5305
-84
genhookstubs.py
xposedcompat/genhookstubs.py
+169
-0
HookStubManager.java
...swift/sandhook/xposedcompat/hookstub/HookStubManager.java
+2
-2
MethodHookerStubs32.java
...t/sandhook/xposedcompat/hookstub/MethodHookerStubs32.java
+2566
-41
MethodHookerStubs64.java
...t/sandhook/xposedcompat/hookstub/MethodHookerStubs64.java
+2568
-41
No files found.
xposedcompat/genhookstubs.py
0 → 100644
View file @
a9debfed
#!/usr/bin/python
import
os
STUB_FILE_NAME
=
"MethodHookerStubs"
TEMP_STUB_CLASS_WRAPPER
=
"""package com.swift.sandhook.xposedcompat.hookstub;
import static com.swift.sandhook.xposedcompat.hookstub.HookStubManager.hookBridge;
import static com.swift.sandhook.xposedcompat.hookstub.HookStubManager.getMethodId;
import static com.swift.sandhook.xposedcompat.hookstub.HookStubManager.originMethods;
import static com.swift.sandhook.xposedcompat.utils.DexLog.printCallOriginError;
/**
* this file is auto gen by genhookstubs.py
* it is for sandhook internal hooker & backup methods
**/
public class MethodHookerStubs
%
d {
%
s
}
"""
TEMP_STUB_HOOK_METHOD_NAME
=
"""stub_hook_
%
d"""
TEMP_STUB_HOOK_BACKUP_NAME
=
"""stub_backup_
%
d"""
TEMP_STUB_CALL_ORIGIN_NAME
=
"""call_origin_
%
d_
%
d"""
TEMP_STUB_GET_METHOD_ID_NAME
=
"""getMethodId(
%
d,
%
d)"""
JAVA_TYPE_INT
=
"int"
JAVA_CAST_INT
=
"(int)"
JAVA_TYPE_LONG
=
"long"
TEMP_STUB_HOOK_METHOD
=
"""
public static
%
s
%
s(
%
s) throws Throwable {
return
%
s hookBridge(
%
s, new
%
s()
%
s);
}
"""
TEMP_STUB_BACKUP_METHOD
=
"""
public static
%
s
%
s(
%
s) throws Throwable {
try {
printCallOriginError(originMethods[
%
s]);
} catch (Throwable throwable) {}
return 0;
}
"""
TEMP_STUB_CALL_ORIGIN_CLASS
=
"""
static class
%
s implements CallOriginCallBack {
@Override
public long call(long... args) throws Throwable {
return
%
s(
%
s);
}
}
"""
STUB_SIZES
=
[
10
,
20
,
30
,
20
,
10
,
20
,
20
,
5
,
5
]
def
getMethodId
(
args
,
index
):
return
TEMP_STUB_GET_METHOD_ID_NAME
%
(
args
,
index
)
def
getMethodHookName
(
index
):
return
TEMP_STUB_HOOK_METHOD_NAME
%
index
def
getMethodBackupName
(
index
):
return
TEMP_STUB_HOOK_BACKUP_NAME
%
index
def
getCallOriginClassName
(
args
,
index
):
return
TEMP_STUB_CALL_ORIGIN_NAME
%
(
args
,
index
)
def
genArgsList
(
is64Bit
,
isDefine
,
length
):
args_list
=
""
for
i
in
range
(
length
):
if
(
i
!=
0
):
args_list
+=
", "
if
isDefine
:
if
(
is64Bit
):
args_list
+=
(
JAVA_TYPE_LONG
+
" "
+
"a"
+
str
(
i
))
else
:
args_list
+=
(
JAVA_TYPE_INT
+
" "
+
"a"
+
str
(
i
))
else
:
args_list
+=
(
"a"
+
str
(
i
))
return
args_list
def
genArgsListForCallOriginMethod
(
is64Bit
,
length
):
arg_name
=
"""args[
%
s]"""
args_list
=
""
for
i
in
range
(
length
):
if
(
i
!=
0
):
args_list
+=
", "
if
(
is64Bit
):
args_list
+=
arg_name
%
i
else
:
args_list
+=
(
JAVA_CAST_INT
+
arg_name
%
i
)
return
args_list
def
genHookMethod
(
is64Bit
,
args
,
index
):
java_type
=
JAVA_TYPE_LONG
if
is64Bit
else
JAVA_TYPE_INT
cast
=
""
if
is64Bit
else
JAVA_CAST_INT
args_list_pre
=
", "
if
args
>
0
else
""
args_list
=
genArgsList
(
is64Bit
,
False
,
args
)
args_list_def
=
genArgsList
(
is64Bit
,
True
,
args
)
method
=
TEMP_STUB_HOOK_METHOD
%
(
java_type
,
getMethodHookName
(
index
),
args_list_def
,
cast
,
getMethodId
(
args
,
index
),
getCallOriginClassName
(
args
,
index
),
args_list_pre
+
args_list
)
return
method
def
genBackupMethod
(
is64Bit
,
args
,
index
):
java_type
=
JAVA_TYPE_LONG
if
is64Bit
else
JAVA_TYPE_INT
args_list_def
=
genArgsList
(
is64Bit
,
True
,
args
)
method
=
TEMP_STUB_BACKUP_METHOD
%
(
java_type
,
getMethodBackupName
(
index
),
args_list_def
,
getMethodId
(
args
,
index
))
return
method
def
genCallOriginClass
(
is64Bit
,
args
,
index
):
method
=
TEMP_STUB_CALL_ORIGIN_CLASS
%
(
getCallOriginClassName
(
args
,
index
),
getMethodBackupName
(
index
),
genArgsListForCallOriginMethod
(
is64Bit
,
args
))
return
method
def
gen32Stub
(
packageDir
):
class_content
=
""
class_name
=
STUB_FILE_NAME
+
"32"
for
args
in
range
(
len
(
STUB_SIZES
)):
for
index
in
range
(
STUB_SIZES
[
args
]):
class_content
+=
"""
\n\n\n\t
//stub of arg size
%
d, index
%
d"""
%
(
args
,
index
)
class_content
+=
genCallOriginClass
(
False
,
args
,
index
)
class_content
+=
"
\n
"
class_content
+=
genHookMethod
(
False
,
args
,
index
)
class_content
+=
"
\n
"
class_content
+=
genBackupMethod
(
False
,
args
,
index
)
class_content
+=
"
\n
"
class_str
=
TEMP_STUB_CLASS_WRAPPER
%
(
32
,
class_content
)
javaFile
=
open
(
os
.
path
.
join
(
packageDir
,
class_name
+
".java"
),
"w"
)
javaFile
.
write
(
class_str
)
javaFile
.
close
()
def
gen64Stub
(
packageDir
):
class_content
=
""
class_name
=
STUB_FILE_NAME
+
"64"
for
args
in
range
(
len
(
STUB_SIZES
)):
for
index
in
range
(
STUB_SIZES
[
args
]):
class_content
+=
"""
\n\n\n\t
//stub of arg size
%
d, index
%
d"""
%
(
args
,
index
)
class_content
+=
genCallOriginClass
(
True
,
args
,
index
)
class_content
+=
"
\n
"
class_content
+=
genHookMethod
(
True
,
args
,
index
)
class_content
+=
"
\n
"
class_content
+=
genBackupMethod
(
True
,
args
,
index
)
class_content
+=
"
\n
"
class_str
=
TEMP_STUB_CLASS_WRAPPER
%
(
64
,
class_content
)
javaFile
=
open
(
os
.
path
.
join
(
packageDir
,
class_name
+
".java"
),
"w"
)
javaFile
.
write
(
class_str
)
javaFile
.
close
()
def
genStub
(
packageDir
):
for
fileName
in
os
.
listdir
(
packageDir
):
if
fileName
.
startswith
(
STUB_FILE_NAME
):
os
.
remove
(
os
.
path
.
join
(
packageDir
,
fileName
))
gen32Stub
(
packageDir
)
gen64Stub
(
packageDir
)
if
__name__
==
"__main__"
:
genStub
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"src/main/java/com/swift/sandhook/xposedcompat/hookstub"
))
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/hookstub/HookStubManager.java
View file @
a9debfed
...
...
@@ -19,10 +19,10 @@ import static de.robv.android.xposed.XposedBridge.sHookedMethodCallbacks;
public
class
HookStubManager
{
public
final
static
int
MAX_STUB_ARGS
=
5
;
public
final
static
int
MAX_STUB_ARGS
=
8
;
public
final
static
int
[]
stubSizes
=
new
int
[]
{
0
,
0
,
0
,
0
,
0
,
6
10
,
20
,
30
,
20
,
10
,
20
,
20
,
5
,
5
};
public
final
static
AtomicInteger
[]
curUseStubIndexes
=
new
AtomicInteger
[
MAX_STUB_ARGS
+
1
];
...
...
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/hookstub/MethodHookerStubs32.java
View file @
a9debfed
This diff is collapsed.
Click to expand it.
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/hookstub/MethodHookerStubs64.java
View file @
a9debfed
This diff is collapsed.
Click to expand it.
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