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
2bc5ab99
Commit
2bc5ab99
authored
Apr 04, 2019
by
swift_gan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove useless code
parent
c4f618d1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
182 deletions
+6
-182
HookBlackList.java
...main/java/com/swift/sandhook/blacklist/HookBlackList.java
+0
-2
DynamicBridge.java
.../swift/sandhook/xposedcompat/methodgen/DynamicBridge.java
+6
-8
ClassLoaderUtils.java
...m/swift/sandhook/xposedcompat/utils/ClassLoaderUtils.java
+0
-106
DexUtils.java
.../java/com/swift/sandhook/xposedcompat/utils/DexUtils.java
+0
-66
No files found.
hooklib/src/main/java/com/swift/sandhook/blacklist/HookBlackList.java
View file @
2bc5ab99
package
com
.
swift
.
sandhook
.
blacklist
;
import
java.lang.reflect.Member
;
import
java.lang.reflect.Method
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
public
class
HookBlackList
{
...
...
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/methodgen/DynamicBridge.java
View file @
2bc5ab99
...
...
@@ -23,16 +23,14 @@ import de.robv.android.xposed.XposedBridge;
public
final
class
DynamicBridge
{
private
static
final
HashMap
<
Member
,
Method
>
hookedInfo
=
new
HashMap
<>();
private
static
HookMaker
hookMaker
=
XposedCompat
.
useNewCallBackup
?
new
HookerDexMakerNew
()
:
new
HookerDexMaker
();
private
static
final
AtomicBoolean
dexPathInited
=
new
AtomicBoolean
(
false
);
private
static
File
dexDir
;
public
static
Map
<
Member
,
HookMethodEntity
>
entityMap
=
new
HashMap
<>();
public
static
void
onForkPost
()
{
dexPathInited
.
set
(
false
);
}
//use internal stubs
private
final
static
Map
<
Member
,
HookMethodEntity
>
entityMap
=
new
HashMap
<>();
//use dex maker
private
final
static
HashMap
<
Member
,
Method
>
hookedInfo
=
new
HashMap
<>();
public
static
synchronized
void
hookMethod
(
Member
hookMethod
,
XposedBridge
.
AdditionalHookInfo
additionalHookInfo
)
{
...
...
@@ -70,9 +68,9 @@ public final class DynamicBridge {
XposedCompat
.
classLoader
,
dexDir
==
null
?
null
:
dexDir
.
getAbsolutePath
());
hookedInfo
.
put
(
hookMethod
,
hookMaker
.
getCallBackupMethod
());
}
DexLog
.
d
(
"hook method <"
+
hookMethod
.
toString
()
+
"> cost "
+
(
System
.
currentTimeMillis
()
-
timeStart
)
+
" ms, by "
+
(
stub
!=
null
?
"internal stub
.
"
:
"dex maker"
));
DexLog
.
d
(
"hook method <"
+
hookMethod
.
toString
()
+
"> cost "
+
(
System
.
currentTimeMillis
()
-
timeStart
)
+
" ms, by "
+
(
stub
!=
null
?
"internal stub"
:
"dex maker"
));
Trace
.
endSection
();
}
catch
(
Exception
e
)
{
}
catch
(
Throwable
e
)
{
DexLog
.
e
(
"error occur when hook method <"
+
hookMethod
.
toString
()
+
">"
,
e
);
}
}
...
...
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/utils/ClassLoaderUtils.java
deleted
100644 → 0
View file @
c4f618d1
package
com
.
swift
.
sandhook
.
xposedcompat
.
utils
;
import
android.os.Build
;
import
android.util.ArrayMap
;
import
com.swift.sandhook.xposedcompat.BuildConfig
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
dalvik.system.PathClassLoader
;
public
class
ClassLoaderUtils
{
public
static
final
String
DEXPATH
=
"/system/framework/edxposed.dex:/system/framework/eddalvikdx.dex:/system/framework/eddexmaker.dex"
;
public
static
void
replaceParentClassLoader
(
ClassLoader
appClassLoader
)
{
if
(
appClassLoader
==
null
)
{
DexLog
.
e
(
"appClassLoader is null, you might be kidding me?"
);
return
;
}
try
{
ClassLoader
curCL
=
ClassLoaderUtils
.
class
.
getClassLoader
();
ClassLoader
parent
=
appClassLoader
;
ClassLoader
lastChild
=
appClassLoader
;
while
(
parent
!=
null
)
{
ClassLoader
tmp
=
parent
.
getParent
();
if
(
tmp
==
curCL
)
{
DexLog
.
d
(
"replacing has been done before, skip."
);
return
;
}
if
(
tmp
==
null
)
{
DexLog
.
d
(
"before replacing =========================================>"
);
dumpClassLoaders
(
appClassLoader
);
Field
parentField
=
ClassLoader
.
class
.
getDeclaredField
(
"parent"
);
parentField
.
setAccessible
(
true
);
parentField
.
set
(
curCL
,
parent
);
parentField
.
set
(
lastChild
,
curCL
);
DexLog
.
d
(
"after replacing ==========================================>"
);
dumpClassLoaders
(
appClassLoader
);
}
lastChild
=
parent
;
parent
=
tmp
;
}
}
catch
(
Throwable
throwable
)
{
DexLog
.
e
(
"error when replacing class loader."
,
throwable
);
}
}
private
static
void
dumpClassLoaders
(
ClassLoader
classLoader
)
{
if
(
BuildConfig
.
DEBUG
)
{
while
(
classLoader
!=
null
)
{
DexLog
.
d
(
classLoader
+
" =>"
);
classLoader
=
classLoader
.
getParent
();
}
}
}
public
static
List
<
ClassLoader
>
getAppClassLoader
()
{
List
<
ClassLoader
>
cacheLoaders
=
new
ArrayList
<>(
0
);
try
{
DexLog
.
d
(
"start getting app classloader"
);
Class
appLoadersClass
=
Class
.
forName
(
"android.app.ApplicationLoaders"
);
Field
loadersField
=
appLoadersClass
.
getDeclaredField
(
"gApplicationLoaders"
);
loadersField
.
setAccessible
(
true
);
Object
loaders
=
loadersField
.
get
(
null
);
Field
mLoaderMapField
=
loaders
.
getClass
().
getDeclaredField
(
"mLoaders"
);
mLoaderMapField
.
setAccessible
(
true
);
ArrayMap
<
String
,
ClassLoader
>
mLoaderMap
=
(
ArrayMap
<
String
,
ClassLoader
>)
mLoaderMapField
.
get
(
loaders
);
DexLog
.
d
(
"mLoaders size = "
+
mLoaderMap
.
size
());
cacheLoaders
=
new
ArrayList
<>(
mLoaderMap
.
values
());
}
catch
(
Exception
ex
)
{
DexLog
.
e
(
"error get app class loader."
,
ex
);
}
return
cacheLoaders
;
}
private
static
HashSet
<
ClassLoader
>
classLoaders
=
new
HashSet
<>();
public
static
boolean
addPathToClassLoader
(
ClassLoader
classLoader
)
{
if
(!(
classLoader
instanceof
PathClassLoader
))
{
DexLog
.
w
(
classLoader
+
" is not a BaseDexClassLoader!!!"
);
return
false
;
}
if
(
classLoaders
.
contains
(
classLoader
))
{
DexLog
.
d
(
classLoader
+
" has been hooked before"
);
return
true
;
}
try
{
PathClassLoader
baseDexClassLoader
=
(
PathClassLoader
)
classLoader
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
//baseDexClassLoader.addDexPath(DEXPATH);
}
else
{
DexUtils
.
injectDexAtFirst
(
DEXPATH
,
baseDexClassLoader
);
}
classLoaders
.
add
(
classLoader
);
return
true
;
}
catch
(
Throwable
throwable
)
{
DexLog
.
e
(
"error when addPath to ClassLoader: "
+
classLoader
,
throwable
);
}
return
false
;
}
}
xposedcompat/src/main/java/com/swift/sandhook/xposedcompat/utils/DexUtils.java
deleted
100644 → 0
View file @
c4f618d1
package
com
.
swift
.
sandhook
.
xposedcompat
.
utils
;
import
android.annotation.TargetApi
;
import
android.os.Build
;
import
java.lang.reflect.Array
;
import
java.lang.reflect.Field
;
import
dalvik.system.BaseDexClassLoader
;
import
dalvik.system.DexClassLoader
;
/**
* For 6.0 only.
*/
@TargetApi
(
Build
.
VERSION_CODES
.
M
)
public
class
DexUtils
{
public
static
void
injectDexAtFirst
(
String
dexPath
,
BaseDexClassLoader
classLoader
)
throws
NoSuchFieldException
,
IllegalAccessException
,
ClassNotFoundException
{
DexClassLoader
dexClassLoader
=
new
DexClassLoader
(
dexPath
,
null
,
dexPath
,
classLoader
);
Object
baseDexElements
=
getDexElements
(
getPathList
(
classLoader
));
Object
newDexElements
=
getDexElements
(
getPathList
(
dexClassLoader
));
Object
allDexElements
=
combineArray
(
newDexElements
,
baseDexElements
);
Object
pathList
=
getPathList
(
classLoader
);
setField
(
pathList
,
pathList
.
getClass
(),
"dexElements"
,
allDexElements
);
}
private
static
Object
getDexElements
(
Object
paramObject
)
throws
IllegalArgumentException
,
NoSuchFieldException
,
IllegalAccessException
{
return
getField
(
paramObject
,
paramObject
.
getClass
(),
"dexElements"
);
}
private
static
Object
getPathList
(
Object
baseDexClassLoader
)
throws
IllegalArgumentException
,
NoSuchFieldException
,
IllegalAccessException
,
ClassNotFoundException
{
return
getField
(
baseDexClassLoader
,
Class
.
forName
(
"dalvik.system.BaseDexClassLoader"
),
"pathList"
);
}
private
static
Object
combineArray
(
Object
firstArray
,
Object
secondArray
)
{
Class
<?>
localClass
=
firstArray
.
getClass
().
getComponentType
();
int
firstArrayLength
=
Array
.
getLength
(
firstArray
);
int
allLength
=
firstArrayLength
+
Array
.
getLength
(
secondArray
);
Object
result
=
Array
.
newInstance
(
localClass
,
allLength
);
for
(
int
k
=
0
;
k
<
allLength
;
++
k
)
{
if
(
k
<
firstArrayLength
)
{
Array
.
set
(
result
,
k
,
Array
.
get
(
firstArray
,
k
));
}
else
{
Array
.
set
(
result
,
k
,
Array
.
get
(
secondArray
,
k
-
firstArrayLength
));
}
}
return
result
;
}
public
static
Object
getField
(
Object
obj
,
Class
<?>
cl
,
String
field
)
throws
NoSuchFieldException
,
IllegalArgumentException
,
IllegalAccessException
{
Field
localField
=
cl
.
getDeclaredField
(
field
);
localField
.
setAccessible
(
true
);
return
localField
.
get
(
obj
);
}
public
static
void
setField
(
Object
obj
,
Class
<?>
cl
,
String
field
,
Object
value
)
throws
NoSuchFieldException
,
IllegalArgumentException
,
IllegalAccessException
{
Field
localField
=
cl
.
getDeclaredField
(
field
);
localField
.
setAccessible
(
true
);
localField
.
set
(
obj
,
value
);
}
}
\ No newline at end of file
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