Skip to content

Commit d288e9e

Browse files
author
asLody
committed
CVS: commit code.
1 parent 554a002 commit d288e9e

File tree

241 files changed

+240418
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+240418
-3
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea
2+
.DS_Store
13
CMakeCache.txt
24
CMakeFiles
35
CMakeScripts

CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.4.1)
2+
3+
set(CMAKE_CXX_STANDARD 14)
4+
add_subdirectory(whale)
5+
include_directories(whale/include)
6+
include_directories(whale/src)
7+
8+
#add_executable(test whale/test/test_hook.cc)
9+
#target_link_libraries(test whale)

README.md

+103-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,106 @@
1-
# whale
2-
## The next generation Hook Engine For Android/IOS/Linux/MacOS
1+
# Whale
2+
![logo][0]
33

4+
[Chinese Version](https://github.com/asLody/whale/blob/master/README.zh-CN.md)
45

5-
## This project is about to open source, Please click the `WATCH` in the upper right corner to follow the project :)
6+
## Overview
7+
Whale is a cross-platform Hook Framework, allowed to run *Android、IOS、Linux、MacOS*.
8+
Whale support both **ARM/THUMB, ARM64, X86, X86_64 (AMD64)**, This covers almost all the major devices available today.
69

10+
## Feature
11+
#### Android
12+
* **Xposed-Stylae** Method Hook
13+
* Modify the inheritance relationship between classes at runtime
14+
* Modifies the class to which the object belongs at runtime
15+
* bypass `Hidden API Policy`
16+
17+
#### Darwin/Linux Platforms
18+
* Internal symbol resolver
19+
* Native Hook
20+
21+
#### IOS Restrictions
22+
InlineHook on IOS is only usable in `debug compile mode` on non-jailbreak devices.
23+
Release compilation mode will not work properly.
24+
25+
To solve this problem,Whale will provide a new core named `Binary Static Inline Hook`.
26+
27+
`Binary Static Inline Hook` will open source in the near future.
28+
29+
30+
## What can you do with it?
31+
* Turn on the god mode of an app
32+
* The act of monitoring or tampering with app
33+
* Instant hotfix
34+
* SandBox
35+
* Inject to system and instead of Xposed
36+
37+
## Compatibility
38+
- [x] Android 5.0.0
39+
- [x] Android 5.1.1
40+
- [x] Android 6.0
41+
- [x] Android 6.0.1
42+
- [x] Android 7.1.2
43+
- [x] Android 8.1.0
44+
- [x] Android 9.0.0
45+
- [x] IOS 11.3
46+
- [x] IOS 12.0
47+
- [x] MacOS mojave (10.14)
48+
- (Not in the list means ++untested++ )
49+
50+
## InlineHook
51+
For `pcrel instruction`, Whale will convert it to `pc-independent instruction`
52+
If the Hook procedure have not convert instructions, please feedback to ` issue `.
53+
54+
## About Jit
55+
Whale has a `built-in Jit Engine`, When you have more advanced Hook requirements, you can directly **generate executable instructions** in memory through the Jit.
56+
There is no longer the need to generate ugly hard code through tools as before.
57+
58+
## Compile
59+
We have pre-built binary versions of Android & IOS. You can find them in the built directory.
60+
61+
Whale uses CMake to build projects, so you need to install CMake on your system.
62+
63+
#### Android
64+
1. If you need to use ` Java Hook ` please copy java folder to your project.
65+
66+
2. Direct use of binary,You just copy the files under ++built/Android++ to ++src/main/jniLibs++ in your project.
67+
68+
3. If you need to compile the source code, specify `CMakeLists.txt` in build.gradle:
69+
```
70+
externalNativeBuild {
71+
cmake {
72+
path "your/whale/path/CMakeLists.txt"
73+
}
74+
}
75+
```
76+
77+
#### IOS
78+
```
79+
cd toolchain
80+
81+
cmake .. \
82+
-DCMAKE_TOOLCHAIN_FILE=ios.toolchain.cmake \
83+
-DIOS_PLATFORM=OS64 \
84+
-DPLATFORM=IOS \
85+
-DIOS_ARCH=arm64 \
86+
-DENABLE_ARC=0 \
87+
-DENABLE_BITCODE=0 \
88+
-DENABLE_VISIBILITY=0 \
89+
-DIOS_DEPLOYMENT_TARGET=9.3 \
90+
-DSHARED=ON \
91+
-DCMAKE_BUILD_TYPE=Release
92+
93+
make -j4
94+
```
95+
96+
#### Ohter platforms
97+
```
98+
cmake .
99+
make -j4
100+
```
101+
102+
## Technogy communication
103+
> [GOTO => Discord](https://discord.gg/j2Cdy2g)
104+
105+
106+
[0]: https://github.com/asLody/whale/blob/master/LOGO.png?raw=true

README.zh-CN.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Whale
2+
![logo][0]
3+
4+
## 概述
5+
Whale是一个跨平台的Hook Framework,同时支持Android、IOS、Linux、MacOS。
6+
Whale 支持**ARM/THUMB、ARM64、X86、X86_64 (AMD64)**,这几乎覆盖了目前所有主流的设备。
7+
8+
## 特性
9+
#### Android
10+
* **Xposed-Style** Method Hook
11+
* 运行时修改类之间的继承关系
12+
* 修改对象所属的类
13+
* 绕过`Hidden API Policy`
14+
15+
#### Darwin/Linux Platforms
16+
* Internal symbol resolver
17+
* Native Hook
18+
19+
#### IOS的限制
20+
IOS的InlineHook在非越狱设备上只限在debug编译模式下开启,
21+
release编译模式下将无法正常工作。
22+
23+
为了解决这个问题,Whale将提供`Binary Static Inline Hook`
24+
25+
IOS下的`Binary Static Inline Hook`将在近期开源。
26+
27+
28+
## 你可以用它做什么?
29+
* 开启App的上帝模式
30+
* 监控或篡改软件的行为
31+
* 即时生效的热修复
32+
* SandBox
33+
* 注入到系统代替Xposed
34+
35+
## Whale的兼容性
36+
- [x] Android 5.0.0
37+
- [x] Android 5.1.1
38+
- [x] Android 6.0
39+
- [x] Android 6.0.1
40+
- [x] Android 7.1.2
41+
- [x] Android 8.1.0
42+
- [x] Android 9.0.0
43+
- [x] IOS 11.3
44+
- [x] IOS 12.0
45+
- [x] MacOS mojave (10.14)
46+
- (不在清单内表示 ++未测试++ )
47+
48+
## InlineHook
49+
对于`pcrel指令`, Whale会将其转换为`pc 无关指令`
50+
如果在Hook过程有遇到未转换的指令,请提`issue`
51+
52+
## 关于Jit
53+
Whale内置了 **Jit Engine**, 当你有更高级的Hook需求时可以通过Jit直接在内存中生成可执行的指令。
54+
不再需要像从前那样通过工具来生成丑陋的hard code。
55+
56+
## 编译
57+
我们已提前编译了Android & IOS的**二进制版本**,您可以在`built目录`找到它们。
58+
59+
Whale使用了CMake来构建项目,所以你需要在你的系统上安装CMake。
60+
61+
#### Android
62+
1. 如果需要使用`Java Hook`, 请把java文件夹的代码复制到你的项目。
63+
64+
2. 直接使用二进制,你只需要复制 ++built/Android++ 下你所需的abi到你的项目的src/main/jniLibs下。
65+
66+
3. 如果需要编译源码,请在build.gradle中指定CMakelists.txt:
67+
```
68+
externalNativeBuild {
69+
cmake {
70+
path "your/whale/path/CMakeLists.txt"
71+
}
72+
}
73+
```
74+
75+
#### IOS
76+
```
77+
cd toolchain
78+
79+
cmake .. \
80+
-DCMAKE_TOOLCHAIN_FILE=ios.toolchain.cmake \
81+
-DIOS_PLATFORM=OS64 \
82+
-DPLATFORM=IOS \
83+
-DIOS_ARCH=arm64 \
84+
-DENABLE_ARC=0 \
85+
-DENABLE_BITCODE=0 \
86+
-DENABLE_VISIBILITY=0 \
87+
-DIOS_DEPLOYMENT_TARGET=9.3 \
88+
-DSHARED=ON \
89+
-DCMAKE_BUILD_TYPE=Release
90+
91+
make -j4
92+
```
93+
94+
#### Ohter platforms
95+
```
96+
cmake .
97+
make -j8
98+
```
99+
100+
## Technogy communication
101+
> **QQ Group: 977793836**
102+
103+
104+
105+
[0]: https://github.com/asLody/whale/blob/master/LOGO.png?raw=true

built/Android/arm64-v8a/libwhale.so

1.19 MB
Binary file not shown.

built/Android/armeabi-v7a/libwhale.so

786 KB
Binary file not shown.

built/Android/x86/libwhale.so

1.04 MB
Binary file not shown.

built/Android/x86_64/libwhale.so

1.08 MB
Binary file not shown.

built/IOS/libwhale.dylib

574 KB
Binary file not shown.

java/com/lody/whale/VMHelper.java

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.lody.whale;
2+
3+
import java.lang.reflect.Constructor;
4+
import java.lang.reflect.Member;
5+
import java.lang.reflect.Method;
6+
import java.util.HashMap;
7+
8+
/**
9+
* @author Lody
10+
*/
11+
class VMHelper {
12+
13+
// Holds a mapping from Java type names to native type codes.
14+
private static final HashMap<Class<?>, String> PRIMITIVE_TO_SIGNATURE;
15+
16+
static {
17+
PRIMITIVE_TO_SIGNATURE = new HashMap<>(9);
18+
PRIMITIVE_TO_SIGNATURE.put(byte.class, "B");
19+
PRIMITIVE_TO_SIGNATURE.put(char.class, "C");
20+
PRIMITIVE_TO_SIGNATURE.put(short.class, "S");
21+
PRIMITIVE_TO_SIGNATURE.put(int.class, "I");
22+
PRIMITIVE_TO_SIGNATURE.put(long.class, "J");
23+
PRIMITIVE_TO_SIGNATURE.put(float.class, "F");
24+
PRIMITIVE_TO_SIGNATURE.put(double.class, "D");
25+
PRIMITIVE_TO_SIGNATURE.put(void.class, "V");
26+
PRIMITIVE_TO_SIGNATURE.put(boolean.class, "Z");
27+
}
28+
29+
/**
30+
* Returns the internal name of {@code clazz} (also known as the
31+
* descriptor).
32+
*/
33+
private static String getSignature(final Class<?> clazz) {
34+
final String primitiveSignature = PRIMITIVE_TO_SIGNATURE.get(clazz);
35+
if (primitiveSignature != null) {
36+
return primitiveSignature;
37+
} else if (clazz.isArray()) {
38+
return "[" + getSignature(clazz.getComponentType());
39+
} else {
40+
return "L" + clazz.getName().replace('.', '/') + ";";
41+
}
42+
}
43+
44+
/**
45+
* Returns the native type codes of {@code clazz}.
46+
*/
47+
private static String getShortyType(final Class<?> clazz) {
48+
final String primitiveSignature = PRIMITIVE_TO_SIGNATURE.get(clazz);
49+
if (primitiveSignature != null) {
50+
return primitiveSignature;
51+
}
52+
return "L";
53+
}
54+
55+
// @SuppressWarnings("ConstantConditions")
56+
private static String getSignature(final Class<?> retType,
57+
final Class<?>[] parameterTypes) {
58+
final StringBuilder result = new StringBuilder();
59+
60+
result.append('(');
61+
for (final Class<?> parameterType : parameterTypes) {
62+
result.append(getSignature(parameterType));
63+
}
64+
result.append(")");
65+
result.append(getSignature(retType));
66+
67+
return result.toString();
68+
}
69+
70+
private static String getShorty(final Class<?> retType,
71+
final Class<?>[] parameterTypes) {
72+
final StringBuilder result = new StringBuilder();
73+
74+
result.append(getShortyType(retType));
75+
for (final Class<?> parameterType : parameterTypes) {
76+
result.append(getShortyType(parameterType));
77+
}
78+
79+
return result.toString();
80+
}
81+
82+
static String getSignature(final Member m) {
83+
if (m instanceof Method) {
84+
final Method md = (Method) m;
85+
return getSignature(md.getReturnType(), md.getParameterTypes());
86+
}
87+
if (m instanceof Constructor) {
88+
final Constructor<?> c = (Constructor<?>) m;
89+
return getSignature(void.class, c.getParameterTypes());
90+
}
91+
return null;
92+
}
93+
94+
static String getShorty(final Member m) {
95+
if (m instanceof Method) {
96+
final Method md = (Method) m;
97+
return getShorty(md.getReturnType(), md.getParameterTypes());
98+
}
99+
if (m instanceof Constructor) {
100+
final Constructor<?> c = (Constructor<?>) m;
101+
return getShorty(void.class, c.getParameterTypes());
102+
}
103+
return null;
104+
}
105+
}

0 commit comments

Comments
 (0)