mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16a36ef22a | ||
|
|
4305000bf7 | ||
|
|
65824934d1 | ||
|
|
992fbd9f8d | ||
|
|
882c19ad8f | ||
|
|
637640b938 | ||
|
|
490e4ce2ac | ||
|
|
30ecc82ca2 | ||
|
|
bf4ebd0e5b | ||
|
|
ec7d221b08 | ||
|
|
e5b054fcfc | ||
|
|
b3ec5b6eb5 | ||
|
|
d5a49a5ce7 | ||
|
|
90689f306b | ||
|
|
1e2e5afd07 | ||
|
|
d9d44f029f | ||
|
|
cc1c2bff30 | ||
|
|
7352f8d872 | ||
|
|
4be6324cf3 | ||
|
|
0169e5e133 | ||
|
|
fc5d23109d | ||
|
|
2493a9243f | ||
|
|
28804c0af3 | ||
|
|
9d0fdecf92 | ||
|
|
dfc5886812 | ||
|
|
9a582addc3 | ||
|
|
41a8572c55 | ||
|
|
01c46c6b98 | ||
|
|
bb6f5d50bb | ||
|
|
e2d6dcaa25 | ||
|
|
75062b805c | ||
|
|
853002e70a | ||
|
|
962cbbe25d | ||
|
|
97e3b44130 | ||
|
|
8002386230 | ||
|
|
f84e13c14d | ||
|
|
ee382817d3 | ||
|
|
a834584b9d | ||
|
|
49f737ec2f | ||
|
|
7bf6d486c3 | ||
|
|
bf75790921 | ||
|
|
5b253ddd5d | ||
|
|
4c940c848b | ||
|
|
6564a0e020 | ||
|
|
c6dd965a9a | ||
|
|
d87972242a | ||
|
|
50eb73d4e8 | ||
|
|
08ec414094 | ||
|
|
601c999023 | ||
|
|
e1577d4fae | ||
|
|
79ae4b62a3 | ||
|
|
f90582d24f | ||
|
|
bc2440eeab | ||
|
|
92837c9597 | ||
|
|
b348757416 | ||
|
|
f5912f8040 | ||
|
|
95f5604bfe | ||
|
|
1ae65dd516 | ||
|
|
50773f5456 | ||
|
|
ccb332cb42 | ||
|
|
9a2dd217f1 | ||
|
|
3fe9f5a573 | ||
|
|
6858a35754 | ||
|
|
e7ce54188b | ||
|
|
9f366645c9 | ||
|
|
6a7e5a1d38 | ||
|
|
17bc993296 | ||
|
|
c348529e65 | ||
|
|
cc52a25db4 | ||
|
|
8b0bf8f211 | ||
|
|
455986b08c | ||
|
|
5b2c3c77ef | ||
|
|
11aaac0f0b | ||
|
|
6d3e29db03 | ||
|
|
655039745a | ||
|
|
09f44f1aff | ||
|
|
5ac0bac555 | ||
|
|
c7d9336b70 | ||
|
|
c11891e718 | ||
|
|
de56fca73d | ||
|
|
c20ec1e839 | ||
|
|
f8be8cb795 | ||
|
|
eb3a76769d | ||
|
|
49d2499f73 | ||
|
|
a64bbb8bb8 | ||
|
|
011fafb5b0 | ||
|
|
748b118fb1 | ||
|
|
b78839a8d4 | ||
|
|
8894a819f2 | ||
|
|
e25f0c304a | ||
|
|
bbea7b72c3 | ||
|
|
896a856c57 | ||
|
|
c80851adb7 | ||
|
|
49ac4a51a1 | ||
|
|
0d9e5fe836 | ||
|
|
34c8ccd497 | ||
|
|
f73265ac3e | ||
|
|
5e7972779f | ||
|
|
8ad8f45545 | ||
|
|
71965165b9 | ||
|
|
34dbd82a59 | ||
|
|
9aa77848d7 | ||
|
|
ad69f9d11a | ||
|
|
faeaf052b9 | ||
|
|
b0d8b5901f | ||
|
|
4496931bdf | ||
|
|
34cb16d385 | ||
|
|
bad147d898 | ||
|
|
289b0311bf | ||
|
|
1714f7603d | ||
|
|
d6d17aac35 | ||
|
|
6350bfb0ec | ||
|
|
8421d3817a | ||
|
|
3362e2071c | ||
|
|
72c0518ebc | ||
|
|
0a4ec5e97a | ||
|
|
15d7f0295a | ||
|
|
c5817a3b06 | ||
|
|
e5ac60d476 | ||
|
|
3e3f9d1c14 | ||
|
|
3ce1bccf02 | ||
|
|
205e608d60 | ||
|
|
9dab75b5fd | ||
|
|
c9c10686ab | ||
|
|
a110e675c6 | ||
|
|
9b24ea0ae4 | ||
|
|
172f354b04 | ||
|
|
cf49ed0a7b | ||
|
|
ea5ce8258d | ||
|
|
ab9369d8b7 | ||
|
|
2ce6a8e192 | ||
|
|
d8bed79f84 | ||
|
|
6ab3c279aa |
No files matched your search
+3
-3
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(JuiceAgent LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# output directories
|
||||
@@ -16,6 +16,6 @@ link_directories("$ENV{JAVA_HOME}/lib")
|
||||
add_subdirectory(${CMAKE_SOURCE_DIR}/includes/ReflectiveDLLInjection)
|
||||
|
||||
# modules
|
||||
add_subdirectory(${SRC_DIR}/libagent)
|
||||
add_subdirectory(${SRC_DIR}/libloader)
|
||||
add_subdirectory(${SRC_DIR}/libinjector)
|
||||
add_subdirectory(${SRC_DIR}/libjuiceloader)
|
||||
add_subdirectory(${SRC_DIR}/libagent)
|
||||
@@ -1,131 +1,188 @@
|
||||
|
||||
# JuiceAgent
|
||||
[English]() | [中文]()
|
||||
|
||||
JuiceAgent — a JVMTI-based injection library for loading external JARs and transforming Java bytecode, even when DisableAttachMechanism is enabled.
|
||||
JuiceAgent is an advanced JVMTI-based injection framework designed for runtime JAR loading, bytecode transformation, and runtime JVM instrumentation, even when DisableAttachMechanism is enabled.
|
||||
|
||||
**NOTICE:** Currently only supports **Windows**, and plans to support **Linux** in the future.
|
||||
**Warning**: This project is still experimental and is not recommended for production use. Use it at your own risk.
|
||||
|
||||
**WARNING:** This project is still in the experimental stage and is not recommended for production use.
|
||||
**Use this at your own risk.**
|
||||
**Note**: This project is designed for a regular JVM. Custom JVMs may not be able to run it.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Introduction
|
||||
JuiceAgent is a JVMTI-native injection framework for loading external JARs and redefining or retransformation of Java classes in a target JVM without requiring -javaagent startup arguments or attach javaagent. It also works when DisableAttachMechanism=true.
|
||||
|
||||
With JuiceAgent, developers can:
|
||||
- Dynamically load external JARs into a running JVM process
|
||||
- Invoke a specified entry class and method after injection
|
||||
- Redefine already loaded classes at runtime
|
||||
- Retransform bytecode for instrumentation or modification
|
||||
- Dump classes to disk by -agentpath:libagent.dll flags
|
||||
- And more...
|
||||
|
||||
**If you have any questions or suggestions, please feel free to open an issue or submit a pull request. =D**
|
||||
|
||||
## Index
|
||||
- [JuiceAgent](#juiceagent)
|
||||
- [Introduction](#introduction)
|
||||
- [Index](#index)
|
||||
- [Features](#features)
|
||||
- [Quick Start](#quick-start)
|
||||
- [1. Download Release](#1-download-release)
|
||||
- [2. Copy your custom JAR/Dependencies to Directory](#2-copy-your-custom-jardependencies-to-directory)
|
||||
- [3. Write Config](#3-write-config)
|
||||
- [4. Run the Injector](#4-run-the-injector)
|
||||
- [Method A: Use `injector.exe`](#method-a-use-injectorexe)
|
||||
- [Method B: Use JNI to call `inject`](#method-b-use-jni-to-call-inject)
|
||||
- [5. Done](#5-done)
|
||||
- [How To Build](#how-to-build)
|
||||
- [Requirements](#requirements)
|
||||
- [Build with CMake Presets](#build-with-cmake-presets)
|
||||
- [Manual Build](#manual-build)
|
||||
- [Full Disclaimer](#full-disclaimer)
|
||||
- [Acknowledgements](#acknowledgements)
|
||||
|
||||
## Summary
|
||||
JuiceAgent is a JVMTI-native injection framework that injects native code into a target JVM to dynamically load external JARs and perform bytecode redefinition/transformations without requiring a javaagent (works when DisableAttachMechanism=true).
|
||||
## Features
|
||||
### JuiceAgent (src/libagent)
|
||||
Low-level injection implementation for loading JuiceLoader
|
||||
- Initialize JuiceLoader
|
||||
- Lightweight Library (No Javaagent)
|
||||
- Read Config File and Load JARs
|
||||
- Invoke JuiceLoader Bootstrap API
|
||||
This project is the native implementation of JuiceAgent-API. See [JuiceAgent.java](https://github.com/xiaozhou233/JuiceAgent-API/blob/master/src/main/java/cn/xiaozhou233/juiceagent/api/JuiceAgent.java) for the API definition.
|
||||
|
||||
### libinjector (src/libinjector)
|
||||
Injector, supporting **ReflectiveDLLInjection** and CreateRemoteThread Inject.
|
||||
- Provides JNI functions for injecting DLLs into target processes
|
||||
- Get PID by process name
|
||||
- Load JARs into the Bootstrap or System ClassLoader
|
||||
- Define classes dynamically
|
||||
- Redefine classes by name or class reference
|
||||
- Retransform classes by name or class reference
|
||||
- Get all loaded classes
|
||||
- Find classes by name
|
||||
- Get class bytecode by name or class reference
|
||||
|
||||
### JuiceLoader Native (src/juiceloader)
|
||||
Native library for [JuiceLoader](https://github.com/xiaozhou233/JuiceLoader) , Inject Jars/ Redefine class Low-level implementation.
|
||||
- Implements JuiceLoader's native API
|
||||
- init
|
||||
- injectJar
|
||||
- redefineClass (redefineClassByName)
|
||||
- retransformClass (retransformClassByName)
|
||||
- getLoadedClasses
|
||||
- getClassBytes (getClassBytesByName)
|
||||
- getClassByName
|
||||
- AddToBootstrapClassLoaderSearch
|
||||
- AddToSystemClassLoaderSearch
|
||||
- nativeGetThreadByName* (test function, myself-use)
|
||||
- nativeInjectJarToThread (test function, myself-use)
|
||||
## How To Use (For Version 2.3 Build 1)
|
||||
## Quick Start
|
||||
### 1. Download Release
|
||||
Download `JuiceAgent_vx.x.x_x64.zip` from the [releases](https://github.com/xiaozhou233/JuiceAgent/releases) page.
|
||||
|
||||
### 1. Download Files
|
||||
- Download `libagent`, `libinjector`, and `libjuiceloader` from the Release to the same directory.
|
||||
- Download JARs `bootstrap-api.jar`, `JuiceLoader.jar`, and `Entry.jar` (or your own JAR) to the same directory.
|
||||
Extract the ZIP file to a directory.
|
||||
- YourDir
|
||||
- libagent.dll
|
||||
- libinject.dll
|
||||
- libloader.dll
|
||||
- injector.exe
|
||||
|
||||
### 2. Write Config File
|
||||
Create a config file named `AgentConfig.toml` in the same directory. Example:
|
||||
### 2. Copy your custom JAR/Dependencies to Directory
|
||||
- YourDir
|
||||
- libagent.dll
|
||||
- libinject.dll
|
||||
- libloader.dll
|
||||
- injector.exe
|
||||
- **MyCustomJar.jar**
|
||||
- **injection**
|
||||
- **Dependencies1.jar**
|
||||
- **Dependencies2.jar**
|
||||
|
||||
### 3. Write Config
|
||||
|
||||
```toml
|
||||
# Leave empty to use default values
|
||||
# Default values: <Current Directory>/default-name
|
||||
[JuiceAgent]
|
||||
Version = 1
|
||||
|
||||
# Example: JuiceLoaderJarPath = "D:\\Development\\JuiceSky\\build\\libs\\JuiceLoader-1.0.jar"
|
||||
# Default: <Current Directory>/JuiceLoader.jar
|
||||
JuiceLoaderJarPath = ""
|
||||
# Default: <Current Directory>/libjuiceloader.dll
|
||||
JuiceLoaderLibraryPath = ""
|
||||
# Default: <Current Directory>/injection/
|
||||
InjectionDir = ""
|
||||
# Default: <Current Directory>/Entry.jar
|
||||
EntryJarPath = "D:\\Development\\JuiceSky\\build\\libs\\JuiceSky-1.0-Hooked.jar"
|
||||
EntryClass = "cn.xiaozhou233.juicesky.LoaderEntry"
|
||||
EntryMethod = "start"
|
||||
```
|
||||
| Method| Usage|
|
||||
| - | -|
|
||||
| **Reflective Inject** | Uses `libinjector`. Pass the config directory as a parameter. </br></br> Example: config file at `<YourDir>/AgentConfig.toml`, </br></br>pass `<YourDir>` as parameter.</br></br> Example:</br>`C/C++: libinjector.dll -> inject(pid, agentpath, configpath)`</br>`Java: See 3. Invoke Inject Function`|
|
||||
| **Normal Inject** | Uses `LoadLibraryA + CreateRemoteThread`. Keep `AgentConfig.toml` and all DLLs/JARs in the same directory.</br>
|
||||
[JuiceAgent.Loader]
|
||||
# Path to JuiceAgent-API-x.x.x+build.x.jar
|
||||
JuiceAgentAPIJarPath = "./JuiceAgent-API-x.x.x+build.x.jar"
|
||||
# Path to libagent.dll, default is "./libagent.dll"
|
||||
JuiceAgentNativeLibraryPath = ""
|
||||
|
||||
### 3. Invoke Inject Function
|
||||
C/C++ Use libinjector and invoke inject(int pid, char* path, InjectParameters *params)
|
||||
[JuiceAgent.Modules]
|
||||
|
||||
Java Use `Injecor.jar`: `java -jar Injecor.jar` or
|
||||
```
|
||||
package cn.xiaozhou233.juiceagent.injector;
|
||||
|
||||
public class InjectorNative {
|
||||
/*
|
||||
* @param pid target process id
|
||||
*/
|
||||
public native boolean inject(int pid, String path);
|
||||
|
||||
/*
|
||||
* @param pid target process id
|
||||
* @param path injection dll path
|
||||
* @param configPath config file path
|
||||
*/
|
||||
public native boolean inject(int pid, String path, String configPath);
|
||||
}
|
||||
```
|
||||
```
|
||||
// Your class
|
||||
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
|
||||
|
||||
System.load("<path-to-libinjector>");
|
||||
InjectorNative injectorNative = new InjectorNative();
|
||||
|
||||
injectorNative.inject(<pid>, "<path-to-libagent>", "<path-to-toml-config-dir>");
|
||||
[JuiceAgent.Modules.JarLoader]
|
||||
Enabled = true
|
||||
# Path to the Injection JAR files to be loaded
|
||||
InjectionDir = "./injection"
|
||||
# Path to the JAR file to be loaded
|
||||
JarPath = "./MyCustomJar.jar"
|
||||
# Entry class to be executed after loading the JAR
|
||||
EntryClass = "Example.Main"
|
||||
# Entry method to be executed after loading the JAR
|
||||
# Method: public static void run()
|
||||
EntryMethod = "run"
|
||||
```
|
||||
|
||||
### 4. Done!
|
||||
If the injection is successful, EntryClass .EntryMethod() of <EntryJarPath> will be executed.
|
||||
## Hot To Build
|
||||
### Environment
|
||||
Save the config file as `config.toml`.
|
||||
|
||||
- YourDir
|
||||
- **config.toml**
|
||||
- libagent.dll
|
||||
- libinject.dll
|
||||
- libloader.dll
|
||||
- injector.exe
|
||||
- MyCustomJar.jar
|
||||
- injection
|
||||
- Dependencies1.jar
|
||||
- Dependencies2.jar
|
||||
|
||||
### 4. Run the Injector
|
||||
|
||||
#### Method A: Use `injector.exe`
|
||||
Run `injector.exe` from `YourDir`.
|
||||
|
||||
```text
|
||||
<jps output>
|
||||
Input PID:
|
||||
```
|
||||
|
||||
Enter the PID of the target JVM process and press Enter.
|
||||
|
||||
#### Method B: Use JNI to call `inject`
|
||||
|
||||
See [Documents](https://github.com/xiaozhou233/JuiceAgent/blob/main/docs/Inject.md) for details.
|
||||
|
||||
### 5. Done
|
||||
The target JVM will load the specified JAR and execute the specified entry class and method.
|
||||
|
||||
## How To Build
|
||||
|
||||
### Requirements
|
||||
- Java 8+
|
||||
- MinGW
|
||||
- CMake
|
||||
- CMake 3.15+
|
||||
- Ninja
|
||||
```
|
||||
|
||||
### Build with CMake Presets
|
||||
```powershell
|
||||
git clone https://github.com/xiaozhou233/JuiceAgent.git
|
||||
cd JuiceAgent
|
||||
|
||||
mkdir -p build
|
||||
cmake --build build --
|
||||
cmake --preset ninja-release
|
||||
cmake --build build
|
||||
```
|
||||
dlls: build/bin/
|
||||
|
||||
jars: see [JuiceLoader](https://github.com/xiaozhou233/JuiceLoader)
|
||||
### Manual Build
|
||||
```powershell
|
||||
git clone https://github.com/xiaozhou233/JuiceAgent.git
|
||||
cd JuiceAgent
|
||||
|
||||
## Full Disclaimer/ 完整免责声明
|
||||
Disclaimer: This project is intended for learning and research in controlled environments only. The author is not responsible for any consequences arising from unauthorized use, modification, cracking, or violation of any applicable agreements or laws. Users are responsible for ensuring their actions are legal and compliant.
|
||||
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
免责声明: 本项目仅建议在受控环境中用于学习与研究。任何利用本项目实施破解、篡改、未经授权获取源码或其他违反目标协议或法律的行为所导致的一切后果,作者概不负责。使用者应自行确保其行为合法合规,并对相应后果承担全部责任。
|
||||
The generated binaries will be placed in `build/bin`.
|
||||
|
||||
`JuiceAgent-API.jar` can be built from or downloaded from [JuiceAgent-API](https://github.com/xiaozhou233/JuiceAgent-API).
|
||||
|
||||
## Full Disclaimer
|
||||
This project is intended for learning and research in controlled environments only. The author is not responsible for any consequences arising from unauthorized use, modification, cracking, or violation of any applicable agreements or laws. Users are responsible for ensuring that their actions are legal and compliant.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
- [ReflectiveDLLInjection](https://github.com/stephenfewer/ReflectiveDLLInjection) - DLL Inject
|
||||
- [plog](https://github.com/SergiusTheBest/plog) - portable, simple and extensible C++ logging library
|
||||
- [tinytoml](https://github.com/mayah/tinytoml) - A header only C++11 library for parsing TOML.
|
||||
|
||||
- [ReflectiveDLLInjection](https://github.com/stephenfewer/ReflectiveDLLInjection) - DLL injection implementation
|
||||
- [plog](https://github.com/SergiusTheBest/plog) - Portable, simple, and extensible C++ logging library
|
||||
- [toml11](https://github.com/ToruNiina/toml11) - TOML for Modern C++
|
||||
- [eventpp](https://github.com/wqking/eventpp) - C++ library for event dispatchers and callback lists
|
||||
-204
@@ -1,204 +0,0 @@
|
||||
# JuiceAgent
|
||||
[English]() | [中文]()
|
||||
|
||||
JuiceAgent —— 一个基于 **JVMTI** 的注入库,用于在 **DisableAttachMechanism 启用的情况下**,向目标 JVM 注入外部 JAR 并对 Java 字节码进行转换。
|
||||
|
||||
**注意:** 当前仅支持 **Windows**,未来计划支持 **Linux**。
|
||||
|
||||
**警告:** 本项目仍处于实验阶段,不建议用于生产环境。
|
||||
**使用风险自负。**
|
||||
|
||||
---
|
||||
|
||||
## 简介(Summary)
|
||||
|
||||
JuiceAgent 是一个基于 **JVMTI 的原生注入框架**,通过向目标 JVM 注入原生代码,实现 **动态加载外部 JAR** 以及 **类重定义 / 类重转换**,并且 **无需使用 javaagent**(即使 `DisableAttachMechanism=true` 也可正常工作)。
|
||||
|
||||
---
|
||||
|
||||
## 特性(Features)
|
||||
|
||||
### JuiceAgent(`src/libagent`)
|
||||
用于加载 JuiceLoader 的底层注入实现:
|
||||
|
||||
- 初始化 JuiceLoader
|
||||
- 轻量级库(无需 Java Agent)
|
||||
- 读取配置文件并加载 JAR
|
||||
- 调用 JuiceLoader Bootstrap API
|
||||
|
||||
---
|
||||
|
||||
### libinjector(`src/libinjector`)
|
||||
注入器模块,支持 **ReflectiveDLLInjection** 与 **CreateRemoteThread** 注入方式:
|
||||
|
||||
- 提供 JNI 接口,用于向目标进程注入 DLL
|
||||
- 支持通过进程名获取 PID
|
||||
|
||||
---
|
||||
|
||||
### JuiceLoader Native(`src/juiceloader`)
|
||||
[JuiceLoader](https://github.com/xiaozhou233/JuiceLoader) 的原生实现,用于 JAR 注入与类重定义的底层支持。
|
||||
|
||||
实现的 Native API 包括:
|
||||
|
||||
- `init`
|
||||
- `injectJar`
|
||||
- `redefineClass`(`redefineClassByName`)
|
||||
- `retransformClass`(`retransformClassByName`)
|
||||
- `getLoadedClasses`
|
||||
- `getClassBytes`(`getClassBytesByName`)
|
||||
- `getClassByName`
|
||||
- `AddToBootstrapClassLoaderSearch`
|
||||
- `AddToSystemClassLoaderSearch`
|
||||
- `nativeGetThreadByName`(测试函数,自用)
|
||||
- `nativeInjectJarToThread`(测试函数,自用)
|
||||
|
||||
---
|
||||
|
||||
## 使用方法(How To Use,Version 2.3 Build 1)
|
||||
|
||||
### 1. 下载文件
|
||||
|
||||
- 从 Release 页面下载 `libagent`、`libinjector`、`libjuiceloader`,并放置在 **同一目录**
|
||||
- 下载以下 JAR 并放置在同一目录:
|
||||
- `bootstrap-api.jar`
|
||||
- `JuiceLoader.jar`
|
||||
- `Entry.jar`(或你自己的 JAR)
|
||||
|
||||
---
|
||||
|
||||
### 2. 编写配置文件
|
||||
|
||||
在同一目录下创建 `AgentConfig.toml`,示例如下:
|
||||
|
||||
```toml
|
||||
# 留空表示使用默认值
|
||||
# 默认值:<当前目录>/default-name
|
||||
|
||||
# 示例:
|
||||
# JuiceLoaderJarPath = "D:\Development\JuiceSky\build\libs\JuiceLoader-1.0.jar"
|
||||
|
||||
# 默认:<当前目录>/JuiceLoader.jar
|
||||
JuiceLoaderJarPath = ""
|
||||
|
||||
# 默认:<当前目录>/libjuiceloader.dll
|
||||
JuiceLoaderLibraryPath = ""
|
||||
|
||||
# 默认:<当前目录>/injection/
|
||||
InjectionDir = ""
|
||||
|
||||
# 默认:<当前目录>/Entry.jar
|
||||
EntryJarPath = "D:\Development\JuiceSky\build\libs\JuiceSky-1.0-Hooked.jar"
|
||||
|
||||
EntryClass = "cn.xiaozhou233.juicesky.LoaderEntry"
|
||||
EntryMethod = "start"
|
||||
```
|
||||
|
||||
#### 注入方式说明
|
||||
|
||||
| 注入方式 | 说明 |
|
||||
|---------|------|
|
||||
| **Reflective 注入** | 使用 `libinjector`,将 **配置文件所在目录** 作为参数传入。<br/><br/>示例:配置文件位于 `<YourDir>/AgentConfig.toml`,则传入 `<YourDir>`。<br/><br/>调用示例:<br/>`C/C++: libinjector.dll -> inject(pid, agentPath, configPath)`<br/>`Java: 见下方步骤` |
|
||||
| **普通注入** | 使用 `LoadLibraryA + CreateRemoteThread`。<br/>要求 `AgentConfig.toml` 与所有 DLL / JAR 位于同一目录 |
|
||||
|
||||
---
|
||||
|
||||
### 3. 调用注入函数
|
||||
|
||||
#### C / C++
|
||||
|
||||
使用 `libinjector`,调用:
|
||||
|
||||
```
|
||||
inject(int pid, char* path, InjectParameters *params)
|
||||
```
|
||||
|
||||
#### Java
|
||||
|
||||
使用 `Injecor.jar`:
|
||||
|
||||
```
|
||||
java -jar Injecor.jar
|
||||
```
|
||||
|
||||
或通过 Native 接口:
|
||||
|
||||
```java
|
||||
package cn.xiaozhou233.juiceagent.injector;
|
||||
|
||||
public class InjectorNative {
|
||||
|
||||
/*
|
||||
* @param pid target process id
|
||||
*/
|
||||
public native boolean inject(int pid, String path);
|
||||
|
||||
/*
|
||||
* @param pid target process id
|
||||
* @param path injection dll path
|
||||
* @param configPath config file path
|
||||
*/
|
||||
public native boolean inject(int pid, String path, String configPath);
|
||||
}
|
||||
```
|
||||
|
||||
使用示例:
|
||||
|
||||
```java
|
||||
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
|
||||
|
||||
System.load("<path-to-libinjector>");
|
||||
InjectorNative injectorNative = new InjectorNative();
|
||||
|
||||
injectorNative.inject(<pid>, "<path-to-libagent>", "<path-to-toml-config-dir>");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4. 完成
|
||||
|
||||
如果注入成功,将会执行 `<EntryJarPath>` 中配置的:
|
||||
|
||||
```
|
||||
EntryClass.EntryMethod()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 构建方式(How To Build)
|
||||
|
||||
### 构建环境
|
||||
|
||||
- Java 8+
|
||||
- MinGW
|
||||
- CMake
|
||||
- Ninja
|
||||
|
||||
```bash
|
||||
git clone https://github.com/xiaozhou233/JuiceAgent.git
|
||||
cd JuiceAgent
|
||||
|
||||
mkdir -p build
|
||||
cmake --build build --
|
||||
```
|
||||
|
||||
- DLL 输出目录:`build/bin/`
|
||||
- JAR 文件:请参考 [JuiceLoader](https://github.com/xiaozhou233/JuiceLoader)
|
||||
|
||||
---
|
||||
|
||||
## 完整免责声明(Full Disclaimer)
|
||||
|
||||
**免责声明(英文):**
|
||||
This project is intended for learning and research in controlled environments only. The author is not responsible for any consequences arising from unauthorized use, modification, cracking, or violation of any applicable agreements or laws. Users are responsible for ensuring their actions are legal and compliant.
|
||||
|
||||
**免责声明(中文):**
|
||||
本项目仅建议在受控环境中用于学习与研究。任何利用本项目实施破解、篡改、未经授权获取源码或其他违反目标协议或法律的行为所导致的一切后果,作者概不负责。使用者应自行确保其行为合法合规,并对相应后果承担全部责任。
|
||||
|
||||
---
|
||||
|
||||
## 致谢(Acknowledgements)
|
||||
|
||||
- [ReflectiveDLLInjection](https://github.com/stephenfewer/ReflectiveDLLInjection) —— DLL 注入实现
|
||||
- [plog](https://github.com/SergiusTheBest/plog) —— 轻量级、可扩展的 C++ 日志库
|
||||
- [tinytoml](https://github.com/mayah/tinytoml) —— 仅头文件的 C++11 TOML 解析库
|
||||
@@ -0,0 +1,22 @@
|
||||
# TODO - 开发待办事项
|
||||
这个文档用来记录开发时的待办事项以及以后的开发计划。
|
||||
---
|
||||
|
||||
## 2026-04-16
|
||||
- [ ] ~~把读取toml的库换成支持toml 1.0的库~~
|
||||
- [x] 在 `includes/JuiceAgent` 文件夹下实现 `Config.hpp` 配置系统
|
||||
- [ ] ~~新建测试 读取配置文件 (放弃)~~
|
||||
|
||||
- [ ] 重构 `libloader` 的配置系统
|
||||
|
||||
## 2026-04-17
|
||||
- [x] 重构项目为模块化项目
|
||||
- [x] `libloader` 模块只负责加载`JuiceAgent-API`和`JuiceAgent`, Jar文件由`JuiceAgent`接管
|
||||
- [x] `libloader` 读取配置文件并传参`JuiceAgentNativePath`和`ConfigDir`到 `JuiceAgent` 中,由`JuiceAgent`读取配置文件继续进行操作
|
||||
|
||||
## 2026-04-19
|
||||
- [x] 在 `JuiceAgent/Utils.hpp`做序列化操作
|
||||
- [x] 统一调用 module的Java实现
|
||||
|
||||
## 2026-04-20
|
||||
- [x] 修改文档
|
||||
+1
-1
@@ -1 +1 @@
|
||||
VERSION = Version 2.3 Build 1
|
||||
VERSION = Version 3.4.0 Build 1
|
||||
@@ -0,0 +1,44 @@
|
||||
# Inject Method
|
||||
|
||||
## Method A: Use `injector.exe`
|
||||
Run `injector.exe` from `YourDir`.
|
||||
|
||||
```text
|
||||
<jps output>
|
||||
Input PID:
|
||||
```
|
||||
|
||||
Enter the PID of the target JVM process and press Enter.
|
||||
|
||||
## Method B: Use JNI to call `inject`
|
||||
Create `cn/xiaozhou233/juiceagent/injector/InjectorNative.java` in your project:
|
||||
|
||||
```java
|
||||
package cn.xiaozhou233.juiceagent.injector;
|
||||
|
||||
public class InjectorNative {
|
||||
/*
|
||||
* @param pid target process id
|
||||
* @param path injection DLL path
|
||||
*/
|
||||
public native boolean inject(int pid, String path);
|
||||
|
||||
/*
|
||||
* @param pid target process id
|
||||
* @param path injection DLL path
|
||||
* @param configDir directory containing config.toml
|
||||
*/
|
||||
public native boolean inject(int pid, String path, String configDir);
|
||||
}
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```java
|
||||
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
|
||||
|
||||
System.load("<path-to-libinject>");
|
||||
InjectorNative injectorNative = new InjectorNative();
|
||||
|
||||
injectorNative.inject(<pid>, "<path-to-libloader>", "<path-to-config-directory>");
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
[JuiceAgent]
|
||||
Version = 1
|
||||
|
||||
[JuiceAgent.Loader]
|
||||
JuiceAgentNativeLibraryPath = ""
|
||||
|
||||
[JuiceAgent.Modules]
|
||||
|
||||
[JuiceAgent.Modules.JarLoader]
|
||||
Enabled = true
|
||||
InjectionDir = ""
|
||||
JarPath = ""
|
||||
EntryClass = ""
|
||||
EntryMethod = ""
|
||||
|
||||
[JuiceAgent.Modules.Dumper]
|
||||
Enabled = false
|
||||
DumpDir = ""
|
||||
|
||||
[JuiceAgent.Modules.Remapper]
|
||||
Enabled = false
|
||||
JuiceRemapperJarPath = ""
|
||||
@@ -0,0 +1,162 @@
|
||||
#pragma once
|
||||
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <JuiceAgent/JuiceAgent.hpp>
|
||||
#include <toml.hpp>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <JuiceAgent/Utils.hpp>
|
||||
|
||||
namespace JuiceAgent::Config {
|
||||
|
||||
class Config {
|
||||
private:
|
||||
std::filesystem::path _runtime_dir;
|
||||
toml::value _config;
|
||||
bool _valid = false;
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
static T _read_value(const toml::value& v) {
|
||||
if constexpr (std::is_same_v<T, std::string>) {
|
||||
return v.as_string();
|
||||
} else if constexpr (std::is_same_v<T, bool>) {
|
||||
return v.as_boolean();
|
||||
} else if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) {
|
||||
return static_cast<T>(v.as_integer());
|
||||
} else if constexpr (std::is_floating_point_v<T>) {
|
||||
return static_cast<T>(v.as_floating());
|
||||
} else {
|
||||
static_assert(sizeof(T) == 0, "Unsupported config type");
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
explicit Config(const std::filesystem::path& runtime_dir = {})
|
||||
{
|
||||
_runtime_dir = runtime_dir.empty()
|
||||
? std::filesystem::current_path()
|
||||
: runtime_dir;
|
||||
|
||||
const auto result = toml::try_parse(_runtime_dir / "config.toml");
|
||||
|
||||
if (result.is_ok()) {
|
||||
_config = result.unwrap();
|
||||
_valid = true;
|
||||
} else {
|
||||
PLOGE << "Failed to parse config.toml";
|
||||
|
||||
for (const auto& err : result.unwrap_err()) {
|
||||
PLOGE << toml::format_error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool is_valid() const noexcept {
|
||||
return _valid;
|
||||
}
|
||||
|
||||
const toml::value& get_config() const noexcept {
|
||||
return _config;
|
||||
}
|
||||
|
||||
const std::filesystem::path& runtime_dir() const noexcept {
|
||||
return _runtime_dir;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T get(const std::string& path, const T& default_value, bool is_path = false) const {
|
||||
if (!_valid) {
|
||||
return default_value;
|
||||
}
|
||||
|
||||
try {
|
||||
const toml::value* current = &_config;
|
||||
std::size_t start = 0;
|
||||
|
||||
while (start < path.size()) {
|
||||
const std::size_t end = path.find('.', start);
|
||||
const std::string key = path.substr(
|
||||
start,
|
||||
end == std::string::npos ? std::string::npos : end - start
|
||||
);
|
||||
|
||||
current = ¤t->at(key);
|
||||
|
||||
if (end == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
|
||||
start = end + 1;
|
||||
}
|
||||
|
||||
T value = _read_value<T>(*current);
|
||||
|
||||
if constexpr (std::is_same_v<T, std::string>) {
|
||||
if (value.empty()) {
|
||||
value = default_value;
|
||||
}
|
||||
|
||||
// Handle relative paths
|
||||
if (is_path) {
|
||||
// Check if starts with "."
|
||||
if (value.starts_with(".")) {
|
||||
// Remove "."
|
||||
value = value.substr(1);
|
||||
// Check if starts with "/"
|
||||
if (value.starts_with("/")) {
|
||||
// Remove "/"
|
||||
value = value.substr(1);
|
||||
}
|
||||
|
||||
// runtime_dir + value
|
||||
value = (_runtime_dir / value).string();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
PLOGW << "Config get failed: " << path << ", using default value";
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace Utils {
|
||||
inline LoaderConfig get_loader_config(const Config& config) {
|
||||
|
||||
LoaderConfig loader_config = LoaderConfig();
|
||||
loader_config.JuiceAgentNativeLibraryPath = config.get<std::string>("JuiceAgent.Loader.JuiceAgentNativeLibraryPath",
|
||||
(config.runtime_dir()/"libagent.dll").string(),
|
||||
true);
|
||||
loader_config.RuntimeDir = config.runtime_dir().string();
|
||||
|
||||
return loader_config;
|
||||
}
|
||||
|
||||
inline void print_loader_config(const LoaderConfig& config) {
|
||||
PLOGI << "JuiceAgentNativeLibraryPath: " << config.JuiceAgentNativeLibraryPath;
|
||||
PLOGI << "RuntimeDir: " << config.RuntimeDir;
|
||||
}
|
||||
|
||||
inline std::string serialize_loader_config(const LoaderConfig& config) {
|
||||
// std::string result = "";
|
||||
|
||||
// result += "Version=2;";
|
||||
// result += "JuiceAgentAPIJarPath=" + config.JuiceAgentAPIJarPath + ";";
|
||||
// result += "JuiceAgentNativeLibraryPath=" + config.JuiceAgentNativeLibraryPath + ";";
|
||||
// result += "RuntimeDir=" + config.RuntimeDir + ";";
|
||||
|
||||
JuiceAgent::Utils::Serializer ser;
|
||||
ser.add_kv("Version", 2);
|
||||
ser.add_kv("JuiceAgentNativeLibraryPath", config.JuiceAgentNativeLibraryPath);
|
||||
ser.add_kv("RuntimeDir", config.RuntimeDir);
|
||||
|
||||
return ser.serialize();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace JuiceAgent::Config
|
||||
@@ -0,0 +1,896 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace JuiceAgent::Resource {
|
||||
|
||||
static const unsigned char juiceagent_api_bytes[] = {
|
||||
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72,
|
||||
0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4d, 0x45, 0x54, 0x41, 0x2d, 0x49,
|
||||
0x4e, 0x46, 0x2f, 0x03, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00,
|
||||
0x08, 0x08, 0x00, 0xd9, 0x72, 0x95, 0x5c, 0xcf, 0x58, 0x6d, 0xcb, 0x2d,
|
||||
0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x4d,
|
||||
0x45, 0x54, 0x41, 0x2d, 0x49, 0x4e, 0x46, 0x2f, 0x4d, 0x41, 0x4e, 0x49,
|
||||
0x46, 0x45, 0x53, 0x54, 0x2e, 0x4d, 0x46, 0xf3, 0x4d, 0xcc, 0xcb, 0x4c,
|
||||
0x4b, 0x2d, 0x2e, 0xd1, 0x0d, 0x4b, 0x2d, 0x2a, 0xce, 0xcc, 0xcf, 0xb3,
|
||||
0x52, 0x30, 0xd4, 0x33, 0xe0, 0xe5, 0x72, 0x2a, 0xcd, 0xcc, 0x49, 0x41,
|
||||
0x16, 0x33, 0xd1, 0x33, 0xd4, 0x4e, 0x02, 0x09, 0xea, 0x19, 0xf2, 0x72,
|
||||
0xf1, 0x72, 0x01, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08,
|
||||
0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x63, 0x6e,
|
||||
0x2f, 0x03, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08,
|
||||
0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f,
|
||||
0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f,
|
||||
0x03, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00,
|
||||
0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78,
|
||||
0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a,
|
||||
0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x03, 0x00,
|
||||
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72,
|
||||
0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61,
|
||||
0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69,
|
||||
0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f,
|
||||
0x03, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00,
|
||||
0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78,
|
||||
0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a,
|
||||
0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70,
|
||||
0x69, 0x2f, 0x62, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x2f,
|
||||
0x03, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00,
|
||||
0xdd, 0x72, 0x95, 0x5c, 0x89, 0xbd, 0x76, 0xf7, 0x74, 0x01, 0x00, 0x00,
|
||||
0xf9, 0x02, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78,
|
||||
0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a,
|
||||
0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70,
|
||||
0x69, 0x2f, 0x62, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x2f,
|
||||
0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x42, 0x72, 0x69,
|
||||
0x64, 0x67, 0x65, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x9d, 0x92, 0xd9,
|
||||
0x4a, 0x43, 0x31, 0x10, 0x86, 0xff, 0xb4, 0xc7, 0x6e, 0xd6, 0x7d, 0x5f,
|
||||
0x1e, 0xa0, 0x7a, 0x61, 0x70, 0xc1, 0x05, 0x45, 0xb0, 0x82, 0xa2, 0x14,
|
||||
0x15, 0x15, 0xef, 0x73, 0x4e, 0x43, 0x4d, 0x6d, 0x93, 0x72, 0x4e, 0x4e,
|
||||
0x11, 0x9f, 0xca, 0xe5, 0x42, 0xf0, 0xc2, 0x07, 0xf0, 0xa1, 0xc4, 0xc9,
|
||||
0x69, 0x5d, 0xaf, 0xa4, 0x04, 0x32, 0x93, 0x49, 0xfe, 0xf9, 0x66, 0x86,
|
||||
0xbc, 0xbd, 0xbf, 0xbc, 0x02, 0x58, 0xc3, 0x6c, 0x01, 0x1e, 0x26, 0xf3,
|
||||
0x48, 0x63, 0x2a, 0x8b, 0xe9, 0x2c, 0x66, 0x18, 0x72, 0xad, 0xd0, 0xb4,
|
||||
0x55, 0x55, 0x86, 0x0c, 0xeb, 0x95, 0x40, 0xf3, 0x5b, 0x25, 0xcc, 0xdd,
|
||||
0xb5, 0x89, 0x57, 0x56, 0x57, 0x79, 0x3d, 0x56, 0x81, 0x14, 0x35, 0xa9,
|
||||
0x2d, 0x17, 0x2d, 0xc5, 0x7d, 0x63, 0x6c, 0x64, 0x43, 0xd1, 0xe2, 0x15,
|
||||
0x23, 0x48, 0x51, 0x0e, 0x55, 0xb5, 0x26, 0xb7, 0x19, 0x32, 0x3b, 0x4a,
|
||||
0x2b, 0xbb, 0xcb, 0x90, 0x2e, 0x2d, 0x5c, 0x31, 0x78, 0xfb, 0xa6, 0x2a,
|
||||
0x19, 0x86, 0x2a, 0x4a, 0xcb, 0x93, 0xb8, 0xe9, 0xcb, 0xf0, 0x52, 0xf8,
|
||||
0x0d, 0x8a, 0x8c, 0x56, 0x4c, 0x20, 0x1a, 0x57, 0x22, 0x54, 0xee, 0xdc,
|
||||
0x0d, 0x7a, 0xf6, 0x5a, 0x45, 0x0c, 0x5b, 0xff, 0x86, 0x97, 0x3f, 0xbd,
|
||||
0x2f, 0x7e, 0x7f, 0x4d, 0xda, 0xb3, 0xaf, 0x36, 0x36, 0x4b, 0x0b, 0xbd,
|
||||
0x36, 0x32, 0x77, 0x1e, 0x6b, 0xab, 0x9a, 0xf2, 0x48, 0xb7, 0x55, 0xa4,
|
||||
0xa8, 0xbc, 0x3d, 0xad, 0x8d, 0x15, 0x56, 0x19, 0x1d, 0xb9, 0xf2, 0x1b,
|
||||
0xa6, 0xe9, 0x9b, 0x1b, 0x7e, 0x28, 0xb5, 0x0c, 0x85, 0x95, 0x55, 0xc7,
|
||||
0x8e, 0x7e, 0xb2, 0xb7, 0x4a, 0xbd, 0xa1, 0xdd, 0xd8, 0x0a, 0x17, 0x26,
|
||||
0x0e, 0x03, 0x79, 0xa0, 0xdc, 0x54, 0xc6, 0xff, 0x74, 0xb9, 0x54, 0x17,
|
||||
0x6d, 0x51, 0x44, 0x16, 0xb9, 0x22, 0xfa, 0x90, 0x61, 0xd8, 0xe8, 0x71,
|
||||
0x5c, 0x0c, 0xc3, 0x2e, 0x15, 0x6f, 0x08, 0x5d, 0xe3, 0xa7, 0x7e, 0x5d,
|
||||
0x06, 0x16, 0xcb, 0xf4, 0x21, 0x3c, 0xfa, 0x20, 0x0c, 0xc7, 0x2e, 0x39,
|
||||
0x79, 0x69, 0xa4, 0x1c, 0x8b, 0x22, 0x79, 0x3a, 0x71, 0xb2, 0x8c, 0x6c,
|
||||
0xdf, 0xe2, 0x33, 0xd8, 0x03, 0x39, 0x29, 0x14, 0x68, 0xcf, 0x24, 0xc1,
|
||||
0x7e, 0x5a, 0x40, 0xb1, 0xf3, 0x80, 0xec, 0x00, 0xd9, 0x3c, 0x06, 0x31,
|
||||
0x44, 0xaf, 0x9c, 0x78, 0x3e, 0xb9, 0x01, 0xbc, 0x47, 0xa4, 0xee, 0x13,
|
||||
0xc8, 0xb7, 0x36, 0x8b, 0xe1, 0xae, 0x3f, 0x92, 0xa8, 0x46, 0x31, 0xd6,
|
||||
0x55, 0x7d, 0x23, 0x9f, 0x90, 0xfa, 0x8b, 0xcc, 0xfd, 0x42, 0x76, 0x2a,
|
||||
0xfe, 0x99, 0x88, 0xc6, 0x97, 0x28, 0x26, 0x3e, 0x00, 0x50, 0x4b, 0x03,
|
||||
0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0xfd,
|
||||
0xd1, 0xa0, 0x53, 0xac, 0x00, 0x00, 0x00, 0xd2, 0x00, 0x00, 0x00, 0x3a,
|
||||
0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68,
|
||||
0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61,
|
||||
0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x62, 0x6f, 0x6f,
|
||||
0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x2f, 0x4c, 0x6f, 0x61, 0x64, 0x65,
|
||||
0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2e, 0x63, 0x6c, 0x61, 0x73,
|
||||
0x73, 0x4d, 0x4e, 0x31, 0x0a, 0xc2, 0x40, 0x10, 0x9c, 0xd5, 0x68, 0x34,
|
||||
0x36, 0x5a, 0xf8, 0x07, 0x6d, 0x3c, 0x30, 0xe9, 0xec, 0x04, 0xad, 0x02,
|
||||
0x16, 0x82, 0xfd, 0x26, 0x1e, 0xe7, 0x85, 0x70, 0x17, 0x2e, 0x17, 0x51,
|
||||
0x9f, 0x66, 0xe1, 0x03, 0x7c, 0x94, 0x98, 0x54, 0x3a, 0xc5, 0x0c, 0xcc,
|
||||
0xcc, 0xb2, 0xf3, 0xfe, 0x3c, 0x5f, 0x00, 0x12, 0x4c, 0x42, 0x8c, 0x43,
|
||||
0x44, 0x84, 0xa8, 0xf6, 0xec, 0xfc, 0xce, 0x78, 0x77, 0x27, 0xf4, 0x17,
|
||||
0xcb, 0x53, 0xcb, 0xa5, 0x55, 0x84, 0xf9, 0x22, 0x2d, 0xf8, 0xca, 0xa2,
|
||||
0x64, 0xa3, 0xc4, 0xd1, 0x3b, 0x6d, 0xd4, 0xa6, 0x4b, 0xa3, 0xa3, 0x6d,
|
||||
0x5c, 0x2e, 0xf7, 0xba, 0x94, 0x84, 0x59, 0x6a, 0xf9, 0x2c, 0xdd, 0xd6,
|
||||
0xe9, 0xb3, 0x92, 0xab, 0xae, 0x4f, 0x48, 0x72, 0x23, 0x6e, 0x9a, 0xed,
|
||||
0xe3, 0x62, 0x9b, 0x75, 0x1c, 0x8b, 0xa2, 0xd1, 0xb9, 0x64, 0x25, 0x8d,
|
||||
0x17, 0x5c, 0x69, 0x91, 0x59, 0xeb, 0x6b, 0xef, 0xb8, 0x12, 0xff, 0xb7,
|
||||
0x84, 0xe9, 0xef, 0xdb, 0x21, 0x2b, 0x64, 0xee, 0x87, 0x04, 0x42, 0x0f,
|
||||
0x1d, 0x7a, 0x41, 0xbb, 0x0a, 0x01, 0xd0, 0xea, 0x00, 0xc3, 0xd6, 0x21,
|
||||
0x84, 0x9d, 0x8f, 0xd1, 0x17, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00,
|
||||
0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x7b, 0x04, 0xd3, 0xdd, 0x5f,
|
||||
0x04, 0x00, 0x00, 0xf7, 0x07, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x63,
|
||||
0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33,
|
||||
0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74,
|
||||
0x2f, 0x61, 0x70, 0x69, 0x2f, 0x49, 0x6e, 0x6a, 0x65, 0x63, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73,
|
||||
0x95, 0x55, 0xdd, 0x53, 0x1b, 0x55, 0x14, 0xff, 0xdd, 0x7c, 0xed, 0x66,
|
||||
0x59, 0x08, 0x04, 0x12, 0x1a, 0x11, 0x58, 0x3e, 0xe4, 0x9b, 0xa6, 0x42,
|
||||
0x8d, 0x14, 0x68, 0x2b, 0xa5, 0x50, 0x83, 0x81, 0x62, 0x69, 0xa9, 0x50,
|
||||
0xd4, 0xb9, 0x09, 0x6b, 0x58, 0x58, 0x76, 0xe3, 0x66, 0xc3, 0x50, 0x9f,
|
||||
0xfd, 0x27, 0xfa, 0xe4, 0x8c, 0x2f, 0x99, 0xd1, 0x17, 0x9d, 0x69, 0xc1,
|
||||
0xb1, 0x33, 0xf8, 0xe2, 0xf8, 0xe0, 0xff, 0xe1, 0x83, 0xe3, 0x8c, 0xbe,
|
||||
0xf6, 0x05, 0xf1, 0xdc, 0x4d, 0x94, 0x02, 0x99, 0x61, 0x0c, 0xb9, 0xe7,
|
||||
0xde, 0x73, 0xee, 0x3d, 0xbf, 0xfb, 0x3b, 0x1f, 0x37, 0xfc, 0xfa, 0xf7,
|
||||
0x8f, 0x47, 0x00, 0xae, 0xe3, 0x13, 0x05, 0x09, 0x4c, 0x2b, 0xb8, 0x89,
|
||||
0x5b, 0x12, 0x6e, 0xcb, 0x78, 0x4f, 0x81, 0x1f, 0x33, 0x32, 0xee, 0x08,
|
||||
0xd3, 0xac, 0x8c, 0xbb, 0x12, 0xe6, 0x14, 0x84, 0x31, 0x2d, 0x63, 0x5e,
|
||||
0xcc, 0xf7, 0x84, 0x78, 0x5f, 0x6c, 0xa6, 0x65, 0x74, 0x88, 0x79, 0x41,
|
||||
0x86, 0x26, 0xa3, 0x4b, 0x46, 0x77, 0x18, 0x57, 0xf0, 0x81, 0x10, 0x19,
|
||||
0x21, 0x16, 0x85, 0x58, 0x92, 0x70, 0x5f, 0xc2, 0x32, 0x83, 0xc4, 0x9d,
|
||||
0x7c, 0x71, 0xa9, 0xb4, 0xcb, 0xc0, 0xd2, 0x0c, 0xf5, 0xb3, 0xb6, 0x55,
|
||||
0x74, 0xb9, 0xe5, 0xae, 0x72, 0xb3, 0xa4, 0xfb, 0x89, 0x49, 0x90, 0x8e,
|
||||
0xac, 0xea, 0x4e, 0xd1, 0xb0, 0x2d, 0x86, 0x68, 0x66, 0x9b, 0xef, 0xf1,
|
||||
0xa4, 0xc9, 0xad, 0x7c, 0x72, 0xc5, 0x75, 0x0c, 0x2b, 0x3f, 0xc5, 0xd0,
|
||||
0xb2, 0x50, 0x32, 0x72, 0xfa, 0x4c, 0x5e, 0xb7, 0xdc, 0x99, 0xe5, 0xf4,
|
||||
0x02, 0x77, 0x96, 0xb9, 0xbb, 0xc5, 0xd0, 0x76, 0x6a, 0x5e, 0xe2, 0xae,
|
||||
0xb1, 0xa7, 0x67, 0x8c, 0xac, 0xc3, 0x9d, 0xa7, 0x95, 0x5d, 0xe5, 0x41,
|
||||
0xc9, 0x72, 0x8d, 0x5d, 0xfd, 0xae, 0xe1, 0x30, 0x84, 0xa6, 0x0d, 0xcb,
|
||||
0x70, 0x6f, 0x31, 0xc4, 0x06, 0x2e, 0x5e, 0x30, 0xb8, 0xca, 0x10, 0x98,
|
||||
0xb5, 0x37, 0x75, 0x86, 0x48, 0xc6, 0xb0, 0x74, 0xe2, 0x9a, 0xd5, 0x9d,
|
||||
0x87, 0x3c, 0x6b, 0xea, 0x82, 0x90, 0x9d, 0xe3, 0xe6, 0x2a, 0x77, 0x0c,
|
||||
0xa1, 0x57, 0x8d, 0xbe, 0x9d, 0x3d, 0x86, 0xe6, 0x27, 0xb5, 0xb8, 0xfa,
|
||||
0x29, 0x5a, 0x82, 0x73, 0xb7, 0x8c, 0x22, 0xc3, 0x68, 0x26, 0x67, 0x25,
|
||||
0xf7, 0x0d, 0x6e, 0x7f, 0xb1, 0x65, 0x97, 0xc6, 0xc6, 0xc7, 0x93, 0xdb,
|
||||
0x82, 0x31, 0x17, 0x8c, 0x93, 0xbc, 0x60, 0x24, 0xd3, 0xd6, 0xb6, 0x9e,
|
||||
0x73, 0x29, 0xf0, 0xb4, 0xf5, 0x99, 0x4d, 0xce, 0x75, 0x22, 0x55, 0x9f,
|
||||
0x16, 0x3d, 0x2c, 0x02, 0x11, 0x1a, 0x65, 0x6c, 0xc5, 0xe5, 0xb9, 0x9d,
|
||||
0x45, 0x5e, 0xf0, 0x2e, 0xf7, 0xb2, 0xfa, 0xa1, 0x84, 0x41, 0x8a, 0x30,
|
||||
0xaf, 0xbb, 0xff, 0x25, 0xae, 0x65, 0x60, 0xb0, 0x16, 0x9d, 0xb6, 0x6a,
|
||||
0x16, 0xd2, 0xd6, 0x9e, 0x51, 0x34, 0xc8, 0x7f, 0xc6, 0xb2, 0x6c, 0x97,
|
||||
0x8b, 0x3b, 0x8b, 0x22, 0x38, 0xd3, 0xde, 0xcd, 0xda, 0x3b, 0xc9, 0x7b,
|
||||
0xba, 0xa5, 0x3b, 0xdc, 0xd5, 0x37, 0xc9, 0xa5, 0x95, 0x60, 0x6b, 0x27,
|
||||
0xbc, 0xe3, 0xcc, 0x4e, 0x8d, 0x9c, 0xd7, 0xd3, 0x81, 0xd7, 0xd3, 0xae,
|
||||
0xac, 0xd8, 0x25, 0x27, 0xa7, 0xcf, 0x1b, 0x5e, 0x26, 0xcf, 0x44, 0x7b,
|
||||
0x55, 0x90, 0x55, 0xd1, 0x83, 0x07, 0x14, 0x8e, 0x8a, 0x15, 0x3c, 0x64,
|
||||
0xe8, 0x3e, 0x0d, 0x20, 0x6d, 0x9a, 0x7a, 0x9e, 0x9b, 0x33, 0x4e, 0xbe,
|
||||
0xb4, 0x4b, 0x77, 0xcd, 0xed, 0xe7, 0xf4, 0x82, 0xeb, 0x05, 0xda, 0xf3,
|
||||
0x5a, 0x8e, 0xb4, 0x1c, 0x17, 0xe1, 0x68, 0x59, 0x5d, 0xb3, 0x4a, 0xa6,
|
||||
0xa9, 0xd9, 0x8e, 0xa6, 0xef, 0x16, 0xdc, 0xa7, 0x02, 0xb7, 0x97, 0xfa,
|
||||
0x6d, 0x4a, 0xc5, 0x23, 0x50, 0x75, 0xd9, 0x4d, 0x0a, 0xeb, 0x7c, 0x76,
|
||||
0xee, 0x94, 0x0c, 0x73, 0x53, 0x77, 0x3c, 0x62, 0x7b, 0xdc, 0x34, 0x36,
|
||||
0x35, 0x5e, 0xbd, 0x6d, 0x52, 0x53, 0xf1, 0x18, 0x1f, 0xa9, 0x58, 0xc3,
|
||||
0x75, 0x15, 0xeb, 0x78, 0xa2, 0x62, 0x03, 0x1f, 0xab, 0xe8, 0x40, 0xa7,
|
||||
0x0a, 0x4d, 0x88, 0x2e, 0x21, 0xba, 0xd1, 0xc9, 0x30, 0xfc, 0x3f, 0x2a,
|
||||
0xcc, 0xd0, 0x78, 0x4a, 0xe2, 0x7e, 0x56, 0xec, 0x9c, 0x31, 0xad, 0x54,
|
||||
0x0b, 0xef, 0x1f, 0x10, 0x2d, 0x29, 0x19, 0xc5, 0x39, 0x11, 0x8c, 0xa7,
|
||||
0xaf, 0x33, 0x04, 0x8b, 0x05, 0xd3, 0x20, 0x87, 0xfe, 0x5a, 0x2d, 0x5c,
|
||||
0xb3, 0x17, 0x43, 0xbc, 0x50, 0xd0, 0xad, 0x4d, 0xea, 0xc3, 0x5a, 0x2e,
|
||||
0x17, 0x4c, 0xd5, 0x84, 0x90, 0xa3, 0xec, 0xda, 0xff, 0x72, 0x91, 0xb7,
|
||||
0x78, 0x71, 0xab, 0xf2, 0x38, 0x88, 0x06, 0x3d, 0xe0, 0x90, 0xfe, 0x79,
|
||||
0x89, 0x9b, 0xc5, 0x73, 0x4f, 0xa9, 0x12, 0xcd, 0xd4, 0xe0, 0x3a, 0xa5,
|
||||
0xe6, 0x0a, 0xfd, 0xae, 0xd0, 0xb3, 0xc6, 0x1b, 0xf4, 0xd7, 0x06, 0x86,
|
||||
0x37, 0x49, 0xf3, 0xa1, 0x9d, 0x06, 0x25, 0xd0, 0x5b, 0x6b, 0xd5, 0xb9,
|
||||
0xab, 0x3a, 0x77, 0x7b, 0x73, 0x90, 0xce, 0x52, 0xdd, 0x48, 0xbe, 0x45,
|
||||
0x46, 0x0d, 0x01, 0x28, 0x00, 0x1b, 0x1e, 0x3a, 0x24, 0xf1, 0x0b, 0x94,
|
||||
0xe1, 0x03, 0xf8, 0x9e, 0xa1, 0xfe, 0x25, 0xfc, 0x6b, 0xd1, 0xc0, 0x21,
|
||||
0x82, 0x3f, 0x0d, 0x47, 0x43, 0x07, 0x90, 0x16, 0x47, 0x96, 0x46, 0x8f,
|
||||
0x52, 0x01, 0x7f, 0x2a, 0x18, 0x0b, 0xc6, 0x02, 0x5f, 0xe3, 0x78, 0x34,
|
||||
0x16, 0x1c, 0x9b, 0x0c, 0x25, 0x42, 0x51, 0x99, 0x76, 0x27, 0xa5, 0x84,
|
||||
0x74, 0x14, 0xfc, 0x0a, 0x9d, 0xc2, 0xed, 0x25, 0xc2, 0x6b, 0x87, 0x50,
|
||||
0xa2, 0x75, 0x07, 0x50, 0x13, 0xe4, 0xab, 0x1e, 0xa0, 0x5e, 0x00, 0x25,
|
||||
0x24, 0xff, 0xd8, 0xa4, 0xec, 0x4b, 0x85, 0x13, 0xe4, 0xd2, 0xf0, 0x2d,
|
||||
0xbc, 0x8f, 0x41, 0x23, 0x10, 0xde, 0xf8, 0xeb, 0x67, 0x9a, 0x33, 0xf3,
|
||||
0x4d, 0x13, 0x7f, 0xd0, 0x3c, 0xfd, 0x78, 0xfa, 0xf7, 0x17, 0x34, 0x6f,
|
||||
0xec, 0x8f, 0x3e, 0xff, 0x81, 0xe6, 0x91, 0x84, 0x1c, 0x8d, 0x1c, 0xa0,
|
||||
0xf1, 0x19, 0x52, 0xfe, 0x54, 0xb8, 0x8c, 0x6b, 0xa4, 0x37, 0x79, 0x7a,
|
||||
0x5f, 0x40, 0xe8, 0x1a, 0xe9, 0x51, 0x4f, 0x8f, 0x07, 0x85, 0xde, 0x48,
|
||||
0x7a, 0xb3, 0xa7, 0x87, 0x42, 0xa9, 0x70, 0x2c, 0xfc, 0x0d, 0x61, 0xa4,
|
||||
0x2b, 0xd7, 0x41, 0xfc, 0x14, 0xb6, 0xd3, 0x18, 0xa0, 0x31, 0x4e, 0xe3,
|
||||
0xd6, 0x50, 0x42, 0x0a, 0x8c, 0xbd, 0x40, 0x4b, 0x19, 0xbd, 0xd5, 0x65,
|
||||
0xac, 0x8c, 0x44, 0x75, 0x19, 0x2f, 0xa3, 0xa1, 0xba, 0x6c, 0x2d, 0xc3,
|
||||
0xff, 0x65, 0x90, 0x95, 0x4f, 0x7c, 0xdf, 0x7b, 0x30, 0x7d, 0x24, 0x97,
|
||||
0xd0, 0x4c, 0xb2, 0x91, 0x52, 0xd8, 0x84, 0x08, 0xa2, 0x54, 0x90, 0x18,
|
||||
0x25, 0x3d, 0x8e, 0x14, 0x5a, 0x71, 0x9b, 0x0a, 0x34, 0x4f, 0x96, 0x2c,
|
||||
0x15, 0xe7, 0x15, 0xda, 0x19, 0xd0, 0xc1, 0xfc, 0xd0, 0x58, 0x1d, 0xba,
|
||||
0x58, 0x03, 0x7a, 0x58, 0x9c, 0x9e, 0x4e, 0x02, 0x7d, 0xac, 0x0b, 0xfd,
|
||||
0xac, 0x17, 0x71, 0x36, 0x84, 0x11, 0xf4, 0x7b, 0xff, 0x31, 0x82, 0xe4,
|
||||
0xfb, 0x1b, 0x11, 0x1c, 0x84, 0x44, 0x48, 0x7f, 0x62, 0x88, 0xca, 0x16,
|
||||
0x12, 0x25, 0xc2, 0x30, 0x9d, 0x81, 0xb7, 0x1a, 0x25, 0x1b, 0xf3, 0xd0,
|
||||
0xae, 0xd2, 0x39, 0x1f, 0x92, 0x64, 0x7e, 0x84, 0xc8, 0x09, 0xd1, 0xf0,
|
||||
0x49, 0xb8, 0x26, 0xe1, 0x6d, 0x20, 0x2c, 0xb4, 0x50, 0x45, 0x93, 0x30,
|
||||
0x46, 0x5f, 0x46, 0x2c, 0x8e, 0x31, 0x51, 0xd1, 0x8f, 0x71, 0x83, 0x16,
|
||||
0x2c, 0x12, 0x89, 0xa8, 0x1d, 0x8a, 0xa2, 0x9c, 0x50, 0x1b, 0x5c, 0x38,
|
||||
0xfc, 0xca, 0xeb, 0x96, 0x71, 0x22, 0xe5, 0x13, 0xdd, 0x42, 0xd7, 0xd0,
|
||||
0x2b, 0x17, 0x3d, 0x34, 0xf4, 0x1c, 0x2d, 0xdf, 0x79, 0x4d, 0x25, 0xf2,
|
||||
0x10, 0xf2, 0x8c, 0x75, 0x1e, 0x7f, 0xb5, 0x72, 0xa0, 0xca, 0xf5, 0x9d,
|
||||
0xea, 0x6e, 0x4a, 0xd0, 0xc6, 0xbb, 0x35, 0x81, 0x62, 0xe7, 0x81, 0xd4,
|
||||
0x4b, 0x81, 0x26, 0x6a, 0x02, 0xc5, 0xcf, 0x03, 0xd5, 0x5f, 0x0a, 0x74,
|
||||
0xa3, 0x26, 0x50, 0xeb, 0x79, 0xa0, 0x86, 0x4b, 0x81, 0x26, 0x3d, 0x8f,
|
||||
0xa9, 0x7f, 0x00, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08,
|
||||
0x00, 0xdd, 0x72, 0x95, 0x5c, 0x40, 0xc9, 0x71, 0xc0, 0x05, 0x02, 0x00,
|
||||
0x00, 0xae, 0x04, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f,
|
||||
0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f,
|
||||
0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x2f, 0x4a, 0x75, 0x69, 0x63, 0x65, 0x41, 0x67, 0x65, 0x6e,
|
||||
0x74, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x95, 0x53, 0x4d, 0x6f, 0xd3,
|
||||
0x40, 0x10, 0x9d, 0x6d, 0xd3, 0x84, 0xa4, 0x6d, 0x12, 0x9a, 0x26, 0x29,
|
||||
0xa5, 0x50, 0x0a, 0x14, 0xec, 0x50, 0x61, 0x89, 0x72, 0x6b, 0x55, 0x89,
|
||||
0x54, 0x42, 0x02, 0x59, 0xe5, 0x90, 0xaa, 0x87, 0xe6, 0xb4, 0xb1, 0xb7,
|
||||
0xce, 0x46, 0x89, 0xb7, 0x5a, 0xaf, 0x11, 0xe5, 0x5f, 0x71, 0x42, 0xe2,
|
||||
0xc0, 0x0f, 0xe0, 0x47, 0x21, 0x66, 0xb7, 0xae, 0x93, 0x38, 0x3e, 0x14,
|
||||
0x1f, 0x76, 0xf6, 0xbd, 0x99, 0x79, 0xf3, 0x21, 0xef, 0x9f, 0xbf, 0xbf,
|
||||
0x7e, 0x03, 0xc0, 0x7b, 0x38, 0xa8, 0xc0, 0x32, 0xd8, 0x25, 0xe8, 0x94,
|
||||
0xe0, 0x0d, 0x81, 0xe2, 0x31, 0x0f, 0xb9, 0x3a, 0x21, 0xb0, 0x6c, 0xd9,
|
||||
0x17, 0x04, 0x0a, 0xa7, 0xc2, 0x67, 0x04, 0x6a, 0x2e, 0x0f, 0xd9, 0x59,
|
||||
0x3c, 0x19, 0x30, 0x79, 0x4e, 0x07, 0x63, 0x64, 0x36, 0x5c, 0xe1, 0xd1,
|
||||
0xf1, 0x05, 0x95, 0x5c, 0xe3, 0x84, 0x2c, 0xa8, 0x21, 0x8f, 0x08, 0x74,
|
||||
0x5c, 0x2f, 0x74, 0xbe, 0x71, 0x2a, 0xbe, 0x0f, 0x45, 0xfc, 0xee, 0xf0,
|
||||
0xd0, 0x19, 0xc5, 0xdc, 0x63, 0x34, 0x60, 0xa1, 0x72, 0xe8, 0x35, 0x77,
|
||||
0x3e, 0x6b, 0xf8, 0x41, 0xc3, 0x23, 0xcc, 0xd1, 0xf5, 0x08, 0x34, 0x2d,
|
||||
0x77, 0x44, 0xbf, 0x52, 0x67, 0x4c, 0xc3, 0xc0, 0xe9, 0x29, 0xc9, 0xc3,
|
||||
0xe0, 0xc8, 0xbe, 0x24, 0xb0, 0x4b, 0x7d, 0xff, 0x5c, 0x74, 0x85, 0x50,
|
||||
0x91, 0x92, 0xf4, 0xfa, 0x74, 0x4c, 0xa3, 0xc8, 0x15, 0xd4, 0x67, 0xb2,
|
||||
0xc7, 0xa8, 0xf4, 0x86, 0x04, 0x76, 0x4c, 0x44, 0xef, 0x26, 0x52, 0x6c,
|
||||
0x92, 0xe3, 0xae, 0x1b, 0xf7, 0x8c, 0x83, 0xc0, 0x41, 0x4e, 0xad, 0x19,
|
||||
0x66, 0x26, 0xd6, 0xb4, 0xb0, 0xea, 0xb3, 0x2b, 0x1c, 0xdf, 0xd0, 0x99,
|
||||
0xe4, 0xd9, 0xd0, 0x7e, 0xd7, 0xce, 0x7a, 0x70, 0xbc, 0x72, 0x8f, 0x07,
|
||||
0x21, 0x55, 0xb1, 0xc4, 0xf5, 0x38, 0xff, 0x91, 0x7a, 0xdc, 0x39, 0xc1,
|
||||
0xec, 0x75, 0xc9, 0xe6, 0x8a, 0xb7, 0x17, 0x14, 0x30, 0xf7, 0x93, 0x6e,
|
||||
0x72, 0x7b, 0xc1, 0xa3, 0x15, 0x12, 0x67, 0x63, 0x4e, 0xa6, 0x7b, 0x73,
|
||||
0x46, 0x27, 0xd8, 0xce, 0x56, 0xce, 0x1a, 0x92, 0x84, 0xba, 0x64, 0xb8,
|
||||
0xed, 0x30, 0xba, 0x12, 0x72, 0x92, 0x94, 0x6e, 0x65, 0xa9, 0x3b, 0x99,
|
||||
0x7a, 0xc0, 0x94, 0x99, 0xc3, 0x37, 0x34, 0xc3, 0xd8, 0x4d, 0xcb, 0xee,
|
||||
0xe7, 0xec, 0xa2, 0x9d, 0x43, 0xdf, 0xce, 0x59, 0x45, 0x8d, 0x39, 0xd1,
|
||||
0xfd, 0xbc, 0xdf, 0x21, 0x47, 0xd2, 0xba, 0x4f, 0x5c, 0xb2, 0xcb, 0x69,
|
||||
0x0d, 0xa5, 0x9b, 0x6c, 0x2e, 0xee, 0xd2, 0xee, 0x77, 0x33, 0x6b, 0x49,
|
||||
0xf3, 0x8d, 0xab, 0x31, 0x27, 0x71, 0xd7, 0x6b, 0x2b, 0xaf, 0x07, 0x1d,
|
||||
0x5e, 0xe9, 0x89, 0x58, 0x7a, 0xec, 0x23, 0xd7, 0x6f, 0xa3, 0x36, 0xfd,
|
||||
0xeb, 0xdf, 0xea, 0xf0, 0x35, 0x28, 0xc0, 0x0a, 0x0e, 0x70, 0xdf, 0xa7,
|
||||
0x82, 0x8b, 0x9e, 0x56, 0xf9, 0x32, 0x18, 0x31, 0x4f, 0xc1, 0x1e, 0x2c,
|
||||
0xe1, 0xdb, 0xd5, 0x5f, 0x15, 0x88, 0xd6, 0xc3, 0xb3, 0x88, 0xc8, 0x41,
|
||||
0x4b, 0xd0, 0xae, 0x74, 0x7e, 0x02, 0xf9, 0x81, 0x97, 0x25, 0x28, 0xe1,
|
||||
0x59, 0x34, 0x64, 0x01, 0x1e, 0xe0, 0xb9, 0x76, 0x1b, 0x00, 0x65, 0xa8,
|
||||
0x00, 0x90, 0x32, 0xac, 0x22, 0xa3, 0xed, 0x7a, 0x62, 0xab, 0x89, 0xad,
|
||||
0x41, 0xdd, 0xd8, 0x87, 0xb0, 0x81, 0x19, 0x0d, 0xa3, 0xb5, 0x89, 0xb8,
|
||||
0x09, 0xad, 0x14, 0xb7, 0x11, 0x6f, 0xc1, 0x23, 0x13, 0xb7, 0x9d, 0xe1,
|
||||
0x1f, 0x27, 0xfc, 0x0e, 0x3c, 0x49, 0xf9, 0xa7, 0x88, 0x77, 0xe1, 0x59,
|
||||
0x8a, 0xf7, 0x10, 0x3f, 0x87, 0x17, 0x29, 0x7e, 0x89, 0x78, 0x1f, 0x5e,
|
||||
0xe1, 0x9d, 0xc0, 0x6b, 0xc3, 0x58, 0xff, 0x00, 0x50, 0x4b, 0x03, 0x04,
|
||||
0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x09, 0xad,
|
||||
0xfd, 0x53, 0x35, 0x02, 0x00, 0x00, 0x34, 0x04, 0x00, 0x00, 0x39, 0x00,
|
||||
0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f,
|
||||
0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67,
|
||||
0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x4a, 0x75, 0x69, 0x63,
|
||||
0x65, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74,
|
||||
0x72, 0x61, 0x70, 0x24, 0x31, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x9d,
|
||||
0x53, 0x5b, 0x6f, 0x12, 0x41, 0x14, 0xfe, 0xa6, 0x5c, 0x16, 0x70, 0x6d,
|
||||
0x2b, 0xbd, 0x50, 0xaf, 0x05, 0xa5, 0x0a, 0xd4, 0x76, 0x4b, 0xa1, 0xf6,
|
||||
0x01, 0x63, 0x62, 0x9b, 0x36, 0xd1, 0xe0, 0x25, 0x62, 0x9a, 0x18, 0xe3,
|
||||
0xc3, 0x00, 0x13, 0x18, 0xb2, 0xec, 0x90, 0xdd, 0xc1, 0x58, 0xff, 0x95,
|
||||
0x3e, 0xd0, 0x44, 0x13, 0x7f, 0x80, 0x3f, 0xca, 0x78, 0x06, 0xb0, 0x58,
|
||||
0x21, 0x26, 0xfa, 0x30, 0x73, 0xee, 0xdf, 0x7c, 0x73, 0xce, 0xcc, 0xf7,
|
||||
0x1f, 0x5f, 0xbe, 0x01, 0x28, 0x63, 0x3f, 0x81, 0x4b, 0x58, 0x8f, 0x23,
|
||||
0x8d, 0x4c, 0x0c, 0xb7, 0x13, 0xb8, 0x83, 0xac, 0x85, 0x8d, 0x04, 0x22,
|
||||
0x58, 0x8f, 0xe1, 0xae, 0x91, 0xf7, 0xcc, 0x96, 0xb3, 0x90, 0xb7, 0x50,
|
||||
0xb0, 0xb0, 0xc9, 0x10, 0x7d, 0x28, 0x3d, 0xa9, 0x1f, 0x31, 0x84, 0x72,
|
||||
0xf9, 0x13, 0x86, 0xf0, 0xa1, 0x6a, 0x0a, 0x86, 0x85, 0xaa, 0xf4, 0xc4,
|
||||
0xf3, 0x7e, 0xb7, 0x2e, 0xfc, 0xd7, 0xbc, 0xee, 0x92, 0x27, 0x59, 0x55,
|
||||
0x0d, 0xee, 0x9e, 0x70, 0x5f, 0x1a, 0x7b, 0xec, 0x0c, 0xeb, 0xb6, 0x0c,
|
||||
0x18, 0xec, 0x27, 0x9e, 0x27, 0xfc, 0x43, 0x97, 0x07, 0x81, 0x20, 0x73,
|
||||
0xaf, 0xda, 0xf0, 0x9c, 0x0f, 0x92, 0xab, 0x8f, 0x6d, 0xd5, 0xdf, 0x2d,
|
||||
0x95, 0x9c, 0x4e, 0x5f, 0x36, 0x04, 0x6f, 0x09, 0x4f, 0x3b, 0xbc, 0x27,
|
||||
0x9d, 0xa7, 0xc6, 0x7c, 0x6c, 0xcc, 0x03, 0xa5, 0x74, 0xa0, 0x7d, 0xde,
|
||||
0xcb, 0x16, 0x2b, 0x0c, 0x89, 0x40, 0x73, 0x5f, 0x1f, 0x79, 0xda, 0x3f,
|
||||
0x25, 0x3a, 0xae, 0x6a, 0x31, 0xac, 0xe4, 0xaa, 0x1d, 0xfe, 0x9e, 0x3b,
|
||||
0x2e, 0xf7, 0x5a, 0x4e, 0x4d, 0xfb, 0xd2, 0x6b, 0x55, 0x0c, 0x4d, 0x16,
|
||||
0x18, 0x46, 0x53, 0x21, 0xc2, 0xa8, 0xa9, 0xbe, 0xdf, 0x10, 0xc7, 0xd2,
|
||||
0xd0, 0x5b, 0x9b, 0x71, 0xd2, 0xb6, 0x29, 0xa2, 0x0b, 0x1e, 0x79, 0x0d,
|
||||
0x57, 0x05, 0x54, 0xf4, 0x4c, 0xe8, 0xb6, 0x6a, 0x5a, 0xb8, 0x6f, 0x63,
|
||||
0x0b, 0x29, 0x1b, 0x97, 0x31, 0x6f, 0x61, 0xdb, 0x86, 0x83, 0x1d, 0x86,
|
||||
0xf4, 0xdb, 0x21, 0x44, 0x55, 0xf1, 0xa6, 0xf0, 0xdf, 0xa5, 0x27, 0x04,
|
||||
0xd3, 0xd4, 0x0c, 0x57, 0x34, 0x33, 0x16, 0x8a, 0x36, 0x76, 0x91, 0x62,
|
||||
0x48, 0xfd, 0xc9, 0xe6, 0xa0, 0x2f, 0x5d, 0xaa, 0x62, 0x98, 0xbf, 0x08,
|
||||
0x62, 0xa3, 0x84, 0xb2, 0x8d, 0x3d, 0x3c, 0x60, 0x28, 0xfd, 0x47, 0xa7,
|
||||
0x18, 0x16, 0x27, 0x47, 0xbd, 0xa8, 0x77, 0x44, 0x43, 0x33, 0x94, 0xff,
|
||||
0x0e, 0x54, 0xff, 0x55, 0xee, 0x8c, 0x58, 0x1c, 0xf8, 0xb2, 0xd9, 0xa2,
|
||||
0x0e, 0x15, 0xff, 0xf9, 0x7c, 0x86, 0xc8, 0xb0, 0x0b, 0x17, 0x58, 0xd4,
|
||||
0x4e, 0x03, 0x2d, 0xba, 0x34, 0x34, 0xd5, 0xa7, 0xc0, 0xca, 0x68, 0x30,
|
||||
0x52, 0x39, 0x2f, 0xa9, 0x0f, 0x9a, 0xba, 0x21, 0x78, 0x97, 0x66, 0xb3,
|
||||
0x34, 0xc3, 0xcd, 0x60, 0xf5, 0x8c, 0xe5, 0x7a, 0xf4, 0x14, 0x79, 0xaf,
|
||||
0x27, 0xbc, 0x26, 0xc3, 0xd6, 0xac, 0xa9, 0x4f, 0xb9, 0xc6, 0xfd, 0x25,
|
||||
0xe0, 0x98, 0x56, 0x23, 0x17, 0xc3, 0x72, 0x6e, 0x3a, 0xb1, 0x82, 0x1d,
|
||||
0x98, 0x8f, 0x41, 0x0f, 0x95, 0x7e, 0x49, 0x88, 0x16, 0xcd, 0x98, 0xac,
|
||||
0x05, 0xd2, 0x1c, 0x92, 0x8c, 0x64, 0xa4, 0x70, 0x06, 0xf6, 0x89, 0x94,
|
||||
0x39, 0x2c, 0xd2, 0x1e, 0x1d, 0x3a, 0x33, 0xb8, 0x42, 0xbb, 0x3d, 0x4a,
|
||||
0x40, 0x12, 0xcb, 0x24, 0xe9, 0x7a, 0xe7, 0xc5, 0xfb, 0x94, 0x6d, 0x62,
|
||||
0xf1, 0xcf, 0x98, 0x4b, 0x86, 0x06, 0x08, 0x4f, 0x00, 0x12, 0x24, 0x81,
|
||||
0x2c, 0x62, 0xd8, 0xf8, 0x0d, 0x24, 0x7e, 0x0e, 0xb2, 0x8a, 0xd4, 0x18,
|
||||
0xe4, 0x15, 0x31, 0x32, 0xb9, 0xd7, 0x08, 0xe4, 0x2b, 0x22, 0x6f, 0xce,
|
||||
0x10, 0x4d, 0x5a, 0x03, 0xc4, 0x36, 0x69, 0x0d, 0x10, 0x9f, 0x81, 0x9a,
|
||||
0xc7, 0x55, 0x14, 0x86, 0xa8, 0xab, 0xa3, 0xca, 0x31, 0xaa, 0xd1, 0xd6,
|
||||
0x28, 0x46, 0x73, 0x20, 0xcd, 0xd4, 0x5c, 0xc7, 0x0d, 0x92, 0x61, 0xdc,
|
||||
0xc4, 0x2d, 0x2c, 0x0d, 0xeb, 0xe9, 0x87, 0x0c, 0x33, 0x63, 0x3f, 0x01,
|
||||
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72,
|
||||
0x95, 0x5c, 0x8f, 0x63, 0xf6, 0x0e, 0x07, 0x04, 0x00, 0x00, 0x35, 0x08,
|
||||
0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61,
|
||||
0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69,
|
||||
0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f,
|
||||
0x4a, 0x75, 0x69, 0x63, 0x65, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x6f,
|
||||
0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x2e, 0x63, 0x6c, 0x61, 0x73,
|
||||
0x73, 0x95, 0x55, 0x5f, 0x53, 0x1b, 0x55, 0x14, 0xff, 0x5d, 0x02, 0x6c,
|
||||
0x58, 0x96, 0x42, 0x03, 0x15, 0x8a, 0x82, 0x0b, 0x56, 0x4d, 0x0b, 0x6d,
|
||||
0xa4, 0x54, 0x4b, 0xa1, 0x45, 0x81, 0xb6, 0x1a, 0x0c, 0x14, 0x9b, 0x8a,
|
||||
0xa6, 0xb5, 0xd6, 0x9b, 0xe4, 0x12, 0x2e, 0x5d, 0x76, 0xe3, 0xee, 0x0d,
|
||||
0x43, 0xfb, 0xe6, 0xa3, 0x1f, 0xa0, 0x0f, 0xf6, 0xb5, 0x9f, 0xa0, 0x3e,
|
||||
0x00, 0x53, 0x66, 0xea, 0xf8, 0xe6, 0xf8, 0xe8, 0xb3, 0xe3, 0xa3, 0x7e,
|
||||
0x0a, 0x1d, 0xcf, 0xdd, 0x4d, 0x09, 0x90, 0xd8, 0xca, 0x66, 0xe6, 0x9e,
|
||||
0x9c, 0x73, 0x7e, 0xe7, 0x9c, 0x3d, 0xff, 0xee, 0xfe, 0xfa, 0xcf, 0xb3,
|
||||
0xe7, 0x00, 0x2e, 0xc0, 0x37, 0x31, 0x8c, 0x09, 0x03, 0x97, 0x4c, 0x34,
|
||||
0x61, 0xb2, 0x0d, 0x53, 0xb8, 0x1c, 0xc7, 0x15, 0x13, 0xd3, 0xf8, 0xd0,
|
||||
0xc0, 0x47, 0x26, 0x0c, 0x4c, 0xc4, 0x31, 0xa3, 0xe9, 0xac, 0x46, 0xcc,
|
||||
0xe9, 0x7f, 0x57, 0xe3, 0xb8, 0xa6, 0x99, 0xeb, 0x71, 0x7c, 0xac, 0xe9,
|
||||
0x27, 0x71, 0xa4, 0x35, 0x9d, 0x37, 0xf0, 0xa9, 0x89, 0x6e, 0x4c, 0xea,
|
||||
0x23, 0xa3, 0x8f, 0x05, 0x03, 0x8b, 0x71, 0xdc, 0x30, 0xd1, 0x1b, 0x09,
|
||||
0x97, 0x4c, 0x0a, 0xf0, 0x99, 0x89, 0x9b, 0xc8, 0xc6, 0x71, 0xcb, 0xc0,
|
||||
0xe7, 0x26, 0x06, 0x31, 0x61, 0x62, 0x19, 0x5f, 0x18, 0xf8, 0xd2, 0x40,
|
||||
0x8e, 0xc1, 0x4a, 0xbb, 0xae, 0xf0, 0xe7, 0x1c, 0x1e, 0x04, 0x22, 0x60,
|
||||
0x68, 0xbd, 0x2c, 0x5d, 0xa9, 0xa6, 0x19, 0x62, 0xc9, 0xd3, 0xcb, 0x0c,
|
||||
0xcd, 0x73, 0x5e, 0x51, 0x30, 0x74, 0x66, 0xa4, 0x2b, 0x16, 0x2b, 0xeb,
|
||||
0x79, 0xe1, 0xdf, 0xe2, 0x79, 0x87, 0x24, 0x89, 0x8c, 0x57, 0xe0, 0xce,
|
||||
0x32, 0xf7, 0xa5, 0xe6, 0xab, 0xc2, 0x66, 0xb5, 0x2a, 0xc9, 0xc7, 0x78,
|
||||
0xa6, 0xe0, 0xa6, 0x36, 0x25, 0xf7, 0x1e, 0xae, 0x7a, 0x95, 0xf3, 0xe3,
|
||||
0xe3, 0xa9, 0xb5, 0x8a, 0x2c, 0x08, 0x5e, 0x12, 0xae, 0x4a, 0xf1, 0xb2,
|
||||
0x4c, 0xcd, 0x6b, 0x76, 0x46, 0xb3, 0xb3, 0x9e, 0xa7, 0x02, 0xe5, 0xf3,
|
||||
0xf2, 0x14, 0x43, 0x4b, 0xa0, 0xb8, 0xaf, 0x18, 0x4e, 0x24, 0x33, 0x6b,
|
||||
0x7c, 0x83, 0xa7, 0x1c, 0xee, 0x96, 0x52, 0x59, 0xe5, 0x4b, 0xb7, 0x34,
|
||||
0xa5, 0x5f, 0xa5, 0x9d, 0xfb, 0xa5, 0xe0, 0x5e, 0x10, 0x0a, 0x74, 0xfc,
|
||||
0x3a, 0x10, 0xc5, 0x97, 0xee, 0x8a, 0xc7, 0x70, 0xf6, 0x15, 0xf1, 0xd3,
|
||||
0xee, 0x9a, 0x28, 0x28, 0xe9, 0xb9, 0x69, 0x82, 0x93, 0x99, 0xe1, 0xc8,
|
||||
0xbc, 0xcf, 0xfd, 0x07, 0x0c, 0xc7, 0x22, 0xaf, 0xd2, 0x4b, 0x5d, 0x97,
|
||||
0x8e, 0x20, 0x55, 0x47, 0x56, 0xf1, 0xc2, 0xfd, 0x05, 0x5e, 0x0e, 0x33,
|
||||
0xa4, 0xb6, 0x51, 0xc9, 0x19, 0xcc, 0xac, 0x57, 0xf1, 0x0b, 0x42, 0x63,
|
||||
0x18, 0xfa, 0x1a, 0xa4, 0x73, 0x4e, 0xbb, 0xb1, 0x70, 0x0a, 0x6f, 0x33,
|
||||
0x8c, 0x1c, 0xe1, 0x65, 0xb4, 0xc9, 0xa8, 0x81, 0xdb, 0x16, 0xee, 0xe0,
|
||||
0x2b, 0x86, 0xe1, 0x3b, 0x35, 0xdf, 0xf6, 0xcc, 0x52, 0xfa, 0xae, 0x7d,
|
||||
0xe5, 0xf0, 0x63, 0xe0, 0xae, 0x85, 0xaf, 0x31, 0xca, 0xd0, 0x7b, 0xb8,
|
||||
0x20, 0xb3, 0x15, 0xe9, 0x14, 0x85, 0xdf, 0xc8, 0xcd, 0x9c, 0xe7, 0xae,
|
||||
0xc8, 0x92, 0xbd, 0x2c, 0xfc, 0x80, 0x22, 0xdb, 0x93, 0xb6, 0x85, 0x7b,
|
||||
0xf8, 0xc6, 0x02, 0x47, 0xde, 0x42, 0x01, 0x79, 0x86, 0x64, 0x9d, 0x4d,
|
||||
0x8d, 0x27, 0x76, 0x9e, 0xfb, 0x4b, 0x5c, 0xad, 0x86, 0x96, 0x45, 0x8d,
|
||||
0x4f, 0xbd, 0x04, 0xbf, 0xc8, 0x95, 0xdc, 0x10, 0x99, 0xa8, 0xc8, 0x7b,
|
||||
0x66, 0x42, 0x9b, 0x0d, 0xd6, 0x99, 0xdd, 0xac, 0xb8, 0x4a, 0xae, 0x8b,
|
||||
0xab, 0xd2, 0x0f, 0x51, 0x2b, 0x1a, 0x65, 0xed, 0xef, 0x8a, 0x85, 0x12,
|
||||
0x56, 0x2d, 0x48, 0xac, 0x32, 0xf4, 0xd7, 0x72, 0xae, 0xda, 0x5d, 0xdb,
|
||||
0x2c, 0x88, 0xb2, 0x2e, 0x27, 0xc3, 0xd0, 0x3e, 0xd7, 0xd5, 0x0e, 0xdb,
|
||||
0xae, 0xa7, 0xec, 0x15, 0xaf, 0xe2, 0x16, 0x6d, 0xae, 0xb4, 0xfb, 0x35,
|
||||
0x9d, 0xf0, 0x7d, 0x5d, 0x73, 0xc7, 0xc2, 0x3a, 0x0e, 0x59, 0xe9, 0x55,
|
||||
0x90, 0xdc, 0x91, 0x0f, 0xb9, 0xf6, 0x68, 0xaf, 0x70, 0x0a, 0x5f, 0x1c,
|
||||
0xa2, 0x01, 0x3f, 0xf2, 0x7c, 0x9f, 0x1a, 0x33, 0x40, 0xdd, 0x2d, 0xe3,
|
||||
0x5b, 0x86, 0xb1, 0x23, 0x5b, 0x33, 0x74, 0xd5, 0x12, 0xbd, 0x91, 0xd7,
|
||||
0x03, 0x73, 0x40, 0x94, 0x7d, 0x10, 0x28, 0xb1, 0x4e, 0x3b, 0xeb, 0x55,
|
||||
0xf4, 0x02, 0xed, 0x0d, 0xf1, 0x12, 0x8d, 0x81, 0xa2, 0x61, 0x10, 0x7c,
|
||||
0x9d, 0x66, 0xb9, 0xbb, 0x81, 0x98, 0x86, 0xbf, 0xac, 0x39, 0x87, 0x32,
|
||||
0x6f, 0xe5, 0xe5, 0xb2, 0x70, 0x8b, 0xb4, 0x3f, 0x8d, 0x36, 0xb0, 0x4e,
|
||||
0x54, 0x1d, 0x2f, 0x72, 0x6c, 0x96, 0x84, 0xaa, 0x8e, 0x12, 0x43, 0x4f,
|
||||
0xb2, 0x1e, 0x4a, 0x98, 0xb8, 0xf2, 0xb2, 0xd5, 0xd5, 0xed, 0x25, 0x78,
|
||||
0xa3, 0x61, 0xa2, 0x69, 0x38, 0xa0, 0xa9, 0x1b, 0x1b, 0x5a, 0x47, 0x02,
|
||||
0xd4, 0x06, 0x84, 0x5e, 0x59, 0x6c, 0xca, 0x40, 0x05, 0xe1, 0x6d, 0x75,
|
||||
0x9b, 0x58, 0x19, 0x44, 0x3b, 0xd9, 0x49, 0xb8, 0x99, 0x7c, 0xe0, 0x39,
|
||||
0x15, 0x25, 0x22, 0xcb, 0x66, 0xc7, 0xe3, 0x94, 0x5a, 0xf2, 0xff, 0xd6,
|
||||
0x3e, 0xbc, 0x4c, 0xe4, 0x7f, 0x5d, 0x47, 0x14, 0xeb, 0xe2, 0xcb, 0x3d,
|
||||
0xe5, 0x5f, 0xf4, 0x2e, 0xb5, 0xd7, 0xc5, 0x59, 0x5f, 0x16, 0x4b, 0xf4,
|
||||
0x72, 0xed, 0x81, 0x50, 0x4b, 0xbe, 0xb7, 0x21, 0xc3, 0xe5, 0xbc, 0x94,
|
||||
0x7c, 0xc5, 0x6d, 0x55, 0xf3, 0x94, 0xa1, 0x14, 0x84, 0x1f, 0xb9, 0xa1,
|
||||
0x2b, 0x11, 0x43, 0xf4, 0x1b, 0x86, 0x7e, 0x9a, 0xc0, 0xf4, 0x65, 0x43,
|
||||
0xe7, 0x3b, 0xc4, 0xa5, 0x88, 0x32, 0xa2, 0x2d, 0x67, 0xb6, 0xc1, 0x9e,
|
||||
0x86, 0xea, 0x77, 0xe9, 0x6c, 0x0d, 0x85, 0x6d, 0x48, 0xd2, 0x69, 0x45,
|
||||
0x00, 0x9c, 0xc6, 0x99, 0x50, 0x36, 0x82, 0xd1, 0xc8, 0x98, 0x95, 0xd1,
|
||||
0x8c, 0x18, 0xc9, 0xfe, 0xda, 0x45, 0x53, 0x8e, 0x1c, 0xc4, 0x32, 0x3f,
|
||||
0xa2, 0x39, 0xd1, 0xb2, 0x85, 0x56, 0xa2, 0xbb, 0x30, 0x72, 0xdb, 0x88,
|
||||
0x27, 0xda, 0xb6, 0x60, 0x8e, 0x6c, 0xa1, 0x9d, 0xc8, 0x16, 0xac, 0x83,
|
||||
0xba, 0x8e, 0x48, 0x77, 0xac, 0x91, 0xae, 0x33, 0xd2, 0x75, 0x35, 0xd2,
|
||||
0x1d, 0x8f, 0x74, 0x89, 0xfd, 0xba, 0x30, 0xee, 0x2e, 0xba, 0x73, 0xda,
|
||||
0x68, 0x1b, 0x3d, 0x0b, 0xa3, 0x5b, 0x38, 0xf1, 0x03, 0x4c, 0x22, 0xaf,
|
||||
0x3d, 0xc6, 0xd0, 0x2e, 0x7a, 0x73, 0x2f, 0xcc, 0xfb, 0x0e, 0xb8, 0xde,
|
||||
0xc6, 0xc9, 0x9f, 0x08, 0xd4, 0xbf, 0x83, 0xd7, 0xb5, 0xcf, 0x1d, 0xbc,
|
||||
0xf1, 0x18, 0x1d, 0x1a, 0x9e, 0x18, 0xd0, 0xaa, 0x5d, 0x0c, 0x92, 0xd1,
|
||||
0x9b, 0x3b, 0xb0, 0x75, 0x79, 0x62, 0x61, 0x79, 0xa6, 0xd1, 0x19, 0x16,
|
||||
0xa6, 0x8d, 0xe8, 0x71, 0x74, 0xe1, 0x2c, 0x9d, 0x69, 0x24, 0xe8, 0x9e,
|
||||
0xea, 0xc6, 0x77, 0xe8, 0xc1, 0xf7, 0xf4, 0x51, 0x7d, 0x84, 0x3e, 0x3c,
|
||||
0xc1, 0x49, 0xfc, 0x8c, 0x7e, 0xfc, 0x82, 0x01, 0xfc, 0x46, 0x9f, 0xd3,
|
||||
0xdf, 0xa9, 0x0b, 0x7f, 0x12, 0x5a, 0x97, 0xd5, 0x8e, 0x4a, 0x47, 0xdc,
|
||||
0xb9, 0xb0, 0xac, 0x7f, 0x50, 0x2f, 0xde, 0xa3, 0xc2, 0x3e, 0xa2, 0x2f,
|
||||
0xf0, 0x18, 0xce, 0x53, 0x23, 0xc6, 0x49, 0xde, 0x81, 0xd8, 0xdf, 0x78,
|
||||
0x62, 0xe0, 0x82, 0x81, 0xf7, 0x07, 0xfa, 0x49, 0xf8, 0x41, 0xd8, 0xa3,
|
||||
0x8b, 0x78, 0x8b, 0xa8, 0x49, 0xf0, 0xc1, 0xb0, 0xa9, 0xf1, 0x7f, 0x01,
|
||||
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72,
|
||||
0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61,
|
||||
0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69,
|
||||
0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f,
|
||||
0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x2f, 0x03, 0x00, 0x50, 0x4b,
|
||||
0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c,
|
||||
0x19, 0x77, 0xde, 0xdf, 0x52, 0x08, 0x00, 0x00, 0xcd, 0x11, 0x00, 0x00,
|
||||
0x35, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a,
|
||||
0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65,
|
||||
0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6d, 0x6f,
|
||||
0x64, 0x75, 0x6c, 0x65, 0x73, 0x2f, 0x4a, 0x61, 0x72, 0x4c, 0x6f, 0x61,
|
||||
0x64, 0x65, 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x95, 0x57, 0x7b,
|
||||
0x74, 0x14, 0x57, 0x19, 0xff, 0xdd, 0x49, 0xb2, 0x33, 0xbb, 0x99, 0x64,
|
||||
0xc9, 0x92, 0x00, 0x0b, 0x81, 0x4e, 0x79, 0x26, 0x21, 0xc9, 0xd2, 0x00,
|
||||
0x11, 0x36, 0x84, 0x57, 0x1e, 0x10, 0x5c, 0x02, 0x92, 0x94, 0x98, 0xc6,
|
||||
0xb4, 0x4e, 0x76, 0x27, 0xc9, 0x84, 0xcd, 0xce, 0x3a, 0x3b, 0x0b, 0x04,
|
||||
0xb5, 0xbe, 0x10, 0x45, 0xb4, 0x56, 0xeb, 0x0b, 0x7c, 0xd7, 0x47, 0x94,
|
||||
0xd6, 0xb6, 0xa0, 0x6e, 0x80, 0x58, 0x90, 0x5a, 0xa3, 0xd6, 0xea, 0x5f,
|
||||
0x1e, 0xff, 0xf0, 0x1c, 0x3d, 0xc7, 0x73, 0x3c, 0xfe, 0xed, 0x3f, 0xb6,
|
||||
0xd2, 0xc3, 0xa1, 0x7e, 0x77, 0x66, 0x93, 0xcc, 0x26, 0xd9, 0xa4, 0xe5,
|
||||
0x84, 0x7b, 0xef, 0x7c, 0xdf, 0xef, 0x7b, 0xdf, 0xfb, 0xdd, 0xbb, 0xaf,
|
||||
0x3d, 0xb8, 0x75, 0x1b, 0xc0, 0x0e, 0xfc, 0xc9, 0x87, 0x5d, 0x18, 0xf1,
|
||||
0xe2, 0x14, 0xe2, 0x22, 0x46, 0x7d, 0x28, 0xc0, 0x88, 0x84, 0x04, 0x9f,
|
||||
0x0d, 0x3e, 0x24, 0x7d, 0xf8, 0x10, 0x4c, 0x11, 0x29, 0x1f, 0xbc, 0xb0,
|
||||
0x24, 0xa4, 0xf9, 0x7c, 0x5a, 0xc2, 0x19, 0x09, 0x67, 0x25, 0x8c, 0x49,
|
||||
0x38, 0x27, 0xe1, 0xc3, 0x12, 0x3e, 0x22, 0xe1, 0xa3, 0x22, 0x9e, 0xf4,
|
||||
0xa1, 0x1c, 0x16, 0x1f, 0x3e, 0xc6, 0x87, 0x8f, 0xf3, 0xe1, 0x13, 0x12,
|
||||
0x3e, 0xc9, 0xe7, 0x4f, 0xf1, 0xe1, 0xbc, 0x0f, 0x9f, 0xc6, 0x05, 0x09,
|
||||
0x9f, 0xe1, 0xf3, 0x67, 0x39, 0xe5, 0xa2, 0x84, 0xcf, 0xf9, 0x70, 0x09,
|
||||
0x9f, 0x97, 0xf0, 0x05, 0x09, 0x4f, 0x89, 0xf8, 0xa2, 0x84, 0xa7, 0x7d,
|
||||
0xd8, 0x88, 0x2f, 0x49, 0xf8, 0x32, 0x77, 0xe0, 0x19, 0x09, 0x5f, 0x91,
|
||||
0xf0, 0x55, 0x09, 0x5f, 0x93, 0xf0, 0x75, 0x11, 0xdf, 0x90, 0x70, 0xd9,
|
||||
0x87, 0x3a, 0xee, 0xca, 0x15, 0x09, 0xdf, 0xf4, 0x51, 0x04, 0xdf, 0x92,
|
||||
0xf0, 0x6d, 0x11, 0xdf, 0xe1, 0xcb, 0xef, 0x4a, 0xf8, 0x9e, 0x84, 0xef,
|
||||
0x8b, 0x78, 0xd6, 0x87, 0x1f, 0xe0, 0x87, 0x12, 0x7e, 0x24, 0xe1, 0xc7,
|
||||
0x12, 0xc6, 0xb9, 0xc4, 0x4f, 0x44, 0xfc, 0x94, 0xc1, 0xb3, 0x47, 0x4f,
|
||||
0xe8, 0xd6, 0x5e, 0x86, 0x82, 0xaa, 0xea, 0x93, 0x0c, 0x85, 0x2d, 0x46,
|
||||
0x4c, 0x63, 0xf0, 0x47, 0xf4, 0x84, 0xd6, 0x99, 0x1e, 0x1d, 0xd0, 0xcc,
|
||||
0x6e, 0x75, 0x20, 0x4e, 0x94, 0x40, 0xc4, 0x88, 0xaa, 0xf1, 0x93, 0xaa,
|
||||
0xa9, 0xf3, 0xef, 0x2c, 0xb1, 0xd0, 0x1a, 0xd6, 0x53, 0x0c, 0x8f, 0x44,
|
||||
0xa2, 0x89, 0xd0, 0x59, 0x5d, 0x35, 0xce, 0x0d, 0x1b, 0xe9, 0x86, 0xed,
|
||||
0xdb, 0x43, 0x23, 0x69, 0x3d, 0xaa, 0xa9, 0x43, 0x5a, 0xc2, 0x0a, 0xa9,
|
||||
0x49, 0x3d, 0x34, 0x6a, 0xc4, 0xd2, 0x71, 0x2d, 0x15, 0x3a, 0xa2, 0x9a,
|
||||
0x11, 0x43, 0x8d, 0x69, 0x66, 0x13, 0x83, 0x18, 0xa7, 0x15, 0x11, 0x18,
|
||||
0x2a, 0xaa, 0x22, 0x23, 0xea, 0x69, 0x35, 0x14, 0x57, 0x13, 0x43, 0xa1,
|
||||
0x2e, 0xcb, 0xd4, 0x13, 0x43, 0x4d, 0xdc, 0x15, 0x69, 0x50, 0x8f, 0x6b,
|
||||
0x9d, 0xea, 0xa8, 0x6d, 0x7c, 0x1e, 0x22, 0xcb, 0x3f, 0xae, 0x5a, 0xc3,
|
||||
0x0c, 0x8c, 0x30, 0x15, 0x2e, 0x4c, 0xdb, 0xd9, 0xa8, 0x96, 0xb4, 0x74,
|
||||
0x23, 0x41, 0xb0, 0x42, 0x0e, 0x63, 0x28, 0x75, 0xd8, 0xba, 0x11, 0x6a,
|
||||
0xa7, 0x6f, 0xee, 0x40, 0x2a, 0x1d, 0x8d, 0x6a, 0x29, 0x72, 0x9f, 0x75,
|
||||
0x50, 0x1a, 0x06, 0x55, 0x22, 0xc7, 0x18, 0xbc, 0x31, 0xdd, 0xd4, 0xa2,
|
||||
0x96, 0x61, 0x8e, 0x31, 0x14, 0x71, 0x51, 0x02, 0xf8, 0xfb, 0xe6, 0x0a,
|
||||
0x17, 0x5b, 0xaa, 0x39, 0xa4, 0x59, 0x2d, 0x71, 0x95, 0x2b, 0x28, 0x73,
|
||||
0x99, 0xb6, 0x49, 0x84, 0x90, 0x1d, 0xc4, 0x51, 0xcd, 0x1a, 0x36, 0x48,
|
||||
0xed, 0x6a, 0x17, 0xc4, 0xd4, 0x06, 0xe3, 0x64, 0x22, 0xe4, 0xf0, 0x08,
|
||||
0xeb, 0x49, 0xaa, 0xa6, 0x3a, 0x4a, 0x8a, 0xe4, 0x98, 0x96, 0xd2, 0x28,
|
||||
0xc3, 0x71, 0xfd, 0x9c, 0x46, 0x99, 0x69, 0x58, 0x22, 0xaf, 0x69, 0x4b,
|
||||
0x8f, 0xa7, 0x42, 0xad, 0x2e, 0x19, 0x1e, 0xd7, 0x88, 0x6a, 0x3a, 0x59,
|
||||
0xf1, 0x11, 0xce, 0x1c, 0xcb, 0xfa, 0x58, 0x6c, 0x7f, 0x4c, 0xbb, 0x23,
|
||||
0xeb, 0x89, 0x11, 0x72, 0x81, 0x32, 0xd4, 0xaa, 0x93, 0xa1, 0x15, 0xb9,
|
||||
0xc5, 0x1d, 0x4b, 0x4e, 0x17, 0xb8, 0x7c, 0x6e, 0x64, 0x7b, 0x6a, 0xf6,
|
||||
0x92, 0x8d, 0x92, 0x2e, 0x4b, 0x8d, 0x9e, 0x3a, 0xaa, 0x26, 0x6d, 0x98,
|
||||
0x88, 0xab, 0x74, 0x1e, 0x68, 0xb7, 0x8b, 0xe8, 0xa6, 0xfd, 0x4a, 0x86,
|
||||
0xbb, 0x8c, 0xb4, 0x19, 0xd5, 0xda, 0x9d, 0xc4, 0xcf, 0x54, 0xbd, 0x9e,
|
||||
0xeb, 0x92, 0xb1, 0x0f, 0xfb, 0x45, 0x3c, 0x27, 0xe3, 0x79, 0xfc, 0x8c,
|
||||
0x61, 0xe5, 0xdc, 0xc2, 0x1e, 0x4c, 0xeb, 0xf1, 0x18, 0x0f, 0x7e, 0x43,
|
||||
0xdf, 0x11, 0x1e, 0xed, 0x01, 0x1e, 0xad, 0x32, 0xa3, 0xa3, 0x5f, 0x39,
|
||||
0x64, 0x58, 0x8a, 0x93, 0xaf, 0xb0, 0x22, 0xe3, 0x05, 0xbc, 0x28, 0xe3,
|
||||
0x25, 0x5c, 0x13, 0x71, 0x5d, 0xc6, 0xcf, 0x71, 0x88, 0x61, 0xdb, 0xbb,
|
||||
0xcd, 0x19, 0xf7, 0x88, 0xe4, 0xc4, 0x23, 0x4e, 0xde, 0x64, 0xfc, 0x02,
|
||||
0xbf, 0xa4, 0x18, 0xda, 0xdc, 0xc9, 0x6b, 0xcb, 0x49, 0x5e, 0x47, 0x4e,
|
||||
0xf2, 0x94, 0x3c, 0x8e, 0x66, 0xf5, 0x85, 0x95, 0xfc, 0xb1, 0xcc, 0xda,
|
||||
0xe0, 0xa8, 0x8d, 0x8b, 0xa1, 0x1c, 0xe3, 0x1c, 0xb6, 0x29, 0x0f, 0xcc,
|
||||
0xed, 0x15, 0xc7, 0xc9, 0xee, 0x3d, 0x2b, 0x23, 0x83, 0x09, 0x19, 0x37,
|
||||
0x70, 0x53, 0xc6, 0x2d, 0xdc, 0x64, 0x68, 0xcc, 0xa3, 0xa5, 0x2b, 0xaa,
|
||||
0x26, 0x12, 0x54, 0x07, 0x65, 0x66, 0x87, 0x28, 0x33, 0x27, 0xa2, 0xbe,
|
||||
0xbe, 0x5e, 0xc6, 0x24, 0x57, 0xf1, 0x2b, 0x9e, 0xf1, 0xab, 0x32, 0x5e,
|
||||
0xc6, 0x35, 0x3a, 0x61, 0x54, 0x58, 0xca, 0xe2, 0x6d, 0xdc, 0x91, 0xf1,
|
||||
0x6b, 0x4e, 0xa8, 0xcd, 0xa3, 0xbb, 0xdd, 0x48, 0x27, 0x62, 0x2e, 0xc5,
|
||||
0x24, 0x16, 0x56, 0x44, 0xdc, 0x95, 0xf1, 0x0a, 0xee, 0x30, 0xd4, 0xe5,
|
||||
0x11, 0xb3, 0xe7, 0x79, 0x72, 0x0c, 0x3b, 0xf3, 0x99, 0xb1, 0x8f, 0xb2,
|
||||
0x62, 0x19, 0x0a, 0xef, 0x31, 0xf3, 0xe5, 0x96, 0x2f, 0xd0, 0x28, 0x18,
|
||||
0x76, 0xe4, 0xcb, 0xbe, 0x69, 0x1a, 0xa6, 0xad, 0x29, 0x37, 0x2b, 0xb6,
|
||||
0x32, 0x19, 0xbf, 0xc1, 0x7e, 0x86, 0xed, 0x4b, 0x95, 0x44, 0x19, 0xa4,
|
||||
0x2e, 0x9b, 0x1a, 0xd6, 0x62, 0xf5, 0x4a, 0x97, 0xd3, 0x76, 0x9a, 0xf9,
|
||||
0xde, 0x7d, 0x95, 0xfa, 0x4d, 0x6d, 0xd6, 0xdf, 0x66, 0x86, 0x7d, 0x4b,
|
||||
0xaa, 0x99, 0x29, 0x85, 0x92, 0xa0, 0x63, 0x30, 0x68, 0xe7, 0x93, 0xbc,
|
||||
0xd3, 0x46, 0x93, 0xd6, 0x18, 0x0f, 0xad, 0xf5, 0x1d, 0xec, 0x0d, 0x45,
|
||||
0x4f, 0x29, 0x89, 0x74, 0x3c, 0x5e, 0xab, 0xa4, 0x4e, 0xe9, 0x49, 0x57,
|
||||
0x44, 0xd9, 0x18, 0xeb, 0x19, 0x6a, 0x16, 0xa9, 0x04, 0xcf, 0x82, 0xdd,
|
||||
0x4b, 0xa6, 0xd3, 0xb9, 0x7a, 0x36, 0x9d, 0x27, 0xd2, 0x09, 0x4b, 0x1f,
|
||||
0xd5, 0x5c, 0x59, 0x2d, 0x9f, 0x53, 0x8c, 0x25, 0x4a, 0xd7, 0x36, 0xad,
|
||||
0xd8, 0x46, 0x93, 0x5c, 0xb6, 0x49, 0x0f, 0x92, 0xbf, 0x63, 0xe4, 0x58,
|
||||
0x55, 0x1e, 0xb9, 0x13, 0x5a, 0xca, 0x88, 0x9f, 0xe6, 0xae, 0x45, 0x9d,
|
||||
0xd3, 0x24, 0xe3, 0xb7, 0x98, 0x62, 0xa8, 0x5e, 0x12, 0x3f, 0x3a, 0x73,
|
||||
0xae, 0xfc, 0x73, 0x5a, 0x9d, 0x8c, 0xdf, 0xe1, 0xf7, 0xf9, 0x4d, 0x76,
|
||||
0x24, 0x4e, 0x1b, 0xa7, 0x72, 0x35, 0x30, 0xf2, 0x70, 0xd9, 0xac, 0x96,
|
||||
0x63, 0x03, 0x3c, 0xb3, 0x22, 0xfe, 0x20, 0xe3, 0x35, 0xfc, 0x91, 0x61,
|
||||
0xf7, 0xa2, 0x41, 0x3b, 0x6a, 0xa8, 0x1c, 0xa4, 0x76, 0x7e, 0xe0, 0x4b,
|
||||
0xef, 0x75, 0x47, 0x30, 0x5b, 0x1a, 0x47, 0x19, 0xc9, 0x05, 0xe6, 0x02,
|
||||
0x78, 0x6a, 0xf6, 0xe1, 0x75, 0x86, 0xd0, 0xbb, 0xbc, 0xb3, 0x73, 0x42,
|
||||
0x73, 0x7a, 0x75, 0x2e, 0x69, 0x2c, 0x65, 0x69, 0xa3, 0xf4, 0x8e, 0x30,
|
||||
0xd2, 0xd6, 0xcc, 0x6d, 0x4c, 0xdd, 0xe7, 0x38, 0x21, 0x2d, 0xc2, 0x6b,
|
||||
0xea, 0x28, 0xbf, 0xea, 0xd4, 0x64, 0x52, 0x4b, 0x50, 0x13, 0xad, 0x5b,
|
||||
0xe8, 0xd6, 0x9f, 0x47, 0xca, 0xde, 0x06, 0xfc, 0xb6, 0xb7, 0x8c, 0x69,
|
||||
0xa3, 0xe5, 0x55, 0xf3, 0x81, 0x4d, 0xd3, 0xc7, 0x3a, 0xd7, 0x22, 0xb5,
|
||||
0xf5, 0x24, 0xff, 0x8a, 0xd3, 0x56, 0x2c, 0xa0, 0xeb, 0x98, 0x61, 0xd7,
|
||||
0x02, 0x76, 0xdf, 0x89, 0x27, 0x64, 0xc0, 0x1b, 0xd7, 0x53, 0x56, 0xbb,
|
||||
0xf3, 0x24, 0x28, 0xab, 0xaa, 0x9e, 0xf7, 0x28, 0xf0, 0x68, 0x67, 0x09,
|
||||
0x90, 0xb2, 0x9f, 0x52, 0x8f, 0xd1, 0xa5, 0xa1, 0xa7, 0x5a, 0x67, 0xdf,
|
||||
0x12, 0x1e, 0x3d, 0xe5, 0xdc, 0x87, 0x22, 0xb9, 0xe1, 0xbc, 0x6a, 0x8a,
|
||||
0x2d, 0x23, 0x62, 0x9c, 0xd1, 0xcc, 0x16, 0x35, 0x45, 0x5f, 0x12, 0xa5,
|
||||
0x25, 0xd5, 0xa3, 0xf3, 0x8b, 0x7b, 0xc1, 0x17, 0x11, 0x69, 0xf4, 0x93,
|
||||
0xe8, 0x81, 0x01, 0xda, 0xb9, 0x69, 0x2b, 0xfb, 0xf0, 0xa9, 0x5a, 0xbc,
|
||||
0x88, 0xb3, 0x7b, 0x86, 0xa1, 0x52, 0x8d, 0xc5, 0xba, 0x0d, 0xa7, 0x4a,
|
||||
0xf6, 0xfe, 0x76, 0xca, 0xda, 0xa5, 0xa9, 0x66, 0x94, 0x34, 0xf9, 0x93,
|
||||
0x4e, 0xd6, 0xe8, 0x5e, 0xef, 0x36, 0xd5, 0x28, 0x39, 0x54, 0x59, 0xd5,
|
||||
0xb1, 0x58, 0x41, 0xc4, 0x41, 0xc3, 0x74, 0xe2, 0xd8, 0xb4, 0x44, 0x29,
|
||||
0xa7, 0x9f, 0x44, 0x5e, 0xd7, 0x7b, 0x68, 0xff, 0x02, 0x32, 0x7d, 0xf3,
|
||||
0x64, 0xaa, 0x17, 0x7b, 0x35, 0xad, 0xca, 0xc7, 0xe3, 0xc9, 0xb6, 0xf7,
|
||||
0x3a, 0x1d, 0x39, 0xb7, 0x19, 0xe7, 0x3c, 0xe6, 0x98, 0xc9, 0x92, 0xaa,
|
||||
0xe7, 0x93, 0xa8, 0x09, 0x2e, 0xbe, 0x53, 0xba, 0x87, 0x4d, 0xe3, 0x0c,
|
||||
0x7f, 0xfe, 0xd0, 0x63, 0x15, 0x0f, 0x63, 0x2f, 0xfd, 0x6a, 0xe0, 0xff,
|
||||
0x04, 0x30, 0xfe, 0xc2, 0xa1, 0xf1, 0x00, 0x7d, 0x85, 0x68, 0x66, 0x34,
|
||||
0x17, 0xd5, 0x4c, 0x80, 0x5d, 0xb3, 0xd9, 0x07, 0x69, 0xf4, 0xd8, 0x44,
|
||||
0x2f, 0x5a, 0x68, 0x94, 0x1d, 0x00, 0x5a, 0xd1, 0x66, 0xd3, 0xda, 0x71,
|
||||
0xc8, 0x11, 0x2e, 0x0a, 0xa1, 0x10, 0xcb, 0x48, 0xe4, 0x8d, 0xeb, 0x10,
|
||||
0x26, 0x51, 0xd0, 0x3b, 0x81, 0xc2, 0x40, 0x51, 0x06, 0x9e, 0x1a, 0xfa,
|
||||
0x9f, 0x81, 0x98, 0x81, 0x34, 0x09, 0x6f, 0x2f, 0x69, 0xf6, 0x45, 0xb6,
|
||||
0x06, 0x8a, 0x59, 0x06, 0xf2, 0xd1, 0xad, 0x81, 0x12, 0x3e, 0x77, 0x6e,
|
||||
0x0d, 0x94, 0xf2, 0x39, 0x5c, 0xb8, 0x35, 0xe0, 0xb7, 0x17, 0x45, 0x2e,
|
||||
0x1d, 0xcb, 0x48, 0xbe, 0x76, 0x46, 0x87, 0x8b, 0x51, 0x46, 0xc4, 0xba,
|
||||
0x85, 0x18, 0x01, 0x22, 0x06, 0x0b, 0x17, 0xe2, 0x2c, 0xe7, 0x9c, 0xa2,
|
||||
0x19, 0x4e, 0xb0, 0x68, 0x8a, 0x75, 0x4e, 0xa2, 0xbc, 0x37, 0x58, 0x34,
|
||||
0x81, 0x8a, 0xb0, 0x27, 0x48, 0xf4, 0x15, 0x61, 0x91, 0x4f, 0x2b, 0x2f,
|
||||
0xb3, 0x95, 0x7c, 0x5e, 0x75, 0x99, 0xf9, 0x83, 0xe2, 0x14, 0xf3, 0x91,
|
||||
0x96, 0x40, 0x90, 0x64, 0x0a, 0x1a, 0xe9, 0xcf, 0x1b, 0x14, 0xc3, 0xbe,
|
||||
0xa0, 0xef, 0x76, 0x63, 0x71, 0x41, 0xa3, 0x5c, 0x21, 0x57, 0x14, 0x3f,
|
||||
0x8b, 0x57, 0x82, 0xbe, 0x0a, 0xb9, 0x21, 0x5c, 0x12, 0x2c, 0xc9, 0x60,
|
||||
0xf5, 0x15, 0x78, 0xc6, 0x71, 0x95, 0x2f, 0xd7, 0x64, 0x50, 0x19, 0x2e,
|
||||
0x0d, 0x96, 0x06, 0xd6, 0x66, 0xb0, 0xce, 0x26, 0x3f, 0xc3, 0xc9, 0x0f,
|
||||
0x85, 0xfd, 0x2e, 0xb7, 0x14, 0xee, 0x96, 0x7f, 0xd6, 0x2d, 0xff, 0x0d,
|
||||
0x3c, 0x7c, 0x19, 0x1b, 0xce, 0x4b, 0xcc, 0x05, 0x5a, 0x9f, 0x0b, 0x1a,
|
||||
0x87, 0x72, 0xde, 0xeb, 0xe6, 0x6f, 0x98, 0xcb, 0xaf, 0x09, 0x97, 0xe6,
|
||||
0x22, 0x36, 0x71, 0x04, 0x37, 0x3e, 0x6b, 0xa9, 0x34, 0x83, 0xcd, 0xe7,
|
||||
0x65, 0x36, 0xfe, 0x76, 0xb3, 0x0b, 0xb7, 0x85, 0xf8, 0x15, 0x52, 0x06,
|
||||
0x55, 0x81, 0x6a, 0xbe, 0xf2, 0xd2, 0x6a, 0x5a, 0xe7, 0x5a, 0x17, 0xac,
|
||||
0x26, 0x37, 0x99, 0xe3, 0x28, 0xe6, 0x39, 0xda, 0x9a, 0x9b, 0xf1, 0xda,
|
||||
0x9c, 0xea, 0xd5, 0x52, 0x60, 0x57, 0xb0, 0x6e, 0x12, 0x75, 0xbd, 0xd3,
|
||||
0x80, 0xfa, 0x59, 0xc0, 0x04, 0x42, 0x77, 0xb8, 0x8a, 0x6d, 0xb9, 0x2a,
|
||||
0x1e, 0xc9, 0xa9, 0x73, 0xdd, 0x0d, 0x34, 0x84, 0x3d, 0x2e, 0xf6, 0xf6,
|
||||
0xdc, 0x6a, 0x07, 0xe9, 0xa3, 0xe0, 0x65, 0xec, 0xc8, 0x60, 0x67, 0x58,
|
||||
0x74, 0xc1, 0x1a, 0xb3, 0x5a, 0x02, 0xef, 0x99, 0x83, 0x17, 0x19, 0xc1,
|
||||
0x77, 0x65, 0xb0, 0xbb, 0x87, 0xdb, 0x0e, 0xdb, 0x91, 0xec, 0xb0, 0x2d,
|
||||
0x04, 0x9a, 0xec, 0x4d, 0x3b, 0xeb, 0xeb, 0x9e, 0x85, 0x74, 0x04, 0x3d,
|
||||
0x13, 0x68, 0xbe, 0x73, 0x8d, 0x76, 0xff, 0x03, 0xe6, 0x61, 0x17, 0xb1,
|
||||
0x91, 0x79, 0xd9, 0x5a, 0x7b, 0x56, 0xd8, 0x05, 0x3e, 0x0b, 0x6d, 0xc2,
|
||||
0x5d, 0xe1, 0x55, 0xfa, 0x4d, 0x5c, 0x68, 0x9f, 0xa6, 0x7f, 0x63, 0xb7,
|
||||
0x7d, 0x8e, 0x82, 0x28, 0xc5, 0x7a, 0x3a, 0x31, 0x35, 0x28, 0x43, 0x03,
|
||||
0x02, 0x68, 0xc2, 0x72, 0x3a, 0x55, 0x15, 0xe8, 0xc7, 0x0a, 0x9c, 0xc6,
|
||||
0x4a, 0x3c, 0x8d, 0x55, 0xb8, 0x8a, 0xd5, 0x78, 0x11, 0x6b, 0xe8, 0x0d,
|
||||
0x5c, 0x89, 0xbb, 0x58, 0x87, 0xbf, 0xe2, 0x21, 0xfc, 0x83, 0x8e, 0xef,
|
||||
0x3f, 0x49, 0xf2, 0x5f, 0xa4, 0xf1, 0x01, 0x36, 0x33, 0x0f, 0xb6, 0x30,
|
||||
0x2f, 0x6a, 0xd8, 0x72, 0xd4, 0xb2, 0xb5, 0xa8, 0x63, 0x0a, 0xb6, 0xb1,
|
||||
0x2d, 0x68, 0x60, 0x07, 0xb0, 0x83, 0x75, 0x60, 0x27, 0x8b, 0xa0, 0x91,
|
||||
0xe9, 0xd8, 0xc5, 0xe2, 0xd8, 0xcd, 0x2e, 0xd0, 0xf3, 0xef, 0x22, 0xf6,
|
||||
0xb0, 0x4b, 0x68, 0x66, 0x4f, 0x61, 0x2f, 0x7b, 0x0e, 0xfb, 0xd8, 0x4b,
|
||||
0xe4, 0x69, 0x06, 0x2d, 0xec, 0x6f, 0x68, 0x63, 0x7f, 0x47, 0x3b, 0x7b,
|
||||
0x13, 0x87, 0xd9, 0x5b, 0xe8, 0x10, 0x04, 0x44, 0x84, 0x35, 0xe8, 0x14,
|
||||
0xd6, 0xe3, 0x98, 0xd0, 0x8c, 0x13, 0x42, 0x1b, 0x1e, 0x15, 0x1e, 0x47,
|
||||
0x8f, 0x10, 0x43, 0xaf, 0xf0, 0x24, 0xfa, 0x84, 0x4b, 0xe8, 0x17, 0x5e,
|
||||
0xc0, 0x13, 0xc2, 0x4d, 0xa8, 0xc2, 0x5d, 0xe8, 0x14, 0x61, 0x54, 0x98,
|
||||
0x42, 0x4c, 0xf8, 0x33, 0x34, 0xe1, 0xbf, 0x18, 0xb1, 0xbb, 0xc5, 0xf3,
|
||||
0x28, 0x23, 0xbf, 0x52, 0x38, 0x8c, 0x0e, 0x94, 0x92, 0x57, 0x4f, 0xe0,
|
||||
0x08, 0xad, 0xfc, 0x64, 0x7f, 0x13, 0xde, 0x8b, 0x08, 0x65, 0xe0, 0x01,
|
||||
0xae, 0xe3, 0x28, 0x3a, 0x51, 0x42, 0x31, 0xdd, 0xc3, 0x31, 0x1c, 0x87,
|
||||
0x44, 0x91, 0xbd, 0x81, 0xf7, 0xd1, 0xca, 0x8b, 0x5b, 0x8c, 0x2c, 0x13,
|
||||
0xd7, 0x83, 0xbb, 0xac, 0x11, 0x5d, 0xe8, 0x86, 0x48, 0xf6, 0xfb, 0xf1,
|
||||
0x28, 0x4e, 0xc2, 0x43, 0x1e, 0x34, 0xa2, 0x07, 0xef, 0x27, 0xda, 0x14,
|
||||
0xb5, 0x2e, 0xae, 0xcf, 0xc3, 0xfb, 0x0f, 0x7a, 0xc9, 0x06, 0xb0, 0x5e,
|
||||
0xf8, 0x0b, 0x1e, 0x43, 0x1f, 0x75, 0xa7, 0x1a, 0xe1, 0x75, 0x7c, 0x80,
|
||||
0x68, 0x02, 0x1a, 0xc8, 0xcb, 0x7e, 0x5a, 0x15, 0xa0, 0x89, 0x36, 0xc6,
|
||||
0xe3, 0xb4, 0x2a, 0x44, 0xab, 0x70, 0x9d, 0xfc, 0xea, 0xa0, 0x9e, 0xf6,
|
||||
0x41, 0xa7, 0xbf, 0x65, 0x2d, 0xa8, 0xa4, 0x6d, 0x80, 0x28, 0x3d, 0xf0,
|
||||
0xbf, 0x8d, 0xff, 0xa0, 0x44, 0x44, 0x54, 0x44, 0xcc, 0x1e, 0x67, 0xfe,
|
||||
0xe8, 0xc7, 0xe4, 0x20, 0x63, 0xf6, 0x00, 0xdc, 0xc7, 0x2a, 0xa2, 0xdc,
|
||||
0xc7, 0x0a, 0x62, 0xdd, 0xc7, 0x61, 0x1a, 0xef, 0xa1, 0xf2, 0xa0, 0x88,
|
||||
0xa1, 0xb7, 0xb0, 0xf9, 0x7f, 0x28, 0xba, 0x87, 0xcd, 0xf7, 0x10, 0x14,
|
||||
0xc4, 0xf0, 0x9b, 0xb8, 0x40, 0xc4, 0x6d, 0xe4, 0xd8, 0xb0, 0xdd, 0x62,
|
||||
0xf5, 0xff, 0x03, 0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08,
|
||||
0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f,
|
||||
0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f,
|
||||
0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x73, 0x2f, 0x03, 0x00, 0x50,
|
||||
0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95,
|
||||
0x5c, 0x50, 0xe7, 0x20, 0x38, 0xbd, 0x07, 0x00, 0x00, 0xd4, 0x10, 0x00,
|
||||
0x00, 0x36, 0x00, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f,
|
||||
0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63,
|
||||
0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x75,
|
||||
0x74, 0x69, 0x6c, 0x73, 0x2f, 0x44, 0x65, 0x73, 0x65, 0x72, 0x69, 0x61,
|
||||
0x6c, 0x69, 0x7a, 0x65, 0x72, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x95,
|
||||
0x57, 0xfb, 0x73, 0x13, 0xd7, 0x19, 0x3d, 0x6b, 0xad, 0xb4, 0xd2, 0x7a,
|
||||
0xfd, 0x90, 0xb1, 0x48, 0x0c, 0x4e, 0x0c, 0x84, 0x52, 0x59, 0xc6, 0x11,
|
||||
0x81, 0xc4, 0x26, 0x36, 0xb8, 0xc1, 0x36, 0x26, 0x76, 0x8c, 0x69, 0x71,
|
||||
0x0a, 0xc5, 0x09, 0x34, 0x6b, 0x69, 0x6d, 0xaf, 0x2d, 0xaf, 0x14, 0x69,
|
||||
0xe5, 0x00, 0x49, 0xc8, 0xa3, 0xf4, 0x41, 0xda, 0xb4, 0x49, 0x9a, 0xb4,
|
||||
0x35, 0x7d, 0xd1, 0x94, 0xd4, 0x6d, 0x6a, 0x5e, 0x6d, 0x30, 0x6e, 0xd2,
|
||||
0x49, 0x3b, 0x9d, 0x29, 0xd3, 0xe9, 0xf4, 0x87, 0xce, 0xf4, 0x4f, 0x68,
|
||||
0xfe, 0x88, 0x4e, 0x87, 0x69, 0x7a, 0xee, 0x95, 0x90, 0x1f, 0x5a, 0xb7,
|
||||
0x30, 0x78, 0xaf, 0xbe, 0xfb, 0xdd, 0xef, 0x9e, 0x7b, 0xee, 0xf7, 0xda,
|
||||
0xe5, 0xaf, 0xff, 0xf9, 0xf0, 0x63, 0x00, 0x0f, 0xe3, 0x43, 0x1d, 0x51,
|
||||
0x64, 0x34, 0x3c, 0xab, 0xa3, 0x02, 0x99, 0x10, 0x3e, 0x8b, 0xac, 0x18,
|
||||
0x72, 0x3a, 0x07, 0x57, 0x47, 0x1d, 0xf2, 0x1a, 0x66, 0x74, 0x04, 0x91,
|
||||
0x11, 0x93, 0xe7, 0x84, 0x74, 0x52, 0x0c, 0x79, 0x31, 0x9c, 0x12, 0x9b,
|
||||
0x4e, 0x0b, 0xe9, 0x79, 0x21, 0xbd, 0x20, 0x86, 0x17, 0x35, 0x9c, 0x11,
|
||||
0xa6, 0x2f, 0x09, 0x84, 0x97, 0x75, 0xbc, 0x82, 0x57, 0x35, 0x7c, 0x45,
|
||||
0x68, 0xce, 0xea, 0xf8, 0x2a, 0xbe, 0x26, 0xa4, 0xaf, 0xeb, 0xf8, 0x06,
|
||||
0xce, 0x09, 0xe9, 0x35, 0x1d, 0xdf, 0xc4, 0xb7, 0x84, 0xf4, 0xba, 0x18,
|
||||
0xbe, 0x1d, 0xc4, 0x77, 0xc4, 0xef, 0x1b, 0x41, 0xbc, 0x19, 0xc4, 0x5b,
|
||||
0x41, 0x7c, 0x57, 0x40, 0xbe, 0x2d, 0x86, 0x77, 0xc4, 0xf0, 0x3d, 0x0d,
|
||||
0xdf, 0xd7, 0xf0, 0x03, 0x05, 0x6a, 0xd2, 0x74, 0x4d, 0x05, 0x75, 0x83,
|
||||
0x93, 0xe6, 0x8c, 0x19, 0x4f, 0x99, 0xce, 0x78, 0x7c, 0xd8, 0xcd, 0xda,
|
||||
0xce, 0x78, 0xa7, 0x02, 0xdf, 0xb4, 0x99, 0x51, 0xb0, 0xae, 0xb0, 0x94,
|
||||
0x77, 0xed, 0x54, 0xfc, 0x71, 0x33, 0x37, 0x71, 0xd0, 0xcc, 0x70, 0x2d,
|
||||
0x34, 0x6c, 0x8f, 0x3b, 0xa6, 0x9b, 0xcf, 0x5a, 0x0a, 0x1e, 0x2d, 0xb7,
|
||||
0xd8, 0x53, 0x8e, 0x57, 0xae, 0xe9, 0x22, 0x4e, 0x60, 0x8f, 0xed, 0xd8,
|
||||
0x6e, 0x97, 0x82, 0x48, 0xb4, 0xdc, 0xa0, 0xf9, 0x08, 0x09, 0xf6, 0xa4,
|
||||
0x93, 0x3c, 0xa3, 0x66, 0xd0, 0x76, 0xac, 0xa1, 0xfc, 0xf4, 0xa8, 0x95,
|
||||
0x7d, 0xd2, 0x1c, 0x4d, 0x59, 0x82, 0x72, 0x3a, 0x61, 0xa6, 0x8e, 0x98,
|
||||
0x59, 0x5b, 0xcc, 0x8b, 0x4a, 0xd5, 0x9d, 0xb0, 0x73, 0x0a, 0x76, 0x0e,
|
||||
0x26, 0x9c, 0xf8, 0x49, 0xdb, 0x4c, 0x9f, 0x9e, 0x48, 0xe7, 0x77, 0xee,
|
||||
0xda, 0x15, 0x9f, 0xcc, 0xdb, 0x09, 0xcb, 0x1c, 0xb7, 0x1c, 0x37, 0x6e,
|
||||
0x66, 0x6c, 0x49, 0x35, 0x17, 0xef, 0xb5, 0x72, 0x16, 0x77, 0xa7, 0xec,
|
||||
0xd3, 0x56, 0x96, 0x54, 0xfc, 0x19, 0x33, 0x9b, 0x23, 0x86, 0x92, 0xe0,
|
||||
0xd3, 0xc3, 0xb9, 0xed, 0x64, 0xf2, 0x2e, 0xdd, 0x30, 0x65, 0x9d, 0x52,
|
||||
0xd0, 0x50, 0x46, 0xaf, 0x3b, 0x6f, 0xa7, 0x92, 0x85, 0x9d, 0x33, 0x66,
|
||||
0x2a, 0xcf, 0x9d, 0x7a, 0xd6, 0x32, 0x93, 0x5c, 0x79, 0x42, 0x6c, 0x50,
|
||||
0x46, 0x14, 0x68, 0x56, 0x2e, 0x61, 0x66, 0xac, 0x24, 0x4d, 0x12, 0x13,
|
||||
0x44, 0x57, 0x50, 0xf1, 0x14, 0x91, 0xab, 0x86, 0x5d, 0x33, 0x31, 0x45,
|
||||
0x37, 0x49, 0xd6, 0x32, 0x14, 0x67, 0x98, 0x1d, 0x1a, 0xf6, 0x29, 0xa8,
|
||||
0x4c, 0x2e, 0xb1, 0x12, 0x5e, 0x69, 0xf6, 0x74, 0x7f, 0xa7, 0x97, 0xfe,
|
||||
0x8e, 0x9d, 0xee, 0x9b, 0x30, 0x73, 0x6b, 0x78, 0x9c, 0xa4, 0x7d, 0xe3,
|
||||
0x16, 0x6f, 0xbd, 0xdb, 0x63, 0xd5, 0xc3, 0xde, 0x33, 0x6f, 0x92, 0xd6,
|
||||
0x18, 0x23, 0x4b, 0x98, 0x7e, 0x87, 0x48, 0xeb, 0x3d, 0x90, 0xfa, 0x9b,
|
||||
0xfb, 0xe9, 0x21, 0x71, 0xc1, 0x65, 0x6b, 0xfb, 0x4f, 0x26, 0xac, 0x8c,
|
||||
0x6b, 0xa7, 0x1d, 0x62, 0x28, 0xfd, 0x4c, 0x76, 0x3a, 0x90, 0x20, 0x83,
|
||||
0x69, 0x67, 0xdc, 0x1b, 0x65, 0xa0, 0x79, 0x80, 0x96, 0x7c, 0x42, 0x34,
|
||||
0xeb, 0x4d, 0xe7, 0x65, 0x0a, 0x78, 0x19, 0xf6, 0x36, 0xf7, 0xd2, 0x90,
|
||||
0x4f, 0x90, 0x86, 0x7d, 0xa9, 0xb4, 0xb9, 0x06, 0xad, 0xbe, 0xe6, 0x3e,
|
||||
0xda, 0xf1, 0xd1, 0x69, 0xd7, 0x9d, 0x4e, 0xa7, 0x2c, 0xd3, 0xf1, 0xb6,
|
||||
0x1c, 0x11, 0x9e, 0x52, 0x73, 0x32, 0x48, 0xbe, 0xa8, 0xb8, 0x8d, 0x66,
|
||||
0xe7, 0xf6, 0x4f, 0x67, 0xdc, 0x53, 0x72, 0x3e, 0x22, 0x22, 0xce, 0xdd,
|
||||
0x59, 0x39, 0x63, 0x1a, 0xfb, 0xcd, 0xdc, 0x41, 0x51, 0x4d, 0xe1, 0x15,
|
||||
0x81, 0x2b, 0x04, 0xb3, 0x7d, 0xb5, 0xee, 0x8e, 0x03, 0x29, 0xdc, 0xd3,
|
||||
0x2b, 0x0b, 0xb8, 0x3e, 0xea, 0x19, 0x8a, 0x8d, 0x87, 0xf3, 0x8e, 0x6b,
|
||||
0x4f, 0x5b, 0xfd, 0xce, 0x8c, 0x9d, 0xb3, 0xe9, 0x9f, 0x7d, 0x8e, 0x93,
|
||||
0x76, 0x4d, 0xe1, 0xe4, 0x9c, 0x28, 0xa1, 0x54, 0x7a, 0x7a, 0x34, 0x3d,
|
||||
0x15, 0x3f, 0x60, 0x39, 0x56, 0xd6, 0x74, 0xad, 0x64, 0x67, 0x21, 0x6e,
|
||||
0x92, 0xaa, 0x3e, 0x9c, 0xce, 0x67, 0x13, 0x56, 0x9f, 0x2d, 0xbc, 0x1a,
|
||||
0x5e, 0x5e, 0x2c, 0x0f, 0x8a, 0x93, 0x0c, 0xc4, 0x21, 0x16, 0xca, 0xd2,
|
||||
0xd0, 0x40, 0x0b, 0xb6, 0x1b, 0x68, 0x46, 0xcc, 0x40, 0x1b, 0x76, 0x18,
|
||||
0x98, 0x05, 0x09, 0xde, 0xb3, 0x46, 0xf9, 0x18, 0x38, 0x8f, 0x1f, 0x1a,
|
||||
0xf8, 0x11, 0x7e, 0x6c, 0xe0, 0x27, 0x98, 0x34, 0xf0, 0x53, 0x5c, 0x30,
|
||||
0xf0, 0x33, 0xbc, 0x6b, 0xe0, 0xe7, 0xb8, 0x68, 0x60, 0x10, 0xef, 0x29,
|
||||
0xa8, 0x5d, 0xbd, 0xd9, 0xc0, 0x2f, 0x30, 0x27, 0x16, 0x0f, 0x6a, 0xf8,
|
||||
0xa5, 0x81, 0x5f, 0xe1, 0x7d, 0x36, 0x2a, 0x8f, 0x4c, 0x12, 0x76, 0xbf,
|
||||
0xd6, 0x30, 0x6f, 0xe0, 0x12, 0x2e, 0x8b, 0xc9, 0x15, 0x0d, 0x57, 0x0d,
|
||||
0x5c, 0xc3, 0x6f, 0xc4, 0xe4, 0xb7, 0x1a, 0x3e, 0x30, 0x70, 0x1d, 0x0b,
|
||||
0x62, 0x72, 0xc3, 0xc0, 0x22, 0x26, 0x45, 0x0b, 0xc9, 0xe6, 0x2d, 0x03,
|
||||
0xbf, 0xc3, 0x45, 0xa6, 0xc2, 0x43, 0x8c, 0xdc, 0x98, 0x99, 0x92, 0x6d,
|
||||
0x81, 0x37, 0x79, 0x06, 0xbc, 0xf6, 0x28, 0x12, 0x06, 0x92, 0xe2, 0xee,
|
||||
0x3b, 0xee, 0xb6, 0xcb, 0xac, 0xb8, 0xc9, 0xa1, 0xd1, 0x49, 0x2b, 0xc1,
|
||||
0x44, 0x0c, 0xa4, 0x2c, 0x67, 0xdc, 0x9d, 0x60, 0xe9, 0xbb, 0xe9, 0x1e,
|
||||
0x76, 0x89, 0x7d, 0xd9, 0xac, 0xc9, 0x2c, 0x52, 0xa3, 0xcd, 0xa2, 0x57,
|
||||
0x04, 0xcc, 0x4c, 0xc6, 0x72, 0xd8, 0x41, 0x1a, 0xa3, 0x3d, 0xe5, 0x21,
|
||||
0x5e, 0xea, 0x41, 0x41, 0x37, 0x5d, 0x50, 0x31, 0xe3, 0x64, 0xdb, 0x5a,
|
||||
0x51, 0xc0, 0x85, 0xb3, 0x3a, 0xcb, 0x35, 0xcd, 0xe5, 0x2a, 0x96, 0x53,
|
||||
0x8e, 0x55, 0x57, 0x24, 0xa5, 0x46, 0xfb, 0x45, 0xfe, 0x56, 0x26, 0xd2,
|
||||
0x8e, 0x6b, 0xda, 0x4e, 0x4e, 0xf6, 0xb6, 0x88, 0x07, 0xb6, 0xc8, 0xf9,
|
||||
0x6d, 0x5e, 0x7a, 0xaf, 0x13, 0x34, 0xd9, 0x31, 0x0f, 0x8d, 0x09, 0xa8,
|
||||
0x7e, 0xcf, 0xcc, 0x0d, 0x2f, 0xe9, 0xd8, 0x45, 0xac, 0x71, 0xe1, 0xbc,
|
||||
0xa0, 0xec, 0xd0, 0xb2, 0xa9, 0x78, 0x36, 0xaf, 0x7e, 0xa1, 0x1f, 0xf0,
|
||||
0x84, 0xab, 0x5e, 0xd2, 0x15, 0xfa, 0x49, 0x48, 0x62, 0x15, 0x64, 0x4f,
|
||||
0xb0, 0x01, 0xa1, 0xef, 0xf5, 0x04, 0x5b, 0x16, 0xc4, 0xdb, 0x5d, 0xa7,
|
||||
0x52, 0xc2, 0xdd, 0x9e, 0x79, 0x02, 0xf6, 0x0a, 0x7d, 0x9f, 0x27, 0x60,
|
||||
0xcd, 0x92, 0xae, 0xd8, 0x9d, 0x74, 0x89, 0x57, 0x9c, 0x78, 0xc2, 0xf5,
|
||||
0x09, 0xfd, 0x88, 0x27, 0x1c, 0x13, 0x69, 0x30, 0xfd, 0x9c, 0x95, 0xed,
|
||||
0x31, 0x45, 0xe2, 0x06, 0xac, 0x67, 0xf3, 0x4c, 0x61, 0x6c, 0xe6, 0x77,
|
||||
0x44, 0x94, 0xdf, 0x2a, 0x15, 0xfc, 0x2e, 0x60, 0x71, 0x52, 0xaa, 0x13,
|
||||
0x95, 0x0a, 0x05, 0xad, 0x52, 0xfb, 0x20, 0x6a, 0x29, 0xc7, 0xb1, 0x83,
|
||||
0xe3, 0x43, 0xd4, 0x9c, 0x80, 0x8f, 0x5a, 0x60, 0x43, 0xec, 0x06, 0x94,
|
||||
0xd8, 0x47, 0xa8, 0x38, 0x76, 0x03, 0xbe, 0xeb, 0x50, 0x63, 0x2d, 0xd7,
|
||||
0xe1, 0x8f, 0xb5, 0xdc, 0x40, 0xe0, 0x9a, 0xdc, 0xb7, 0x93, 0xe3, 0x7a,
|
||||
0xf8, 0x39, 0x56, 0x43, 0x85, 0x81, 0x1a, 0xfe, 0xab, 0x27, 0x56, 0x03,
|
||||
0xc2, 0xd8, 0x25, 0xd7, 0x24, 0x0a, 0xbf, 0x91, 0x1e, 0x01, 0xa4, 0x24,
|
||||
0x4e, 0xe7, 0xab, 0x50, 0x74, 0x87, 0xc2, 0x59, 0x15, 0x61, 0x9e, 0x55,
|
||||
0xc9, 0xb5, 0x4f, 0x5a, 0x6e, 0x42, 0x6f, 0x59, 0x80, 0x76, 0x1e, 0xea,
|
||||
0xb5, 0x8f, 0x10, 0xe4, 0x91, 0xa1, 0x83, 0xc5, 0xdf, 0x21, 0xb5, 0x4d,
|
||||
0xf5, 0xb5, 0xf9, 0xb9, 0xaa, 0x77, 0x04, 0x1a, 0x02, 0x1d, 0x5a, 0x83,
|
||||
0xf6, 0x71, 0x5b, 0xd0, 0xd7, 0x16, 0x8a, 0x84, 0x22, 0xc1, 0x77, 0xf1,
|
||||
0x76, 0x83, 0x16, 0x09, 0x3d, 0xdc, 0xa6, 0x47, 0xfc, 0xb3, 0x68, 0x8a,
|
||||
0xa8, 0xb3, 0xa8, 0xda, 0x1e, 0xd1, 0x17, 0x50, 0x79, 0x74, 0x0e, 0x7a,
|
||||
0x6b, 0x41, 0xe2, 0xee, 0x39, 0x8c, 0x45, 0xf4, 0xda, 0xa7, 0x2f, 0x20,
|
||||
0xa4, 0x8a, 0xc9, 0x31, 0x61, 0x58, 0x4b, 0xcd, 0x5e, 0x6a, 0x7c, 0x6d,
|
||||
0xea, 0x1c, 0x0e, 0x70, 0xd2, 0x79, 0x01, 0xb1, 0xed, 0x0b, 0x30, 0x66,
|
||||
0xb1, 0x2e, 0xf6, 0x01, 0x54, 0x8a, 0x55, 0xad, 0x7c, 0x16, 0x50, 0x7d,
|
||||
0x74, 0xbb, 0x6f, 0x01, 0x35, 0xad, 0x62, 0x50, 0x85, 0x75, 0x83, 0xf7,
|
||||
0x41, 0x67, 0x43, 0xca, 0xdc, 0xa7, 0x53, 0x6b, 0x40, 0x08, 0xaf, 0xf9,
|
||||
0xa4, 0xd7, 0x5e, 0xc3, 0x16, 0x8e, 0xf5, 0xbc, 0x79, 0x84, 0x7e, 0xbb,
|
||||
0x97, 0x52, 0x03, 0x1a, 0xb1, 0x11, 0x4d, 0x1c, 0xb7, 0xe0, 0x7e, 0x46,
|
||||
0x6b, 0x13, 0xba, 0x29, 0x1d, 0xc0, 0x03, 0x6c, 0x75, 0x5b, 0x71, 0x04,
|
||||
0xdb, 0x70, 0x9c, 0xda, 0x67, 0xe8, 0xc1, 0x04, 0x23, 0x37, 0xc9, 0xc8,
|
||||
0x4d, 0x33, 0x6e, 0x19, 0xfa, 0xf0, 0x05, 0x22, 0xbe, 0x44, 0x7f, 0xbf,
|
||||
0x4a, 0xaf, 0x9e, 0x43, 0x3b, 0xde, 0xc0, 0x6e, 0x5c, 0x40, 0x27, 0xde,
|
||||
0xc3, 0x1e, 0xbc, 0x8f, 0xbd, 0xec, 0x7f, 0x5d, 0xb8, 0x8a, 0x7d, 0xec,
|
||||
0x76, 0xdd, 0xf8, 0x03, 0x7a, 0x71, 0x93, 0xd8, 0x7f, 0xc3, 0xe3, 0xf8,
|
||||
0x07, 0xfa, 0xf1, 0x4f, 0x3c, 0x21, 0x23, 0x75, 0x98, 0x1f, 0xa0, 0xdd,
|
||||
0x38, 0xcb, 0xdd, 0xbb, 0xa1, 0x8b, 0x68, 0x94, 0x62, 0xf6, 0x09, 0x1e,
|
||||
0x95, 0x31, 0xab, 0xc7, 0xdf, 0xd1, 0x41, 0xd4, 0x0a, 0x32, 0xfc, 0x0b,
|
||||
0x91, 0x3b, 0x79, 0x93, 0x26, 0xfc, 0x99, 0xf8, 0x5d, 0x8c, 0xfd, 0x16,
|
||||
0xfc, 0x09, 0x9f, 0xa3, 0xe4, 0x27, 0xc7, 0xdf, 0xe3, 0x31, 0x9e, 0x16,
|
||||
0x20, 0x1e, 0x88, 0x5d, 0x5d, 0x89, 0x4f, 0x99, 0x7e, 0xba, 0x86, 0x1e,
|
||||
0x0d, 0xbd, 0x1a, 0xf6, 0xf3, 0x4f, 0x51, 0x34, 0xf4, 0xf1, 0x4f, 0x51,
|
||||
0x80, 0x5b, 0xd8, 0xac, 0x04, 0xfc, 0x46, 0xf8, 0xbe, 0x9a, 0xea, 0x7f,
|
||||
0x23, 0xf0, 0x2f, 0xf8, 0xd7, 0xf3, 0xb0, 0x03, 0xa4, 0x57, 0x21, 0x53,
|
||||
0x31, 0xce, 0x19, 0xad, 0x98, 0x76, 0xf4, 0xe5, 0xd5, 0x52, 0xd6, 0x05,
|
||||
0xa4, 0x72, 0x48, 0x72, 0x37, 0x0a, 0x06, 0x45, 0xc6, 0x85, 0x8c, 0xee,
|
||||
0xa7, 0x6e, 0x80, 0x77, 0x2b, 0xe4, 0xf3, 0x5e, 0x6a, 0x44, 0x26, 0x86,
|
||||
0x04, 0x08, 0xb3, 0xa8, 0x76, 0x7e, 0x15, 0xd0, 0xe1, 0x65, 0xe9, 0x1a,
|
||||
0x2a, 0x5d, 0x3d, 0xc4, 0x0b, 0xc7, 0xe4, 0xf9, 0x7c, 0xdb, 0x14, 0xa1,
|
||||
0x5c, 0xda, 0xa8, 0xc2, 0xb6, 0x08, 0x15, 0xfe, 0x23, 0xea, 0x86, 0x5a,
|
||||
0x6f, 0x42, 0x6b, 0x9d, 0x63, 0xac, 0xaf, 0x96, 0x02, 0xac, 0x4b, 0xac,
|
||||
0x23, 0x24, 0x77, 0x54, 0x62, 0xc7, 0x0a, 0xbb, 0x4a, 0xd8, 0xeb, 0x8b,
|
||||
0xd8, 0x42, 0x1a, 0xa2, 0x54, 0x41, 0x4b, 0x9d, 0x6e, 0x8d, 0x71, 0x7f,
|
||||
0xb7, 0xbc, 0x54, 0xc5, 0x2d, 0xd4, 0xd3, 0x63, 0x8f, 0xf1, 0xa1, 0xdd,
|
||||
0x21, 0x7c, 0xbe, 0xc4, 0xc0, 0x27, 0xb1, 0x6a, 0x63, 0x2d, 0x8d, 0x8b,
|
||||
0x58, 0xb7, 0x80, 0xfa, 0x45, 0x44, 0xe6, 0x87, 0x1a, 0xe7, 0x25, 0x9a,
|
||||
0x81, 0x2a, 0x22, 0x16, 0x38, 0x54, 0xf3, 0x17, 0x78, 0x9a, 0x9a, 0xe3,
|
||||
0x94, 0x4f, 0x94, 0x78, 0x54, 0xf3, 0xb4, 0x2f, 0xf0, 0xce, 0x62, 0xb5,
|
||||
0xb6, 0xc4, 0xa8, 0xb6, 0xc4, 0xa8, 0x96, 0x8c, 0x86, 0x69, 0xd3, 0x5d,
|
||||
0xf0, 0x0f, 0x5f, 0xb4, 0x4f, 0x52, 0xff, 0x45, 0xde, 0xa6, 0xc0, 0x20,
|
||||
0x4f, 0x0c, 0x51, 0xf4, 0xe1, 0x58, 0xcb, 0xa6, 0x45, 0xdc, 0x23, 0x19,
|
||||
0xdc, 0x7b, 0xa9, 0x43, 0xdd, 0x74, 0x69, 0x0d, 0x0a, 0x49, 0x6a, 0x2c,
|
||||
0xf6, 0x86, 0xb1, 0x12, 0x85, 0x9a, 0x22, 0x05, 0x71, 0x91, 0x70, 0x89,
|
||||
0x42, 0xb8, 0x44, 0x21, 0x4c, 0x0a, 0x47, 0xcb, 0x28, 0x7c, 0x09, 0xc7,
|
||||
0xca, 0x29, 0x44, 0x17, 0xd1, 0x20, 0x29, 0x6c, 0xb8, 0xd2, 0xa1, 0x46,
|
||||
0xaf, 0xac, 0x41, 0x21, 0x45, 0xcd, 0x34, 0x8f, 0x75, 0xee, 0x8a, 0xc2,
|
||||
0x48, 0x19, 0x85, 0xa7, 0xe8, 0xcf, 0xb2, 0x38, 0x6c, 0x5d, 0xc4, 0x46,
|
||||
0x49, 0xa1, 0xf1, 0xf2, 0xd0, 0xd6, 0xcb, 0x6b, 0x30, 0x70, 0xa9, 0xc9,
|
||||
0x53, 0x9e, 0xb9, 0xab, 0x38, 0x1c, 0x2f, 0x63, 0x70, 0x02, 0x5f, 0x2e,
|
||||
0x32, 0xb8, 0x58, 0x64, 0xd0, 0x2e, 0x33, 0xe1, 0x3e, 0x32, 0x58, 0xc0,
|
||||
0xfd, 0x43, 0x75, 0x4d, 0x6c, 0x37, 0x9b, 0xce, 0xc3, 0xa8, 0xdb, 0x2c,
|
||||
0x84, 0x59, 0xf8, 0xd5, 0xf9, 0xba, 0x2d, 0xb7, 0x75, 0x0f, 0x14, 0x75,
|
||||
0xbe, 0xf9, 0xc6, 0xf9, 0x52, 0xb2, 0x6e, 0x20, 0x3c, 0xf0, 0x3c, 0x09,
|
||||
0xbe, 0xc8, 0x9a, 0x3e, 0xc3, 0xf7, 0xc5, 0x2b, 0xb2, 0x9f, 0x3c, 0xc2,
|
||||
0xff, 0x6d, 0x2e, 0x25, 0x6f, 0x7b, 0x89, 0x62, 0x7b, 0x89, 0x62, 0x3b,
|
||||
0x29, 0x76, 0x91, 0x62, 0x15, 0xe7, 0x4b, 0xc9, 0x5b, 0x09, 0xf5, 0x16,
|
||||
0x9a, 0x98, 0xb8, 0x4a, 0x58, 0x54, 0x0f, 0xbf, 0x9d, 0x8a, 0x8c, 0x77,
|
||||
0x16, 0xab, 0x39, 0x28, 0xaa, 0x67, 0x01, 0x5b, 0x57, 0xd7, 0xe1, 0xb9,
|
||||
0x65, 0x05, 0x1d, 0x2c, 0x1e, 0xa7, 0x88, 0xcf, 0x2e, 0xef, 0xfd, 0x9f,
|
||||
0x59, 0xbd, 0xff, 0x75, 0xcf, 0xfd, 0xfc, 0x62, 0x2b, 0xee, 0x6f, 0x5b,
|
||||
0xb9, 0x7f, 0xdb, 0xd2, 0x6b, 0xac, 0x50, 0xaf, 0x6f, 0x42, 0xc3, 0x5b,
|
||||
0x9e, 0x18, 0x63, 0x18, 0xbf, 0x93, 0x8e, 0xf4, 0xce, 0x9a, 0x1d, 0x69,
|
||||
0x82, 0x3a, 0x9b, 0x7d, 0xbb, 0x1c, 0xc4, 0xbf, 0x1a, 0xa4, 0xd2, 0x03,
|
||||
0x64, 0xaa, 0xb8, 0x9a, 0x92, 0x6c, 0xa6, 0xd9, 0x1f, 0x7d, 0xff, 0x9f,
|
||||
0x8d, 0xf1, 0x3f, 0xfa, 0xe3, 0x4a, 0x40, 0x47, 0x6a, 0xd3, 0xff, 0x05,
|
||||
0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00,
|
||||
0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x10, 0x00, 0xed, 0x41, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x45,
|
||||
0x54, 0x41, 0x2d, 0x49, 0x4e, 0x46, 0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14,
|
||||
0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xd9, 0x72, 0x95, 0x5c, 0xcf,
|
||||
0x58, 0x6d, 0xcb, 0x2d, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4,
|
||||
0x81, 0x29, 0x00, 0x00, 0x00, 0x4d, 0x45, 0x54, 0x41, 0x2d, 0x49, 0x4e,
|
||||
0x46, 0x2f, 0x4d, 0x41, 0x4e, 0x49, 0x46, 0x45, 0x53, 0x54, 0x2e, 0x4d,
|
||||
0x46, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08,
|
||||
0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x10, 0x00, 0xed, 0x41, 0x88, 0x00, 0x00, 0x00, 0x63,
|
||||
0x6e, 0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08,
|
||||
0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xed, 0x41, 0xab, 0x00, 0x00, 0x00,
|
||||
0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32,
|
||||
0x33, 0x33, 0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00,
|
||||
0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xed, 0x41, 0xda, 0x00, 0x00,
|
||||
0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75,
|
||||
0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65,
|
||||
0x6e, 0x74, 0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00,
|
||||
0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xed, 0x41, 0x14, 0x01, 0x00,
|
||||
0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75,
|
||||
0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65,
|
||||
0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14,
|
||||
0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00,
|
||||
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xed,
|
||||
0x41, 0x52, 0x01, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f,
|
||||
0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63,
|
||||
0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x62,
|
||||
0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x2f, 0x50, 0x4b, 0x01,
|
||||
0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95,
|
||||
0x5c, 0x89, 0xbd, 0x76, 0xf7, 0x74, 0x01, 0x00, 0x00, 0xf9, 0x02, 0x00,
|
||||
0x00, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xa4, 0x81, 0x9a, 0x01, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69,
|
||||
0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75,
|
||||
0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69,
|
||||
0x2f, 0x62, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x2f, 0x42,
|
||||
0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x42, 0x72, 0x69, 0x64,
|
||||
0x67, 0x65, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x50, 0x4b, 0x01, 0x02,
|
||||
0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c,
|
||||
0xfd, 0xd1, 0xa0, 0x53, 0xac, 0x00, 0x00, 0x00, 0xd2, 0x00, 0x00, 0x00,
|
||||
0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xa4, 0x81, 0x69, 0x03, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61,
|
||||
0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69,
|
||||
0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f,
|
||||
0x62, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x2f, 0x4c, 0x6f,
|
||||
0x61, 0x64, 0x65, 0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2e, 0x63,
|
||||
0x6c, 0x61, 0x73, 0x73, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00,
|
||||
0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x7b, 0x04, 0xd3, 0xdd,
|
||||
0x5f, 0x04, 0x00, 0x00, 0xf7, 0x07, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x6d, 0x04,
|
||||
0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f,
|
||||
0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67,
|
||||
0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x49, 0x6e, 0x6a, 0x65,
|
||||
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x63, 0x6c,
|
||||
0x61, 0x73, 0x73, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00,
|
||||
0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x40, 0xc9, 0x71, 0xc0, 0x05,
|
||||
0x02, 0x00, 0x00, 0xae, 0x04, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x1b, 0x09, 0x00,
|
||||
0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75,
|
||||
0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65,
|
||||
0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x4a, 0x75, 0x69, 0x63, 0x65,
|
||||
0x41, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x50,
|
||||
0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd,
|
||||
0x72, 0x95, 0x5c, 0x09, 0xad, 0xfd, 0x53, 0x35, 0x02, 0x00, 0x00, 0x34,
|
||||
0x04, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xa4, 0x81, 0x6c, 0x0b, 0x00, 0x00, 0x63, 0x6e, 0x2f,
|
||||
0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f,
|
||||
0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x2f, 0x4a, 0x75, 0x69, 0x63, 0x65, 0x41, 0x67, 0x65, 0x6e,
|
||||
0x74, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x24, 0x31,
|
||||
0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03,
|
||||
0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x8f, 0x63,
|
||||
0xf6, 0x0e, 0x07, 0x04, 0x00, 0x00, 0x35, 0x08, 0x00, 0x00, 0x37, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81,
|
||||
0xf8, 0x0d, 0x00, 0x00, 0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a,
|
||||
0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65,
|
||||
0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x4a, 0x75,
|
||||
0x69, 0x63, 0x65, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x6f, 0x6f, 0x74,
|
||||
0x73, 0x74, 0x72, 0x61, 0x70, 0x2e, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x50,
|
||||
0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd,
|
||||
0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x10, 0x00, 0xed, 0x41, 0x54, 0x12, 0x00, 0x00, 0x63, 0x6e, 0x2f,
|
||||
0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f,
|
||||
0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x2f, 0x50,
|
||||
0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00, 0xdd,
|
||||
0x72, 0x95, 0x5c, 0x19, 0x77, 0xde, 0xdf, 0x52, 0x08, 0x00, 0x00, 0xcd,
|
||||
0x11, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xa4, 0x81, 0x9a, 0x12, 0x00, 0x00, 0x63, 0x6e, 0x2f,
|
||||
0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33, 0x2f,
|
||||
0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x2f, 0x4a,
|
||||
0x61, 0x72, 0x4c, 0x6f, 0x61, 0x64, 0x65, 0x72, 0x2e, 0x63, 0x6c, 0x61,
|
||||
0x73, 0x73, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08,
|
||||
0x08, 0x00, 0xdd, 0x72, 0x95, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xed, 0x41, 0x3f, 0x1b, 0x00, 0x00,
|
||||
0x63, 0x6e, 0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32,
|
||||
0x33, 0x33, 0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e,
|
||||
0x74, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x73, 0x2f,
|
||||
0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00, 0x08, 0x08, 0x00,
|
||||
0xdd, 0x72, 0x95, 0x5c, 0x50, 0xe7, 0x20, 0x38, 0xbd, 0x07, 0x00, 0x00,
|
||||
0xd4, 0x10, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x83, 0x1b, 0x00, 0x00, 0x63, 0x6e,
|
||||
0x2f, 0x78, 0x69, 0x61, 0x6f, 0x7a, 0x68, 0x6f, 0x75, 0x32, 0x33, 0x33,
|
||||
0x2f, 0x6a, 0x75, 0x69, 0x63, 0x65, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f,
|
||||
0x61, 0x70, 0x69, 0x2f, 0x75, 0x74, 0x69, 0x6c, 0x73, 0x2f, 0x44, 0x65,
|
||||
0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x72, 0x2e, 0x63,
|
||||
0x6c, 0x61, 0x73, 0x73, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00,
|
||||
0x11, 0x00, 0x11, 0x00, 0x98, 0x05, 0x00, 0x00, 0x94, 0x23, 0x00, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
static const std::size_t juiceagent_api_bytes_len = 10562;
|
||||
static const char* juiceagent_api_bytes_name = "JuiceAgent-API-1.4.1+build.1.jar";
|
||||
static const char* juiceagent_api_bytes_mime = "application/java-archive";
|
||||
static const char* juiceagent_api_bytes_sha256 = "089954f82770dbb59e36f6a168d50d3e9493051ca11fea7e9f0fc81d863df6b0";
|
||||
|
||||
} // namespace JuiceAgent::Resource
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef JUICEAGENT_H
|
||||
#define JUICEAGENT_H
|
||||
|
||||
#define INJECT_PATH_MAX 260
|
||||
|
||||
typedef struct _InjectionInfo {
|
||||
char BootstrapAPIPath[INJECT_PATH_MAX];
|
||||
char JuiceLoaderJarPath[INJECT_PATH_MAX];
|
||||
char EntryJarPath[INJECT_PATH_MAX];
|
||||
char EntryClass[INJECT_PATH_MAX];
|
||||
char EntryMethod[INJECT_PATH_MAX];
|
||||
char InjectionDir[INJECT_PATH_MAX];
|
||||
char JuiceLoaderLibraryPath[INJECT_PATH_MAX];
|
||||
} InjectionInfoType;
|
||||
|
||||
extern InjectionInfoType InjectionInfo;
|
||||
|
||||
#endif // JUICEAGENT_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
struct LoaderConfig {
|
||||
std::string JuiceAgentNativeLibraryPath;
|
||||
|
||||
std::string RuntimeDir;
|
||||
};
|
||||
@@ -3,15 +3,16 @@
|
||||
#include <plog/Log.h>
|
||||
#include <plog/Init.h>
|
||||
#include <plog/Formatters/TxtFormatter.h>
|
||||
#include <plog/Appenders/ConsoleAppender.h>
|
||||
#include <plog/Appenders/ColorConsoleAppender.h>
|
||||
#include <plog/Appenders/DebugOutputAppender.h>
|
||||
#include <plog/Appenders/RollingFileAppender.h>
|
||||
|
||||
inline void InitLogger()
|
||||
{
|
||||
static plog::ConsoleAppender<plog::TxtFormatter> consoleAppender;
|
||||
static plog::ColorConsoleAppender<plog::TxtFormatter> colorConsoleAppender;
|
||||
static plog::DebugOutputAppender<plog::TxtFormatter> debugAppender;
|
||||
|
||||
plog::init(plog::debug, &consoleAppender).addAppender(&debugAppender);
|
||||
plog::init(plog::debug, &colorConsoleAppender).addAppender(&debugAppender);
|
||||
|
||||
PLOG_INFO << "Logger initialized: Console + Debug Output";
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <type_traits>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <chrono>
|
||||
#include <stdexcept>
|
||||
|
||||
// Check for JNI exceptions and clear them
|
||||
inline bool check_and_clear_exception(JNIEnv* env, const char* context) {
|
||||
if (env->ExceptionCheck()) {
|
||||
PLOGE << "JNI Exception occurred at: " << context;
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace JuiceAgent::Utils
|
||||
{
|
||||
inline bool call_java_impl(JNIEnv* env, const char* clazz, const char* method, const char* params) {
|
||||
if (!env || !clazz || !method) {
|
||||
PLOGE << "Invalid JNI arguments";
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr const char* method_signature = "(Ljava/lang/String;)V";
|
||||
|
||||
PLOGD << "Calling Java method: " << clazz << "." << method << " " << method_signature;
|
||||
|
||||
jclass cls = env->FindClass(clazz);
|
||||
if (!cls) {
|
||||
check_and_clear_exception(env, "FindClass failed");
|
||||
PLOGE << "Class not found: " << clazz;
|
||||
return false;
|
||||
}
|
||||
|
||||
jmethodID mid = env->GetStaticMethodID(cls, method, method_signature);
|
||||
if (!mid) {
|
||||
check_and_clear_exception(env, "GetStaticMethodID failed");
|
||||
PLOGE << "Method not found: " << method;
|
||||
env->DeleteLocalRef(cls);
|
||||
return false;
|
||||
}
|
||||
|
||||
jstring j_params = env->NewStringUTF(params ? params : "");
|
||||
if (!j_params) {
|
||||
PLOGE << "Failed to create jstring";
|
||||
env->DeleteLocalRef(cls);
|
||||
return false;
|
||||
}
|
||||
|
||||
env->CallStaticVoidMethod(cls, mid, j_params);
|
||||
|
||||
bool success = !env->ExceptionCheck();
|
||||
|
||||
check_and_clear_exception(env, "CallStaticVoidMethod failed");
|
||||
|
||||
env->DeleteLocalRef(j_params);
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
class Serializer {
|
||||
private:
|
||||
std::string s;
|
||||
|
||||
private:
|
||||
static std::string escape(const std::string& input) {
|
||||
std::string out;
|
||||
out.reserve(input.size());
|
||||
|
||||
for (char c : input) {
|
||||
if (c == '=' || c == ';' || c == '\\') {
|
||||
out += '\\';
|
||||
}
|
||||
out += c;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public:
|
||||
Serializer() = default;
|
||||
|
||||
Serializer& add_kv(const std::string& key, const std::string& value) {
|
||||
s += escape(key);
|
||||
s += '=';
|
||||
s += escape(value);
|
||||
s += ';';
|
||||
return *this;
|
||||
}
|
||||
|
||||
Serializer& add_kv(const std::string& key, const char* value) {
|
||||
return add_kv(key, std::string(value));
|
||||
}
|
||||
|
||||
Serializer& add_kv(const std::string& key, int value) {
|
||||
return add_kv(key, std::to_string(value));
|
||||
}
|
||||
|
||||
Serializer& add_kv(const std::string& key, bool value) {
|
||||
return add_kv(key, value ? "true" : "false");
|
||||
}
|
||||
|
||||
void clear() {
|
||||
s.clear();
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return s.empty();
|
||||
}
|
||||
|
||||
const std::string& serialize() const {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Deserializer {
|
||||
private:
|
||||
std::unordered_map<std::string, std::string> data;
|
||||
|
||||
private:
|
||||
static std::string unescape(const std::string& input) {
|
||||
std::string out;
|
||||
out.reserve(input.size());
|
||||
|
||||
bool escaped = false;
|
||||
|
||||
for (char c : input) {
|
||||
if (escaped) {
|
||||
out += c;
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\\') {
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
out += c;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool to_bool(const std::string& v, bool def) {
|
||||
if (v == "true" || v == "1") return true;
|
||||
if (v == "false" || v == "0") return false;
|
||||
return def;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T convert(const std::string& v, T def) {
|
||||
if constexpr (std::is_same_v<T, std::string>) {
|
||||
return v;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, bool>) {
|
||||
return to_bool(v, def);
|
||||
}
|
||||
else if constexpr (std::is_integral_v<T>) {
|
||||
try {
|
||||
long long n = std::stoll(v);
|
||||
return static_cast<T>(n);
|
||||
} catch (...) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
else if constexpr (std::is_floating_point_v<T>) {
|
||||
try {
|
||||
long double n = std::stold(v);
|
||||
return static_cast<T>(n);
|
||||
} catch (...) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
Deserializer() = default;
|
||||
|
||||
explicit Deserializer(const std::string& input) {
|
||||
parse(input);
|
||||
}
|
||||
|
||||
void parse(const std::string& input) {
|
||||
data.clear();
|
||||
|
||||
std::string key;
|
||||
std::string value;
|
||||
|
||||
bool reading_key = true;
|
||||
bool escaped = false;
|
||||
|
||||
for (char c : input) {
|
||||
if (escaped) {
|
||||
(reading_key ? key : value) += c;
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\\') {
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (reading_key && c == '=') {
|
||||
reading_key = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == ';') {
|
||||
if (!key.empty()) {
|
||||
data[unescape(key)] = unescape(value);
|
||||
}
|
||||
|
||||
key.clear();
|
||||
value.clear();
|
||||
reading_key = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
(reading_key ? key : value) += c;
|
||||
}
|
||||
|
||||
if (!key.empty()) {
|
||||
data[unescape(key)] = unescape(value);
|
||||
}
|
||||
}
|
||||
|
||||
bool has(const std::string& key) const {
|
||||
return data.find(key) != data.end();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T get(const std::string& key, T def) const {
|
||||
auto it = data.find(key);
|
||||
if (it == data.end()) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return convert<T>(it->second, def);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return data.empty();
|
||||
}
|
||||
|
||||
std::size_t size() const {
|
||||
return data.size();
|
||||
}
|
||||
};
|
||||
|
||||
class File {
|
||||
public:
|
||||
static inline std::string write_to_tempfile(
|
||||
const unsigned char* data,
|
||||
std::size_t size,
|
||||
const std::string& name
|
||||
) {
|
||||
#ifdef _WIN32
|
||||
const char* env = std::getenv("TEMP");
|
||||
std::filesystem::path dir = env ? env : ".";
|
||||
#else
|
||||
const char* env = std::getenv("TMPDIR");
|
||||
std::filesystem::path dir = env ? env : "/tmp";
|
||||
#endif
|
||||
|
||||
auto path = dir / name;
|
||||
|
||||
std::ofstream out(path, std::ios::binary | std::ios::trunc);
|
||||
if (!out) {
|
||||
PLOGE << "Failed to create temp file " << path;
|
||||
return "";
|
||||
}
|
||||
|
||||
out.write(reinterpret_cast<const char*>(data), size);
|
||||
return path.string();
|
||||
}
|
||||
};
|
||||
} // namespace JuiceAgent::Utils
|
||||
|
||||
@@ -0,0 +1,498 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CALLBACKLIST_H_588722158669
|
||||
#define CALLBACKLIST_H_588722158669
|
||||
|
||||
#include "eventpolicies.h"
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <cassert>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <
|
||||
typename Prototype,
|
||||
typename PoliciesType
|
||||
>
|
||||
class CallbackListBase;
|
||||
|
||||
template <
|
||||
typename PoliciesType,
|
||||
typename ReturnType, typename ...Args
|
||||
>
|
||||
class CallbackListBase<
|
||||
ReturnType (Args...),
|
||||
PoliciesType
|
||||
>
|
||||
{
|
||||
private:
|
||||
using Policies = PoliciesType;
|
||||
|
||||
using Threading = typename SelectThreading<Policies, HasTypeThreading<Policies>::value>::Type;
|
||||
|
||||
using Callback_ = typename SelectCallback<
|
||||
Policies,
|
||||
HasTypeCallback<Policies>::value,
|
||||
std::function<ReturnType (Args...)>
|
||||
>::Type;
|
||||
|
||||
using CanContinueInvoking = typename SelectCanContinueInvoking<
|
||||
Policies, HasFunctionCanContinueInvoking<Policies, Args...>::value
|
||||
>::Type;
|
||||
|
||||
struct Node;
|
||||
using NodePtr = std::shared_ptr<Node>;
|
||||
|
||||
struct Node
|
||||
{
|
||||
using Counter = unsigned int;
|
||||
|
||||
Node(const Callback_ & callback, const Counter counter)
|
||||
: callback(callback), counter(counter)
|
||||
{
|
||||
}
|
||||
|
||||
NodePtr previous;
|
||||
NodePtr next;
|
||||
Callback_ callback;
|
||||
Counter counter;
|
||||
};
|
||||
|
||||
class Handle_ : public std::weak_ptr<Node>
|
||||
{
|
||||
private:
|
||||
using super = std::weak_ptr<Node>;
|
||||
|
||||
public:
|
||||
using super::super;
|
||||
|
||||
operator bool () const noexcept {
|
||||
return ! this->expired();
|
||||
}
|
||||
};
|
||||
|
||||
using Counter = typename Node::Counter;
|
||||
enum : Counter {
|
||||
removedCounter = 0
|
||||
};
|
||||
|
||||
public:
|
||||
using Callback = Callback_;
|
||||
using Handle = Handle_;
|
||||
using Mutex = typename Threading::Mutex;
|
||||
|
||||
public:
|
||||
CallbackListBase() noexcept
|
||||
:
|
||||
head(),
|
||||
tail(),
|
||||
mutex(),
|
||||
currentCounter(0)
|
||||
{
|
||||
}
|
||||
|
||||
CallbackListBase(const CallbackListBase & other)
|
||||
: CallbackListBase()
|
||||
{
|
||||
cloneFrom(other.head);
|
||||
}
|
||||
|
||||
CallbackListBase(CallbackListBase && other) noexcept
|
||||
: CallbackListBase()
|
||||
{
|
||||
swap(other);
|
||||
}
|
||||
|
||||
// If we use pass by value idiom and omit the 'this' check,
|
||||
// when assigning to self there is a deep copy which is inefficient.
|
||||
CallbackListBase & operator = (const CallbackListBase & other) {
|
||||
if(this != &other) {
|
||||
CallbackListBase copied(other);
|
||||
swap(copied);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
CallbackListBase & operator = (CallbackListBase && other) noexcept {
|
||||
if(this != &other) {
|
||||
doFreeAllNodes();
|
||||
|
||||
head = std::move(other.head);
|
||||
tail = std::move(other.tail);
|
||||
currentCounter = other.currentCounter.load();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~CallbackListBase() {
|
||||
// Don't lock mutex here since it may throw exception
|
||||
|
||||
doFreeAllNodes();
|
||||
}
|
||||
|
||||
void swap(CallbackListBase & other) noexcept {
|
||||
using std::swap;
|
||||
|
||||
swap(head, other.head);
|
||||
swap(tail, other.tail);
|
||||
|
||||
const auto value = currentCounter.load();
|
||||
currentCounter.exchange(other.currentCounter.load());
|
||||
other.currentCounter.exchange(value);
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
// Don't lock the mutex for performance reason.
|
||||
// !head still works even when the underlying raw pointer is garbled (for other thread is writting to head)
|
||||
// And empty() doesn't guarantee the list is still empty after the function returned.
|
||||
//std::lock_guard<Mutex> lockGuard(mutex);
|
||||
|
||||
return ! head;
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return ! empty();
|
||||
}
|
||||
|
||||
Handle append(const Callback & callback)
|
||||
{
|
||||
NodePtr node(doAllocateNode(callback));
|
||||
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
|
||||
if(head) {
|
||||
node->previous = tail;
|
||||
tail->next = node;
|
||||
tail = node;
|
||||
}
|
||||
else {
|
||||
head = node;
|
||||
tail = node;
|
||||
}
|
||||
|
||||
return Handle(node);
|
||||
}
|
||||
|
||||
Handle prepend(const Callback & callback)
|
||||
{
|
||||
NodePtr node(doAllocateNode(callback));
|
||||
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
|
||||
if(head) {
|
||||
node->next = head;
|
||||
head->previous = node;
|
||||
head = node;
|
||||
}
|
||||
else {
|
||||
head = node;
|
||||
tail = node;
|
||||
}
|
||||
|
||||
return Handle(node);
|
||||
}
|
||||
|
||||
Handle insert(const Callback & callback, const Handle & before)
|
||||
{
|
||||
// Disable this assertion because it's too slow in debug mode.
|
||||
//assert(before.expired() || ownsHandle(before));
|
||||
|
||||
NodePtr beforeNode = before.lock();
|
||||
if(beforeNode) {
|
||||
NodePtr node(doAllocateNode(callback));
|
||||
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
|
||||
doInsert(node, beforeNode);
|
||||
|
||||
return Handle(node);
|
||||
}
|
||||
|
||||
return append(callback);
|
||||
}
|
||||
|
||||
bool remove(const Handle & handle)
|
||||
{
|
||||
// Disable this assertion because it's too slow in debug mode.
|
||||
//assert(handle.expired() || ownsHandle(handle));
|
||||
|
||||
// It looks like the lock can be put inside the `if` below,
|
||||
// but that doesn't work in multi-threading and cause related unit tests fail.
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
|
||||
auto node = handle.lock();
|
||||
if(node) {
|
||||
doFreeNode(node);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ownsHandle(const Handle & handle) const
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
|
||||
auto node = handle.lock();
|
||||
if(node) {
|
||||
while(node->previous) {
|
||||
node = node->previous;
|
||||
}
|
||||
return node == head;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
void forEach(Func && func) const
|
||||
{
|
||||
doForEachIf([&func, this](NodePtr & node) -> bool {
|
||||
doForEachInvoke<void>(func, node);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
bool forEachIf(Func && func) const
|
||||
{
|
||||
return doForEachIf([&func, this](NodePtr & node) -> bool {
|
||||
return doForEachInvoke<bool>(func, node);
|
||||
});
|
||||
}
|
||||
|
||||
#if !defined(__GNUC__) || __GNUC__ >= 5
|
||||
void operator() (Args ...args) const
|
||||
{
|
||||
forEachIf([&args...](Callback & callback) -> bool {
|
||||
// We can't use std::forward here, because if we use std::forward,
|
||||
// for arg that is passed by value, and the callback prototype accepts it by value,
|
||||
// std::forward will move it and may cause the original value invalid.
|
||||
// That happens on any value-to-value passing, no matter the callback moves it or not.
|
||||
|
||||
callback(args...);
|
||||
return CanContinueInvoking::canContinueInvoking(args...);
|
||||
});
|
||||
}
|
||||
#else
|
||||
// This is a patch version for GCC 4. It inlines the unrolled doForEachIf.
|
||||
// GCC 4.8.3 doesn't supporting parameter pack catpure in lambda, see,
|
||||
// https://github.com/wqking/eventpp/issues/19
|
||||
// This is a compromised patch for GCC 4, it may be not maintained or updated unless there are bugs.
|
||||
// We don't use the patch as main code because the patch generates longer code, and duplicated with doForEachIf.
|
||||
void operator() (Args ...args) const
|
||||
{
|
||||
NodePtr node;
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
node = head;
|
||||
}
|
||||
|
||||
const Counter counter = currentCounter.load(std::memory_order_acquire);
|
||||
|
||||
while(node) {
|
||||
if(node->counter != removedCounter && counter >= node->counter) {
|
||||
node->callback(args...);
|
||||
if(! CanContinueInvoking::canContinueInvoking(args...)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
template <typename F>
|
||||
bool doForEachIf(F && f) const
|
||||
{
|
||||
NodePtr node;
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
node = head;
|
||||
}
|
||||
|
||||
const Counter counter = currentCounter.load(std::memory_order_acquire);
|
||||
|
||||
while(node) {
|
||||
if(node->counter != removedCounter && counter >= node->counter) {
|
||||
if(! f(node)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename RT, typename Func>
|
||||
auto doForEachInvoke(Func && func, NodePtr & node) const
|
||||
-> typename std::enable_if<CanInvoke<Func, Handle, Callback &>::value, RT>::type
|
||||
{
|
||||
return func(Handle(node), node->callback);
|
||||
}
|
||||
|
||||
template <typename RT, typename Func>
|
||||
auto doForEachInvoke(Func && func, NodePtr & node) const
|
||||
-> typename std::enable_if<CanInvoke<Func, Callback &>::value, RT>::type
|
||||
{
|
||||
return func(node->callback);
|
||||
}
|
||||
|
||||
void doInsert(NodePtr & node, NodePtr & beforeNode)
|
||||
{
|
||||
node->previous = beforeNode->previous;
|
||||
node->next = beforeNode;
|
||||
if(beforeNode->previous) {
|
||||
beforeNode->previous->next = node;
|
||||
}
|
||||
beforeNode->previous = node;
|
||||
|
||||
if(beforeNode == head) {
|
||||
head = node;
|
||||
}
|
||||
}
|
||||
|
||||
NodePtr doAllocateNode(const Callback & callback)
|
||||
{
|
||||
return std::make_shared<Node>(callback, getNextCounter());
|
||||
}
|
||||
|
||||
void doFreeNode(NodePtr & node)
|
||||
{
|
||||
if(node->next) {
|
||||
node->next->previous = node->previous;
|
||||
}
|
||||
if(node->previous) {
|
||||
node->previous->next = node->next;
|
||||
}
|
||||
|
||||
// Mark it as deleted, this must be before the assignment of head and tail below,
|
||||
// because node can be a reference to head or tail, and after the assignment, node
|
||||
// can be null pointer.
|
||||
node->counter = removedCounter;
|
||||
|
||||
if(head == node) {
|
||||
head = node->next;
|
||||
}
|
||||
if(tail == node) {
|
||||
tail = node->previous;
|
||||
}
|
||||
|
||||
// don't modify node->previous or node->next
|
||||
// because node may be still used in a loop.
|
||||
}
|
||||
|
||||
void doFreeAllNodes() {
|
||||
NodePtr node = head;
|
||||
head.reset();
|
||||
while(node) {
|
||||
NodePtr next = node->next;
|
||||
node->previous.reset();
|
||||
node->next.reset();
|
||||
node = next;
|
||||
}
|
||||
node.reset();
|
||||
}
|
||||
|
||||
Counter getNextCounter()
|
||||
{
|
||||
Counter result = ++currentCounter;;
|
||||
if(result == 0) { // overflow, let's reset all nodes' counters.
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(mutex);
|
||||
NodePtr node = head;
|
||||
while(node) {
|
||||
node->counter = 1;
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
result = ++currentCounter;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void cloneFrom(const NodePtr & fromHead) {
|
||||
NodePtr fromNode(fromHead);
|
||||
NodePtr node;
|
||||
const Counter counter = getNextCounter();
|
||||
while(fromNode) {
|
||||
const NodePtr nextNode(std::make_shared<Node>(fromNode->callback, counter));
|
||||
|
||||
nextNode->previous = node;
|
||||
|
||||
if(node) {
|
||||
node->next = nextNode;
|
||||
}
|
||||
else {
|
||||
node = nextNode;
|
||||
head = node;
|
||||
}
|
||||
|
||||
node = nextNode;
|
||||
fromNode = fromNode->next;
|
||||
}
|
||||
|
||||
tail = node;
|
||||
}
|
||||
|
||||
private:
|
||||
NodePtr head;
|
||||
NodePtr tail;
|
||||
mutable Mutex mutex;
|
||||
typename Threading::template Atomic<Counter> currentCounter;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
|
||||
template <
|
||||
typename Prototype_,
|
||||
typename Policies_ = DefaultPolicies
|
||||
>
|
||||
class CallbackList : public internal_::CallbackListBase<Prototype_, Policies_>, public TagCallbackList
|
||||
{
|
||||
private:
|
||||
using super = internal_::CallbackListBase<Prototype_, Policies_>;
|
||||
|
||||
public:
|
||||
using super::super;
|
||||
|
||||
friend void swap(CallbackList & first, CallbackList & second) noexcept {
|
||||
first.swap(second);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,328 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef EVENTDISPATCHER_H_319010983013
|
||||
#define EVENTDISPATCHER_H_319010983013
|
||||
|
||||
#include "callbacklist.h"
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <
|
||||
typename EventType_,
|
||||
typename Prototype_,
|
||||
typename Policies_,
|
||||
typename MixinRoot_
|
||||
>
|
||||
class EventDispatcherBase;
|
||||
|
||||
template <
|
||||
typename EventType_,
|
||||
typename Policies_,
|
||||
typename MixinRoot_,
|
||||
typename ReturnType, typename ...Args
|
||||
>
|
||||
class EventDispatcherBase <
|
||||
EventType_,
|
||||
ReturnType (Args...),
|
||||
Policies_,
|
||||
MixinRoot_
|
||||
>
|
||||
{
|
||||
protected:
|
||||
using ThisType = EventDispatcherBase<
|
||||
EventType_,
|
||||
ReturnType (Args...),
|
||||
Policies_,
|
||||
MixinRoot_
|
||||
>;
|
||||
using MixinRoot = typename std::conditional<
|
||||
std::is_same<MixinRoot_, void>::value,
|
||||
ThisType,
|
||||
MixinRoot_
|
||||
>::type;
|
||||
using Policies = Policies_;
|
||||
|
||||
using Threading = typename SelectThreading<Policies_, HasTypeThreading<Policies_>::value>::Type;
|
||||
|
||||
using ArgumentPassingMode = typename SelectArgumentPassingMode<
|
||||
Policies_,
|
||||
HasTypeArgumentPassingMode<Policies_>::value,
|
||||
ArgumentPassingAutoDetect
|
||||
>::Type;
|
||||
|
||||
using Callback_ = typename SelectCallback<
|
||||
Policies_,
|
||||
HasTypeCallback<Policies_>::value,
|
||||
std::function<ReturnType (Args...)>
|
||||
>::Type;
|
||||
using CallbackList_ = CallbackList<ReturnType (Args...), Policies_>;
|
||||
|
||||
using Prototype = ReturnType (Args...);
|
||||
|
||||
using Map = typename SelectMap<
|
||||
EventType_,
|
||||
CallbackList_,
|
||||
Policies_,
|
||||
HasTemplateMap<Policies_>::value
|
||||
>::Type;
|
||||
|
||||
using Mixins = typename internal_::SelectMixins<
|
||||
Policies_,
|
||||
internal_::HasTypeMixins<Policies_>::value
|
||||
>::Type;
|
||||
|
||||
public:
|
||||
using Handle = typename CallbackList_::Handle;
|
||||
using Callback = Callback_;
|
||||
using Event = EventType_;
|
||||
using Mutex = typename Threading::Mutex;
|
||||
|
||||
public:
|
||||
EventDispatcherBase()
|
||||
:
|
||||
eventCallbackListMap(),
|
||||
listenerMutex()
|
||||
{
|
||||
}
|
||||
|
||||
EventDispatcherBase(const EventDispatcherBase & other)
|
||||
:
|
||||
eventCallbackListMap(other.eventCallbackListMap),
|
||||
listenerMutex()
|
||||
{
|
||||
}
|
||||
|
||||
EventDispatcherBase(EventDispatcherBase && other) noexcept
|
||||
:
|
||||
eventCallbackListMap(std::move(other.eventCallbackListMap)),
|
||||
listenerMutex()
|
||||
{
|
||||
}
|
||||
|
||||
EventDispatcherBase & operator = (const EventDispatcherBase & other)
|
||||
{
|
||||
eventCallbackListMap = other.eventCallbackListMap;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EventDispatcherBase & operator = (EventDispatcherBase && other) noexcept
|
||||
{
|
||||
eventCallbackListMap = std::move(other.eventCallbackListMap);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(EventDispatcherBase & other) noexcept {
|
||||
using std::swap;
|
||||
|
||||
swap(eventCallbackListMap, other.eventCallbackListMap);
|
||||
}
|
||||
|
||||
Handle appendListener(const Event & event, const Callback & callback)
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(listenerMutex);
|
||||
|
||||
return eventCallbackListMap[event].append(callback);
|
||||
}
|
||||
|
||||
Handle prependListener(const Event & event, const Callback & callback)
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(listenerMutex);
|
||||
|
||||
return eventCallbackListMap[event].prepend(callback);
|
||||
}
|
||||
|
||||
Handle insertListener(const Event & event, const Callback & callback, const Handle & before)
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(listenerMutex);
|
||||
|
||||
return eventCallbackListMap[event].insert(callback, before);
|
||||
}
|
||||
|
||||
bool removeListener(const Event & event, const Handle handle)
|
||||
{
|
||||
CallbackList_ * callableList = doFindCallableList(event);
|
||||
if(callableList) {
|
||||
return callableList->remove(handle);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasAnyListener(const Event & event) const
|
||||
{
|
||||
const CallbackList_ * callableList = doFindCallableList(event);
|
||||
if(callableList) {
|
||||
return ! callableList->empty();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ownsHandle(const Event & event, const Handle & handle) const
|
||||
{
|
||||
const CallbackList_ * callableList = doFindCallableList(event);
|
||||
if(callableList) {
|
||||
return callableList->ownsHandle(handle);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
void forEach(const Event & event, Func && func) const
|
||||
{
|
||||
const CallbackList_ * callableList = doFindCallableList(event);
|
||||
if(callableList) {
|
||||
callableList->forEach(std::forward<Func>(func));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
bool forEachIf(const Event & event, Func && func) const
|
||||
{
|
||||
const CallbackList_ * callableList = doFindCallableList(event);
|
||||
if (callableList) {
|
||||
return callableList->forEachIf(std::forward<Func>(func));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dispatch(Args ...args) const
|
||||
{
|
||||
static_assert(ArgumentPassingMode::canIncludeEventType, "Dispatching arguments count doesn't match required (Event type should be included).");
|
||||
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, Args...>::value>::Type;
|
||||
|
||||
// can't std::forward<Args>(args) in GetEvent::getEvent because the pass by value arguments will be moved to getEvent
|
||||
// then the other std::forward<Args>(args) to directDispatch will get empty values.
|
||||
directDispatch(
|
||||
GetEvent::getEvent(args...),
|
||||
std::forward<Args>(args)...
|
||||
);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void dispatch(T && first, Args ...args) const
|
||||
{
|
||||
static_assert(ArgumentPassingMode::canExcludeEventType, "Dispatching arguments count doesn't match required (Event type should NOT be included).");
|
||||
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, T &&, Args...>::value>::Type;
|
||||
|
||||
directDispatch(
|
||||
GetEvent::getEvent(std::forward<T>(first), args...),
|
||||
std::forward<Args>(args)...
|
||||
);
|
||||
}
|
||||
|
||||
// Bypass any getEvent policy. The first argument is the event type.
|
||||
// Most used for internal purpose.
|
||||
void directDispatch(const Event & e, Args ...args) const
|
||||
{
|
||||
if(! internal_::ForEachMixins<MixinRoot, Mixins, DoMixinBeforeDispatch>::forEach(
|
||||
this, typename std::add_lvalue_reference<Args>::type(args)...)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const CallbackList_ * callableList = doFindCallableList(e);
|
||||
if(callableList) {
|
||||
(*callableList)(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
const CallbackList_ * doFindCallableList(const Event & e) const
|
||||
{
|
||||
return doFindCallableListHelper(this, e);
|
||||
}
|
||||
|
||||
CallbackList_ * doFindCallableList(const Event & e)
|
||||
{
|
||||
return doFindCallableListHelper(this, e);
|
||||
}
|
||||
|
||||
private:
|
||||
// template helper to avoid code duplication in doFindCallableList
|
||||
template <typename T>
|
||||
static auto doFindCallableListHelper(T * self, const Event & e)
|
||||
-> typename std::conditional<std::is_const<T>::value, const CallbackList_ *, CallbackList_ *>::type
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(self->listenerMutex);
|
||||
|
||||
auto it = self->eventCallbackListMap.find(e);
|
||||
if(it != self->eventCallbackListMap.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Mixin related
|
||||
struct DoMixinBeforeDispatch
|
||||
{
|
||||
template <typename T, typename Self, typename ...A>
|
||||
static auto forEach(const Self * self, A && ...args)
|
||||
-> typename std::enable_if<HasFunctionMixinBeforeDispatch<T, A...>::value, bool>::type {
|
||||
return static_cast<const T *>(self)->mixinBeforeDispatch(std::forward<A>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename Self, typename ...A>
|
||||
static auto forEach(const Self * /*self*/, A && ... /*args*/)
|
||||
-> typename std::enable_if<! HasFunctionMixinBeforeDispatch<T, A...>::value, bool>::type {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
Map eventCallbackListMap;
|
||||
mutable Mutex listenerMutex;
|
||||
};
|
||||
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
template <
|
||||
typename Event_,
|
||||
typename Prototype_,
|
||||
typename Policies_ = DefaultPolicies
|
||||
>
|
||||
class EventDispatcher : public internal_::InheritMixins<
|
||||
internal_::EventDispatcherBase<Event_, Prototype_, Policies_, void>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type, public TagEventDispatcher
|
||||
{
|
||||
private:
|
||||
using super = typename internal_::InheritMixins<
|
||||
internal_::EventDispatcherBase<Event_, Prototype_, Policies_, void>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type;
|
||||
|
||||
public:
|
||||
using super::super;
|
||||
|
||||
friend void swap(EventDispatcher & first, EventDispatcher & second) noexcept {
|
||||
first.swap(second);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef EVENTOPTIONS_H_730367862613
|
||||
#define EVENTOPTIONS_H_730367862613
|
||||
|
||||
#include "internal/typeutil_i.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <list>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
struct TagHomo {};
|
||||
struct TagCallbackList : public TagHomo {};
|
||||
struct TagEventDispatcher : public TagHomo {};
|
||||
struct TagEventQueue : public TagHomo {};
|
||||
|
||||
struct TagHeter {};
|
||||
struct TagHeterCallbackList : public TagHeter {};
|
||||
struct TagHeterEventDispatcher : public TagHeter {};
|
||||
struct TagHeterEventQueue : public TagHeter {};
|
||||
|
||||
struct SpinLock
|
||||
{
|
||||
public:
|
||||
void lock() {
|
||||
while(locked.test_and_set(std::memory_order_acquire)) {
|
||||
}
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
locked.clear(std::memory_order_release);
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic_flag locked = ATOMIC_FLAG_INIT;
|
||||
};
|
||||
|
||||
template <
|
||||
typename Mutex_,
|
||||
template <typename > class Atomic_ = std::atomic,
|
||||
typename ConditionVariable_ = std::condition_variable
|
||||
>
|
||||
struct GeneralThreading
|
||||
{
|
||||
using Mutex = Mutex_;
|
||||
|
||||
template <typename T>
|
||||
using Atomic = Atomic_<T>;
|
||||
|
||||
using ConditionVariable = ConditionVariable_;
|
||||
};
|
||||
|
||||
struct MultipleThreading
|
||||
{
|
||||
using Mutex = std::mutex;
|
||||
|
||||
template <typename T>
|
||||
using Atomic = std::atomic<T>;
|
||||
|
||||
using ConditionVariable = std::condition_variable;
|
||||
};
|
||||
|
||||
struct SingleThreading
|
||||
{
|
||||
struct Mutex
|
||||
{
|
||||
void lock() {}
|
||||
void unlock() {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Atomic
|
||||
{
|
||||
Atomic() noexcept = default;
|
||||
constexpr Atomic(T desired) noexcept
|
||||
: value(desired)
|
||||
{
|
||||
}
|
||||
|
||||
void store(T desired, std::memory_order /*order*/ = std::memory_order_seq_cst) noexcept
|
||||
{
|
||||
value = desired;
|
||||
}
|
||||
|
||||
T load(std::memory_order /*order*/ = std::memory_order_seq_cst) const noexcept
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
T exchange(T desired, std::memory_order /*order*/ = std::memory_order_seq_cst) noexcept
|
||||
{
|
||||
const T previous = value;
|
||||
value = desired;
|
||||
return previous;
|
||||
}
|
||||
|
||||
T operator ++ () noexcept
|
||||
{
|
||||
return ++value;
|
||||
}
|
||||
|
||||
T operator -- () noexcept
|
||||
{
|
||||
return --value;
|
||||
}
|
||||
|
||||
T value;
|
||||
};
|
||||
|
||||
struct ConditionVariable
|
||||
{
|
||||
void notify_one() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
template <class Predicate>
|
||||
void wait(std::unique_lock<std::mutex> & /*lock*/, Predicate /*pred*/)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Rep, class Period, class Predicate>
|
||||
bool wait_for(std::unique_lock<std::mutex> & /*lock*/,
|
||||
const std::chrono::duration<Rep, Period> & /*rel_time*/,
|
||||
Predicate /*pred*/
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct ArgumentPassingAutoDetect
|
||||
{
|
||||
enum {
|
||||
canIncludeEventType = true,
|
||||
canExcludeEventType = true
|
||||
};
|
||||
};
|
||||
|
||||
struct ArgumentPassingIncludeEvent
|
||||
{
|
||||
enum {
|
||||
canIncludeEventType = true,
|
||||
canExcludeEventType = false
|
||||
};
|
||||
};
|
||||
|
||||
struct ArgumentPassingExcludeEvent
|
||||
{
|
||||
enum {
|
||||
canIncludeEventType = false,
|
||||
canExcludeEventType = true
|
||||
};
|
||||
};
|
||||
|
||||
struct DefaultPolicies
|
||||
{
|
||||
};
|
||||
|
||||
template <template <typename> class ...Mixins>
|
||||
struct MixinList
|
||||
{
|
||||
};
|
||||
|
||||
#include "internal/eventpolicies_i.h"
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,561 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef EVENTQUEUE_H_705786053037
|
||||
#define EVENTQUEUE_H_705786053037
|
||||
|
||||
#include "eventdispatcher.h"
|
||||
#include "internal/eventqueue_i.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <chrono>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <
|
||||
typename EventType_,
|
||||
typename Prototype_,
|
||||
typename Policies_
|
||||
>
|
||||
class EventQueueBase;
|
||||
|
||||
template <
|
||||
typename EventType_,
|
||||
typename Policies_,
|
||||
typename ReturnType, typename ...Args
|
||||
>
|
||||
class EventQueueBase <
|
||||
EventType_,
|
||||
ReturnType (Args...),
|
||||
Policies_
|
||||
> : public EventDispatcherBase<
|
||||
EventType_,
|
||||
ReturnType (Args...),
|
||||
Policies_,
|
||||
EventQueueBase <
|
||||
EventType_,
|
||||
ReturnType (Args...),
|
||||
Policies_
|
||||
>
|
||||
>
|
||||
{
|
||||
private:
|
||||
using super = EventDispatcherBase<
|
||||
EventType_,
|
||||
ReturnType (Args...),
|
||||
Policies_,
|
||||
EventQueueBase <
|
||||
EventType_,
|
||||
ReturnType (Args...),
|
||||
Policies_
|
||||
>
|
||||
>;
|
||||
|
||||
using Policies = typename super::Policies;
|
||||
using Threading = typename super::Threading;
|
||||
using ConditionVariable = typename Threading::ConditionVariable;
|
||||
|
||||
using QueuedEventArgumentsType = std::tuple<typename std::decay<Args>::type...>;
|
||||
|
||||
struct QueuedEvent_
|
||||
{
|
||||
typename std::decay<typename super::Event>::type event;
|
||||
QueuedEventArgumentsType arguments;
|
||||
|
||||
typename super::Event getEvent() const {
|
||||
return event;
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
auto getArgument() const
|
||||
-> typename std::tuple_element<N, std::tuple<Args...> >::type {
|
||||
return std::get<N>(arguments);
|
||||
}
|
||||
};
|
||||
|
||||
using BufferedItemList = typename SelectQueueList<
|
||||
BufferedItem<QueuedEvent_>,
|
||||
Policies_,
|
||||
HasTemplateQueueList<Policies_>::value
|
||||
>::Type;
|
||||
|
||||
public:
|
||||
using QueuedEvent = QueuedEvent_;
|
||||
using Event = typename super::Event;
|
||||
using Handle = typename super::Handle;
|
||||
using Callback = typename super::Callback;
|
||||
using Mutex = typename super::Mutex;
|
||||
|
||||
struct DisableQueueNotify
|
||||
{
|
||||
DisableQueueNotify(EventQueueBase * queue)
|
||||
: queue(queue)
|
||||
{
|
||||
++queue->queueNotifyCounter;
|
||||
}
|
||||
|
||||
~DisableQueueNotify()
|
||||
{
|
||||
--queue->queueNotifyCounter;
|
||||
|
||||
if(queue->doCanNotifyQueueAvailable() && ! queue->emptyQueue()) {
|
||||
queue->queueListConditionVariable.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
EventQueueBase * queue;
|
||||
};
|
||||
|
||||
public:
|
||||
EventQueueBase()
|
||||
:
|
||||
super(),
|
||||
queueListConditionVariable(),
|
||||
queueEmptyCounter(0),
|
||||
queueNotifyCounter(0),
|
||||
queueListMutex(),
|
||||
queueList(),
|
||||
freeListMutex(),
|
||||
freeList()
|
||||
{
|
||||
}
|
||||
|
||||
EventQueueBase(const EventQueueBase & other)
|
||||
: super(other)
|
||||
{
|
||||
}
|
||||
|
||||
EventQueueBase(EventQueueBase && other) noexcept
|
||||
: super(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
EventQueueBase & operator = (const EventQueueBase & other)
|
||||
{
|
||||
super::operator = (other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
EventQueueBase & operator = (EventQueueBase && other) noexcept
|
||||
{
|
||||
super::operator = (std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename ...A>
|
||||
auto enqueue(A && ...args) -> typename std::enable_if<sizeof...(A) == sizeof...(Args), void>::type
|
||||
{
|
||||
static_assert(super::ArgumentPassingMode::canIncludeEventType, "Enqueuing arguments count doesn't match required (Event type should be included).");
|
||||
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, A...>::value>::Type;
|
||||
|
||||
doEnqueue(QueuedEvent{
|
||||
GetEvent::getEvent(args...),
|
||||
QueuedEventArgumentsType(std::forward<A>(args)...)
|
||||
});
|
||||
|
||||
if(doCanProcess()) {
|
||||
queueListConditionVariable.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename ...A>
|
||||
auto enqueue(T && first, A && ...args) -> typename std::enable_if<sizeof...(A) == sizeof...(Args), void>::type
|
||||
{
|
||||
static_assert(super::ArgumentPassingMode::canExcludeEventType, "Enqueuing arguments count doesn't match required (Event type should NOT be included).");
|
||||
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, T &&, A...>::value>::Type;
|
||||
|
||||
doEnqueue(QueuedEvent{
|
||||
GetEvent::getEvent(std::forward<T>(first), args...),
|
||||
QueuedEventArgumentsType(std::forward<A>(args)...)
|
||||
});
|
||||
|
||||
if(doCanProcess()) {
|
||||
queueListConditionVariable.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
bool emptyQueue() const
|
||||
{
|
||||
return queueList.empty() && (queueEmptyCounter.load(std::memory_order_acquire) == 0);
|
||||
}
|
||||
|
||||
void clearEvents()
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
std::swap(queueList, tempList);
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
for(auto & item : tempList) {
|
||||
item.clear();
|
||||
}
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), tempList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool process()
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
|
||||
// Use a counter to tell the queue list is not empty during processing
|
||||
// even though queueList is swapped to empty.
|
||||
CounterGuard<decltype(queueEmptyCounter)> counterGuard(queueEmptyCounter);
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
std::swap(queueList, tempList);
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
for(auto & item : tempList) {
|
||||
doDispatchQueuedEvent(
|
||||
item.get(),
|
||||
typename MakeIndexSequence<sizeof...(Args)>::Type()
|
||||
);
|
||||
item.clear();
|
||||
}
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), tempList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool processOne()
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
|
||||
// Use a counter to tell the queue list is not empty during processing
|
||||
// even though queueList is swapped to empty.
|
||||
CounterGuard<decltype(queueEmptyCounter)> counterGuard(queueEmptyCounter);
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
if(! queueList.empty()) {
|
||||
tempList.splice(tempList.end(), queueList, queueList.begin());
|
||||
}
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
auto & item = tempList.front();
|
||||
doDispatchQueuedEvent(
|
||||
item.get(),
|
||||
typename MakeIndexSequence<sizeof...(Args)>::Type()
|
||||
);
|
||||
item.clear();
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), tempList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Predictor>
|
||||
bool processIf(Predictor && predictor)
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
BufferedItemList idleList;
|
||||
|
||||
// Use a counter to tell the queue list is not empty during processing
|
||||
// even though queueList is swapped to empty.
|
||||
CounterGuard<decltype(queueEmptyCounter)> counterGuard(queueEmptyCounter);
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
std::swap(queueList, tempList);
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
for(auto it = tempList.begin(); it != tempList.end(); ) {
|
||||
if(doInvokeFuncWithQueuedEvent(
|
||||
predictor,
|
||||
it->get(),
|
||||
typename MakeIndexSequence<sizeof...(Args)>::Type())
|
||||
) {
|
||||
doDispatchQueuedEvent(
|
||||
it->get(),
|
||||
typename MakeIndexSequence<sizeof...(Args)>::Type()
|
||||
);
|
||||
it->clear();
|
||||
|
||||
auto tempIt = it;
|
||||
++it;
|
||||
idleList.splice(idleList.end(), tempList, tempIt);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
if (! tempList.empty()) {
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
queueList.splice(queueList.begin(), tempList);
|
||||
}
|
||||
|
||||
if(! idleList.empty()) {
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), idleList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Predictor>
|
||||
bool processUntil(Predictor && predictor)
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
BufferedItemList idleList;
|
||||
|
||||
// Use a counter to tell the queue list is not empty during processing
|
||||
// even though queueList is swapped to empty.
|
||||
CounterGuard<decltype(queueEmptyCounter)> counterGuard(queueEmptyCounter);
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
std::swap(queueList, tempList);
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
for(auto it = tempList.begin(); it != tempList.end(); ) {
|
||||
if(doInvokeFuncWithQueuedEvent(
|
||||
predictor,
|
||||
it->get(),
|
||||
typename MakeIndexSequence<sizeof...(Args)>::Type())
|
||||
) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
doDispatchQueuedEvent(
|
||||
it->get(),
|
||||
typename MakeIndexSequence<sizeof...(Args)>::Type()
|
||||
);
|
||||
it->clear();
|
||||
|
||||
auto tempIt = it;
|
||||
++it;
|
||||
idleList.splice(idleList.end(), tempList, tempIt);
|
||||
}
|
||||
}
|
||||
|
||||
if (! tempList.empty()) {
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
queueList.splice(queueList.begin(), tempList);
|
||||
}
|
||||
|
||||
if(! idleList.empty()) {
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), idleList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void wait() const
|
||||
{
|
||||
std::unique_lock<Mutex> queueListLock(queueListMutex);
|
||||
queueListConditionVariable.wait(queueListLock, [this]() -> bool {
|
||||
return doCanProcess();
|
||||
});
|
||||
}
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool waitFor(const std::chrono::duration<Rep, Period> & duration) const
|
||||
{
|
||||
std::unique_lock<Mutex> queueListLock(queueListMutex);
|
||||
return queueListConditionVariable.wait_for(queueListLock, duration, [this]() -> bool {
|
||||
return doCanProcess();
|
||||
});
|
||||
}
|
||||
|
||||
using super::dispatch;
|
||||
|
||||
template <typename U>
|
||||
auto dispatch(const U & queuedEvent)
|
||||
-> typename std::enable_if<std::is_same<U, QueuedEvent>::value, void>::type
|
||||
{
|
||||
doDispatchQueuedEvent(
|
||||
queuedEvent,
|
||||
typename MakeIndexSequence<sizeof...(Args)>::Type()
|
||||
);
|
||||
}
|
||||
|
||||
bool peekEvent(QueuedEvent * queuedEvent)
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
|
||||
if(! queueList.empty()) {
|
||||
*queuedEvent = queueList.front().get();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool takeEvent(QueuedEvent * queuedEvent)
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
|
||||
if(! queueList.empty()) {
|
||||
tempList.splice(tempList.end(), queueList, queueList.begin());
|
||||
}
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
*queuedEvent = std::move(tempList.front().get());
|
||||
tempList.front().clear();
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), tempList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool doCanProcess() const
|
||||
{
|
||||
return ! emptyQueue() && doCanNotifyQueueAvailable();
|
||||
}
|
||||
|
||||
bool doCanNotifyQueueAvailable() const
|
||||
{
|
||||
return queueNotifyCounter.load(std::memory_order_acquire) == 0;
|
||||
}
|
||||
|
||||
template <typename T, size_t ...Indexes>
|
||||
void doDispatchQueuedEvent(T && item, IndexSequence<Indexes...>)
|
||||
{
|
||||
this->directDispatch(item.event, std::get<Indexes>(item.arguments)...);
|
||||
}
|
||||
|
||||
template <typename F, typename T, size_t ...Indexes>
|
||||
bool doInvokeFuncWithQueuedEvent(F && func, T && item, IndexSequence<Indexes...>) const
|
||||
{
|
||||
return doInvokeFuncWithQueuedEventHelper(std::forward<F>(func), std::get<Indexes>(item.arguments)...);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
auto doInvokeFuncWithQueuedEventHelper(F && func, Args ...args) const
|
||||
-> typename std::enable_if<! CanInvoke<F>::value, bool>::type
|
||||
{
|
||||
return func(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
auto doInvokeFuncWithQueuedEventHelper(F && func, Args .../*args*/) const
|
||||
-> typename std::enable_if<CanInvoke<F>::value, bool>::type
|
||||
{
|
||||
return func();
|
||||
}
|
||||
|
||||
void doEnqueue(QueuedEvent && item)
|
||||
{
|
||||
BufferedItemList tempList;
|
||||
if(! freeList.empty()) {
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
if(! freeList.empty()) {
|
||||
tempList.splice(tempList.end(), freeList, freeList.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(tempList.empty()) {
|
||||
tempList.emplace_back();
|
||||
}
|
||||
|
||||
auto it = tempList.begin();
|
||||
it->set(std::move(item));
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
queueList.splice(queueList.end(), tempList, it);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable ConditionVariable queueListConditionVariable;
|
||||
typename Threading::template Atomic<int> queueEmptyCounter;
|
||||
typename Threading::template Atomic<int> queueNotifyCounter;
|
||||
mutable Mutex queueListMutex;
|
||||
BufferedItemList queueList;
|
||||
Mutex freeListMutex;
|
||||
BufferedItemList freeList;
|
||||
};
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
template <
|
||||
typename Event_,
|
||||
typename Prototype_,
|
||||
typename Policies_ = DefaultPolicies
|
||||
>
|
||||
class EventQueue : public internal_::InheritMixins<
|
||||
internal_::EventQueueBase<Event_, Prototype_, Policies_>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type, public TagEventDispatcher, public TagEventQueue
|
||||
{
|
||||
private:
|
||||
using super = typename internal_::InheritMixins<
|
||||
internal_::EventQueueBase<Event_, Prototype_, Policies_>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type;
|
||||
|
||||
public:
|
||||
using super::super;
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef HETERCALLBACKLIST_H_966730936077
|
||||
#define HETERCALLBACKLIST_H_966730936077
|
||||
|
||||
#include "internal/hetercallbacklist_i.h"
|
||||
#include "callbacklist.h"
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <
|
||||
typename PrototypeList_,
|
||||
typename Policies_
|
||||
>
|
||||
class HeterCallbackListBase
|
||||
{
|
||||
protected:
|
||||
struct HeterHandle_
|
||||
{
|
||||
int index;
|
||||
std::weak_ptr<void> homoHandle;
|
||||
|
||||
operator bool () const noexcept {
|
||||
return (bool)homoHandle;
|
||||
}
|
||||
};
|
||||
|
||||
struct UnderlyingPoliciesType_
|
||||
{
|
||||
};
|
||||
|
||||
class HomoCallbackListTypeBase
|
||||
{
|
||||
public:
|
||||
virtual ~HomoCallbackListTypeBase() {}
|
||||
|
||||
virtual bool empty() = 0;
|
||||
virtual bool doRemove(const HeterHandle_ & handle) = 0;
|
||||
virtual std::shared_ptr<HomoCallbackListTypeBase> doClone() = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class HomoCallbackListType : public CallbackList<T, UnderlyingPoliciesType_>, public HomoCallbackListTypeBase
|
||||
{
|
||||
private:
|
||||
using super = CallbackList<T, UnderlyingPoliciesType_>;
|
||||
|
||||
public:
|
||||
virtual bool empty() override {
|
||||
return super::empty();
|
||||
}
|
||||
|
||||
virtual bool doRemove(const HeterHandle_ & handle) override {
|
||||
auto sp = handle.homoHandle.lock();
|
||||
if(! sp) {
|
||||
return false;
|
||||
}
|
||||
return this->remove(typename super::Handle(std::static_pointer_cast<typename super::Handle::element_type>(sp)));
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<HomoCallbackListTypeBase> doClone() override {
|
||||
return std::make_shared<HomoCallbackListType<T> >(*this);
|
||||
}
|
||||
};
|
||||
|
||||
using Policies = Policies_;
|
||||
using Threading = typename SelectThreading<Policies, HasTypeThreading<Policies>::value>::Type;
|
||||
|
||||
using PrototypeList = PrototypeList_;
|
||||
|
||||
public:
|
||||
using Handle = HeterHandle_;
|
||||
using Mutex = typename Threading::Mutex;
|
||||
|
||||
public:
|
||||
HeterCallbackListBase()
|
||||
:
|
||||
callbackListList(),
|
||||
callbackListListMutex()
|
||||
{
|
||||
}
|
||||
|
||||
HeterCallbackListBase(const HeterCallbackListBase & other)
|
||||
:
|
||||
callbackListList(),
|
||||
callbackListListMutex()
|
||||
{
|
||||
for(size_t i = 0; i < callbackListList.size(); ++i) {
|
||||
if(other.callbackListList[i]) {
|
||||
callbackListList[i] = other.callbackListList[i]->doClone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HeterCallbackListBase(HeterCallbackListBase && other) noexcept
|
||||
:
|
||||
callbackListList(std::move(other.callbackListList)),
|
||||
callbackListListMutex()
|
||||
{
|
||||
}
|
||||
|
||||
// If we use pass by value idiom and omit the 'this' check,
|
||||
// when assigning to self there is a deep copy which is inefficient.
|
||||
HeterCallbackListBase & operator = (const HeterCallbackListBase & other) noexcept
|
||||
{
|
||||
if(this != &other) {
|
||||
HeterCallbackListBase copied(other);
|
||||
swap(copied);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
HeterCallbackListBase & operator = (HeterCallbackListBase && other) noexcept
|
||||
{
|
||||
if(this != &other) {
|
||||
for(size_t i = 0; i < callbackListList.size(); ++i) {
|
||||
callbackListList[i] = std::move(other.callbackListList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(HeterCallbackListBase & other) noexcept {
|
||||
using std::swap;
|
||||
|
||||
swap(callbackListList, other.callbackListList);
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
for(const auto & callbackList : callbackListList) {
|
||||
if(callbackList && ! callbackList->empty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
operator bool() const {
|
||||
return ! empty();
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Handle append(const C & callback)
|
||||
{
|
||||
using PrototypeInfo = FindPrototypeByCallable<PrototypeList_, C>;
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
|
||||
auto callbackList= doGetCallbackList<PrototypeInfo>();
|
||||
return Handle {
|
||||
PrototypeInfo::index,
|
||||
callbackList->append(callback)
|
||||
};
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Handle prepend(const C & callback)
|
||||
{
|
||||
using PrototypeInfo = FindPrototypeByCallable<PrototypeList_, C>;
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
|
||||
auto callbackList= doGetCallbackList<PrototypeInfo>();
|
||||
return Handle {
|
||||
PrototypeInfo::index,
|
||||
callbackList->prepend(callback)
|
||||
};
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Handle insert(const C & callback, const Handle & before)
|
||||
{
|
||||
using PrototypeInfo = FindPrototypeByCallable<PrototypeList_, C>;
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
|
||||
auto callbackList= doGetCallbackList<PrototypeInfo>();
|
||||
|
||||
if(before.index != PrototypeInfo::index) {
|
||||
return Handle {
|
||||
PrototypeInfo::index,
|
||||
callbackList->append(callback)
|
||||
};
|
||||
}
|
||||
|
||||
using UnderlyingHandle = typename decltype(callbackList)::element_type::Handle;
|
||||
|
||||
return Handle {
|
||||
PrototypeInfo::index,
|
||||
callbackList->insert(
|
||||
callback,
|
||||
UnderlyingHandle(std::static_pointer_cast<typename UnderlyingHandle::element_type>(before.homoHandle.lock()))
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
bool remove(const Handle & handle)
|
||||
{
|
||||
auto callbackList = callbackListList[handle.index];
|
||||
if(callbackList) {
|
||||
return callbackList->doRemove(handle);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Prototype, typename Func>
|
||||
void forEach(Func && func) const
|
||||
{
|
||||
using PrototypeInfo = FindPrototypeByCallable<PrototypeList, Prototype>;
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
|
||||
auto callbackList= doGetCallbackList<PrototypeInfo>();
|
||||
using CL = typename decltype(callbackList)::element_type;
|
||||
callbackList->forEach([this, &func](const typename CL::Handle & handle, const typename CL::Callback & callback) {
|
||||
doForEachInvoke<void, PrototypeInfo::index>(func, handle, callback);
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Prototype, typename Func>
|
||||
bool forEachIf(Func && func) const
|
||||
{
|
||||
using PrototypeInfo = FindPrototypeByCallable<PrototypeList, Prototype>;
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
|
||||
auto callbackList= doGetCallbackList<PrototypeInfo>();
|
||||
using CL = typename decltype(callbackList)::element_type;
|
||||
return callbackList->forEachIf([this, &func](const typename CL::Handle & handle, const typename CL::Callback & callback) {
|
||||
return doForEachInvoke<bool, PrototypeInfo::index>(func, handle, callback);
|
||||
});
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
void operator() (Args && ...args) const
|
||||
{
|
||||
using PrototypeInfo = FindPrototypeByArgs<PrototypeList, Args...>;
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
|
||||
auto callbackList= doGetCallbackList<PrototypeInfo>();
|
||||
(*callbackList)(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename RT, int PrototypeIndex, typename Func, typename H, typename CL>
|
||||
auto doForEachInvoke(Func && func, const H & handle, CL && callback) const
|
||||
-> typename std::enable_if<CanInvoke<Func, Handle, CL>::value, RT>::type
|
||||
{
|
||||
return func(Handle { PrototypeIndex, handle }, callback);
|
||||
}
|
||||
|
||||
template <typename RT, int PrototypeIndex, typename Func, typename H, typename CL>
|
||||
auto doForEachInvoke(Func && func, const H & /*handle*/, CL && callback) const
|
||||
-> typename std::enable_if<CanInvoke<Func, CL>::value, RT>::type
|
||||
{
|
||||
return func(callback);
|
||||
}
|
||||
|
||||
template <typename PrototypeInfo>
|
||||
auto doGetCallbackList() const
|
||||
-> std::shared_ptr<HomoCallbackListType<typename PrototypeInfo::Prototype> >
|
||||
{
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
|
||||
if(! callbackListList[PrototypeInfo::index]) {
|
||||
std::lock_guard<Mutex> lockGuard(callbackListListMutex);
|
||||
|
||||
if(! callbackListList[PrototypeInfo::index]) {
|
||||
callbackListList[PrototypeInfo::index] = std::make_shared<HomoCallbackListType<typename PrototypeInfo::Prototype> >();
|
||||
}
|
||||
}
|
||||
|
||||
return std::static_pointer_cast<HomoCallbackListType<typename PrototypeInfo::Prototype> >(callbackListList[PrototypeInfo::index]);
|
||||
}
|
||||
|
||||
private:
|
||||
// the postfix 'ListList' is not good, but it's better to use consistent naming convention.
|
||||
mutable std::array<std::shared_ptr<HomoCallbackListTypeBase>, HeterTupleSize<PrototypeList_>::value> callbackListList;
|
||||
mutable Mutex callbackListListMutex;
|
||||
};
|
||||
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
template <
|
||||
typename PrototypeList_,
|
||||
typename Policies_ = DefaultPolicies
|
||||
>
|
||||
class HeterCallbackList : public internal_::HeterCallbackListBase<PrototypeList_, Policies_>, public TagCallbackList, public TagHeterCallbackList
|
||||
{
|
||||
private:
|
||||
using super = internal_::HeterCallbackListBase<PrototypeList_, Policies_>;
|
||||
|
||||
public:
|
||||
using super::super;
|
||||
|
||||
friend void swap(HeterCallbackList & first, HeterCallbackList & second) noexcept {
|
||||
first.swap(second);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,325 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef HETEREVENTDISPATCHER_H_127766658555
|
||||
#define HETEREVENTDISPATCHER_H_127766658555
|
||||
|
||||
#include "mixins/mixinheterfilter.h"
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <
|
||||
typename EventType_,
|
||||
typename PrototypeList_,
|
||||
typename Policies_,
|
||||
typename MixinRoot_
|
||||
>
|
||||
class HeterEventDispatcherBase
|
||||
{
|
||||
protected:
|
||||
using ThisType = HeterEventDispatcherBase<
|
||||
EventType_,
|
||||
PrototypeList_,
|
||||
Policies_,
|
||||
MixinRoot_
|
||||
>;
|
||||
using MixinRoot = typename std::conditional<
|
||||
std::is_same<MixinRoot_, void>::value,
|
||||
ThisType,
|
||||
MixinRoot_
|
||||
>::type;
|
||||
using Policies = Policies_;
|
||||
|
||||
using Threading = typename SelectThreading<Policies, HasTypeThreading<Policies_>::value>::Type;
|
||||
|
||||
using ArgumentPassingMode = typename SelectArgumentPassingMode<
|
||||
Policies_,
|
||||
HasTypeArgumentPassingMode<Policies_>::value,
|
||||
ArgumentPassingExcludeEvent
|
||||
>::Type;
|
||||
|
||||
static_assert(! std::is_same<ArgumentPassingMode, ArgumentPassingAutoDetect>::value,
|
||||
"ArgumentPassingMode can't be ArgumentPassingAutoDetect in heterogeneous dispatcher.");
|
||||
|
||||
using CallbackList_ = HeterCallbackList<PrototypeList_, Policies_>;
|
||||
|
||||
using Map = typename SelectMap<
|
||||
EventType_,
|
||||
CallbackList_,
|
||||
Policies_,
|
||||
HasTemplateMap<Policies_>::value
|
||||
>::Type;
|
||||
|
||||
using Mixins = typename internal_::SelectMixins<
|
||||
Policies_,
|
||||
internal_::HasTypeMixins<Policies_>::value
|
||||
>::Type;
|
||||
|
||||
public:
|
||||
using PrototypeList = PrototypeList_;
|
||||
using Handle = typename CallbackList_::Handle;
|
||||
using Event = EventType_;
|
||||
using Mutex = typename Threading::Mutex;
|
||||
|
||||
public:
|
||||
HeterEventDispatcherBase()
|
||||
:
|
||||
eventCallbackListMap(),
|
||||
listenerMutex()
|
||||
{
|
||||
}
|
||||
|
||||
HeterEventDispatcherBase(const HeterEventDispatcherBase & other)
|
||||
:
|
||||
eventCallbackListMap(other.eventCallbackListMap),
|
||||
listenerMutex()
|
||||
{
|
||||
}
|
||||
|
||||
HeterEventDispatcherBase(HeterEventDispatcherBase && other) noexcept
|
||||
:
|
||||
eventCallbackListMap(std::move(other.eventCallbackListMap)),
|
||||
listenerMutex()
|
||||
{
|
||||
}
|
||||
|
||||
HeterEventDispatcherBase & operator = (const HeterEventDispatcherBase & other)
|
||||
{
|
||||
eventCallbackListMap = other.eventCallbackListMap;
|
||||
return *this;
|
||||
}
|
||||
|
||||
HeterEventDispatcherBase & operator = (HeterEventDispatcherBase && other) noexcept
|
||||
{
|
||||
eventCallbackListMap = std::move(other.eventCallbackListMap);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(HeterEventDispatcherBase & other) noexcept {
|
||||
using std::swap;
|
||||
|
||||
swap(eventCallbackListMap, other.eventCallbackListMap);
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Handle appendListener(const Event & event, const C & callback)
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(listenerMutex);
|
||||
|
||||
return eventCallbackListMap[event].append(callback);
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Handle prependListener(const Event & event, const C & callback)
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(listenerMutex);
|
||||
|
||||
return eventCallbackListMap[event].prepend(callback);
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
Handle insertListener(const Event & event, const C & callback, const Handle & before)
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(listenerMutex);
|
||||
|
||||
return eventCallbackListMap[event].insert(callback, before);
|
||||
}
|
||||
|
||||
bool removeListener(const Event & event, const Handle handle)
|
||||
{
|
||||
CallbackList_ * callableList = doFindCallableList(event);
|
||||
if(callableList) {
|
||||
return callableList->remove(handle);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasAnyListener(const Event & event) const
|
||||
{
|
||||
const CallbackList_ * callableList = doFindCallableList(event);
|
||||
if(callableList) {
|
||||
return ! callableList->empty();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Prototype, typename Func>
|
||||
void forEach(const Event & event, Func && func) const
|
||||
{
|
||||
const CallbackList_ * callableList = doFindCallableList(event);
|
||||
if(callableList) {
|
||||
callableList->template forEach<Prototype>(std::forward<Func>(func));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Prototype, typename Func>
|
||||
bool forEachIf(const Event & event, Func && func) const
|
||||
{
|
||||
const CallbackList_ * callableList = doFindCallableList(event);
|
||||
if (callableList) {
|
||||
return callableList->template forEachIf<Prototype>(std::forward<Func>(func));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
void dispatch(T && first, Args && ...args) const
|
||||
{
|
||||
doDispatch<ArgumentPassingMode>(std::forward<T>(first), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// Bypass any getEvent policy. The first argument is the event type.
|
||||
// Most used for internal purpose.
|
||||
template <typename ...Args>
|
||||
void directDispatch(const Event & e, Args && ...args) const
|
||||
{
|
||||
if(! internal_::ForEachMixins<MixinRoot, Mixins, DoMixinBeforeDispatch>::forEach(
|
||||
this, typename std::add_lvalue_reference<Args>::type(args)...)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const CallbackList_ * callableList = doFindCallableList(e);
|
||||
if(callableList) {
|
||||
(*callableList)(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename ArgumentMode, typename T, typename ...Args>
|
||||
auto doDispatch(T && first, Args && ...args) const
|
||||
-> typename std::enable_if<std::is_same<ArgumentMode, ArgumentPassingIncludeEvent>::value>::type
|
||||
{
|
||||
if(! internal_::ForEachMixins<MixinRoot, Mixins, DoMixinBeforeDispatch>::forEach(
|
||||
this,
|
||||
typename std::add_lvalue_reference<T>::type(first),
|
||||
typename std::add_lvalue_reference<Args>::type(args)...)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, T &&, Args...>::value>::Type;
|
||||
const auto e = GetEvent::getEvent(std::forward<T>(first), args...);
|
||||
const CallbackList_ * callableList = doFindCallableList(e);
|
||||
if(callableList) {
|
||||
(*callableList)(std::forward<T>(first), std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ArgumentMode, typename T, typename ...Args>
|
||||
auto doDispatch(T && first, Args && ...args) const
|
||||
-> typename std::enable_if<std::is_same<ArgumentMode, ArgumentPassingExcludeEvent>::value>::type
|
||||
{
|
||||
if(! internal_::ForEachMixins<MixinRoot, Mixins, DoMixinBeforeDispatch>::forEach(
|
||||
this,
|
||||
typename std::add_lvalue_reference<Args>::type(args)...)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, T &&, Args...>::value>::Type;
|
||||
const auto e = GetEvent::getEvent(std::forward<T>(first), args...);
|
||||
const CallbackList_ * callableList = doFindCallableList(e);
|
||||
if(callableList) {
|
||||
(*callableList)(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
const CallbackList_ * doFindCallableList(const Event & e) const
|
||||
{
|
||||
return doFindCallableListHelper(this, e);
|
||||
}
|
||||
|
||||
CallbackList_ * doFindCallableList(const Event & e)
|
||||
{
|
||||
return doFindCallableListHelper(this, e);
|
||||
}
|
||||
|
||||
private:
|
||||
// template helper to avoid code duplication in doFindCallableList
|
||||
template <typename T>
|
||||
static auto doFindCallableListHelper(T * self, const Event & e)
|
||||
-> typename std::conditional<std::is_const<T>::value, const CallbackList_ *, CallbackList_ *>::type
|
||||
{
|
||||
std::lock_guard<Mutex> lockGuard(self->listenerMutex);
|
||||
|
||||
auto it = self->eventCallbackListMap.find(e);
|
||||
if(it != self->eventCallbackListMap.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Mixin related
|
||||
struct DoMixinBeforeDispatch
|
||||
{
|
||||
template <typename T, typename Self, typename ...A>
|
||||
static auto forEach(const Self * self, A && ...args)
|
||||
-> typename std::enable_if<HasFunctionMixinBeforeDispatch<T, A...>::value, bool>::type {
|
||||
return static_cast<const T *>(self)->mixinBeforeDispatch(std::forward<A>(args)...);
|
||||
}
|
||||
|
||||
template <typename T, typename Self, typename ...A>
|
||||
static auto forEach(const Self * self, A && ...args)
|
||||
-> typename std::enable_if<! HasFunctionMixinBeforeDispatch<T, A...>::value, bool>::type {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
Map eventCallbackListMap;
|
||||
mutable Mutex listenerMutex;
|
||||
};
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
|
||||
template <
|
||||
typename Event_,
|
||||
typename PrototypeList_,
|
||||
typename Policies_ = DefaultPolicies
|
||||
>
|
||||
class HeterEventDispatcher : public internal_::InheritMixins<
|
||||
internal_::HeterEventDispatcherBase<Event_, PrototypeList_, Policies_, void>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type, public TagEventDispatcher, public TagHeterEventDispatcher
|
||||
{
|
||||
private:
|
||||
using super = typename internal_::InheritMixins<
|
||||
internal_::HeterEventDispatcherBase<Event_, PrototypeList_, Policies_, void>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type;
|
||||
|
||||
public:
|
||||
using super::super;
|
||||
|
||||
friend void swap(HeterEventDispatcher & first, HeterEventDispatcher & second) noexcept {
|
||||
first.swap(second);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,482 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef HETEREVENTQUEUE_H_210892536510
|
||||
#define HETEREVENTQUEUE_H_210892536510
|
||||
|
||||
#include "hetereventdispatcher.h"
|
||||
|
||||
// temp, should move the internal code in eventqueue to separated file
|
||||
#include "eventqueue.h"
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <
|
||||
typename EventType_,
|
||||
typename PrototypeList_,
|
||||
typename Policies_
|
||||
>
|
||||
class HeterEventQueueBase : public HeterEventDispatcherBase<
|
||||
EventType_,
|
||||
PrototypeList_,
|
||||
Policies_,
|
||||
HeterEventQueueBase <
|
||||
EventType_,
|
||||
PrototypeList_,
|
||||
Policies_
|
||||
>
|
||||
>
|
||||
{
|
||||
private:
|
||||
using super = HeterEventDispatcherBase<
|
||||
EventType_,
|
||||
PrototypeList_,
|
||||
Policies_,
|
||||
HeterEventQueueBase <
|
||||
EventType_,
|
||||
PrototypeList_,
|
||||
Policies_
|
||||
>
|
||||
>;
|
||||
|
||||
using Policies = typename super::Policies;
|
||||
using Threading = typename super::Threading;
|
||||
using ConditionVariable = typename Threading::ConditionVariable;
|
||||
|
||||
struct QueuedItemBase;
|
||||
using ItemDispatcher = void (*)(const HeterEventQueueBase *, const QueuedItemBase &);
|
||||
|
||||
struct QueuedItemBase
|
||||
{
|
||||
QueuedItemBase(const int callableIndex, const EventType_ & event, const ItemDispatcher dispatcher)
|
||||
: callableIndex(callableIndex), event(event), dispatcher(dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
int callableIndex;
|
||||
EventType_ event;
|
||||
ItemDispatcher dispatcher;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct QueuedItem : public QueuedItemBase
|
||||
{
|
||||
QueuedItem(const int callableIndex, const EventType_ & event, const ItemDispatcher dispatcher, T && arguments)
|
||||
: QueuedItemBase(callableIndex, event, dispatcher), arguments(std::move(arguments))
|
||||
{
|
||||
}
|
||||
|
||||
T arguments;
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
using QueuedItemSizer = QueuedItem<std::tuple<typename std::remove_cv<typename std::remove_reference<Args>::type>::type...> >;
|
||||
|
||||
using BufferedQueuedItem = BufferedUnion<GetCallablePrototypeMaxSize<PrototypeList_, QueuedItemSizer>::value>;
|
||||
|
||||
using BufferedItemList = std::list<BufferedQueuedItem>;
|
||||
|
||||
using PrototypeList = typename super::PrototypeList;
|
||||
|
||||
using ArgumentPassingMode = typename super::ArgumentPassingMode;
|
||||
|
||||
public:
|
||||
using Event = typename super::Event;
|
||||
using Handle = typename super::Handle;
|
||||
using Mutex = typename super::Mutex;
|
||||
|
||||
public:
|
||||
HeterEventQueueBase()
|
||||
:
|
||||
super(),
|
||||
queueListConditionVariable(),
|
||||
queueEmptyCounter(0),
|
||||
queueNotifyCounter(0),
|
||||
queueListMutex(),
|
||||
queueList(),
|
||||
freeListMutex(),
|
||||
freeList()
|
||||
{
|
||||
}
|
||||
|
||||
HeterEventQueueBase(const HeterEventQueueBase & other)
|
||||
: super(other)
|
||||
{
|
||||
}
|
||||
|
||||
HeterEventQueueBase(HeterEventQueueBase && other) noexcept
|
||||
: super(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
HeterEventQueueBase & operator = (const HeterEventQueueBase & other)
|
||||
{
|
||||
super::operator = (other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
HeterEventQueueBase & operator = (HeterEventQueueBase && other) noexcept
|
||||
{
|
||||
super::operator = (std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
void enqueue(T && first, Args && ...args)
|
||||
{
|
||||
doEnqueue<ArgumentPassingMode>(std::forward<T>(first), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
bool emptyQueue() const
|
||||
{
|
||||
return queueList.empty() && (queueEmptyCounter.load(std::memory_order_acquire) == 0);
|
||||
}
|
||||
|
||||
void clearEvents()
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
std::swap(queueList, tempList);
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
for(auto & item : tempList) {
|
||||
item.clear();
|
||||
}
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), tempList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool process()
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
|
||||
// Use a counter to tell the queue list is not empty during processing
|
||||
// even though queueList is swapped to empty.
|
||||
CounterGuard<decltype(queueEmptyCounter)> counterGuard(queueEmptyCounter);
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
std::swap(queueList, tempList);
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
for(auto & item : tempList) {
|
||||
doDispatchQueuedEvent(item.template get<QueuedItemBase>());
|
||||
item.clear();
|
||||
}
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), tempList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool processOne()
|
||||
{
|
||||
if(! queueList.empty()) {
|
||||
BufferedItemList tempList;
|
||||
|
||||
// Use a counter to tell the queue list is not empty during processing
|
||||
// even though queueList is swapped to empty.
|
||||
CounterGuard<decltype(queueEmptyCounter)> counterGuard(queueEmptyCounter);
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
if(! queueList.empty()) {
|
||||
tempList.splice(tempList.end(), queueList, queueList.begin());
|
||||
}
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
auto & item = tempList.front();
|
||||
doDispatchQueuedEvent(item.template get<QueuedItemBase>());
|
||||
item.clear();
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), tempList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
bool processIf(F && func)
|
||||
{
|
||||
if(queueList.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
using PrototypeInfo = FindPrototypeByCallable<PrototypeList, F>;
|
||||
return doProcessIf<PrototypeInfo>(std::forward<F>(func));
|
||||
}
|
||||
|
||||
void wait() const
|
||||
{
|
||||
std::unique_lock<Mutex> queueListLock(queueListMutex);
|
||||
queueListConditionVariable.wait(queueListLock, [this]() -> bool {
|
||||
return doCanProcess();
|
||||
});
|
||||
}
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool waitFor(const std::chrono::duration<Rep, Period> & duration) const
|
||||
{
|
||||
std::unique_lock<Mutex> queueListLock(queueListMutex);
|
||||
return queueListConditionVariable.wait_for(queueListLock, duration, [this]() -> bool {
|
||||
return doCanProcess();
|
||||
});
|
||||
}
|
||||
|
||||
using super::dispatch;
|
||||
|
||||
private:
|
||||
bool doCanProcess() const
|
||||
{
|
||||
return ! emptyQueue() && doCanNotifyQueueAvailable();
|
||||
}
|
||||
|
||||
bool doCanNotifyQueueAvailable() const
|
||||
{
|
||||
return queueNotifyCounter.load(std::memory_order_acquire) == 0;
|
||||
}
|
||||
|
||||
void doDispatchQueuedEvent(const QueuedItemBase & item)
|
||||
{
|
||||
item.dispatcher(this, item);
|
||||
}
|
||||
|
||||
template <typename PrototypeInfo>
|
||||
static void doDispatchItem(const HeterEventQueueBase * self, const QueuedItemBase & baseItem)
|
||||
{
|
||||
const auto & item = static_cast<const QueuedItem<typename PrototypeInfo::ArgsTuple> &>(baseItem);
|
||||
self->doDispatchQueuedItem<PrototypeInfo>(
|
||||
item,
|
||||
typename MakeIndexSequence<std::tuple_size<typename PrototypeInfo::ArgsTuple>::value>::Type()
|
||||
);
|
||||
}
|
||||
|
||||
template <typename PrototypeInfo, typename T, size_t ...Indexes>
|
||||
void doDispatchQueuedItem(T && item, IndexSequence<Indexes...>) const
|
||||
{
|
||||
this->directDispatch(item.event, std::get<Indexes>(item.arguments)...);
|
||||
}
|
||||
|
||||
template <typename PrototypeInfo, typename F>
|
||||
auto doProcessIf(F && func)
|
||||
-> typename std::enable_if<(PrototypeInfo::index >= 0), bool>::type
|
||||
{
|
||||
BufferedItemList tempList;
|
||||
BufferedItemList idleList;
|
||||
|
||||
// Use a counter to tell the queue list is not empty during processing
|
||||
// even though queueList is swapped to empty.
|
||||
CounterGuard<decltype(queueEmptyCounter)> counterGuard(queueEmptyCounter);
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
std::swap(queueList, tempList);
|
||||
}
|
||||
|
||||
if(! tempList.empty()) {
|
||||
for(auto it = tempList.begin(); it != tempList.end(); ) {
|
||||
using ArgsTuple = typename PrototypeInfo::ArgsTuple;
|
||||
auto item = it->template get<QueuedItem<ArgsTuple> >();
|
||||
|
||||
if(item.callableIndex != PrototypeInfo::index) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
if(doInvokeFuncWithQueuedEvent(
|
||||
func,
|
||||
item,
|
||||
typename MakeIndexSequence<std::tuple_size<ArgsTuple>::value>::Type())
|
||||
) {
|
||||
doDispatchQueuedEvent(item);
|
||||
it->clear();
|
||||
|
||||
auto tempIt = it;
|
||||
++it;
|
||||
idleList.splice(idleList.end(), tempList, tempIt);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
if (! tempList.empty()) {
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
queueList.splice(queueList.begin(), tempList);
|
||||
}
|
||||
|
||||
if(! idleList.empty()) {
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
freeList.splice(freeList.end(), idleList);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
using NextPrototypeInfo = FindPrototypeByCallableFromIndex<PrototypeInfo::index + 1, PrototypeList, F>;
|
||||
if(doProcessIf<NextPrototypeInfo>(std::forward<F>(func))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename PrototypeInfo, typename F>
|
||||
auto doProcessIf(F && /*func*/)
|
||||
-> typename std::enable_if<(PrototypeInfo::index < 0), bool>::type
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename F, typename T, size_t ...Indexes>
|
||||
bool doInvokeFuncWithQueuedEvent(F && func, T && item, IndexSequence<Indexes...>) const
|
||||
{
|
||||
return doInvokeFuncWithQueuedEventHelper(std::forward<F>(func), std::get<Indexes>(item.arguments)...);
|
||||
}
|
||||
|
||||
template <typename F, typename ...Args>
|
||||
bool doInvokeFuncWithQueuedEventHelper(F && func, Args && ...args) const
|
||||
{
|
||||
return func(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ArgumentMode, typename T, typename ...Args>
|
||||
auto doEnqueue(T && first, Args && ...args)
|
||||
-> typename std::enable_if<std::is_same<ArgumentMode, ArgumentPassingIncludeEvent>::value>::type
|
||||
{
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, T &&, Args...>::value>::Type;
|
||||
using PrototypeInfo = FindPrototypeByArgs<PrototypeList_, T, Args...>;
|
||||
using QueuedItemType = QueuedItem<typename PrototypeInfo::ArgsTuple>;
|
||||
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
static_assert(std::tuple_size<typename PrototypeInfo::ArgsTuple>::value == 1 + sizeof...(Args), "Arguments count mismatch.");
|
||||
|
||||
doEnqueueItem(QueuedItemType(
|
||||
PrototypeInfo::index,
|
||||
GetEvent::getEvent(std::forward<T>(first), args...),
|
||||
&HeterEventQueueBase::doDispatchItem<PrototypeInfo>,
|
||||
typename PrototypeInfo::ArgsTuple(std::forward<T>(first), std::forward<Args>(args)...)
|
||||
));
|
||||
|
||||
if(doCanProcess()) {
|
||||
queueListConditionVariable.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ArgumentMode, typename T, typename ...Args>
|
||||
auto doEnqueue(T && first, Args && ...args)
|
||||
-> typename std::enable_if<std::is_same<ArgumentMode, ArgumentPassingExcludeEvent>::value>::type
|
||||
{
|
||||
using GetEvent = typename SelectGetEvent<Policies_, EventType_, HasFunctionGetEvent<Policies_, T &&, Args...>::value>::Type;
|
||||
using PrototypeInfo = FindPrototypeByArgs<PrototypeList_, Args...>;
|
||||
using QueuedItemType = QueuedItem<typename PrototypeInfo::ArgsTuple>;
|
||||
|
||||
static_assert(PrototypeInfo::index >= 0, "Can't find invoker for the given argument types.");
|
||||
static_assert(std::tuple_size<typename PrototypeInfo::ArgsTuple>::value == sizeof...(Args), "Arguments count mismatch.");
|
||||
|
||||
doEnqueueItem(QueuedItemType(
|
||||
PrototypeInfo::index,
|
||||
GetEvent::getEvent(std::forward<T>(first), args...),
|
||||
&HeterEventQueueBase::doDispatchItem<PrototypeInfo>,
|
||||
typename PrototypeInfo::ArgsTuple(std::forward<Args>(args)...)
|
||||
));
|
||||
|
||||
if(doCanProcess()) {
|
||||
queueListConditionVariable.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void doEnqueueItem(T && item)
|
||||
{
|
||||
BufferedItemList tempList;
|
||||
if(! freeList.empty()) {
|
||||
{
|
||||
std::lock_guard<Mutex> queueListLock(freeListMutex);
|
||||
if(! freeList.empty()) {
|
||||
tempList.splice(tempList.end(), freeList, freeList.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(tempList.empty()) {
|
||||
tempList.emplace_back();
|
||||
}
|
||||
|
||||
auto it = tempList.begin();
|
||||
it->set(std::move(item));
|
||||
|
||||
std::lock_guard<Mutex> queueListLock(queueListMutex);
|
||||
queueList.splice(queueList.end(), tempList, it);
|
||||
}
|
||||
|
||||
private:
|
||||
mutable ConditionVariable queueListConditionVariable;
|
||||
typename Threading::template Atomic<int> queueEmptyCounter;
|
||||
typename Threading::template Atomic<int> queueNotifyCounter;
|
||||
mutable Mutex queueListMutex;
|
||||
BufferedItemList queueList;
|
||||
Mutex freeListMutex;
|
||||
BufferedItemList freeList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
template <
|
||||
typename Event_,
|
||||
typename PrototypeList_,
|
||||
typename Policies_ = DefaultPolicies
|
||||
>
|
||||
class HeterEventQueue : public internal_::InheritMixins<
|
||||
internal_::HeterEventQueueBase<Event_, PrototypeList_, Policies_>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type, public TagEventDispatcher, public TagEventQueue, public TagHeterEventDispatcher, public TagHeterEventQueue
|
||||
{
|
||||
private:
|
||||
using super = typename internal_::InheritMixins<
|
||||
internal_::HeterEventQueueBase<Event_, PrototypeList_, Policies_>,
|
||||
typename internal_::SelectMixins<Policies_, internal_::HasTypeMixins<Policies_>::value >::Type
|
||||
>::Type;
|
||||
|
||||
public:
|
||||
using super::super;
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
// Don't include this header, include eventpolicies.h instead
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <typename T>
|
||||
struct HasTypeArgumentPassingMode
|
||||
{
|
||||
template <typename C> static std::true_type test(typename C::ArgumentPassingMode *) ;
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename T, bool, typename Default> struct SelectArgumentPassingMode { using Type = typename T::ArgumentPassingMode; };
|
||||
template <typename T, typename Default> struct SelectArgumentPassingMode <T, false, Default> { using Type = Default; };
|
||||
|
||||
template <typename T>
|
||||
struct HasTypeThreading
|
||||
{
|
||||
template <typename C> static std::true_type test(typename C::Threading *) ;
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename T, bool> struct SelectThreading { using Type = typename T::Threading; };
|
||||
template <typename T> struct SelectThreading <T, false> { using Type = MultipleThreading; };
|
||||
|
||||
template <typename T>
|
||||
struct HasTypeCallback
|
||||
{
|
||||
template <typename C> static std::true_type test(typename C::Callback *) ;
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename T, bool, typename D> struct SelectCallback { using Type = typename T::Callback; };
|
||||
template <typename T, typename D> struct SelectCallback<T, false, D> { using Type = D; };
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
struct HasFunctionGetEvent
|
||||
{
|
||||
template <typename C> static std::true_type test(decltype(C::getEvent(std::declval<Args>()...)) *);
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename E>
|
||||
struct DefaultGetEvent
|
||||
{
|
||||
template <typename U, typename ...Args>
|
||||
static E getEvent(U && e, Args && ...) {
|
||||
return e;
|
||||
}
|
||||
};
|
||||
template <typename T, typename Key, bool> struct SelectGetEvent { using Type = T; };
|
||||
template <typename T, typename Key> struct SelectGetEvent<T, Key, false> { using Type = DefaultGetEvent<Key>; };
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
struct HasFunctionCanContinueInvoking
|
||||
{
|
||||
template <typename C> static std::true_type test(decltype(C::canContinueInvoking(std::declval<Args>()...)) *) ;
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
struct DefaultCanContinueInvoking
|
||||
{
|
||||
template <typename ...Args>
|
||||
static bool canContinueInvoking(Args && ...) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
template <typename T, bool> struct SelectCanContinueInvoking { using Type = T; };
|
||||
template <typename T> struct SelectCanContinueInvoking<T, false> { using Type = DefaultCanContinueInvoking; };
|
||||
|
||||
template <typename T>
|
||||
struct HasTemplateMap
|
||||
{
|
||||
template <typename C> static std::true_type test(typename C::template Map<int, int> *) ;
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename T>
|
||||
class HasHash
|
||||
{
|
||||
template <typename C> static std::true_type test(decltype(std::hash<C>()(std::declval<C>())) *) ;
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
public:
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename Key, typename Value, typename T, bool>
|
||||
struct SelectMap
|
||||
{
|
||||
using Type = typename T::template Map<Key, Value>;
|
||||
};
|
||||
template <typename Key, typename Value, typename T>
|
||||
struct SelectMap<Key, Value, T, false> {
|
||||
using Type = typename std::conditional<
|
||||
HasHash<Key>::value,
|
||||
std::unordered_map<Key, Value>,
|
||||
std::map<Key, Value>
|
||||
>::type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct HasTemplateQueueList
|
||||
{
|
||||
template <typename C> static std::true_type test(typename C::template QueueList<int> *);
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename Value, typename T, bool>
|
||||
struct SelectQueueList
|
||||
{
|
||||
using Type = typename T::template QueueList<Value>;
|
||||
};
|
||||
template <typename Value, typename T>
|
||||
struct SelectQueueList<Value, T, false> {
|
||||
using Type = std::list<Value>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct HasTypeMixins
|
||||
{
|
||||
template <typename C> static std::true_type test(typename C::Mixins *) ;
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
template <typename T, bool> struct SelectMixins { using Type = typename T::Mixins; };
|
||||
template <typename T> struct SelectMixins <T, false> { using Type = MixinList<>; };
|
||||
|
||||
|
||||
template <typename Root, typename TList>
|
||||
struct InheritMixins;
|
||||
|
||||
template <typename Root, template <typename> class T, template <typename> class ...Args>
|
||||
struct InheritMixins <Root, MixinList<T, Args...> >
|
||||
{
|
||||
using Type = T <typename InheritMixins<Root, MixinList<Args...> >::Type>;
|
||||
};
|
||||
|
||||
template <typename Root>
|
||||
struct InheritMixins <Root, MixinList<> >
|
||||
{
|
||||
using Type = Root;
|
||||
};
|
||||
|
||||
template <typename Root, typename TList, typename Func>
|
||||
struct ForEachMixins;
|
||||
|
||||
template <typename Func, typename Root, template <typename> class T, template <typename> class ...Args>
|
||||
struct ForEachMixins <Root, MixinList<T, Args...>, Func>
|
||||
{
|
||||
using Type = typename InheritMixins<Root, MixinList<T, Args...> >::Type;
|
||||
|
||||
template <typename ...A>
|
||||
static bool forEach(A && ...args) {
|
||||
if(Func::template forEach<Type>(args...)) {
|
||||
return ForEachMixins<Root, MixinList<Args...>, Func>::forEach(std::forward<A>(args)...);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Root, typename Func>
|
||||
struct ForEachMixins <Root, MixinList<>, Func>
|
||||
{
|
||||
using Type = Root;
|
||||
|
||||
template <typename ...A>
|
||||
static bool forEach(A && .../*args*/) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
struct HasFunctionMixinBeforeDispatch
|
||||
{
|
||||
template <typename C> static std::true_type test(
|
||||
decltype(std::declval<C>().mixinBeforeDispatch(std::declval<Args>()...)) *
|
||||
);
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
|
||||
|
||||
} //namespace internal_
|
||||
@@ -0,0 +1,174 @@
|
||||
#ifndef EVENTQUEUE_I_H
|
||||
#define EVENTQUEUE_I_H
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <size_t ...Indexes>
|
||||
struct IndexSequence
|
||||
{
|
||||
};
|
||||
|
||||
template <size_t N, size_t ...Indexes>
|
||||
struct MakeIndexSequence : MakeIndexSequence <N - 1, N - 1, Indexes...>
|
||||
{
|
||||
};
|
||||
|
||||
template <std::size_t ...Indexes>
|
||||
struct MakeIndexSequence<0, Indexes...>
|
||||
{
|
||||
using Type = IndexSequence<Indexes...>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct CounterGuard
|
||||
{
|
||||
explicit CounterGuard(T & v) : value(v) {
|
||||
++value;
|
||||
}
|
||||
|
||||
~CounterGuard() {
|
||||
--value;
|
||||
}
|
||||
|
||||
T & value;
|
||||
};
|
||||
|
||||
using DtorFunc = void (*)(void *);
|
||||
|
||||
template <typename T>
|
||||
void commonDtor(void * instance)
|
||||
{
|
||||
reinterpret_cast<T *>(instance)->~T();
|
||||
}
|
||||
|
||||
// used by EventQueue
|
||||
template <typename T>
|
||||
class BufferedItem
|
||||
{
|
||||
public:
|
||||
using ValueType = T;
|
||||
|
||||
public:
|
||||
explicit BufferedItem() : buffer(), dtor(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
~BufferedItem()
|
||||
{
|
||||
if(dtor != nullptr) {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
BufferedItem(BufferedItem &&) = delete;
|
||||
BufferedItem(const BufferedItem &) = delete;
|
||||
BufferedItem & operator = (const BufferedItem &) = delete;
|
||||
|
||||
void set(T && item) {
|
||||
assert(dtor == nullptr);
|
||||
|
||||
new (buffer.data()) T(std::forward<T>(item));
|
||||
dtor = &commonDtor<T>;
|
||||
}
|
||||
|
||||
T & get() {
|
||||
assert(dtor != nullptr);
|
||||
|
||||
return *reinterpret_cast<T *>(buffer.data());
|
||||
}
|
||||
|
||||
const T & get() const {
|
||||
assert(dtor != nullptr);
|
||||
|
||||
return *reinterpret_cast<const T *>(buffer.data());
|
||||
}
|
||||
|
||||
void clear() {
|
||||
assert(dtor != nullptr);
|
||||
|
||||
dtor(buffer.data());
|
||||
dtor = nullptr;
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return dtor == nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<char, sizeof(T)> buffer;
|
||||
DtorFunc dtor;
|
||||
};
|
||||
|
||||
|
||||
// used by HeterEventQueue
|
||||
template <size_t Size>
|
||||
class BufferedUnion
|
||||
{
|
||||
public:
|
||||
explicit BufferedUnion() : buffer(), dtor(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
~BufferedUnion()
|
||||
{
|
||||
if(dtor != nullptr) {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
BufferedUnion(BufferedUnion &&) = delete;
|
||||
BufferedUnion(const BufferedUnion &) = delete;
|
||||
BufferedUnion & operator = (const BufferedUnion &) = delete;
|
||||
|
||||
template <typename U>
|
||||
void set(U && item) {
|
||||
static_assert(sizeof(U) <= Size, "Item is too large to fit in BufferedUnion");
|
||||
assert(dtor == nullptr);
|
||||
|
||||
new (buffer.data()) U(std::forward<U>(item));
|
||||
dtor = &commonDtor<U>;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
U & get() {
|
||||
assert(dtor != nullptr);
|
||||
|
||||
return *reinterpret_cast<U *>(buffer.data());
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
const U & get() const {
|
||||
assert(dtor != nullptr);
|
||||
|
||||
return *reinterpret_cast<const U *>(buffer.data());
|
||||
}
|
||||
|
||||
void clear() {
|
||||
assert(dtor != nullptr);
|
||||
|
||||
dtor(buffer.data());
|
||||
dtor = nullptr;
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return dtor == nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<char, Size> buffer;
|
||||
DtorFunc dtor;
|
||||
};
|
||||
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef HETERCALLBACKLIST_I_H
|
||||
#define HETERCALLBACKLIST_I_H
|
||||
|
||||
#include "typeutil_i.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
/*
|
||||
// We can't use std::tuple as HeterTuple because std::tuple is instantialized
|
||||
// somewhere in the Map in HeterEventDispatcherBase, that causes compile error
|
||||
// for that function type can't be declared.
|
||||
template <typename ...Types>
|
||||
using HeterTuple = std::tuple<Types...>;
|
||||
|
||||
template <typename T>
|
||||
struct HeterTupleSize;
|
||||
|
||||
template <typename ...Types>
|
||||
struct HeterTupleSize <HeterTuple <Types...> >
|
||||
{
|
||||
enum { value = std::tuple_size<HeterTuple <Types...> >::value };
|
||||
};
|
||||
*/
|
||||
|
||||
template <typename ...Types>
|
||||
struct HeterTuple
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct HeterTupleSize;
|
||||
|
||||
template <typename ...Types>
|
||||
struct HeterTupleSize <HeterTuple <Types...> >
|
||||
{
|
||||
enum { value = sizeof...(Types) };
|
||||
};
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <typename T>
|
||||
struct FindPrototypeDefaultArgTransformer
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <
|
||||
int N,
|
||||
typename PrototypeList_,
|
||||
typename Callable,
|
||||
template <typename> class ArgTransformer = FindPrototypeDefaultArgTransformer,
|
||||
int M = HeterTupleSize<PrototypeList_>::value,
|
||||
typename Enabled = void
|
||||
>
|
||||
struct FindPrototypeByCallableFromIndex;
|
||||
|
||||
template <
|
||||
int N,
|
||||
typename RT,
|
||||
typename ...Args,
|
||||
typename ...Others,
|
||||
typename Callable,
|
||||
template <typename> class ArgTransformer,
|
||||
int M
|
||||
>
|
||||
struct FindPrototypeByCallableFromIndex <
|
||||
N,
|
||||
HeterTuple<RT (Args...), Others...>,
|
||||
Callable,
|
||||
ArgTransformer,
|
||||
M,
|
||||
typename std::enable_if<(N < M)>::type
|
||||
>
|
||||
{
|
||||
enum { canInvoke = CanInvoke<Callable, typename ArgTransformer<Args>::type...>::value };
|
||||
|
||||
using Prototype = typename std::conditional<
|
||||
canInvoke,
|
||||
RT (Args...),
|
||||
typename FindPrototypeByCallableFromIndex<N + 1, HeterTuple<Others...>, Callable, ArgTransformer, M>::Prototype
|
||||
>::type;
|
||||
|
||||
using ArgsTuple = typename std::conditional<
|
||||
canInvoke,
|
||||
std::tuple<typename std::remove_cv<typename std::remove_reference<Args>::type>::type...>,
|
||||
typename FindPrototypeByCallableFromIndex<N + 1, HeterTuple<Others...>, Callable, ArgTransformer, M>::ArgsTuple
|
||||
>::type;
|
||||
|
||||
enum {
|
||||
index = canInvoke
|
||||
? N
|
||||
: FindPrototypeByCallableFromIndex<N + 1, HeterTuple<Others...>, Callable, ArgTransformer, M>::index
|
||||
};
|
||||
};
|
||||
|
||||
template <
|
||||
int N,
|
||||
typename PrototypeList_,
|
||||
typename Callable,
|
||||
template <typename> class ArgTransformer,
|
||||
int M
|
||||
>
|
||||
struct FindPrototypeByCallableFromIndex <
|
||||
N,
|
||||
PrototypeList_,
|
||||
Callable,
|
||||
ArgTransformer,
|
||||
M,
|
||||
typename std::enable_if<(N >= M)>::type
|
||||
>
|
||||
{
|
||||
using Prototype = void;
|
||||
|
||||
using ArgsTuple = std::tuple<>;
|
||||
|
||||
enum {
|
||||
index = -1
|
||||
};
|
||||
};
|
||||
|
||||
template <typename PrototypeList_, typename Callable, template <typename> class ArgTransformer = FindPrototypeDefaultArgTransformer>
|
||||
struct FindPrototypeByCallable : public FindPrototypeByCallableFromIndex <0, PrototypeList_, Callable, ArgTransformer>
|
||||
{
|
||||
};
|
||||
|
||||
template <int N, typename PrototypeList_, typename ...InArgs>
|
||||
struct FindPrototypeByArgsFromIndex;
|
||||
|
||||
template <int N, typename RT, typename ...Args, typename ...Others, typename ...InArgs>
|
||||
struct FindPrototypeByArgsFromIndex <N, HeterTuple<RT (Args...), Others...>, InArgs...>
|
||||
{
|
||||
enum { canInvoke = CanInvoke<RT (Args...), InArgs...>::value };
|
||||
|
||||
using Prototype = typename std::conditional<
|
||||
canInvoke,
|
||||
RT (Args...),
|
||||
typename FindPrototypeByArgsFromIndex<N + 1, HeterTuple<Others...>, InArgs...>::Prototype
|
||||
>::type;
|
||||
|
||||
using ArgsTuple = typename std::conditional<
|
||||
canInvoke,
|
||||
std::tuple<typename std::remove_cv<typename std::remove_reference<Args>::type>::type...>,
|
||||
typename FindPrototypeByArgsFromIndex<N + 1, HeterTuple<Others...>, InArgs...>::ArgsTuple
|
||||
>::type;
|
||||
|
||||
enum {
|
||||
index = canInvoke
|
||||
? N
|
||||
: FindPrototypeByArgsFromIndex<N + 1, HeterTuple<Others...>, InArgs...>::index
|
||||
};
|
||||
};
|
||||
|
||||
template <int N, typename ...InArgs>
|
||||
struct FindPrototypeByArgsFromIndex <N, HeterTuple<>, InArgs...>
|
||||
{
|
||||
using Prototype = void;
|
||||
|
||||
using ArgsTuple = std::tuple<>;
|
||||
|
||||
enum { index = -1 };
|
||||
};
|
||||
|
||||
template <typename PrototypeList_, typename ...InArgs>
|
||||
struct FindPrototypeByArgs : public FindPrototypeByArgsFromIndex <0, PrototypeList_, InArgs...>
|
||||
{
|
||||
};
|
||||
|
||||
template <int I, int N, typename PrototypeList_>
|
||||
struct FindPrototypeByIndexHelper;
|
||||
|
||||
template <int I, int N, typename RT, typename ...Args, typename ...Others>
|
||||
struct FindPrototypeByIndexHelper <I, N, HeterTuple<RT (Args...), Others...> >
|
||||
{
|
||||
using NextType = FindPrototypeByIndexHelper<I + 1, N, HeterTuple<Others...> >;
|
||||
using Prototype = typename NextType::Prototype;
|
||||
|
||||
using ArgsTuple = typename NextType::ArgsTuple;
|
||||
|
||||
enum { index = NextType::index };
|
||||
};
|
||||
|
||||
template <int N, typename RT, typename ...Args, typename ...Others>
|
||||
struct FindPrototypeByIndexHelper <N, N, HeterTuple<RT (Args...), Others...> >
|
||||
{
|
||||
using Prototype = RT (Args...);
|
||||
|
||||
using ArgsTuple = HeterTuple<typename std::remove_cv<typename std::remove_reference<Args>::type>::type...>;
|
||||
|
||||
enum { index = N };
|
||||
};
|
||||
|
||||
template <int I, int N>
|
||||
struct FindPrototypeByIndexHelper <I, N, HeterTuple<>>
|
||||
{
|
||||
using Prototype = void;
|
||||
|
||||
using ArgsTuple = HeterTuple<>;
|
||||
|
||||
enum { index = -1 };
|
||||
};
|
||||
|
||||
template <typename PrototypeList_, int N>
|
||||
struct FindPrototypeByIndex : public FindPrototypeByIndexHelper <0, N, PrototypeList_>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename PrototypeList_, template <typename ...> class Record>
|
||||
struct GetCallablePrototypeMaxSize;
|
||||
|
||||
template <typename RT, typename ...Args, typename ...Others, template <typename ...> class Record>
|
||||
struct GetCallablePrototypeMaxSize <HeterTuple<RT (Args...), Others...>, Record>
|
||||
{
|
||||
enum {
|
||||
my = sizeof(Record<Args...>),
|
||||
other = GetCallablePrototypeMaxSize<HeterTuple<Others...>, Record>::value
|
||||
};
|
||||
enum { value = (my > other ? (int)my : (int)other) };
|
||||
};
|
||||
|
||||
template <template <typename ...> class Record>
|
||||
struct GetCallablePrototypeMaxSize <HeterTuple<>, Record>
|
||||
{
|
||||
enum { value = 1 }; // set minimum size to 1 instead of 0
|
||||
};
|
||||
|
||||
template <typename List, typename Item>
|
||||
struct PrependHeterTuple;
|
||||
|
||||
template <typename Item, typename ...Types>
|
||||
struct PrependHeterTuple <HeterTuple<Types...>, Item>
|
||||
{
|
||||
using Type = HeterTuple<Item, Types...>;
|
||||
};
|
||||
|
||||
template <typename List, typename Replacement>
|
||||
struct ReplaceReturnTypeList;
|
||||
|
||||
template <typename Replacement, typename RT, typename ...Args, typename ...Others>
|
||||
struct ReplaceReturnTypeList <HeterTuple<RT (Args...), Others...>, Replacement>
|
||||
{
|
||||
using Type = typename PrependHeterTuple<
|
||||
typename ReplaceReturnTypeList<HeterTuple<Others...>, Replacement>::Type,
|
||||
Replacement (Args...)
|
||||
>::Type;
|
||||
};
|
||||
|
||||
template <typename Replacement>
|
||||
struct ReplaceReturnTypeList <HeterTuple<>, Replacement>
|
||||
{
|
||||
using Type = HeterTuple<>;
|
||||
};
|
||||
|
||||
template <typename F, template <typename> class T>
|
||||
struct TransformArgumentsList;
|
||||
|
||||
template <template <typename> class T, typename RT, typename ...Args, typename ...Others>
|
||||
struct TransformArgumentsList <HeterTuple<RT (Args...), Others...>, T>
|
||||
{
|
||||
using Type = typename PrependHeterTuple<
|
||||
typename TransformArgumentsList<HeterTuple<Others...>, T>::Type,
|
||||
RT (typename T<Args>::type...)
|
||||
>::Type;
|
||||
};
|
||||
|
||||
template <template <typename> class T>
|
||||
struct TransformArgumentsList <HeterTuple<>, T>
|
||||
{
|
||||
using Type = HeterTuple<>;
|
||||
};
|
||||
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef TYPEUTIL_I_H
|
||||
#define TYPEUTIL_I_H
|
||||
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <typename F, template <typename> class T>
|
||||
struct TransformArguments;
|
||||
|
||||
template <template <typename> class T, typename RT, typename ...Args>
|
||||
struct TransformArguments <RT (Args...), T>
|
||||
{
|
||||
using Type = RT (typename T<Args>::type...);
|
||||
};
|
||||
|
||||
template <typename F, typename Replacement>
|
||||
struct ReplaceReturnType;
|
||||
|
||||
template <typename Replacement, typename RT, typename ...Args>
|
||||
struct ReplaceReturnType <RT (Args...), Replacement>
|
||||
{
|
||||
using Type = Replacement (Args...);
|
||||
};
|
||||
|
||||
template <int N, int M>
|
||||
struct IntToConstantHelper
|
||||
{
|
||||
template <typename C, typename ...Args>
|
||||
static auto find(const int index, C && c, Args && ...args)
|
||||
-> decltype(std::declval<C>().template operator()<0>(std::declval<Args>()...))
|
||||
{
|
||||
if(N == index) {
|
||||
return c.template operator()<N>(std::forward<Args>(args)...);
|
||||
}
|
||||
else {
|
||||
return IntToConstantHelper<N + 1, M>::find(index, std::forward<C>(c), std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <int M>
|
||||
struct IntToConstantHelper <M, M>
|
||||
{
|
||||
template <typename C, typename ...Args>
|
||||
static auto find(const int /*index*/, C && c, Args && ...args)
|
||||
-> decltype(std::declval<C>().template operator()<0>(std::declval<Args>()...))
|
||||
{
|
||||
return decltype(c.template operator()<0>(std::forward<Args>(args)...))();
|
||||
}
|
||||
};
|
||||
|
||||
template <int M, typename C, typename ...Args>
|
||||
auto intToConstant(const int index, C && c, Args && ...args)
|
||||
-> decltype(std::declval<C>().template operator()<0>(std::declval<Args>()...))
|
||||
{
|
||||
return IntToConstantHelper<0, M>::find(index, std::forward<C>(c), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename F, typename ...Args>
|
||||
struct CanInvoke
|
||||
{
|
||||
template <typename U, typename ...X>
|
||||
static auto invoke(int) -> decltype(std::declval<U>()(std::declval<X>()...), std::true_type());
|
||||
|
||||
template <typename U, typename ...X>
|
||||
static auto invoke(...) -> std::false_type;
|
||||
|
||||
enum {
|
||||
value = !! decltype(invoke<F, Args...>(0))()
|
||||
};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ShiftTuple;
|
||||
|
||||
template <typename A, typename ...Args>
|
||||
struct ShiftTuple <std::tuple<A, Args...> >
|
||||
{
|
||||
using Type = std::tuple<Args...>;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ShiftTuple <std::tuple<> >
|
||||
{
|
||||
using Type = std::tuple<>;
|
||||
};
|
||||
|
||||
// for compile time debug
|
||||
template<typename T>
|
||||
void printTypeInCompileTime(T * = 0)
|
||||
{
|
||||
static_assert(std::is_same<T, int>::value && ! std::is_same<T, int>::value, "The error shows the type name.");
|
||||
}
|
||||
template<int N>
|
||||
void printIntInCompileTime()
|
||||
{
|
||||
int n = 0;
|
||||
switch(n) {
|
||||
case N:
|
||||
case N:
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MIXINFILTER_H_713231680355
|
||||
#define MIXINFILTER_H_713231680355
|
||||
|
||||
#include "../callbacklist.h"
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
template <typename Base>
|
||||
class MixinFilter : public Base
|
||||
{
|
||||
private:
|
||||
using super = Base;
|
||||
|
||||
using BoolReferencePrototype = typename internal_::ReplaceReturnType<
|
||||
typename internal_::TransformArguments<
|
||||
typename super::Prototype,
|
||||
std::add_lvalue_reference
|
||||
>::Type,
|
||||
bool
|
||||
>::Type;
|
||||
|
||||
using Filter = std::function<BoolReferencePrototype>;
|
||||
using FilterList = CallbackList<BoolReferencePrototype>;
|
||||
|
||||
public:
|
||||
using FilterHandle = typename FilterList::Handle;
|
||||
|
||||
public:
|
||||
FilterHandle appendFilter(const Filter & filter)
|
||||
{
|
||||
return filterList.append(filter);
|
||||
}
|
||||
|
||||
bool removeFilter(const FilterHandle & filterHandle)
|
||||
{
|
||||
return filterList.remove(filterHandle);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
bool mixinBeforeDispatch(Args && ...args) const {
|
||||
if(! filterList.empty()) {
|
||||
if(! filterList.forEachIf([&args...](typename FilterList::Callback & callback) {
|
||||
return callback(args...);
|
||||
})
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
FilterList filterList;
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MIXINHETERFILTER_H_990158796753
|
||||
#define MIXINHETERFILTER_H_990158796753
|
||||
|
||||
#include "../hetercallbacklist.h"
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
template <typename Base>
|
||||
class MixinHeterFilter : public Base
|
||||
{
|
||||
private:
|
||||
using super = Base;
|
||||
|
||||
using BoolReferencePrototypeList = typename internal_::ReplaceReturnTypeList<
|
||||
typename internal_::TransformArgumentsList<
|
||||
typename super::PrototypeList,
|
||||
std::add_lvalue_reference
|
||||
>::Type,
|
||||
bool
|
||||
>::Type;
|
||||
|
||||
using FilterList = HeterCallbackList<BoolReferencePrototypeList>;
|
||||
|
||||
public:
|
||||
using FilterHandle = typename FilterList::Handle;
|
||||
|
||||
public:
|
||||
template <typename Callback>
|
||||
FilterHandle appendFilter(const Callback & filter)
|
||||
{
|
||||
return filterList.append(filter);
|
||||
}
|
||||
|
||||
bool removeFilter(const FilterHandle & filterHandle)
|
||||
{
|
||||
return filterList.remove(filterHandle);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
bool mixinBeforeDispatch(Args && ...args) const {
|
||||
if(! filterList.template forEachIf<void (Args...)>([&args...](const typename std::function<bool (Args...)> & callback) -> bool {
|
||||
return callback(std::forward<Args>(args)...);
|
||||
})
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
FilterList filterList;
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef ANYDATA_H_320827729782
|
||||
#define ANYDATA_H_320827729782
|
||||
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace anydata_internal_ {
|
||||
|
||||
template <typename T>
|
||||
void funcDeleteObject(void * object)
|
||||
{
|
||||
delete static_cast<T *>(object);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void funcFreeObject(void * object)
|
||||
{
|
||||
static_cast<T *>(object)->~T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto doFuncMoveConstruct(void * object, void * buffer)
|
||||
-> typename std::enable_if<std::is_move_constructible<T>::value>::type
|
||||
{
|
||||
new (buffer) T(std::move(*(T *)object));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto doFuncMoveConstruct(void * object, void * buffer)
|
||||
-> typename std::enable_if<! std::is_move_constructible<T>::value>::type
|
||||
{
|
||||
static_assert(std::is_move_constructible<T>::value, "AnyData: object must be either copy or move constructible");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void funcMoveConstruct(void * object, void * buffer)
|
||||
{
|
||||
doFuncMoveConstruct<T>(object, buffer);
|
||||
}
|
||||
|
||||
struct AnyDataFunctions
|
||||
{
|
||||
void (*free)(void *);
|
||||
void (*moveConstruct)(void *, void *);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const AnyDataFunctions * doGetAnyDataFunctions()
|
||||
{
|
||||
static const AnyDataFunctions functions {
|
||||
&funcFreeObject<T>,
|
||||
&funcMoveConstruct<T>
|
||||
};
|
||||
return &functions;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct RemoveCvRef
|
||||
{
|
||||
using Type = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const AnyDataFunctions * getAnyDataFunctions()
|
||||
{
|
||||
using U = typename RemoveCvRef<T>::Type;
|
||||
return doGetAnyDataFunctions<U>();
|
||||
}
|
||||
|
||||
template <typename ...Ts>
|
||||
struct MaxSizeOf;
|
||||
|
||||
template <typename T, typename ...Ts>
|
||||
struct MaxSizeOf <T, Ts...>
|
||||
{
|
||||
static constexpr std::size_t otherSize = MaxSizeOf<Ts...>::value;
|
||||
static constexpr std::size_t tSize = sizeof(T);
|
||||
|
||||
static constexpr std::size_t value = tSize > otherSize ? tSize : otherSize;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct MaxSizeOf <T>
|
||||
{
|
||||
static constexpr std::size_t value = sizeof(T);
|
||||
};
|
||||
|
||||
class LargeData
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
explicit LargeData(T && object) : data(), deleter() {
|
||||
using U = typename RemoveCvRef<T>::Type;
|
||||
deleter = &funcDeleteObject<U>;
|
||||
data = new U(std::forward<T>(object));
|
||||
}
|
||||
|
||||
~LargeData() {
|
||||
if(data != nullptr) {
|
||||
assert(deleter != nullptr);
|
||||
deleter(data);
|
||||
}
|
||||
}
|
||||
|
||||
LargeData(LargeData && other) : data(), deleter() {
|
||||
std::swap(data, other.data);
|
||||
std::swap(deleter, other.deleter);
|
||||
}
|
||||
|
||||
LargeData(const LargeData & other) = delete;
|
||||
LargeData & operator = (const LargeData & other) = delete;
|
||||
LargeData & operator = (LargeData && other) = delete;
|
||||
|
||||
const void * getAddress() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool isType() const {
|
||||
using U = typename RemoveCvRef<T>::Type;
|
||||
return deleter == &funcDeleteObject<U>;
|
||||
}
|
||||
|
||||
private:
|
||||
void * data;
|
||||
void (*deleter)(void *);
|
||||
};
|
||||
|
||||
} //namespace anydata_internal_
|
||||
|
||||
template <std::size_t maxSize_>
|
||||
class AnyData
|
||||
{
|
||||
private:
|
||||
using LargeData = anydata_internal_::LargeData;
|
||||
static constexpr std::size_t maxSize = maxSize_ < sizeof(LargeData) ? sizeof(LargeData) : maxSize_;
|
||||
|
||||
static_assert(maxSize > 0, "AnyData: maxSize must be greater than 0");
|
||||
|
||||
public:
|
||||
~AnyData() {
|
||||
if(functions != nullptr) {
|
||||
functions->free(buffer.data());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AnyData(T && object,
|
||||
typename std::enable_if<(sizeof(typename anydata_internal_::RemoveCvRef<T>::Type) <= maxSize)>::type * = 0)
|
||||
: functions(anydata_internal_::getAnyDataFunctions<T>()), buffer() {
|
||||
using U = typename std::remove_reference<T>::type;
|
||||
new (buffer.data()) U(std::forward<T>(object));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AnyData(T && object,
|
||||
typename std::enable_if<(sizeof(typename anydata_internal_::RemoveCvRef<T>::Type) > maxSize)>::type * = 0)
|
||||
: functions(anydata_internal_::getAnyDataFunctions<LargeData>()), buffer() {
|
||||
new (buffer.data()) LargeData(std::forward<T>(object));
|
||||
}
|
||||
|
||||
AnyData(AnyData && other) : functions(other.functions), buffer() {
|
||||
if(functions != nullptr) {
|
||||
functions->moveConstruct(other.buffer.data(), buffer.data());
|
||||
}
|
||||
}
|
||||
|
||||
AnyData(const AnyData & other) = delete;
|
||||
AnyData(AnyData & other) = delete;
|
||||
AnyData & operator = (const AnyData & other) = delete;
|
||||
AnyData & operator = (AnyData && other) = delete;
|
||||
|
||||
template <typename T>
|
||||
const T & get() const {
|
||||
return *(T *)getAddress();
|
||||
}
|
||||
|
||||
const void * getAddress() const {
|
||||
assert(functions != nullptr);
|
||||
|
||||
if(! isLargerData()) {
|
||||
return buffer.data();
|
||||
}
|
||||
else {
|
||||
return ((const LargeData *)buffer.data())->getAddress();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool isType() const {
|
||||
if(! isLargerData()) {
|
||||
return anydata_internal_::getAnyDataFunctions<T>() == functions;
|
||||
}
|
||||
else {
|
||||
return ((const LargeData *)buffer.data())->isType<T>();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
operator T & () const {
|
||||
return *(T *)getAddress();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
operator T * () const {
|
||||
return (T *)getAddress();
|
||||
}
|
||||
|
||||
private:
|
||||
bool isLargerData() const {
|
||||
return functions == anydata_internal_::getAnyDataFunctions<LargeData>();
|
||||
}
|
||||
|
||||
private:
|
||||
const anydata_internal_::AnyDataFunctions * functions;
|
||||
std::array<std::uint8_t, maxSize> buffer;
|
||||
};
|
||||
|
||||
template <typename ...Ts>
|
||||
constexpr std::size_t maxSizeOf()
|
||||
{
|
||||
return anydata_internal_::MaxSizeOf<Ts...>::value;
|
||||
}
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef ANYID_H_320827729782
|
||||
#define ANYID_H_320827729782
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace anyid_internal_ {
|
||||
|
||||
template <typename T, typename Enabled = void>
|
||||
struct MakeHash;
|
||||
|
||||
template <typename T>
|
||||
struct MakeHash <T, typename std::enable_if<std::is_convertible<T, std::size_t>::value>::type>
|
||||
{
|
||||
std::size_t operator() (T value) const {
|
||||
return static_cast<std::size_t>(value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct MakeHash <T, typename std::enable_if<! std::is_convertible<T, std::size_t>::value>::type>
|
||||
{
|
||||
std::size_t operator() (const T & value) const {
|
||||
return std::hash<T>()(value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class HasLess
|
||||
{
|
||||
template <typename C> static std::true_type test(decltype(std::declval<C>() < std::declval<C>()) *);
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
public:
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
auto compareLessThan(const T & a, const T & b)
|
||||
-> typename std::enable_if<HasLess<T>::value, bool>::type
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto compareLessThan(const T &, const T &)
|
||||
-> typename std::enable_if<! HasLess<T>::value, bool>::type
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class HasEqual
|
||||
{
|
||||
template <typename C> static std::true_type test(decltype(std::declval<C>() == std::declval<C>()) *);
|
||||
template <typename C> static std::false_type test(...);
|
||||
|
||||
public:
|
||||
enum { value = !! decltype(test<T>(0))() };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
auto compareEqual(const T & a, const T & b)
|
||||
-> typename std::enable_if<HasEqual<T>::value, bool>::type
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto compareEqual(const T &, const T &)
|
||||
-> typename std::enable_if<! HasEqual<T>::value, bool>::type
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} //namespace anyid_internal_
|
||||
|
||||
struct EmptyAnyStorage
|
||||
{
|
||||
EmptyAnyStorage() {}
|
||||
|
||||
template <typename T>
|
||||
EmptyAnyStorage(const T &) {}
|
||||
};
|
||||
|
||||
template <template <typename> class Digester = std::hash, typename Storage = EmptyAnyStorage>
|
||||
class AnyId
|
||||
{
|
||||
public:
|
||||
using DigestType = decltype(std::declval<Digester<int>>()(0));
|
||||
|
||||
public:
|
||||
AnyId() : digest(), value() {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
AnyId(const T & value)
|
||||
: digest(Digester<T>()(value)), value(value)
|
||||
{
|
||||
}
|
||||
|
||||
DigestType getDigest() const {
|
||||
return digest;
|
||||
}
|
||||
|
||||
const Storage & getValue() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
DigestType digest;
|
||||
Storage value;
|
||||
};
|
||||
|
||||
template <template <typename> class Digester, typename Storage>
|
||||
bool operator == (const AnyId<Digester, Storage> & a, const AnyId<Digester, Storage> & b)
|
||||
{
|
||||
return a.getDigest() == b.getDigest() && anyid_internal_::compareEqual(a.getValue(), b.getValue());
|
||||
}
|
||||
|
||||
template <template <typename> class Digester, typename Storage>
|
||||
bool operator < (const AnyId<Digester, Storage> & a, const AnyId<Digester, Storage> & b)
|
||||
{
|
||||
return (a.getDigest() < b.getDigest())
|
||||
|| (anyid_internal_::compareLessThan(a.getValue(), b.getValue()) && a.getDigest() == b.getDigest())
|
||||
;
|
||||
}
|
||||
|
||||
using AnyHashableId = AnyId<>;
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <template <typename> class Digester, typename Storage>
|
||||
struct hash<eventpp::AnyId<Digester, Storage> >
|
||||
{
|
||||
std::size_t operator()(const eventpp::AnyId<Digester, Storage> & value) const noexcept
|
||||
{
|
||||
return eventpp::anyid_internal_::MakeHash<typename eventpp::AnyId<Digester, Storage>::DigestType>()(value.getDigest());
|
||||
}
|
||||
};
|
||||
} //namespace std
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef ARGUMENTADAPTER_H_566280692673
|
||||
#define ARGUMENTADAPTER_H_566280692673
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace adapter_internal_ {
|
||||
|
||||
template <typename T>
|
||||
struct StaticCast
|
||||
{
|
||||
template <typename U>
|
||||
static T cast(U && value)
|
||||
{
|
||||
return static_cast<T>(value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct StaticCast<std::shared_ptr<T> >
|
||||
{
|
||||
template <typename U>
|
||||
static std::shared_ptr<T> cast(U && value)
|
||||
{
|
||||
return std::static_pointer_cast<T>(value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct IsSharedPtr
|
||||
{
|
||||
enum { value = false };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct IsSharedPtr<std::shared_ptr<T> >
|
||||
{
|
||||
enum { value = true };
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
struct IsAnySharedPtr
|
||||
{
|
||||
enum { value = false };
|
||||
};
|
||||
|
||||
template <typename First, typename ...Others>
|
||||
struct IsAnySharedPtr <First, Others...>
|
||||
{
|
||||
enum { value = IsSharedPtr<First>::value
|
||||
|| IsAnySharedPtr<Others...>::value };
|
||||
};
|
||||
|
||||
} //namespace adapter_internal_
|
||||
|
||||
template <typename Func, typename Prototype, typename IsSharedPtr = void>
|
||||
struct ArgumentAdapter;
|
||||
|
||||
template <typename Func, typename R, typename ...Args>
|
||||
struct ArgumentAdapter <
|
||||
Func,
|
||||
R(Args...),
|
||||
typename std::enable_if<! adapter_internal_::IsAnySharedPtr<Args...>::value>::type
|
||||
>
|
||||
{
|
||||
explicit ArgumentAdapter(Func f)
|
||||
: func(std::move(f))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ...A>
|
||||
void operator() (A &&...args) {
|
||||
func(std::forward<Args>(static_cast<Args>(args))...);
|
||||
}
|
||||
|
||||
Func func;
|
||||
};
|
||||
|
||||
template <typename Func, typename R, typename ...Args>
|
||||
struct ArgumentAdapter <
|
||||
Func,
|
||||
R(Args...),
|
||||
typename std::enable_if<adapter_internal_::IsAnySharedPtr<Args...>::value>::type
|
||||
>
|
||||
{
|
||||
explicit ArgumentAdapter(Func f)
|
||||
: func(std::move(f))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ...A>
|
||||
void operator() (A &&...args) {
|
||||
func(std::forward<Args>(adapter_internal_::StaticCast<Args>::cast(args))...);
|
||||
}
|
||||
|
||||
Func func;
|
||||
};
|
||||
|
||||
template <template <typename> class Func, typename R, typename ...Args>
|
||||
ArgumentAdapter<Func<R(Args...)>, R(Args...)> argumentAdapter(Func<R(Args...)> func)
|
||||
{
|
||||
return ArgumentAdapter<Func<R(Args...)>, R(Args...)>(std::move(func));
|
||||
}
|
||||
|
||||
template <typename Prototype, typename Func>
|
||||
ArgumentAdapter<Func, Prototype> argumentAdapter(Func func)
|
||||
{
|
||||
return ArgumentAdapter<Func, Prototype>(std::move(func));
|
||||
}
|
||||
|
||||
template <typename R, typename ...Args>
|
||||
ArgumentAdapter<R(*)(Args...), R(Args...)> argumentAdapter(R(*func)(Args...))
|
||||
{
|
||||
return ArgumentAdapter<R(*)(Args...), R(Args...)>(std::move(func));
|
||||
}
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CONDITIONALFUNCTOR_H_828958739581
|
||||
#define CONDITIONALFUNCTOR_H_828958739581
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
template <typename Func, typename Condition>
|
||||
struct ConditionalFunctor
|
||||
{
|
||||
ConditionalFunctor(Func f, Condition condition)
|
||||
: func(std::move(f)), condition(std::move(condition))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ...A>
|
||||
void operator() (A &&...args) {
|
||||
if(condition(args...)) {
|
||||
func(std::forward<A>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
Func func;
|
||||
Condition condition;
|
||||
};
|
||||
|
||||
template <typename Func, typename Condition>
|
||||
ConditionalFunctor<Func, Condition> conditionalFunctor(Func func, Condition condition)
|
||||
{
|
||||
return ConditionalFunctor<Func, Condition>(std::move(func), std::move(condition));
|
||||
}
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CONDITIONALREMOVER_H_882115092280
|
||||
#define CONDITIONALREMOVER_H_882115092280
|
||||
|
||||
#include "../eventpolicies.h"
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
template <typename DispatcherType, typename Enabled = void>
|
||||
class ConditionalRemover;
|
||||
|
||||
template <typename DispatcherType>
|
||||
class ConditionalRemover <
|
||||
DispatcherType,
|
||||
typename std::enable_if<std::is_base_of<TagEventDispatcher, DispatcherType>::value>::type
|
||||
>
|
||||
{
|
||||
private:
|
||||
template <typename Callback, typename Condition>
|
||||
struct ItemByCondition
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
Condition shouldRemove;
|
||||
DispatcherType & dispatcher;
|
||||
typename DispatcherType::Event event;
|
||||
Callback listener;
|
||||
typename DispatcherType::Handle handle;
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
auto operator() (Args && ...args) const
|
||||
-> typename std::enable_if<internal_::CanInvoke<Condition, Args...>::value>::type {
|
||||
if(data->shouldRemove(args...)) {
|
||||
data->dispatcher.removeListener(data->event, data->handle);
|
||||
}
|
||||
data->listener(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
auto operator() (Args && ...args) const
|
||||
-> typename std::enable_if<! internal_::CanInvoke<Condition, Args...>::value>::type {
|
||||
if(data->shouldRemove()) {
|
||||
data->dispatcher.removeListener(data->event, data->handle);
|
||||
}
|
||||
data->listener(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
std::shared_ptr<Data> data;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit ConditionalRemover(DispatcherType & dispatcher)
|
||||
: dispatcher(dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Callback, typename Condition>
|
||||
typename DispatcherType::Handle appendListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener,
|
||||
const Condition & condition
|
||||
)
|
||||
{
|
||||
using Wrapper = ItemByCondition<Callback, Condition>;
|
||||
auto data = std::make_shared<typename Wrapper::Data>(typename Wrapper::Data {
|
||||
condition, dispatcher, event, listener, typename DispatcherType::Handle()
|
||||
});
|
||||
data->handle = dispatcher.appendListener(event, Wrapper{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback, typename Condition>
|
||||
typename DispatcherType::Handle prependListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener,
|
||||
const Condition & condition
|
||||
)
|
||||
{
|
||||
using Wrapper = ItemByCondition<Callback, Condition>;
|
||||
auto data = std::make_shared<typename Wrapper::Data>(typename Wrapper::Data {
|
||||
condition, dispatcher, event, listener, typename DispatcherType::Handle()
|
||||
});
|
||||
data->handle = dispatcher.prependListener(event, Wrapper{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback, typename Condition>
|
||||
typename DispatcherType::Handle insertListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener,
|
||||
const typename DispatcherType::Handle & before,
|
||||
const Condition & condition
|
||||
)
|
||||
{
|
||||
using Wrapper = ItemByCondition<Callback, Condition>;
|
||||
auto data = std::make_shared<typename Wrapper::Data>(typename Wrapper::Data {
|
||||
condition, dispatcher, event, listener, typename DispatcherType::Handle()
|
||||
});
|
||||
data->handle = dispatcher.insertListener(event, Wrapper{data}, before);
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
private:
|
||||
DispatcherType & dispatcher;
|
||||
};
|
||||
|
||||
template <typename CallbackListType>
|
||||
class ConditionalRemover <
|
||||
CallbackListType,
|
||||
typename std::enable_if<std::is_base_of<TagCallbackList, CallbackListType>::value>::type
|
||||
>
|
||||
{
|
||||
private:
|
||||
template <typename Callback, typename Condition>
|
||||
struct ItemByCondition
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
Condition shouldRemove;
|
||||
CallbackListType & callbackList;
|
||||
Callback listener;
|
||||
typename CallbackListType::Handle handle;
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
auto operator() (Args && ...args) const
|
||||
-> typename std::enable_if<internal_::CanInvoke<Condition, Args...>::value>::type const {
|
||||
if(data->shouldRemove(args...)) {
|
||||
data->callbackList.remove(data->handle);
|
||||
}
|
||||
data->listener(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
auto operator() (Args && ...args) const
|
||||
-> typename std::enable_if<! internal_::CanInvoke<Condition, Args...>::value>::type {
|
||||
if(data->shouldRemove()) {
|
||||
data->callbackList.remove(data->handle);
|
||||
}
|
||||
data->listener(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
std::shared_ptr<Data> data;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit ConditionalRemover(CallbackListType & callbackList)
|
||||
: callbackList(callbackList)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Callback, typename Condition>
|
||||
typename CallbackListType::Handle append(
|
||||
const Callback & listener,
|
||||
const Condition & condition
|
||||
)
|
||||
{
|
||||
using Wrapper = ItemByCondition<Callback, Condition>;
|
||||
auto data = std::make_shared<typename Wrapper::Data>(typename Wrapper::Data {
|
||||
condition, callbackList, listener, typename CallbackListType::Handle()
|
||||
});
|
||||
data->handle = callbackList.append(Wrapper{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback, typename Condition>
|
||||
typename CallbackListType::Handle prepend(
|
||||
const Callback & listener,
|
||||
const Condition & condition
|
||||
)
|
||||
{
|
||||
using Wrapper = ItemByCondition<Callback, Condition>;
|
||||
auto data = std::make_shared<typename Wrapper::Data>(typename Wrapper::Data {
|
||||
condition, callbackList, listener, typename CallbackListType::Handle()
|
||||
});
|
||||
data->handle = callbackList.prepend(Wrapper{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback, typename Condition>
|
||||
typename CallbackListType::Handle insert(
|
||||
const Callback & listener,
|
||||
const typename CallbackListType::Handle & before,
|
||||
const Condition & condition
|
||||
)
|
||||
{
|
||||
using Wrapper = ItemByCondition<Callback, Condition>;
|
||||
auto data = std::make_shared<typename Wrapper::Data>(typename Wrapper::Data {
|
||||
condition, callbackList, listener, typename CallbackListType::Handle()
|
||||
});
|
||||
data->handle = callbackList.insert(Wrapper{data}, before);
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
private:
|
||||
CallbackListType & callbackList;
|
||||
};
|
||||
|
||||
template <typename DispatcherType>
|
||||
ConditionalRemover<DispatcherType> conditionalRemover(DispatcherType & dispatcher)
|
||||
{
|
||||
return ConditionalRemover<DispatcherType>(dispatcher);
|
||||
}
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef COUNTERREMOVER_H_211532679833
|
||||
#define COUNTERREMOVER_H_211532679833
|
||||
|
||||
#include "../eventpolicies.h"
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
template <typename DispatcherType, typename Enabled = void>
|
||||
class CounterRemover;
|
||||
|
||||
template <typename DispatcherType>
|
||||
class CounterRemover <
|
||||
DispatcherType,
|
||||
typename std::enable_if<std::is_base_of<TagEventDispatcher, DispatcherType>::value>::type
|
||||
>
|
||||
{
|
||||
private:
|
||||
template <typename Callback>
|
||||
struct Wrapper
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
int triggerCount;
|
||||
DispatcherType & dispatcher;
|
||||
typename DispatcherType::Event event;
|
||||
Callback listener;
|
||||
typename DispatcherType::Handle handle;
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
void operator() (Args && ...args) const {
|
||||
if(--data->triggerCount <= 0) {
|
||||
data->dispatcher.removeListener(data->event, data->handle);
|
||||
}
|
||||
data->listener(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
std::shared_ptr<Data> data;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit CounterRemover(DispatcherType & dispatcher)
|
||||
: dispatcher(dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename DispatcherType::Handle appendListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener,
|
||||
const int triggerCount = 1
|
||||
)
|
||||
{
|
||||
auto data = std::make_shared<typename Wrapper<Callback>::Data>(typename Wrapper<Callback>::Data {
|
||||
triggerCount, dispatcher, event, listener, typename DispatcherType::Handle()
|
||||
});
|
||||
data->handle = dispatcher.appendListener(event, Wrapper<Callback>{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename DispatcherType::Handle prependListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener,
|
||||
const int triggerCount = 1
|
||||
)
|
||||
{
|
||||
auto data = std::make_shared<typename Wrapper<Callback>::Data>(typename Wrapper<Callback>::Data {
|
||||
triggerCount, dispatcher, event, listener, typename DispatcherType::Handle()
|
||||
});
|
||||
data->handle = dispatcher.prependListener(event, Wrapper<Callback>{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename DispatcherType::Handle insertListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener,
|
||||
const typename DispatcherType::Handle & before,
|
||||
const int triggerCount = 1
|
||||
)
|
||||
{
|
||||
auto data = std::make_shared<typename Wrapper<Callback>::Data>(typename Wrapper<Callback>::Data {
|
||||
triggerCount, dispatcher, event, listener, typename DispatcherType::Handle()
|
||||
});
|
||||
data->handle = dispatcher.insertListener(event, Wrapper<Callback>{data}, before);
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
private:
|
||||
DispatcherType & dispatcher;
|
||||
};
|
||||
|
||||
template <typename CallbackListType>
|
||||
class CounterRemover <
|
||||
CallbackListType,
|
||||
typename std::enable_if<std::is_base_of<TagCallbackList, CallbackListType>::value>::type
|
||||
>
|
||||
{
|
||||
private:
|
||||
template <typename Callback>
|
||||
struct Wrapper
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
int triggerCount;
|
||||
CallbackListType & callbackList;
|
||||
Callback listener;
|
||||
typename CallbackListType::Handle handle;
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
void operator() (Args && ...args) const {
|
||||
if(--data->triggerCount <= 0) {
|
||||
data->callbackList.remove(data->handle);
|
||||
}
|
||||
data->listener(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
std::shared_ptr<Data> data;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit CounterRemover(CallbackListType & callbackList)
|
||||
: callbackList(callbackList)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename CallbackListType::Handle append(
|
||||
const Callback & listener,
|
||||
const int triggerCount = 1
|
||||
)
|
||||
{
|
||||
auto data = std::make_shared<typename Wrapper<Callback>::Data>(typename Wrapper<Callback>::Data {
|
||||
triggerCount, callbackList, listener, typename CallbackListType::Handle()
|
||||
});
|
||||
data->handle = callbackList.append(Wrapper<Callback>{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename CallbackListType::Handle prepend(
|
||||
const Callback & listener,
|
||||
const int triggerCount = 1
|
||||
)
|
||||
{
|
||||
auto data = std::make_shared<typename Wrapper<Callback>::Data>(typename Wrapper<Callback>::Data {
|
||||
triggerCount, callbackList, listener, typename CallbackListType::Handle()
|
||||
});
|
||||
data->handle = callbackList.prepend(Wrapper<Callback>{data});
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename CallbackListType::Handle insert(
|
||||
const Callback & listener,
|
||||
const typename CallbackListType::Handle & before,
|
||||
const int triggerCount = 1
|
||||
)
|
||||
{
|
||||
auto data = std::make_shared<typename Wrapper<Callback>::Data>(typename Wrapper<Callback>::Data {
|
||||
triggerCount, callbackList, listener, typename CallbackListType::Handle()
|
||||
});
|
||||
data->handle = callbackList.insert(Wrapper<Callback>{data}, before);
|
||||
return data->handle;
|
||||
}
|
||||
|
||||
private:
|
||||
CallbackListType & callbackList;
|
||||
};
|
||||
|
||||
template <typename DispatcherType>
|
||||
CounterRemover<DispatcherType> counterRemover(DispatcherType & dispatcher)
|
||||
{
|
||||
return CounterRemover<DispatcherType>(dispatcher);
|
||||
}
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef EVENTMAKER_H_378278023815
|
||||
#define EVENTMAKER_H_378278023815
|
||||
|
||||
// auto generated macros begin
|
||||
|
||||
#define I_EVENTPP_ARG_COUNT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, ...) p15
|
||||
#define EVENTPP_ARG_COUNT(...) EVENTPP_EXPAND(I_EVENTPP_ARG_COUNT(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
|
||||
|
||||
#define I_EVENTPP_ITERATE_ARGS_0(EXEC, DELI)
|
||||
#define I_EVENTPP_ITERATE_ARGS_1(EXEC, DELI, p0) I_EVENTPP_ITERATE_ARGS_0(EXEC, DELI ) EXEC(p0)
|
||||
#define I_EVENTPP_ITERATE_ARGS_2(EXEC, DELI, p0, p1) I_EVENTPP_ITERATE_ARGS_1(EXEC, DELI, p0) DELI() EXEC(p1)
|
||||
#define I_EVENTPP_ITERATE_ARGS_3(EXEC, DELI, p0, p1, p2) I_EVENTPP_ITERATE_ARGS_2(EXEC, DELI, p0, p1) DELI() EXEC(p2)
|
||||
#define I_EVENTPP_ITERATE_ARGS_4(EXEC, DELI, p0, p1, p2, p3) I_EVENTPP_ITERATE_ARGS_3(EXEC, DELI, p0, p1, p2) DELI() EXEC(p3)
|
||||
#define I_EVENTPP_ITERATE_ARGS_5(EXEC, DELI, p0, p1, p2, p3, p4) I_EVENTPP_ITERATE_ARGS_4(EXEC, DELI, p0, p1, p2, p3) DELI() EXEC(p4)
|
||||
#define I_EVENTPP_ITERATE_ARGS_6(EXEC, DELI, p0, p1, p2, p3, p4, p5) I_EVENTPP_ITERATE_ARGS_5(EXEC, DELI, p0, p1, p2, p3, p4) DELI() EXEC(p5)
|
||||
#define I_EVENTPP_ITERATE_ARGS_7(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6) I_EVENTPP_ITERATE_ARGS_6(EXEC, DELI, p0, p1, p2, p3, p4, p5) DELI() EXEC(p6)
|
||||
#define I_EVENTPP_ITERATE_ARGS_8(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7) I_EVENTPP_ITERATE_ARGS_7(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6) DELI() EXEC(p7)
|
||||
#define I_EVENTPP_ITERATE_ARGS_9(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8) I_EVENTPP_ITERATE_ARGS_8(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7) DELI() EXEC(p8)
|
||||
#define I_EVENTPP_ITERATE_ARGS_10(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) I_EVENTPP_ITERATE_ARGS_9(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8) DELI() EXEC(p9)
|
||||
#define I_EVENTPP_ITERATE_ARGS_11(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) I_EVENTPP_ITERATE_ARGS_10(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) DELI() EXEC(p10)
|
||||
#define I_EVENTPP_ITERATE_ARGS_12(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) I_EVENTPP_ITERATE_ARGS_11(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) DELI() EXEC(p11)
|
||||
#define I_EVENTPP_ITERATE_ARGS_13(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) I_EVENTPP_ITERATE_ARGS_12(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) DELI() EXEC(p12)
|
||||
#define I_EVENTPP_ITERATE_ARGS_14(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) I_EVENTPP_ITERATE_ARGS_13(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) DELI() EXEC(p13)
|
||||
#define I_EVENTPP_ITERATE_ARGS_15(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14) I_EVENTPP_ITERATE_ARGS_14(EXEC, DELI, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) DELI() EXEC(p14)
|
||||
#define I_EVENTPP_ITERATE_ARGS_N(EXEC, DELI, N, ...) EVENTPP_EXPAND(EVENTPP_CONCAT(I_EVENTPP_ITERATE_ARGS_, N) (EXEC, DELI, __VA_ARGS__))
|
||||
#define EVENTPP_ITERATE_ARGS(EXEC, DELI, ...) I_EVENTPP_ITERATE_ARGS_N(EXEC, DELI, EVENTPP_ARG_COUNT(__VA_ARGS__), __VA_ARGS__)
|
||||
|
||||
// auto generated macros end
|
||||
|
||||
#define I_EVENTPP_STRINGIFY(x) #x
|
||||
#define EVENTPP_STRINGIFY(x) I_EVENTPP_STRINGIFY(x)
|
||||
|
||||
#define I_EVENTPP_CONCAT(a, b) a ## b
|
||||
#define EVENTPP_CONCAT(a, b) I_EVENTPP_CONCAT(a, b)
|
||||
|
||||
// EVENTPP_EXPAND is used to expand __VA_ARGS__ correctly in VC++
|
||||
#define EVENTPP_EXPAND(...) __VA_ARGS__
|
||||
#define EVENTPP_BRACKETS_EXPAND(...) EVENTPP_EXPAND(EVENTPP_EXPAND __VA_ARGS__)
|
||||
|
||||
#define EVENTPP_EMPTY()
|
||||
#define EVENTPP_COMMA() ,
|
||||
#define EVENTPP_SEMICOLON() ;
|
||||
|
||||
#define I_EVENTPP_GET0_2(p0, ...) p0
|
||||
#define I_EVENTPP_GET0(...) EVENTPP_EXPAND(I_EVENTPP_GET0_2(__VA_ARGS__, ))
|
||||
#define EVENTPP_GET0(p0) EVENTPP_EXPAND(I_EVENTPP_GET0 p0)
|
||||
|
||||
#define I_EVENTPP_GET1_2(p0, p1, ...) p1
|
||||
#define I_EVENTPP_GET1(...) EVENTPP_EXPAND(I_EVENTPP_GET1_2(__VA_ARGS__, ))
|
||||
#define EVENTPP_GET1(p0) EVENTPP_EXPAND(I_EVENTPP_GET1 p0)
|
||||
|
||||
#define I_EVENTPP_GET2_2(p0, p1, p2, ...) p2
|
||||
#define I_EVENTPP_GET2(...) EVENTPP_EXPAND(I_EVENTPP_GET2_2(__VA_ARGS__, ))
|
||||
#define EVENTPP_GET2(p0) EVENTPP_EXPAND(I_EVENTPP_GET2 p0)
|
||||
|
||||
#define EVENTPP_MAKE_FIELD_NAME(p0) EVENTPP_CONCAT(v, EVENTPP_GET1(p0))
|
||||
#define EVENTPP_EXEC_MAKE_FIELD(p0) EVENTPP_GET0(p0) EVENTPP_MAKE_FIELD_NAME(p0)
|
||||
#define EVENTPP_EXEC_MAKE_GETTER(p0) const EVENTPP_GET0(p0) & EVENTPP_GET1(p0) () const { return EVENTPP_MAKE_FIELD_NAME(p0); }
|
||||
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_0(p0)
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_1(p0)
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_2(p0)
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_3(p0) void EVENTPP_GET2(p0) (const EVENTPP_GET0(p0) & value) { EVENTPP_MAKE_FIELD_NAME(p0) = value; }
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_4(p0) I_EVENTPP_MAKE_SETTER_HELPER_3(p0)
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_5(p0) I_EVENTPP_MAKE_SETTER_HELPER_3(p0)
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_6(p0) I_EVENTPP_MAKE_SETTER_HELPER_3(p0)
|
||||
#define I_EVENTPP_EXEC_MAKE_SETTER_N(N, p0) EVENTPP_EXPAND(EVENTPP_CONCAT(I_EVENTPP_EXEC_MAKE_SETTER_, N) (p0))
|
||||
#define EVENTPP_EXEC_MAKE_SETTER(p0) EVENTPP_EXPAND(I_EVENTPP_EXEC_MAKE_SETTER_N(EVENTPP_ARG_COUNT EVENTPP_EXPAND(p0), p0))
|
||||
|
||||
#define EVENTPP_EXEC_MAKE_INITIALIZE(p0) EVENTPP_MAKE_FIELD_NAME(p0)(EVENTPP_MAKE_FIELD_NAME(p0))
|
||||
#define EVENTPP_EXEC_MAKE_DEFAULT_INITIALIZE(p0) EVENTPP_MAKE_FIELD_NAME(p0)()
|
||||
#define EVENTPP_EXEC_MAKE_CTOR_FIELD(p0) const EVENTPP_GET0(p0) & EVENTPP_MAKE_FIELD_NAME(p0)
|
||||
|
||||
#define I_EVENTPP_CHECK(x, n, ...) n
|
||||
#define EVENTPP_CHECK(...) EVENTPP_EXPAND(I_EVENTPP_CHECK(__VA_ARGS__, 0, ))
|
||||
|
||||
#define I_EVENTPP_IS_ENCLOSED_BY_BRACKETS(...) x, 1
|
||||
#define EVENTPP_IS_ENCLOSED_BY_BRACKETS(x) EVENTPP_CHECK(I_EVENTPP_IS_ENCLOSED_BY_BRACKETS x)
|
||||
|
||||
#define I_EVENTPP_IF_1(t, f) t
|
||||
#define I_EVENTPP_IF_0(t, f) f
|
||||
#define EVENTPP_IF(b, t, f) EVENTPP_CONCAT(I_EVENTPP_IF_, b)(t, f)
|
||||
|
||||
#define EVENTPP_ADD_BACKETS(x) EVENTPP_IF(EVENTPP_IS_ENCLOSED_BY_BRACKETS(x), x, (x))
|
||||
#define EVENTPP_REMOVE_BACKETS(x) EVENTPP_BRACKETS_EXPAND(EVENTPP_IF(EVENTPP_IS_ENCLOSED_BY_BRACKETS(x), (EVENTPP_EXPAND x), (x)))
|
||||
|
||||
#define I_EVENTPP_MAKE_EVENT(className, baseClassName, baseClassArgs, ...) \
|
||||
class className : public EVENTPP_REMOVE_BACKETS(baseClassName) { \
|
||||
public: \
|
||||
className() \
|
||||
: EVENTPP_REMOVE_BACKETS(baseClassName) EVENTPP_ADD_BACKETS(baseClassArgs), \
|
||||
EVENTPP_ITERATE_ARGS(EVENTPP_EXEC_MAKE_DEFAULT_INITIALIZE, EVENTPP_COMMA, __VA_ARGS__) {} \
|
||||
className(EVENTPP_ITERATE_ARGS(EVENTPP_EXEC_MAKE_CTOR_FIELD, EVENTPP_COMMA, __VA_ARGS__)) \
|
||||
: EVENTPP_REMOVE_BACKETS(baseClassName) EVENTPP_ADD_BACKETS(baseClassArgs), \
|
||||
EVENTPP_ITERATE_ARGS(EVENTPP_EXEC_MAKE_INITIALIZE, EVENTPP_COMMA, __VA_ARGS__) {} \
|
||||
EVENTPP_ITERATE_ARGS(EVENTPP_EXEC_MAKE_GETTER, EVENTPP_EMPTY, __VA_ARGS__) \
|
||||
EVENTPP_ITERATE_ARGS(EVENTPP_EXEC_MAKE_SETTER, EVENTPP_EMPTY, __VA_ARGS__) \
|
||||
private: \
|
||||
EVENTPP_ITERATE_ARGS(EVENTPP_EXEC_MAKE_FIELD, EVENTPP_SEMICOLON, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define EVENTPP_MAKE_EVENT(className, baseClassName, baseClassArgs, ...) EVENTPP_EXPAND(I_EVENTPP_MAKE_EVENT(className, baseClassName, baseClassArgs, __VA_ARGS__))
|
||||
|
||||
#define EVENTPP_MAKE_EMPTY_EVENT(className, baseClassName, baseClassArgs) \
|
||||
class className : public EVENTPP_REMOVE_BACKETS(baseClassName) { \
|
||||
public: \
|
||||
className() \
|
||||
: EVENTPP_REMOVE_BACKETS(baseClassName) EVENTPP_ADD_BACKETS(baseClassArgs) {} \
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Perl script to generate some of the macros
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $paramCount = 15;
|
||||
|
||||
sub outputParams
|
||||
{
|
||||
my ($count) = @_;
|
||||
|
||||
for(my $i = 0; $i < $count; ++$i) {
|
||||
print ', ' if($i > 0);
|
||||
print 'p', $i;
|
||||
}
|
||||
}
|
||||
|
||||
sub doMain
|
||||
{
|
||||
print '#define I_EVENTPP_ARG_COUNT(';
|
||||
&outputParams($paramCount + 1);
|
||||
print ', ...) p', $paramCount, "\n";
|
||||
print '#define EVENTPP_ARG_COUNT(...) EVENTPP_EXPAND(I_EVENTPP_ARG_COUNT(__VA_ARGS__';
|
||||
for(my $i = $paramCount; $i >= 0; --$i) {
|
||||
print ', ', $i;
|
||||
}
|
||||
print "))\n";
|
||||
print "\n";
|
||||
|
||||
print "#define I_EVENTPP_ITERATE_ARGS_0(EXEC, DELI)\n";
|
||||
for(my $i = 1; $i <= $paramCount; ++$i) {
|
||||
print '#define I_EVENTPP_ITERATE_ARGS_', $i, '(EXEC, DELI, ';
|
||||
&outputParams($i);
|
||||
print ') I_EVENTPP_ITERATE_ARGS_', ($i - 1), '(EXEC, DELI';
|
||||
print ($i > 1 ? ', ' : ' ');
|
||||
&outputParams($i - 1);
|
||||
print ')', ($i > 1 ? ' DELI()' : ''), ' EXEC(p', ($i - 1), ')';
|
||||
print "\n";
|
||||
}
|
||||
print "#define I_EVENTPP_ITERATE_ARGS_N(EXEC, DELI, N, ...) EVENTPP_EXPAND(EVENTPP_CONCAT(I_EVENTPP_ITERATE_ARGS_, N) (EXEC, DELI, __VA_ARGS__))\n";
|
||||
print "#define EVENTPP_ITERATE_ARGS(EXEC, DELI, ...) I_EVENTPP_ITERATE_ARGS_N(EXEC, DELI, EVENTPP_ARG_COUNT(__VA_ARGS__), __VA_ARGS__)\n";
|
||||
print "\n";
|
||||
|
||||
}
|
||||
|
||||
&doMain;
|
||||
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,169 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef EVENTUTIL_H_802615012766
|
||||
#define EVENTUTIL_H_802615012766
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
template <typename DispatcherType>
|
||||
bool removeListener(
|
||||
DispatcherType & dispatcher,
|
||||
const typename DispatcherType::Event & event,
|
||||
const typename DispatcherType::Callback & listener
|
||||
)
|
||||
{
|
||||
bool found = false;
|
||||
dispatcher.forEachIf(
|
||||
event,
|
||||
[&found, &dispatcher, &event, &listener](
|
||||
const typename DispatcherType::Handle & handle,
|
||||
const typename DispatcherType::Callback & item
|
||||
) -> bool {
|
||||
if(item == listener) {
|
||||
found = true;
|
||||
dispatcher.removeListener(event, handle);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
template <typename CallbackListType>
|
||||
bool removeListener(
|
||||
CallbackListType & callbackList,
|
||||
const typename CallbackListType::Callback & callback
|
||||
)
|
||||
{
|
||||
bool found = false;
|
||||
callbackList.forEachIf(
|
||||
[&found, &callbackList, &callback](
|
||||
const typename CallbackListType::Handle & handle,
|
||||
const typename CallbackListType::Callback & item
|
||||
) -> bool {
|
||||
if(item == callback) {
|
||||
found = true;
|
||||
callbackList.remove(handle);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
template <typename DispatcherType>
|
||||
bool hasListener(
|
||||
DispatcherType & dispatcher,
|
||||
const typename DispatcherType::Event & event,
|
||||
const typename DispatcherType::Callback & listener
|
||||
)
|
||||
{
|
||||
bool found = false;
|
||||
dispatcher.forEachIf(
|
||||
event,
|
||||
[&found, &listener](
|
||||
const typename DispatcherType::Handle & /*handle*/,
|
||||
const typename DispatcherType::Callback & item
|
||||
) -> bool {
|
||||
if(item == listener) {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
template <typename DispatcherType>
|
||||
bool hasAnyListener(
|
||||
DispatcherType & dispatcher,
|
||||
const typename DispatcherType::Event & event
|
||||
)
|
||||
{
|
||||
bool found = false;
|
||||
dispatcher.forEachIf(
|
||||
event,
|
||||
[&found](
|
||||
const typename DispatcherType::Handle & /*handle*/,
|
||||
const typename DispatcherType::Callback & /*item*/
|
||||
) -> bool {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
template <typename CallbackListType>
|
||||
bool hasListener(
|
||||
CallbackListType & callbackList,
|
||||
const typename CallbackListType::Callback & callback
|
||||
)
|
||||
{
|
||||
bool found = false;
|
||||
callbackList.forEachIf(
|
||||
[&found, &callback](
|
||||
const typename CallbackListType::Handle & /*handle*/,
|
||||
const typename CallbackListType::Callback & item
|
||||
) -> bool {
|
||||
if(item == callback) {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
template <typename CallbackListType>
|
||||
bool hasAnyListener(
|
||||
CallbackListType & callbackList
|
||||
)
|
||||
{
|
||||
bool found = false;
|
||||
callbackList.forEachIf(
|
||||
[&found](
|
||||
const typename CallbackListType::Handle & /*handle*/,
|
||||
const typename CallbackListType::Callback & /*item*/
|
||||
) -> bool {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef ORDEREDQUEUELIST_H_862875671799
|
||||
#define ORDEREDQUEUELIST_H_862875671799
|
||||
|
||||
#include "../eventpolicies.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
struct OrderedQueueListCompare
|
||||
{
|
||||
template <typename T>
|
||||
bool operator() (const T & a, const T & b) const {
|
||||
return a.event < b.event;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename Compare = OrderedQueueListCompare>
|
||||
class OrderedQueueList : private std::list<T>
|
||||
{
|
||||
private:
|
||||
using super = std::list<T>;
|
||||
|
||||
public:
|
||||
using iterator = typename super::iterator;
|
||||
using const_iterator = typename super::const_iterator;
|
||||
using super::empty;
|
||||
using super::begin;
|
||||
using super::end;
|
||||
using super::front;
|
||||
using super::swap;
|
||||
using super::emplace_back;
|
||||
|
||||
void splice(const_iterator pos, OrderedQueueList & other) {
|
||||
super::splice(pos, other);
|
||||
doSort();
|
||||
}
|
||||
|
||||
void splice(const_iterator pos, OrderedQueueList & other, const_iterator it) {
|
||||
super::splice(pos, other, it);
|
||||
doSort();
|
||||
}
|
||||
|
||||
private:
|
||||
void doSort() {
|
||||
auto compare = Compare();
|
||||
this->sort([compare](const T & a, const T & b) {
|
||||
// a and b may be empty if they are recycled to free list.
|
||||
if(a.empty()) {
|
||||
if(b.empty()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(b.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return compare(a.get(), b.get());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,330 @@
|
||||
// eventpp library
|
||||
// Copyright (C) 2018 Wang Qi (wqking)
|
||||
// Github: https://github.com/wqking/eventpp
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SCOPEDREMOVER_H_695291515513
|
||||
#define SCOPEDREMOVER_H_695291515513
|
||||
|
||||
#include "../eventpolicies.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace eventpp {
|
||||
|
||||
namespace internal_ {
|
||||
|
||||
template <typename Item, typename Handle, typename Mutex>
|
||||
bool removeHandleFromScopedRemoverItemList(std::vector<Item> & itemList, Handle & handle, Mutex & mutex)
|
||||
{
|
||||
if(! handle) {
|
||||
return false;
|
||||
}
|
||||
auto handlePointer = handle.lock();
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
auto it = std::find_if(itemList.begin(), itemList.end(), [&handlePointer](Item & item) {
|
||||
return item.handle && item.handle.lock() == handlePointer;
|
||||
});
|
||||
if(it != itemList.end()) {
|
||||
itemList.erase(it);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} //namespace internal_
|
||||
|
||||
template <typename DispatcherType, typename Enabled = void>
|
||||
class ScopedRemover;
|
||||
|
||||
template <typename DispatcherType>
|
||||
class ScopedRemover <
|
||||
DispatcherType,
|
||||
typename std::enable_if<std::is_base_of<TagEventDispatcher, DispatcherType>::value>::type
|
||||
>
|
||||
{
|
||||
private:
|
||||
struct Item
|
||||
{
|
||||
typename DispatcherType::Event event;
|
||||
typename DispatcherType::Handle handle;
|
||||
};
|
||||
|
||||
public:
|
||||
ScopedRemover()
|
||||
: dispatcher(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
explicit ScopedRemover(DispatcherType & dispatcher)
|
||||
: dispatcher(&dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
ScopedRemover(ScopedRemover && other) noexcept
|
||||
: dispatcher(std::move(other.dispatcher)), itemList(std::move(other.itemList))
|
||||
{
|
||||
other.reset();
|
||||
}
|
||||
|
||||
ScopedRemover & operator = (ScopedRemover && other) noexcept
|
||||
{
|
||||
dispatcher = std::move(other.dispatcher);
|
||||
itemList = std::move(other.itemList);
|
||||
other.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
~ScopedRemover()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void swap(ScopedRemover & other) noexcept {
|
||||
using std::swap;
|
||||
|
||||
swap(dispatcher, other.dispatcher);
|
||||
swap(itemList, other.itemList);
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
if(dispatcher != nullptr) {
|
||||
for(const auto & item : itemList) {
|
||||
dispatcher->removeListener(item.event, item.handle);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_lock<typename DispatcherType::Mutex> lock(itemListMutex);
|
||||
itemList.clear();
|
||||
}
|
||||
|
||||
void setDispatcher(DispatcherType & dispatcher_)
|
||||
{
|
||||
if(this->dispatcher != &dispatcher_) {
|
||||
reset();
|
||||
this->dispatcher = &dispatcher_;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename DispatcherType::Handle appendListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener
|
||||
)
|
||||
{
|
||||
Item item {
|
||||
event,
|
||||
dispatcher->appendListener(event, listener)
|
||||
};
|
||||
|
||||
{
|
||||
std::unique_lock<typename DispatcherType::Mutex> lock(itemListMutex);
|
||||
itemList.push_back(item);
|
||||
}
|
||||
|
||||
return item.handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename DispatcherType::Handle prependListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener
|
||||
)
|
||||
{
|
||||
Item item {
|
||||
event,
|
||||
dispatcher->prependListener(event, listener)
|
||||
};
|
||||
|
||||
{
|
||||
std::unique_lock<typename DispatcherType::Mutex> lock(itemListMutex);
|
||||
itemList.push_back(item);
|
||||
}
|
||||
|
||||
return item.handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename DispatcherType::Handle insertListener(
|
||||
const typename DispatcherType::Event & event,
|
||||
const Callback & listener,
|
||||
const typename DispatcherType::Handle & before
|
||||
)
|
||||
{
|
||||
Item item {
|
||||
event,
|
||||
dispatcher->insertListener(event, listener, before)
|
||||
};
|
||||
|
||||
{
|
||||
std::unique_lock<typename DispatcherType::Mutex> lock(itemListMutex);
|
||||
itemList.push_back(item);
|
||||
}
|
||||
|
||||
return item.handle;
|
||||
}
|
||||
|
||||
bool removeListener(const typename DispatcherType::Event & event, const typename DispatcherType::Handle handle)
|
||||
{
|
||||
if(internal_::removeHandleFromScopedRemoverItemList(itemList, handle, itemListMutex)) {
|
||||
return dispatcher->removeListener(event, handle);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
DispatcherType * dispatcher;
|
||||
std::vector<Item> itemList;
|
||||
typename DispatcherType::Mutex itemListMutex;
|
||||
};
|
||||
|
||||
template <typename CallbackListType>
|
||||
class ScopedRemover <
|
||||
CallbackListType,
|
||||
typename std::enable_if<std::is_base_of<TagCallbackList, CallbackListType>::value>::type
|
||||
>
|
||||
{
|
||||
private:
|
||||
struct Item
|
||||
{
|
||||
typename CallbackListType::Handle handle;
|
||||
};
|
||||
|
||||
public:
|
||||
ScopedRemover()
|
||||
: callbackList(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
explicit ScopedRemover(CallbackListType & callbackList)
|
||||
: callbackList(&callbackList)
|
||||
{
|
||||
}
|
||||
|
||||
ScopedRemover(ScopedRemover && other) noexcept
|
||||
: callbackList(std::move(other.callbackList)), itemList(std::move(other.itemList))
|
||||
{
|
||||
other.reset();
|
||||
}
|
||||
|
||||
ScopedRemover & operator = (ScopedRemover && other) noexcept
|
||||
{
|
||||
callbackList = std::move(other.callbackList);
|
||||
itemList = std::move(other.itemList);
|
||||
other.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
~ScopedRemover()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void swap(ScopedRemover & other) noexcept {
|
||||
using std::swap;
|
||||
|
||||
swap(callbackList, other.callbackList);
|
||||
swap(itemList, other.itemList);
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
if(callbackList != nullptr) {
|
||||
for(const auto & item : itemList) {
|
||||
callbackList->remove(item.handle);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_lock<typename CallbackListType::Mutex> lock(itemListMutex);
|
||||
itemList.clear();
|
||||
}
|
||||
|
||||
void setCallbackList(CallbackListType & callbackList_)
|
||||
{
|
||||
if(this->callbackList != &callbackList_) {
|
||||
reset();
|
||||
this->callbackList = &callbackList_;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename CallbackListType::Handle append(
|
||||
const Callback & callback
|
||||
)
|
||||
{
|
||||
Item item {
|
||||
callbackList->append(callback)
|
||||
};
|
||||
|
||||
{
|
||||
std::unique_lock<typename CallbackListType::Mutex> lock(itemListMutex);
|
||||
itemList.push_back(item);
|
||||
}
|
||||
|
||||
return item.handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename CallbackListType::Handle prepend(
|
||||
const Callback & callback
|
||||
)
|
||||
{
|
||||
Item item {
|
||||
callbackList->prepend(callback)
|
||||
};
|
||||
|
||||
{
|
||||
std::unique_lock<typename CallbackListType::Mutex> lock(itemListMutex);
|
||||
itemList.push_back(item);
|
||||
}
|
||||
|
||||
return item.handle;
|
||||
}
|
||||
|
||||
template <typename Callback>
|
||||
typename CallbackListType::Handle insert(
|
||||
const Callback & callback,
|
||||
const typename CallbackListType::Handle & before
|
||||
)
|
||||
{
|
||||
Item item {
|
||||
callbackList->insert(callback, before)
|
||||
};
|
||||
|
||||
{
|
||||
std::unique_lock<typename CallbackListType::Mutex> lock(itemListMutex);
|
||||
itemList.push_back(item);
|
||||
}
|
||||
|
||||
return item.handle;
|
||||
}
|
||||
|
||||
bool remove(const typename CallbackListType::Handle handle)
|
||||
{
|
||||
if(internal_::removeHandleFromScopedRemoverItemList(itemList, handle, itemListMutex)) {
|
||||
return callbackList->remove(handle);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
CallbackListType * callbackList;
|
||||
std::vector<Item> itemList;
|
||||
typename CallbackListType::Mutex itemListMutex;
|
||||
};
|
||||
|
||||
|
||||
} //namespace eventpp
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+18162
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,16 @@
|
||||
eventpp library
|
||||
|
||||
Copyright (C) 2018 Wang Qi (wqking)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
Copyright (c) 2014, MAYAH
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Toru Niina
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,96 @@
|
||||
#include <JuiceAgent.hpp>
|
||||
#include <jni_impl.hpp>
|
||||
#include <event/event_type.hpp>
|
||||
#include <event/eventbus.hpp>
|
||||
#include <JuiceAgent/Config.hpp>
|
||||
#include <services.hpp>
|
||||
|
||||
namespace JuiceAgent {
|
||||
// ===== Singleton =====
|
||||
Agent& Agent::instance() {
|
||||
static Agent instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool Agent::init(JavaVM* jvm, JNIEnv* env, jvmtiEnv* jvmti, std::string& runtime_dir) {
|
||||
try {
|
||||
PLOGI << "JuiceAgent Native EntryPoint Invoked!";
|
||||
|
||||
// ======== neccessary environment check ========
|
||||
if (jvm == nullptr) {
|
||||
PLOGE << "Failed to initialize JuiceAgent: jvm is null";
|
||||
return false;
|
||||
}
|
||||
if (env == nullptr) {
|
||||
PLOGE << "Failed to initialize JuiceAgent: env is null";
|
||||
return false;
|
||||
}
|
||||
if (jvmti == nullptr) {
|
||||
PLOGE << "Failed to initialize JuiceAgent: jvmti is null";
|
||||
return false;
|
||||
}
|
||||
JuiceAgent::Config::Config cfg (runtime_dir);
|
||||
if (!cfg.is_valid()) {
|
||||
PLOGE << "Failed to initialize JuiceAgent: config is invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
set_jvm(jvm);
|
||||
set_jvmti(jvmti);
|
||||
set_env(env);
|
||||
set_config(cfg);
|
||||
PLOGD << "env: " << env << ", jvmti: " << jvmti;
|
||||
|
||||
// Register events for services
|
||||
JuiceAgent::services::Manager::register_events();
|
||||
|
||||
// PreLoad Event
|
||||
eventbus.post(EventPreLoad{
|
||||
.jvm = jvm,
|
||||
.env = env,
|
||||
.jvmti = jvmti
|
||||
});
|
||||
|
||||
// ======== Application ability ========
|
||||
jvmtiCapabilities caps{};
|
||||
caps.can_get_bytecodes = 1;
|
||||
caps.can_redefine_classes = 1;
|
||||
caps.can_redefine_any_class = 1;
|
||||
caps.can_retransform_classes = 1;
|
||||
caps.can_retransform_any_class = 1;
|
||||
caps.can_generate_all_class_hook_events = 1;
|
||||
jint result = jvmti->AddCapabilities(&caps);
|
||||
if (result != JNI_OK) {
|
||||
PLOGE << "Failed to add capabilities: " << result;
|
||||
return false;
|
||||
}
|
||||
|
||||
PLOGI << "Abilities added successfully";
|
||||
|
||||
// ======== Register callbacks ========
|
||||
jvmtiEventCallbacks callbacks{};
|
||||
callbacks.ClassFileLoadHook = &ClassFileLoadHook;
|
||||
result = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
if (result != JNI_OK) {
|
||||
PLOGE << "Failed to set event callbacks: " << result;
|
||||
}
|
||||
|
||||
// Enable events
|
||||
result = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
|
||||
if (result != JNI_OK) {
|
||||
PLOGE << "Failed to enable event notification: " << result;
|
||||
}
|
||||
|
||||
// Loaded Event
|
||||
eventbus.post(EventLoaded{
|
||||
.jvm = jvm,
|
||||
.env = env,
|
||||
.jvmti = jvmti
|
||||
});
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
PLOGE << "Exception: " << e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <event/event_type.hpp>
|
||||
|
||||
void JNICALL ClassFileLoadHook(
|
||||
jvmtiEnv* jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jclass class_being_redefined,
|
||||
jobject loader,
|
||||
const char* name,
|
||||
jobject protection_domain,
|
||||
jint class_data_len,
|
||||
const unsigned char* classbytes,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_classbytes) {
|
||||
if (!name) {
|
||||
PLOGW << "name is null";
|
||||
return;
|
||||
}
|
||||
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
EventClassFileLoadHook event{
|
||||
.jvmti_env = jvmti_env,
|
||||
.jni_env = jni_env,
|
||||
.class_being_redefined = class_being_redefined,
|
||||
.loader = loader,
|
||||
.name = name,
|
||||
.protection_domain = protection_domain,
|
||||
.class_data_len = class_data_len,
|
||||
.classbytes = classbytes,
|
||||
.new_class_data_len = new_class_data_len,
|
||||
.new_classbytes = new_classbytes
|
||||
};
|
||||
|
||||
agent.get_eventbus().post(event);
|
||||
|
||||
agent.get_eventbus().post_mutable(event);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <event/event_type.hpp>
|
||||
|
||||
void JNICALL MethodEntry(jvmtiEnv *jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jthread thread,
|
||||
jmethodID method) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
agent.get_eventbus().post(EventMethodEntry{
|
||||
.jvmti_env = jvmti_env,
|
||||
.jni_env = jni_env,
|
||||
.thread = thread,
|
||||
.method = method
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <event/event_type.hpp>
|
||||
|
||||
void JNICALL MethodExit(jvmtiEnv *jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jthread thread,
|
||||
jmethodID method,
|
||||
jboolean was_popped_by_exception,
|
||||
jvalue return_value) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
agent.get_eventbus().post(EventMethodExit{
|
||||
.jvmti_env = jvmti_env,
|
||||
.jni_env = jni_env,
|
||||
.thread = thread,
|
||||
.method = method,
|
||||
.was_popped_by_exception = was_popped_by_exception,
|
||||
.return_value = return_value
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <global.hpp>
|
||||
|
||||
std::unordered_set<std::string> classToCapture;
|
||||
std::unordered_map<std::string, ClassFileData> classFileDataMap;
|
||||
std::mutex classDataMutex;
|
||||
|
||||
std::unordered_map<std::string, std::vector<unsigned char>> pendingRetransform;
|
||||
std::mutex pendingRetransformMutex;
|
||||
@@ -0,0 +1,119 @@
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <jni_impl.hpp>
|
||||
#include <JuiceAgent/JuiceAgent-API-1.4.1+build.1.hpp>
|
||||
|
||||
// Global state
|
||||
static JavaVM* g_vm = nullptr;
|
||||
static jvmtiEnv* g_jvmti = nullptr;
|
||||
|
||||
// Forward declaration
|
||||
void JNICALL OnVMInit(jvmtiEnv* jvmti, JNIEnv* env, jthread thread);
|
||||
|
||||
// Utility: check JVMTI error
|
||||
static bool CheckJvmti(jvmtiError err, const char* action) {
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
PLOGE << action << " failed, code=" << err;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// VMInit callback
|
||||
void JNICALL OnVMInit(jvmtiEnv* jvmti, JNIEnv* env, jthread thread) {
|
||||
PLOGI << "JVMTI VMInit triggered";
|
||||
|
||||
std::string runtime_dir = std::filesystem::current_path().string();
|
||||
|
||||
if (runtime_dir.empty()) {
|
||||
PLOGE << "runtime_dir is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
PLOGI << "Runtime directory: " << runtime_dir;
|
||||
|
||||
// Inject JuiceAgent-API
|
||||
// Save bytes to file
|
||||
std::string hash =
|
||||
JuiceAgent::Resource::juiceagent_api_bytes_sha256;
|
||||
|
||||
std::string file_name =
|
||||
hash.substr(0, 8) + "_" +
|
||||
JuiceAgent::Resource::juiceagent_api_bytes_name;
|
||||
|
||||
std::string juiceagent_api_path =
|
||||
JuiceAgent::Utils::File::write_to_tempfile(
|
||||
JuiceAgent::Resource::juiceagent_api_bytes,
|
||||
JuiceAgent::Resource::juiceagent_api_bytes_len,
|
||||
file_name
|
||||
);
|
||||
|
||||
PLOGD << "Saved JuiceAgent-API to: " << juiceagent_api_path;
|
||||
PLOGD << "JuiceAgent-API size: " << JuiceAgent::Resource::juiceagent_api_bytes_len;
|
||||
PLOGD << "JuiceAgent-API SHA256: " << JuiceAgent::Resource::juiceagent_api_bytes_sha256;
|
||||
|
||||
// Inject JuiceAgent jar into system class loader
|
||||
jint status = jvmti->AddToSystemClassLoaderSearch(juiceagent_api_path.c_str());
|
||||
if (status != JNI_OK) {
|
||||
PLOGE << "AddToSystemClassLoaderSearch failed: " << status;
|
||||
return;
|
||||
}
|
||||
|
||||
PLOGI << "Jar injected successfully: " << juiceagent_api_path;
|
||||
|
||||
JuiceAgent::Agent& agent = JuiceAgent::Agent::instance();
|
||||
agent.init(g_vm, env, g_jvmti, runtime_dir);
|
||||
|
||||
PLOGI << "JuiceAgent initialized successfully";
|
||||
}
|
||||
|
||||
// Agent entry
|
||||
JNIEXPORT jint JNICALL
|
||||
Agent_OnLoad(JavaVM* vm, char* options, void* reserved) {
|
||||
InitLogger();
|
||||
|
||||
PLOGI << "Agent_OnLoad";
|
||||
|
||||
g_vm = vm;
|
||||
|
||||
// Get JVMTI first
|
||||
jint result = vm->GetEnv(reinterpret_cast<void**>(&g_jvmti), JVMTI_VERSION_1_2);
|
||||
if (result != JNI_OK || g_jvmti == nullptr) {
|
||||
PLOGE << "Failed to get JVMTI, code=" << result;
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
// Optional capabilities
|
||||
jvmtiCapabilities caps{};
|
||||
CheckJvmti(g_jvmti->AddCapabilities(&caps), "AddCapabilities");
|
||||
|
||||
// Register callbacks
|
||||
jvmtiEventCallbacks callbacks{};
|
||||
callbacks.VMInit = &OnVMInit;
|
||||
|
||||
if (!CheckJvmti(
|
||||
g_jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks)),
|
||||
"SetEventCallbacks")) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
if (!CheckJvmti(
|
||||
g_jvmti->SetEventNotificationMode(
|
||||
JVMTI_ENABLE,
|
||||
JVMTI_EVENT_VM_INIT,
|
||||
nullptr),
|
||||
"Enable VM_INIT")) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
PLOGI << "Agent loaded, waiting for VMInit...";
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
// Optional unload
|
||||
JNIEXPORT void JNICALL
|
||||
Agent_OnUnload(JavaVM* vm) {
|
||||
PLOGI << "Agent_OnUnload";
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <JuiceAgent.hpp>
|
||||
|
||||
// This function is called by Java to initialize the agent.
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_init
|
||||
(JNIEnv *env, jclass , jstring j_runtime_dir) {
|
||||
InitLogger();
|
||||
|
||||
PLOGI << "Initializing JuiceAgent...";
|
||||
|
||||
// Get runtime directory
|
||||
const char* c_runtime_dir = env->GetStringUTFChars(j_runtime_dir, nullptr);
|
||||
std::string runtime_dir(c_runtime_dir);
|
||||
env->ReleaseStringUTFChars(j_runtime_dir, c_runtime_dir);
|
||||
|
||||
if (runtime_dir.empty()) {
|
||||
PLOGE << "Failed to get runtime directory from argument, runtime_dir is empty";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
PLOGI << "JuiceAgent got runtime directory: " << runtime_dir;
|
||||
|
||||
JavaVM* jvm = nullptr;
|
||||
jvmtiEnv* jvmti = nullptr;
|
||||
|
||||
// Get Java VM
|
||||
env->GetJavaVM(&jvm);
|
||||
if (jvm == nullptr) {
|
||||
PLOGE << "Failed to get JavaVM instance";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Get JVMTI
|
||||
jvmtiError err = static_cast<jvmtiError>(jvm->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_2));
|
||||
if (err != JVMTI_ERROR_NONE || jvmti == nullptr) {
|
||||
PLOGE << "Failed to get JVMTI environment, error: " << err;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Invoke EntryPoint
|
||||
JuiceAgent::Agent& agent = JuiceAgent::Agent::instance();
|
||||
agent.init(jvm, env, jvmti, runtime_dir);
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <event/eventbus.hpp>
|
||||
#include <JuiceAgent/Config.hpp>
|
||||
|
||||
namespace JuiceAgent {
|
||||
class Agent {
|
||||
private:
|
||||
JavaVM* jvm;
|
||||
jvmtiEnv* jvmti;
|
||||
JNIEnv* env;
|
||||
EventBus eventbus;
|
||||
JuiceAgent::Config::Config config;
|
||||
|
||||
private:
|
||||
Agent() = default;
|
||||
~Agent() = default;
|
||||
|
||||
public:
|
||||
// ===== Singleton =====
|
||||
static Agent& instance();
|
||||
|
||||
Agent(const Agent&) = delete;
|
||||
Agent& operator=(const Agent&) = delete;
|
||||
|
||||
// EntryPoint
|
||||
bool init(JavaVM* jvm, JNIEnv* env, jvmtiEnv* jvmti, std::string& runtime_dir);
|
||||
|
||||
// getters
|
||||
JavaVM* get_jvm() const { return jvm; }
|
||||
jvmtiEnv* get_jvmti() const { return jvmti; }
|
||||
JNIEnv* get_env() const { return env; }
|
||||
EventBus& get_eventbus() { return eventbus; }
|
||||
JuiceAgent::Config::Config& get_config() { return config; }
|
||||
|
||||
// setters
|
||||
void set_jvm(JavaVM* jvm) { this->jvm = jvm; }
|
||||
void set_jvmti(jvmtiEnv* jvmti) { this->jvmti = jvmti; }
|
||||
void set_env(JNIEnv* env) { this->env = env; }
|
||||
void set_config(JuiceAgent::Config::Config& config) { this->config = config; }
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class cn_xiaozhou233_juiceagent_api_JuiceAgent */
|
||||
|
||||
#ifndef _Included_cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
#define _Included_cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: init
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_init
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: addToBootstrapClassLoaderSearch
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addToBootstrapClassLoaderSearch
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: addToSystemClassLoaderSearch
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addToSystemClassLoaderSearch
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: addToClassLoader
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addToClassLoader
|
||||
(JNIEnv *, jclass, jstring, jobject);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: defineClass
|
||||
* Signature: (Ljava/lang/ClassLoader;[B)Ljava/lang/Class;
|
||||
*/
|
||||
JNIEXPORT jclass JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_defineClass
|
||||
(JNIEnv *, jclass, jobject, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: redefineClass
|
||||
* Signature: (Ljava/lang/Class;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_redefineClass
|
||||
(JNIEnv *, jclass, jclass, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: redefineClassByName
|
||||
* Signature: (Ljava/lang/String;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_redefineClassByName
|
||||
(JNIEnv *, jclass, jstring, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: retransformClass
|
||||
* Signature: (Ljava/lang/Class;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_retransformClass
|
||||
(JNIEnv *, jclass, jclass, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: retransformClassByName
|
||||
* Signature: (Ljava/lang/String;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_retransformClassByName
|
||||
(JNIEnv *, jclass, jstring, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: getLoadedClasses
|
||||
* Signature: ()[Ljava/lang/Class;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getLoadedClasses
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: getClassByName
|
||||
* Signature: (Ljava/lang/String;)Ljava/lang/Class;
|
||||
*/
|
||||
JNIEXPORT jclass JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassByName
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: getClassBytes
|
||||
* Signature: (Ljava/lang/Class;)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassBytes
|
||||
(JNIEnv *, jclass, jclass);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: getClassBytesByName
|
||||
* Signature: (Ljava/lang/String;)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassBytesByName
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: addRemapperWhiteList
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addRemapperWhiteList
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: removeRemapperWhiteList
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_removeRemapperWhiteList
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceagent_api_JuiceAgent
|
||||
* Method: clearRemapperWhiteList
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_clearRemapperWhiteList
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni_impl.hpp>
|
||||
|
||||
// ClassFileLoadHook
|
||||
struct EventClassFileLoadHook {
|
||||
jvmtiEnv* jvmti_env;
|
||||
JNIEnv* jni_env;
|
||||
jclass class_being_redefined;
|
||||
jobject loader;
|
||||
const char* name;
|
||||
jobject protection_domain;
|
||||
jint class_data_len;
|
||||
const unsigned char* classbytes;
|
||||
jint* new_class_data_len;
|
||||
unsigned char** new_classbytes;
|
||||
};
|
||||
|
||||
// MethodEntry
|
||||
struct EventMethodEntry {
|
||||
jvmtiEnv* jvmti_env;
|
||||
JNIEnv* jni_env;
|
||||
jthread thread;
|
||||
jmethodID method;
|
||||
};
|
||||
|
||||
// MethodExit
|
||||
struct EventMethodExit {
|
||||
jvmtiEnv* jvmti_env;
|
||||
JNIEnv* jni_env;
|
||||
jthread thread;
|
||||
jmethodID method;
|
||||
jboolean was_popped_by_exception;
|
||||
jvalue return_value;
|
||||
};
|
||||
|
||||
// JuiceAgent PreLoad/PostLoad
|
||||
struct EventPreLoad {
|
||||
JavaVM* jvm;
|
||||
JNIEnv* env;
|
||||
jvmtiEnv* jvmti;
|
||||
};
|
||||
|
||||
struct EventLoaded {
|
||||
JavaVM* jvm;
|
||||
JNIEnv* env;
|
||||
jvmtiEnv* jvmti;
|
||||
};
|
||||
@@ -0,0 +1,218 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <typeindex>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
class EventBus {
|
||||
public:
|
||||
using Token = std::uint64_t;
|
||||
|
||||
// === Readonly ===
|
||||
template<typename Event>
|
||||
using Listener = std::function<void(const Event&)>;
|
||||
|
||||
// === Mutable ===
|
||||
template<typename Event>
|
||||
using MutableListener = std::function<void(Event&)>;
|
||||
|
||||
// =========================
|
||||
// Subscribe (Readonly)
|
||||
// =========================
|
||||
template<typename Event>
|
||||
Token subscribe(Listener<Event> listener, int priority = 0) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto& vec = getListeners<Event>();
|
||||
|
||||
Token token = nextToken_++;
|
||||
|
||||
vec.push_back({
|
||||
token,
|
||||
priority,
|
||||
std::move(listener)
|
||||
});
|
||||
|
||||
sort(vec);
|
||||
return token;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Subscribe (Mutable)
|
||||
// =========================
|
||||
template<typename Event>
|
||||
Token subscribe_mutable(MutableListener<Event> listener, int priority = 0) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto& vec = getMutableListeners<Event>();
|
||||
|
||||
Token token = nextToken_++;
|
||||
|
||||
vec.push_back({
|
||||
token,
|
||||
priority,
|
||||
std::move(listener)
|
||||
});
|
||||
|
||||
sort(vec);
|
||||
return token;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Unsubscribe
|
||||
// =========================
|
||||
template<typename Event>
|
||||
bool unsubscribe(Token token) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
bool removed = false;
|
||||
|
||||
// readonly
|
||||
if (auto it = listeners_.find(std::type_index(typeid(Event))); it != listeners_.end()) {
|
||||
auto& vec = *std::static_pointer_cast<std::vector<Node<Event>>>(it->second);
|
||||
removed |= erase(vec, token);
|
||||
}
|
||||
|
||||
// mutable
|
||||
if (auto it = mutable_listeners_.find(std::type_index(typeid(Event))); it != mutable_listeners_.end()) {
|
||||
auto& vec = *std::static_pointer_cast<std::vector<MutableNode<Event>>>(it->second);
|
||||
removed |= erase(vec, token);
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Post (Readonly)
|
||||
// =========================
|
||||
template<typename Event>
|
||||
void post(const Event& event) {
|
||||
std::vector<Node<Event>> copy;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto it = listeners_.find(std::type_index(typeid(Event)));
|
||||
if (it == listeners_.end()) return;
|
||||
|
||||
copy = *std::static_pointer_cast<std::vector<Node<Event>>>(it->second);
|
||||
}
|
||||
|
||||
for (auto& node : copy) {
|
||||
node.callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Post (Mutable)
|
||||
// =========================
|
||||
template<typename Event>
|
||||
void post_mutable(Event& event) {
|
||||
std::vector<MutableNode<Event>> copy;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto it = mutable_listeners_.find(std::type_index(typeid(Event)));
|
||||
if (it == mutable_listeners_.end()) return;
|
||||
|
||||
copy = *std::static_pointer_cast<std::vector<MutableNode<Event>>>(it->second);
|
||||
}
|
||||
|
||||
for (auto& node : copy) {
|
||||
node.callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Clear
|
||||
// =========================
|
||||
template<typename Event>
|
||||
void clear() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
listeners_.erase(std::type_index(typeid(Event)));
|
||||
mutable_listeners_.erase(std::type_index(typeid(Event)));
|
||||
}
|
||||
|
||||
void clearAll() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
listeners_.clear();
|
||||
mutable_listeners_.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename Event>
|
||||
struct Node {
|
||||
Token token;
|
||||
int priority;
|
||||
Listener<Event> callback;
|
||||
};
|
||||
|
||||
template<typename Event>
|
||||
struct MutableNode {
|
||||
Token token;
|
||||
int priority;
|
||||
MutableListener<Event> callback;
|
||||
};
|
||||
|
||||
std::mutex mutex_;
|
||||
std::atomic<Token> nextToken_{1};
|
||||
|
||||
std::unordered_map<std::type_index, std::shared_ptr<void>> listeners_;
|
||||
std::unordered_map<std::type_index, std::shared_ptr<void>> mutable_listeners_;
|
||||
|
||||
// === helpers ===
|
||||
|
||||
template<typename T>
|
||||
static void sort(std::vector<T>& vec) {
|
||||
std::sort(vec.begin(), vec.end(),
|
||||
[](const auto& a, const auto& b) {
|
||||
return a.priority > b.priority;
|
||||
});
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static bool erase(std::vector<T>& vec, Token token) {
|
||||
auto oldSize = vec.size();
|
||||
|
||||
vec.erase(
|
||||
std::remove_if(vec.begin(), vec.end(),
|
||||
[token](const T& node) {
|
||||
return node.token == token;
|
||||
}),
|
||||
vec.end()
|
||||
);
|
||||
|
||||
return vec.size() != oldSize;
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
std::vector<Node<Event>>& getListeners() {
|
||||
return getContainer<Event, Node<Event>>(listeners_);
|
||||
}
|
||||
|
||||
template<typename Event>
|
||||
std::vector<MutableNode<Event>>& getMutableListeners() {
|
||||
return getContainer<Event, MutableNode<Event>>(mutable_listeners_);
|
||||
}
|
||||
|
||||
template<typename Event, typename NodeType>
|
||||
std::vector<NodeType>& getContainer(std::unordered_map<std::type_index, std::shared_ptr<void>>& map) {
|
||||
auto type = std::type_index(typeid(Event));
|
||||
auto it = map.find(type);
|
||||
|
||||
if (it == map.end()) {
|
||||
auto ptr = std::make_shared<std::vector<NodeType>>();
|
||||
map[type] = ptr;
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
return *std::static_pointer_cast<std::vector<NodeType>>(it->second);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <mutex>
|
||||
|
||||
// Data Structures
|
||||
struct ClassRetransformRequest {
|
||||
std::string classname;
|
||||
std::vector<unsigned char> bytecode;
|
||||
};
|
||||
struct ClassFileData {
|
||||
std::string classname;
|
||||
std::vector<unsigned char> bytecode;
|
||||
|
||||
// ======== Global references to prevent GC ========
|
||||
// Remember to release these references when they are no longer needed, otherwise it will cause memory leaks
|
||||
jclass clazz;
|
||||
jobject classloader;
|
||||
jobject protection_domain;
|
||||
|
||||
};
|
||||
|
||||
// Set of target class internal names to capture (e.g. java/lang/String)
|
||||
extern std::unordered_set<std::string> classToCapture;
|
||||
|
||||
// Cache of captured class bytecode, keyed by internal class name
|
||||
extern std::unordered_map<std::string, ClassFileData> classFileDataMap;
|
||||
|
||||
// Mutex protecting access to classToCapture and classFileDataMap (thread-safe for JVMTI callbacks)
|
||||
extern std::mutex classDataMutex;
|
||||
|
||||
extern std::unordered_map<std::string, std::vector<unsigned char>> pendingRetransform;
|
||||
extern std::mutex pendingRetransformMutex;
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <JuiceAgent.hpp>
|
||||
#include <utils.hpp>
|
||||
#include <global.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
// Generated by JuiceAgent-API
|
||||
#include <cn_xiaozhou233_juiceagent_api_JuiceAgent.h>
|
||||
|
||||
// Event callbacks
|
||||
// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#ClassFileLoadHook
|
||||
void JNICALL ClassFileLoadHook(
|
||||
jvmtiEnv* jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jclass class_being_redefined,
|
||||
jobject loader,
|
||||
const char* name,
|
||||
jobject protection_domain,
|
||||
jint class_data_len,
|
||||
const unsigned char* classbytes,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_classbytes);
|
||||
|
||||
// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#MethodEntry
|
||||
void JNICALL MethodEntry(jvmtiEnv *jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jthread thread,
|
||||
jmethodID method);
|
||||
|
||||
// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#MethodExit
|
||||
void JNICALL MethodExit(jvmtiEnv *jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jthread thread,
|
||||
jmethodID method,
|
||||
jboolean was_popped_by_exception,
|
||||
jvalue return_value);
|
||||
@@ -1,10 +0,0 @@
|
||||
#ifndef LIBAGENT_H
|
||||
#define LIBAGENT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern "C" __declspec(dllexport)
|
||||
bool InitJuiceAgent(const char* runtime_path);
|
||||
|
||||
|
||||
#endif // LIBAGENT_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <JuiceAgent.hpp>
|
||||
#include <event/event_type.hpp>
|
||||
|
||||
namespace JuiceAgent::services
|
||||
{
|
||||
static JuiceAgent::Agent& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
namespace Manager {
|
||||
void register_events();
|
||||
void init(const EventPreLoad&);
|
||||
void start(const EventLoaded&);
|
||||
void stop();
|
||||
}
|
||||
|
||||
namespace JarLoader
|
||||
{
|
||||
struct JarLoaderConfig {
|
||||
bool enabled = false;
|
||||
std::string injection_dir;
|
||||
std::string jar_path;
|
||||
std::string entry_class;
|
||||
std::string entry_method;
|
||||
};
|
||||
|
||||
void init();
|
||||
void start();
|
||||
} // namespace JarLoader
|
||||
|
||||
namespace Bytecode
|
||||
{
|
||||
void init();
|
||||
void start();
|
||||
}
|
||||
} // namespace JuiceAgent::services
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <JuiceAgent.hpp>
|
||||
|
||||
inline bool check_env(JuiceAgent::Agent& agent) {
|
||||
if (agent.get_jvm() == nullptr) {
|
||||
PLOGE << "Failed to get JavaVM instance";
|
||||
return false;
|
||||
}
|
||||
if (agent.get_jvmti() == nullptr) {
|
||||
PLOGE << "Failed to get JVMTI environment";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::string get_class_name(JNIEnv* env, jclass clazz) {
|
||||
if (!env || !clazz) return "";
|
||||
|
||||
jclass clsClass = env->FindClass("java/lang/Class");
|
||||
if (!clsClass) return "";
|
||||
|
||||
jmethodID mid = env->GetMethodID(clsClass, "getName", "()Ljava/lang/String;");
|
||||
if (!mid) {
|
||||
env->DeleteLocalRef(clsClass);
|
||||
return "";
|
||||
}
|
||||
|
||||
jstring nameStr = static_cast<jstring>(env->CallObjectMethod(clazz, mid));
|
||||
std::string result;
|
||||
|
||||
if (nameStr) {
|
||||
const char* tmp = env->GetStringUTFChars(nameStr, nullptr);
|
||||
if (tmp) {
|
||||
result = tmp; // copy to std::string
|
||||
env->ReleaseStringUTFChars(nameStr, tmp);
|
||||
}
|
||||
env->DeleteLocalRef(nameStr);
|
||||
}
|
||||
|
||||
env->DeleteLocalRef(clsClass);
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
// ============================
|
||||
// Get class bytecode (already captured)
|
||||
// ============================
|
||||
JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassBytes
|
||||
(JNIEnv *env, jclass, jclass clazz) {
|
||||
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
if (!check_env(agent)) return nullptr;
|
||||
|
||||
char* signature = nullptr;
|
||||
if (agent.get_jvmti()->GetClassSignature(clazz, &signature, nullptr) != JVMTI_ERROR_NONE || !signature)
|
||||
return nullptr;
|
||||
|
||||
// Convert Lxxx; -> xxx
|
||||
std::string internalName(signature + 1, strlen(signature) - 2);
|
||||
agent.get_jvmti()->Deallocate(reinterpret_cast<unsigned char*>(signature));
|
||||
|
||||
// ============================
|
||||
// 1. Mark class for capture
|
||||
// ============================
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(classDataMutex);
|
||||
classToCapture.insert(internalName);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 2. Trigger class retransform
|
||||
// ============================
|
||||
jvmtiError err = agent.get_jvmti()->RetransformClasses(1, &clazz);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
PLOGE << "Retransform class failed: " << err;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 3. Retrieve bytecode from cache
|
||||
// ============================
|
||||
ClassFileData data;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(classDataMutex);
|
||||
auto it = classFileDataMap.find(internalName);
|
||||
if (it != classFileDataMap.end()) {
|
||||
data = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.bytecode.empty()) {
|
||||
PLOGE << "Failed to capture bytecode for class: " << internalName;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jbyteArray out = env->NewByteArray(static_cast<jsize>(data.bytecode.size()));
|
||||
if (!out || env->ExceptionCheck()) {
|
||||
env->ExceptionClear();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
env->SetByteArrayRegion(out, 0, static_cast<jsize>(data.bytecode.size()), reinterpret_cast<const jbyte*>(data.bytecode.data()));
|
||||
return out;
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Get class bytecode by class name
|
||||
// ============================
|
||||
JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassBytesByName
|
||||
(JNIEnv *env, jclass loader_class, jstring name) {
|
||||
|
||||
if (!name) return nullptr;
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
if (!check_env(agent)) return nullptr;
|
||||
|
||||
// ============================
|
||||
// 1. Convert jstring -> internal name
|
||||
// ============================
|
||||
const char* utf = env->GetStringUTFChars(name, nullptr);
|
||||
if (!utf) return nullptr;
|
||||
std::string internalName(utf);
|
||||
env->ReleaseStringUTFChars(name, utf);
|
||||
|
||||
// Convert dots to slashes: a.b.C -> a/b/C
|
||||
std::replace(internalName.begin(), internalName.end(), '.', '/');
|
||||
|
||||
// ============================
|
||||
// 2. Iterate loaded classes
|
||||
// ============================
|
||||
jint count = 0;
|
||||
jclass* classes = nullptr;
|
||||
jvmtiEnv* jvmti = agent.get_jvmti();
|
||||
|
||||
if (jvmti->GetLoadedClasses(&count, &classes) != JVMTI_ERROR_NONE || count == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jclass targetClass = nullptr;
|
||||
for (jint i = 0; i < count; i++) {
|
||||
char* signature = nullptr;
|
||||
if (jvmti->GetClassSignature(classes[i], &signature, nullptr) == JVMTI_ERROR_NONE && signature) {
|
||||
size_t len = strlen(signature);
|
||||
if (len > 2 && signature[0] == 'L' && signature[len - 1] == ';') {
|
||||
if (internalName == std::string_view(signature + 1, len - 2)) {
|
||||
targetClass = classes[i];
|
||||
jvmti->Deallocate(reinterpret_cast<unsigned char*>(signature));
|
||||
break;
|
||||
}
|
||||
}
|
||||
jvmti->Deallocate(reinterpret_cast<unsigned char*>(signature));
|
||||
}
|
||||
}
|
||||
|
||||
if (classes) {
|
||||
jvmti->Deallocate(reinterpret_cast<unsigned char*>(classes));
|
||||
}
|
||||
|
||||
if (!targetClass) {
|
||||
PLOGE << "Class not loaded: " << internalName;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 3. Reuse getClassBytes logic
|
||||
// ============================
|
||||
return Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassBytes(env, loader_class, targetClass);
|
||||
}
|
||||
|
||||
// ============================
|
||||
// Redefine class using jclass
|
||||
// ============================
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_redefineClass
|
||||
(JNIEnv *env, jclass loader_class, jclass clazz, jbyteArray class_bytes, jint class_bytes_len) {
|
||||
|
||||
// Get singleton agent instance
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
if (!check_env(agent))
|
||||
return JNI_FALSE;
|
||||
|
||||
// Get byte array elements
|
||||
jbyte* buf = env->GetByteArrayElements(class_bytes, nullptr);
|
||||
if (!buf) {
|
||||
PLOGE << "Cannot get class bytes";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Prepare JVMTI class definition
|
||||
jvmtiClassDefinition defs[1];
|
||||
defs[0].klass = clazz;
|
||||
defs[0].class_byte_count = class_bytes_len;
|
||||
defs[0].class_bytes = reinterpret_cast<const unsigned char*>(buf);
|
||||
|
||||
// Redefine class via JVMTI
|
||||
jvmtiError result = agent.get_jvmti()->RedefineClasses(1, defs);
|
||||
|
||||
// Release byte array (no need to copy back)
|
||||
env->ReleaseByteArrayElements(class_bytes, buf, JNI_ABORT);
|
||||
|
||||
if (result != JVMTI_ERROR_NONE) {
|
||||
PLOGE << "Redefine class failed: " << result;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
PLOGD << "Class redefined successfully!";
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Redefine class using its fully qualified name
|
||||
// Supports automatic '.' -> '/' conversion
|
||||
// ============================================
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_redefineClassByName
|
||||
(JNIEnv *env, jclass loader_class, jstring class_name, jbyteArray class_bytes, jint class_bytes_len) {
|
||||
|
||||
// Convert jstring to C string
|
||||
const char* cname = env->GetStringUTFChars(class_name, nullptr);
|
||||
if (!cname) {
|
||||
PLOGE << "Class name is NULL!";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Copy and replace '.' with '/' for JVM internal class name
|
||||
std::string internal_name(cname);
|
||||
std::replace(internal_name.begin(), internal_name.end(), '.', '/');
|
||||
|
||||
// Release the original Java string
|
||||
env->ReleaseStringUTFChars(class_name, cname);
|
||||
|
||||
// Find class by internal name
|
||||
jclass clazz = env->FindClass(internal_name.c_str());
|
||||
if (!clazz) {
|
||||
PLOGE << "Cannot find class: " << internal_name;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Call redefineClass with the found class
|
||||
return Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_redefineClass(
|
||||
env, loader_class, clazz, class_bytes, class_bytes_len
|
||||
);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_retransformClass
|
||||
(JNIEnv* env, jclass, jclass clazz, jbyteArray bytecodes, jint length) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
// =========================
|
||||
// 1. Check environment & parameters
|
||||
// =========================
|
||||
if (!check_env(agent) || !clazz || !bytecodes) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 2. Get class internal name
|
||||
// =========================
|
||||
std::string nameDot = get_class_name(env, clazz);
|
||||
if (nameDot.empty()) {
|
||||
PLOGE << "Failed to get class name for retransform";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Convert '.' to '/' for internal name
|
||||
for (auto& c : nameDot) if (c == '.') c = '/';
|
||||
|
||||
// =========================
|
||||
// 3. Extract bytecode from jbyteArray
|
||||
// =========================
|
||||
jbyte* bytes = env->GetByteArrayElements(bytecodes, nullptr);
|
||||
jint len = env->GetArrayLength(bytecodes);
|
||||
if (!bytes || len <= 0) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 4. Cache bytecode & class info for ClassFileLoadHook
|
||||
// =========================
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(classDataMutex);
|
||||
|
||||
ClassFileData data;
|
||||
data.classname = nameDot;
|
||||
data.bytecode.assign(bytes, bytes + len);
|
||||
data.clazz = static_cast<jclass>(env->NewGlobalRef(clazz)); // prevent GC
|
||||
data.classloader = nullptr; // optional
|
||||
data.protection_domain = nullptr;
|
||||
|
||||
classFileDataMap[nameDot] = std::move(data);
|
||||
}
|
||||
|
||||
env->ReleaseByteArrayElements(bytecodes, bytes, JNI_ABORT);
|
||||
|
||||
// =========================
|
||||
// 5. Trigger JVMTI retransform
|
||||
// =========================
|
||||
jclass classes[1] = { clazz };
|
||||
jvmtiError err = agent.get_jvmti()->RetransformClasses(1, classes);
|
||||
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
PLOGE << "[retransformClass] failed: " << err << " for " << nameDot;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
PLOGI << "[retransformClass] OK: " << nameDot << " (" << len << " bytes)";
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_retransformClassByName
|
||||
(JNIEnv* env, jclass, jstring className, jbyteArray bytecodes, jint length) {
|
||||
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
if (!check_env(agent) || !className || !bytecodes) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 1. Get UTF string from jstring
|
||||
// =========================
|
||||
const char* utf = env->GetStringUTFChars(className, nullptr);
|
||||
if (!utf) return JNI_FALSE;
|
||||
|
||||
std::string internalName(utf);
|
||||
env->ReleaseStringUTFChars(className, utf);
|
||||
|
||||
// Convert '.' to '/' for internal name
|
||||
for (auto& c : internalName) if (c == '.') c = '/';
|
||||
|
||||
// =========================
|
||||
// 2. Find loaded class by internal name (inline)
|
||||
// =========================
|
||||
jclass target = nullptr;
|
||||
{
|
||||
jint classCount = 0;
|
||||
jclass* loadedClasses = nullptr;
|
||||
|
||||
if (agent.get_jvmti()->GetLoadedClasses(&classCount, &loadedClasses) == JVMTI_ERROR_NONE && classCount > 0) {
|
||||
for (jint i = 0; i < classCount; ++i) {
|
||||
char* sig = nullptr;
|
||||
if (agent.get_jvmti()->GetClassSignature(loadedClasses[i], &sig, nullptr) == JVMTI_ERROR_NONE && sig) {
|
||||
// sig: "Lnet/minecraft/client/Minecraft;"
|
||||
if (sig[0] == 'L') {
|
||||
size_t len = strlen(sig);
|
||||
if (len > 2 && internalName == std::string(sig + 1, len - 2)) {
|
||||
target = loadedClasses[i];
|
||||
agent.get_jvmti()->Deallocate(reinterpret_cast<unsigned char*>(sig));
|
||||
break;
|
||||
}
|
||||
}
|
||||
agent.get_jvmti()->Deallocate(reinterpret_cast<unsigned char*>(sig));
|
||||
}
|
||||
}
|
||||
agent.get_jvmti()->Deallocate(reinterpret_cast<unsigned char*>(loadedClasses));
|
||||
}
|
||||
}
|
||||
|
||||
if (!target) {
|
||||
PLOGE << "[retransformClassByName] class not loaded: " << internalName;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// 3. Delegate to retransformClass
|
||||
// =========================
|
||||
return Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_retransformClass(
|
||||
env, nullptr, target, bytecodes, length
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
#include <jni_impl.hpp>
|
||||
|
||||
// Add jar to bootstrap classloader search path
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addToBootstrapClassLoaderSearch
|
||||
(JNIEnv *env, jclass, jstring jar_path) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
if (!check_env(agent))
|
||||
return JNI_FALSE;
|
||||
|
||||
const char* j_jar_path = env->GetStringUTFChars(jar_path, nullptr);
|
||||
if (!j_jar_path) {
|
||||
PLOGE << "Path is NULL!";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jvmtiError result = agent.get_jvmti()->AddToBootstrapClassLoaderSearch(j_jar_path);
|
||||
if (result != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("Cannot AddToBootstrapClassLoaderSearch [result=%d]", result);
|
||||
env->ReleaseStringUTFChars(jar_path, j_jar_path);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
PLOGI << "AddToBootstrapClassLoaderSearch: " << j_jar_path;
|
||||
|
||||
env->ReleaseStringUTFChars(jar_path, j_jar_path);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
// Add jar to system classloader search path
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addToSystemClassLoaderSearch
|
||||
(JNIEnv *env, jclass, jstring jar_path) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
if (!check_env(agent))
|
||||
return JNI_FALSE;
|
||||
|
||||
const char* j_jar_path = env->GetStringUTFChars(jar_path, nullptr);
|
||||
if (!j_jar_path) {
|
||||
PLOGE << "Path is NULL!";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jvmtiError result = agent.get_jvmti()->AddToSystemClassLoaderSearch(j_jar_path);
|
||||
if (result != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("Cannot AddToSystemClassLoaderSearch [result=%d]", result);
|
||||
env->ReleaseStringUTFChars(jar_path, j_jar_path);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
PLOGI << "AddToSystemClassLoaderSearch: " << j_jar_path;
|
||||
|
||||
env->ReleaseStringUTFChars(jar_path, j_jar_path);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_addToClassLoader
|
||||
(JNIEnv *env, jclass, jstring jar_path, jobject target_classloader) {
|
||||
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
if (!check_env(agent))
|
||||
return JNI_FALSE;
|
||||
|
||||
if (!jar_path || !target_classloader)
|
||||
return JNI_FALSE;
|
||||
|
||||
// --- Try URLClassLoader path ---
|
||||
jclass urlClassLoader = env->FindClass("java/net/URLClassLoader");
|
||||
if (env->ExceptionCheck() || !urlClassLoader) {
|
||||
env->ExceptionClear();
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
if (env->IsInstanceOf(target_classloader, urlClassLoader)) {
|
||||
|
||||
jclass fileClass = env->FindClass("java/io/File");
|
||||
if (env->ExceptionCheck() || !fileClass) {
|
||||
env->ExceptionClear();
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jmethodID fileInit = env->GetMethodID(fileClass, "<init>", "(Ljava/lang/String;)V");
|
||||
if (env->ExceptionCheck() || !fileInit) {
|
||||
env->ExceptionClear();
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jobject file = env->NewObject(fileClass, fileInit, jar_path);
|
||||
if (env->ExceptionCheck() || !file) {
|
||||
env->ExceptionClear();
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jmethodID toURI = env->GetMethodID(fileClass, "toURI", "()Ljava/net/URI;");
|
||||
if (env->ExceptionCheck() || !toURI) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(file);
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jobject uri = env->CallObjectMethod(file, toURI);
|
||||
if (env->ExceptionCheck() || !uri) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(file);
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jclass uriClass = env->FindClass("java/net/URI");
|
||||
if (env->ExceptionCheck() || !uriClass) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(file);
|
||||
env->DeleteLocalRef(uri);
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jmethodID toURL = env->GetMethodID(uriClass, "toURL", "()Ljava/net/URL;");
|
||||
if (env->ExceptionCheck() || !toURL) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(file);
|
||||
env->DeleteLocalRef(uri);
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jobject url = env->CallObjectMethod(uri, toURL);
|
||||
if (env->ExceptionCheck() || !url) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(file);
|
||||
env->DeleteLocalRef(uri);
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
jmethodID addURL = env->GetMethodID(urlClassLoader, "addURL", "(Ljava/net/URL;)V");
|
||||
if (env->ExceptionCheck() || !addURL) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(file);
|
||||
env->DeleteLocalRef(uri);
|
||||
env->DeleteLocalRef(url);
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
env->CallVoidMethod(target_classloader, addURL, url);
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionClear();
|
||||
env->DeleteLocalRef(file);
|
||||
env->DeleteLocalRef(uri);
|
||||
env->DeleteLocalRef(url);
|
||||
goto FALLBACK;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
env->DeleteLocalRef(file);
|
||||
env->DeleteLocalRef(uri);
|
||||
env->DeleteLocalRef(url);
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
FALLBACK:
|
||||
|
||||
// --- JVMTI fallback ---
|
||||
const char* j_jar_path = env->GetStringUTFChars(jar_path, nullptr);
|
||||
if (!j_jar_path)
|
||||
return JNI_FALSE;
|
||||
|
||||
jvmtiError err = agent.get_jvmti()->AddToSystemClassLoaderSearch(j_jar_path);
|
||||
|
||||
env->ReleaseStringUTFChars(jar_path, j_jar_path);
|
||||
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
// TODO: Safety and Compatibility: Define Class
|
||||
// Define class using target classloader
|
||||
JNIEXPORT jclass JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_defineClass
|
||||
(JNIEnv *env, jclass, jobject target_classloader, jbyteArray bytes) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
if (!check_env(agent))
|
||||
return nullptr;
|
||||
|
||||
jclass clClass = env->FindClass("java/lang/ClassLoader");
|
||||
jmethodID defineClass = env->GetMethodID(clClass, "defineClass", "([BII)Ljava/lang/Class;");
|
||||
jobject classDefined = env->CallObjectMethod(target_classloader, defineClass, bytes, 0,
|
||||
env->GetArrayLength(bytes));
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
return nullptr;
|
||||
}
|
||||
return (jclass)classDefined;
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getLoadedClasses
|
||||
(JNIEnv *env, jclass) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
if (!check_env(agent))
|
||||
return nullptr;
|
||||
|
||||
jint count = 0;
|
||||
jclass* classes = nullptr;
|
||||
jvmtiError err = agent.get_jvmti()->GetLoadedClasses(&count, &classes);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("GetLoadedClasses failed: %d", err);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jclass classClass = env->FindClass("java/lang/Class");
|
||||
jobjectArray classesArray = env->NewObjectArray(count, classClass, nullptr);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
env->SetObjectArrayElement(classesArray, i, classes[i]);
|
||||
}
|
||||
|
||||
agent.get_jvmti()->Deallocate((unsigned char*)classes);
|
||||
return classesArray;
|
||||
}
|
||||
|
||||
JNIEXPORT jclass JNICALL Java_cn_xiaozhou233_juiceagent_api_JuiceAgent_getClassByName
|
||||
(JNIEnv *env, jclass, jstring name) {
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
|
||||
if (!check_env(agent))
|
||||
return nullptr;
|
||||
|
||||
const char* utf = env->GetStringUTFChars(name, nullptr);
|
||||
if (!utf) {
|
||||
PLOGE << "Class name is NULL!";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Convert Java name to internal name: a.b.C -> a/b/C
|
||||
std::string internal_name(utf);
|
||||
std::replace(internal_name.begin(), internal_name.end(), '.', '/');
|
||||
env->ReleaseStringUTFChars(name, utf);
|
||||
|
||||
// Get all loaded classes
|
||||
jint count = 0;
|
||||
jclass* classes = nullptr;
|
||||
if (agent.get_jvmti()->GetLoadedClasses(&count, &classes) != JVMTI_ERROR_NONE || count == 0) {
|
||||
PLOGE << "GetLoadedClasses failed or no classes loaded";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jclass result = nullptr;
|
||||
|
||||
for (jint i = 0; i < count; i++) {
|
||||
char* signature = nullptr;
|
||||
if (agent.get_jvmti()->GetClassSignature(classes[i], &signature, nullptr) != JVMTI_ERROR_NONE || !signature)
|
||||
continue;
|
||||
|
||||
size_t sig_len = strlen(signature);
|
||||
if (sig_len > 2 && signature[0] == 'L' && signature[sig_len - 1] == ';' &&
|
||||
internal_name.size() == sig_len - 2 &&
|
||||
strncmp(signature + 1, internal_name.c_str(), sig_len - 2) == 0) {
|
||||
result = classes[i];
|
||||
agent.get_jvmti()->Deallocate((unsigned char*)signature);
|
||||
break;
|
||||
}
|
||||
|
||||
agent.get_jvmti()->Deallocate((unsigned char*)signature);
|
||||
}
|
||||
|
||||
if (classes) {
|
||||
agent.get_jvmti()->Deallocate((unsigned char*)classes);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
PLOGE << "Failed to find loaded class: " << internal_name;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#include <jni_impl.hpp>
|
||||
|
||||
@@ -1,251 +0,0 @@
|
||||
#include <jvm/jni.h>
|
||||
#include <jvm/jvmti.h>
|
||||
#include <stdio.h>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <libagent.h>
|
||||
#include <thread>
|
||||
#include <tinytoml/toml.h>
|
||||
#include <JuiceAgent/JuiceAgent.h>
|
||||
|
||||
struct _JuiceAgent {
|
||||
bool isAttached;
|
||||
JavaVM *jvm;
|
||||
jvmtiEnv *jvmti;
|
||||
JNIEnv *env;
|
||||
} JuiceAgent = {false, NULL, NULL, NULL};
|
||||
|
||||
InjectionInfoType InjectionInfo;
|
||||
|
||||
static int ReadConfig(const char* ConfigDir)
|
||||
{
|
||||
// ConfigDir/config.toml
|
||||
std::string path = std::string(ConfigDir) + "\\config.toml";
|
||||
std::ifstream ifs(path);
|
||||
if (!ifs) return -1;
|
||||
|
||||
// Parse toml
|
||||
toml::ParseResult pr = toml::parse(ifs);
|
||||
if (!pr.valid()) return -2;
|
||||
|
||||
const toml::Value& tbl = pr.value;
|
||||
|
||||
// Helper function: get string from toml
|
||||
auto get_str = [&](const char* key, const char* def, char* out) {
|
||||
const toml::Value* v = tbl.find(key);
|
||||
if (v && v->is<std::string>()) {
|
||||
std::string s = v->as<std::string>();
|
||||
if (!s.empty()) {
|
||||
strncpy(out, s.c_str(), INJECT_PATH_MAX - 1);
|
||||
PLOGD << "Found parameter: " << key << " = " << s.c_str();
|
||||
} else {
|
||||
strncpy(out, def, INJECT_PATH_MAX - 1);
|
||||
PLOGD << "Parameter " << key << " is empty, use default: " << def;
|
||||
}
|
||||
} else {
|
||||
strncpy(out, def, INJECT_PATH_MAX - 1);
|
||||
PLOGD << "Not found parameter: " << key << ", use default: " << def;
|
||||
}
|
||||
out[INJECT_PATH_MAX - 1] = '\0';
|
||||
};
|
||||
|
||||
// Default values
|
||||
std::string defaultJuiceLoader = std::string(ConfigDir) + "\\JuiceLoader.jar";
|
||||
std::string defaultJuiceLoaderLibrary = std::string(ConfigDir) + "\\libjuiceloader.dll";
|
||||
std::string defaultEntryJar = std::string(ConfigDir) + "\\Entry.jar";
|
||||
std::string defaultInjectionDir = std::string(ConfigDir) + "\\injection";
|
||||
|
||||
get_str("JuiceLoaderJarPath", defaultJuiceLoader.c_str(), InjectionInfo.JuiceLoaderJarPath);
|
||||
get_str("JuiceLoaderLibraryPath", defaultJuiceLoaderLibrary.c_str(), InjectionInfo.JuiceLoaderLibraryPath);
|
||||
get_str("InjectionDir", defaultInjectionDir.c_str(), InjectionInfo.InjectionDir);
|
||||
get_str("EntryJarPath", defaultEntryJar.c_str(), InjectionInfo.EntryJarPath);
|
||||
get_str("EntryClass", "cn.xiaozhou233.test.Entry", InjectionInfo.EntryClass);
|
||||
get_str("EntryMethod", "start", InjectionInfo.EntryMethod);
|
||||
|
||||
PLOGD << "JuiceLoaderJarPath: " << InjectionInfo.JuiceLoaderJarPath;
|
||||
PLOGD << "JuiceLoaderLibraryPath: " << InjectionInfo.JuiceLoaderLibraryPath;
|
||||
PLOGD << "InjectionDir: " << InjectionInfo.InjectionDir;
|
||||
PLOGD << "EntryJarPath: " << InjectionInfo.EntryJarPath;
|
||||
PLOGD << "EntryClass: " << InjectionInfo.EntryClass;
|
||||
PLOGD << "EntryMethod: " << InjectionInfo.EntryMethod;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int GetJavaEnv() {
|
||||
jint res = JNI_ERR;
|
||||
JavaVM *jvm = NULL;
|
||||
jvmtiEnv *jvmti = NULL;
|
||||
JNIEnv *env = NULL;
|
||||
int max_try = 30;
|
||||
|
||||
// Get the JVM
|
||||
max_try = 30;
|
||||
do {
|
||||
res = JNI_GetCreatedJavaVMs(&jvm, 1, NULL);
|
||||
if (res != JNI_OK || jvm == NULL) {
|
||||
PLOGE.printf("JNI_GetCreatedJavaVMs failed: %d", res);
|
||||
PLOGD << "JVM NULL: " << (jvm == NULL);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
max_try--;
|
||||
if (jvm != NULL) {
|
||||
break;
|
||||
} else {
|
||||
PLOGI.printf("Waiting for JVM... (%d)", max_try);
|
||||
}
|
||||
} while (jvm == NULL && max_try > 0);
|
||||
if (jvm == NULL) {
|
||||
PLOGE << "GetJavaEnv failed";
|
||||
return res;
|
||||
}
|
||||
JuiceAgent.jvm = jvm;
|
||||
PLOGI << "Got the JVM";
|
||||
|
||||
// Get the JNIEnv
|
||||
max_try = 30;
|
||||
do {
|
||||
res = jvm->GetEnv((void**)&env, JNI_VERSION_1_8);
|
||||
if (res != JNI_OK || env == NULL) {
|
||||
PLOGI << "GetEnv failed, trying to attach.";
|
||||
PLOGD << "env NULL: " << (env == NULL);
|
||||
res = jvm->AttachCurrentThread((void**)&env, NULL);
|
||||
if (res != JNI_OK || env == NULL) {
|
||||
PLOGE.printf("AttachCurrentThread failed: %d", res);
|
||||
PLOGD << "env NULL: " << (env == NULL);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
max_try--;
|
||||
if (env != NULL) {
|
||||
break;
|
||||
} else {
|
||||
PLOGI.printf("Waiting for JNI... (%d)", max_try);
|
||||
}
|
||||
} while (env == NULL && max_try > 0);
|
||||
if (env == NULL) {
|
||||
PLOGE << "Get JNI failed";
|
||||
return res;
|
||||
}
|
||||
JuiceAgent.env = env;
|
||||
PLOGI << "Got the JNIEnv";
|
||||
|
||||
// Get the JVMTI
|
||||
res = jvm->GetEnv((void**)&jvmti, JVMTI_VERSION_1_2);
|
||||
if (res != JNI_OK || jvmti == NULL) {
|
||||
PLOGE.printf("GetEnv failed: %d", res);
|
||||
PLOGD << "jvmti NULL: " << (jvmti == NULL);
|
||||
return res;
|
||||
}
|
||||
JuiceAgent.jvmti = jvmti;
|
||||
PLOGI << "Got the JVMTI";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int InvokeJuiceLoaderInit(const char* ConfigDir) {
|
||||
// Variables
|
||||
int result = JNI_ERR;
|
||||
JNIEnv *env = JuiceAgent.env;
|
||||
jvmtiEnv *jvmti = JuiceAgent.jvmti;
|
||||
|
||||
const char *bootstrap_class = "cn/xiaozhou233/juiceloader/JuiceLoaderBootstrap";
|
||||
const char *method_name = "init";
|
||||
const char *method_signature = "([Ljava/lang/String;)V";
|
||||
|
||||
PLOGI << "Invoke JuiceLoader Init";
|
||||
PLOGI << "================ JuiceLoader Init =================";
|
||||
// Find class
|
||||
jclass cls = env->FindClass(bootstrap_class);
|
||||
if (cls == NULL) {
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
}
|
||||
PLOGE << "FindClass failed";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Find method
|
||||
jmethodID mid = env->GetStaticMethodID(cls, method_name, method_signature);
|
||||
if (mid == NULL) {
|
||||
PLOGE << "GetStaticMethodID failed";
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// arguments array
|
||||
const char* args[] = {
|
||||
InjectionInfo.EntryJarPath,
|
||||
InjectionInfo.EntryClass,
|
||||
InjectionInfo.EntryMethod,
|
||||
InjectionInfo.InjectionDir,
|
||||
InjectionInfo.JuiceLoaderLibraryPath
|
||||
};
|
||||
int argCount = sizeof(args)/sizeof(args[0]);
|
||||
|
||||
jclass stringCls = env->FindClass("java/lang/String");
|
||||
jobjectArray jArgs = env->NewObjectArray(argCount, stringCls, nullptr);
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
env->SetObjectArrayElement(jArgs, i, env->NewStringUTF(args[i]));
|
||||
}
|
||||
|
||||
// Invoke method
|
||||
env->CallStaticVoidMethod(cls, mid, jArgs);
|
||||
if (env->ExceptionCheck()) {
|
||||
env->ExceptionDescribe();
|
||||
env->ExceptionClear();
|
||||
}
|
||||
|
||||
PLOGI << "================ JuiceLoader Init =================";
|
||||
|
||||
PLOGI << "Invoke JuiceLoader Init done";
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport)
|
||||
bool InitJuiceAgent(const char* runtime_path) {
|
||||
PLOGI << "--------> InitJuiceAgent Invoke <--------";
|
||||
PLOGD << "runtime_path: " << runtime_path;
|
||||
|
||||
// Read Config
|
||||
PLOGI << "ReadConfig ...";
|
||||
if (ReadConfig(runtime_path) != 0) {
|
||||
PLOGE << "ReadConfig failed";
|
||||
return false;
|
||||
}
|
||||
PLOGI << "[OK] ReadConfig";
|
||||
|
||||
// Get JavaEnv
|
||||
PLOGI << "Get JavaEnv ...";
|
||||
if (GetJavaEnv() != 0) {
|
||||
PLOGE << "GetJavaEnv failed";
|
||||
return false;
|
||||
}
|
||||
PLOGI << "[OK] Get JavaEnv";
|
||||
|
||||
// Inject JuiceLoader jar
|
||||
PLOGI << "Inject JuiceLoader jar ...";
|
||||
if (JuiceAgent.jvmti->AddToSystemClassLoaderSearch(InjectionInfo.JuiceLoaderJarPath) != JNI_OK) {
|
||||
PLOGE << "AddToSystemClassLoaderSearch failed";
|
||||
return false;
|
||||
}
|
||||
PLOGI << "[OK] Inject JuiceLoader jar";
|
||||
|
||||
// Invoke JuiceLoader Init
|
||||
PLOGI << "Invoke JuiceLoader Init ...";
|
||||
if (InvokeJuiceLoaderInit(runtime_path) != 0) {
|
||||
PLOGE << "Invoke JuiceLoader Init failed";
|
||||
return false;
|
||||
}
|
||||
PLOGI << "[OK] Invoke JuiceLoader Init";
|
||||
|
||||
// Load JuiceLoaderLibrary
|
||||
|
||||
PLOGI << "--------> InitJuiceAgent Succeed <--------";
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include <services.hpp>
|
||||
#include <jni_impl.hpp>
|
||||
|
||||
namespace JuiceAgent::services::Bytecode {
|
||||
void capture_bytecodes(const EventClassFileLoadHook& e) {
|
||||
/* =========================
|
||||
* 1. Capture original bytes
|
||||
* ========================= */
|
||||
std::lock_guard<std::mutex> lock(classDataMutex);
|
||||
if (classToCapture.contains(e.name)) {
|
||||
if (!classFileDataMap.contains(e.name)) {
|
||||
ClassFileData data;
|
||||
|
||||
data.classname = e.name;
|
||||
data.bytecode.assign(e.classbytes, e.classbytes + e.class_data_len);
|
||||
// Experimental: class/classloader/protection_domain references (to be used in future features, e.g. dynamic patching)
|
||||
data.clazz = e.class_being_redefined;
|
||||
data.classloader = e.loader;
|
||||
data.protection_domain = e.protection_domain;
|
||||
|
||||
|
||||
classFileDataMap[e.name] = std::move(data);
|
||||
|
||||
classToCapture.erase(e.name);
|
||||
|
||||
PLOGI << "Captured class: " << e.name << " (length: " << e.class_data_len << ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void patch_bytecodes(const EventClassFileLoadHook& e) {
|
||||
/* =========================
|
||||
* 2. Apply patches
|
||||
* ========================= */
|
||||
if (pendingRetransform.contains(e.name)) {
|
||||
auto& bytes = pendingRetransform[e.name];
|
||||
|
||||
unsigned char* new_buf = nullptr;
|
||||
e.jvmti_env->Allocate(bytes.size(), &new_buf);
|
||||
|
||||
memcpy(new_buf, bytes.data(), bytes.size());
|
||||
|
||||
*e.new_class_data_len = (jint)bytes.size();
|
||||
*e.new_classbytes = new_buf;
|
||||
|
||||
pendingRetransform.erase(e.name);
|
||||
|
||||
PLOGI << "Retransformed: " << e.name << " (new length: " << bytes.size() << ")";
|
||||
}
|
||||
}
|
||||
|
||||
void init() {
|
||||
agent.get_eventbus().subscribe<EventClassFileLoadHook>(capture_bytecodes);
|
||||
agent.get_eventbus().subscribe<EventClassFileLoadHook>(patch_bytecodes);
|
||||
}
|
||||
|
||||
void start() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#include <services.hpp>
|
||||
|
||||
namespace JuiceAgent::services::JarLoader {
|
||||
static JarLoaderConfig config;
|
||||
|
||||
static const char* MODULE_CLASS = "cn/xiaozhou233/juiceagent/api/modules/JarLoader";
|
||||
static const char* MODULE_METHOD = "loadJar";
|
||||
|
||||
void init() {
|
||||
auto& cfg = agent.get_config();
|
||||
|
||||
config.enabled = cfg.get<bool>(
|
||||
"JuiceAgent.Modules.JarLoader.Enabled",
|
||||
false
|
||||
);
|
||||
|
||||
config.injection_dir = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.InjectionDir",
|
||||
(cfg.runtime_dir() / "injection").string(),
|
||||
true
|
||||
);
|
||||
|
||||
config.jar_path = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.JarPath",
|
||||
"./Entry.jar",
|
||||
true
|
||||
);
|
||||
|
||||
config.entry_class = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.EntryClass",
|
||||
"Example.Main",
|
||||
false
|
||||
);
|
||||
|
||||
config.entry_method = cfg.get<std::string>(
|
||||
"JuiceAgent.Modules.JarLoader.EntryMethod",
|
||||
"start",
|
||||
false
|
||||
);
|
||||
|
||||
PLOGI << "JarLoaderService initialized";
|
||||
}
|
||||
|
||||
void start() {
|
||||
if (!config.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
JuiceAgent::Utils::Serializer ser;
|
||||
|
||||
ser.add_kv("InjectionDir", config.injection_dir);
|
||||
ser.add_kv("JarPath", config.jar_path);
|
||||
ser.add_kv("EntryClass", config.entry_class);
|
||||
ser.add_kv("EntryMethod", config.entry_method);
|
||||
|
||||
auto data = ser.serialize();
|
||||
|
||||
JuiceAgent::Utils::call_java_impl(
|
||||
agent.get_env(),
|
||||
MODULE_CLASS,
|
||||
MODULE_METHOD,
|
||||
data.c_str()
|
||||
);
|
||||
|
||||
PLOGI << "JarLoader start";
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <services.hpp>
|
||||
#include <event/event_type.hpp>
|
||||
|
||||
namespace JuiceAgent::services::Manager {
|
||||
void register_events() {
|
||||
// PreLoad
|
||||
agent.get_eventbus().subscribe<EventPreLoad>(init);
|
||||
|
||||
// Loaded
|
||||
agent.get_eventbus().subscribe<EventLoaded>(start);
|
||||
|
||||
// TODO: Stopped
|
||||
|
||||
PLOGI << "Services Manager registered events";
|
||||
}
|
||||
|
||||
void init(const EventPreLoad& event) {
|
||||
PLOGI << "Initializing services";
|
||||
// JarLoader
|
||||
JuiceAgent::services::JarLoader::init();
|
||||
|
||||
// Bytecode
|
||||
JuiceAgent::services::Bytecode::init();
|
||||
}
|
||||
|
||||
void start(const EventLoaded& event) {
|
||||
PLOGI << "Starting services";
|
||||
// JarLoader
|
||||
JuiceAgent::services::JarLoader::start();
|
||||
|
||||
// Bytecode
|
||||
JuiceAgent::services::Bytecode::start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ int main(int argc, char **argv) {
|
||||
printf("Warning: GetCurrentDirectory failed, using '.'\n");
|
||||
strncpy(cwd, ".", MAX_PATH_LEN - 1);
|
||||
}
|
||||
snprintf(dll_path, MAX_PATH_LEN, "%s\\libagent.dll", cwd);
|
||||
snprintf(dll_path, MAX_PATH_LEN, "%s\\libloader.dll", cwd);
|
||||
printf("Using DLL path: %s\n", dll_path);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
file(
|
||||
GLOB_RECURSE
|
||||
libjuiceloader_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/jni/*.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/jni/*.cpp
|
||||
)
|
||||
|
||||
add_library(juiceloader SHARED ${libjuiceloader_sources})
|
||||
|
||||
target_include_directories(juiceloader PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/includes
|
||||
${CMAKE_SOURCE_DIR}/includes/jvm
|
||||
${CMAKE_SOURCE_DIR}/includes/jvm/win32
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/includes
|
||||
)
|
||||
|
||||
target_link_libraries(juiceloader PRIVATE
|
||||
ReflectiveDLLInjection
|
||||
jvm
|
||||
)
|
||||
@@ -1,141 +0,0 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class cn_xiaozhou233_juiceloader_JuiceLoader */
|
||||
|
||||
#ifndef _Included_cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
#define _Included_cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: init
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_init
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: injectJar
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_injectJar
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: AddToBootstrapClassLoaderSearch
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_AddToBootstrapClassLoaderSearch
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: AddToSystemClassLoaderSearch
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_AddToSystemClassLoaderSearch
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: AddToClassLoader
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_AddToClassLoader
|
||||
(JNIEnv *, jclass, jstring, jobject);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: defineClass
|
||||
* Signature: (Ljava/lang/ClassLoader;[B)Ljava/lang/Class;
|
||||
*/
|
||||
JNIEXPORT jclass JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_defineClass
|
||||
(JNIEnv *, jclass, jobject, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: redefineClass
|
||||
* Signature: (Ljava/lang/Class;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_redefineClass
|
||||
(JNIEnv *, jclass, jclass, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: redefineClassByName
|
||||
* Signature: (Ljava/lang/String;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_redefineClassByName
|
||||
(JNIEnv *, jclass, jstring, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: getLoadedClasses
|
||||
* Signature: ()[Ljava/lang/Class;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_getLoadedClasses
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: getClassBytes
|
||||
* Signature: (Ljava/lang/Class;)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_getClassBytes
|
||||
(JNIEnv *, jclass, jclass);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: getClassBytesByName
|
||||
* Signature: (Ljava/lang/String;)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_getClassBytesByName
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: retransformClass
|
||||
* Signature: (Ljava/lang/Class;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_retransformClass
|
||||
(JNIEnv *, jclass, jclass, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: retransformClassByName
|
||||
* Signature: (Ljava/lang/String;[BI)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_retransformClassByName
|
||||
(JNIEnv *, jclass, jstring, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: getClassByName
|
||||
* Signature: (Ljava/lang/String;)Ljava/lang/Class;
|
||||
*/
|
||||
JNIEXPORT jclass JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_getClassByName
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: nativeGetThreadByName
|
||||
* Signature: (Ljava/lang/String;)Ljava/lang/Thread;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_nativeGetThreadByName
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: cn_xiaozhou233_juiceloader_JuiceLoader
|
||||
* Method: nativeInjectJarToThread
|
||||
* Signature: (Ljava/lang/Thread;Ljava/lang/String;)Ljava/lang/ClassLoader;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_nativeInjectJarToThread
|
||||
(JNIEnv *, jclass, jobject, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef JNI_IMPL_H
|
||||
#define JNI_IMPL_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <juiceloader.h>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <cn_xiaozhou233_juiceloader_JuiceLoader.h>
|
||||
|
||||
// Variables
|
||||
extern const char* g_target_internal_name;
|
||||
extern unsigned char* g_bytecodes;
|
||||
extern jint g_bytecodes_len;
|
||||
|
||||
void JNICALL ClassFileLoadHook(
|
||||
jvmtiEnv* jvmti_env,
|
||||
JNIEnv* jni_env,
|
||||
jclass class_being_redefined,
|
||||
jobject loader,
|
||||
const char* name,
|
||||
jobject protection_domain,
|
||||
jint class_data_len,
|
||||
const unsigned char* classbytes,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_classbytes);
|
||||
|
||||
#endif // JNI_IMPL_H
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef JUICELOADER_H
|
||||
#define JUICELOADER_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
|
||||
typedef struct _JuiceLoaderNative {
|
||||
jvmtiEnv *jvmti;
|
||||
} JuiceLoaderNativeType;
|
||||
extern JuiceLoaderNativeType JuiceLoaderNative;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
unsigned char *bytes;
|
||||
int len;
|
||||
} ClassBytesCacheType;
|
||||
|
||||
typedef struct {
|
||||
ClassBytesCacheType *arr;
|
||||
int size;
|
||||
int capacity;
|
||||
} RetransformClassCacheType;
|
||||
|
||||
extern RetransformClassCacheType RetransformClassCache;
|
||||
|
||||
extern "C" __declspec(dllexport)
|
||||
int InitJuiceLoader(JNIEnv *env, jvmtiEnv *jvmti);
|
||||
|
||||
#endif
|
||||
@@ -1,74 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
|
||||
RetransformClassCacheType RetransformClassCache = {NULL, 0, 0};
|
||||
|
||||
static void throwRuntimeException(JNIEnv *env, const char *msg) {
|
||||
jclass rte = env->FindClass("java/lang/RuntimeException");
|
||||
if (rte != NULL) {
|
||||
env->ThrowNew(rte, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void JNICALL ClassFileLoadHook(
|
||||
jvmtiEnv* jvmti_env,
|
||||
JNIEnv*,
|
||||
jclass,
|
||||
jobject,
|
||||
const char* name,
|
||||
jobject,
|
||||
jint class_data_len,
|
||||
const unsigned char* classbytes,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_classbytes) {
|
||||
|
||||
if (!name) return;
|
||||
|
||||
/* =========================
|
||||
* 1. Capture original bytes
|
||||
* ========================= */
|
||||
if (g_target_internal_name &&
|
||||
g_bytecodes == nullptr &&
|
||||
strcmp(name, g_target_internal_name) == 0) {
|
||||
|
||||
g_bytecodes_len = class_data_len;
|
||||
g_bytecodes = (unsigned char*)malloc(class_data_len);
|
||||
memcpy(g_bytecodes, classbytes, class_data_len);
|
||||
|
||||
// IMPORTANT:
|
||||
// Do NOT touch new_classbytes here
|
||||
// Let JVM continue normally
|
||||
PLOGD.printf("[Hook:get] Captured class bytes: %s (%d)", name, class_data_len);
|
||||
return;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* 2. Apply redefine patch
|
||||
* ========================= */
|
||||
if (RetransformClassCache.size == 0) return;
|
||||
|
||||
for (int i = 0; i < RetransformClassCache.size; i++) {
|
||||
ClassBytesCacheType* entry = &RetransformClassCache.arr[i];
|
||||
if (strcmp(entry->name, name) == 0) {
|
||||
|
||||
unsigned char* newBytes = nullptr;
|
||||
if (jvmti_env->Allocate(entry->len, &newBytes) != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("[Hook:set] Allocate failed: %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(newBytes, entry->bytes, entry->len);
|
||||
*new_classbytes = newBytes;
|
||||
*new_class_data_len = entry->len;
|
||||
|
||||
PLOGI.printf("[Hook:set] Redefined class: %s (%d)", name, entry->len);
|
||||
|
||||
free(entry->name);
|
||||
free(entry->bytes);
|
||||
for (int j = i; j < RetransformClassCache.size - 1; j++) {
|
||||
RetransformClassCache.arr[j] = RetransformClassCache.arr[j + 1];
|
||||
}
|
||||
RetransformClassCache.size--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
/* =========================
|
||||
* Global bytecode capture
|
||||
* ========================= */
|
||||
const char* g_target_internal_name = nullptr;
|
||||
unsigned char* g_bytecodes = nullptr;
|
||||
jint g_bytecodes_len = 0;
|
||||
|
||||
/* =========================
|
||||
* Utils
|
||||
* ========================= */
|
||||
|
||||
// Convert java name to internal name: a.b.C -> a/b/C
|
||||
static void to_internal_name(char* s) {
|
||||
for (; *s; ++s) {
|
||||
if (*s == '.') *s = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* JVMTI: enumerate loaded classes
|
||||
* ========================= */
|
||||
static jclass findLoadedClassByInternalName(jvmtiEnv* jvmti, const char* internalName) {
|
||||
jint count = 0;
|
||||
jclass* classes = nullptr;
|
||||
|
||||
if (jvmti->GetLoadedClasses(&count, &classes) != JVMTI_ERROR_NONE || count == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jclass result = nullptr;
|
||||
|
||||
for (jint i = 0; i < count; i++) {
|
||||
char* signature = nullptr;
|
||||
if (jvmti->GetClassSignature(classes[i], &signature, nullptr) == JVMTI_ERROR_NONE && signature) {
|
||||
// signature format: Lnet/minecraft/xxx;
|
||||
size_t len = strlen(signature);
|
||||
if (len > 2 && signature[0] == 'L' && signature[len - 1] == ';') {
|
||||
if (strncmp(signature + 1, internalName, len - 2) == 0) {
|
||||
result = classes[i];
|
||||
jvmti->Deallocate((unsigned char*)signature);
|
||||
break;
|
||||
}
|
||||
}
|
||||
jvmti->Deallocate((unsigned char*)signature);
|
||||
}
|
||||
}
|
||||
|
||||
if (classes) {
|
||||
jvmti->Deallocate((unsigned char*)classes);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* Exposed: get all loaded classes
|
||||
* ========================= */
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_cn_xiaozhou233_juiceloader_JuiceLoader_getLoadedClasses
|
||||
(JNIEnv* env, jclass) {
|
||||
|
||||
if (!JuiceLoaderNative.jvmti) return nullptr;
|
||||
|
||||
jint count = 0;
|
||||
jclass* classes = nullptr;
|
||||
if (JuiceLoaderNative.jvmti->GetLoadedClasses(&count, &classes) != JVMTI_ERROR_NONE || count == 0) {
|
||||
return env->NewObjectArray(0, env->FindClass("java/lang/Class"), nullptr);
|
||||
}
|
||||
|
||||
jclass classClass = env->FindClass("java/lang/Class");
|
||||
jobjectArray result = env->NewObjectArray(count, classClass, nullptr);
|
||||
|
||||
for (jint i = 0; i < count; i++) {
|
||||
env->SetObjectArrayElement(result, i, classes[i]);
|
||||
}
|
||||
|
||||
JuiceLoaderNative.jvmti->Deallocate((unsigned char*)classes);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* Get bytecode by jclass
|
||||
* ========================= */
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_cn_xiaozhou233_juiceloader_JuiceLoader_getClassBytes
|
||||
(JNIEnv* env, jclass, jclass clazz) {
|
||||
|
||||
if (!JuiceLoaderNative.jvmti || !clazz) return nullptr;
|
||||
|
||||
char* signature = nullptr;
|
||||
if (JuiceLoaderNative.jvmti->GetClassSignature(clazz, &signature, nullptr) != JVMTI_ERROR_NONE || !signature) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Lxxx; -> xxx
|
||||
std::string internalName(signature + 1, strlen(signature) - 2);
|
||||
JuiceLoaderNative.jvmti->Deallocate((unsigned char*)signature);
|
||||
|
||||
g_target_internal_name = internalName.c_str();
|
||||
g_bytecodes = nullptr;
|
||||
g_bytecodes_len = 0;
|
||||
|
||||
jvmtiError err = JuiceLoaderNative.jvmti->RetransformClasses(1, &clazz);
|
||||
if (err != JVMTI_ERROR_NONE || !g_bytecodes) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jbyteArray out = env->NewByteArray(g_bytecodes_len);
|
||||
env->SetByteArrayRegion(out, 0, g_bytecodes_len, (jbyte*)g_bytecodes);
|
||||
|
||||
free(g_bytecodes);
|
||||
g_bytecodes = nullptr;
|
||||
g_target_internal_name = nullptr;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* Get bytecode by class name
|
||||
* ========================= */
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_cn_xiaozhou233_juiceloader_JuiceLoader_getClassBytesByName
|
||||
(JNIEnv* env, jclass loader_class, jstring className) {
|
||||
|
||||
if (!JuiceLoaderNative.jvmti || !className) return nullptr;
|
||||
|
||||
const char* utf = env->GetStringUTFChars(className, nullptr);
|
||||
if (!utf) return nullptr;
|
||||
|
||||
char internal[512];
|
||||
strncpy(internal, utf, sizeof(internal) - 1);
|
||||
internal[sizeof(internal) - 1] = '\0';
|
||||
env->ReleaseStringUTFChars(className, utf);
|
||||
|
||||
to_internal_name(internal);
|
||||
|
||||
jclass clazz = findLoadedClassByInternalName(JuiceLoaderNative.jvmti, internal);
|
||||
if (!clazz) {
|
||||
PLOGE.printf("Class not loaded: %s", internal);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Java_cn_xiaozhou233_juiceloader_JuiceLoader_getClassBytes(
|
||||
env, loader_class, clazz
|
||||
);
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* Get jclass by name (no ClassLoader)
|
||||
* ========================= */
|
||||
JNIEXPORT jclass JNICALL
|
||||
Java_cn_xiaozhou233_juiceloader_JuiceLoader_getClassByName
|
||||
(JNIEnv* env, jclass, jstring className) {
|
||||
|
||||
if (!JuiceLoaderNative.jvmti || !className) return nullptr;
|
||||
|
||||
const char* utf = env->GetStringUTFChars(className, nullptr);
|
||||
if (!utf) return nullptr;
|
||||
|
||||
char internal[512];
|
||||
strncpy(internal, utf, sizeof(internal) - 1);
|
||||
internal[sizeof(internal) - 1] = '\0';
|
||||
env->ReleaseStringUTFChars(className, utf);
|
||||
|
||||
to_internal_name(internal);
|
||||
|
||||
jclass clazz = findLoadedClassByInternalName(JuiceLoaderNative.jvmti, internal);
|
||||
if (!clazz) {
|
||||
PLOGE.printf("Failed to find loaded class: %s", internal);
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
|
||||
JNIEXPORT jclass JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_defineClass
|
||||
(JNIEnv *env, jclass, jobject cl, jbyteArray bytes) {
|
||||
PLOGD << "Invoked!";
|
||||
jclass clClass = env->FindClass("java/lang/ClassLoader");
|
||||
jmethodID defineClass = env->GetMethodID(clClass, "defineClass", "([BII)Ljava/lang/Class;");
|
||||
jobject classDefined = env->CallObjectMethod(cl, defineClass, bytes, 0,
|
||||
env->GetArrayLength(bytes));
|
||||
return (jclass)classDefined;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_init
|
||||
(JNIEnv *env, jclass loader_class) {
|
||||
PLOGI << "Invoked!";
|
||||
|
||||
// Get JavaVM
|
||||
JavaVM* jvm = nullptr;
|
||||
env->GetJavaVM(&jvm);
|
||||
if (jvm == nullptr) {
|
||||
PLOGE << "Failed to get JavaVM instance";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// Get JVMTI
|
||||
jvmtiEnv* jvmti = nullptr;
|
||||
jvmtiError err = static_cast<jvmtiError>(jvm->GetEnv(reinterpret_cast<void**>(&jvmti), JVMTI_VERSION_1_2));
|
||||
if (err != JVMTI_ERROR_NONE || jvmti == nullptr) {
|
||||
PLOGE << "Failed to get JVMTI environment, error: " << err;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
int result = InitJuiceLoader(env, jvmti);
|
||||
if (result != 0) {
|
||||
PLOGE << "Failed to initialize JuiceLoader, error code: " << result;
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
PLOGI << "JuiceLoader initialized successfully";
|
||||
return JNI_TRUE;
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
|
||||
// Deprecated
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_injectJar
|
||||
(JNIEnv *env, jclass loader_class, jstring jarPath) {
|
||||
PLOGI << "Invoked!";
|
||||
const char *pathStr = env->GetStringUTFChars(jarPath, NULL);
|
||||
if (!pathStr) {
|
||||
PLOGE << "Path is NULL!";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if (!JuiceLoaderNative.jvmti) {
|
||||
PLOGE.printf("JuiceLoaderNative.jvmti is NULL! [jvmti=%p]", JuiceLoaderNative.jvmti);
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jvmtiError result = JuiceLoaderNative.jvmti->AddToSystemClassLoaderSearch(pathStr);
|
||||
if (result != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("Cannot inject jar [result=%d]", result);
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
PLOGI << "Jar injected: " << pathStr;
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
JNIEXPORT jobject JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_nativeInjectJarToThread
|
||||
(JNIEnv* env, jclass, jobject threadObj, jstring jJarPath)
|
||||
{
|
||||
// Convert jstring -> std::string
|
||||
const char* cJarPath = env->GetStringUTFChars(jJarPath, nullptr);
|
||||
|
||||
// new File(jarPath)
|
||||
jclass fileClass = env->FindClass("java/io/File");
|
||||
jmethodID fileCtor = env->GetMethodID(fileClass, "<init>", "(Ljava/lang/String;)V");
|
||||
jstring jPathCopy = env->NewStringUTF(cJarPath);
|
||||
jobject fileObj = env->NewObject(fileClass, fileCtor, jPathCopy);
|
||||
|
||||
// File.toURI()
|
||||
jmethodID midToURI = env->GetMethodID(fileClass, "toURI", "()Ljava/net/URI;");
|
||||
jobject uriObj = env->CallObjectMethod(fileObj, midToURI);
|
||||
|
||||
// URI.toURL()
|
||||
jclass uriClass = env->FindClass("java/net/URI");
|
||||
jmethodID midToURL = env->GetMethodID(uriClass, "toURL", "()Ljava/net/URL;");
|
||||
jobject urlObj = env->CallObjectMethod(uriObj, midToURL);
|
||||
|
||||
// Thread.getContextClassLoader()
|
||||
jclass threadClass = env->FindClass("java/lang/Thread");
|
||||
jmethodID midGetCL = env->GetMethodID(
|
||||
threadClass, "getContextClassLoader", "()Ljava/lang/ClassLoader;"
|
||||
);
|
||||
jobject originalCL = env->CallObjectMethod(threadObj, midGetCL);
|
||||
|
||||
// URLClassLoader(URL[] urls, ClassLoader parent)
|
||||
jclass urlClassLoaderClass = env->FindClass("java/net/URLClassLoader");
|
||||
jmethodID urlCLCtor = env->GetMethodID(
|
||||
urlClassLoaderClass,
|
||||
"<init>",
|
||||
"([Ljava/net/URL;Ljava/lang/ClassLoader;)V"
|
||||
);
|
||||
|
||||
// Create URL[] array with 1 element
|
||||
jobjectArray urlArray = env->NewObjectArray(1, env->FindClass("java/net/URL"), nullptr);
|
||||
env->SetObjectArrayElement(urlArray, 0, urlObj);
|
||||
|
||||
// Create new URLClassLoader
|
||||
jobject newClassLoader = env->NewObject(
|
||||
urlClassLoaderClass,
|
||||
urlCLCtor,
|
||||
urlArray,
|
||||
originalCL
|
||||
);
|
||||
|
||||
// thread.setContextClassLoader(newCL)
|
||||
jmethodID midSetCL = env->GetMethodID(
|
||||
threadClass,
|
||||
"setContextClassLoader",
|
||||
"(Ljava/lang/ClassLoader;)V"
|
||||
);
|
||||
env->CallVoidMethod(threadObj, midSetCL, newClassLoader);
|
||||
|
||||
env->ReleaseStringUTFChars(jJarPath, cJarPath);
|
||||
|
||||
return newClassLoader;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_AddToBootstrapClassLoaderSearch
|
||||
(JNIEnv *env, jclass, jstring jarPath) {
|
||||
PLOGD << "Invoked!";
|
||||
const char *pathStr = env->GetStringUTFChars(jarPath, NULL);
|
||||
if (!pathStr) {
|
||||
PLOGE << "Path is NULL!";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if (!JuiceLoaderNative.jvmti) {
|
||||
PLOGE.printf("JuiceLoaderNative.jvmti is NULL! [jvmti=%p]", JuiceLoaderNative.jvmti);
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jvmtiError result = JuiceLoaderNative.jvmti->AddToBootstrapClassLoaderSearch(pathStr);
|
||||
if (result != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("Cannot AddToBootstrapClassLoaderSearch [result=%d]", result);
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
PLOGI << "AddToBootstrapClassLoaderSearch: " << pathStr;
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_AddToSystemClassLoaderSearch
|
||||
(JNIEnv *env, jclass, jstring jarPath) {
|
||||
PLOGD << "Invoked!";
|
||||
const char *pathStr = env->GetStringUTFChars(jarPath, NULL);
|
||||
if (!pathStr) {
|
||||
PLOGE << "Path is NULL!";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
if (!JuiceLoaderNative.jvmti) {
|
||||
PLOGE.printf("JuiceLoaderNative.jvmti is NULL! [jvmti=%p]", JuiceLoaderNative.jvmti);
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jvmtiError result = JuiceLoaderNative.jvmti->AddToSystemClassLoaderSearch(pathStr);
|
||||
if (result != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("Cannot AddToSystemClassLoaderSearch [result=%d]", result);
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(jarPath, pathStr);
|
||||
PLOGI << "AddToSystemClassLoaderSearch: " << pathStr;
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_cn_xiaozhou233_juiceloader_JuiceLoader_AddToClassLoader
|
||||
(JNIEnv *env, jclass, jstring path, jobject loader) {
|
||||
|
||||
jclass urlClassLoader = env->FindClass("java/net/URLClassLoader");
|
||||
|
||||
if (env->IsInstanceOf(loader, urlClassLoader)) {
|
||||
jclass fileClass = env->FindClass("java/io/File");
|
||||
jmethodID fileInit = env->GetMethodID(
|
||||
fileClass,
|
||||
"<init>",
|
||||
"(Ljava/lang/String;)V"
|
||||
);
|
||||
|
||||
jobject file = env->NewObject(fileClass, fileInit, path);
|
||||
|
||||
jmethodID toURI = env->GetMethodID(
|
||||
fileClass,
|
||||
"toURI",
|
||||
"()Ljava/net/URI;"
|
||||
);
|
||||
jobject uri = env->CallObjectMethod(file, toURI);
|
||||
|
||||
jclass uriClass = env->FindClass("java/net/URI");
|
||||
jmethodID toURL = env->GetMethodID(
|
||||
uriClass,
|
||||
"toURL",
|
||||
"()Ljava/net/URL;"
|
||||
);
|
||||
jobject url = env->CallObjectMethod(uri, toURL);
|
||||
|
||||
jmethodID addURL = env->GetMethodID(
|
||||
urlClassLoader,
|
||||
"addURL",
|
||||
"(Ljava/net/URL;)V"
|
||||
);
|
||||
env->CallVoidMethod(loader, addURL, url);
|
||||
} else {
|
||||
// jstring -> const char*
|
||||
const char* nativePath = env->GetStringUTFChars(path, nullptr);
|
||||
|
||||
JuiceLoaderNative.jvmti->AddToSystemClassLoaderSearch(nativePath);
|
||||
|
||||
// Release UTF string
|
||||
env->ReleaseStringUTFChars(path, nativePath);
|
||||
}
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_redefineClass
|
||||
(JNIEnv *env, jclass loader_class, jclass clazz, jbyteArray classBytes, jint length) {
|
||||
PLOGI << "Invoked!";
|
||||
if (!JuiceLoaderNative.jvmti) {
|
||||
PLOGE.printf("JuiceLoaderNative.jvmti is NULL! [jvmti=%p]", JuiceLoaderNative.jvmti);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jbyte* buf = env->GetByteArrayElements(classBytes, NULL);
|
||||
if (!buf) {
|
||||
PLOGE << "Cannot get class bytes";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jvmtiClassDefinition defs[1];
|
||||
defs[0].klass = clazz;
|
||||
defs[0].class_byte_count = length;
|
||||
defs[0].class_bytes = reinterpret_cast<const unsigned char*>(buf);
|
||||
|
||||
jvmtiError result = JuiceLoaderNative.jvmti->RedefineClasses(1, defs);
|
||||
env->ReleaseByteArrayElements(classBytes, buf, JNI_ABORT);
|
||||
|
||||
if (result != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("Cannot redefine class [result=%d]", result);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
PLOGI.printf("Class redefined successfully!");
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_redefineClassByName
|
||||
(JNIEnv *env, jclass loader_class, jstring className, jbyteArray classBytes, jint length) {
|
||||
PLOGI << "redefineClass_className Invoked!";
|
||||
if (!JuiceLoaderNative.jvmti) {
|
||||
PLOGE.printf("JuiceLoaderNative.jvmti is NULL! [jvmti=%p]", JuiceLoaderNative.jvmti);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
const char* cname = env->GetStringUTFChars(className, NULL);
|
||||
if (!cname) {
|
||||
PLOGE << "Class name is NULL!";
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jclass clazz = env->FindClass(cname);
|
||||
if (!clazz) {
|
||||
PLOGE.printf("Class not found! [ClassName=%s]", cname);
|
||||
env->ReleaseStringUTFChars(className, cname);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
jboolean ret = Java_cn_xiaozhou233_juiceloader_JuiceLoader_redefineClass(env, loader_class, clazz, classBytes, length);
|
||||
env->ReleaseStringUTFChars(className, cname);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
#include <string.h>
|
||||
|
||||
/* =========================
|
||||
* utils
|
||||
* ========================= */
|
||||
|
||||
static char* get_class_name(JNIEnv* env, jclass clazz) {
|
||||
jclass clsClass = env->FindClass("java/lang/Class");
|
||||
jmethodID mid = env->GetMethodID(clsClass, "getName", "()Ljava/lang/String;");
|
||||
jstring nameStr = (jstring)env->CallObjectMethod(clazz, mid);
|
||||
|
||||
const char* tmp = env->GetStringUTFChars(nameStr, nullptr);
|
||||
char* result = _strdup(tmp);
|
||||
env->ReleaseStringUTFChars(nameStr, tmp);
|
||||
env->DeleteLocalRef(nameStr);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* JVMTI global lookup
|
||||
* ========================= */
|
||||
|
||||
static jclass findLoadedClassByInternalName(
|
||||
jvmtiEnv* jvmti,
|
||||
const char* internalName
|
||||
) {
|
||||
jint count = 0;
|
||||
jclass* classes = nullptr;
|
||||
|
||||
if (jvmti->GetLoadedClasses(&count, &classes) != JVMTI_ERROR_NONE || count == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
jclass result = nullptr;
|
||||
|
||||
for (jint i = 0; i < count; i++) {
|
||||
char* sig = nullptr;
|
||||
if (jvmti->GetClassSignature(classes[i], &sig, nullptr) == JVMTI_ERROR_NONE && sig) {
|
||||
// Lnet/minecraft/client/Minecraft;
|
||||
if (sig[0] == 'L') {
|
||||
size_t len = strlen(sig);
|
||||
if (len > 2 &&
|
||||
strncmp(sig + 1, internalName, len - 2) == 0 &&
|
||||
internalName[len - 2] == '\0') {
|
||||
result = classes[i];
|
||||
jvmti->Deallocate((unsigned char*)sig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
jvmti->Deallocate((unsigned char*)sig);
|
||||
}
|
||||
}
|
||||
|
||||
jvmti->Deallocate((unsigned char*)classes);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* retransform by jclass
|
||||
* ========================= */
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_cn_xiaozhou233_juiceloader_JuiceLoader_retransformClass
|
||||
(JNIEnv* env, jclass, jclass clazz, jbyteArray classBytes, jint) {
|
||||
|
||||
if (!JuiceLoaderNative.jvmti || !clazz || !classBytes) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
char* nameDot = get_class_name(env, clazz);
|
||||
for (char* p = nameDot; *p; ++p)
|
||||
if (*p == '.') *p = '/';
|
||||
|
||||
jbyte* bytes = env->GetByteArrayElements(classBytes, nullptr);
|
||||
jint len = env->GetArrayLength(classBytes);
|
||||
|
||||
if (RetransformClassCache.size >= RetransformClassCache.capacity) {
|
||||
int newCap = RetransformClassCache.capacity == 0 ? 4 : RetransformClassCache.capacity * 2;
|
||||
RetransformClassCache.arr =
|
||||
(ClassBytesCacheType*)realloc(RetransformClassCache.arr, newCap * sizeof(ClassBytesCacheType));
|
||||
RetransformClassCache.capacity = newCap;
|
||||
}
|
||||
|
||||
ClassBytesCacheType* entry =
|
||||
&RetransformClassCache.arr[RetransformClassCache.size++];
|
||||
|
||||
entry->name = _strdup(nameDot);
|
||||
entry->bytes = (unsigned char*)malloc(len);
|
||||
memcpy(entry->bytes, bytes, len);
|
||||
entry->len = len;
|
||||
|
||||
env->ReleaseByteArrayElements(classBytes, bytes, JNI_ABORT);
|
||||
|
||||
jclass arr[1] = { clazz };
|
||||
jvmtiError err = JuiceLoaderNative.jvmti->RetransformClasses(1, arr);
|
||||
|
||||
free(nameDot);
|
||||
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
PLOGE.printf("RetransformClasses failed: %d", err);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
PLOGI.printf("[retransformClass] OK: %s (%d)", entry->name, entry->len);
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* retransform by name (NO FindClass)
|
||||
* ========================= */
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_cn_xiaozhou233_juiceloader_JuiceLoader_retransformClassByName
|
||||
(JNIEnv* env, jclass loader_class, jstring className, jbyteArray classBytes, jint length) {
|
||||
|
||||
if (!JuiceLoaderNative.jvmti || !className) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
const char* utf = env->GetStringUTFChars(className, nullptr);
|
||||
char internalName[512];
|
||||
strncpy(internalName, utf, sizeof(internalName) - 1);
|
||||
internalName[sizeof(internalName) - 1] = 0;
|
||||
|
||||
for (char* p = internalName; *p; ++p)
|
||||
if (*p == '.') *p = '/';
|
||||
|
||||
env->ReleaseStringUTFChars(className, utf);
|
||||
|
||||
jclass target =
|
||||
findLoadedClassByInternalName(JuiceLoaderNative.jvmti, internalName);
|
||||
|
||||
if (!target) {
|
||||
PLOGE.printf("Class not loaded: %s", internalName);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
return Java_cn_xiaozhou233_juiceloader_JuiceLoader_retransformClass(
|
||||
env, loader_class, target, classBytes, length
|
||||
);
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
#include <jni_impl.h>
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_cn_xiaozhou233_juiceloader_JuiceLoader_nativeGetThreadByName
|
||||
(JNIEnv* env, jclass, jstring jName)
|
||||
{
|
||||
// Convert jstring to std::string
|
||||
const char* cName = env->GetStringUTFChars(jName, nullptr);
|
||||
std::string targetName = cName;
|
||||
env->ReleaseStringUTFChars(jName, cName);
|
||||
|
||||
// Thread class
|
||||
jclass threadClass = env->FindClass("java/lang/Thread");
|
||||
|
||||
// Call Thread.getAllStackTraces(), signature: ()Ljava/util/Map;
|
||||
jmethodID midGetAll = env->GetStaticMethodID(
|
||||
threadClass,
|
||||
"getAllStackTraces",
|
||||
"()Ljava/util/Map;"
|
||||
);
|
||||
|
||||
jobject mapObj = env->CallStaticObjectMethod(threadClass, midGetAll);
|
||||
|
||||
// Map.keySet() -> Set
|
||||
jclass mapClass = env->FindClass("java/util/Map");
|
||||
jmethodID midKeySet = env->GetMethodID(
|
||||
mapClass,
|
||||
"keySet",
|
||||
"()Ljava/util/Set;"
|
||||
);
|
||||
jobject setObj = env->CallObjectMethod(mapObj, midKeySet);
|
||||
|
||||
// Set.iterator() -> Iterator
|
||||
jclass setClass = env->FindClass("java/util/Set");
|
||||
jmethodID midIterator = env->GetMethodID(
|
||||
setClass,
|
||||
"iterator",
|
||||
"()Ljava/util/Iterator;"
|
||||
);
|
||||
jobject iteratorObj = env->CallObjectMethod(setObj, midIterator);
|
||||
|
||||
// Iterator.hasNext() / next()
|
||||
jclass iteratorClass = env->FindClass("java/util/Iterator");
|
||||
jmethodID midHasNext = env->GetMethodID(iteratorClass, "hasNext", "()Z");
|
||||
jmethodID midNext = env->GetMethodID(iteratorClass, "next", "()Ljava/lang/Object;");
|
||||
|
||||
// Thread.getName()
|
||||
jmethodID midGetName = env->GetMethodID(threadClass, "getName", "()Ljava/lang/String;");
|
||||
|
||||
while (env->CallBooleanMethod(iteratorObj, midHasNext)) {
|
||||
jobject threadObj = env->CallObjectMethod(iteratorObj, midNext);
|
||||
jstring jThreadName = (jstring)env->CallObjectMethod(threadObj, midGetName);
|
||||
|
||||
const char* cThreadName = env->GetStringUTFChars(jThreadName, nullptr);
|
||||
bool match = (targetName == cThreadName);
|
||||
env->ReleaseStringUTFChars(jThreadName, cThreadName);
|
||||
|
||||
if (match) {
|
||||
return threadObj; // Found target
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr; // Not found
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
// JVM
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <juiceloader.h>
|
||||
#include <jni_impl.h>
|
||||
|
||||
JuiceLoaderNativeType JuiceLoaderNative;
|
||||
|
||||
static int ConfigureJVMTI(JNIEnv *env, _jvmtiEnv *jvmti) {
|
||||
// Retransform Class Cache : to store classes that need to be retransformed
|
||||
RetransformClassCache.arr = NULL;
|
||||
RetransformClassCache.size = 0;
|
||||
RetransformClassCache.capacity = 0;
|
||||
|
||||
// Application ability
|
||||
jvmtiCapabilities caps;
|
||||
memset(&caps, 0, sizeof(caps));
|
||||
caps.can_get_bytecodes = 1;
|
||||
caps.can_redefine_classes = 1;
|
||||
caps.can_redefine_any_class = 1;
|
||||
caps.can_retransform_classes = 1;
|
||||
caps.can_retransform_any_class = 1;
|
||||
caps.can_generate_all_class_hook_events = 1;
|
||||
jint result = jvmti->AddCapabilities(&caps);
|
||||
if (result != JNI_OK) {
|
||||
PLOGE << "Failed to add capabilities: " << result;
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
// Register callbacks
|
||||
jvmtiEventCallbacks callbacks;
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.ClassFileLoadHook = &ClassFileLoadHook;
|
||||
jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
|
||||
|
||||
// Enable events
|
||||
jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL);
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport)
|
||||
int InitJuiceLoader(JNIEnv *env, _jvmtiEnv *jvmti) {
|
||||
InitLogger();
|
||||
// Step 1: Check if env/jvmti is null
|
||||
PLOGD.printf("env: %p, jvmti: %p", env, jvmti);
|
||||
if (env == nullptr) {
|
||||
PLOGE.printf("[-] Failed to initialize libjuiceloader: env is null");
|
||||
return -1;
|
||||
}
|
||||
if (jvmti == nullptr) {
|
||||
PLOGE.printf("[-] Failed to initialize libjuiceloader: jvmti is null");
|
||||
return -1;
|
||||
}
|
||||
JuiceLoaderNative.jvmti = jvmti;
|
||||
|
||||
|
||||
// Step 2: Configure JVMTI
|
||||
if (ConfigureJVMTI(env, jvmti) != JNI_OK) {
|
||||
PLOGE.printf("[-] Failed to initialize libjuiceloader: ConfigureJVMTI failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
file(GLOB_RECURSE loader_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/*.c
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
message(STATUS "Detected System: Windows")
|
||||
|
||||
file(GLOB_RECURSE windows_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows/*.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows/*.c
|
||||
)
|
||||
|
||||
list(APPEND loader_sources ${windows_sources})
|
||||
endif()
|
||||
|
||||
add_library(loader SHARED ${loader_sources})
|
||||
|
||||
target_include_directories(loader PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/includes
|
||||
${CMAKE_SOURCE_DIR}/includes/jvm
|
||||
${CMAKE_SOURCE_DIR}/includes/jvm/win32
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/includes
|
||||
)
|
||||
|
||||
target_link_libraries(loader PRIVATE
|
||||
ReflectiveDLLInjection
|
||||
jvm
|
||||
)
|
||||
@@ -0,0 +1,152 @@
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <Loader.hpp>
|
||||
#include <JuiceAgent/Config.hpp>
|
||||
#include <JvmManager.hpp>
|
||||
#include <JuiceAgent/Utils.hpp>
|
||||
#include <JuiceAgent/JuiceAgent-API-1.4.1+build.1.hpp>
|
||||
|
||||
namespace JuiceAgent::Loader {
|
||||
|
||||
// Invoke JuiceAgentBootstrap.start(String) via JNI
|
||||
bool invoke_juiceagent_init(JNIEnv* env, const LoaderConfig& config) {
|
||||
const char* bootstrap_class = "cn/xiaozhou233/juiceagent/api/JuiceAgentBootstrap";
|
||||
const char* method_name = "start";
|
||||
const char* method_desc = "(Ljava/lang/String;)V";
|
||||
|
||||
// Find Java class
|
||||
LocalRef<jclass> cls(env, env->FindClass(bootstrap_class));
|
||||
if (!cls.get() || check_and_clear_exception(env, "FindClass")) {
|
||||
PLOGE << "Failed to find class: " << bootstrap_class;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find static method
|
||||
jmethodID method_id = env->GetStaticMethodID(cls, method_name, method_desc);
|
||||
if (!method_id || check_and_clear_exception(env, "GetStaticMethodID")) {
|
||||
PLOGE << "Failed to find method: " << method_name;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Serialize InjectionInfo to string
|
||||
std::string args = JuiceAgent::Config::Utils::serialize_loader_config(config);
|
||||
PLOGD << "Invoke args: " << args;
|
||||
|
||||
// Create Java string
|
||||
jstring jArgs = env->NewStringUTF(args.c_str());
|
||||
if (!jArgs || check_and_clear_exception(env, "NewStringUTF")) {
|
||||
PLOGE << "Failed to create jstring";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Call the static method
|
||||
env->CallStaticVoidMethod(cls, method_id, jArgs);
|
||||
|
||||
// Check for exceptions
|
||||
if (check_and_clear_exception(env, "CallStaticVoidMethod")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PLOGI << "JuiceAgentBootstrap.start invoked successfully";
|
||||
return true;
|
||||
}
|
||||
|
||||
static void init(const char* runtime_dir, JNIEnv * env, jvmtiEnv* jvmti) {
|
||||
if (!runtime_dir) {
|
||||
PLOGW << "runtime_dir is null, using empty path";
|
||||
}
|
||||
|
||||
// Load configuration
|
||||
JuiceAgent::Config::Config cfg(runtime_dir);
|
||||
if (!cfg.is_valid()) {
|
||||
PLOGW << "Invalid config, using default values";
|
||||
|
||||
// TODO: Use default values
|
||||
// Before impl TODO, must return, or crash will happen
|
||||
return;
|
||||
}
|
||||
|
||||
// Get InjectionInfo
|
||||
LoaderConfig config = JuiceAgent::Config::Utils::get_loader_config(cfg);
|
||||
JuiceAgent::Config::Utils::print_loader_config(config);
|
||||
|
||||
// Save bytes to file
|
||||
std::string hash =
|
||||
JuiceAgent::Resource::juiceagent_api_bytes_sha256;
|
||||
|
||||
std::string file_name =
|
||||
hash.substr(0, 8) + "_" +
|
||||
JuiceAgent::Resource::juiceagent_api_bytes_name;
|
||||
|
||||
std::string juiceagent_api_path =
|
||||
JuiceAgent::Utils::File::write_to_tempfile(
|
||||
JuiceAgent::Resource::juiceagent_api_bytes,
|
||||
JuiceAgent::Resource::juiceagent_api_bytes_len,
|
||||
file_name
|
||||
);
|
||||
|
||||
PLOGD << "Saved JuiceAgent-API to: " << juiceagent_api_path;
|
||||
PLOGD << "JuiceAgent-API size: " << JuiceAgent::Resource::juiceagent_api_bytes_len;
|
||||
PLOGD << "JuiceAgent-API SHA256: " << JuiceAgent::Resource::juiceagent_api_bytes_sha256;
|
||||
|
||||
// Inject JuiceAgent jar into system class loader
|
||||
jint status = jvmti->AddToSystemClassLoaderSearch(juiceagent_api_path.c_str());
|
||||
if (status != JNI_OK) {
|
||||
PLOGE << "AddToSystemClassLoaderSearch failed: " << status;
|
||||
return;
|
||||
}
|
||||
|
||||
PLOGI << "Jar injected successfully: " << juiceagent_api_path;
|
||||
|
||||
// Invoke JuiceAgent initialization
|
||||
if (!invoke_juiceagent_init(env, config)) {
|
||||
PLOGE << "invoke_juiceagent_init failed";
|
||||
}
|
||||
}
|
||||
|
||||
// Entrypoint function for loader
|
||||
void entrypoint(const char* runtime_dir) {
|
||||
// Attach to JVM
|
||||
JuiceAgent::Loader::JvmManager::Jvm jvm;
|
||||
if (!jvm.attach()) {
|
||||
PLOGE << "Attach to JVM failed";
|
||||
return;
|
||||
}
|
||||
|
||||
JNIEnv* env = jvm.get_env();
|
||||
auto* jvmti = jvm.get_jvmti();
|
||||
|
||||
if (!env || !jvmti) {
|
||||
PLOGE << "JNIEnv or JVMTI is null";
|
||||
return;
|
||||
}
|
||||
|
||||
// Init JuiceAgent
|
||||
init(runtime_dir, env, jvmti);
|
||||
}
|
||||
|
||||
void entrypoint_with_env(const char* runtime_dir, JNIEnv* env) {
|
||||
JavaVM* jvm = nullptr;
|
||||
jvmtiEnv* jvmti = nullptr;
|
||||
|
||||
env->GetJavaVM(&jvm);
|
||||
|
||||
if (!jvm) {
|
||||
PLOGE << "Failed to get JavaVM";
|
||||
return;
|
||||
}
|
||||
|
||||
jint result = jvm->GetEnv(
|
||||
reinterpret_cast<void**>(&jvmti),
|
||||
JVMTI_VERSION_1_2
|
||||
);
|
||||
|
||||
if (result != JNI_OK || !jvmti) {
|
||||
PLOGE << "Failed to get JVMTI environment";
|
||||
return;
|
||||
}
|
||||
|
||||
PLOGI << "Successfully acquired JVMTI";
|
||||
|
||||
init(runtime_dir, env, jvmti);
|
||||
}
|
||||
} // namespace JuiceAgent::Loader
|
||||
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <jvm/jni.h>
|
||||
#include <jvm/jvmti.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
namespace JuiceAgent::Loader::JvmManager
|
||||
{
|
||||
class Jvm {
|
||||
private:
|
||||
JavaVM* jvm = nullptr;
|
||||
jvmtiEnv* jvmti = nullptr;
|
||||
|
||||
thread_local static JNIEnv* env;
|
||||
|
||||
bool attached = false;
|
||||
int max_try = 30;
|
||||
|
||||
public:
|
||||
Jvm() = default;
|
||||
|
||||
~Jvm() = default;
|
||||
|
||||
JavaVM* get_jvm() const { return jvm; }
|
||||
JNIEnv* get_env() const { return env; }
|
||||
jvmtiEnv* get_jvmti() const { return jvmti; }
|
||||
|
||||
bool attach() {
|
||||
// reset state
|
||||
jvm = nullptr;
|
||||
jvmti = nullptr;
|
||||
env = nullptr;
|
||||
attached = false;
|
||||
|
||||
jint status = JNI_ERR;
|
||||
|
||||
// ======== Get JavaVM ========
|
||||
for (int i = 0; i < max_try; i++) {
|
||||
status = JNI_GetCreatedJavaVMs(&jvm, 1, nullptr);
|
||||
|
||||
if (status == JNI_OK && jvm != nullptr) {
|
||||
PLOGI << "Got JavaVM";
|
||||
break;
|
||||
}
|
||||
|
||||
PLOGE << "Failed to get JavaVM: " << status;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
if (!jvm) {
|
||||
PLOGF << "JavaVM not found!";
|
||||
return false;
|
||||
}
|
||||
|
||||
// ======== Get JNIEnv ========
|
||||
for (int i = 0; i < max_try; i++) {
|
||||
status = jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
|
||||
|
||||
if (status == JNI_OK && env != nullptr) {
|
||||
PLOGI << "Got JNIEnv (already attached)";
|
||||
break;
|
||||
}
|
||||
|
||||
// try attach
|
||||
status = jvm->AttachCurrentThread((void**)&env, nullptr);
|
||||
if (status == JNI_OK && env != nullptr) {
|
||||
attached = true;
|
||||
PLOGI << "Attached current thread";
|
||||
break;
|
||||
}
|
||||
|
||||
PLOGE << "Attach failed: " << status;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
if (!env) {
|
||||
PLOGF << "Failed to get JNIEnv";
|
||||
return false;
|
||||
}
|
||||
|
||||
// ======== Get JVMTI ========
|
||||
for (int i = 0; i < max_try; i++) {
|
||||
status = jvm->GetEnv((void**)&jvmti, JVMTI_VERSION_1_2);
|
||||
|
||||
if (status == JNI_OK && jvmti != nullptr) {
|
||||
PLOGI << "Got JVMTI";
|
||||
break;
|
||||
}
|
||||
|
||||
PLOGE << "Failed to get JVMTI: " << status;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
if (!jvmti) {
|
||||
PLOGF << "Failed to get JVMTI";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool detach() {
|
||||
if (jvm && attached) {
|
||||
jint res = jvm->DetachCurrentThread();
|
||||
if (res != JNI_OK) {
|
||||
PLOGE << "DetachCurrentThread failed: " << res;
|
||||
return false;
|
||||
}
|
||||
|
||||
PLOGI << "Thread detached";
|
||||
attached = false;
|
||||
env = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
thread_local JNIEnv* Jvm::env = nullptr;
|
||||
|
||||
} // namespace JuiceAgent::Loader::JvmManager
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <JuiceAgent/JuiceAgent.hpp>
|
||||
#include <string>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <jvm/jni.h>
|
||||
#include <jvm/jvmti.h>
|
||||
|
||||
namespace JuiceAgent::Loader
|
||||
{
|
||||
void entrypoint(const char* runtime_dir);
|
||||
void entrypoint_with_env(const char* runtime_dir, JNIEnv* env);
|
||||
|
||||
bool invoke_juiceagent_init(JNIEnv* env, const LoaderConfig& info);
|
||||
} // namespace JuiceAgent::Loader
|
||||
|
||||
namespace {
|
||||
// RAII wrapper for local JNI references
|
||||
template<typename T>
|
||||
class LocalRef {
|
||||
private:
|
||||
JNIEnv* env;
|
||||
T ref;
|
||||
public:
|
||||
LocalRef(JNIEnv* env, T ref) : env(env), ref(ref) {}
|
||||
~LocalRef() {
|
||||
if (ref) env->DeleteLocalRef(ref);
|
||||
}
|
||||
T get() const { return ref; }
|
||||
operator T() const { return ref; }
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <windows.h>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <libagent.h>
|
||||
#include <Loader.hpp>
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved ) {
|
||||
switch( fdwReason )
|
||||
@@ -8,12 +8,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved ) {
|
||||
case DLL_PROCESS_ATTACH: {
|
||||
InitLogger();
|
||||
PLOGI << "DllMain: DLL_PROCESS_ATTACH";
|
||||
PLOGD.printf("lpReserved: %p", lpReserved);
|
||||
|
||||
const char* runtime_dir = (const char*)lpReserved;
|
||||
PLOGD << "runtime_dir: " << runtime_dir;
|
||||
|
||||
InitJuiceAgent(runtime_dir);
|
||||
JuiceAgent::Loader::entrypoint(runtime_dir);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -29,7 +27,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved ) {
|
||||
|
||||
case DLL_PROCESS_DETACH: {
|
||||
PLOGI << "DllMain: DLL_PROCESS_DETACH";
|
||||
PLOGD.printf("lpReserved: %p", lpReserved);
|
||||
break;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,4 @@
|
||||
*.h
|
||||
*.hpp
|
||||
JuiceAgent-API*.jar
|
||||
*.class
|
||||
@@ -0,0 +1,327 @@
|
||||
/*
|
||||
* File: file2bytes.cpp
|
||||
* Description:
|
||||
* Converts any file to a C++ byte array header with:
|
||||
* - MIME / type metadata
|
||||
* - SHA-256 hash
|
||||
* - Namespace wrapping
|
||||
*
|
||||
* Build:
|
||||
* g++ -std=c++17 file2bytes.cpp -o file2bytes
|
||||
*
|
||||
* Usage:
|
||||
* file2bytes <input_file> <output.hpp> [var_name] [namespace]
|
||||
*
|
||||
* Example:
|
||||
* file2bytes JuiceRemapper.jar payload.hpp jar_data Resource
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstdint>
|
||||
|
||||
static std::string getFileName(const std::string& path) {
|
||||
std::size_t pos = path.find_last_of("/\\");
|
||||
if (pos == std::string::npos)
|
||||
return path;
|
||||
return path.substr(pos + 1);
|
||||
}
|
||||
|
||||
static std::string getExtension(const std::string& fileName) {
|
||||
std::size_t pos = fileName.find_last_of('.');
|
||||
if (pos == std::string::npos)
|
||||
return "";
|
||||
return fileName.substr(pos + 1);
|
||||
}
|
||||
|
||||
static std::string toLower(std::string s) {
|
||||
for (char& c : s) {
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c = static_cast<char>(c - 'A' + 'a');
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static std::string detectMime(const std::string& fileName) {
|
||||
std::string ext = toLower(getExtension(fileName));
|
||||
|
||||
if (ext == "jar") return "application/java-archive";
|
||||
if (ext == "zip") return "application/zip";
|
||||
if (ext == "json") return "application/json";
|
||||
if (ext == "txt") return "text/plain";
|
||||
if (ext == "xml") return "application/xml";
|
||||
if (ext == "png") return "image/png";
|
||||
if (ext == "jpg" || ext == "jpeg") return "image/jpeg";
|
||||
if (ext == "gif") return "image/gif";
|
||||
if (ext == "dll") return "application/x-msdownload";
|
||||
if (ext == "so") return "application/octet-stream";
|
||||
if (ext == "class") return "application/java-vm";
|
||||
|
||||
return "application/octet-stream";
|
||||
}
|
||||
|
||||
/* =========================
|
||||
Minimal SHA-256
|
||||
Public domain style impl
|
||||
========================= */
|
||||
|
||||
struct SHA256_CTX {
|
||||
uint8_t data[64];
|
||||
uint32_t datalen;
|
||||
uint64_t bitlen;
|
||||
uint32_t state[8];
|
||||
};
|
||||
|
||||
static uint32_t rotr(uint32_t x, uint32_t n) {
|
||||
return (x >> n) | (x << (32 - n));
|
||||
}
|
||||
|
||||
static uint32_t ch(uint32_t x, uint32_t y, uint32_t z) {
|
||||
return (x & y) ^ (~x & z);
|
||||
}
|
||||
|
||||
static uint32_t maj(uint32_t x, uint32_t y, uint32_t z) {
|
||||
return (x & y) ^ (x & z) ^ (y & z);
|
||||
}
|
||||
|
||||
static uint32_t ep0(uint32_t x) {
|
||||
return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
|
||||
}
|
||||
|
||||
static uint32_t ep1(uint32_t x) {
|
||||
return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
|
||||
}
|
||||
|
||||
static uint32_t sig0(uint32_t x) {
|
||||
return rotr(x, 7) ^ rotr(x, 18) ^ (x >> 3);
|
||||
}
|
||||
|
||||
static uint32_t sig1(uint32_t x) {
|
||||
return rotr(x, 17) ^ rotr(x, 19) ^ (x >> 10);
|
||||
}
|
||||
|
||||
static const uint32_t k[64] = {
|
||||
0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,
|
||||
0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
|
||||
0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,
|
||||
0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
|
||||
0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,
|
||||
0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
|
||||
0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,
|
||||
0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
|
||||
0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,
|
||||
0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
|
||||
0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,
|
||||
0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
|
||||
0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,
|
||||
0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
|
||||
0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,
|
||||
0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
|
||||
};
|
||||
|
||||
static void sha256_transform(SHA256_CTX* ctx, const uint8_t data[]) {
|
||||
uint32_t a,b,c,d,e,f,g,h,i,j,t1,t2,m[64];
|
||||
|
||||
for (i = 0, j = 0; i < 16; ++i, j += 4)
|
||||
m[i] = (data[j] << 24) | (data[j+1] << 16) |
|
||||
(data[j+2] << 8) | (data[j+3]);
|
||||
|
||||
for (; i < 64; ++i)
|
||||
m[i] = sig1(m[i-2]) + m[i-7] + sig0(m[i-15]) + m[i-16];
|
||||
|
||||
a = ctx->state[0];
|
||||
b = ctx->state[1];
|
||||
c = ctx->state[2];
|
||||
d = ctx->state[3];
|
||||
e = ctx->state[4];
|
||||
f = ctx->state[5];
|
||||
g = ctx->state[6];
|
||||
h = ctx->state[7];
|
||||
|
||||
for (i = 0; i < 64; ++i) {
|
||||
t1 = h + ep1(e) + ch(e,f,g) + k[i] + m[i];
|
||||
t2 = ep0(a) + maj(a,b,c);
|
||||
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
|
||||
ctx->state[0] += a;
|
||||
ctx->state[1] += b;
|
||||
ctx->state[2] += c;
|
||||
ctx->state[3] += d;
|
||||
ctx->state[4] += e;
|
||||
ctx->state[5] += f;
|
||||
ctx->state[6] += g;
|
||||
ctx->state[7] += h;
|
||||
}
|
||||
|
||||
static void sha256_init(SHA256_CTX* ctx) {
|
||||
ctx->datalen = 0;
|
||||
ctx->bitlen = 0;
|
||||
ctx->state[0] = 0x6a09e667;
|
||||
ctx->state[1] = 0xbb67ae85;
|
||||
ctx->state[2] = 0x3c6ef372;
|
||||
ctx->state[3] = 0xa54ff53a;
|
||||
ctx->state[4] = 0x510e527f;
|
||||
ctx->state[5] = 0x9b05688c;
|
||||
ctx->state[6] = 0x1f83d9ab;
|
||||
ctx->state[7] = 0x5be0cd19;
|
||||
}
|
||||
|
||||
static void sha256_update(SHA256_CTX* ctx, const uint8_t data[], size_t len) {
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
ctx->data[ctx->datalen++] = data[i];
|
||||
if (ctx->datalen == 64) {
|
||||
sha256_transform(ctx, ctx->data);
|
||||
ctx->bitlen += 512;
|
||||
ctx->datalen = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void sha256_final(SHA256_CTX* ctx, uint8_t hash[]) {
|
||||
uint32_t i = ctx->datalen;
|
||||
|
||||
if (ctx->datalen < 56) {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 56) ctx->data[i++] = 0x00;
|
||||
} else {
|
||||
ctx->data[i++] = 0x80;
|
||||
while (i < 64) ctx->data[i++] = 0x00;
|
||||
sha256_transform(ctx, ctx->data);
|
||||
std::fill(ctx->data, ctx->data + 56, 0);
|
||||
}
|
||||
|
||||
ctx->bitlen += ctx->datalen * 8;
|
||||
ctx->data[63] = ctx->bitlen;
|
||||
ctx->data[62] = ctx->bitlen >> 8;
|
||||
ctx->data[61] = ctx->bitlen >> 16;
|
||||
ctx->data[60] = ctx->bitlen >> 24;
|
||||
ctx->data[59] = ctx->bitlen >> 32;
|
||||
ctx->data[58] = ctx->bitlen >> 40;
|
||||
ctx->data[57] = ctx->bitlen >> 48;
|
||||
ctx->data[56] = ctx->bitlen >> 56;
|
||||
sha256_transform(ctx, ctx->data);
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
hash[i] = (ctx->state[0] >> (24 - i * 8)) & 0xff;
|
||||
hash[i + 4] = (ctx->state[1] >> (24 - i * 8)) & 0xff;
|
||||
hash[i + 8] = (ctx->state[2] >> (24 - i * 8)) & 0xff;
|
||||
hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0xff;
|
||||
hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0xff;
|
||||
hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0xff;
|
||||
hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0xff;
|
||||
hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
static std::string sha256Hex(const std::vector<unsigned char>& data) {
|
||||
SHA256_CTX ctx{};
|
||||
sha256_init(&ctx);
|
||||
sha256_update(&ctx, data.data(), data.size());
|
||||
|
||||
uint8_t hash[32];
|
||||
sha256_final(&ctx, hash);
|
||||
|
||||
std::ostringstream oss;
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
oss << std::hex
|
||||
<< std::setw(2)
|
||||
<< std::setfill('0')
|
||||
<< static_cast<int>(hash[i]);
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 3) {
|
||||
std::cout << "Usage: file2bytes <input_file> <output.hpp> [var_name] [namespace]\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* input = argv[1];
|
||||
const char* output = argv[2];
|
||||
|
||||
std::string varName = (argc >= 4) ? argv[3] : "bytes";
|
||||
std::string ns = (argc >= 5) ? argv[4] : "Embedded";
|
||||
|
||||
std::string fileName = getFileName(input);
|
||||
std::string mime = detectMime(fileName);
|
||||
|
||||
std::ifstream in(input, std::ios::binary | std::ios::ate);
|
||||
if (!in) {
|
||||
std::cerr << "Failed to open input file: " << input << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::streamsize size = in.tellg();
|
||||
in.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<unsigned char> data(size);
|
||||
if (!in.read(reinterpret_cast<char*>(data.data()), size)) {
|
||||
std::cerr << "Failed to read file\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string hash = sha256Hex(data);
|
||||
|
||||
std::ofstream out(output, std::ios::binary);
|
||||
if (!out) {
|
||||
std::cerr << "Failed to open output file: " << output << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
out << "#pragma once\n\n";
|
||||
out << "#include <cstddef>\n\n";
|
||||
|
||||
out << "namespace " << ns << " {\n\n";
|
||||
|
||||
out << "static const unsigned char " << varName << "[] = {\n";
|
||||
|
||||
for (std::size_t i = 0; i < data.size(); ++i) {
|
||||
if (i % 12 == 0)
|
||||
out << " ";
|
||||
|
||||
out << "0x"
|
||||
<< std::hex
|
||||
<< std::setw(2)
|
||||
<< std::setfill('0')
|
||||
<< static_cast<int>(data[i]);
|
||||
|
||||
if (i + 1 != data.size())
|
||||
out << ", ";
|
||||
|
||||
if (i % 12 == 11)
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
out << "\n};\n\n";
|
||||
|
||||
out << "static const std::size_t " << varName << "_len = "
|
||||
<< std::dec << data.size() << ";\n";
|
||||
|
||||
out << "static const char* " << varName << "_name = "
|
||||
<< "\"" << fileName << "\";\n";
|
||||
|
||||
out << "static const char* " << varName << "_mime = "
|
||||
<< "\"" << mime << "\";\n";
|
||||
|
||||
out << "static const char* " << varName << "_sha256 = "
|
||||
<< "\"" << hash << "\";\n";
|
||||
|
||||
out << "\n} // namespace " << ns << "\n";
|
||||
|
||||
std::cout << "Generated: " << output << "\n";
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
Reference in new issue
Block a user