mirror of
https://github.com/ttttupup/wxhelper.git
synced 2025-04-29 16:29:52 +08:00
Compare commits
10 Commits
main
...
3.9.7.29-v
Author | SHA1 | Date | |
---|---|---|---|
|
514fd1dff4 | ||
|
6fb7653269 | ||
|
4dcd18db6c | ||
|
06bfc6b7c0 | ||
|
5ccfbc40a4 | ||
|
bede8f7150 | ||
|
1ff56fc055 | ||
|
8ab646be96 | ||
|
2767576351 | ||
|
9f2b0f9925 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -32,4 +32,5 @@
|
|||||||
*.app
|
*.app
|
||||||
CMakePresets.json
|
CMakePresets.json
|
||||||
.vscode
|
.vscode
|
||||||
out
|
out
|
||||||
|
.vs
|
7
.gitmodules
vendored
7
.gitmodules
vendored
@ -1,3 +1,4 @@
|
|||||||
[submodule "spdlog"]
|
[submodule "spdlog"]
|
||||||
path = spdlog
|
path = app/3rdparty/spdlog
|
||||||
url = https://github.com/gabime/spdlog
|
url = https://github.com/gabime/spdlog.git
|
||||||
|
branch = v1.x
|
||||||
|
@ -1,53 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.0)
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
# include(ExternalProject)
|
project(app VERSION 1.0.0)
|
||||||
project(wxhelper VERSION 1.0.0)
|
|
||||||
enable_language(ASM_MASM)
|
|
||||||
|
|
||||||
|
|
||||||
|
add_subdirectory(app)
|
||||||
|
|
||||||
# SET(CMAKE_ASM_NASM_FLAGS "-w0")
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D '_UNICODE' /D 'UNICODE' ")
|
|
||||||
|
|
||||||
file(GLOB CPP_FILES ${PROJECT_SOURCE_DIR}/src/*.cc ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*.c )
|
|
||||||
|
|
||||||
file(GLOB ASM_FILES ${PROJECT_SOURCE_DIR}/src/*.asm )
|
|
||||||
|
|
||||||
include_directories(${VCPKG_INSTALLED_DIR}/x64-windows/include ${PROJECT_SOURCE_DIR}/spdlog/include ${DETOURS_INCLUDE_DIRS})
|
|
||||||
# include_directories(${VCPKG_INSTALLED_DIR}/x64-windows/include ${PROJECT_SOURCE_DIR}/spdlog/include )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_subdirectory(spdlog)
|
|
||||||
add_subdirectory(source)
|
|
||||||
|
|
||||||
# find_package(spdlog CONFIG REQUIRED)
|
|
||||||
|
|
||||||
find_package(nlohmann_json CONFIG REQUIRED)
|
|
||||||
|
|
||||||
find_path(DETOURS_INCLUDE_DIRS "detours/detours.h")
|
|
||||||
find_library(DETOURS_LIBRARY detours REQUIRED)
|
|
||||||
|
|
||||||
|
|
||||||
add_library(wxhelper SHARED ${CPP_FILES} ${ASM_FILES} )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(wxhelper PRIVATE nlohmann_json::nlohmann_json)
|
|
||||||
target_link_libraries(wxhelper PRIVATE spdlog::spdlog spdlog::spdlog_header_only)
|
|
||||||
target_link_libraries(wxhelper PRIVATE ${DETOURS_LIBRARY})
|
|
||||||
|
|
||||||
|
|
||||||
SET_TARGET_PROPERTIES(wxhelper PROPERTIES LINKER_LANGUAGE C
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
|
|
||||||
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
|
|
||||||
OUTPUT_NAME "wxhelper"
|
|
||||||
PREFIX "")
|
|
||||||
|
|
6
app/3rdparty/CMakeLists.txt
vendored
Normal file
6
app/3rdparty/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
|
|
||||||
|
add_subdirectory(base64)
|
||||||
|
add_subdirectory(lz4)
|
||||||
|
add_subdirectory(mongoose)
|
||||||
|
add_subdirectory(spdlog)
|
6
app/3rdparty/base64/CMakeLists.txt
vendored
Normal file
6
app/3rdparty/base64/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
|
aux_source_directory(. BASE64_SOURCE)
|
||||||
|
|
||||||
|
add_library(base64 ${BASE64_SOURCE})
|
||||||
|
|
||||||
|
target_include_directories(base64 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
150
src/base64.cpp → app/3rdparty/base64/base64.cpp
vendored
150
src/base64.cpp → app/3rdparty/base64/base64.cpp
vendored
@ -1,14 +1,13 @@
|
|||||||
#include "pch.h"
|
/*
|
||||||
/*
|
|
||||||
base64.cpp and base64.h
|
base64.cpp and base64.h
|
||||||
|
|
||||||
base64 encoding and decoding with C++.
|
base64 encoding and decoding with C++.
|
||||||
More information at
|
More information at
|
||||||
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
|
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
|
||||||
|
|
||||||
Version: 2.rc.08 (release candidate)
|
Version: 2.rc.09 (release candidate)
|
||||||
|
|
||||||
Copyright (C) 2004-2017, 2020, 2021 Ren<EFBFBD><EFBFBD> Nyffenegger
|
Copyright (C) 2004-2017, 2020-2022 René Nyffenegger
|
||||||
|
|
||||||
This source code is provided 'as-is', without any express or implied
|
This source code is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the author be held liable for any damages
|
warranty. In no event will the author be held liable for any damages
|
||||||
@ -28,7 +27,7 @@
|
|||||||
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
Ren<EFBFBD><EFBFBD> Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -42,33 +41,27 @@
|
|||||||
// two sets of base64 characters needs to be chosen.
|
// two sets of base64 characters needs to be chosen.
|
||||||
// They differ in their last two characters.
|
// They differ in their last two characters.
|
||||||
//
|
//
|
||||||
static const char *base64_chars[2] = {
|
static const char* base64_chars[2] = {
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"0123456789"
|
"0123456789"
|
||||||
"+/",
|
"+/",
|
||||||
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"0123456789"
|
"0123456789"
|
||||||
"-_"};
|
"-_" };
|
||||||
|
|
||||||
static unsigned int pos_of_char(const unsigned char chr)
|
static unsigned int pos_of_char(const unsigned char chr) {
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// Return the position of chr within base64_encode()
|
// Return the position of chr within base64_encode()
|
||||||
//
|
//
|
||||||
|
|
||||||
if (chr >= 'A' && chr <= 'Z')
|
if (chr >= 'A' && chr <= 'Z') return chr - 'A';
|
||||||
return chr - 'A';
|
else if (chr >= 'a' && chr <= 'z') return chr - 'a' + ('Z' - 'A') + 1;
|
||||||
else if (chr >= 'a' && chr <= 'z')
|
else if (chr >= '0' && chr <= '9') return chr - '0' + ('Z' - 'A') + ('z' - 'a') + 2;
|
||||||
return chr - 'a' + ('Z' - 'A') + 1;
|
else if (chr == '+' || chr == '-') return 62; // Be liberal with input and accept both url ('-') and non-url ('+') base 64 characters (
|
||||||
else if (chr >= '0' && chr <= '9')
|
else if (chr == '/' || chr == '_') return 63; // Ditto for '/' and '_'
|
||||||
return chr - '0' + ('Z' - 'A') + ('z' - 'a') + 2;
|
|
||||||
else if (chr == '+' || chr == '-')
|
|
||||||
return 62; // Be liberal with input and accept both url ('-') and non-url ('+') base 64 characters (
|
|
||||||
else if (chr == '/' || chr == '_')
|
|
||||||
return 63; // Ditto for '/' and '_'
|
|
||||||
else
|
else
|
||||||
//
|
//
|
||||||
// 2020-10-23: Throw std::exception rather than const char*
|
// 2020-10-23: Throw std::exception rather than const char*
|
||||||
@ -77,20 +70,17 @@ static unsigned int pos_of_char(const unsigned char chr)
|
|||||||
throw std::runtime_error("Input is not valid base64-encoded data.");
|
throw std::runtime_error("Input is not valid base64-encoded data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string insert_linebreaks(std::string str, size_t distance)
|
static std::string insert_linebreaks(std::string str, size_t distance) {
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// Provided by https://github.com/JomaCorpFX, adapted by me.
|
// Provided by https://github.com/JomaCorpFX, adapted by me.
|
||||||
//
|
//
|
||||||
if (!str.length())
|
if (!str.length()) {
|
||||||
{
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pos = distance;
|
size_t pos = distance;
|
||||||
|
|
||||||
while (pos < str.size())
|
while (pos < str.size()) {
|
||||||
{
|
|
||||||
str.insert(pos, "\n");
|
str.insert(pos, "\n");
|
||||||
pos += distance + 1;
|
pos += distance + 1;
|
||||||
}
|
}
|
||||||
@ -99,31 +89,26 @@ static std::string insert_linebreaks(std::string str, size_t distance)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename String, unsigned int line_length>
|
template <typename String, unsigned int line_length>
|
||||||
static std::string encode_with_line_breaks(String s)
|
static std::string encode_with_line_breaks(String s) {
|
||||||
{
|
|
||||||
return insert_linebreaks(base64_encode(s, false), line_length);
|
return insert_linebreaks(base64_encode(s, false), line_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename String>
|
template <typename String>
|
||||||
static std::string encode_pem(String s)
|
static std::string encode_pem(String s) {
|
||||||
{
|
|
||||||
return encode_with_line_breaks<String, 64>(s);
|
return encode_with_line_breaks<String, 64>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename String>
|
template <typename String>
|
||||||
static std::string encode_mime(String s)
|
static std::string encode_mime(String s) {
|
||||||
{
|
|
||||||
return encode_with_line_breaks<String, 76>(s);
|
return encode_with_line_breaks<String, 76>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename String>
|
template <typename String>
|
||||||
static std::string encode(String s, bool url)
|
static std::string encode(String s, bool url) {
|
||||||
{
|
return base64_encode(reinterpret_cast<const unsigned char*>(s.data()), s.length(), url);
|
||||||
return base64_encode(reinterpret_cast<const unsigned char *>(s.data()), s.length(), url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_encode(unsigned char const *bytes_to_encode, size_t in_len, bool url)
|
std::string base64_encode(unsigned char const* bytes_to_encode, size_t in_len, bool url) {
|
||||||
{
|
|
||||||
|
|
||||||
size_t len_encoded = (in_len + 2) / 3 * 4;
|
size_t len_encoded = (in_len + 2) / 3 * 4;
|
||||||
|
|
||||||
@ -138,34 +123,29 @@ std::string base64_encode(unsigned char const *bytes_to_encode, size_t in_len, b
|
|||||||
// the correct character set is chosen by subscripting
|
// the correct character set is chosen by subscripting
|
||||||
// base64_chars with url.
|
// base64_chars with url.
|
||||||
//
|
//
|
||||||
const char *base64_chars_ = base64_chars[url];
|
const char* base64_chars_ = base64_chars[url];
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ret.reserve(len_encoded);
|
ret.reserve(len_encoded);
|
||||||
|
|
||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
|
|
||||||
while (pos < in_len)
|
while (pos < in_len) {
|
||||||
{
|
|
||||||
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0xfc) >> 2]);
|
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0xfc) >> 2]);
|
||||||
|
|
||||||
if (pos + 1 < in_len)
|
if (pos + 1 < in_len) {
|
||||||
{
|
|
||||||
ret.push_back(base64_chars_[((bytes_to_encode[pos + 0] & 0x03) << 4) + ((bytes_to_encode[pos + 1] & 0xf0) >> 4)]);
|
ret.push_back(base64_chars_[((bytes_to_encode[pos + 0] & 0x03) << 4) + ((bytes_to_encode[pos + 1] & 0xf0) >> 4)]);
|
||||||
|
|
||||||
if (pos + 2 < in_len)
|
if (pos + 2 < in_len) {
|
||||||
{
|
|
||||||
ret.push_back(base64_chars_[((bytes_to_encode[pos + 1] & 0x0f) << 2) + ((bytes_to_encode[pos + 2] & 0xc0) >> 6)]);
|
ret.push_back(base64_chars_[((bytes_to_encode[pos + 1] & 0x0f) << 2) + ((bytes_to_encode[pos + 2] & 0xc0) >> 6)]);
|
||||||
ret.push_back(base64_chars_[bytes_to_encode[pos + 2] & 0x3f]);
|
ret.push_back(base64_chars_[bytes_to_encode[pos + 2] & 0x3f]);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
ret.push_back(base64_chars_[(bytes_to_encode[pos + 1] & 0x0f) << 2]);
|
ret.push_back(base64_chars_[(bytes_to_encode[pos + 1] & 0x0f) << 2]);
|
||||||
ret.push_back(trailing_char);
|
ret.push_back(trailing_char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
|
|
||||||
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0x03) << 4]);
|
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0x03) << 4]);
|
||||||
ret.push_back(trailing_char);
|
ret.push_back(trailing_char);
|
||||||
@ -175,22 +155,20 @@ std::string base64_encode(unsigned char const *bytes_to_encode, size_t in_len, b
|
|||||||
pos += 3;
|
pos += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename String>
|
template <typename String>
|
||||||
static std::string decode(String encoded_string, bool remove_linebreaks)
|
static std::string decode(String const& encoded_string, bool remove_linebreaks) {
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// decode(<EFBFBD><EFBFBD>) is templated so that it can be used with String = const std::string&
|
// decode(…) is templated so that it can be used with String = const std::string&
|
||||||
// or std::string_view (requires at least C++17)
|
// or std::string_view (requires at least C++17)
|
||||||
//
|
//
|
||||||
|
|
||||||
if (encoded_string.empty())
|
if (encoded_string.empty()) return std::string();
|
||||||
return std::string();
|
|
||||||
|
|
||||||
if (remove_linebreaks)
|
if (remove_linebreaks) {
|
||||||
{
|
|
||||||
|
|
||||||
std::string copy(encoded_string);
|
std::string copy(encoded_string);
|
||||||
|
|
||||||
@ -212,8 +190,7 @@ static std::string decode(String encoded_string, bool remove_linebreaks)
|
|||||||
std::string ret;
|
std::string ret;
|
||||||
ret.reserve(approx_length_of_decoded_string);
|
ret.reserve(approx_length_of_decoded_string);
|
||||||
|
|
||||||
while (pos < length_of_string)
|
while (pos < length_of_string) {
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// Iterate over encoded input string in chunks. The size of all
|
// Iterate over encoded input string in chunks. The size of all
|
||||||
// chunks except the last one is 4 bytes.
|
// chunks except the last one is 4 bytes.
|
||||||
@ -227,32 +204,33 @@ static std::string decode(String encoded_string, bool remove_linebreaks)
|
|||||||
// The last chunk produces at least one and up to three bytes.
|
// The last chunk produces at least one and up to three bytes.
|
||||||
//
|
//
|
||||||
|
|
||||||
size_t pos_of_char_1 = pos_of_char(encoded_string[pos + 1]);
|
size_t pos_of_char_1 = pos_of_char(encoded_string.at(pos + 1));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Emit the first output byte that is produced in each chunk:
|
// Emit the first output byte that is produced in each chunk:
|
||||||
//
|
//
|
||||||
ret.push_back(static_cast<std::string::value_type>(((pos_of_char(encoded_string[pos + 0])) << 2) + ((pos_of_char_1 & 0x30) >> 4)));
|
ret.push_back(static_cast<std::string::value_type>(((pos_of_char(encoded_string.at(pos + 0))) << 2) + ((pos_of_char_1 & 0x30) >> 4)));
|
||||||
|
|
||||||
if ((pos + 2 < length_of_string) && // Check for data that is not padded with equal signs (which is allowed by RFC 2045)
|
if ((pos + 2 < length_of_string) && // Check for data that is not padded with equal signs (which is allowed by RFC 2045)
|
||||||
encoded_string[pos + 2] != '=' &&
|
encoded_string.at(pos + 2) != '=' &&
|
||||||
encoded_string[pos + 2] != '.' // accept URL-safe base 64 strings, too, so check for '.' also.
|
encoded_string.at(pos + 2) != '.' // accept URL-safe base 64 strings, too, so check for '.' also.
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Emit a chunk's second byte (which might not be produced in the last chunk).
|
// Emit a chunk's second byte (which might not be produced in the last chunk).
|
||||||
//
|
//
|
||||||
unsigned int pos_of_char_2 = pos_of_char(encoded_string[pos + 2]);
|
unsigned int pos_of_char_2 = pos_of_char(encoded_string.at(pos + 2));
|
||||||
ret.push_back(static_cast<std::string::value_type>(((pos_of_char_1 & 0x0f) << 4) + ((pos_of_char_2 & 0x3c) >> 2)));
|
ret.push_back(static_cast<std::string::value_type>(((pos_of_char_1 & 0x0f) << 4) + ((pos_of_char_2 & 0x3c) >> 2)));
|
||||||
|
|
||||||
if ((pos + 3 < length_of_string) &&
|
if ((pos + 3 < length_of_string) &&
|
||||||
encoded_string[pos + 3] != '=' &&
|
encoded_string.at(pos + 3) != '=' &&
|
||||||
encoded_string[pos + 3] != '.')
|
encoded_string.at(pos + 3) != '.'
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Emit a chunk's third byte (which might not be produced in the last chunk).
|
// Emit a chunk's third byte (which might not be produced in the last chunk).
|
||||||
//
|
//
|
||||||
ret.push_back(static_cast<std::string::value_type>(((pos_of_char_2 & 0x03) << 6) + pos_of_char(encoded_string[pos + 3])));
|
ret.push_back(static_cast<std::string::value_type>(((pos_of_char_2 & 0x03) << 6) + pos_of_char(encoded_string.at(pos + 3))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,23 +240,19 @@ static std::string decode(String encoded_string, bool remove_linebreaks)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_decode(std::string const &s, bool remove_linebreaks)
|
std::string base64_decode(std::string const& s, bool remove_linebreaks) {
|
||||||
{
|
|
||||||
return decode(s, remove_linebreaks);
|
return decode(s, remove_linebreaks);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_encode(std::string const &s, bool url)
|
std::string base64_encode(std::string const& s, bool url) {
|
||||||
{
|
|
||||||
return encode(s, url);
|
return encode(s, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_encode_pem(std::string const &s)
|
std::string base64_encode_pem(std::string const& s) {
|
||||||
{
|
|
||||||
return encode_pem(s);
|
return encode_pem(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_encode_mime(std::string const &s)
|
std::string base64_encode_mime(std::string const& s) {
|
||||||
{
|
|
||||||
return encode_mime(s);
|
return encode_mime(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,24 +263,20 @@ std::string base64_encode_mime(std::string const &s)
|
|||||||
// Provided by Yannic Bonenberger (https://github.com/Yannic)
|
// Provided by Yannic Bonenberger (https://github.com/Yannic)
|
||||||
//
|
//
|
||||||
|
|
||||||
std::string base64_encode(std::string_view s, bool url)
|
std::string base64_encode(std::string_view s, bool url) {
|
||||||
{
|
|
||||||
return encode(s, url);
|
return encode(s, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_encode_pem(std::string_view s)
|
std::string base64_encode_pem(std::string_view s) {
|
||||||
{
|
|
||||||
return encode_pem(s);
|
return encode_pem(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_encode_mime(std::string_view s)
|
std::string base64_encode_mime(std::string_view s) {
|
||||||
{
|
|
||||||
return encode_mime(s);
|
return encode_mime(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string base64_decode(std::string_view s, bool remove_linebreaks)
|
std::string base64_decode(std::string_view s, bool remove_linebreaks) {
|
||||||
{
|
|
||||||
return decode(s, remove_linebreaks);
|
return decode(s, remove_linebreaks);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __cplusplus >= 201703L
|
#endif // __cplusplus >= 201703L
|
22
src/base64.h → app/3rdparty/base64/base64.h
vendored
22
src/base64.h → app/3rdparty/base64/base64.h
vendored
@ -1,8 +1,8 @@
|
|||||||
//
|
|
||||||
// base64 encoding and decoding with C++.
|
|
||||||
// Version: 2.rc.08 (release candidate)
|
|
||||||
//
|
//
|
||||||
#pragma once
|
// base64 encoding and decoding with C++.
|
||||||
|
// Version: 2.rc.09 (release candidate)
|
||||||
|
//
|
||||||
|
|
||||||
#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
|
#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
|
||||||
#define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
|
#define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
|
||||||
|
|
||||||
@ -10,14 +10,14 @@
|
|||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#endif // __cplusplus >= 201703L
|
#endif // __cplusplus >= 201703L
|
||||||
|
|
||||||
std::string base64_encode(std::string const &s, bool url = false);
|
std::string base64_encode(std::string const& s, bool url = false);
|
||||||
std::string base64_encode_pem(std::string const &s);
|
std::string base64_encode_pem(std::string const& s);
|
||||||
std::string base64_encode_mime(std::string const &s);
|
std::string base64_encode_mime(std::string const& s);
|
||||||
|
|
||||||
std::string base64_decode(std::string const &s, bool remove_linebreaks = false);
|
std::string base64_decode(std::string const& s, bool remove_linebreaks = false);
|
||||||
std::string base64_encode(unsigned char const *, size_t len, bool url = false);
|
std::string base64_encode(unsigned char const*, size_t len, bool url = false);
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
//
|
//
|
||||||
@ -30,6 +30,6 @@ std::string base64_encode_pem(std::string_view s);
|
|||||||
std::string base64_encode_mime(std::string_view s);
|
std::string base64_encode_mime(std::string_view s);
|
||||||
|
|
||||||
std::string base64_decode(std::string_view s, bool remove_linebreaks = false);
|
std::string base64_decode(std::string_view s, bool remove_linebreaks = false);
|
||||||
#endif // __cplusplus >= 201703L
|
#endif // __cplusplus >= 201703L
|
||||||
|
|
||||||
#endif /* BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A */
|
#endif /* BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A */
|
6
app/3rdparty/lz4/CMakeLists.txt
vendored
Normal file
6
app/3rdparty/lz4/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
|
aux_source_directory(. LZ4_SOURCE)
|
||||||
|
|
||||||
|
add_library(lz4 ${LZ4_SOURCE})
|
||||||
|
|
||||||
|
target_include_directories(lz4 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
1986
src/lz4.c → app/3rdparty/lz4/lz4.c
vendored
1986
src/lz4.c → app/3rdparty/lz4/lz4.c
vendored
File diff suppressed because it is too large
Load Diff
862
app/3rdparty/lz4/lz4.h
vendored
Normal file
862
app/3rdparty/lz4/lz4.h
vendored
Normal file
@ -0,0 +1,862 @@
|
|||||||
|
/*
|
||||||
|
* LZ4 - Fast LZ compression algorithm
|
||||||
|
* Header File
|
||||||
|
* Copyright (C) 2011-2020, Yann Collet.
|
||||||
|
|
||||||
|
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
|
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
|
||||||
|
OWNER 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.
|
||||||
|
|
||||||
|
You can contact the author at :
|
||||||
|
- LZ4 homepage : http://www.lz4.org
|
||||||
|
- LZ4 source repository : https://github.com/lz4/lz4
|
||||||
|
*/
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LZ4_H_2983827168210
|
||||||
|
#define LZ4_H_2983827168210
|
||||||
|
|
||||||
|
/* --- Dependency --- */
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Introduction
|
||||||
|
|
||||||
|
LZ4 is lossless compression algorithm, providing compression speed >500 MB/s per core,
|
||||||
|
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
||||||
|
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
||||||
|
|
||||||
|
The LZ4 compression library provides in-memory compression and decompression functions.
|
||||||
|
It gives full buffer control to user.
|
||||||
|
Compression can be done in:
|
||||||
|
- a single step (described as Simple Functions)
|
||||||
|
- a single step, reusing a context (described in Advanced Functions)
|
||||||
|
- unbounded multiple steps (described as Streaming compression)
|
||||||
|
|
||||||
|
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
||||||
|
Decompressing such a compressed block requires additional metadata.
|
||||||
|
Exact metadata depends on exact decompression function.
|
||||||
|
For the typical case of LZ4_decompress_safe(),
|
||||||
|
metadata includes block's compressed size, and maximum bound of decompressed size.
|
||||||
|
Each application is free to encode and pass such metadata in whichever way it wants.
|
||||||
|
|
||||||
|
lz4.h only handle blocks, it can not generate Frames.
|
||||||
|
|
||||||
|
Blocks are different from Frames (doc/lz4_Frame_format.md).
|
||||||
|
Frames bundle both blocks and metadata in a specified manner.
|
||||||
|
Embedding metadata is required for compressed data to be self-contained and portable.
|
||||||
|
Frame format is delivered through a companion API, declared in lz4frame.h.
|
||||||
|
The `lz4` CLI can only manage frames.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*^***************************************************************
|
||||||
|
* Export parameters
|
||||||
|
*****************************************************************/
|
||||||
|
/*
|
||||||
|
* LZ4_DLL_EXPORT :
|
||||||
|
* Enable exporting of functions when building a Windows DLL
|
||||||
|
* LZ4LIB_VISIBILITY :
|
||||||
|
* Control library symbols visibility.
|
||||||
|
*/
|
||||||
|
#ifndef LZ4LIB_VISIBILITY
|
||||||
|
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
# define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
|
||||||
|
# else
|
||||||
|
# define LZ4LIB_VISIBILITY
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
|
||||||
|
# define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
|
||||||
|
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
|
||||||
|
# define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||||
|
#else
|
||||||
|
# define LZ4LIB_API LZ4LIB_VISIBILITY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! LZ4_FREESTANDING :
|
||||||
|
* When this macro is set to 1, it enables "freestanding mode" that is
|
||||||
|
* suitable for typical freestanding environment which doesn't support
|
||||||
|
* standard C library.
|
||||||
|
*
|
||||||
|
* - LZ4_FREESTANDING is a compile-time switch.
|
||||||
|
* - It requires the following macros to be defined:
|
||||||
|
* LZ4_memcpy, LZ4_memmove, LZ4_memset.
|
||||||
|
* - It only enables LZ4/HC functions which don't use heap.
|
||||||
|
* All LZ4F_* functions are not supported.
|
||||||
|
* - See tests/freestanding.c to check its basic setup.
|
||||||
|
*/
|
||||||
|
#if defined(LZ4_FREESTANDING) && (LZ4_FREESTANDING == 1)
|
||||||
|
# define LZ4_HEAPMODE 0
|
||||||
|
# define LZ4HC_HEAPMODE 0
|
||||||
|
# define LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION 1
|
||||||
|
# if !defined(LZ4_memcpy)
|
||||||
|
# error "LZ4_FREESTANDING requires macro 'LZ4_memcpy'."
|
||||||
|
# endif
|
||||||
|
# if !defined(LZ4_memset)
|
||||||
|
# error "LZ4_FREESTANDING requires macro 'LZ4_memset'."
|
||||||
|
# endif
|
||||||
|
# if !defined(LZ4_memmove)
|
||||||
|
# error "LZ4_FREESTANDING requires macro 'LZ4_memmove'."
|
||||||
|
# endif
|
||||||
|
#elif ! defined(LZ4_FREESTANDING)
|
||||||
|
# define LZ4_FREESTANDING 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*------ Version ------*/
|
||||||
|
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
|
||||||
|
#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
|
||||||
|
#define LZ4_VERSION_RELEASE 4 /* for tweaks, bug-fixes, or development */
|
||||||
|
|
||||||
|
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
|
||||||
|
|
||||||
|
#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
|
||||||
|
#define LZ4_QUOTE(str) #str
|
||||||
|
#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
|
||||||
|
#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) /* requires v1.7.3+ */
|
||||||
|
|
||||||
|
LZ4LIB_API int LZ4_versionNumber(void); /**< library version number; useful to check dll version; requires v1.3.0+ */
|
||||||
|
LZ4LIB_API const char* LZ4_versionString(void); /**< library version string; useful to check dll version; requires v1.7.5+ */
|
||||||
|
|
||||||
|
|
||||||
|
/*-************************************
|
||||||
|
* Tuning parameter
|
||||||
|
**************************************/
|
||||||
|
#define LZ4_MEMORY_USAGE_MIN 10
|
||||||
|
#define LZ4_MEMORY_USAGE_DEFAULT 14
|
||||||
|
#define LZ4_MEMORY_USAGE_MAX 20
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* LZ4_MEMORY_USAGE :
|
||||||
|
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; )
|
||||||
|
* Increasing memory usage improves compression ratio, at the cost of speed.
|
||||||
|
* Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality.
|
||||||
|
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
|
||||||
|
*/
|
||||||
|
#ifndef LZ4_MEMORY_USAGE
|
||||||
|
# define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN)
|
||||||
|
# error "LZ4_MEMORY_USAGE is too small !"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX)
|
||||||
|
# error "LZ4_MEMORY_USAGE is too large !"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-************************************
|
||||||
|
* Simple Functions
|
||||||
|
**************************************/
|
||||||
|
/*! LZ4_compress_default() :
|
||||||
|
* Compresses 'srcSize' bytes from buffer 'src'
|
||||||
|
* into already allocated 'dst' buffer of size 'dstCapacity'.
|
||||||
|
* Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
||||||
|
* It also runs faster, so it's a recommended setting.
|
||||||
|
* If the function cannot compress 'src' into a more limited 'dst' budget,
|
||||||
|
* compression stops *immediately*, and the function result is zero.
|
||||||
|
* In which case, 'dst' content is undefined (invalid).
|
||||||
|
* srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
||||||
|
* dstCapacity : size of buffer 'dst' (which must be already allocated)
|
||||||
|
* @return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
||||||
|
* or 0 if compression fails
|
||||||
|
* Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
||||||
|
|
||||||
|
/*! LZ4_decompress_safe() :
|
||||||
|
* @compressedSize : is the exact complete size of the compressed block.
|
||||||
|
* @dstCapacity : is the size of destination buffer (which must be already allocated),
|
||||||
|
* is an upper bound of decompressed size.
|
||||||
|
* @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
||||||
|
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
||||||
|
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||||
|
* Note 1 : This function is protected against malicious data packets :
|
||||||
|
* it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
|
||||||
|
* even if the compressed block is maliciously modified to order the decoder to do these actions.
|
||||||
|
* In such case, the decoder stops immediately, and considers the compressed block malformed.
|
||||||
|
* Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
|
||||||
|
* The implementation is free to send / store / derive this information in whichever way is most beneficial.
|
||||||
|
* If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_decompress_safe(const char* src, char* dst, int compressedSize, int dstCapacity);
|
||||||
|
|
||||||
|
|
||||||
|
/*-************************************
|
||||||
|
* Advanced Functions
|
||||||
|
**************************************/
|
||||||
|
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
|
||||||
|
#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
|
||||||
|
|
||||||
|
/*! LZ4_compressBound() :
|
||||||
|
Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
|
||||||
|
This function is primarily useful for memory allocation purposes (destination buffer size).
|
||||||
|
Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
|
||||||
|
Note that LZ4_compress_default() compresses faster when dstCapacity is >= LZ4_compressBound(srcSize)
|
||||||
|
inputSize : max supported value is LZ4_MAX_INPUT_SIZE
|
||||||
|
return : maximum output size in a "worst case" scenario
|
||||||
|
or 0, if input size is incorrect (too large or negative)
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_compressBound(int inputSize);
|
||||||
|
|
||||||
|
/*! LZ4_compress_fast() :
|
||||||
|
Same as LZ4_compress_default(), but allows selection of "acceleration" factor.
|
||||||
|
The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
|
||||||
|
It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
|
||||||
|
An acceleration value of "1" is the same as regular LZ4_compress_default()
|
||||||
|
Values <= 0 will be replaced by LZ4_ACCELERATION_DEFAULT (currently == 1, see lz4.c).
|
||||||
|
Values > LZ4_ACCELERATION_MAX will be replaced by LZ4_ACCELERATION_MAX (currently == 65537, see lz4.c).
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_compress_fast(const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||||
|
|
||||||
|
|
||||||
|
/*! LZ4_compress_fast_extState() :
|
||||||
|
* Same as LZ4_compress_fast(), using an externally allocated memory space for its state.
|
||||||
|
* Use LZ4_sizeofState() to know how much memory must be allocated,
|
||||||
|
* and allocate it on 8-bytes boundaries (using `malloc()` typically).
|
||||||
|
* Then, provide this buffer as `void* state` to compression function.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_sizeofState(void);
|
||||||
|
LZ4LIB_API int LZ4_compress_fast_extState(void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||||
|
|
||||||
|
|
||||||
|
/*! LZ4_compress_destSize() :
|
||||||
|
* Reverse the logic : compresses as much data as possible from 'src' buffer
|
||||||
|
* into already allocated buffer 'dst', of size >= 'targetDestSize'.
|
||||||
|
* This function either compresses the entire 'src' content into 'dst' if it's large enough,
|
||||||
|
* or fill 'dst' buffer completely with as much data as possible from 'src'.
|
||||||
|
* note: acceleration parameter is fixed to "default".
|
||||||
|
*
|
||||||
|
* *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
|
||||||
|
* New value is necessarily <= input value.
|
||||||
|
* @return : Nb bytes written into 'dst' (necessarily <= targetDestSize)
|
||||||
|
* or 0 if compression fails.
|
||||||
|
*
|
||||||
|
* Note : from v1.8.2 to v1.9.1, this function had a bug (fixed un v1.9.2+):
|
||||||
|
* the produced compressed content could, in specific circumstances,
|
||||||
|
* require to be decompressed into a destination buffer larger
|
||||||
|
* by at least 1 byte than the content to decompress.
|
||||||
|
* If an application uses `LZ4_compress_destSize()`,
|
||||||
|
* it's highly recommended to update liblz4 to v1.9.2 or better.
|
||||||
|
* If this can't be done or ensured,
|
||||||
|
* the receiving decompression function should provide
|
||||||
|
* a dstCapacity which is > decompressedSize, by at least 1 byte.
|
||||||
|
* See https://github.com/lz4/lz4/issues/859 for details
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize);
|
||||||
|
|
||||||
|
|
||||||
|
/*! LZ4_decompress_safe_partial() :
|
||||||
|
* Decompress an LZ4 compressed block, of size 'srcSize' at position 'src',
|
||||||
|
* into destination buffer 'dst' of size 'dstCapacity'.
|
||||||
|
* Up to 'targetOutputSize' bytes will be decoded.
|
||||||
|
* The function stops decoding on reaching this objective.
|
||||||
|
* This can be useful to boost performance
|
||||||
|
* whenever only the beginning of a block is required.
|
||||||
|
*
|
||||||
|
* @return : the number of bytes decoded in `dst` (necessarily <= targetOutputSize)
|
||||||
|
* If source stream is detected malformed, function returns a negative result.
|
||||||
|
*
|
||||||
|
* Note 1 : @return can be < targetOutputSize, if compressed block contains less data.
|
||||||
|
*
|
||||||
|
* Note 2 : targetOutputSize must be <= dstCapacity
|
||||||
|
*
|
||||||
|
* Note 3 : this function effectively stops decoding on reaching targetOutputSize,
|
||||||
|
* so dstCapacity is kind of redundant.
|
||||||
|
* This is because in older versions of this function,
|
||||||
|
* decoding operation would still write complete sequences.
|
||||||
|
* Therefore, there was no guarantee that it would stop writing at exactly targetOutputSize,
|
||||||
|
* it could write more bytes, though only up to dstCapacity.
|
||||||
|
* Some "margin" used to be required for this operation to work properly.
|
||||||
|
* Thankfully, this is no longer necessary.
|
||||||
|
* The function nonetheless keeps the same signature, in an effort to preserve API compatibility.
|
||||||
|
*
|
||||||
|
* Note 4 : If srcSize is the exact size of the block,
|
||||||
|
* then targetOutputSize can be any value,
|
||||||
|
* including larger than the block's decompressed size.
|
||||||
|
* The function will, at most, generate block's decompressed size.
|
||||||
|
*
|
||||||
|
* Note 5 : If srcSize is _larger_ than block's compressed size,
|
||||||
|
* then targetOutputSize **MUST** be <= block's decompressed size.
|
||||||
|
* Otherwise, *silent corruption will occur*.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_decompress_safe_partial(const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
|
||||||
|
|
||||||
|
|
||||||
|
/*-*********************************************
|
||||||
|
* Streaming Compression Functions
|
||||||
|
***********************************************/
|
||||||
|
typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
Note about RC_INVOKED
|
||||||
|
|
||||||
|
- RC_INVOKED is predefined symbol of rc.exe (the resource compiler which is part of MSVC/Visual Studio).
|
||||||
|
https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros
|
||||||
|
|
||||||
|
- Since rc.exe is a legacy compiler, it truncates long symbol (> 30 chars)
|
||||||
|
and reports warning "RC4011: identifier truncated".
|
||||||
|
|
||||||
|
- To eliminate the warning, we surround long preprocessor symbol with
|
||||||
|
"#if !defined(RC_INVOKED) ... #endif" block that means
|
||||||
|
"skip this block when rc.exe is trying to read it".
|
||||||
|
*/
|
||||||
|
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
|
||||||
|
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
|
||||||
|
LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
|
||||||
|
LZ4LIB_API int LZ4_freeStream(LZ4_stream_t* streamPtr);
|
||||||
|
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! LZ4_resetStream_fast() : v1.9.0+
|
||||||
|
* Use this to prepare an LZ4_stream_t for a new chain of dependent blocks
|
||||||
|
* (e.g., LZ4_compress_fast_continue()).
|
||||||
|
*
|
||||||
|
* An LZ4_stream_t must be initialized once before usage.
|
||||||
|
* This is automatically done when created by LZ4_createStream().
|
||||||
|
* However, should the LZ4_stream_t be simply declared on stack (for example),
|
||||||
|
* it's necessary to initialize it first, using LZ4_initStream().
|
||||||
|
*
|
||||||
|
* After init, start any new stream with LZ4_resetStream_fast().
|
||||||
|
* A same LZ4_stream_t can be re-used multiple times consecutively
|
||||||
|
* and compress multiple streams,
|
||||||
|
* provided that it starts each new stream with LZ4_resetStream_fast().
|
||||||
|
*
|
||||||
|
* LZ4_resetStream_fast() is much faster than LZ4_initStream(),
|
||||||
|
* but is not compatible with memory regions containing garbage data.
|
||||||
|
*
|
||||||
|
* Note: it's only useful to call LZ4_resetStream_fast()
|
||||||
|
* in the context of streaming compression.
|
||||||
|
* The *extState* functions perform their own resets.
|
||||||
|
* Invoking LZ4_resetStream_fast() before is redundant, and even counterproductive.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API void LZ4_resetStream_fast(LZ4_stream_t* streamPtr);
|
||||||
|
|
||||||
|
/*! LZ4_loadDict() :
|
||||||
|
* Use this function to reference a static dictionary into LZ4_stream_t.
|
||||||
|
* The dictionary must remain available during compression.
|
||||||
|
* LZ4_loadDict() triggers a reset, so any previous data will be forgotten.
|
||||||
|
* The same dictionary will have to be loaded on decompression side for successful decoding.
|
||||||
|
* Dictionary are useful for better compression of small data (KB range).
|
||||||
|
* While LZ4 accept any input as dictionary,
|
||||||
|
* results are generally better when using Zstandard's Dictionary Builder.
|
||||||
|
* Loading a size of 0 is allowed, and is the same as reset.
|
||||||
|
* @return : loaded dictionary size, in bytes (necessarily <= 64 KB)
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_loadDict(LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
|
||||||
|
|
||||||
|
/*! LZ4_compress_fast_continue() :
|
||||||
|
* Compress 'src' content using data from previously compressed blocks, for better compression ratio.
|
||||||
|
* 'dst' buffer must be already allocated.
|
||||||
|
* If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
|
||||||
|
*
|
||||||
|
* @return : size of compressed block
|
||||||
|
* or 0 if there is an error (typically, cannot fit into 'dst').
|
||||||
|
*
|
||||||
|
* Note 1 : Each invocation to LZ4_compress_fast_continue() generates a new block.
|
||||||
|
* Each block has precise boundaries.
|
||||||
|
* Each block must be decompressed separately, calling LZ4_decompress_*() with relevant metadata.
|
||||||
|
* It's not possible to append blocks together and expect a single invocation of LZ4_decompress_*() to decompress them together.
|
||||||
|
*
|
||||||
|
* Note 2 : The previous 64KB of source data is __assumed__ to remain present, unmodified, at same address in memory !
|
||||||
|
*
|
||||||
|
* Note 3 : When input is structured as a double-buffer, each buffer can have any size, including < 64 KB.
|
||||||
|
* Make sure that buffers are separated, by at least one byte.
|
||||||
|
* This construction ensures that each block only depends on previous block.
|
||||||
|
*
|
||||||
|
* Note 4 : If input buffer is a ring-buffer, it can have any size, including < 64 KB.
|
||||||
|
*
|
||||||
|
* Note 5 : After an error, the stream status is undefined (invalid), it can only be reset or freed.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_compress_fast_continue(LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||||
|
|
||||||
|
/*! LZ4_saveDict() :
|
||||||
|
* If last 64KB data cannot be guaranteed to remain available at its current memory location,
|
||||||
|
* save it into a safer place (char* safeBuffer).
|
||||||
|
* This is schematically equivalent to a memcpy() followed by LZ4_loadDict(),
|
||||||
|
* but is much faster, because LZ4_saveDict() doesn't need to rebuild tables.
|
||||||
|
* @return : saved dictionary size in bytes (necessarily <= maxDictSize), or 0 if error.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_saveDict(LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
|
||||||
|
|
||||||
|
|
||||||
|
/*-**********************************************
|
||||||
|
* Streaming Decompression Functions
|
||||||
|
* Bufferless synchronous API
|
||||||
|
************************************************/
|
||||||
|
typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
|
||||||
|
|
||||||
|
/*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() :
|
||||||
|
* creation / destruction of streaming decompression tracking context.
|
||||||
|
* A tracking context can be re-used multiple times.
|
||||||
|
*/
|
||||||
|
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
|
||||||
|
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
|
||||||
|
LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
|
||||||
|
LZ4LIB_API int LZ4_freeStreamDecode(LZ4_streamDecode_t* LZ4_stream);
|
||||||
|
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! LZ4_setStreamDecode() :
|
||||||
|
* An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
|
||||||
|
* Use this function to start decompression of a new stream of blocks.
|
||||||
|
* A dictionary can optionally be set. Use NULL or size 0 for a reset order.
|
||||||
|
* Dictionary is presumed stable : it must remain accessible and unmodified during next decompression.
|
||||||
|
* @return : 1 if OK, 0 if error
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_setStreamDecode(LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
|
||||||
|
|
||||||
|
/*! LZ4_decoderRingBufferSize() : v1.8.2+
|
||||||
|
* Note : in a ring buffer scenario (optional),
|
||||||
|
* blocks are presumed decompressed next to each other
|
||||||
|
* up to the moment there is not enough remaining space for next block (remainingSize < maxBlockSize),
|
||||||
|
* at which stage it resumes from beginning of ring buffer.
|
||||||
|
* When setting such a ring buffer for streaming decompression,
|
||||||
|
* provides the minimum size of this ring buffer
|
||||||
|
* to be compatible with any source respecting maxBlockSize condition.
|
||||||
|
* @return : minimum ring buffer size,
|
||||||
|
* or 0 if there is an error (invalid maxBlockSize).
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
|
||||||
|
#define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
|
||||||
|
|
||||||
|
/*! LZ4_decompress_safe_continue() :
|
||||||
|
* This decoding function allows decompression of consecutive blocks in "streaming" mode.
|
||||||
|
* The difference with the usual independent blocks is that
|
||||||
|
* new blocks are allowed to find references into former blocks.
|
||||||
|
* A block is an unsplittable entity, and must be presented entirely to the decompression function.
|
||||||
|
* LZ4_decompress_safe_continue() only accepts one block at a time.
|
||||||
|
* It's modeled after `LZ4_decompress_safe()` and behaves similarly.
|
||||||
|
*
|
||||||
|
* @LZ4_streamDecode : decompression state, tracking the position in memory of past data
|
||||||
|
* @compressedSize : exact complete size of one compressed block.
|
||||||
|
* @dstCapacity : size of destination buffer (which must be already allocated),
|
||||||
|
* must be an upper bound of decompressed size.
|
||||||
|
* @return : number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
||||||
|
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
||||||
|
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||||
|
*
|
||||||
|
* The last 64KB of previously decoded data *must* remain available and unmodified
|
||||||
|
* at the memory position where they were previously decoded.
|
||||||
|
* If less than 64KB of data has been decoded, all the data must be present.
|
||||||
|
*
|
||||||
|
* Special : if decompression side sets a ring buffer, it must respect one of the following conditions :
|
||||||
|
* - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize).
|
||||||
|
* maxBlockSize is the maximum size of any single block. It can have any value > 16 bytes.
|
||||||
|
* In which case, encoding and decoding buffers do not need to be synchronized.
|
||||||
|
* Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize.
|
||||||
|
* - Synchronized mode :
|
||||||
|
* Decompression buffer size is _exactly_ the same as compression buffer size,
|
||||||
|
* and follows exactly same update rule (block boundaries at same positions),
|
||||||
|
* and decoding function is provided with exact decompressed size of each block (exception for last block of the stream),
|
||||||
|
* _then_ decoding & encoding ring buffer can have any size, including small ones ( < 64 KB).
|
||||||
|
* - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes.
|
||||||
|
* In which case, encoding and decoding buffers do not need to be synchronized,
|
||||||
|
* and encoding ring buffer can have any size, including small ones ( < 64 KB).
|
||||||
|
*
|
||||||
|
* Whenever these conditions are not possible,
|
||||||
|
* save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
|
||||||
|
* then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int
|
||||||
|
LZ4_decompress_safe_continue(LZ4_streamDecode_t* LZ4_streamDecode,
|
||||||
|
const char* src, char* dst,
|
||||||
|
int srcSize, int dstCapacity);
|
||||||
|
|
||||||
|
|
||||||
|
/*! LZ4_decompress_safe_usingDict() :
|
||||||
|
* Works the same as
|
||||||
|
* a combination of LZ4_setStreamDecode() followed by LZ4_decompress_safe_continue()
|
||||||
|
* However, it's stateless: it doesn't need any LZ4_streamDecode_t state.
|
||||||
|
* Dictionary is presumed stable : it must remain accessible and unmodified during decompression.
|
||||||
|
* Performance tip : Decompression speed can be substantially increased
|
||||||
|
* when dst == dictStart + dictSize.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int
|
||||||
|
LZ4_decompress_safe_usingDict(const char* src, char* dst,
|
||||||
|
int srcSize, int dstCapacity,
|
||||||
|
const char* dictStart, int dictSize);
|
||||||
|
|
||||||
|
/*! LZ4_decompress_safe_partial_usingDict() :
|
||||||
|
* Behaves the same as LZ4_decompress_safe_partial()
|
||||||
|
* with the added ability to specify a memory segment for past data.
|
||||||
|
* Performance tip : Decompression speed can be substantially increased
|
||||||
|
* when dst == dictStart + dictSize.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API int
|
||||||
|
LZ4_decompress_safe_partial_usingDict(const char* src, char* dst,
|
||||||
|
int compressedSize,
|
||||||
|
int targetOutputSize, int maxOutputSize,
|
||||||
|
const char* dictStart, int dictSize);
|
||||||
|
|
||||||
|
#endif /* LZ4_H_2983827168210 */
|
||||||
|
|
||||||
|
|
||||||
|
/*^*************************************
|
||||||
|
* !!!!!! STATIC LINKING ONLY !!!!!!
|
||||||
|
***************************************/
|
||||||
|
|
||||||
|
/*-****************************************************************************
|
||||||
|
* Experimental section
|
||||||
|
*
|
||||||
|
* Symbols declared in this section must be considered unstable. Their
|
||||||
|
* signatures or semantics may change, or they may be removed altogether in the
|
||||||
|
* future. They are therefore only safe to depend on when the caller is
|
||||||
|
* statically linked against the library.
|
||||||
|
*
|
||||||
|
* To protect against unsafe usage, not only are the declarations guarded,
|
||||||
|
* the definitions are hidden by default
|
||||||
|
* when building LZ4 as a shared/dynamic library.
|
||||||
|
*
|
||||||
|
* In order to access these declarations,
|
||||||
|
* define LZ4_STATIC_LINKING_ONLY in your application
|
||||||
|
* before including LZ4's headers.
|
||||||
|
*
|
||||||
|
* In order to make their implementations accessible dynamically, you must
|
||||||
|
* define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifdef LZ4_STATIC_LINKING_ONLY
|
||||||
|
|
||||||
|
#ifndef LZ4_STATIC_3504398509
|
||||||
|
#define LZ4_STATIC_3504398509
|
||||||
|
|
||||||
|
#ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
|
||||||
|
#define LZ4LIB_STATIC_API LZ4LIB_API
|
||||||
|
#else
|
||||||
|
#define LZ4LIB_STATIC_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*! LZ4_compress_fast_extState_fastReset() :
|
||||||
|
* A variant of LZ4_compress_fast_extState().
|
||||||
|
*
|
||||||
|
* Using this variant avoids an expensive initialization step.
|
||||||
|
* It is only safe to call if the state buffer is known to be correctly initialized already
|
||||||
|
* (see above comment on LZ4_resetStream_fast() for a definition of "correctly initialized").
|
||||||
|
* From a high level, the difference is that
|
||||||
|
* this function initializes the provided state with a call to something like LZ4_resetStream_fast()
|
||||||
|
* while LZ4_compress_fast_extState() starts with a call to LZ4_resetStream().
|
||||||
|
*/
|
||||||
|
LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset(void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||||
|
|
||||||
|
/*! LZ4_attach_dictionary() :
|
||||||
|
* This is an experimental API that allows
|
||||||
|
* efficient use of a static dictionary many times.
|
||||||
|
*
|
||||||
|
* Rather than re-loading the dictionary buffer into a working context before
|
||||||
|
* each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
|
||||||
|
* working LZ4_stream_t, this function introduces a no-copy setup mechanism,
|
||||||
|
* in which the working stream references the dictionary stream in-place.
|
||||||
|
*
|
||||||
|
* Several assumptions are made about the state of the dictionary stream.
|
||||||
|
* Currently, only streams which have been prepared by LZ4_loadDict() should
|
||||||
|
* be expected to work.
|
||||||
|
*
|
||||||
|
* Alternatively, the provided dictionaryStream may be NULL,
|
||||||
|
* in which case any existing dictionary stream is unset.
|
||||||
|
*
|
||||||
|
* If a dictionary is provided, it replaces any pre-existing stream history.
|
||||||
|
* The dictionary contents are the only history that can be referenced and
|
||||||
|
* logically immediately precede the data compressed in the first subsequent
|
||||||
|
* compression call.
|
||||||
|
*
|
||||||
|
* The dictionary will only remain attached to the working stream through the
|
||||||
|
* first compression call, at the end of which it is cleared. The dictionary
|
||||||
|
* stream (and source buffer) must remain in-place / accessible / unchanged
|
||||||
|
* through the completion of the first compression call on the stream.
|
||||||
|
*/
|
||||||
|
LZ4LIB_STATIC_API void
|
||||||
|
LZ4_attach_dictionary(LZ4_stream_t* workingStream,
|
||||||
|
const LZ4_stream_t* dictionaryStream);
|
||||||
|
|
||||||
|
|
||||||
|
/*! In-place compression and decompression
|
||||||
|
*
|
||||||
|
* It's possible to have input and output sharing the same buffer,
|
||||||
|
* for highly constrained memory environments.
|
||||||
|
* In both cases, it requires input to lay at the end of the buffer,
|
||||||
|
* and decompression to start at beginning of the buffer.
|
||||||
|
* Buffer size must feature some margin, hence be larger than final size.
|
||||||
|
*
|
||||||
|
* |<------------------------buffer--------------------------------->|
|
||||||
|
* |<-----------compressed data--------->|
|
||||||
|
* |<-----------decompressed size------------------>|
|
||||||
|
* |<----margin---->|
|
||||||
|
*
|
||||||
|
* This technique is more useful for decompression,
|
||||||
|
* since decompressed size is typically larger,
|
||||||
|
* and margin is short.
|
||||||
|
*
|
||||||
|
* In-place decompression will work inside any buffer
|
||||||
|
* which size is >= LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize).
|
||||||
|
* This presumes that decompressedSize > compressedSize.
|
||||||
|
* Otherwise, it means compression actually expanded data,
|
||||||
|
* and it would be more efficient to store such data with a flag indicating it's not compressed.
|
||||||
|
* This can happen when data is not compressible (already compressed, or encrypted).
|
||||||
|
*
|
||||||
|
* For in-place compression, margin is larger, as it must be able to cope with both
|
||||||
|
* history preservation, requiring input data to remain unmodified up to LZ4_DISTANCE_MAX,
|
||||||
|
* and data expansion, which can happen when input is not compressible.
|
||||||
|
* As a consequence, buffer size requirements are much higher,
|
||||||
|
* and memory savings offered by in-place compression are more limited.
|
||||||
|
*
|
||||||
|
* There are ways to limit this cost for compression :
|
||||||
|
* - Reduce history size, by modifying LZ4_DISTANCE_MAX.
|
||||||
|
* Note that it is a compile-time constant, so all compressions will apply this limit.
|
||||||
|
* Lower values will reduce compression ratio, except when input_size < LZ4_DISTANCE_MAX,
|
||||||
|
* so it's a reasonable trick when inputs are known to be small.
|
||||||
|
* - Require the compressor to deliver a "maximum compressed size".
|
||||||
|
* This is the `dstCapacity` parameter in `LZ4_compress*()`.
|
||||||
|
* When this size is < LZ4_COMPRESSBOUND(inputSize), then compression can fail,
|
||||||
|
* in which case, the return code will be 0 (zero).
|
||||||
|
* The caller must be ready for these cases to happen,
|
||||||
|
* and typically design a backup scheme to send data uncompressed.
|
||||||
|
* The combination of both techniques can significantly reduce
|
||||||
|
* the amount of margin required for in-place compression.
|
||||||
|
*
|
||||||
|
* In-place compression can work in any buffer
|
||||||
|
* which size is >= (maxCompressedSize)
|
||||||
|
* with maxCompressedSize == LZ4_COMPRESSBOUND(srcSize) for guaranteed compression success.
|
||||||
|
* LZ4_COMPRESS_INPLACE_BUFFER_SIZE() depends on both maxCompressedSize and LZ4_DISTANCE_MAX,
|
||||||
|
* so it's possible to reduce memory requirements by playing with them.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
|
||||||
|
#define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize)) /**< note: presumes that compressedSize < decompressedSize. note2: margin is overestimated a bit, since it could use compressedSize instead */
|
||||||
|
|
||||||
|
#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
|
||||||
|
# define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
|
||||||
|
#define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN) /**< maxCompressedSize is generally LZ4_COMPRESSBOUND(inputSize), but can be set to any lower value, with the risk that compression can fail (return code 0(zero)) */
|
||||||
|
|
||||||
|
#endif /* LZ4_STATIC_3504398509 */
|
||||||
|
#endif /* LZ4_STATIC_LINKING_ONLY */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LZ4_H_98237428734687
|
||||||
|
#define LZ4_H_98237428734687
|
||||||
|
|
||||||
|
/*-************************************************************
|
||||||
|
* Private Definitions
|
||||||
|
**************************************************************
|
||||||
|
* Do not use these definitions directly.
|
||||||
|
* They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
|
||||||
|
* Accessing members will expose user code to API and/or ABI break in future versions of the library.
|
||||||
|
**************************************************************/
|
||||||
|
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
|
||||||
|
#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
|
||||||
|
#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
|
||||||
|
|
||||||
|
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
||||||
|
# include <stdint.h>
|
||||||
|
typedef int8_t LZ4_i8;
|
||||||
|
typedef uint8_t LZ4_byte;
|
||||||
|
typedef uint16_t LZ4_u16;
|
||||||
|
typedef uint32_t LZ4_u32;
|
||||||
|
#else
|
||||||
|
typedef signed char LZ4_i8;
|
||||||
|
typedef unsigned char LZ4_byte;
|
||||||
|
typedef unsigned short LZ4_u16;
|
||||||
|
typedef unsigned int LZ4_u32;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! LZ4_stream_t :
|
||||||
|
* Never ever use below internal definitions directly !
|
||||||
|
* These definitions are not API/ABI safe, and may change in future versions.
|
||||||
|
* If you need static allocation, declare or allocate an LZ4_stream_t object.
|
||||||
|
**/
|
||||||
|
|
||||||
|
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
|
||||||
|
struct LZ4_stream_t_internal {
|
||||||
|
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32];
|
||||||
|
const LZ4_byte* dictionary;
|
||||||
|
const LZ4_stream_t_internal* dictCtx;
|
||||||
|
LZ4_u32 currentOffset;
|
||||||
|
LZ4_u32 tableType;
|
||||||
|
LZ4_u32 dictSize;
|
||||||
|
/* Implicit padding to ensure structure is aligned */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define LZ4_STREAM_MINSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) /* static size, for inter-version compatibility */
|
||||||
|
union LZ4_stream_u {
|
||||||
|
char minStateSize[LZ4_STREAM_MINSIZE];
|
||||||
|
LZ4_stream_t_internal internal_donotuse;
|
||||||
|
}; /* previously typedef'd to LZ4_stream_t */
|
||||||
|
|
||||||
|
|
||||||
|
/*! LZ4_initStream() : v1.9.0+
|
||||||
|
* An LZ4_stream_t structure must be initialized at least once.
|
||||||
|
* This is automatically done when invoking LZ4_createStream(),
|
||||||
|
* but it's not when the structure is simply declared on stack (for example).
|
||||||
|
*
|
||||||
|
* Use LZ4_initStream() to properly initialize a newly declared LZ4_stream_t.
|
||||||
|
* It can also initialize any arbitrary buffer of sufficient size,
|
||||||
|
* and will @return a pointer of proper type upon initialization.
|
||||||
|
*
|
||||||
|
* Note : initialization fails if size and alignment conditions are not respected.
|
||||||
|
* In which case, the function will @return NULL.
|
||||||
|
* Note2: An LZ4_stream_t structure guarantees correct alignment and size.
|
||||||
|
* Note3: Before v1.9.0, use LZ4_resetStream() instead
|
||||||
|
**/
|
||||||
|
LZ4LIB_API LZ4_stream_t* LZ4_initStream(void* buffer, size_t size);
|
||||||
|
|
||||||
|
|
||||||
|
/*! LZ4_streamDecode_t :
|
||||||
|
* Never ever use below internal definitions directly !
|
||||||
|
* These definitions are not API/ABI safe, and may change in future versions.
|
||||||
|
* If you need static allocation, declare or allocate an LZ4_streamDecode_t object.
|
||||||
|
**/
|
||||||
|
typedef struct {
|
||||||
|
const LZ4_byte* externalDict;
|
||||||
|
const LZ4_byte* prefixEnd;
|
||||||
|
size_t extDictSize;
|
||||||
|
size_t prefixSize;
|
||||||
|
} LZ4_streamDecode_t_internal;
|
||||||
|
|
||||||
|
#define LZ4_STREAMDECODE_MINSIZE 32
|
||||||
|
union LZ4_streamDecode_u {
|
||||||
|
char minStateSize[LZ4_STREAMDECODE_MINSIZE];
|
||||||
|
LZ4_streamDecode_t_internal internal_donotuse;
|
||||||
|
}; /* previously typedef'd to LZ4_streamDecode_t */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-************************************
|
||||||
|
* Obsolete Functions
|
||||||
|
**************************************/
|
||||||
|
|
||||||
|
/*! Deprecation warnings
|
||||||
|
*
|
||||||
|
* Deprecated functions make the compiler generate a warning when invoked.
|
||||||
|
* This is meant to invite users to update their source code.
|
||||||
|
* Should deprecation warnings be a problem, it is generally possible to disable them,
|
||||||
|
* typically with -Wno-deprecated-declarations for gcc
|
||||||
|
* or _CRT_SECURE_NO_WARNINGS in Visual.
|
||||||
|
*
|
||||||
|
* Another method is to define LZ4_DISABLE_DEPRECATE_WARNINGS
|
||||||
|
* before including the header file.
|
||||||
|
*/
|
||||||
|
#ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
|
||||||
|
# define LZ4_DEPRECATED(message) /* disable deprecation warnings */
|
||||||
|
#else
|
||||||
|
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
||||||
|
# define LZ4_DEPRECATED(message) [[deprecated(message)]]
|
||||||
|
# elif defined(_MSC_VER)
|
||||||
|
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
|
||||||
|
# elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 45))
|
||||||
|
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 31)
|
||||||
|
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
|
||||||
|
# else
|
||||||
|
# pragma message("WARNING: LZ4_DEPRECATED needs custom implementation for this compiler")
|
||||||
|
# define LZ4_DEPRECATED(message) /* disabled */
|
||||||
|
# endif
|
||||||
|
#endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
|
||||||
|
|
||||||
|
/*! Obsolete compression functions (since v1.7.3) */
|
||||||
|
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress(const char* src, char* dest, int srcSize);
|
||||||
|
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress_limitedOutput(const char* src, char* dest, int srcSize, int maxOutputSize);
|
||||||
|
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_withState(void* state, const char* source, char* dest, int inputSize);
|
||||||
|
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_limitedOutput_withState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||||
|
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_continue(LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
|
||||||
|
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_limitedOutput_continue(LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||||
|
|
||||||
|
/*! Obsolete decompression functions (since v1.8.0) */
|
||||||
|
LZ4_DEPRECATED("use LZ4_decompress_fast() instead") LZ4LIB_API int LZ4_uncompress(const char* source, char* dest, int outputSize);
|
||||||
|
LZ4_DEPRECATED("use LZ4_decompress_safe() instead") LZ4LIB_API int LZ4_uncompress_unknownOutputSize(const char* source, char* dest, int isize, int maxOutputSize);
|
||||||
|
|
||||||
|
/* Obsolete streaming functions (since v1.7.0)
|
||||||
|
* degraded functionality; do not use!
|
||||||
|
*
|
||||||
|
* In order to perform streaming compression, these functions depended on data
|
||||||
|
* that is no longer tracked in the state. They have been preserved as well as
|
||||||
|
* possible: using them will still produce a correct output. However, they don't
|
||||||
|
* actually retain any history between compression calls. The compression ratio
|
||||||
|
* achieved will therefore be no better than compressing each chunk
|
||||||
|
* independently.
|
||||||
|
*/
|
||||||
|
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API void* LZ4_create(char* inputBuffer);
|
||||||
|
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API int LZ4_sizeofStreamState(void);
|
||||||
|
LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStreamState(void* state, char* inputBuffer);
|
||||||
|
LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer(void* state);
|
||||||
|
|
||||||
|
/*! Obsolete streaming decoding functions (since v1.7.0) */
|
||||||
|
LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4_decompress_safe_withPrefix64k(const char* src, char* dst, int compressedSize, int maxDstSize);
|
||||||
|
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k(const char* src, char* dst, int originalSize);
|
||||||
|
|
||||||
|
/*! Obsolete LZ4_decompress_fast variants (since v1.9.0) :
|
||||||
|
* These functions used to be faster than LZ4_decompress_safe(),
|
||||||
|
* but this is no longer the case. They are now slower.
|
||||||
|
* This is because LZ4_decompress_fast() doesn't know the input size,
|
||||||
|
* and therefore must progress more cautiously into the input buffer to not read beyond the end of block.
|
||||||
|
* On top of that `LZ4_decompress_fast()` is not protected vs malformed or malicious inputs, making it a security liability.
|
||||||
|
* As a consequence, LZ4_decompress_fast() is strongly discouraged, and deprecated.
|
||||||
|
*
|
||||||
|
* The last remaining LZ4_decompress_fast() specificity is that
|
||||||
|
* it can decompress a block without knowing its compressed size.
|
||||||
|
* Such functionality can be achieved in a more secure manner
|
||||||
|
* by employing LZ4_decompress_safe_partial().
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* originalSize : is the uncompressed size to regenerate.
|
||||||
|
* `dst` must be already allocated, its size must be >= 'originalSize' bytes.
|
||||||
|
* @return : number of bytes read from source buffer (== compressed size).
|
||||||
|
* The function expects to finish at block's end exactly.
|
||||||
|
* If the source stream is detected malformed, the function stops decoding and returns a negative result.
|
||||||
|
* note : LZ4_decompress_fast*() requires originalSize. Thanks to this information, it never writes past the output buffer.
|
||||||
|
* However, since it doesn't know its 'src' size, it may read an unknown amount of input, past input buffer bounds.
|
||||||
|
* Also, since match offsets are not validated, match reads from 'src' may underflow too.
|
||||||
|
* These issues never happen if input (compressed) data is correct.
|
||||||
|
* But they may happen if input data is invalid (error or intentional tampering).
|
||||||
|
* As a consequence, use these functions in trusted environments with trusted data **only**.
|
||||||
|
*/
|
||||||
|
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
|
||||||
|
LZ4LIB_API int LZ4_decompress_fast(const char* src, char* dst, int originalSize);
|
||||||
|
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
|
||||||
|
LZ4LIB_API int LZ4_decompress_fast_continue(LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
|
||||||
|
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
|
||||||
|
LZ4LIB_API int LZ4_decompress_fast_usingDict(const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
|
||||||
|
|
||||||
|
/*! LZ4_resetStream() :
|
||||||
|
* An LZ4_stream_t structure must be initialized at least once.
|
||||||
|
* This is done with LZ4_initStream(), or LZ4_resetStream().
|
||||||
|
* Consider switching to LZ4_initStream(),
|
||||||
|
* invoking LZ4_resetStream() will trigger deprecation warnings in the future.
|
||||||
|
*/
|
||||||
|
LZ4LIB_API void LZ4_resetStream(LZ4_stream_t* streamPtr);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* LZ4_H_98237428734687 */
|
||||||
|
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
6
app/3rdparty/mongoose/CMakeLists.txt
vendored
Normal file
6
app/3rdparty/mongoose/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
|
aux_source_directory(. MONGOOSE_SOURCE)
|
||||||
|
|
||||||
|
add_library(mongoose ${MONGOOSE_SOURCE})
|
||||||
|
|
||||||
|
target_include_directories(mongoose INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
8847
app/3rdparty/mongoose/mongoose.c
vendored
Normal file
8847
app/3rdparty/mongoose/mongoose.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1760
app/3rdparty/mongoose/mongoose.h
vendored
Normal file
1760
app/3rdparty/mongoose/mongoose.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
app/3rdparty/spdlog
vendored
Submodule
1
app/3rdparty/spdlog
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 91807c2e718890ca2c0c88620326c6919ce041f4
|
7
app/CMakeLists.txt
Normal file
7
app/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_subdirectory(injector)
|
||||||
|
add_subdirectory(wxhelper)
|
||||||
|
|
14
app/base/CMakeLists.txt
Normal file
14
app/base/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
|
aux_source_directory(./src BASE_SOURCE)
|
||||||
|
aux_source_directory(./src/include BASE_HEADER_SOURCE)
|
||||||
|
|
||||||
|
add_library(base ${BASE_SOURCE} ${BASE_HEADER_SOURCE})
|
||||||
|
|
||||||
|
target_include_directories(base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/include)
|
||||||
|
|
||||||
|
|
||||||
|
#target_include_directories(base PUBLIC C:/other/codeSource/windows/wxhelper/app/base/src/include)
|
||||||
|
|
||||||
|
#install(TARGETS base LIBRARY DESTINATION base)
|
||||||
|
|
||||||
|
|
30
app/base/src/include/base_config.h
Normal file
30
app/base/src/include/base_config.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef BASE_BASE_CONFIG_H_
|
||||||
|
#define BASE_BASE_CONFIG_H_
|
||||||
|
// Lib/Dll switch
|
||||||
|
#if !defined(BASE_EXPORTS) && !defined(BASE_IMPORTS) && !defined(BASE_STATIC)
|
||||||
|
#define BASE_STATIC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
|
#ifndef COMPILER_MSVC
|
||||||
|
#define COMPILER_MSVC 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(BASE_IMPORTS)
|
||||||
|
#define BASE_API __declspec(dllimport)
|
||||||
|
#elif defined(BASE_EXPORTS)
|
||||||
|
#define BASE_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define BASE_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define COMPILER_GCC
|
||||||
|
#define BASE_API
|
||||||
|
#else
|
||||||
|
#error "Unknown or unsupported compiler"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef WXHELPER_SINGLETON_H_
|
#ifndef BASE_SINGLETON_H_
|
||||||
#define WXHELPER_SINGLETON_H_
|
#define BASE_SINGLETON_H_
|
||||||
|
namespace base {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class Singleton {
|
class Singleton {
|
||||||
protected:
|
protected:
|
||||||
@ -18,4 +19,5 @@ class Singleton {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
} // namespace base
|
||||||
#endif
|
#endif
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef WXHELPER_THREAD_POOL_H_
|
#ifndef BASE_THREAD_POOL_H_
|
||||||
#define WXHELPER_THREAD_POOL_H_
|
#define BASE_THREAD_POOL_H_
|
||||||
#include "Windows.h"
|
|
||||||
#include "singleton.h"
|
#include "singleton.h"
|
||||||
namespace wxhelper {
|
#include <windows.h>
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
|
||||||
class ThreadPool :public Singleton<ThreadPool>{
|
class ThreadPool :public Singleton<ThreadPool>{
|
||||||
public:
|
public:
|
67
app/base/src/include/utils.h
Normal file
67
app/base/src/include/utils.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#ifndef BASE_UTILS_H_
|
||||||
|
#define BASE_UTILS_H_
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
namespace base {
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
std::wstring Utf8ToWstring(const std::string &str);
|
||||||
|
|
||||||
|
std::string WstringToUtf8(const std::wstring &str);
|
||||||
|
|
||||||
|
std::wstring AnsiToWstring(const std::string &input, INT64 locale = CP_ACP);
|
||||||
|
|
||||||
|
std::string WstringToAnsi(const std::wstring &input, INT64 locale = CP_ACP);
|
||||||
|
|
||||||
|
std::string WcharToUtf8(wchar_t *wstr);
|
||||||
|
|
||||||
|
std::string StringToHex(const std::string &str);
|
||||||
|
|
||||||
|
std::string HexToString(const std::string &hex_str);
|
||||||
|
|
||||||
|
std::string BytesToHex(const BYTE *bytes, const int length);
|
||||||
|
|
||||||
|
void HexToBytes(const std::string &hex, BYTE *bytes);
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
std::vector<T1> split(T1 str, T2 letter) {
|
||||||
|
std::vector<T1> arr;
|
||||||
|
size_t pos;
|
||||||
|
while ((pos = str.find_first_of(letter)) != T1::npos) {
|
||||||
|
T1 str1 = str.substr(0, pos);
|
||||||
|
arr.push_back(str1);
|
||||||
|
str = str.substr(pos + 1, str.length() - pos - 1);
|
||||||
|
}
|
||||||
|
arr.push_back(str);
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
T1 replace(T1 source, T2 replaced, T1 replaceto) {
|
||||||
|
std::vector<T1> v_arr = split(source, replaced);
|
||||||
|
if (v_arr.size() < 2) return source;
|
||||||
|
T1 temp;
|
||||||
|
for (unsigned int i = 0; i < v_arr.size() - 1; i++) {
|
||||||
|
temp += v_arr[i];
|
||||||
|
temp += replaceto;
|
||||||
|
}
|
||||||
|
temp += v_arr[v_arr.size() - 1];
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CreateConsole();
|
||||||
|
|
||||||
|
void CloseConsole();
|
||||||
|
|
||||||
|
void HideModule(HMODULE module);
|
||||||
|
|
||||||
|
bool IsDigit(const std::string &str);
|
||||||
|
|
||||||
|
std::string Bytes2Hex(const BYTE *bytes, const int length);
|
||||||
|
|
||||||
|
bool IsTextUtf8(const char *str, INT64 length);
|
||||||
|
} // namespace utils
|
||||||
|
} // namespace base
|
||||||
|
#endif
|
5
app/base/src/include/win_header.h
Normal file
5
app/base/src/include/win_header.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#ifndef BASE_WIN_HEADER_H_
|
||||||
|
#define BASE_WIN_HEADER_H_
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#endif
|
@ -1,17 +1,13 @@
|
|||||||
|
#include "include/thread_pool.h"
|
||||||
#include "pch.h"
|
|
||||||
#include "thread_pool.h"
|
|
||||||
|
|
||||||
#include "Windows.h"
|
namespace base {
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
ThreadPool::~ThreadPool() {
|
ThreadPool::~ThreadPool() {
|
||||||
if(cleanup_group_){
|
if (cleanup_group_) {
|
||||||
CloseThreadpoolCleanupGroupMembers(cleanup_group_, true, NULL);
|
CloseThreadpoolCleanupGroupMembers(cleanup_group_, true, NULL);
|
||||||
CloseThreadpoolCleanupGroup(cleanup_group_);
|
CloseThreadpoolCleanupGroup(cleanup_group_);
|
||||||
}
|
}
|
||||||
DestroyThreadpoolEnvironment(&env_);
|
DestroyThreadpoolEnvironment(&env_);
|
||||||
if (pool_){
|
if (pool_) {
|
||||||
CloseThreadpool(pool_);
|
CloseThreadpool(pool_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,7 +32,7 @@ bool ThreadPool::Create(unsigned long min, unsigned long max) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThreadPool::AddWork(PTP_WORK_CALLBACK callback,PVOID opt) {
|
bool ThreadPool::AddWork(PTP_WORK_CALLBACK callback, PVOID opt) {
|
||||||
PTP_WORK work = CreateThreadpoolWork(callback, opt, &env_);
|
PTP_WORK work = CreateThreadpoolWork(callback, opt, &env_);
|
||||||
if (NULL == work) {
|
if (NULL == work) {
|
||||||
return false;
|
return false;
|
||||||
@ -45,4 +41,4 @@ bool ThreadPool::AddWork(PTP_WORK_CALLBACK callback,PVOID opt) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace wxhelper
|
} // namespace base
|
225
app/base/src/utils.cc
Normal file
225
app/base/src/utils.cc
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
#include "include/utils.h"
|
||||||
|
|
||||||
|
#include <winternl.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
namespace base {
|
||||||
|
namespace utils {
|
||||||
|
const std::string hex_table = "0123456789abcdef";
|
||||||
|
std::wstring Utf8ToWstring(const std::string &str) {
|
||||||
|
return AnsiToWstring(str, CP_UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string WstringToUtf8(const std::wstring &str) {
|
||||||
|
return WstringToAnsi(str, CP_UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring AnsiToWstring(const std::string &input, INT64 locale) {
|
||||||
|
int wchar_len = MultiByteToWideChar(locale, 0, input.c_str(), -1, NULL, 0);
|
||||||
|
if (wchar_len > 0) {
|
||||||
|
std::vector<wchar_t> temp(wchar_len);
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, &temp[0], wchar_len);
|
||||||
|
return std::wstring(&temp[0]);
|
||||||
|
}
|
||||||
|
return std::wstring();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string WstringToAnsi(const std::wstring &input, INT64 locale) {
|
||||||
|
int char_len = WideCharToMultiByte(locale, 0, input.c_str(), -1, 0, 0, 0, 0);
|
||||||
|
if (char_len > 0) {
|
||||||
|
std::vector<char> temp(char_len);
|
||||||
|
WideCharToMultiByte(locale, 0, input.c_str(), -1, &temp[0], char_len, 0, 0);
|
||||||
|
return std::string(&temp[0]);
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string WcharToUtf8(wchar_t *wstr) {
|
||||||
|
int c_size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, FALSE);
|
||||||
|
if (c_size > 0) {
|
||||||
|
char *buffer = new char[c_size];
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, buffer, c_size, NULL, FALSE);
|
||||||
|
std::string str(buffer);
|
||||||
|
delete[] buffer;
|
||||||
|
buffer = NULL;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringToHex(const std::string &str) {
|
||||||
|
std::string sb;
|
||||||
|
for (int i = 0; i < str.length(); i++) {
|
||||||
|
sb += hex_table.at((str[i] & 0xf0) >> 4);
|
||||||
|
sb += hex_table.at((str[i] & 0x0f) >> 0);
|
||||||
|
}
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string HexToString(const std::string &hex_str) {
|
||||||
|
std::string ret;
|
||||||
|
for (int i = 0; i < hex_str.length(); i += 2) {
|
||||||
|
ret += BYTE(hex_table.find(hex_str.at(i)) << 4 |
|
||||||
|
hex_table.find(hex_str.at(i + 1)));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BytesToHex(const BYTE *bytes, const int length) {
|
||||||
|
if (bytes == NULL) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::string buff;
|
||||||
|
const int len = length;
|
||||||
|
for (int j = 0; j < len; j++) {
|
||||||
|
int high = bytes[j] / 16, low = bytes[j] % 16;
|
||||||
|
buff += (high < 10) ? ('0' + high) : ('a' + high - 10);
|
||||||
|
buff += (low < 10) ? ('0' + low) : ('a' + low - 10);
|
||||||
|
}
|
||||||
|
return buff;
|
||||||
|
}
|
||||||
|
void HexToBytes(const std::string &hex, BYTE *bytes) {
|
||||||
|
int byte_len = hex.length() / 2;
|
||||||
|
std::string str;
|
||||||
|
unsigned int n;
|
||||||
|
for (int i = 0; i < byte_len; i++) {
|
||||||
|
str = hex.substr(i * 2, 2);
|
||||||
|
sscanf_s(str.c_str(), "%x", &n);
|
||||||
|
bytes[i] = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CreateConsole() {
|
||||||
|
if (AllocConsole()) {
|
||||||
|
AttachConsole(GetCurrentProcessId());
|
||||||
|
FILE *retStream;
|
||||||
|
freopen_s(&retStream, "CONOUT$", "w", stdout);
|
||||||
|
if (!retStream) throw std::runtime_error("Stdout redirection failed.");
|
||||||
|
freopen_s(&retStream, "CONOUT$", "w", stderr);
|
||||||
|
if (!retStream) throw std::runtime_error("Stderr redirection failed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseConsole() {
|
||||||
|
fclose(stdin);
|
||||||
|
fclose(stdout);
|
||||||
|
fclose(stderr);
|
||||||
|
FreeConsole();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HideModule(HMODULE module) {
|
||||||
|
#ifdef _WIN64
|
||||||
|
PPEB peb = (PPEB)__readgsqword(0x60);
|
||||||
|
PPEB_LDR_DATA ldr = peb->Ldr;
|
||||||
|
|
||||||
|
void *cur_ptr = *((void **)((unsigned char *)ldr + 0x18));
|
||||||
|
void *next_ptr = cur_ptr;
|
||||||
|
do {
|
||||||
|
void *next = *((void **)((unsigned char *)next_ptr));
|
||||||
|
void *last = *((void **)((unsigned char *)next_ptr + 0x8));
|
||||||
|
void *base_addr = *((void **)((unsigned char *)next_ptr + 0x30));
|
||||||
|
if (base_addr == module) {
|
||||||
|
*((void **)((unsigned char *)last)) = next;
|
||||||
|
*((void **)((unsigned char *)next + 0x8)) = last;
|
||||||
|
cur_ptr = next;
|
||||||
|
}
|
||||||
|
next_ptr = *((void **)next_ptr);
|
||||||
|
} while (cur_ptr != next_ptr);
|
||||||
|
#else
|
||||||
|
void *peb_ptr = nullptr;
|
||||||
|
_asm {
|
||||||
|
PUSH EAX
|
||||||
|
MOV EAX, FS:[0x30]
|
||||||
|
MOV peb_ptr, EAX
|
||||||
|
POP EAX
|
||||||
|
}
|
||||||
|
void *ldr_ptr = *((void **)((unsigned char *)peb_ptr + 0xc));
|
||||||
|
void *cur_ptr = *((void **)((unsigned char *)ldr_ptr + 0x0c));
|
||||||
|
void *next_ptr = cur_ptr;
|
||||||
|
do {
|
||||||
|
void *next = *((void **)((unsigned char *)next_ptr));
|
||||||
|
void *last = *((void **)((unsigned char *)next_ptr + 0x4));
|
||||||
|
void *base_addr = *((void **)((unsigned char *)next_ptr + 0x18));
|
||||||
|
if (base_addr == module) {
|
||||||
|
*((void **)((unsigned char *)last)) = next;
|
||||||
|
*((void **)((unsigned char *)next + 0x4)) = last;
|
||||||
|
cur_ptr = next;
|
||||||
|
}
|
||||||
|
next_ptr = *((void **)next_ptr);
|
||||||
|
} while (cur_ptr != next_ptr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsDigit(const std::string &str) {
|
||||||
|
if (str.length() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (auto it : str) {
|
||||||
|
if (it < '0' || it > '9') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Bytes2Hex(const BYTE *bytes, const int length) {
|
||||||
|
if (bytes == NULL) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::string buff;
|
||||||
|
const int len = length;
|
||||||
|
for (int j = 0; j < len; j++) {
|
||||||
|
int high = bytes[j] / 16, low = bytes[j] % 16;
|
||||||
|
buff += (high < 10) ? ('0' + high) : ('a' + high - 10);
|
||||||
|
buff += (low < 10) ? ('0' + low) : ('a' + low - 10);
|
||||||
|
}
|
||||||
|
return buff;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsTextUtf8(const char *str, INT64 length) {
|
||||||
|
char endian = 1;
|
||||||
|
bool littlen_endian = (*(char *)&endian == 1);
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
int bytes_num;
|
||||||
|
unsigned char chr;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
bytes_num = 0;
|
||||||
|
while (i < length) {
|
||||||
|
if (littlen_endian) {
|
||||||
|
chr = *(str + i);
|
||||||
|
} else { // Big Endian
|
||||||
|
chr = (*(str + i) << 8) | *(str + i + 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytes_num == 0) {
|
||||||
|
if ((chr & 0x80) != 0) {
|
||||||
|
while ((chr & 0x80) != 0) {
|
||||||
|
chr <<= 1;
|
||||||
|
bytes_num++;
|
||||||
|
}
|
||||||
|
if ((bytes_num < 2) || (bytes_num > 6)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bytes_num--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((chr & 0xC0) != 0x80) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bytes_num--;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (bytes_num == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
} // namespace base
|
20
app/injector/CMakeLists.txt
Normal file
20
app/injector/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0.0)
|
||||||
|
project(injector VERSION 1.0.0)
|
||||||
|
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D '_UNICODE' /D 'UNICODE'")
|
||||||
|
|
||||||
|
file(GLOB INJECT_CPP_FILES ${PROJECT_SOURCE_DIR}/src/*.cc ${PROJECT_SOURCE_DIR}/src/*.cpp)
|
||||||
|
|
||||||
|
add_executable (injector ${INJECT_CPP_FILES})
|
||||||
|
|
||||||
|
SET_TARGET_PROPERTIES(injector PROPERTIES LINKER_LANGUAGE C
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
|
||||||
|
OUTPUT_NAME "injector"
|
||||||
|
PREFIX "")
|
||||||
|
|
659
app/injector/src/getopt.h
Normal file
659
app/injector/src/getopt.h
Normal file
@ -0,0 +1,659 @@
|
|||||||
|
#ifndef __GETOPT_H__
|
||||||
|
/**
|
||||||
|
* DISCLAIMER
|
||||||
|
* This file is part of the mingw-w64 runtime package.
|
||||||
|
*
|
||||||
|
* The mingw-w64 runtime package and its code is distributed in the hope that it
|
||||||
|
* will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
|
||||||
|
* IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
|
||||||
|
* warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* Sponsored in part by the Defense Advanced Research Projects
|
||||||
|
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||||
|
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||||
|
*/
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Dieter Baron and Thomas Klausner.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma warning(disable:4996);
|
||||||
|
|
||||||
|
#define __GETOPT_H__
|
||||||
|
|
||||||
|
/* All the headers include this file. */
|
||||||
|
#include <crtdefs.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
|
||||||
|
|
||||||
|
#ifdef REPLACE_GETOPT
|
||||||
|
int opterr = 1; /* if error message should be printed */
|
||||||
|
int optind = 1; /* index into parent argv vector */
|
||||||
|
int optopt = '?'; /* character checked for validity */
|
||||||
|
#undef optreset /* see getopt.h */
|
||||||
|
#define optreset __mingw_optreset
|
||||||
|
int optreset; /* reset getopt */
|
||||||
|
char* optarg; /* argument associated with option */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//extern int optind; /* index of first non-option in argv */
|
||||||
|
//extern int optopt; /* single option character, as parsed */
|
||||||
|
//extern int opterr; /* flag to enable built-in diagnostics... */
|
||||||
|
// /* (user may set to zero, to suppress) */
|
||||||
|
//
|
||||||
|
//extern char *optarg; /* pointer to argument of current option */
|
||||||
|
|
||||||
|
#define PRINT_ERROR ((opterr) && (*options != ':'))
|
||||||
|
|
||||||
|
#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
|
||||||
|
#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
|
||||||
|
#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
|
||||||
|
|
||||||
|
/* return values */
|
||||||
|
#define BADCH (int)'?'
|
||||||
|
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
|
||||||
|
#define INORDER (int)1
|
||||||
|
|
||||||
|
#ifndef __CYGWIN__
|
||||||
|
#define __progname __argv[0]
|
||||||
|
#else
|
||||||
|
extern char __declspec(dllimport)* __progname;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
static char EMSG[] = "";
|
||||||
|
#else
|
||||||
|
#define EMSG ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int getopt_internal(int, char* const*, const char*,
|
||||||
|
const struct option*, int*, int);
|
||||||
|
static int parse_long_options(char* const*, const char*,
|
||||||
|
const struct option*, int*, int);
|
||||||
|
static int gcd(int, int);
|
||||||
|
static void permute_args(int, int, int, char* const*);
|
||||||
|
|
||||||
|
static char* place = EMSG; /* option letter processing */
|
||||||
|
|
||||||
|
/* XXX: set optreset to 1 rather than these two */
|
||||||
|
static int nonopt_start = -1; /* first non option argument (for permute) */
|
||||||
|
static int nonopt_end = -1; /* first option after non options (for permute) */
|
||||||
|
|
||||||
|
/* Error messages */
|
||||||
|
static const char recargchar[] = "option requires an argument -- %c";
|
||||||
|
static const char recargstring[] = "option requires an argument -- %s";
|
||||||
|
static const char ambig[] = "ambiguous option -- %.*s";
|
||||||
|
static const char noarg[] = "option doesn't take an argument -- %.*s";
|
||||||
|
static const char illoptchar[] = "unknown option -- %c";
|
||||||
|
static const char illoptstring[] = "unknown option -- %s";
|
||||||
|
|
||||||
|
static void
|
||||||
|
_vwarnx(const char* fmt, va_list ap)
|
||||||
|
{
|
||||||
|
(void)fprintf(stderr, "%s: ", __progname);
|
||||||
|
if (fmt != NULL)
|
||||||
|
(void)vfprintf(stderr, fmt, ap);
|
||||||
|
(void)fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
warnx(const char* fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
_vwarnx(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compute the greatest common divisor of a and b.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
gcd(int a, int b)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = a % b;
|
||||||
|
while (c != 0) {
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
c = a % b;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Exchange the block from nonopt_start to nonopt_end with the block
|
||||||
|
* from nonopt_end to opt_end (keeping the same order of arguments
|
||||||
|
* in each block).
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
permute_args(int panonopt_start, int panonopt_end, int opt_end,
|
||||||
|
char* const* nargv)
|
||||||
|
{
|
||||||
|
int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
|
||||||
|
char* swap;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* compute lengths of blocks and number and size of cycles
|
||||||
|
*/
|
||||||
|
nnonopts = panonopt_end - panonopt_start;
|
||||||
|
nopts = opt_end - panonopt_end;
|
||||||
|
ncycle = gcd(nnonopts, nopts);
|
||||||
|
cyclelen = (opt_end - panonopt_start) / ncycle;
|
||||||
|
|
||||||
|
for (i = 0; i < ncycle; i++) {
|
||||||
|
cstart = panonopt_end + i;
|
||||||
|
pos = cstart;
|
||||||
|
for (j = 0; j < cyclelen; j++) {
|
||||||
|
if (pos >= panonopt_end)
|
||||||
|
pos -= nnonopts;
|
||||||
|
else
|
||||||
|
pos += nopts;
|
||||||
|
swap = nargv[pos];
|
||||||
|
/* LINTED const cast */
|
||||||
|
((char**)nargv)[pos] = nargv[cstart];
|
||||||
|
/* LINTED const cast */
|
||||||
|
((char**)nargv)[cstart] = swap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef REPLACE_GETOPT
|
||||||
|
/*
|
||||||
|
* getopt --
|
||||||
|
* Parse argc/argv argument vector.
|
||||||
|
*
|
||||||
|
* [eventually this will replace the BSD getopt]
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
getopt(int nargc, char* const* nargv, const char* options)
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We don't pass FLAG_PERMUTE to getopt_internal() since
|
||||||
|
* the BSD getopt(3) (unlike GNU) has never done this.
|
||||||
|
*
|
||||||
|
* Furthermore, since many privileged programs call getopt()
|
||||||
|
* before dropping privileges it makes sense to keep things
|
||||||
|
* as simple (and bug-free) as possible.
|
||||||
|
*/
|
||||||
|
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
|
||||||
|
}
|
||||||
|
#endif /* REPLACE_GETOPT */
|
||||||
|
|
||||||
|
//extern int getopt(int nargc, char * const *nargv, const char *options);
|
||||||
|
|
||||||
|
#ifdef _BSD_SOURCE
|
||||||
|
/*
|
||||||
|
* BSD adds the non-standard `optreset' feature, for reinitialisation
|
||||||
|
* of `getopt' parsing. We support this feature, for applications which
|
||||||
|
* proclaim their BSD heritage, before including this header; however,
|
||||||
|
* to maintain portability, developers are advised to avoid it.
|
||||||
|
*/
|
||||||
|
# define optreset __mingw_optreset
|
||||||
|
extern int optreset;
|
||||||
|
#endif
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* POSIX requires the `getopt' API to be specified in `unistd.h';
|
||||||
|
* thus, `unistd.h' includes this header. However, we do not want
|
||||||
|
* to expose the `getopt_long' or `getopt_long_only' APIs, when
|
||||||
|
* included in this manner. Thus, close the standard __GETOPT_H__
|
||||||
|
* declarations block, and open an additional __GETOPT_LONG_H__
|
||||||
|
* specific block, only when *not* __UNISTD_H_SOURCED__, in which
|
||||||
|
* to declare the extended API.
|
||||||
|
*/
|
||||||
|
#endif /* !defined(__GETOPT_H__) */
|
||||||
|
|
||||||
|
#if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
|
||||||
|
#define __GETOPT_LONG_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct option /* specification for a long form option... */
|
||||||
|
{
|
||||||
|
const char* name; /* option name, without leading hyphens */
|
||||||
|
int has_arg; /* does it take an argument? */
|
||||||
|
int* flag; /* where to save its status, or NULL */
|
||||||
|
int val; /* its associated status value */
|
||||||
|
};
|
||||||
|
|
||||||
|
enum /* permitted values for its `has_arg' field... */
|
||||||
|
{
|
||||||
|
no_argument = 0, /* option never takes an argument */
|
||||||
|
required_argument, /* option always requires an argument */
|
||||||
|
optional_argument /* option may take an argument */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* parse_long_options --
|
||||||
|
* Parse long options in argc/argv argument vector.
|
||||||
|
* Returns -1 if short_too is set and the option does not match long_options.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
parse_long_options(char* const* nargv, const char* options,
|
||||||
|
const struct option* long_options, int* idx, int short_too)
|
||||||
|
{
|
||||||
|
char* current_argv, * has_equal;
|
||||||
|
size_t current_argv_len;
|
||||||
|
int i, ambiguous, match;
|
||||||
|
|
||||||
|
#define IDENTICAL_INTERPRETATION(_x, _y) \
|
||||||
|
(long_options[(_x)].has_arg == long_options[(_y)].has_arg && \
|
||||||
|
long_options[(_x)].flag == long_options[(_y)].flag && \
|
||||||
|
long_options[(_x)].val == long_options[(_y)].val)
|
||||||
|
|
||||||
|
current_argv = place;
|
||||||
|
match = -1;
|
||||||
|
ambiguous = 0;
|
||||||
|
|
||||||
|
optind++;
|
||||||
|
|
||||||
|
if ((has_equal = strchr(current_argv, '=')) != NULL) {
|
||||||
|
/* argument found (--option=arg) */
|
||||||
|
current_argv_len = has_equal - current_argv;
|
||||||
|
has_equal++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
current_argv_len = strlen(current_argv);
|
||||||
|
|
||||||
|
for (i = 0; long_options[i].name; i++) {
|
||||||
|
/* find matching long option */
|
||||||
|
if (strncmp(current_argv, long_options[i].name,
|
||||||
|
current_argv_len))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (strlen(long_options[i].name) == current_argv_len) {
|
||||||
|
/* exact match */
|
||||||
|
match = i;
|
||||||
|
ambiguous = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* If this is a known short option, don't allow
|
||||||
|
* a partial match of a single character.
|
||||||
|
*/
|
||||||
|
if (short_too && current_argv_len == 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (match == -1) /* partial match */
|
||||||
|
match = i;
|
||||||
|
else if (!IDENTICAL_INTERPRETATION(i, match))
|
||||||
|
ambiguous = 1;
|
||||||
|
}
|
||||||
|
if (ambiguous) {
|
||||||
|
/* ambiguous abbreviation */
|
||||||
|
if (PRINT_ERROR)
|
||||||
|
warnx(ambig, (int)current_argv_len,
|
||||||
|
current_argv);
|
||||||
|
optopt = 0;
|
||||||
|
return (BADCH);
|
||||||
|
}
|
||||||
|
if (match != -1) { /* option found */
|
||||||
|
if (long_options[match].has_arg == no_argument
|
||||||
|
&& has_equal) {
|
||||||
|
if (PRINT_ERROR)
|
||||||
|
warnx(noarg, (int)current_argv_len,
|
||||||
|
current_argv);
|
||||||
|
/*
|
||||||
|
* XXX: GNU sets optopt to val regardless of flag
|
||||||
|
*/
|
||||||
|
if (long_options[match].flag == NULL)
|
||||||
|
optopt = long_options[match].val;
|
||||||
|
else
|
||||||
|
optopt = 0;
|
||||||
|
return (BADARG);
|
||||||
|
}
|
||||||
|
if (long_options[match].has_arg == required_argument ||
|
||||||
|
long_options[match].has_arg == optional_argument) {
|
||||||
|
if (has_equal)
|
||||||
|
optarg = has_equal;
|
||||||
|
else if (long_options[match].has_arg ==
|
||||||
|
required_argument) {
|
||||||
|
/*
|
||||||
|
* optional argument doesn't use next nargv
|
||||||
|
*/
|
||||||
|
optarg = nargv[optind++];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((long_options[match].has_arg == required_argument)
|
||||||
|
&& (optarg == NULL)) {
|
||||||
|
/*
|
||||||
|
* Missing argument; leading ':' indicates no error
|
||||||
|
* should be generated.
|
||||||
|
*/
|
||||||
|
if (PRINT_ERROR)
|
||||||
|
warnx(recargstring,
|
||||||
|
current_argv);
|
||||||
|
/*
|
||||||
|
* XXX: GNU sets optopt to val regardless of flag
|
||||||
|
*/
|
||||||
|
if (long_options[match].flag == NULL)
|
||||||
|
optopt = long_options[match].val;
|
||||||
|
else
|
||||||
|
optopt = 0;
|
||||||
|
--optind;
|
||||||
|
return (BADARG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { /* unknown option */
|
||||||
|
if (short_too) {
|
||||||
|
--optind;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (PRINT_ERROR)
|
||||||
|
warnx(illoptstring, current_argv);
|
||||||
|
optopt = 0;
|
||||||
|
return (BADCH);
|
||||||
|
}
|
||||||
|
if (idx)
|
||||||
|
*idx = match;
|
||||||
|
if (long_options[match].flag) {
|
||||||
|
*long_options[match].flag = long_options[match].val;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (long_options[match].val);
|
||||||
|
#undef IDENTICAL_INTERPRETATION
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getopt_internal --
|
||||||
|
* Parse argc/argv argument vector. Called by user level routines.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
getopt_internal(int nargc, char* const* nargv, const char* options,
|
||||||
|
const struct option* long_options, int* idx, int flags)
|
||||||
|
{
|
||||||
|
char* oli; /* option letter list index */
|
||||||
|
int optchar, short_too;
|
||||||
|
static int posixly_correct = -1;
|
||||||
|
|
||||||
|
if (options == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX Some GNU programs (like cvs) set optind to 0 instead of
|
||||||
|
* XXX using optreset. Work around this braindamage.
|
||||||
|
*/
|
||||||
|
if (optind == 0)
|
||||||
|
optind = optreset = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disable GNU extensions if POSIXLY_CORRECT is set or options
|
||||||
|
* string begins with a '+'.
|
||||||
|
*
|
||||||
|
* CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or
|
||||||
|
* optreset != 0 for GNU compatibility.
|
||||||
|
*/
|
||||||
|
if (posixly_correct == -1 || optreset != 0)
|
||||||
|
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
|
||||||
|
if (*options == '-')
|
||||||
|
flags |= FLAG_ALLARGS;
|
||||||
|
else if (posixly_correct || *options == '+')
|
||||||
|
flags &= ~FLAG_PERMUTE;
|
||||||
|
if (*options == '+' || *options == '-')
|
||||||
|
options++;
|
||||||
|
|
||||||
|
optarg = NULL;
|
||||||
|
if (optreset)
|
||||||
|
nonopt_start = nonopt_end = -1;
|
||||||
|
start:
|
||||||
|
if (optreset || !*place) { /* update scanning pointer */
|
||||||
|
optreset = 0;
|
||||||
|
if (optind >= nargc) { /* end of argument vector */
|
||||||
|
place = EMSG;
|
||||||
|
if (nonopt_end != -1) {
|
||||||
|
/* do permutation, if we have to */
|
||||||
|
permute_args(nonopt_start, nonopt_end,
|
||||||
|
optind, nargv);
|
||||||
|
optind -= nonopt_end - nonopt_start;
|
||||||
|
}
|
||||||
|
else if (nonopt_start != -1) {
|
||||||
|
/*
|
||||||
|
* If we skipped non-options, set optind
|
||||||
|
* to the first of them.
|
||||||
|
*/
|
||||||
|
optind = nonopt_start;
|
||||||
|
}
|
||||||
|
nonopt_start = nonopt_end = -1;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (*(place = nargv[optind]) != '-' ||
|
||||||
|
(place[1] == '\0' && strchr(options, '-') == NULL)) {
|
||||||
|
place = EMSG; /* found non-option */
|
||||||
|
if (flags & FLAG_ALLARGS) {
|
||||||
|
/*
|
||||||
|
* GNU extension:
|
||||||
|
* return non-option as argument to option 1
|
||||||
|
*/
|
||||||
|
optarg = nargv[optind++];
|
||||||
|
return (INORDER);
|
||||||
|
}
|
||||||
|
if (!(flags & FLAG_PERMUTE)) {
|
||||||
|
/*
|
||||||
|
* If no permutation wanted, stop parsing
|
||||||
|
* at first non-option.
|
||||||
|
*/
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
/* do permutation */
|
||||||
|
if (nonopt_start == -1)
|
||||||
|
nonopt_start = optind;
|
||||||
|
else if (nonopt_end != -1) {
|
||||||
|
permute_args(nonopt_start, nonopt_end,
|
||||||
|
optind, nargv);
|
||||||
|
nonopt_start = optind -
|
||||||
|
(nonopt_end - nonopt_start);
|
||||||
|
nonopt_end = -1;
|
||||||
|
}
|
||||||
|
optind++;
|
||||||
|
/* process next argument */
|
||||||
|
goto start;
|
||||||
|
}
|
||||||
|
if (nonopt_start != -1 && nonopt_end == -1)
|
||||||
|
nonopt_end = optind;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we have "-" do nothing, if "--" we are done.
|
||||||
|
*/
|
||||||
|
if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
|
||||||
|
optind++;
|
||||||
|
place = EMSG;
|
||||||
|
/*
|
||||||
|
* We found an option (--), so if we skipped
|
||||||
|
* non-options, we have to permute.
|
||||||
|
*/
|
||||||
|
if (nonopt_end != -1) {
|
||||||
|
permute_args(nonopt_start, nonopt_end,
|
||||||
|
optind, nargv);
|
||||||
|
optind -= nonopt_end - nonopt_start;
|
||||||
|
}
|
||||||
|
nonopt_start = nonopt_end = -1;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check long options if:
|
||||||
|
* 1) we were passed some
|
||||||
|
* 2) the arg is not just "-"
|
||||||
|
* 3) either the arg starts with -- we are getopt_long_only()
|
||||||
|
*/
|
||||||
|
if (long_options != NULL && place != nargv[optind] &&
|
||||||
|
(*place == '-' || (flags & FLAG_LONGONLY))) {
|
||||||
|
short_too = 0;
|
||||||
|
if (*place == '-')
|
||||||
|
place++; /* --foo long option */
|
||||||
|
else if (*place != ':' && strchr(options, *place) != NULL)
|
||||||
|
short_too = 1; /* could be short option too */
|
||||||
|
|
||||||
|
optchar = parse_long_options(nargv, options, long_options,
|
||||||
|
idx, short_too);
|
||||||
|
if (optchar != -1) {
|
||||||
|
place = EMSG;
|
||||||
|
return (optchar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((optchar = (int)*place++) == (int)':' ||
|
||||||
|
(optchar == (int)'-' && *place != '\0') ||
|
||||||
|
(oli = (char*)strchr(options, optchar)) == NULL) {
|
||||||
|
/*
|
||||||
|
* If the user specified "-" and '-' isn't listed in
|
||||||
|
* options, return -1 (non-option) as per POSIX.
|
||||||
|
* Otherwise, it is an unknown option character (or ':').
|
||||||
|
*/
|
||||||
|
if (optchar == (int)'-' && *place == '\0')
|
||||||
|
return (-1);
|
||||||
|
if (!*place)
|
||||||
|
++optind;
|
||||||
|
if (PRINT_ERROR)
|
||||||
|
warnx(illoptchar, optchar);
|
||||||
|
optopt = optchar;
|
||||||
|
return (BADCH);
|
||||||
|
}
|
||||||
|
if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
|
||||||
|
/* -W long-option */
|
||||||
|
if (*place) /* no space */
|
||||||
|
/* NOTHING */;
|
||||||
|
else if (++optind >= nargc) { /* no arg */
|
||||||
|
place = EMSG;
|
||||||
|
if (PRINT_ERROR)
|
||||||
|
warnx(recargchar, optchar);
|
||||||
|
optopt = optchar;
|
||||||
|
return (BADARG);
|
||||||
|
}
|
||||||
|
else /* white space */
|
||||||
|
place = nargv[optind];
|
||||||
|
optchar = parse_long_options(nargv, options, long_options,
|
||||||
|
idx, 0);
|
||||||
|
place = EMSG;
|
||||||
|
return (optchar);
|
||||||
|
}
|
||||||
|
if (*++oli != ':') { /* doesn't take argument */
|
||||||
|
if (!*place)
|
||||||
|
++optind;
|
||||||
|
}
|
||||||
|
else { /* takes (optional) argument */
|
||||||
|
optarg = NULL;
|
||||||
|
if (*place) /* no white space */
|
||||||
|
optarg = place;
|
||||||
|
else if (oli[1] != ':') { /* arg not optional */
|
||||||
|
if (++optind >= nargc) { /* no arg */
|
||||||
|
place = EMSG;
|
||||||
|
if (PRINT_ERROR)
|
||||||
|
warnx(recargchar, optchar);
|
||||||
|
optopt = optchar;
|
||||||
|
return (BADARG);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
optarg = nargv[optind];
|
||||||
|
}
|
||||||
|
place = EMSG;
|
||||||
|
++optind;
|
||||||
|
}
|
||||||
|
/* dump back option letter */
|
||||||
|
return (optchar);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getopt_long --
|
||||||
|
* Parse argc/argv argument vector.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
getopt_long(int nargc, char* const* nargv, const char* options,
|
||||||
|
const struct option* long_options, int* idx)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (getopt_internal(nargc, nargv, options, long_options, idx,
|
||||||
|
FLAG_PERMUTE));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getopt_long_only --
|
||||||
|
* Parse argc/argv argument vector.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
getopt_long_only(int nargc, char* const* nargv, const char* options,
|
||||||
|
const struct option* long_options, int* idx)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (getopt_internal(nargc, nargv, options, long_options, idx,
|
||||||
|
FLAG_PERMUTE | FLAG_LONGONLY));
|
||||||
|
}
|
||||||
|
|
||||||
|
//extern int getopt_long(int nargc, char * const *nargv, const char *options,
|
||||||
|
// const struct option *long_options, int *idx);
|
||||||
|
//extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
|
||||||
|
// const struct option *long_options, int *idx);
|
||||||
|
/*
|
||||||
|
* Previous MinGW implementation had...
|
||||||
|
*/
|
||||||
|
#ifndef HAVE_DECL_GETOPT
|
||||||
|
/*
|
||||||
|
* ...for the long form API only; keep this for compatibility.
|
||||||
|
*/
|
||||||
|
# define HAVE_DECL_GETOPT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */
|
1170
app/injector/src/injector.cc
Normal file
1170
app/injector/src/injector.cc
Normal file
File diff suppressed because it is too large
Load Diff
60
app/wxhelper/CMakeLists.txt
Normal file
60
app/wxhelper/CMakeLists.txt
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10...3.27)
|
||||||
|
project(wxhelper VERSION 1.0.0)
|
||||||
|
# enable_language(ASM_MASM)
|
||||||
|
# add_compile_options("/experimental:module")
|
||||||
|
|
||||||
|
message(${CMAKE_VERSION})
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /MD /EHsc")
|
||||||
|
file(GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c )
|
||||||
|
|
||||||
|
file(GLOB ASM_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.asm )
|
||||||
|
|
||||||
|
include_directories(${VCPKG_INSTALLED_DIR}/x64-windows/include ${DETOURS_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
|
||||||
|
add_subdirectory(../3rdparty 3rdparty)
|
||||||
|
|
||||||
|
add_subdirectory(../base base)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
find_path(DETOURS_INCLUDE_DIRS "detours/detours.h")
|
||||||
|
find_library(DETOURS_LIBRARY detours REQUIRED)
|
||||||
|
|
||||||
|
find_package(nlohmann_json CONFIG REQUIRED)
|
||||||
|
|
||||||
|
add_library(wxhelper SHARED ${CPP_FILES} ${ASM_FILES})
|
||||||
|
message(11233)
|
||||||
|
message(${PROJECT_SOURCE_DIR})
|
||||||
|
target_include_directories(wxhelper
|
||||||
|
PRIVATE ${DETOURS_INCLUDE_DIRS}
|
||||||
|
PRIVATE ../base/src/include
|
||||||
|
PRIVATE ../3rdparty/spdlog/include
|
||||||
|
PRIVATE ../3rdparty/base64
|
||||||
|
PRIVATE ../3rdparty/lz4
|
||||||
|
PRIVATE ../3rdparty/mongoose
|
||||||
|
PRIVATE ../base/src/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(wxhelper
|
||||||
|
PRIVATE ${DETOURS_LIBRARY}
|
||||||
|
PRIVATE spdlog::spdlog
|
||||||
|
PRIVATE lz4
|
||||||
|
PRIVATE base64
|
||||||
|
PRIVATE mongoose
|
||||||
|
PRIVATE nlohmann_json::nlohmann_json
|
||||||
|
PRIVATE base
|
||||||
|
)
|
||||||
|
|
||||||
|
SET_TARGET_PROPERTIES(wxhelper PROPERTIES LINKER_LANGUAGE C
|
||||||
|
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
|
||||||
|
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
|
||||||
|
OUTPUT_NAME "wxhelper"
|
||||||
|
PREFIX "")
|
||||||
|
|
30
app/wxhelper/src/config.cc
Normal file
30
app/wxhelper/src/config.cc
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "spdlog/sinks/daily_file_sink.h"
|
||||||
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "windows.h"
|
||||||
|
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
||||||
|
namespace wxhelper {
|
||||||
|
Config::Config(/* args */) {}
|
||||||
|
|
||||||
|
Config::~Config() {}
|
||||||
|
|
||||||
|
void Config::Initialize() {
|
||||||
|
port_ = GetPrivateProfileInt("config", "Port", 19088, "./config.ini");
|
||||||
|
hidden_dll_ =
|
||||||
|
GetPrivateProfileInt("config", "HiddenDll", 1, "./config.ini");
|
||||||
|
auto logger =
|
||||||
|
spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 23, 59);
|
||||||
|
logger->flush_on(spdlog::level::err);
|
||||||
|
spdlog::set_default_logger(logger);
|
||||||
|
spdlog::flush_every(std::chrono::seconds(3));
|
||||||
|
spdlog::set_level(spdlog::level::debug);
|
||||||
|
spdlog::set_pattern("%Y-%m-%d %H:%M:%S [%l] [%t] - <%s>|<%#>|<%!>,%v");
|
||||||
|
}
|
||||||
|
int Config::GetPort() { return port_; }
|
||||||
|
|
||||||
|
int Config::GetHideDll() { return hidden_dll_; }
|
||||||
|
|
||||||
|
} // namespace wxhelper
|
@ -1,4 +1,4 @@
|
|||||||
#ifndef WXHELPER_CONFIG_H_
|
#ifndef WXHELPER_CONFIG_H_
|
||||||
#define WXHELPER_CONFIG_H_
|
#define WXHELPER_CONFIG_H_
|
||||||
|
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
@ -9,9 +9,11 @@ class Config {
|
|||||||
~Config();
|
~Config();
|
||||||
void Initialize();
|
void Initialize();
|
||||||
int GetPort();
|
int GetPort();
|
||||||
|
int GetHideDll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int port_;
|
int port_;
|
||||||
|
int hidden_dll_;
|
||||||
};
|
};
|
||||||
} // namespace wxhelper
|
} // namespace wxhelper
|
||||||
#endif
|
#endif
|
@ -1,21 +1,11 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
|
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "wechat_function.h"
|
#include "spdlog/spdlog.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
namespace offset = wxhelper::V3_9_7_29::offset;
|
||||||
namespace offset = wxhelper::V3_9_5_81::offset;
|
|
||||||
|
|
||||||
|
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
|
|
||||||
void DB::init(UINT64 base) {
|
|
||||||
base_addr_ = base;
|
|
||||||
dbmap_ = {};
|
|
||||||
dbs_ = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
void FreeResult(std::vector<std::vector<common::SqlResult>> &data) {
|
void FreeResult(std::vector<std::vector<common::SqlResult>> &data) {
|
||||||
if (data.size() == 0) {
|
if (data.size() == 0) {
|
||||||
return;
|
return;
|
||||||
@ -37,23 +27,25 @@ void FreeResult(std::vector<std::vector<common::SqlResult>> &data) {
|
|||||||
data.clear();
|
data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DB::SelectDataInner(UINT64 db, const char *sql,
|
int DB::ExecSelect(UINT64 db, const char *sql,
|
||||||
std::vector<std::vector<common::SqlResult>> &data) {
|
std::vector<std::vector<common::SqlResult>> &data) {
|
||||||
common::sqlite3_prepare p_sqlite3_prepare =
|
common::sqlite3_prepare p_sqlite3_prepare =
|
||||||
(common::sqlite3_prepare)(base_addr_ + offset::k_sqlite3_prepare);
|
(common::sqlite3_prepare)(base_addr_ + offset::k_sqlite3_prepare);
|
||||||
common::sqlite3_step p_sqlite3_step =
|
common::sqlite3_step p_sqlite3_step =
|
||||||
(common::sqlite3_step)(base_addr_ + offset::k_sqlite3_step);
|
(common::sqlite3_step)(base_addr_ + offset::k_sqlite3_step);
|
||||||
common::sqlite3_column_count p_sqlite3_column_count =
|
common::sqlite3_column_count p_sqlite3_column_count =
|
||||||
(common::sqlite3_column_count)(base_addr_ + offset::k_sqlite3_column_count);
|
(common::sqlite3_column_count)(base_addr_ +
|
||||||
|
offset::k_sqlite3_column_count);
|
||||||
common::sqlite3_column_name p_sqlite3_column_name =
|
common::sqlite3_column_name p_sqlite3_column_name =
|
||||||
(common::sqlite3_column_name)(base_addr_ + offset::k_sqlite3_column_name);
|
(common::sqlite3_column_name)(base_addr_ + offset::k_sqlite3_column_name);
|
||||||
common::sqlite3_column_type p_sqlite3_column_type =
|
common::sqlite3_column_type p_sqlite3_column_type =
|
||||||
(common::sqlite3_column_type)(base_addr_ + offset::k_sqlite3_column_type);
|
(common::sqlite3_column_type)(base_addr_ + offset::k_sqlite3_column_type);
|
||||||
common::sqlite3_column_blob p_sqlite3_column_blob =
|
common::sqlite3_column_blob p_sqlite3_column_blob =
|
||||||
(common::sqlite3_column_blob)(base_addr_ + offset::k_sqlite3_column_blob);
|
(common::sqlite3_column_blob)(base_addr_ + offset::k_sqlite3_column_blob);
|
||||||
common::sqlite3_column_bytes p_sqlite3_column_bytes =
|
common::sqlite3_column_bytes p_sqlite3_column_bytes =
|
||||||
(common::sqlite3_column_bytes)(base_addr_ + offset::k_sqlite3_column_bytes);
|
(common::sqlite3_column_bytes)(base_addr_ +
|
||||||
common::sqlite3_finalize p_sqlite3_finalize =
|
offset::k_sqlite3_column_bytes);
|
||||||
|
common::sqlite3_finalize p_sqlite3_finalize =
|
||||||
(common::sqlite3_finalize)(base_addr_ + offset::k_sqlite3_finalize);
|
(common::sqlite3_finalize)(base_addr_ + offset::k_sqlite3_finalize);
|
||||||
UINT64 *stmt;
|
UINT64 *stmt;
|
||||||
int rc = p_sqlite3_prepare(db, sql, -1, &stmt, 0);
|
int rc = p_sqlite3_prepare(db, sql, -1, &stmt, 0);
|
||||||
@ -101,9 +93,9 @@ int DB::SelectDataInner(UINT64 db, const char *sql,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DB::Select(UINT64 db_hanle, const char *sql,
|
int DB::Select(UINT64 db_hanle, const char *sql,
|
||||||
std::vector<std::vector<std::string>> &query_result) {
|
std::vector<std::vector<std::string>> &query_result) {
|
||||||
std::vector<std::vector<common::SqlResult>> data;
|
std::vector<std::vector<common::SqlResult>> data;
|
||||||
int status = SelectDataInner(db_hanle, sql, data);
|
int status = ExecSelect(db_hanle, sql, data);
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -120,7 +112,8 @@ int DB::Select(UINT64 db_hanle, const char *sql,
|
|||||||
std::vector<std::string> item;
|
std::vector<std::string> item;
|
||||||
for (size_t i = 0; i < it.size(); i++) {
|
for (size_t i = 0; i < it.size(); i++) {
|
||||||
if (!it[i].is_blob) {
|
if (!it[i].is_blob) {
|
||||||
bool is_utf8 = Utils::IsTextUtf8(it[i].content, it[i].content_len);
|
bool is_utf8 =
|
||||||
|
base::utils::IsTextUtf8(it[i].content, it[i].content_len);
|
||||||
if (is_utf8) {
|
if (is_utf8) {
|
||||||
std::string content(it[i].content);
|
std::string content(it[i].content);
|
||||||
item.push_back(content);
|
item.push_back(content);
|
||||||
@ -142,34 +135,6 @@ int DB::Select(UINT64 db_hanle, const char *sql,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SelectDbInfo(void *data, int argc, char **argv, char **name) {
|
|
||||||
std::vector<common::SqlResult> result;
|
|
||||||
for (int i = 0; i < argc; i++) {
|
|
||||||
common::SqlResult temp = {0};
|
|
||||||
temp.column_name = new char[strlen(name[i]) + 1];
|
|
||||||
memcpy(temp.column_name, name[i], strlen(name[i]) + 1);
|
|
||||||
temp.column_name_len = strlen(name[i]);
|
|
||||||
if (argv[i]) {
|
|
||||||
temp.content = new char[strlen(argv[i]) + 1];
|
|
||||||
memcpy(temp.content, argv[i], strlen(argv[i]) + 1);
|
|
||||||
temp.content_len = strlen(argv[i]);
|
|
||||||
} else {
|
|
||||||
temp.content = new char[2];
|
|
||||||
ZeroMemory(temp.content, 2);
|
|
||||||
temp.content_len = 0;
|
|
||||||
}
|
|
||||||
result.push_back(temp);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DB::ExecuteSQL(UINT64 db, const char *sql, UINT64 callback, void *data) {
|
|
||||||
UINT64 sqlite3_exec_addr = base_addr_ + offset::k_sqlite3_exec;
|
|
||||||
common::sqlite3_exec fn_sqlite3_exec = (common::sqlite3_exec)sqlite3_exec_addr;
|
|
||||||
int status = fn_sqlite3_exec(db, sql, (common::sqlite3_callback)callback, data, 0);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetDbInfo(void *data, int argc, char **argv, char **name) {
|
int GetDbInfo(void *data, int argc, char **argv, char **name) {
|
||||||
common::DatabaseInfo *pdata = (common::DatabaseInfo *)data;
|
common::DatabaseInfo *pdata = (common::DatabaseInfo *)data;
|
||||||
common::TableInfo tb = {0};
|
common::TableInfo tb = {0};
|
||||||
@ -206,7 +171,21 @@ int GetDbInfo(void *data, int argc, char **argv, char **name) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<void *> DB::GetDbHandles() {
|
void DB::init(UINT64 base) {
|
||||||
|
base_addr_ = base;
|
||||||
|
dbmap_ = {};
|
||||||
|
dbs_ = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
int DB::ExecuteSQL(UINT64 db, const char *sql,
|
||||||
|
common::sqlite3_callback callback, void *data) {
|
||||||
|
UINT64 sqlite3_exec_addr = base_addr_ + offset::k_sqlite3_exec;
|
||||||
|
common::sqlite3_exec sqlite3_exec = (common::sqlite3_exec)sqlite3_exec_addr;
|
||||||
|
int status = sqlite3_exec(db, sql, callback, data, 0);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<void *> DB::GetWeChatDbHandles() {
|
||||||
dbs_.clear();
|
dbs_.clear();
|
||||||
dbmap_.clear();
|
dbmap_.clear();
|
||||||
UINT64 p_contact_addr = *(UINT64 *)(base_addr_ + offset::kGPInstance);
|
UINT64 p_contact_addr = *(UINT64 *)(base_addr_ + offset::kGPInstance);
|
||||||
@ -228,8 +207,8 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
*(DWORD *)(p_contact_addr + offset::kMicroMsgDB + offset::kDBName + 0x8);
|
*(DWORD *)(p_contact_addr + offset::kMicroMsgDB + offset::kDBName + 0x8);
|
||||||
micro_msg_db.handle = micro_msg_db_addr;
|
micro_msg_db.handle = micro_msg_db_addr;
|
||||||
ExecuteSQL(micro_msg_db_addr,
|
ExecuteSQL(micro_msg_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, µ_msg_db);
|
µ_msg_db);
|
||||||
dbs_.push_back(micro_msg_db);
|
dbs_.push_back(micro_msg_db);
|
||||||
std::wstring micro_msg_name = std::wstring((wchar_t *)(*(
|
std::wstring micro_msg_name = std::wstring((wchar_t *)(*(
|
||||||
UINT64 *)(p_contact_addr + offset::kMicroMsgDB + offset::kDBName)));
|
UINT64 *)(p_contact_addr + offset::kMicroMsgDB + offset::kDBName)));
|
||||||
@ -240,28 +219,28 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
chat_msg_db.db_name = (wchar_t *)(*(
|
chat_msg_db.db_name = (wchar_t *)(*(
|
||||||
UINT64 *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName));
|
UINT64 *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName));
|
||||||
chat_msg_db.db_name_len =
|
chat_msg_db.db_name_len =
|
||||||
*(DWORD *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName + 0x8);
|
*(DWORD *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName + 0x8);
|
||||||
chat_msg_db.handle = chat_msg_db_addr;
|
chat_msg_db.handle = chat_msg_db_addr;
|
||||||
ExecuteSQL(chat_msg_db_addr,
|
ExecuteSQL(chat_msg_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &chat_msg_db);
|
&chat_msg_db);
|
||||||
dbs_.push_back(chat_msg_db);
|
dbs_.push_back(chat_msg_db);
|
||||||
std::wstring chat_msg_name = std::wstring((wchar_t *)(*(
|
std::wstring chat_msg_name = std::wstring((wchar_t *)(*(
|
||||||
UINT64 *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName)));
|
UINT64 *)(p_contact_addr + offset::kChatMsgDB + offset::kDBName)));
|
||||||
dbmap_[chat_msg_name] = chat_msg_db;
|
dbmap_[chat_msg_name] = chat_msg_db;
|
||||||
|
|
||||||
// misc.db
|
// misc.db
|
||||||
common::DatabaseInfo misc_db{0};
|
common::DatabaseInfo misc_db{0};
|
||||||
misc_db.db_name =
|
misc_db.db_name = (wchar_t *)(*(UINT64 *)(p_contact_addr + offset::kMiscDB +
|
||||||
(wchar_t *)(*(UINT64 *)(p_contact_addr + offset::kMiscDB + offset::kDBName));
|
offset::kDBName));
|
||||||
misc_db.db_name_len =
|
misc_db.db_name_len =
|
||||||
*(DWORD *)(p_contact_addr + offset::kMiscDB + offset::kDBName + 0x8);
|
*(DWORD *)(p_contact_addr + offset::kMiscDB + offset::kDBName + 0x8);
|
||||||
misc_db.handle = misc_db_addr;
|
misc_db.handle = misc_db_addr;
|
||||||
ExecuteSQL(misc_db_addr, "select * from sqlite_master where type=\"table\";",
|
ExecuteSQL(misc_db_addr, "select * from sqlite_master where type=\"table\";",
|
||||||
(UINT64)GetDbInfo, &misc_db);
|
GetDbInfo, &misc_db);
|
||||||
dbs_.push_back(misc_db);
|
dbs_.push_back(misc_db);
|
||||||
std::wstring misc_name = std::wstring((
|
std::wstring misc_name = std::wstring((wchar_t *)(*(
|
||||||
wchar_t *)(*(UINT64 *)(p_contact_addr + offset::kMiscDB + offset::kDBName)));
|
UINT64 *)(p_contact_addr + offset::kMiscDB + offset::kDBName)));
|
||||||
dbmap_[misc_name] = misc_db;
|
dbmap_[misc_name] = misc_db;
|
||||||
|
|
||||||
// emotion.db
|
// emotion.db
|
||||||
@ -272,8 +251,8 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
*(DWORD *)(p_contact_addr + offset::kEmotionDB + offset::kDBName + 0x8);
|
*(DWORD *)(p_contact_addr + offset::kEmotionDB + offset::kDBName + 0x8);
|
||||||
emotion_db.handle = emotion_db_addr;
|
emotion_db.handle = emotion_db_addr;
|
||||||
ExecuteSQL(emotion_db_addr,
|
ExecuteSQL(emotion_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &emotion_db);
|
&emotion_db);
|
||||||
dbs_.push_back(emotion_db);
|
dbs_.push_back(emotion_db);
|
||||||
std::wstring emotion_name = std::wstring((wchar_t *)(*(
|
std::wstring emotion_name = std::wstring((wchar_t *)(*(
|
||||||
UINT64 *)(p_contact_addr + offset::kEmotionDB + offset::kDBName)));
|
UINT64 *)(p_contact_addr + offset::kEmotionDB + offset::kDBName)));
|
||||||
@ -282,12 +261,12 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
// media.db
|
// media.db
|
||||||
common::DatabaseInfo media_db{0};
|
common::DatabaseInfo media_db{0};
|
||||||
media_db.db_name = (wchar_t *)(*(UINT64 *)(p_contact_addr + offset::kMediaDB +
|
media_db.db_name = (wchar_t *)(*(UINT64 *)(p_contact_addr + offset::kMediaDB +
|
||||||
offset::kDBName));
|
offset::kDBName));
|
||||||
media_db.db_name_len =
|
media_db.db_name_len =
|
||||||
*(DWORD *)(p_contact_addr + offset::kMediaDB + offset::kDBName + 0x8);
|
*(DWORD *)(p_contact_addr + offset::kMediaDB + offset::kDBName + 0x8);
|
||||||
media_db.handle = media_db_addr;
|
media_db.handle = media_db_addr;
|
||||||
ExecuteSQL(media_db_addr, "select * from sqlite_master where type=\"table\";",
|
ExecuteSQL(media_db_addr, "select * from sqlite_master where type=\"table\";",
|
||||||
(UINT64)GetDbInfo, &media_db);
|
GetDbInfo, &media_db);
|
||||||
dbs_.push_back(media_db);
|
dbs_.push_back(media_db);
|
||||||
std::wstring media_name = std::wstring((wchar_t *)(*(
|
std::wstring media_name = std::wstring((wchar_t *)(*(
|
||||||
UINT64 *)(p_contact_addr + offset::kMediaDB + offset::kDBName)));
|
UINT64 *)(p_contact_addr + offset::kMediaDB + offset::kDBName)));
|
||||||
@ -301,8 +280,8 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
DWORD *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName + 0x8);
|
DWORD *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName + 0x8);
|
||||||
function_msg_db.handle = function_msg_db_addr;
|
function_msg_db.handle = function_msg_db_addr;
|
||||||
ExecuteSQL(function_msg_db_addr,
|
ExecuteSQL(function_msg_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &function_msg_db);
|
&function_msg_db);
|
||||||
dbs_.push_back(function_msg_db);
|
dbs_.push_back(function_msg_db);
|
||||||
std::wstring function_msg_name = std::wstring((wchar_t *)(*(
|
std::wstring function_msg_name = std::wstring((wchar_t *)(*(
|
||||||
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName)));
|
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName)));
|
||||||
@ -318,14 +297,14 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
0x8);
|
0x8);
|
||||||
bizchat_msg_db.handle = bizchat_msg_db_addr;
|
bizchat_msg_db.handle = bizchat_msg_db_addr;
|
||||||
ExecuteSQL(bizchat_msg_db_addr,
|
ExecuteSQL(bizchat_msg_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &bizchat_msg_db);
|
&bizchat_msg_db);
|
||||||
dbs_.push_back(bizchat_msg_db);
|
dbs_.push_back(bizchat_msg_db);
|
||||||
std::wstring bizchat_msg_name = std::wstring((wchar_t *)(*(
|
std::wstring bizchat_msg_name = std::wstring((wchar_t *)(*(
|
||||||
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName)));
|
UINT64 *)(p_contact_addr + offset::kFunctionMsgDB + offset::kDBName)));
|
||||||
dbmap_[bizchat_msg_name] = bizchat_msg_db;
|
dbmap_[bizchat_msg_name] = bizchat_msg_db;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT64 multi_db_mgr_addr = base_addr_ + offset::kMultiDBMgr;
|
UINT64 multi_db_mgr_addr = base_addr_ + offset::kMultiDBMgr;
|
||||||
UINT64 public_msg_mgr_addr = base_addr_ + offset::kPublicMsgMgr;
|
UINT64 public_msg_mgr_addr = base_addr_ + offset::kPublicMsgMgr;
|
||||||
UINT64 favorite_storage_mgr_addr = base_addr_ + offset::kFavoriteStorageMgr;
|
UINT64 favorite_storage_mgr_addr = base_addr_ + offset::kFavoriteStorageMgr;
|
||||||
@ -346,10 +325,11 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
msg0_db.handle = msg0_db_addr;
|
msg0_db.handle = msg0_db_addr;
|
||||||
msg0_db.extrainfo = *(UINT64 *)(*(UINT64 *)(db_addr + 0x28) + 0x1E8);
|
msg0_db.extrainfo = *(UINT64 *)(*(UINT64 *)(db_addr + 0x28) + 0x1E8);
|
||||||
ExecuteSQL(msg0_db_addr,
|
ExecuteSQL(msg0_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &msg0_db);
|
&msg0_db);
|
||||||
dbs_.push_back(msg0_db);
|
dbs_.push_back(msg0_db);
|
||||||
std::wstring msg_db_name = std::wstring(msg0_db.db_name,msg0_db.db_name_len);
|
std::wstring msg_db_name =
|
||||||
|
std::wstring(msg0_db.db_name, msg0_db.db_name_len);
|
||||||
dbmap_[msg_db_name] = msg0_db;
|
dbmap_[msg_db_name] = msg0_db;
|
||||||
|
|
||||||
// BufInfoStorage
|
// BufInfoStorage
|
||||||
@ -361,18 +341,17 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
media_msg0_db.db_name_len = *(DWORD *)(buf_info_addr + 0x80);
|
media_msg0_db.db_name_len = *(DWORD *)(buf_info_addr + 0x80);
|
||||||
media_msg0_db.handle = buf_info_handle;
|
media_msg0_db.handle = buf_info_handle;
|
||||||
ExecuteSQL(buf_info_handle,
|
ExecuteSQL(buf_info_handle,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &media_msg0_db);
|
&media_msg0_db);
|
||||||
dbs_.push_back(media_msg0_db);
|
dbs_.push_back(media_msg0_db);
|
||||||
std::wstring media_msg_db_name =
|
std::wstring media_msg_db_name =
|
||||||
std::wstring(media_msg0_db.db_name,media_msg0_db.db_name_len);
|
std::wstring(media_msg0_db.db_name, media_msg0_db.db_name_len);
|
||||||
dbmap_[media_msg_db_name] = media_msg0_db;
|
dbmap_[media_msg_db_name] = media_msg0_db;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// publicMsg.db
|
// publicMsg.db
|
||||||
UINT64 public_msg_mgr_ptr =*(UINT64 *)(public_msg_mgr_addr);
|
UINT64 public_msg_mgr_ptr = *(UINT64 *)(public_msg_mgr_addr);
|
||||||
for (unsigned int i = 1; i < 4; i++) {
|
for (unsigned int i = 1; i < 4; i++) {
|
||||||
UINT64 public_msg_ptr = *(UINT64 *)(public_msg_mgr_ptr + i * 0x8);
|
UINT64 public_msg_ptr = *(UINT64 *)(public_msg_mgr_ptr + i * 0x8);
|
||||||
if (public_msg_ptr) {
|
if (public_msg_ptr) {
|
||||||
@ -382,18 +361,19 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
public_msg_db.db_name_len = *(DWORD *)(public_msg_ptr + 0x80);
|
public_msg_db.db_name_len = *(DWORD *)(public_msg_ptr + 0x80);
|
||||||
public_msg_db.handle = public_msg_db_addr;
|
public_msg_db.handle = public_msg_db_addr;
|
||||||
ExecuteSQL(public_msg_db_addr,
|
ExecuteSQL(public_msg_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &public_msg_db);
|
&public_msg_db);
|
||||||
dbs_.push_back(public_msg_db);
|
dbs_.push_back(public_msg_db);
|
||||||
std::wstring public_msg_db_name =
|
std::wstring public_msg_db_name =
|
||||||
std::wstring(public_msg_db.db_name , public_msg_db.db_name_len);
|
std::wstring(public_msg_db.db_name, public_msg_db.db_name_len);
|
||||||
dbmap_[public_msg_db_name] = public_msg_db;
|
dbmap_[public_msg_db_name] = public_msg_db;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Favorite.db
|
// Favorite.db
|
||||||
UINT64 favItems_ptr =
|
UINT64 favItems_ptr =
|
||||||
*(UINT64 *)(*(UINT64 *)(*(UINT64 *)(favorite_storage_mgr_addr) + 0x10) + 0x8);
|
*(UINT64 *)(*(UINT64 *)(*(UINT64 *)(favorite_storage_mgr_addr) + 0x10) +
|
||||||
|
0x8);
|
||||||
if (favItems_ptr) {
|
if (favItems_ptr) {
|
||||||
UINT64 favorite_db_addr = *(UINT64 *)(favItems_ptr + 0x50);
|
UINT64 favorite_db_addr = *(UINT64 *)(favItems_ptr + 0x50);
|
||||||
common::DatabaseInfo favorite_db{0};
|
common::DatabaseInfo favorite_db{0};
|
||||||
@ -401,17 +381,17 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
favorite_db.db_name_len = *(DWORD *)(favItems_ptr + 0x80);
|
favorite_db.db_name_len = *(DWORD *)(favItems_ptr + 0x80);
|
||||||
favorite_db.handle = favorite_db_addr;
|
favorite_db.handle = favorite_db_addr;
|
||||||
ExecuteSQL(favorite_db_addr,
|
ExecuteSQL(favorite_db_addr,
|
||||||
"select * from sqlite_master where type=\"table\";",
|
"select * from sqlite_master where type=\"table\";", GetDbInfo,
|
||||||
(UINT64)GetDbInfo, &favorite_db);
|
&favorite_db);
|
||||||
dbs_.push_back(favorite_db);
|
dbs_.push_back(favorite_db);
|
||||||
std::wstring public_msg_db_name =
|
std::wstring public_msg_db_name =
|
||||||
std::wstring(favorite_db.db_name,favorite_db.db_name_len);
|
std::wstring(favorite_db.db_name, favorite_db.db_name_len);
|
||||||
dbmap_[public_msg_db_name] = favorite_db;
|
dbmap_[public_msg_db_name] = favorite_db;
|
||||||
}
|
}
|
||||||
common::DatabaseInfo db_end = {0};
|
common::DatabaseInfo db_end = {0};
|
||||||
dbs_.push_back(db_end);
|
dbs_.push_back(db_end);
|
||||||
std::vector<void *> ret_array;
|
std::vector<void *> ret_array;
|
||||||
for (unsigned int i = 0; i < dbs_.size() - 1; i++){
|
for (unsigned int i = 0; i < dbs_.size() - 1; i++) {
|
||||||
ret_array.push_back(&dbs_[i]);
|
ret_array.push_back(&dbs_[i]);
|
||||||
}
|
}
|
||||||
return ret_array;
|
return ret_array;
|
||||||
@ -419,7 +399,7 @@ std::vector<void *> DB::GetDbHandles() {
|
|||||||
|
|
||||||
UINT64 DB::GetDbHandleByDbName(wchar_t *dbname) {
|
UINT64 DB::GetDbHandleByDbName(wchar_t *dbname) {
|
||||||
if (dbmap_.size() == 0) {
|
if (dbmap_.size() == 0) {
|
||||||
GetDbHandles();
|
GetWeChatDbHandles();
|
||||||
}
|
}
|
||||||
if (dbmap_.find(dbname) != dbmap_.end()) {
|
if (dbmap_.find(dbname) != dbmap_.end()) {
|
||||||
return dbmap_[dbname].handle;
|
return dbmap_[dbname].handle;
|
||||||
@ -461,7 +441,7 @@ std::vector<std::string> DB::GetChatMsgByMsgId(ULONG64 msgid) {
|
|||||||
swprintf_s(dbname, L"MSG%d.db", i);
|
swprintf_s(dbname, L"MSG%d.db", i);
|
||||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||||
if (handle == 0) {
|
if (handle == 0) {
|
||||||
// LOG(INFO) << "MSG db handle is null";
|
SPDLOG_INFO("MSG db handle is null");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
std::vector<std::vector<std::string>> result;
|
std::vector<std::vector<std::string>> result;
|
||||||
@ -480,7 +460,7 @@ std::string DB::GetVoiceBuffByMsgId(ULONG64 msgid) {
|
|||||||
swprintf_s(dbname, L"MediaMSG%d.db", i);
|
swprintf_s(dbname, L"MediaMSG%d.db", i);
|
||||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||||
if (handle == 0) {
|
if (handle == 0) {
|
||||||
// LOG(INFO) << "Media db handle is null";
|
SPDLOG_INFO("Media db handle is null");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
std::vector<std::vector<std::string>> result;
|
std::vector<std::vector<std::string>> result;
|
||||||
@ -493,16 +473,20 @@ std::string DB::GetVoiceBuffByMsgId(ULONG64 msgid) {
|
|||||||
|
|
||||||
std::string DB::GetPublicMsgCompressContentByMsgId(ULONG64 msgid) {
|
std::string DB::GetPublicMsgCompressContentByMsgId(ULONG64 msgid) {
|
||||||
char sql[260] = {0};
|
char sql[260] = {0};
|
||||||
sprintf_s(sql, "SELECT CompressContent from PublicMsg WHERE MsgSvrID=%llu;", msgid);
|
sprintf_s(sql, "SELECT CompressContent from PublicMsg WHERE MsgSvrID=%llu;",
|
||||||
|
msgid);
|
||||||
wchar_t dbname[20] = {0};
|
wchar_t dbname[20] = {0};
|
||||||
swprintf_s( dbname, 20, L"%s", L"PublicMsg.db");
|
swprintf_s(dbname, 20, L"%s", L"PublicMsg.db");
|
||||||
UINT64 handle = GetDbHandleByDbName(dbname);
|
UINT64 handle = GetDbHandleByDbName(dbname);
|
||||||
if (handle == 0) {
|
if (handle == 0) {
|
||||||
|
SPDLOG_INFO("db handle not found,check msgid");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
std::vector<std::vector<std::string>> result;
|
std::vector<std::vector<std::string>> result;
|
||||||
int ret = Select(handle, (const char *)sql, result);
|
int ret = Select(handle, (const char *)sql, result);
|
||||||
if (result.size() == 0) {
|
if (result.size() == 0) {
|
||||||
|
SPDLOG_INFO(
|
||||||
|
"this SQL statement executed normally, but the result was empty");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return result[1][0];
|
return result[1][0];
|
@ -1,21 +1,21 @@
|
|||||||
#ifndef WXHELPER_DB_H_
|
#ifndef WXHELPER_DB_H_
|
||||||
#define WXHELPER_DB_H_
|
#define WXHELPER_DB_H_
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "wechat_function.h"
|
|
||||||
#include "windows.h"
|
|
||||||
#include "singleton.h"
|
#include "singleton.h"
|
||||||
|
#include "wechat_function.h"
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
class DB :public Singleton<DB>{
|
|
||||||
|
class DB : public base::Singleton<DB> {
|
||||||
public:
|
public:
|
||||||
void init(UINT64 base);
|
void init(UINT64 base);
|
||||||
int ExecuteSQL(UINT64 db, const char *sql, UINT64 callback, void *data);
|
int ExecuteSQL(UINT64 db, const char *sql, common::sqlite3_callback callback,
|
||||||
|
void *data);
|
||||||
|
std::vector<void *> GetWeChatDbHandles();
|
||||||
int Select(UINT64 db_hanle, const char *sql,
|
int Select(UINT64 db_hanle, const char *sql,
|
||||||
std::vector<std::vector<std::string>> &query_result);
|
std::vector<std::vector<std::string>> &query_result);
|
||||||
|
|
||||||
std::vector<void *> GetDbHandles();
|
|
||||||
UINT64 GetDbHandleByDbName(wchar_t *dbname);
|
UINT64 GetDbHandleByDbName(wchar_t *dbname);
|
||||||
INT64 GetLocalIdByMsgId(ULONG64 msgid, INT64 &dbIndex);
|
INT64 GetLocalIdByMsgId(ULONG64 msgid, INT64 &dbIndex);
|
||||||
std::vector<std::string> GetChatMsgByMsgId(ULONG64 msgid);
|
std::vector<std::string> GetChatMsgByMsgId(ULONG64 msgid);
|
||||||
@ -25,8 +25,8 @@ class DB :public Singleton<DB>{
|
|||||||
std::string GetPublicMsgCompressContentByMsgId(ULONG64 msgid);
|
std::string GetPublicMsgCompressContentByMsgId(ULONG64 msgid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int SelectDataInner(UINT64 db, const char *sql,
|
int ExecSelect(UINT64 db, const char *sql,
|
||||||
std::vector<std::vector<common::SqlResult>> &data);
|
std::vector<std::vector<common::SqlResult>> &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::wstring, common::DatabaseInfo> dbmap_;
|
std::map<std::wstring, common::DatabaseInfo> dbmap_;
|
||||||
@ -35,5 +35,4 @@ class DB :public Singleton<DB>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace wxhelper
|
} // namespace wxhelper
|
||||||
|
#endif
|
||||||
#endif
|
|
@ -1,16 +1,11 @@
|
|||||||
#include "pch.h"
|
#include "global_manager.h"
|
||||||
#include "global_context.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace wxhelper;
|
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
||||||
LPVOID lpReserved) {
|
LPVOID lpReserved) {
|
||||||
switch (ul_reason_for_call) {
|
switch (ul_reason_for_call) {
|
||||||
case DLL_PROCESS_ATTACH: {
|
case DLL_PROCESS_ATTACH: {
|
||||||
DisableThreadLibraryCalls(hModule);
|
DisableThreadLibraryCalls(hModule);
|
||||||
GlobalContext::GetInstance().initialize(hModule);
|
wxhelper::GlobalManager::GetInstance().initialize(hModule);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DLL_THREAD_ATTACH: {
|
case DLL_THREAD_ATTACH: {
|
||||||
@ -20,7 +15,6 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DLL_PROCESS_DETACH: {
|
case DLL_PROCESS_DETACH: {
|
||||||
GlobalContext::GetInstance().finally();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
47
app/wxhelper/src/global_manager.cc
Normal file
47
app/wxhelper/src/global_manager.cc
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include "global_manager.h"
|
||||||
|
|
||||||
|
#include "db.h"
|
||||||
|
#include "http_url_handler.h"
|
||||||
|
#include "thread_pool.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "wechat_service.h"
|
||||||
|
#include "wxutils.h"
|
||||||
|
namespace wxhelper {
|
||||||
|
|
||||||
|
GlobalManager::~GlobalManager() {}
|
||||||
|
|
||||||
|
void GlobalManager::initialize(HMODULE module) {
|
||||||
|
state = GlobalContextState::INITIALIZING;
|
||||||
|
module_ = module;
|
||||||
|
config = std::unique_ptr<Config>(new Config());
|
||||||
|
config->Initialize();
|
||||||
|
if (config->GetHideDll()) {
|
||||||
|
base::utils::HideModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT64 base = wxutils::GetWeChatWinBase();
|
||||||
|
DB::GetInstance().init(base);
|
||||||
|
WechatService::GetInstance().SetBaseAddr(base);
|
||||||
|
http_server = std::unique_ptr<http::HttpServer>(
|
||||||
|
new http::HttpServer(config->GetPort()));
|
||||||
|
http_server->AddHttpApiUrl("/api/sendTextMsg", SendTextMsg);
|
||||||
|
http_server->AddHttpApiUrl("/api/hookSyncMsg", HookSyncMsg);
|
||||||
|
http_server->AddHttpApiUrl("/api/getContactList", GetContacts);
|
||||||
|
http_server->AddHttpApiUrl("/api/unhookSyncMsg", UnHookSyncMsg);
|
||||||
|
http_server->AddHttpApiUrl("/api/checkLogin", CheckLogin);
|
||||||
|
http_server->AddHttpApiUrl("/api/userInfo", GetSelfInfo);
|
||||||
|
http_server->AddHttpApiUrl("/api/getDBInfo", GetDBInfo);
|
||||||
|
http_server->AddHttpApiUrl("/api/execSql", ExecSql);
|
||||||
|
|
||||||
|
http_server->Start();
|
||||||
|
base::ThreadPool::GetInstance().Create(2, 8);
|
||||||
|
|
||||||
|
state = GlobalContextState::INITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalManager::finally() {
|
||||||
|
if (http_server) {
|
||||||
|
http_server->Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace wxhelper
|
@ -1,28 +1,27 @@
|
|||||||
#ifndef GLOBAL_CONTEXT_H_
|
#ifndef WXHELPER_GLOBAL_MANAGER_H_
|
||||||
#define GLOBAL_CONTEXT_H_
|
#define WXHELPER_GLOBAL_MANAGER_H_
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "http_server.h"
|
#include "http_server.h"
|
||||||
#include "log.h"
|
|
||||||
#include "singleton.h"
|
#include "singleton.h"
|
||||||
#include "manager.h"
|
|
||||||
|
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
|
|
||||||
enum class GlobalContextState { NOT_INITIALIZED, INITIALIZING, INITIALIZED };
|
enum class GlobalContextState { NOT_INITIALIZED, INITIALIZING, INITIALIZED };
|
||||||
|
|
||||||
class GlobalContext : public Singleton<GlobalContext> {
|
class GlobalManager : public base::Singleton<GlobalManager> {
|
||||||
friend class Singleton<GlobalContext>;
|
friend class base::Singleton<GlobalManager>;
|
||||||
~GlobalContext();
|
~GlobalManager();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void initialize(HMODULE module);
|
void initialize(HMODULE module);
|
||||||
void finally();
|
void finally();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::optional<Config> config;
|
std::unique_ptr<Config> config;
|
||||||
std::optional<Log> log;
|
std::unique_ptr<http::HttpServer> http_server;
|
||||||
std::unique_ptr<HttpServer> http_server;
|
// std::unique_ptr<WechatService> service_;
|
||||||
std::unique_ptr<Manager> mgr;
|
|
||||||
|
|
||||||
GlobalContextState state = GlobalContextState::NOT_INITIALIZED;
|
GlobalContextState state = GlobalContextState::NOT_INITIALIZED;
|
||||||
|
|
73
app/wxhelper/src/http_client.cc
Normal file
73
app/wxhelper/src/http_client.cc
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#include "http_client.h"
|
||||||
|
|
||||||
|
namespace http {
|
||||||
|
|
||||||
|
void HttpClient::SendRequest(const std::string &content) {
|
||||||
|
struct mg_mgr mgr;
|
||||||
|
Data data;
|
||||||
|
data.done = false;
|
||||||
|
data.post_data = content;
|
||||||
|
mg_mgr_init(&mgr);
|
||||||
|
mg_http_connect(&mgr, kUrl.c_str(), OnHttpEvent, &data);
|
||||||
|
while (!data.done) {
|
||||||
|
mg_mgr_poll(&mgr, 500);
|
||||||
|
}
|
||||||
|
mg_mgr_free(&mgr);
|
||||||
|
data.done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpClient::SetConfig(std::string url, uint64_t timeout) {
|
||||||
|
kUrl = url;
|
||||||
|
kTimeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpClient::OnHttpEvent(struct mg_connection *c, int ev, void *ev_data,
|
||||||
|
void *fn_data) {
|
||||||
|
const char *s_url = kUrl.c_str();
|
||||||
|
Data *data = (Data *)fn_data;
|
||||||
|
if (ev == MG_EV_OPEN) {
|
||||||
|
// Connection created. Store connect expiration time in c->data
|
||||||
|
*(uint64_t *)c->data = mg_millis() + kTimeout;
|
||||||
|
} else if (ev == MG_EV_POLL) {
|
||||||
|
if (mg_millis() > *(uint64_t *)c->data &&
|
||||||
|
(c->is_connecting || c->is_resolving)) {
|
||||||
|
mg_error(c, "Connect timeout");
|
||||||
|
}
|
||||||
|
} else if (ev == MG_EV_CONNECT) {
|
||||||
|
struct mg_str host = mg_url_host(s_url);
|
||||||
|
if (mg_url_is_ssl(s_url)) {
|
||||||
|
// no implement
|
||||||
|
}
|
||||||
|
// Send request
|
||||||
|
size_t content_length = data->post_data.size();
|
||||||
|
mg_printf(c,
|
||||||
|
"POST %s HTTP/1.0\r\n"
|
||||||
|
"Host: %.*s\r\n"
|
||||||
|
"Content-Type: application/json\r\n"
|
||||||
|
"Content-Length: %d\r\n"
|
||||||
|
"\r\n",
|
||||||
|
mg_url_uri(s_url), (int)host.len, host.ptr, content_length);
|
||||||
|
mg_send(c, data->post_data.c_str(), content_length);
|
||||||
|
} else if (ev == MG_EV_HTTP_MSG) {
|
||||||
|
// Response is received. Print it
|
||||||
|
#ifdef _DEBUG
|
||||||
|
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
||||||
|
printf("%.*s", (int)hm->message.len, hm->message.ptr);
|
||||||
|
#endif
|
||||||
|
// c->is_closing = 1; // Tell mongoose to close this connection
|
||||||
|
c->is_draining = 1;
|
||||||
|
data->done = true; // Tell event loop to stops
|
||||||
|
} else if (ev == MG_EV_ERROR) {
|
||||||
|
data->done = true; // Error, tell event loop to stop
|
||||||
|
} else if (ev == MG_EV_CLOSE) {
|
||||||
|
if (!data->done) {
|
||||||
|
data->done = true;
|
||||||
|
}
|
||||||
|
} else if (ev == MG_EV_HTTP_CHUNK) {
|
||||||
|
mg_error(c, "http chunk no implement");
|
||||||
|
c->is_closing = 1;
|
||||||
|
data->done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace http
|
26
app/wxhelper/src/http_client.h
Normal file
26
app/wxhelper/src/http_client.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef WXHELPER_HTTP_CLIENT_H_
|
||||||
|
#define WXHELPER_HTTP_CLIENT_H_
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
#include "singleton.h"
|
||||||
|
|
||||||
|
namespace http {
|
||||||
|
static std::string kUrl = "http://127.0.0.1:8000";
|
||||||
|
static uint64_t kTimeout = 3000;
|
||||||
|
struct Data {
|
||||||
|
bool done;
|
||||||
|
std::string post_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
class HttpClient {
|
||||||
|
public:
|
||||||
|
static void SendRequest(const std::string &content);
|
||||||
|
static void SetConfig(std::string url, uint64_t timeout);
|
||||||
|
static void OnHttpEvent(struct mg_connection *c, int ev, void *ev_data,
|
||||||
|
void *fn_data);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace http
|
||||||
|
#endif
|
148
app/wxhelper/src/http_server.cc
Normal file
148
app/wxhelper/src/http_server.cc
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
#include "http_server.h"
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "utils.h"
|
||||||
|
namespace http {
|
||||||
|
|
||||||
|
HttpServer::HttpServer(int port) {
|
||||||
|
port_ = port;
|
||||||
|
running_ = false;
|
||||||
|
mg_mgr_init(&mgr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpServer::~HttpServer() {
|
||||||
|
if (thread_ != nullptr) {
|
||||||
|
CloseHandle(thread_);
|
||||||
|
}
|
||||||
|
mg_mgr_free(&mgr_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HttpServer::Start() {
|
||||||
|
if (running_) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#ifdef _DEBUG
|
||||||
|
base::utils::CreateConsole();
|
||||||
|
#endif
|
||||||
|
running_ = true;
|
||||||
|
thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartHttpServer, this,
|
||||||
|
NULL, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HttpServer::Stop() {
|
||||||
|
if (!running_) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#ifdef _DEBUG
|
||||||
|
base::utils::CloseConsole();
|
||||||
|
#endif
|
||||||
|
running_ = false;
|
||||||
|
if (thread_) {
|
||||||
|
WaitForSingleObject(thread_, -1);
|
||||||
|
CloseHandle(thread_);
|
||||||
|
thread_ = NULL;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int HttpServer::GetPort() { return port_; }
|
||||||
|
bool HttpServer::GetRunning() { return running_; }
|
||||||
|
|
||||||
|
const mg_mgr *HttpServer::GetMgr() { return &mgr_; }
|
||||||
|
|
||||||
|
void HttpServer::AddHttpApiUrl(const std::string &uri, HttpCbFunc func) {
|
||||||
|
http_api_url_map_[uri] = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpServer::StartHttpServer(HttpServer *server) {
|
||||||
|
int port = server->GetPort();
|
||||||
|
std::string lsten_addr = "http://0.0.0.0:" + std::to_string(port);
|
||||||
|
if (mg_http_listen(const_cast<mg_mgr *>(server->GetMgr()), lsten_addr.c_str(),
|
||||||
|
EventHandler, server) == NULL) {
|
||||||
|
SPDLOG_INFO("http server listen fail.port:{}", port);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (;;) {
|
||||||
|
mg_mgr_poll(const_cast<mg_mgr *>(server->GetMgr()), 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpServer::EventHandler(struct mg_connection *c, int ev, void *ev_data,
|
||||||
|
void *fn_data) {
|
||||||
|
if (ev == MG_EV_OPEN) {
|
||||||
|
} else if (ev == MG_EV_HTTP_MSG) {
|
||||||
|
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
||||||
|
if (mg_http_match_uri(hm, "/websocket")) {
|
||||||
|
mg_ws_upgrade(c, hm, NULL);
|
||||||
|
} else if (mg_http_match_uri(hm, "/api/*")) {
|
||||||
|
HandleHttpRequest(c, hm, fn_data);
|
||||||
|
} else {
|
||||||
|
nlohmann::json res = {{"code", 400},
|
||||||
|
{"msg", "invalid url, please check url"},
|
||||||
|
{"data", NULL}};
|
||||||
|
std::string ret = res.dump();
|
||||||
|
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n",
|
||||||
|
ret.c_str());
|
||||||
|
}
|
||||||
|
} else if (ev == MG_EV_WS_MSG) {
|
||||||
|
HandleWebsocketRequest(c, ev_data, fn_data);
|
||||||
|
}
|
||||||
|
(void)fn_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpServer::HandleHttpRequest(struct mg_connection *c, void *ev_data,
|
||||||
|
void *fn_data) {
|
||||||
|
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
||||||
|
std::string ret = R"({"code":200,"msg":"success"})";
|
||||||
|
try {
|
||||||
|
ret = HttpDispatch(c, hm, fn_data);
|
||||||
|
} catch (nlohmann::json::exception &e) {
|
||||||
|
nlohmann::json res = {{"code", "500"}, {"msg", e.what()}, {"data", NULL}};
|
||||||
|
ret = res.dump();
|
||||||
|
}
|
||||||
|
if (ret != "") {
|
||||||
|
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n",
|
||||||
|
ret.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpServer::HandleWebsocketRequest(struct mg_connection *c, void *ev_data,
|
||||||
|
void *fn_data) {
|
||||||
|
// Got websocket frame. Received data is wm->data. Echo it back!
|
||||||
|
struct mg_ws_message *wm = (struct mg_ws_message *)ev_data;
|
||||||
|
mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string HttpServer::HttpDispatch(struct mg_connection *c,
|
||||||
|
struct mg_http_message *hm,
|
||||||
|
void *fn_data) {
|
||||||
|
std::string ret;
|
||||||
|
if (mg_vcasecmp(&hm->method, "GET") == 0) {
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", 200},
|
||||||
|
{"data", {}},
|
||||||
|
{"msg", "the get method is not supported.please use post method."}};
|
||||||
|
ret = ret_data.dump();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
std::string api_uri(hm->uri.ptr,hm->uri.len);
|
||||||
|
HttpServer *server = (HttpServer *)fn_data;
|
||||||
|
return server->ProcessHttpRequest(api_uri, hm);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string HttpServer::ProcessHttpRequest(const std::string &url,
|
||||||
|
mg_http_message *hm) {
|
||||||
|
SPDLOG_INFO("http server process request url :{}", url);
|
||||||
|
if (http_api_url_map_.find(url) != http_api_url_map_.end()) {
|
||||||
|
return http_api_url_map_[url](hm);
|
||||||
|
} else {
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", 200}, {"data", {}}, {"msg", "the url is not supported"}};
|
||||||
|
return ret_data.dump();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace http
|
49
app/wxhelper/src/http_server.h
Normal file
49
app/wxhelper/src/http_server.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef WXHELPER_HTTP_SERVER_H_
|
||||||
|
#define WXHELPER_HTTP_SERVER_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
namespace http {
|
||||||
|
typedef std::function<std::string(struct mg_http_message *)> HttpCbFunc;
|
||||||
|
class HttpServer {
|
||||||
|
public:
|
||||||
|
explicit HttpServer(int port);
|
||||||
|
HttpServer(const HttpServer &) = delete;
|
||||||
|
HttpServer(HttpServer &&) = delete;
|
||||||
|
HttpServer &operator=(const HttpServer &) = delete;
|
||||||
|
~HttpServer();
|
||||||
|
|
||||||
|
bool Start();
|
||||||
|
bool Stop();
|
||||||
|
int GetPort();
|
||||||
|
bool GetRunning();
|
||||||
|
const mg_mgr *GetMgr();
|
||||||
|
void AddHttpApiUrl(const std::string &uri, HttpCbFunc func);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int port_;
|
||||||
|
bool running_;
|
||||||
|
struct mg_mgr mgr_;
|
||||||
|
HANDLE thread_;
|
||||||
|
std::map<const std::string, HttpCbFunc> http_api_url_map_;
|
||||||
|
|
||||||
|
static void StartHttpServer(HttpServer *server);
|
||||||
|
static void EventHandler(struct mg_connection *c, int ev, void *ev_data,
|
||||||
|
void *fn_data);
|
||||||
|
|
||||||
|
static void HandleHttpRequest(struct mg_connection *c, void *ev_data,
|
||||||
|
void *fn_data);
|
||||||
|
static void HandleWebsocketRequest(struct mg_connection *c, void *ev_data,
|
||||||
|
void *fn_data);
|
||||||
|
static std::string HttpDispatch(struct mg_connection *c,
|
||||||
|
struct mg_http_message *hm, void *fn_data);
|
||||||
|
std::string ProcessHttpRequest(const std::string &url,
|
||||||
|
struct mg_http_message *hm);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace http
|
||||||
|
|
||||||
|
#endif
|
193
app/wxhelper/src/http_url_handler.cc
Normal file
193
app/wxhelper/src/http_url_handler.cc
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
#include "http_url_handler.h"
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "db.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "wechat_hook.h"
|
||||||
|
#include "wechat_service.h"
|
||||||
|
|
||||||
|
#define STR2ULL(str) (base::utils::IsDigit(str) ? stoull(str) : 0)
|
||||||
|
#define STR2LL(str) (base::utils::IsDigit(str) ? stoll(str) : 0)
|
||||||
|
#define STR2I(str) (base::utils::IsDigit(str) ? stoi(str) : 0)
|
||||||
|
namespace wxhelper {
|
||||||
|
std::wstring GetWStringParam(nlohmann::json data, std::string key) {
|
||||||
|
return base::utils::Utf8ToWstring(data[key].get<std::string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetIntParam(nlohmann::json data, std::string key) {
|
||||||
|
int result;
|
||||||
|
try {
|
||||||
|
result = data[key].get<int>();
|
||||||
|
} catch (nlohmann::json::exception) {
|
||||||
|
result = STR2I(data[key].get<std::string>());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GetBoolParam(nlohmann::json data, std::string key) {
|
||||||
|
return data[key].get<bool>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetStringParam(nlohmann::json data, std::string key) {
|
||||||
|
return data[key].get<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 GetInt64Param(nlohmann::json data, std::string key) {
|
||||||
|
INT64 result;
|
||||||
|
try {
|
||||||
|
result = data[key].get<INT64>();
|
||||||
|
} catch (nlohmann::json::exception) {
|
||||||
|
result = STR2LL(data[key].get<std::string>());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SendTextMsg(mg_http_message* hm) {
|
||||||
|
nlohmann::json j_param = nlohmann::json::parse(
|
||||||
|
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||||
|
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
||||||
|
std::wstring msg = GetWStringParam(j_param, "msg");
|
||||||
|
INT64 success = WechatService::GetInstance().SendTextMsg(wxid, msg);
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||||
|
std::string ret = ret_data.dump();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string HookSyncMsg(mg_http_message* hm) {
|
||||||
|
nlohmann::json j_param = nlohmann::json::parse(
|
||||||
|
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||||
|
int port = GetIntParam(j_param, "port");
|
||||||
|
std::string ip = GetStringParam(j_param, "ip");
|
||||||
|
bool enable = GetBoolParam(j_param, "enableHttp");
|
||||||
|
std::string url = "http:://127.0.0.1:19088";
|
||||||
|
uint64_t timeout = 3000;
|
||||||
|
if (enable) {
|
||||||
|
url = GetStringParam(j_param, "url");
|
||||||
|
timeout = GetIntParam(j_param, "timeout");
|
||||||
|
}
|
||||||
|
hook::WechatHookParam param = {
|
||||||
|
ip, url, port, enable, timeout,
|
||||||
|
};
|
||||||
|
hook::WechatHook::GetInstance().Init(param);
|
||||||
|
INT64 success = hook::WechatHook::GetInstance().HookSyncMsg();
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||||
|
std::string ret = ret_data.dump();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetContacts(mg_http_message* hm) {
|
||||||
|
std::vector<common::ContactInner> vec;
|
||||||
|
INT64 success = WechatService::GetInstance().GetContacts(vec);
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||||
|
for (unsigned int i = 0; i < vec.size(); i++) {
|
||||||
|
nlohmann::json item = {
|
||||||
|
{"customAccount", vec[i].custom_account},
|
||||||
|
{"encryptName", vec[i].encrypt_name},
|
||||||
|
{"type", vec[i].type},
|
||||||
|
{"verifyFlag", vec[i].verify_flag},
|
||||||
|
{"wxid", vec[i].wxid},
|
||||||
|
{"nickname", vec[i].nickname},
|
||||||
|
{"pinyin", vec[i].pinyin},
|
||||||
|
{"pinyinAll", vec[i].pinyin_all},
|
||||||
|
{"reserved1", vec[i].reserved1},
|
||||||
|
{"reserved2", vec[i].reserved2},
|
||||||
|
};
|
||||||
|
ret_data["data"].push_back(item);
|
||||||
|
}
|
||||||
|
std::string ret = ret_data.dump();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string UnHookSyncMsg(mg_http_message* hm) {
|
||||||
|
INT64 success = hook::WechatHook::GetInstance().UnHookSyncMsg();
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||||
|
return ret_data.dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CheckLogin(mg_http_message* hm) {
|
||||||
|
INT64 success = WechatService::GetInstance().CheckLogin();
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||||
|
return ret_data.dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetSelfInfo(mg_http_message* hm) {
|
||||||
|
common::SelfInfoInner self_info;
|
||||||
|
INT64 success = WechatService::GetInstance().GetSelfInfo(self_info);
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"code", success}, {"data", {}}, {"msg", "success"}};
|
||||||
|
if (success) {
|
||||||
|
nlohmann::json j_info = {
|
||||||
|
{"name", self_info.name},
|
||||||
|
{"city", self_info.city},
|
||||||
|
{"province", self_info.province},
|
||||||
|
{"country", self_info.country},
|
||||||
|
{"account", self_info.account},
|
||||||
|
{"wxid", self_info.wxid},
|
||||||
|
{"mobile", self_info.mobile},
|
||||||
|
{"headImage", self_info.head_img},
|
||||||
|
{"signature", self_info.signature},
|
||||||
|
{"dataSavePath", self_info.data_save_path},
|
||||||
|
{"currentDataPath", self_info.current_data_path},
|
||||||
|
{"dbKey", self_info.db_key},
|
||||||
|
};
|
||||||
|
ret_data["data"] = j_info;
|
||||||
|
}
|
||||||
|
return ret_data.dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetDBInfo(mg_http_message* hm) {
|
||||||
|
std::vector<void*> v_ptr = wxhelper::DB::GetInstance().GetWeChatDbHandles();
|
||||||
|
nlohmann::json ret_data = {{"data", nlohmann::json::array()}};
|
||||||
|
for (unsigned int i = 0; i < v_ptr.size(); i++) {
|
||||||
|
nlohmann::json db_info;
|
||||||
|
db_info["tables"] = nlohmann::json::array();
|
||||||
|
common::DatabaseInfo* db =
|
||||||
|
reinterpret_cast<common::DatabaseInfo*>(v_ptr[i]);
|
||||||
|
db_info["handle"] = db->handle;
|
||||||
|
std::wstring dbname(db->db_name);
|
||||||
|
db_info["databaseName"] = base::utils::WstringToUtf8(dbname);
|
||||||
|
for (auto table : db->tables) {
|
||||||
|
nlohmann::json table_info = {{"name", table.name},
|
||||||
|
{"tableName", table.table_name},
|
||||||
|
{"sql", table.sql},
|
||||||
|
{"rootpage", table.rootpage}};
|
||||||
|
db_info["tables"].push_back(table_info);
|
||||||
|
}
|
||||||
|
ret_data["data"].push_back(db_info);
|
||||||
|
}
|
||||||
|
ret_data["code"] = 1;
|
||||||
|
ret_data["msg"] = "success";
|
||||||
|
return ret_data.dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ExecSql(mg_http_message* hm) {
|
||||||
|
nlohmann::json j_param = nlohmann::json::parse(
|
||||||
|
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
||||||
|
UINT64 db_handle = GetInt64Param(j_param, "dbHandle");
|
||||||
|
std::string sql = GetStringParam(j_param, "sql");
|
||||||
|
std::vector<std::vector<std::string>> items;
|
||||||
|
int success =
|
||||||
|
wxhelper::DB::GetInstance().Select(db_handle, sql.c_str(), items);
|
||||||
|
nlohmann::json ret_data = {
|
||||||
|
{"data", nlohmann::json::array()}, {"code", success}, {"msg", "success"}};
|
||||||
|
if (success == 0) {
|
||||||
|
ret_data["msg"] = "no data";
|
||||||
|
return ret_data.dump();
|
||||||
|
}
|
||||||
|
for (auto it : items) {
|
||||||
|
nlohmann::json temp_arr = nlohmann::json::array();
|
||||||
|
for (size_t i = 0; i < it.size(); i++) {
|
||||||
|
temp_arr.push_back(it[i]);
|
||||||
|
}
|
||||||
|
ret_data["data"].push_back(temp_arr);
|
||||||
|
}
|
||||||
|
return ret_data.dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace wxhelper
|
17
app/wxhelper/src/http_url_handler.h
Normal file
17
app/wxhelper/src/http_url_handler.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef WXHELPER_HTTP_URL_HANDLER_H_
|
||||||
|
#define WXHELPER_HTTP_URL_HANDLER_H_
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
namespace wxhelper {
|
||||||
|
std::string SendTextMsg(struct mg_http_message *hm);
|
||||||
|
std::string HookSyncMsg(struct mg_http_message *hm);
|
||||||
|
std::string GetContacts(struct mg_http_message *hm);
|
||||||
|
std::string UnHookSyncMsg(struct mg_http_message *hm);
|
||||||
|
std::string CheckLogin(struct mg_http_message *hm);
|
||||||
|
std::string GetSelfInfo(struct mg_http_message *hm);
|
||||||
|
std::string GetDBInfo(struct mg_http_message *hm);
|
||||||
|
std::string ExecSql(struct mg_http_message *hm);
|
||||||
|
} // namespace wxhelper
|
||||||
|
|
||||||
|
#endif
|
@ -1,9 +1,12 @@
|
|||||||
#ifndef WXHELPER_WECHAT_FUNCTION_H_
|
#ifndef WXHELPER_WECHAT_FUNCTION_H_
|
||||||
#define WXHELPER_WECHAT_FUNCTION_H_
|
#define WXHELPER_WECHAT_FUNCTION_H_
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
namespace common {
|
namespace common {
|
||||||
/***************************sqlite3***************************************/
|
/***************************sqlite3***************************************/
|
||||||
#define SQLITE_OK 0 /* Successful result */
|
#define SQLITE_OK 0 /* Successful result */
|
||||||
/* beginning-of-error-codes */
|
/* beginning-of-error-codes */
|
||||||
#define SQLITE_ERROR 1 /* Generic error */
|
#define SQLITE_ERROR 1 /* Generic error */
|
||||||
@ -38,45 +41,41 @@ namespace common {
|
|||||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||||
/* end-of-error-codes */
|
/* end-of-error-codes */
|
||||||
|
|
||||||
#define SQLITE_INTEGER 1
|
#define SQLITE_INTEGER 1
|
||||||
#define SQLITE_FLOAT 2
|
#define SQLITE_FLOAT 2
|
||||||
#define SQLITE_BLOB 4
|
#define SQLITE_BLOB 4
|
||||||
#define SQLITE_NULL 5
|
#define SQLITE_NULL 5
|
||||||
#define SQLITE_TEXT 3
|
#define SQLITE_TEXT 3
|
||||||
|
|
||||||
|
typedef int (*sqlite3_callback)(void *, int, char **, char **);
|
||||||
|
|
||||||
|
typedef int(__cdecl *sqlite3_exec)(UINT64, /* An open database */
|
||||||
|
const char *sql, /* SQL to be evaluated */
|
||||||
typedef int (*sqlite3_callback)(void*, int, char**, char**);
|
|
||||||
|
|
||||||
typedef int(__cdecl* sqlite3_exec)(UINT64, /* An open database */
|
|
||||||
const char* sql, /* SQL to be evaluated */
|
|
||||||
sqlite3_callback, /* Callback function */
|
sqlite3_callback, /* Callback function */
|
||||||
void*, /* 1st argument to callback */
|
void *, /* 1st argument to callback */
|
||||||
char** errmsg /* Error msg written here */
|
char **errmsg /* Error msg written here */
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef int(__cdecl* sqlite3_prepare)(
|
typedef int(__cdecl *sqlite3_prepare)(
|
||||||
UINT64 db, /* Database handle */
|
UINT64 db, /* Database handle */
|
||||||
const char* zSql, /* SQL statement, UTF-8 encoded */
|
const char *zSql, /* SQL statement, UTF-8 encoded */
|
||||||
int nByte, /* Maximum length of zSql in bytes. */
|
int nByte, /* Maximum length of zSql in bytes. */
|
||||||
UINT64** ppStmt, /* OUT: Statement handle */
|
UINT64 **ppStmt, /* OUT: Statement handle */
|
||||||
const char** pzTail /* OUT: Pointer to unused portion of zSql */
|
const char **pzTail /* OUT: Pointer to unused portion of zSql */
|
||||||
);
|
);
|
||||||
typedef int(__cdecl* sqlite3_open)(const char* filename, UINT64** ppDb);
|
typedef int(__cdecl *sqlite3_open)(const char *filename, UINT64 **ppDb);
|
||||||
|
|
||||||
typedef int(__cdecl* sqlite3_sleep)(int);
|
typedef int(__cdecl *sqlite3_sleep)(int);
|
||||||
typedef int(__cdecl* sqlite3_errcode)(UINT64* db);
|
typedef int(__cdecl *sqlite3_errcode)(UINT64 *db);
|
||||||
typedef int(__cdecl* sqlite3_close)(UINT64*);
|
typedef int(__cdecl *sqlite3_close)(UINT64 *);
|
||||||
|
|
||||||
typedef int(__cdecl* sqlite3_step)(UINT64*);
|
|
||||||
typedef int(__cdecl* sqlite3_column_count)(UINT64* pStmt);
|
|
||||||
typedef const char*(__cdecl* sqlite3_column_name)(UINT64*, int N);
|
|
||||||
typedef int(__cdecl* sqlite3_column_type)(UINT64*, int iCol);
|
|
||||||
typedef const void*(__cdecl* sqlite3_column_blob)(UINT64*, int iCol);
|
|
||||||
typedef int(__cdecl* sqlite3_column_bytes)(UINT64*, int iCol);
|
|
||||||
typedef int(__cdecl* sqlite3_finalize)(UINT64* pStmt);
|
|
||||||
|
|
||||||
|
typedef int(__cdecl *sqlite3_step)(UINT64 *);
|
||||||
|
typedef int(__cdecl *sqlite3_column_count)(UINT64 *pStmt);
|
||||||
|
typedef const char *(__cdecl *sqlite3_column_name)(UINT64 *, int N);
|
||||||
|
typedef int(__cdecl *sqlite3_column_type)(UINT64 *, int iCol);
|
||||||
|
typedef const void *(__cdecl *sqlite3_column_blob)(UINT64 *, int iCol);
|
||||||
|
typedef int(__cdecl *sqlite3_column_bytes)(UINT64 *, int iCol);
|
||||||
|
typedef int(__cdecl *sqlite3_finalize)(UINT64 *pStmt);
|
||||||
|
|
||||||
/***************************sqlite3 end*************************************/
|
/***************************sqlite3 end*************************************/
|
||||||
|
|
||||||
@ -100,7 +99,6 @@ struct DatabaseInfo {
|
|||||||
INT64 extrainfo = 0;
|
INT64 extrainfo = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct SqlResult {
|
struct SqlResult {
|
||||||
char *column_name;
|
char *column_name;
|
||||||
INT64 column_name_len;
|
INT64 column_name_len;
|
||||||
@ -109,7 +107,6 @@ struct SqlResult {
|
|||||||
BOOL is_blob;
|
BOOL is_blob;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct InnerMessageStruct {
|
struct InnerMessageStruct {
|
||||||
char *buffer;
|
char *buffer;
|
||||||
INT64 length;
|
INT64 length;
|
||||||
@ -147,13 +144,13 @@ struct ContactInner {
|
|||||||
DWORD verify_flag;
|
DWORD verify_flag;
|
||||||
DWORD reserved1;
|
DWORD reserved1;
|
||||||
DWORD reserved2;
|
DWORD reserved2;
|
||||||
ContactInner(){
|
ContactInner() {
|
||||||
wxid = "";
|
wxid = "";
|
||||||
custom_account = "";
|
custom_account = "";
|
||||||
encrypt_name = "";
|
encrypt_name = "";
|
||||||
nickname ="";
|
nickname = "";
|
||||||
pinyin ="";
|
pinyin = "";
|
||||||
pinyin_all ="";
|
pinyin_all = "";
|
||||||
type = -1;
|
type = -1;
|
||||||
verify_flag = -1;
|
verify_flag = -1;
|
||||||
reserved1 = -1;
|
reserved1 = -1;
|
||||||
@ -166,13 +163,12 @@ struct ChatRoomInfoInner {
|
|||||||
std::string notice;
|
std::string notice;
|
||||||
std::string admin;
|
std::string admin;
|
||||||
std::string xml;
|
std::string xml;
|
||||||
ChatRoomInfoInner(){
|
ChatRoomInfoInner() {
|
||||||
chat_room_id = "";
|
chat_room_id = "";
|
||||||
notice = "";
|
notice = "";
|
||||||
admin = "";
|
admin = "";
|
||||||
xml = "";
|
xml = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VectorInner {
|
struct VectorInner {
|
||||||
@ -212,80 +208,81 @@ struct ContactProfileInner {
|
|||||||
namespace V3_9_5_81 {
|
namespace V3_9_5_81 {
|
||||||
namespace function {
|
namespace function {
|
||||||
|
|
||||||
|
typedef UINT64 (*__GetAccountService)();
|
||||||
typedef UINT64(*__GetAccountService)();
|
typedef UINT64 (*__GetDataSavePath)(UINT64);
|
||||||
typedef UINT64(*__GetDataSavePath)(UINT64);
|
typedef UINT64 (*__GetCurrentDataPath)(UINT64);
|
||||||
typedef UINT64(*__GetCurrentDataPath)(UINT64);
|
typedef UINT64 (*__GetSendMessageMgr)();
|
||||||
typedef UINT64(*__GetSendMessageMgr)();
|
|
||||||
typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||||
UINT64, UINT64);
|
UINT64, UINT64);
|
||||||
typedef UINT64 (*__FreeChatMsg)(UINT64);
|
typedef UINT64 (*__FreeChatMsg)(UINT64);
|
||||||
|
|
||||||
typedef UINT64 (*__SendImageMsg)(UINT64, UINT64, UINT64, UINT64, UINT64);
|
typedef UINT64 (*__SendImageMsg)(UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__NewChatMsg)(UINT64);
|
typedef UINT64 (*__NewChatMsg)(UINT64);
|
||||||
typedef UINT64 (*__SendFile)(UINT64, UINT64, UINT64, UINT64, UINT64,UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, UINT64);
|
typedef UINT64 (*__SendFile)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||||
typedef UINT64(*__GetAppMsgMgr)();
|
UINT64, UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||||
typedef UINT64(*__OperatorNew)(UINT64);
|
typedef UINT64 (*__GetAppMsgMgr)();
|
||||||
|
typedef UINT64 (*__OperatorNew)(UINT64);
|
||||||
|
|
||||||
typedef UINT64(*__Free)();
|
typedef UINT64 (*__Free)();
|
||||||
typedef UINT64 (*__GetContactMgr)();
|
typedef UINT64 (*__GetContactMgr)();
|
||||||
typedef UINT64 (*__GetContactList)(UINT64,UINT64);
|
typedef UINT64 (*__GetContactList)(UINT64, UINT64);
|
||||||
|
|
||||||
typedef UINT64 (*__GetChatRoomMgr)();
|
typedef UINT64 (*__GetChatRoomMgr)();
|
||||||
typedef UINT64 (*__NewChatRoomInfo)(UINT64);
|
typedef UINT64 (*__NewChatRoomInfo)(UINT64);
|
||||||
typedef UINT64 (*__FreeChatRoomInfo)(UINT64);
|
typedef UINT64 (*__FreeChatRoomInfo)(UINT64);
|
||||||
typedef UINT64 (*__GetChatRoomDetailInfo)(UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__GetChatRoomDetailInfo)(UINT64, UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__DoAddMemberToChatRoom)(UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__DoAddMemberToChatRoom)(UINT64, UINT64, UINT64, UINT64);
|
||||||
|
|
||||||
typedef UINT64 (*__DoModChatRoomMemberNickName)(UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__DoModChatRoomMemberNickName)(UINT64, UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__DoDelMemberFromChatRoom)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__DoDelMemberFromChatRoom)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__GetMemberFromChatRoom)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__GetMemberFromChatRoom)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__NewChatRoom)(UINT64);
|
typedef UINT64 (*__NewChatRoom)(UINT64);
|
||||||
typedef UINT64 (*__FreeChatRoom)(UINT64);
|
typedef UINT64 (*__FreeChatRoom)(UINT64);
|
||||||
|
|
||||||
typedef UINT64 (*__DoTopMsg)(UINT64,UINT64);
|
typedef UINT64 (*__DoTopMsg)(UINT64, UINT64);
|
||||||
typedef UINT64 (*__RemoveTopMsg)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__RemoveTopMsg)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__InviteMemberToChatRoom)(UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__InviteMemberToChatRoom)(UINT64, UINT64, UINT64, UINT64);
|
||||||
|
|
||||||
typedef UINT64 (*__CreateChatRoom)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__CreateChatRoom)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__QuitChatRoom)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__QuitChatRoom)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__ForwardMsg)(UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__ForwardMsg)(UINT64, UINT64, UINT64, UINT64);
|
||||||
|
|
||||||
typedef UINT64 (*__GetSNSFirstPage)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__GetSNSFirstPage)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__GetSNSNextPageScene)(UINT64,UINT64);
|
typedef UINT64 (*__GetSNSNextPageScene)(UINT64, UINT64);
|
||||||
|
|
||||||
typedef UINT64 (*__GetSNSDataMgr)();
|
typedef UINT64 (*__GetSNSDataMgr)();
|
||||||
typedef UINT64 (*__GetSnsTimeLineMgr)();
|
typedef UINT64 (*__GetSnsTimeLineMgr)();
|
||||||
typedef UINT64 (*__GetMgrByPrefixLocalId)(UINT64,UINT64);
|
typedef UINT64 (*__GetMgrByPrefixLocalId)(UINT64, UINT64);
|
||||||
typedef UINT64 (*__AddFavFromMsg)(UINT64,UINT64);
|
typedef UINT64 (*__AddFavFromMsg)(UINT64, UINT64);
|
||||||
typedef UINT64 (*__GetChatMgr)();
|
typedef UINT64 (*__GetChatMgr)();
|
||||||
typedef UINT64 (*__GetFavoriteMgr)();
|
typedef UINT64 (*__GetFavoriteMgr)();
|
||||||
typedef UINT64 (*__AddFavFromImage)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__AddFavFromImage)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__GetContact)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__GetContact)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__NewContact)(UINT64);
|
typedef UINT64 (*__NewContact)(UINT64);
|
||||||
typedef UINT64 (*__FreeContact)(UINT64);
|
typedef UINT64 (*__FreeContact)(UINT64);
|
||||||
typedef UINT64 (*__NewMMReaderItem)(UINT64);
|
typedef UINT64 (*__NewMMReaderItem)(UINT64);
|
||||||
typedef UINT64 (*__FreeMMReaderItem)(UINT64);
|
typedef UINT64 (*__FreeMMReaderItem)(UINT64);
|
||||||
typedef UINT64 (*__ForwordPublicMsg)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__ForwordPublicMsg)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__NewAppMsgInfo)(UINT64);
|
typedef UINT64 (*__NewAppMsgInfo)(UINT64);
|
||||||
typedef UINT64 (*__FreeAppMsgInfo)(UINT64);
|
typedef UINT64 (*__FreeAppMsgInfo)(UINT64);
|
||||||
typedef UINT64 (*__ParseAppMsgXml)(UINT64,UINT64,UINT64);
|
typedef UINT64 (*__ParseAppMsgXml)(UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__GetPreDownLoadMgr)();
|
typedef UINT64 (*__GetPreDownLoadMgr)();
|
||||||
typedef UINT64 (*__PushAttachTask)(UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__PushAttachTask)(UINT64, UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__GetCustomSmileyMgr)();
|
typedef UINT64 (*__GetCustomSmileyMgr)();
|
||||||
typedef UINT64 (*__SendCustomEmotion)(UINT64,UINT64,UINT64,UINT64,UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__SendCustomEmotion)(UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||||
|
UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__JsApiShareAppMessage)(UINT64);
|
typedef UINT64 (*__JsApiShareAppMessage)(UINT64);
|
||||||
typedef UINT64 (*__InitJsConfig)(UINT64,UINT64);
|
typedef UINT64 (*__InitJsConfig)(UINT64, UINT64);
|
||||||
typedef UINT64 (*__SendApplet)(UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__SendApplet)(UINT64, UINT64, UINT64, UINT64);
|
||||||
typedef UINT64 (*__SendAppletSecond)(UINT64,UINT64,UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__SendAppletSecond)(UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||||
typedef UINT64 (*__GetAppInfoByWaid)(UINT64,UINT64);
|
UINT64);
|
||||||
typedef UINT64 (*__CopyShareAppMessageRequest)(UINT64,UINT64);
|
typedef UINT64 (*__GetAppInfoByWaid)(UINT64, UINT64);
|
||||||
|
typedef UINT64 (*__CopyShareAppMessageRequest)(UINT64, UINT64);
|
||||||
typedef UINT64 (*__NewWAUpdatableMsgInfo)(UINT64);
|
typedef UINT64 (*__NewWAUpdatableMsgInfo)(UINT64);
|
||||||
typedef UINT64 (*__FreeWAUpdatableMsgInfo)(UINT64);
|
typedef UINT64 (*__FreeWAUpdatableMsgInfo)(UINT64);
|
||||||
typedef UINT64 (*__SendPatMsg)(UINT64,UINT64);
|
typedef UINT64 (*__SendPatMsg)(UINT64, UINT64);
|
||||||
typedef UINT64 (*__GetOCRManager)();
|
typedef UINT64 (*__GetOCRManager)();
|
||||||
typedef UINT64 (*__DoOCRTask)(UINT64,UINT64,UINT64,UINT64,UINT64);
|
typedef UINT64 (*__DoOCRTask)(UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||||
|
|
||||||
|
|
||||||
} // namespace function
|
} // namespace function
|
||||||
namespace prototype {
|
namespace prototype {
|
||||||
@ -324,19 +321,19 @@ struct WeChatString {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WeChatStr{
|
struct WeChatStr {
|
||||||
char * ptr;
|
char *ptr;
|
||||||
INT64 buf;
|
INT64 buf;
|
||||||
INT64 len;
|
INT64 len;
|
||||||
INT64 maxlen;
|
INT64 maxlen;
|
||||||
|
|
||||||
WeChatStr(const char* p) {
|
WeChatStr(const char *p) {
|
||||||
ptr = (char *)p;
|
ptr = (char *)p;
|
||||||
buf = 0;
|
buf = 0;
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
maxlen = len | 0xF;
|
maxlen = len | 0xF;
|
||||||
}
|
}
|
||||||
WeChatStr() {
|
WeChatStr() {
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
buf = 0;
|
buf = 0;
|
||||||
len = 0;
|
len = 0;
|
||||||
@ -364,18 +361,18 @@ const UINT64 kGetContactMgr = 0x8ae3d0;
|
|||||||
const UINT64 kGetContactList = 0xeab270;
|
const UINT64 kGetContactList = 0xeab270;
|
||||||
|
|
||||||
const UINT64 k_sqlite3_exec = 0x252e340;
|
const UINT64 k_sqlite3_exec = 0x252e340;
|
||||||
const UINT64 k_sqlite3_prepare = 0x2535eb0;
|
const UINT64 k_sqlite3_prepare = 0x2535eb0;
|
||||||
const UINT64 k_sqlite3_open = 0x256d6b0;
|
const UINT64 k_sqlite3_open = 0x256d6b0;
|
||||||
const UINT64 k_sqlite3_backup_init= 0x24e8450;
|
const UINT64 k_sqlite3_backup_init = 0x24e8450;
|
||||||
const UINT64 k_sqlite3_errcode = 0x256bfb0;
|
const UINT64 k_sqlite3_errcode = 0x256bfb0;
|
||||||
const UINT64 k_sqlite3_close = 0x256a110;
|
const UINT64 k_sqlite3_close = 0x256a110;
|
||||||
const UINT64 k_sqlite3_step = 0x24f2350;
|
const UINT64 k_sqlite3_step = 0x24f2350;
|
||||||
const UINT64 k_sqlite3_column_count = 0x24f2b70;
|
const UINT64 k_sqlite3_column_count = 0x24f2b70;
|
||||||
const UINT64 k_sqlite3_column_name = 0x24f3570;
|
const UINT64 k_sqlite3_column_name = 0x24f3570;
|
||||||
const UINT64 k_sqlite3_column_type = 0x24f33c0;
|
const UINT64 k_sqlite3_column_type = 0x24f33c0;
|
||||||
const UINT64 k_sqlite3_column_blob = 0x24f2ba0;
|
const UINT64 k_sqlite3_column_blob = 0x24f2ba0;
|
||||||
const UINT64 k_sqlite3_column_bytes = 0x24f2c90;
|
const UINT64 k_sqlite3_column_bytes = 0x24f2c90;
|
||||||
const UINT64 k_sqlite3_finalize = 0x24f1400;
|
const UINT64 k_sqlite3_finalize = 0x24f1400;
|
||||||
|
|
||||||
const UINT64 kGPInstance = 0x3a6f908;
|
const UINT64 kGPInstance = 0x3a6f908;
|
||||||
const UINT64 kMicroMsgDB = 0xb8;
|
const UINT64 kMicroMsgDB = 0xb8;
|
||||||
@ -450,6 +447,96 @@ const UINT64 kDoOCRTask = 0x190b2a0;
|
|||||||
} // namespace offset
|
} // namespace offset
|
||||||
} // namespace V3_9_5_81
|
} // namespace V3_9_5_81
|
||||||
|
|
||||||
|
namespace V3_9_7_29 {
|
||||||
|
|
||||||
|
namespace prototype {
|
||||||
|
struct WeChatString {
|
||||||
|
wchar_t *ptr;
|
||||||
|
DWORD length;
|
||||||
|
DWORD max_length;
|
||||||
|
INT64 c_ptr = 0;
|
||||||
|
DWORD c_len = 0;
|
||||||
|
WeChatString() { WeChatString(NULL); }
|
||||||
|
|
||||||
|
WeChatString(const std::wstring &s) {
|
||||||
|
ptr = (wchar_t *)(s.c_str());
|
||||||
|
length = static_cast<DWORD>(s.length());
|
||||||
|
max_length = static_cast<DWORD>(s.length());
|
||||||
|
}
|
||||||
|
WeChatString(const wchar_t *pStr) { WeChatString((wchar_t *)pStr); }
|
||||||
|
WeChatString(int tmp) {
|
||||||
|
ptr = NULL;
|
||||||
|
length = 0x0;
|
||||||
|
max_length = 0x0;
|
||||||
|
}
|
||||||
|
WeChatString(wchar_t *pStr) {
|
||||||
|
ptr = pStr;
|
||||||
|
length = static_cast<DWORD>(wcslen(pStr));
|
||||||
|
max_length = static_cast<DWORD>(wcslen(pStr));
|
||||||
|
}
|
||||||
|
void set_value(const wchar_t *pStr) {
|
||||||
|
ptr = (wchar_t *)pStr;
|
||||||
|
length = static_cast<DWORD>(wcslen(pStr));
|
||||||
|
max_length = static_cast<DWORD>(wcslen(pStr) * 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace prototype
|
||||||
|
|
||||||
|
namespace offset {
|
||||||
|
const UINT64 k_sqlite3_exec = 0x2654db0;
|
||||||
|
const UINT64 k_sqlite3_prepare = 0x265c920;
|
||||||
|
const UINT64 k_sqlite3_open = 0x2694120;
|
||||||
|
const UINT64 k_sqlite3_backup_init = 0x260eec0;
|
||||||
|
const UINT64 k_sqlite3_errcode = 0x2692a20;
|
||||||
|
const UINT64 k_sqlite3_close = 0x2690b80;
|
||||||
|
const UINT64 k_sqlite3_step = 0x2618dc0;
|
||||||
|
const UINT64 k_sqlite3_column_count = 0x26195e0;
|
||||||
|
const UINT64 k_sqlite3_column_name = 0x2619fe0;
|
||||||
|
const UINT64 k_sqlite3_column_type = 0x2619e30;
|
||||||
|
const UINT64 k_sqlite3_column_blob = 0x2619610;
|
||||||
|
const UINT64 k_sqlite3_column_bytes = 0x2619700;
|
||||||
|
const UINT64 k_sqlite3_finalize = 0x2617e70;
|
||||||
|
|
||||||
|
const UINT64 kGPInstance = 0x3c19fe8;
|
||||||
|
const UINT64 kMicroMsgDB = 0xb8;
|
||||||
|
const UINT64 kChatMsgDB = 0x2c8;
|
||||||
|
const UINT64 kMiscDB = 0x5f0;
|
||||||
|
const UINT64 kEmotionDB = 0x888;
|
||||||
|
const UINT64 kMediaDB = 0xf48;
|
||||||
|
const UINT64 kBizchatMsgDB = 0x1ac0;
|
||||||
|
const UINT64 kFunctionMsgDB = 0x1b98;
|
||||||
|
const UINT64 kDBName = 0x28;
|
||||||
|
const UINT64 kStorageStart = 0x0;
|
||||||
|
const UINT64 kStorageEnd = 0x0;
|
||||||
|
const UINT64 kMultiDBMgr = 0x3c8ef40;
|
||||||
|
const UINT64 kPublicMsgMgr = 0x3c8c6c8;
|
||||||
|
const UINT64 kFavoriteStorageMgr = 0x3c8fac0;
|
||||||
|
|
||||||
|
const UINT64 kGetSendMessageMgr = 0x8fe740;
|
||||||
|
const UINT64 kFreeChatMsg = 0x8fffc0;
|
||||||
|
const UINT64 kSendTextMsg = 0x1024370;
|
||||||
|
const UINT64 kDoAddMsg = 0x106b810;
|
||||||
|
const UINT64 kGetContactMgr = 0x8ebfb0;
|
||||||
|
const UINT64 kGetContactList = 0xeff050;
|
||||||
|
const UINT64 kGetAccountServiceMgr = 0x8fff40;
|
||||||
|
const UINT64 kGetAppDataSavePath = 0x1336c60;
|
||||||
|
const UINT64 kGetCurrentDataPath = 0xfacb50;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace offset
|
||||||
|
namespace function {
|
||||||
|
typedef UINT64 (*__GetSendMessageMgr)();
|
||||||
|
typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||||
|
UINT64, UINT64);
|
||||||
|
typedef UINT64 (*__FreeChatMsg)(UINT64);
|
||||||
|
typedef UINT64 (*__GetContactMgr)();
|
||||||
|
typedef UINT64 (*__GetContactList)(UINT64, UINT64);
|
||||||
|
typedef UINT64(*__GetAccountService)();
|
||||||
|
typedef UINT64 (*__GetDataSavePath)(UINT64);
|
||||||
|
typedef UINT64 (*__GetCurrentDataPath)(UINT64);
|
||||||
|
} // namespace function
|
||||||
|
} // namespace V3_9_7_29
|
||||||
} // namespace wxhelper
|
} // namespace wxhelper
|
||||||
|
|
||||||
#endif
|
#endif
|
205
app/wxhelper/src/wechat_hook.cc
Normal file
205
app/wxhelper/src/wechat_hook.cc
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
#include <WS2tcpip.h>
|
||||||
|
#include "wechat_hook.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <detours/detours.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "base64.h"
|
||||||
|
#include "http_client.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "thread_pool.h"
|
||||||
|
#include "wxutils.h"
|
||||||
|
namespace offset = wxhelper::V3_9_7_29::offset;
|
||||||
|
namespace common = wxhelper::common;
|
||||||
|
|
||||||
|
namespace hook {
|
||||||
|
static bool kEnableHttp = false;
|
||||||
|
static bool kLogHookFlag = false;
|
||||||
|
static char kServerIp[20] = "127.0.0.1";
|
||||||
|
static int kServerPort = 19099;
|
||||||
|
|
||||||
|
UINT64(*RealDoAddMsg)
|
||||||
|
(UINT64, UINT64, UINT64) = (UINT64(*)(UINT64, UINT64, UINT64))(
|
||||||
|
wxhelper::wxutils::GetWeChatWinBase() + offset::kDoAddMsg);
|
||||||
|
|
||||||
|
VOID SendMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||||
|
PTP_WORK Work) {
|
||||||
|
common::InnerMessageStruct *msg = (common::InnerMessageStruct *)context;
|
||||||
|
if (msg == NULL) {
|
||||||
|
SPDLOG_INFO("add work:msg is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::unique_ptr<common::InnerMessageStruct> sms(msg);
|
||||||
|
nlohmann::json j_msg = nlohmann::json::parse(
|
||||||
|
msg->buffer, msg->buffer + msg->length, nullptr, false);
|
||||||
|
if (j_msg.is_discarded() == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string jstr = j_msg.dump() + "\n";
|
||||||
|
|
||||||
|
WSADATA was_data = {0};
|
||||||
|
int ret = WSAStartup(MAKEWORD(2, 2), &was_data);
|
||||||
|
if (ret != 0) {
|
||||||
|
SPDLOG_ERROR("WSAStartup failed:{}", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
if (client_socket < 0) {
|
||||||
|
SPDLOG_ERROR("socket init fail");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BOOL status = false;
|
||||||
|
sockaddr_in client_addr;
|
||||||
|
memset(&client_addr, 0, sizeof(client_addr));
|
||||||
|
client_addr.sin_family = AF_INET;
|
||||||
|
client_addr.sin_port = htons((u_short)kServerPort);
|
||||||
|
InetPtonA(AF_INET, kServerIp, &client_addr.sin_addr.s_addr);
|
||||||
|
if (connect(client_socket, reinterpret_cast<sockaddr *>(&client_addr),
|
||||||
|
sizeof(sockaddr)) < 0) {
|
||||||
|
SPDLOG_ERROR("socket connect fail. host:{} , port:{},",kServerIp,kServerPort);
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
char recv_buf[1024] = {0};
|
||||||
|
ret = send(client_socket, jstr.c_str(), static_cast<int>(jstr.size()), 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
SPDLOG_ERROR("socket send fail ,ret:{}", ret);
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
ret = shutdown(client_socket, SD_SEND);
|
||||||
|
if (ret == SOCKET_ERROR) {
|
||||||
|
SPDLOG_ERROR("shutdown failed with erro:{}", ret);
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
ret = recv(client_socket, recv_buf, sizeof(recv_buf), 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
SPDLOG_ERROR("socket recv fail ,ret:{}", ret);
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
clean:
|
||||||
|
closesocket(client_socket);
|
||||||
|
WSACleanup();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID SendHttpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
||||||
|
PTP_WORK Work) {
|
||||||
|
common::InnerMessageStruct *msg = (common::InnerMessageStruct *)context;
|
||||||
|
if (msg == NULL) {
|
||||||
|
SPDLOG_INFO("http msg is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<common::InnerMessageStruct> sms(msg);
|
||||||
|
nlohmann::json j_msg = nlohmann::json::parse(
|
||||||
|
msg->buffer, msg->buffer + msg->length, nullptr, false);
|
||||||
|
if (j_msg.is_discarded() == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string jstr = j_msg.dump() + "\n";
|
||||||
|
http::HttpClient::SendRequest(jstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleSyncMsg(INT64 param1, INT64 param2, INT64 param3) {
|
||||||
|
nlohmann::json msg;
|
||||||
|
|
||||||
|
msg["pid"] = GetCurrentProcessId();
|
||||||
|
msg["fromUser"] =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x18));
|
||||||
|
msg["toUser"] =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x28));
|
||||||
|
msg["content"] =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x30));
|
||||||
|
msg["signature"] =
|
||||||
|
wxhelper::wxutils::ReadWeChatStr(*(INT64 *)(param2 + 0x48));
|
||||||
|
msg["msgId"] = *(INT64 *)(param2 + 0x60);
|
||||||
|
msg["msgSequence"] = *(DWORD *)(param2 + 0x5C);
|
||||||
|
msg["createTime"] = *(DWORD *)(param2 + 0x58);
|
||||||
|
msg["displayFullContent"] =
|
||||||
|
wxhelper::wxutils::ReadWeChatStr(*(INT64 *)(param2 + 0x50));
|
||||||
|
DWORD type = *(DWORD *)(param2 + 0x24);
|
||||||
|
msg["type"] = type;
|
||||||
|
if (type == 3) {
|
||||||
|
int a = 1;
|
||||||
|
std::string img =
|
||||||
|
wxhelper::wxutils::ReadSKBuiltinBuffer(*(INT64 *)(param2 + 0x40));
|
||||||
|
SPDLOG_INFO("encode size:{}", img.size());
|
||||||
|
msg["base64Img"] = base64_encode(img);
|
||||||
|
a = 2;
|
||||||
|
}
|
||||||
|
std::string jstr = msg.dump() + '\n';
|
||||||
|
common::InnerMessageStruct *inner_msg = new common::InnerMessageStruct;
|
||||||
|
inner_msg->buffer = new char[jstr.size() + 1];
|
||||||
|
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
|
||||||
|
inner_msg->length = jstr.size();
|
||||||
|
if (kEnableHttp) {
|
||||||
|
bool add =
|
||||||
|
base::ThreadPool::GetInstance().AddWork(SendHttpMsgCallback, inner_msg);
|
||||||
|
SPDLOG_INFO("add http msg work:{}", add);
|
||||||
|
} else {
|
||||||
|
bool add =
|
||||||
|
base::ThreadPool::GetInstance().AddWork(SendMsgCallback, inner_msg);
|
||||||
|
SPDLOG_INFO("add msg work:{}", add);
|
||||||
|
}
|
||||||
|
RealDoAddMsg(param1, param2, param3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WechatHook::Init(WechatHookParam param) {
|
||||||
|
if(!init_){
|
||||||
|
param_ = param;
|
||||||
|
kEnableHttp = param.enable_http;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int WechatHook::HookSyncMsg() {
|
||||||
|
if (sync_msg_flag_) {
|
||||||
|
SPDLOG_INFO("recv msg hook already called");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param_.server_ip.size() < 1) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
UINT64 base = wxhelper::wxutils::GetWeChatWinBase();
|
||||||
|
if (!base) {
|
||||||
|
SPDLOG_INFO("base addr is null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (param_.enable_http) {
|
||||||
|
http::HttpClient::SetConfig(param_.http_url,param_.http_time_out);
|
||||||
|
}else{
|
||||||
|
const char* charPtr = param_.server_ip.c_str();
|
||||||
|
std::strcpy(kServerIp, charPtr);
|
||||||
|
kServerPort = param_.server_port;
|
||||||
|
}
|
||||||
|
DetourTransactionBegin();
|
||||||
|
DetourUpdateThread(GetCurrentThread());
|
||||||
|
DetourAttach(&(PVOID &)RealDoAddMsg, &HandleSyncMsg);
|
||||||
|
LONG ret = DetourTransactionCommit();
|
||||||
|
if (ret == NO_ERROR) {
|
||||||
|
sync_msg_flag_ = true;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
int WechatHook::UnHookSyncMsg() {
|
||||||
|
if (!sync_msg_flag_) {
|
||||||
|
SPDLOG_INFO("call UnHookSyncMsg but no hooked ");
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
UINT64 base = wxhelper::wxutils::GetWeChatWinBase();
|
||||||
|
DetourTransactionBegin();
|
||||||
|
DetourUpdateThread(GetCurrentThread());
|
||||||
|
DetourDetach(&(PVOID &)RealDoAddMsg, &HandleSyncMsg);
|
||||||
|
LONG ret = DetourTransactionCommit();
|
||||||
|
if (ret == NO_ERROR) {
|
||||||
|
sync_msg_flag_ = false;
|
||||||
|
strcpy_s(kServerIp, "127.0.0.1");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
int WechatHook::HookLog() { return 0; }
|
||||||
|
int WechatHook::UnHookLog() { return 0; }
|
||||||
|
} // namespace hook
|
34
app/wxhelper/src/wechat_hook.h
Normal file
34
app/wxhelper/src/wechat_hook.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef WXHELPER_WECHAT_HOOK_H_
|
||||||
|
#define WXHELPER_WECHAT_HOOK_H_
|
||||||
|
#include "wechat_function.h"
|
||||||
|
#include "singleton.h"
|
||||||
|
|
||||||
|
namespace hook {
|
||||||
|
struct WechatHookParam {
|
||||||
|
std::string server_ip = "127.0.0.1";
|
||||||
|
std::string http_url = "http:://127.0.0.1:19088";
|
||||||
|
int server_port = 19099;
|
||||||
|
bool enable_http = false;
|
||||||
|
uint64_t http_time_out = 3000;
|
||||||
|
};
|
||||||
|
|
||||||
|
class WechatHook :public base::Singleton<WechatHook>{
|
||||||
|
public:
|
||||||
|
void Init(WechatHookParam param);
|
||||||
|
|
||||||
|
int HookSyncMsg();
|
||||||
|
int UnHookSyncMsg();
|
||||||
|
|
||||||
|
int HookLog();
|
||||||
|
|
||||||
|
int UnHookLog();
|
||||||
|
|
||||||
|
private:
|
||||||
|
WechatHookParam param_;
|
||||||
|
bool sync_msg_flag_;
|
||||||
|
bool init_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace hook
|
||||||
|
|
||||||
|
#endif
|
383
app/wxhelper/src/wechat_service.cc
Normal file
383
app/wxhelper/src/wechat_service.cc
Normal file
@ -0,0 +1,383 @@
|
|||||||
|
#include "wechat_service.h"
|
||||||
|
#include "wxutils.h"
|
||||||
|
#include "utils.h"
|
||||||
|
namespace offset = wxhelper::V3_9_7_29::offset;
|
||||||
|
namespace prototype = wxhelper::V3_9_7_29::prototype;
|
||||||
|
namespace func = wxhelper::V3_9_7_29::function;
|
||||||
|
namespace wxhelper {
|
||||||
|
WechatService::~WechatService() {}
|
||||||
|
|
||||||
|
INT64 WechatService::CheckLogin() {
|
||||||
|
INT64 success = -1;
|
||||||
|
UINT64 accout_service_addr = base_addr_ + offset::kGetAccountServiceMgr;
|
||||||
|
func::__GetAccountService GetSevice =
|
||||||
|
(func::__GetAccountService)accout_service_addr;
|
||||||
|
UINT64 service_addr = GetSevice();
|
||||||
|
if (service_addr) {
|
||||||
|
success = *(UINT64*)(service_addr + 0x7F8);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::GetSelfInfo(common::SelfInfoInner& out) {
|
||||||
|
INT64 success = -1;
|
||||||
|
UINT64 accout_service_addr = base_addr_ + offset::kGetAccountServiceMgr;
|
||||||
|
UINT64 get_app_data_save_path_addr = base_addr_ + offset::kGetAppDataSavePath;
|
||||||
|
UINT64 get_current_data_path_addr = base_addr_ + offset::kGetCurrentDataPath;
|
||||||
|
func::__GetAccountService GetSevice = (func::__GetAccountService)accout_service_addr;
|
||||||
|
func::__GetDataSavePath GetDataSavePath = (func::__GetDataSavePath)get_app_data_save_path_addr;
|
||||||
|
func::__GetCurrentDataPath GetCurrentDataPath = (func::__GetCurrentDataPath)get_current_data_path_addr;
|
||||||
|
|
||||||
|
UINT64 service_addr = GetSevice();
|
||||||
|
if (service_addr) {
|
||||||
|
if (*(INT64 *)(service_addr + 0x80) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x80 + 0x10) == 0) {
|
||||||
|
out.wxid = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x80 + 0x18) == 0xF) {
|
||||||
|
out.wxid = std::string((char *)(service_addr + 0x80),
|
||||||
|
*(INT64 *)(service_addr + 0x80 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.wxid = std::string(*(char **)(service_addr + 0x80),
|
||||||
|
*(INT64 *)(service_addr + 0x80 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x108) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x108 + 0x10) == 0) {
|
||||||
|
out.account = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x108 + 0x18) == 0xF) {
|
||||||
|
out.account = std::string((char *)(service_addr + 0x108),
|
||||||
|
*(INT64 *)(service_addr + 0x108 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.account = std::string(*(char **)(service_addr + 0x108),
|
||||||
|
*(INT64 *)(service_addr + 0x108 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x128) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x128 + 0x10) == 0) {
|
||||||
|
out.mobile = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x128 + 0x18) == 0xF) {
|
||||||
|
out.mobile = std::string((char *)(service_addr + 0x128),
|
||||||
|
*(INT64 *)(service_addr + 0x128 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.mobile = std::string(*(char **)(service_addr + 0x128),
|
||||||
|
*(INT64 *)(service_addr + 0x128 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x148) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x148 + 0x10) == 0) {
|
||||||
|
out.signature = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x148 + 0x18) == 0xF) {
|
||||||
|
out.signature = std::string((char *)(service_addr + 0x148),
|
||||||
|
*(INT64 *)(service_addr + 0x148 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.signature = std::string(*(char **)(service_addr + 0x148),
|
||||||
|
*(INT64 *)(service_addr + 0x148 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x168) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x168 + 0x10) == 0) {
|
||||||
|
out.country = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x168 + 0x18) == 0xF) {
|
||||||
|
out.country = std::string((char *)(service_addr + 0x168),
|
||||||
|
*(INT64 *)(service_addr + 0x168 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.country = std::string(*(char **)(service_addr + 0x168),
|
||||||
|
*(INT64 *)(service_addr + 0x168 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x188) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x188 + 0x10) == 0) {
|
||||||
|
out.province = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x188 + 0x18) == 0xF) {
|
||||||
|
out.province = std::string((char *)(service_addr + 0x188),
|
||||||
|
*(INT64 *)(service_addr + 0x188 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.province = std::string(*(char **)(service_addr + 0x188),
|
||||||
|
*(INT64 *)(service_addr + 0x188 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x1A8) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x1A8 + 0x10) == 0) {
|
||||||
|
out.city = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x1A8 + 0x18) == 0xF) {
|
||||||
|
out.city = std::string((char *)(service_addr + 0x1A8),
|
||||||
|
*(INT64 *)(service_addr + 0x1A8 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.city = std::string(*(char **)(service_addr + 0x1A8),
|
||||||
|
*(INT64 *)(service_addr + 0x1A8 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x1E8) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x1E8 + 0x10) == 0) {
|
||||||
|
out.name = std::string();
|
||||||
|
} else {
|
||||||
|
if (*(INT64 *)(service_addr + 0x1E8 + 0x18) == 0xF) {
|
||||||
|
out.name = std::string((char *)(service_addr + 0x1E8),
|
||||||
|
*(INT64 *)(service_addr + 0x1E8 + 0x10));
|
||||||
|
} else {
|
||||||
|
out.name = std::string(*(char **)(service_addr + 0x1E8),
|
||||||
|
*(INT64 *)(service_addr + 0x1E8 + 0x10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x450) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x450 + 0x10) == 0) {
|
||||||
|
out.head_img = std::string();
|
||||||
|
} else {
|
||||||
|
out.head_img = std::string(*(char **)(service_addr + 0x450),
|
||||||
|
*(INT64 *)(service_addr + 0x450 + 0x10));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*(INT64 *)(service_addr + 0x6E0) == 0 ||
|
||||||
|
*(INT64 *)(service_addr + 0x6E8) == 0) {
|
||||||
|
out.db_key = std::string();
|
||||||
|
} else {
|
||||||
|
INT64 byte_addr = *(INT64 *)(service_addr + 0x6E0);
|
||||||
|
INT64 len = *(INT64 *)(service_addr + 0x6E8);
|
||||||
|
out.db_key = base::utils::Bytes2Hex((BYTE *)byte_addr, static_cast<int>(len));
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT64 flag = *(UINT64 *)(service_addr + 0x7F8);
|
||||||
|
if (flag == 1) {
|
||||||
|
prototype::WeChatString current_data_path;
|
||||||
|
// _GetCurrentDataPath(get_current_data_path_addr,
|
||||||
|
// reinterpret_cast<ULONG_PTR>(¤t_data_path));
|
||||||
|
GetCurrentDataPath(reinterpret_cast<ULONG_PTR>(¤t_data_path));
|
||||||
|
if (current_data_path.ptr) {
|
||||||
|
out.current_data_path = base::utils::WstringToUtf8(
|
||||||
|
std::wstring(current_data_path.ptr, current_data_path.length));
|
||||||
|
} else {
|
||||||
|
out.current_data_path = std::string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prototype::WeChatString data_save_path;
|
||||||
|
// _GetDataSavePath(get_app_data_save_path_addr,
|
||||||
|
// reinterpret_cast<ULONG_PTR>(&data_save_path));
|
||||||
|
GetCurrentDataPath(reinterpret_cast<ULONG_PTR>(&data_save_path));
|
||||||
|
if (data_save_path.ptr) {
|
||||||
|
out.data_save_path = base::utils::WstringToUtf8(
|
||||||
|
std::wstring(data_save_path.ptr, data_save_path.length));
|
||||||
|
} else {
|
||||||
|
out.data_save_path = std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
success = 1;
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SendTextMsg(const std::wstring& wxid,
|
||||||
|
const std::wstring& msg) {
|
||||||
|
INT64 success = -1;
|
||||||
|
prototype::WeChatString to_user(wxid);
|
||||||
|
prototype::WeChatString text_msg(msg);
|
||||||
|
UINT64 send_message_mgr_addr = base_addr_ + offset::kGetSendMessageMgr;
|
||||||
|
UINT64 send_text_msg_addr = base_addr_ + offset::kSendTextMsg;
|
||||||
|
UINT64 free_chat_msg_addr = base_addr_ + offset::kFreeChatMsg;
|
||||||
|
char chat_msg[0x460] = {0};
|
||||||
|
UINT64 temp[3] = {0};
|
||||||
|
func::__GetSendMessageMgr mgr;
|
||||||
|
mgr = (func::__GetSendMessageMgr)send_message_mgr_addr;
|
||||||
|
func::__SendTextMsg send;
|
||||||
|
send = (func::__SendTextMsg)send_text_msg_addr;
|
||||||
|
func::__FreeChatMsg free;
|
||||||
|
free = (func::__FreeChatMsg)free_chat_msg_addr;
|
||||||
|
mgr();
|
||||||
|
send(reinterpret_cast<UINT64>(&chat_msg), reinterpret_cast<UINT64>(&to_user),
|
||||||
|
reinterpret_cast<UINT64>(&text_msg), reinterpret_cast<UINT64>(&temp), 1,
|
||||||
|
1, 0, 0);
|
||||||
|
free(reinterpret_cast<UINT64>(&chat_msg));
|
||||||
|
success = 1;
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SendImageMsg(const std::wstring& wxid,
|
||||||
|
const std::wstring& image_path) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SendFileMsg(const std::wstring& wxid,
|
||||||
|
const std::wstring& file_path) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::GetContacts(std::vector<common::ContactInner>& vec) {
|
||||||
|
INT64 success = -1;
|
||||||
|
UINT64 get_contact_mgr_addr = base_addr_ + offset::kGetContactMgr;
|
||||||
|
UINT64 get_contact_list_addr = base_addr_ + offset::kGetContactList;
|
||||||
|
func::__GetContactMgr get_contact_mgr =
|
||||||
|
(func::__GetContactMgr)get_contact_mgr_addr;
|
||||||
|
func::__GetContactList get_contact_list =
|
||||||
|
(func::__GetContactList)get_contact_list_addr;
|
||||||
|
UINT64 mgr = get_contact_mgr();
|
||||||
|
UINT64 contact_vec[3] = {0, 0, 0};
|
||||||
|
success = get_contact_list(mgr, reinterpret_cast<UINT64>(&contact_vec));
|
||||||
|
|
||||||
|
UINT64 start = contact_vec[0];
|
||||||
|
UINT64 end = contact_vec[2];
|
||||||
|
while (start < end) {
|
||||||
|
common::ContactInner temp;
|
||||||
|
temp.wxid = wxutils::ReadWstringThenConvert(start + 0x10);
|
||||||
|
temp.custom_account = wxutils::ReadWstringThenConvert(start + 0x30);
|
||||||
|
temp.encrypt_name = wxutils::ReadWstringThenConvert(start + 0x50);
|
||||||
|
temp.nickname = wxutils::ReadWstringThenConvert(start + 0xA0);
|
||||||
|
temp.pinyin = wxutils::ReadWstringThenConvert(start + 0x108);
|
||||||
|
temp.pinyin_all = wxutils::ReadWstringThenConvert(start + 0x128);
|
||||||
|
temp.verify_flag = *(DWORD *)(start + 0x70);
|
||||||
|
temp.type = *(DWORD *)(start + 0x74);
|
||||||
|
temp.reserved1 = *(DWORD *)(start + 0x1F0);
|
||||||
|
temp.reserved2 = *(DWORD *)(start + 0x1F4);
|
||||||
|
vec.push_back(temp);
|
||||||
|
start += 0x6A8;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::GetChatRoomDetailInfo(
|
||||||
|
const std::wstring& room_id, common::ChatRoomInfoInner& room_info) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::AddMemberToChatRoom(
|
||||||
|
const std::wstring& room_id, const std::vector<std::wstring>& members) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::ModChatRoomMemberNickName(const std::wstring& room_id,
|
||||||
|
const std::wstring& wxid,
|
||||||
|
const std::wstring& nickname) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::DelMemberFromChatRoom(
|
||||||
|
const std::wstring& room_id, const std::vector<std::wstring>& members) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::GetMemberFromChatRoom(
|
||||||
|
const std::wstring& room_id, common::ChatRoomMemberInner& member) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SetTopMsg(ULONG64 msg_id) { return INT64(); }
|
||||||
|
|
||||||
|
INT64 WechatService::RemoveTopMsg(const std::wstring& room_id, ULONG64 msg_id) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::InviteMemberToChatRoom(
|
||||||
|
const std::wstring& room_id, const std::vector<std::wstring>& wxids) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::CreateChatRoom(const std::vector<std::wstring>& wxids) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::QuitChatRoom(const std::wstring& room_id) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::ForwardMsg(UINT64 msg_id, const std::wstring& wxid) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::GetSNSFirstPage() { return INT64(); }
|
||||||
|
|
||||||
|
INT64 WechatService::GetSNSNextPage(UINT64 sns_id) { return INT64(); }
|
||||||
|
|
||||||
|
INT64 WechatService::AddFavFromMsg(UINT64 msg_id) { return INT64(); }
|
||||||
|
|
||||||
|
INT64 WechatService::AddFavFromImage(const std::wstring& wxid,
|
||||||
|
const std::wstring& image_path) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SendAtText(const std::wstring& room_id,
|
||||||
|
const std::vector<std::wstring>& wxids,
|
||||||
|
const std::wstring& msg) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring WechatService::GetContactOrChatRoomNickname(
|
||||||
|
const std::wstring& wxid) {
|
||||||
|
return std::wstring();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::GetContactByWxid(const std::wstring& wxid,
|
||||||
|
common::ContactProfileInner& profile) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::DoDownloadTask(UINT64 msg_id) { return INT64(); }
|
||||||
|
|
||||||
|
INT64 WechatService::ForwardPublicMsg(const std::wstring& wxid,
|
||||||
|
const std::wstring& title,
|
||||||
|
const std::wstring& url,
|
||||||
|
const std::wstring& thumb_url,
|
||||||
|
const std::wstring& sender_id,
|
||||||
|
const std::wstring& sender_name,
|
||||||
|
const std::wstring& digest) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::ForwardPublicMsgByMsgId(const std::wstring& wxid,
|
||||||
|
UINT64 msg_id) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::DecodeImage(const std::wstring& file_path,
|
||||||
|
const std::wstring& save_dir) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::GetVoiceByDB(ULONG64 msg_id, const std::wstring& dir) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SendCustomEmotion(const std::wstring& file_path,
|
||||||
|
const std::wstring& wxid) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SendApplet(
|
||||||
|
const std::wstring& recv_wxid, const std::wstring& waid_suff,
|
||||||
|
const std::wstring& waid_w, const std::string& waid_s,
|
||||||
|
const std::string& wa_wxid, const std::string& json_param,
|
||||||
|
const std::string& head_image, const std::string& big_image,
|
||||||
|
const std::string& index_page) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::SendPatMsg(const std::wstring& room_id,
|
||||||
|
const std::wstring& wxid) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
INT64 WechatService::DoOCRTask(const std::wstring& img_path,
|
||||||
|
std::string& result) {
|
||||||
|
return INT64();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WechatService::SetBaseAddr(UINT64 addr) { base_addr_ = addr; }
|
||||||
|
|
||||||
|
void WechatService::SetJsApiAddr(UINT64 addr) { js_api_addr_ = addr; }
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace wxhelper
|
@ -1,18 +1,25 @@
|
|||||||
#ifndef WXHELPER_MANAGER_H_
|
#ifndef WXHELPER_WECHAT_SERVICE_H_
|
||||||
#define WXHELPER_MANAGER_H_
|
#define WXHELPER_WECHAT_SERVICE_H_
|
||||||
#include "Windows.h"
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "singleton.h"
|
||||||
#include "wechat_function.h"
|
#include "wechat_function.h"
|
||||||
namespace wxhelper {
|
namespace wxhelper {
|
||||||
class Manager {
|
|
||||||
|
class WechatService : public base::Singleton<WechatService> {
|
||||||
|
friend class base::Singleton<WechatService>;
|
||||||
|
~WechatService();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Manager(UINT64 base);
|
|
||||||
~Manager();
|
|
||||||
INT64 CheckLogin();
|
INT64 CheckLogin();
|
||||||
INT64 GetSelfInfo(common::SelfInfoInner& out);
|
INT64 GetSelfInfo(common::SelfInfoInner& out);
|
||||||
INT64 SendTextMsg(const std::wstring& wxid, const std::wstring& msg);
|
INT64 SendTextMsg(const std::wstring& wxid, const std::wstring& msg);
|
||||||
INT64 SendImageMsg(const std::wstring& wxid, const std::wstring& image_path);
|
INT64 SendImageMsg(const std::wstring& wxid, const std::wstring& image_path);
|
||||||
INT64 SendFileMsg(const std::wstring& wxid, const std::wstring& file_path);
|
INT64 SendFileMsg(const std::wstring& wxid, const std::wstring& file_path);
|
||||||
INT64 GetContacts(std::vector<common::ContactInner> &vec);
|
INT64 GetContacts(std::vector<common::ContactInner>& vec);
|
||||||
INT64 GetChatRoomDetailInfo(const std::wstring& room_id,
|
INT64 GetChatRoomDetailInfo(const std::wstring& room_id,
|
||||||
common::ChatRoomInfoInner& room_info);
|
common::ChatRoomInfoInner& room_info);
|
||||||
INT64 AddMemberToChatRoom(const std::wstring& room_id,
|
INT64 AddMemberToChatRoom(const std::wstring& room_id,
|
||||||
@ -26,7 +33,7 @@ class Manager {
|
|||||||
INT64 GetMemberFromChatRoom(const std::wstring& room_id,
|
INT64 GetMemberFromChatRoom(const std::wstring& room_id,
|
||||||
common::ChatRoomMemberInner& member);
|
common::ChatRoomMemberInner& member);
|
||||||
INT64 SetTopMsg(ULONG64 msg_id);
|
INT64 SetTopMsg(ULONG64 msg_id);
|
||||||
INT64 RemoveTopMsg(const std::wstring& room_id,ULONG64 msg_id);
|
INT64 RemoveTopMsg(const std::wstring& room_id, ULONG64 msg_id);
|
||||||
INT64 InviteMemberToChatRoom(const std::wstring& room_id,
|
INT64 InviteMemberToChatRoom(const std::wstring& room_id,
|
||||||
const std::vector<std::wstring>& wxids);
|
const std::vector<std::wstring>& wxids);
|
||||||
INT64 CreateChatRoom(const std::vector<std::wstring>& wxids);
|
INT64 CreateChatRoom(const std::vector<std::wstring>& wxids);
|
||||||
@ -56,19 +63,21 @@ class Manager {
|
|||||||
INT64 GetVoiceByDB(ULONG64 msg_id, const std::wstring& dir);
|
INT64 GetVoiceByDB(ULONG64 msg_id, const std::wstring& dir);
|
||||||
INT64 SendCustomEmotion(const std::wstring& file_path,
|
INT64 SendCustomEmotion(const std::wstring& file_path,
|
||||||
const std::wstring& wxid);
|
const std::wstring& wxid);
|
||||||
INT64 SendApplet(
|
INT64 SendApplet(const std::wstring& recv_wxid, const std::wstring& waid_suff,
|
||||||
const std::wstring& recv_wxid, const std::wstring& waid_suff,
|
const std::wstring& waid_w, const std::string& waid_s,
|
||||||
const std::wstring& waid_w, const std::string& waid_s,
|
const std::string& wa_wxid, const std::string& json_param,
|
||||||
const std::string& wa_wxid, const std::string& json_param,
|
const std::string& head_image, const std::string& big_image,
|
||||||
const std::string& head_image, const std::string& big_image,
|
const std::string& index_page);
|
||||||
const std::string& index_page);
|
|
||||||
INT64 SendPatMsg(const std::wstring& room_id, const std::wstring& wxid);
|
INT64 SendPatMsg(const std::wstring& room_id, const std::wstring& wxid);
|
||||||
INT64 DoOCRTask(const std::wstring& img_path, std::string &result);
|
INT64 DoOCRTask(const std::wstring& img_path, std::string& result);
|
||||||
INT64 Test();
|
void SetBaseAddr(UINT64 addr);
|
||||||
|
void SetJsApiAddr(UINT64 addr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UINT64 base_addr_;
|
UINT64 base_addr_;
|
||||||
UINT64 js_api_addr_;
|
UINT64 js_api_addr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace wxhelper
|
} // namespace wxhelper
|
||||||
|
|
||||||
#endif
|
#endif
|
99
app/wxhelper/src/wxutils.cc
Normal file
99
app/wxhelper/src/wxutils.cc
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#include "wxutils.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#define BUFSIZE 1024
|
||||||
|
#define JPEG0 0xFF
|
||||||
|
#define JPEG1 0xD8
|
||||||
|
#define JPEG2 0xFF
|
||||||
|
#define PNG0 0x89
|
||||||
|
#define PNG1 0x50
|
||||||
|
#define PNG2 0x4E
|
||||||
|
#define BMP0 0x42
|
||||||
|
#define BMP1 0x4D
|
||||||
|
#define GIF0 0x47
|
||||||
|
#define GIF1 0x49
|
||||||
|
#define GIF2 0x46
|
||||||
|
namespace wxhelper {
|
||||||
|
namespace wxutils {
|
||||||
|
UINT64 GetWeChatWinBase() { return (UINT64)GetModuleHandleA("WeChatWin.dll"); }
|
||||||
|
|
||||||
|
std::string ReadSKBuiltinString(INT64 addr) {
|
||||||
|
INT64 inner_string = *(INT64 *)(addr + 0x8);
|
||||||
|
if (inner_string == 0) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
return ReadWeChatStr(inner_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ReadSKBuiltinBuffer(INT64 addr) {
|
||||||
|
INT64 len = *(INT64 *)(addr + 0x10);
|
||||||
|
if (len == 0) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
INT64 inner_string = *(INT64 *)(addr + 0x8);
|
||||||
|
if (inner_string == 0) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
return ReadWeChatStr(inner_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ReadWeChatStr(INT64 addr) {
|
||||||
|
INT64 len = *(INT64 *)(addr + 0x10);
|
||||||
|
if (len == 0) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
INT64 max_len = *(INT64 *)(addr + 0x18);
|
||||||
|
if ((max_len | 0xF) == 0xF) {
|
||||||
|
return std::string((char *)addr, len);
|
||||||
|
}
|
||||||
|
char *char_from_user = *(char **)(addr);
|
||||||
|
return std::string(char_from_user, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ImageXor(std::string buf) {
|
||||||
|
const char *origin = buf.c_str();
|
||||||
|
short key = 0;
|
||||||
|
if ((*origin ^ JPEG0) == (*(origin + 1) ^ JPEG1)) {
|
||||||
|
key = *origin ^ JPEG0;
|
||||||
|
} else if ((*origin ^ PNG1) == (*(origin + 1) ^ PNG2)) {
|
||||||
|
key = *origin ^ PNG1;
|
||||||
|
} else if ((*origin ^ GIF0) == (*(origin + 1) ^ GIF1)) {
|
||||||
|
key = *origin ^ GIF0;
|
||||||
|
} else if ((*origin ^ BMP0) == (*(origin + 1) ^ BMP1)) {
|
||||||
|
key = *origin ^ BMP0;
|
||||||
|
} else {
|
||||||
|
key = -1;
|
||||||
|
}
|
||||||
|
if (key > 0) {
|
||||||
|
char *img_buf = new char[buf.size()];
|
||||||
|
for (unsigned int i = 0; i < buf.size(); i++) {
|
||||||
|
img_buf[i] = *(origin + i) ^ key;
|
||||||
|
}
|
||||||
|
std::string str(img_buf);
|
||||||
|
delete[] img_buf;
|
||||||
|
img_buf = NULL;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring ReadWstring(INT64 addr) {
|
||||||
|
DWORD len = *(DWORD *)(addr + 0x8);
|
||||||
|
if (len == 0) {
|
||||||
|
return std::wstring();
|
||||||
|
}
|
||||||
|
wchar_t *str = *(wchar_t **)(addr);
|
||||||
|
if (str == NULL) {
|
||||||
|
return std::wstring();
|
||||||
|
}
|
||||||
|
return std::wstring(str, len);
|
||||||
|
}
|
||||||
|
std::string ReadWstringThenConvert(INT64 addr) {
|
||||||
|
std::wstring wstr = ReadWstring(addr);
|
||||||
|
return base::utils::WstringToUtf8(wstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace wxutils
|
||||||
|
} // namespace wxhelper
|
21
app/wxhelper/src/wxutils.h
Normal file
21
app/wxhelper/src/wxutils.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef WXHELPER_WXUTILS_H_
|
||||||
|
#define WXHELPER_WXUTILS_H_
|
||||||
|
#include <windows.h>
|
||||||
|
#include <string>
|
||||||
|
namespace wxhelper {
|
||||||
|
namespace wxutils {
|
||||||
|
|
||||||
|
UINT64 GetWeChatWinBase();
|
||||||
|
std::string ReadSKBuiltinString(INT64 addr);
|
||||||
|
std::string ReadSKBuiltinBuffer(INT64 addr);
|
||||||
|
std::string ReadWeChatStr(INT64 addr);
|
||||||
|
|
||||||
|
std::string ImageXor(std::string buf);
|
||||||
|
std::wstring ReadWstring(INT64 addr);
|
||||||
|
std::string ReadWstringThenConvert(INT64 addr);
|
||||||
|
|
||||||
|
INT64 DecodeImage(const wchar_t* file_path, const wchar_t* save_dir);
|
||||||
|
} // namespace wxutils
|
||||||
|
|
||||||
|
} // namespace wxhelper
|
||||||
|
#endif
|
0
doc/3.9.7.25.md
Normal file
0
doc/3.9.7.25.md
Normal file
462
doc/3.9.7.29.md
Normal file
462
doc/3.9.7.29.md
Normal file
@ -0,0 +1,462 @@
|
|||||||
|
|
||||||
|
|
||||||
|
## 3.9.7.29版本,http接口文档,文档仅供参考。
|
||||||
|
|
||||||
|
### 简单说明:
|
||||||
|
所有接口只支持post方法。
|
||||||
|
全部使用json格式。
|
||||||
|
格式: http://host:port/api/xxxx
|
||||||
|
host: 绑定的host
|
||||||
|
port: 监听的端口
|
||||||
|
xxxx: 对应的功能路径
|
||||||
|
返回结构的json格式:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"data": {},
|
||||||
|
"msg": "success"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
code: 错误码
|
||||||
|
msg: 成功/错误信息
|
||||||
|
data: 接口返回的数据
|
||||||
|
|
||||||
|
|
||||||
|
接口与3.9.5.81基本无变化,优化了httpclient连接。
|
||||||
|
config.ini 配置文件可以配置http服务端口和隐藏dll
|
||||||
|
```
|
||||||
|
Port=19088
|
||||||
|
HiddenDll=0 //1隐藏 0不隐藏
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### 0.检查微信登录**
|
||||||
|
###### 接口功能
|
||||||
|
> 检查微信是否登录
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/checkLogin](/api/checkLogin)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,1 成功, 0失败|
|
||||||
|
|result|string|成功提示|
|
||||||
|
|data|string|响应内容|
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"msg": "success",
|
||||||
|
"data":null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 1.获取登录用户信息**
|
||||||
|
###### 接口功能
|
||||||
|
> 获取登录用户信息
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/userInfo](/api/userInfo)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,1 成功, 0失败|
|
||||||
|
|result|string|成功提示|
|
||||||
|
|data|object|响应内容|
|
||||||
|
|  account|string|账号|
|
||||||
|
|  headImage|string|头像|
|
||||||
|
|  city|string|城市|
|
||||||
|
|  country|string|国家|
|
||||||
|
|  currentDataPath|string|当前数据目录,登录的账号目录|
|
||||||
|
|  dataSavePath|string|微信保存目录|
|
||||||
|
|  mobile|string|手机|
|
||||||
|
|  name|string|昵称|
|
||||||
|
|  province|string|省|
|
||||||
|
|  wxid|string|wxid|
|
||||||
|
|  signature|string|个人签名|
|
||||||
|
|  dbKey|string|数据库的SQLCipher的加密key,可以使用该key配合decrypt.py解密数据库
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"data": {
|
||||||
|
"account": "xxx",
|
||||||
|
"city": "Zhengzhou",
|
||||||
|
"country": "CN",
|
||||||
|
"currentDataPath": "C:\\WeChat Files\\wxid_xxx\\",
|
||||||
|
"dataSavePath": "C:\\wechatDir\\WeChat Files\\",
|
||||||
|
"dbKey": "965715e30e474da09250cb5aa047e3940ffa1c8f767c4263b132bb512933db49",
|
||||||
|
"headImage": "https://wx.qlogo.cn/mmhead/ver_1/MiblV0loY0GILewQ4u2121",
|
||||||
|
"mobile": "13949175447",
|
||||||
|
"name": "xxx",
|
||||||
|
"province": "Henan",
|
||||||
|
"signature": "xxx",
|
||||||
|
"wxid": "wxid_22222"
|
||||||
|
},
|
||||||
|
"msg": "success"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### 2.发送文本消息**
|
||||||
|
###### 接口功能
|
||||||
|
> 发送文本消息
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/sendTextMsg](/api/sendTextMsg)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|wxid |true |string| 接收人wxid |
|
||||||
|
|msg|true |string|消息文本内容|
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,不为0成功, 0失败|
|
||||||
|
|msg|string|成功提示|
|
||||||
|
|data|object|null|
|
||||||
|
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"wxid": "filehelper",
|
||||||
|
"msg": "1112222"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{"code":345686720,"msg":"success","data":null}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3.hook消息**
|
||||||
|
###### 接口功能
|
||||||
|
> hook接收文本消息,图片消息,群消息.该接口将hook的消息通过tcp回传给本地的端口。
|
||||||
|
enableHttp=1时,使用url,timeout参数配置服务端的接收地址。请求为post,Content-Type 为json。
|
||||||
|
enableHttp=0时,使用ip,port的tcp服务回传消息。
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/hookSyncMsg](/api/hookSyncMsg)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|port |true |string| 本地服务端端口,用来接收消息内容 |
|
||||||
|
|ip |true |string| 服务端ip地址,用来接收消息内容,可以是任意ip,即tcp客户端连接的服务端的ip|
|
||||||
|
|url |true |string| http的请求地址,enableHttp=1时,不能为空 |
|
||||||
|
|timeout |true |string| 超时时间,单位ms|
|
||||||
|
|enableHttp |true |number| 0/1 :1.启用http 0.不启用http|
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,0成功, 非0失败|
|
||||||
|
|data|object|null|
|
||||||
|
|msg|string|成功提示|
|
||||||
|
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"port": "19099",
|
||||||
|
"ip":"127.0.0.1",
|
||||||
|
"url":"http://localhost:8080",
|
||||||
|
"timeout":"3000",
|
||||||
|
"enableHttp":"0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{"code":0,"msg":"success","data":null}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4.取消hook消息**
|
||||||
|
###### 接口功能
|
||||||
|
> 取消hook消息
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/unhookSyncMsg](/api/unhookSyncMsg)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,0成功, 非0失败|
|
||||||
|
|data|object|null|
|
||||||
|
|msg|string|成功提示|
|
||||||
|
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{"code":0,"msg":"success","data":null}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5.好友列表**
|
||||||
|
###### 接口功能
|
||||||
|
> 好友列表
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/getContactList](/api/getContactList)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,0成功, 非0失败|
|
||||||
|
|data|object|好友信息|
|
||||||
|
|  customAccount|string|自定义账号|
|
||||||
|
|  encryptName|string|昵称|
|
||||||
|
|  nickname|string|昵称|
|
||||||
|
|  pinyin|string|简拼|
|
||||||
|
|  pinyinAll|string|全拼|
|
||||||
|
|  reserved1|number|未知|
|
||||||
|
|  reserved2|number|未知|
|
||||||
|
|  type|number|未知|
|
||||||
|
|  verifyFlag|number|未知|
|
||||||
|
|  wxid|string|wxid|
|
||||||
|
|msg|string|成功提示|
|
||||||
|
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"customAccount": "",
|
||||||
|
"encryptName": "v3_020b3826fd03010000000000e04128fddf4d90000000501ea9a3dba12f95f6b60a0536a1adb6b40fc4086288f46c0b89e6c4eb8062bb1661b4b6fbab708dc4f89d543d7ade135b2be74c14b9cfe3accef377b9@stranger",
|
||||||
|
"nickname": "文件传输助手",
|
||||||
|
"pinyin": "WJCSZS",
|
||||||
|
"pinyinAll": "wenjianchuanshuzhushou",
|
||||||
|
"reserved1": 1,
|
||||||
|
"reserved2": 1,
|
||||||
|
"type": 3,
|
||||||
|
"verifyFlag": 0,
|
||||||
|
"wxid": "filehelper"
|
||||||
|
}
|
||||||
|
].
|
||||||
|
"msg": "success"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 6.获取数据库信息**
|
||||||
|
###### 接口功能
|
||||||
|
> 获取数据库信息和句柄
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/getDBInfo](/api/getDBInfo)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,0成功, 非0失败|
|
||||||
|
|msg|string|返回信息|
|
||||||
|
|data|array|好友信息|
|
||||||
|
|  databaseName|string|数据库名称|
|
||||||
|
|  handle|number|句柄|
|
||||||
|
|  tables|array|表信息|
|
||||||
|
|    name|string|表名|
|
||||||
|
|    rootpage|string|rootpage|
|
||||||
|
|    sql|string|ddl语句|
|
||||||
|
|    tableName|string|表名|
|
||||||
|
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"databaseName": "MicroMsg.db",
|
||||||
|
"handle": 1755003930784,
|
||||||
|
"tables": [
|
||||||
|
{
|
||||||
|
"name": "Contact",
|
||||||
|
"rootpage": "2",
|
||||||
|
"sql": "CREATE TABLE Contact(UserName TEXT PRIMARY KEY ,Alias TEXT,EncryptUserName TEXT,DelFlag INTEGER DEFAULT 0,Type INTEGER DEFAULT 0,VerifyFlag INTEGER DEFAULT 0,Reserved1 INTEGER DEFAULT 0,Reserved2 INTEGER DEFAULT 0,Reserved3 TEXT,Reserved4 TEXT,Remark TEXT,NickName TEXT,LabelIDList TEXT,DomainList TEXT,ChatRoomType int,PYInitial TEXT,QuanPin TEXT,RemarkPYInitial TEXT,RemarkQuanPin TEXT,BigHeadImgUrl TEXT,SmallHeadImgUrl TEXT,HeadImgMd5 TEXT,ChatRoomNotify INTEGER DEFAULT 0,Reserved5 INTEGER DEFAULT 0,Reserved6 TEXT,Reserved7 TEXT,ExtraBuf BLOB,Reserved8 INTEGER DEFAULT 0,Reserved9 INTEGER DEFAULT 0,Reserved10 TEXT,Reserved11 TEXT)",
|
||||||
|
"tableName": "Contact"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"msg":"success"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### 7.查询数据库**
|
||||||
|
###### 接口功能
|
||||||
|
> 查询数据库
|
||||||
|
|
||||||
|
###### 接口地址
|
||||||
|
> [/api/execSql](/api/execSql)
|
||||||
|
|
||||||
|
###### HTTP请求方式
|
||||||
|
> POST JSON
|
||||||
|
|
||||||
|
###### 请求参数
|
||||||
|
|参数|必选|类型|说明|
|
||||||
|
|---|---|---|---|
|
||||||
|
|dbHandle |true |number| |
|
||||||
|
|sql |true |string| 执行的sql |
|
||||||
|
|
||||||
|
###### 返回字段
|
||||||
|
|返回字段|字段类型|说明 |
|
||||||
|
|---|---|---|
|
||||||
|
|code|int|返回状态,0成功, 非0失败|
|
||||||
|
|msg|string|返回信息|
|
||||||
|
|data|array|sqlite返回的结果|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###### 接口示例
|
||||||
|
入参:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"dbHandle":2006119800400,
|
||||||
|
"sql":"select * from MSG where localId =301;"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
响应:
|
||||||
|
``` javascript
|
||||||
|
{
|
||||||
|
"code": 1,
|
||||||
|
"data": [
|
||||||
|
[
|
||||||
|
"localId",
|
||||||
|
"TalkerId",
|
||||||
|
"MsgSvrID",
|
||||||
|
"Type",
|
||||||
|
"SubType",
|
||||||
|
"IsSender",
|
||||||
|
"CreateTime",
|
||||||
|
"Sequence",
|
||||||
|
"StatusEx",
|
||||||
|
"FlagEx",
|
||||||
|
"Status",
|
||||||
|
"MsgServerSeq",
|
||||||
|
"MsgSequence",
|
||||||
|
"StrTalker",
|
||||||
|
"StrContent",
|
||||||
|
"DisplayContent",
|
||||||
|
"Reserved0",
|
||||||
|
"Reserved1",
|
||||||
|
"Reserved2",
|
||||||
|
"Reserved3",
|
||||||
|
"Reserved4",
|
||||||
|
"Reserved5",
|
||||||
|
"Reserved6",
|
||||||
|
"CompressContent",
|
||||||
|
"BytesExtra",
|
||||||
|
"BytesTrans"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"301",
|
||||||
|
"1",
|
||||||
|
"8824834301214701891",
|
||||||
|
"1",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"1685401473",
|
||||||
|
"1685401473000",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"2",
|
||||||
|
"1",
|
||||||
|
"795781866",
|
||||||
|
"wxid_123",
|
||||||
|
"testtest",
|
||||||
|
"",
|
||||||
|
"0",
|
||||||
|
"2",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"CgQIEBAAGo0BCAcSiAE8bXNnc291cmNlPJPHNpZ25hdHVyZT52MV9wd12bTZyRzwvc2lnbmF0dXJPgoJPHRtcF9ub2RlPgoJCTxwsaXNoZXItaWQ+Jmx0OyFbQ0RBVEFbXV0mZ3Q7PC9wdWJsaXNoZXItaWQ+Cgk8L3RtcF9ub2RlPgo8L21zZ3NvdXJjZT4KGiQIAhIgNDE1MDA0NjRhZTRmMjk2NjhjMzY2ZjFkOTdmMjAwNDg=",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"msg": "success"
|
||||||
|
}
|
||||||
|
```
|
640
doc/postman.json
640
doc/postman.json
@ -1,640 +0,0 @@
|
|||||||
{
|
|
||||||
"info": {
|
|
||||||
"name": "Wechat Hook 395",
|
|
||||||
"_postman_id": "d2b6a4f2-6d7d-4a21-9bbf-65b5a5a3a5a",
|
|
||||||
"description": "A collection of Wechat Hook 395 API requests.",
|
|
||||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
|
||||||
},
|
|
||||||
"item": [
|
|
||||||
{
|
|
||||||
"name": "checkLogin",
|
|
||||||
"request": {
|
|
||||||
"url": {
|
|
||||||
"raw": "http://127.0.0.1:19088/api/checkLogin",
|
|
||||||
"protocol": "http",
|
|
||||||
"host": [
|
|
||||||
"127.0.0.1"
|
|
||||||
],
|
|
||||||
"port": "19088",
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"checkLogin"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to check login status."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "userInfo",
|
|
||||||
"request": {
|
|
||||||
"url": {
|
|
||||||
"raw": "http://127.0.0.1:19088/api/userInfo",
|
|
||||||
"protocol": "http",
|
|
||||||
"host": [
|
|
||||||
"127.0.0.1"
|
|
||||||
],
|
|
||||||
"port": "19088",
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"userInfo"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to get user information."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sendTextMsg",
|
|
||||||
"request": {
|
|
||||||
"url": {
|
|
||||||
"raw": "http://127.0.0.1:19088/api/sendTextMsg",
|
|
||||||
"protocol": "http",
|
|
||||||
"host": [
|
|
||||||
"127.0.0.1"
|
|
||||||
],
|
|
||||||
"port": "19088",
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"sendTextMsg"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"wxid\": \"filehelper\",\"msg\": \"12www\"}"
|
|
||||||
},
|
|
||||||
"description": "API to send text messages."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sendImagesMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/sendImagesMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"wxid\": \"filehelper\",\"imagePath\": \"C:\\pic.png\"}"
|
|
||||||
},
|
|
||||||
"description": "API to send image messages."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sendFileMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/sendFileMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"wxid\": \"filehelper\",\"filePath\": \"C:\\test.zip\"}"
|
|
||||||
},
|
|
||||||
"description": "API to send file messages."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "hookSyncMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/hookSyncMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"port\": \"19099\",\"ip\": \"127.0.0.1\",\"url\": \"http://localhost:8080\",\"timeout\": \"3000\",\"enableHttp\": \"0\"}"
|
|
||||||
},
|
|
||||||
"description": "API to hook sync messages."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "unhookSyncMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/unhookSyncMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to unhook sync messages."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getContactList",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getContactList",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to get the contact list."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getDBInfo",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getDBInfo",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to get database information."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "execSql",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/execSql",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"dbHandle\": 1713425147584,\"sql\": \"select * from MSG where localId =100;\"}"
|
|
||||||
},
|
|
||||||
"description": "API to execute SQL queries."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getChatRoomDetailInfo",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getChatRoomDetailInfo",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"123333@chatroom\"}"
|
|
||||||
},
|
|
||||||
"description": "API to get chat room detail information."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "addMemberToChatRoom",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/addMemberToChatRoom",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"123@chatroom\",\"memberIds\": \"wxid_123\"}"
|
|
||||||
},
|
|
||||||
"description": "API to add member to chat room."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "delMemberFromChatRoom",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/delMemberFromChatRoom",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"21363231004@chatroom\",\"memberIds\": \"wxid_123\"}"
|
|
||||||
},
|
|
||||||
"description": "API to delete member from chat room."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "modifyNickname",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/modifyNickname",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"123@chatroom\",\"wxid\": \"wxid_123\",\"nickName\": \"test\"}"
|
|
||||||
},
|
|
||||||
"description": "API to modify a nickname in a chat room."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getMemberFromChatRoom",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getMemberFromChatRoom",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"123@chatroom\"}"
|
|
||||||
},
|
|
||||||
"description": "API to get members from a chat room."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "topMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/topMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"msgId\": 1222222}"
|
|
||||||
},
|
|
||||||
"description": "API to top a message."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "removeTopMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/removeTopMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"123@chatroom\",\"msgId\": 123}"
|
|
||||||
},
|
|
||||||
"description": "API to remove a topped message."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "InviteMemberToChatRoom",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/InviteMemberToChatRoom",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"123@chatroom\",\"memberIds\": \"wxid_123\"}"
|
|
||||||
},
|
|
||||||
"description": "API to invite members to a chat room."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "hookLog",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/hookLog",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to hook logs."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "unhookLog",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/unhookLog",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to unhook logs."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "createChatRoom",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/createChatRoom",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"memberIds\": \"wxid_8yn4k908tdqp22,wxid_oyb662qhop4422\"}"
|
|
||||||
},
|
|
||||||
"description": "API to create a chat room."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "quitChatRoom",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/quitChatRoom",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"chatRoomId\": \"123@chatroom\"}"
|
|
||||||
},
|
|
||||||
"description": "API to quit a chat room."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "forwardMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/forwardMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"wxid\": \"filehelper\",\"msgId\": \"12331\"}"
|
|
||||||
},
|
|
||||||
"description": "API to forward a message."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getSNSFirstPage",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getSNSFirstPage",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"description": "API to get the first page of SNS data."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getSNSNextPage",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getSNSNextPage",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"snsId\": \"\"}"
|
|
||||||
},
|
|
||||||
"description": "API to get the next page of SNS data."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "addFavFromMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/addFavFromMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"msgId\": \"1222222\"}"
|
|
||||||
},
|
|
||||||
"description": "API to add a favorite from a message."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "addFavFromImage",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/addFavFromImage",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"wxid\": \"\",\"imagePath\": \"\"}"
|
|
||||||
},
|
|
||||||
"description": "API to add a favorite from an image."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getContactProfile",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getContactProfile",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"wxid\": \"\"}"
|
|
||||||
},
|
|
||||||
"description": "API to get contact profile."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sendAtText",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/sendAtText",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"wxids\": \"notify@all\",\"chatRoomId\": \"123@chatroom\",\"msg\": \"你好啊\"}"
|
|
||||||
},
|
|
||||||
"description": "API to send an at-text message."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "forwardPublicMsg",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/forwardPublicMsg",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"appName\": \"\",\"userName\": \"\",\"title\": \"\",\"url\": \"\",\"thumbUrl\": \"\",\"digest\": \"\",\"wxid\": \"filehelper\"}"
|
|
||||||
},
|
|
||||||
"description": "API to forward a public message."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "forwardPublicMsgByMsgId",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/forwardPublicMsgByMsgId",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"msgId\": 123,\"wxid\": \"filehelper\"}"
|
|
||||||
},
|
|
||||||
"description": "API to forward a public message by message ID."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "downloadAttach",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/downloadAttach",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"msgId\": 123}"
|
|
||||||
},
|
|
||||||
"description": "API to download an attachment."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "decodeImage",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/decodeImage",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"filePath\": \"C:\\66664816980131.dat\",\"storeDir\": \"C:\\test\"}"
|
|
||||||
},
|
|
||||||
"description": "API to decode an image."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "getVoiceByMsgId",
|
|
||||||
"request": {
|
|
||||||
"url": "http://127.0.0.1:19088/api/getVoiceByMsgId",
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json",
|
|
||||||
"description": "Specify that the request body is in JSON format."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{\"msgId\": 7880439644200,\"storeDir\": \"c:\\test\"}"
|
|
||||||
},
|
|
||||||
"description": "API to get voice by message ID."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.1.0</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
@ -14,8 +14,7 @@
|
|||||||
<name>wxhk</name>
|
<name>wxhk</name>
|
||||||
<description>wxhk</description>
|
<description>wxhk</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>17</java.version>
|
||||||
<vertx-web-client.version>4.5.3</vertx-web-client.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -40,7 +39,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-all</artifactId>
|
<artifactId>netty-all</artifactId>
|
||||||
<version>4.1.105.Final</version>
|
<version>4.1.92.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
@ -51,22 +50,22 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-core</artifactId>
|
<artifactId>vertx-core</artifactId>
|
||||||
<version>${vertx-web-client.version}</version>
|
<version>4.4.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-web</artifactId>
|
<artifactId>vertx-web</artifactId>
|
||||||
<version>${vertx-web-client.version}</version>
|
<version>4.4.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-web-client</artifactId>
|
<artifactId>vertx-web-client</artifactId>
|
||||||
<version>${vertx-web-client.version}</version>
|
<version>4.4.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-mysql-client</artifactId>
|
<artifactId>vertx-mysql-client</artifactId>
|
||||||
<version>${vertx-web-client.version}</version>
|
<version>4.4.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -42,11 +42,6 @@ public class PrivateChatMsg implements Serializable {
|
|||||||
private String signature;
|
private String signature;
|
||||||
private String time;
|
private String time;
|
||||||
private Integer timestamp;
|
private Integer timestamp;
|
||||||
|
|
||||||
/**
|
|
||||||
* 对用户,如果是文件助手是filehelper
|
|
||||||
*/
|
|
||||||
private String toUser;
|
|
||||||
/**
|
/**
|
||||||
* 类型
|
* 类型
|
||||||
*/
|
*/
|
||||||
|
@ -15,17 +15,4 @@ import lombok.experimental.Accessors;
|
|||||||
public class OpenHook implements SendMsg<OpenHook> {
|
public class OpenHook implements SendMsg<OpenHook> {
|
||||||
String port;
|
String port;
|
||||||
String ip;
|
String ip;
|
||||||
/**
|
|
||||||
* 0/1 :1.启用http 0.不启用http
|
|
||||||
*/
|
|
||||||
boolean enableHttp;
|
|
||||||
/**
|
|
||||||
* 超时时间,单位ms
|
|
||||||
*/
|
|
||||||
String timeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* http的请求地址,enableHttp=1时,不能为空
|
|
||||||
*/
|
|
||||||
String url;
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import org.w3c.dom.NodeList;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
@ -51,12 +50,7 @@ public class WxMsgHandle {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
add(chatMsg -> {
|
add(chatMsg -> {
|
||||||
if(Objects.equals(chatMsg.getToUser(), FILEHELPER)){
|
wxSmgServer.私聊(chatMsg);
|
||||||
wxSmgServer.文件助手(chatMsg);
|
|
||||||
}else{
|
|
||||||
wxSmgServer.私聊(chatMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}, WxMsgType.私聊信息);
|
}, WxMsgType.私聊信息);
|
||||||
add(chatMsg -> {
|
add(chatMsg -> {
|
||||||
@ -180,8 +174,8 @@ public class WxMsgHandle {
|
|||||||
if (monery.startsWith("¥")) {
|
if (monery.startsWith("¥")) {
|
||||||
String substring = monery.substring(1);
|
String substring = monery.substring(1);
|
||||||
BigDecimal decimal = new BigDecimal(substring);
|
BigDecimal decimal = new BigDecimal(substring);
|
||||||
log.info("收款:{},付款人:{},付款备注:{}", decimal.stripTrailingZeros().toPlainString(), receiver_username, remark);
|
log.info("收款:{},付款人:{},付款备注:{}", decimal.stripTrailingZeros().toPlainString(), chatMsg.getFromUser(), remark);
|
||||||
wxSmgServer.收款之后(new PayoutInformation(receiver_username, decimal, remark));
|
wxSmgServer.收款之后(new PayoutInformation(chatMsg.getFromUser(), decimal, remark));
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,14 +32,12 @@ public class WxSmgServerImpl implements com.example.wxhk.server.WxSmgServer {
|
|||||||
public void 私聊(PrivateChatMsg chatMsg) {
|
public void 私聊(PrivateChatMsg chatMsg) {
|
||||||
if (Objects.equals(chatMsg.getIsSendMsg(), 1) && Objects.equals(chatMsg.getIsSendByPhone(), 1)) {
|
if (Objects.equals(chatMsg.getIsSendMsg(), 1) && Objects.equals(chatMsg.getIsSendByPhone(), 1)) {
|
||||||
log.info("手机端对:{}发出:{}", chatMsg.getFromUser(), chatMsg.getContent());
|
log.info("手机端对:{}发出:{}", chatMsg.getFromUser(), chatMsg.getContent());
|
||||||
}else{
|
|
||||||
log.info("收到私聊{}",chatMsg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void 文件助手(PrivateChatMsg chatMsg) {
|
public void 文件助手(PrivateChatMsg chatMsg) {
|
||||||
log.info("文件助手:{}",chatMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,8 +2,7 @@ package com.example.wxhk.tcp.vertx;
|
|||||||
|
|
||||||
import com.example.wxhk.WxhkApplication;
|
import com.example.wxhk.WxhkApplication;
|
||||||
import com.example.wxhk.constant.WxMsgType;
|
import com.example.wxhk.constant.WxMsgType;
|
||||||
import com.example.wxhk.model.request.OpenHook;
|
import com.example.wxhk.util.HttpAsyncUtil;
|
||||||
import com.example.wxhk.util.HttpSendUtil;
|
|
||||||
import io.vertx.core.AbstractVerticle;
|
import io.vertx.core.AbstractVerticle;
|
||||||
import io.vertx.core.DeploymentOptions;
|
import io.vertx.core.DeploymentOptions;
|
||||||
import io.vertx.core.Future;
|
import io.vertx.core.Future;
|
||||||
@ -76,10 +75,7 @@ public class VertxTcp extends AbstractVerticle implements CommandLineRunner {
|
|||||||
listen.onComplete(event -> {
|
listen.onComplete(event -> {
|
||||||
boolean succeeded = event.succeeded();
|
boolean succeeded = event.succeeded();
|
||||||
if (succeeded) {
|
if (succeeded) {
|
||||||
HttpSendUtil.开启hook(new OpenHook().setPort(InitWeChat.getVertxPort().toString()).setIp("127.0.0.1")
|
HttpAsyncUtil.exec(HttpAsyncUtil.Type.开启hook, new JsonObject().put("port", InitWeChat.getVertxPort().toString()).put("ip", "127.0.0.1"));
|
||||||
.setEnableHttp(false)
|
|
||||||
.setTimeout("5000"));
|
|
||||||
// HttpAsyncUtil.exec(HttpAsyncUtil.Type.开启hook, new JsonObject().put("port", InitWeChat.getVertxPort().toString()).put("ip", "127.0.0.1"));
|
|
||||||
startPromise.complete();
|
startPromise.complete();
|
||||||
} else {
|
} else {
|
||||||
startPromise.fail(event.cause());
|
startPromise.fail(event.cause());
|
||||||
|
@ -24,7 +24,7 @@ public class HttpAsyncUtil {
|
|||||||
protected static final Log log = Log.get();
|
protected static final Log log = Log.get();
|
||||||
|
|
||||||
public static Future<HttpResponse<Buffer>> exec(Type type, JsonObject object) {
|
public static Future<HttpResponse<Buffer>> exec(Type type, JsonObject object) {
|
||||||
return client.post(InitWeChat.wxPort, "localhost", "/api/" + type.getType())
|
return client.post(InitWeChat.wxPort, "localhost", "/api/?type=" + type.getType())
|
||||||
.sendJsonObject(object)
|
.sendJsonObject(object)
|
||||||
.onSuccess(event ->
|
.onSuccess(event ->
|
||||||
{
|
{
|
||||||
@ -36,7 +36,7 @@ public class HttpAsyncUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Future<HttpResponse<Buffer>> exec(Type type, JsonObject object, Handler<AsyncResult<HttpResponse<Buffer>>> handler) {
|
public static Future<HttpResponse<Buffer>> exec(Type type, JsonObject object, Handler<AsyncResult<HttpResponse<Buffer>>> handler) {
|
||||||
return client.post(InitWeChat.wxPort, "localhost", "/api/" + type.getType())
|
return client.post(InitWeChat.wxPort, "localhost", "/api/?type=" + type.getType())
|
||||||
.sendJsonObject(object)
|
.sendJsonObject(object)
|
||||||
.onComplete(handler)
|
.onComplete(handler)
|
||||||
;
|
;
|
||||||
@ -45,31 +45,22 @@ public class HttpAsyncUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
检查微信登陆("checkLogin"),
|
检查微信登陆("0"),
|
||||||
获取登录信息("userInfo"),
|
获取登录信息("1"),
|
||||||
发送文本("sendTextMsg"),
|
发送文本("2"),
|
||||||
转发消息("forwardMsg"),
|
发送at文本("3"),
|
||||||
发送at文本("sendAtText"),
|
|
||||||
发送图片("5"),
|
发送图片("5"),
|
||||||
发送文件("sendFileMsg"),
|
发送文件("6"),
|
||||||
开启hook("hookSyncMsg"),
|
开启hook("9"),
|
||||||
关闭hook("unhookSyncMsg"),
|
关闭hook("10"),
|
||||||
添加好友("20"),
|
添加好友("20"),
|
||||||
通过好友申请("23"),
|
通过好友申请("23"),
|
||||||
获取群成员("getMemberFromChatRoom"),
|
获取群成员("25"),
|
||||||
获取群成员基础信息("getContactProfile"),
|
获取群成员昵称("26"),
|
||||||
获取群详情("getChatRoomDetailInfo"),
|
删除群成员("27"),
|
||||||
添加群成员("addMemberToChatRoom"),
|
|
||||||
修改群昵称("modifyNickname"),
|
|
||||||
删除群成员("delMemberFromChatRoom"),
|
|
||||||
置顶群消息("topMsg"),
|
|
||||||
取消置顶群消息("removeTopMsg"),
|
|
||||||
邀请入群("InviteMemberToChatRoom"),
|
|
||||||
确认收款("45"),
|
确认收款("45"),
|
||||||
联系人列表("getContactList"),
|
联系人列表("46"),
|
||||||
查询微信信息("55"),
|
查询微信信息("55"),
|
||||||
下载附件("downloadAttach"),
|
|
||||||
解码("decodeImage"),
|
|
||||||
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
@ -27,7 +27,7 @@ public class HttpSyncUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject exec(HttpAsyncUtil.Type type, JsonObject obj) {
|
public static JsonObject exec(HttpAsyncUtil.Type type, JsonObject obj) {
|
||||||
String post = engine.send(Request.of("http://localhost:" + InitWeChat.wxPort + "/api/" + type.getType()).method(Method.POST).body(obj.encode())).bodyStr();
|
String post = engine.send(Request.of("http://localhost:" + InitWeChat.wxPort + "/api/?type=" + type.getType()).method(Method.POST).body(obj.encode())).bodyStr();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("type:{},{}", type.getType(), post);
|
log.debug("type:{},{}", type.getType(), post);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
wx.path=D:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe
|
wx.path=D:\\Program Files (x86)\\Tencent\\WeChat\\[3.9.2.23]\\WeChat.exe
|
||||||
wx.port=19088
|
wx.port=19088
|
||||||
spring.profiles.active=local
|
spring.profiles.active=local
|
||||||
vertx.port=8080
|
vertx.port=8080
|
Binary file not shown.
Binary file not shown.
@ -7,8 +7,6 @@ import org.dromara.hutool.core.lang.Console;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ -43,7 +41,5 @@ class HttpSendUtilTest {
|
|||||||
void 获取群成员() {
|
void 获取群成员() {
|
||||||
GroupMembers 获取群成员 = HttpSendUtil.获取群成员(new GetGroupMembers().setChatRoomId("24964676359@chatroom"));
|
GroupMembers 获取群成员 = HttpSendUtil.获取群成员(new GetGroupMembers().setChatRoomId("24964676359@chatroom"));
|
||||||
Console.log(获取群成员);
|
Console.log(获取群成员);
|
||||||
|
|
||||||
Duration between = Duration.between(LocalDateTime.now(), LocalDateTime.now());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,26 +0,0 @@
|
|||||||
const net = require('net')
|
|
||||||
|
|
||||||
const server = net.createServer(socket => {
|
|
||||||
console.log('New client connected')
|
|
||||||
|
|
||||||
let data = Buffer.from('')
|
|
||||||
|
|
||||||
socket.on('data', data => {
|
|
||||||
data = Buffer.concat([data, chunk])
|
|
||||||
console.log(`Received data: ${data}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('end', () => {
|
|
||||||
const decodedData = data.toString('utf8')
|
|
||||||
console.log(`Received data: ${decodedData}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
socket.on('close', () => {
|
|
||||||
console.log('Client disconnected')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const port = 19099
|
|
||||||
server.listen(port, () => {
|
|
||||||
console.log(`Server listening on port ${port}`)
|
|
||||||
})
|
|
@ -526,7 +526,7 @@ DWORD GetPIDForProcess(wchar_t* process)
|
|||||||
if (!hSnapshot) {
|
if (!hSnapshot) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pe32.dwSize = sizeof(PROCESSENTRY32W);
|
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||||
for (working = Process32FirstW(hSnapshot, &pe32); working; working = Process32NextW(hSnapshot, &pe32))
|
for (working = Process32FirstW(hSnapshot, &pe32); working; working = Process32NextW(hSnapshot, &pe32))
|
||||||
{
|
{
|
||||||
if (!wcscmp(pe32.szExeFile, process))
|
if (!wcscmp(pe32.szExeFile, process))
|
||||||
@ -933,7 +933,7 @@ int InjectDll(wchar_t* szPName, wchar_t* szDllPath)
|
|||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DWORD dErrorCode = GetLastError();
|
DWORD dErrorCode = GetLastError();
|
||||||
printf("dll inject fail");
|
printf("dll inject fail");
|
||||||
printf("error code : %d ", dErrorCode);
|
printf("error code : %d ", dErrorCode);
|
||||||
|
1
spdlog
1
spdlog
@ -1 +0,0 @@
|
|||||||
Subproject commit ad0e89cbfb4d0c1ce4d097e134eb7be67baebb36
|
|
@ -1,14 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
Config::Config(/* args */) {}
|
|
||||||
|
|
||||||
Config::~Config() {}
|
|
||||||
|
|
||||||
void Config::Initialize() {
|
|
||||||
port_ = GetPrivateProfileInt("config", "Port", 19088, "./config.ini");
|
|
||||||
}
|
|
||||||
int Config::GetPort() { return port_; }
|
|
||||||
|
|
||||||
} // namespace wxhelper
|
|
@ -1,61 +0,0 @@
|
|||||||
;#################################################################
|
|
||||||
|
|
||||||
.code
|
|
||||||
|
|
||||||
|
|
||||||
;#################################################################
|
|
||||||
|
|
||||||
|
|
||||||
;#################################################################
|
|
||||||
|
|
||||||
;检测wechat登录状态
|
|
||||||
;param: get_account_service_addr 函数地址
|
|
||||||
|
|
||||||
;#################################################################
|
|
||||||
_GetAccountService PROC,
|
|
||||||
get_account_service_addr:QWORD ; 函数地址
|
|
||||||
sub rsp,28h
|
|
||||||
call rcx
|
|
||||||
add rsp,28h
|
|
||||||
ret
|
|
||||||
_GetAccountService ENDP
|
|
||||||
|
|
||||||
;#################################################################
|
|
||||||
|
|
||||||
;获取wechat数据保存路径
|
|
||||||
;param: addr 函数地址
|
|
||||||
;return:路径地址
|
|
||||||
|
|
||||||
;#################################################################
|
|
||||||
_GetDataSavePath PROC,
|
|
||||||
get_data_path_addr:QWORD, ; 函数地址
|
|
||||||
out_path:QWORD ; 输出
|
|
||||||
sub rsp,40h
|
|
||||||
mov rax,rcx
|
|
||||||
mov rcx,rdx
|
|
||||||
call rax
|
|
||||||
add rsp,40h
|
|
||||||
ret
|
|
||||||
_GetDataSavePath ENDP
|
|
||||||
|
|
||||||
|
|
||||||
;#################################################################
|
|
||||||
|
|
||||||
;获取wechat当前数据保存路径
|
|
||||||
;param: addr 函数地址
|
|
||||||
;return:路径地址
|
|
||||||
|
|
||||||
;#################################################################
|
|
||||||
_GetCurrentDataPath PROC,
|
|
||||||
get_current_path_addr: QWORD, ; 函数地址
|
|
||||||
out_path: QWORD ; 输出
|
|
||||||
sub rsp,28h
|
|
||||||
mov rax,rcx
|
|
||||||
mov rcx,rdx
|
|
||||||
call rax
|
|
||||||
add rsp,28h
|
|
||||||
ret
|
|
||||||
_GetCurrentDataPath ENDP
|
|
||||||
|
|
||||||
|
|
||||||
END
|
|
@ -1,8 +0,0 @@
|
|||||||
#ifndef WXHELPER_EXPORT_H_
|
|
||||||
#define WXHELPER_EXPORT_H_
|
|
||||||
|
|
||||||
extern "C" UINT64 _GetAccountService(UINT64 addr);
|
|
||||||
extern "C" UINT64 _GetDataSavePath(UINT64 addr,ULONG_PTR out);
|
|
||||||
extern "C" UINT64 _GetCurrentDataPath(UINT64 addr,ULONG_PTR out);
|
|
||||||
extern "C" UINT64 _SendTextMsg(UINT64 mgr_addr,UINT64 send_text_addr,UINT64 free_addr,UINT64 receiver,UINT64 msg,UINT64 chat_msg);
|
|
||||||
#endif
|
|
@ -1,41 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "global_context.h"
|
|
||||||
#include "thread_pool.h"
|
|
||||||
#include "db.h"
|
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
|
|
||||||
GlobalContext::~GlobalContext() {
|
|
||||||
if (config.has_value()) {
|
|
||||||
config.reset();
|
|
||||||
}
|
|
||||||
if (log.has_value()) {
|
|
||||||
log.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
void GlobalContext::initialize(HMODULE module) {
|
|
||||||
state =GlobalContextState::INITIALIZING;
|
|
||||||
module_ = module;
|
|
||||||
#ifndef _DEBUG
|
|
||||||
Utils::Hide(module);
|
|
||||||
#endif
|
|
||||||
UINT64 base = Utils::GetWeChatWinBase();
|
|
||||||
config.emplace();
|
|
||||||
config->Initialize();
|
|
||||||
log.emplace();
|
|
||||||
log->Initialize();
|
|
||||||
http_server = std::unique_ptr<HttpServer>( new HttpServer(config->GetPort()));
|
|
||||||
http_server->HttpStart();
|
|
||||||
ThreadPool::GetInstance().Create(2, 8);
|
|
||||||
mgr = std::unique_ptr<Manager>(new Manager(base));
|
|
||||||
DB::GetInstance().init(base);
|
|
||||||
state =GlobalContextState::INITIALIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalContext::finally() {
|
|
||||||
if (http_server) {
|
|
||||||
http_server->HttpClose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace wxhelper
|
|
316
src/hooks.cc
316
src/hooks.cc
@ -1,316 +0,0 @@
|
|||||||
|
|
||||||
#include "pch.h"
|
|
||||||
#include "hooks.h"
|
|
||||||
#include "thread_pool.h"
|
|
||||||
#include "wechat_function.h"
|
|
||||||
#include <WS2tcpip.h>
|
|
||||||
#include "base64.h"
|
|
||||||
#include "http_client.h"
|
|
||||||
|
|
||||||
namespace offset = wxhelper::V3_9_5_81::offset;
|
|
||||||
namespace common = wxhelper::common;
|
|
||||||
namespace wxhelper {
|
|
||||||
namespace hooks {
|
|
||||||
|
|
||||||
static int kServerPort = 19099;
|
|
||||||
static bool kMsgHookFlag = false;
|
|
||||||
static char kServerIp[16] = "127.0.0.1";
|
|
||||||
static bool kEnableHttp = false;
|
|
||||||
static bool kLogHookFlag = false;
|
|
||||||
|
|
||||||
static bool kSnsFinishHookFlag = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static UINT64 (*R_DoAddMsg)(UINT64, UINT64, UINT64) = (UINT64(*)(
|
|
||||||
UINT64, UINT64, UINT64))(Utils::GetWeChatWinBase() + offset::kDoAddMsg);
|
|
||||||
|
|
||||||
static UINT64 (*R_Log)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
|
||||||
UINT64, UINT64, UINT64, UINT64, UINT64) =
|
|
||||||
(UINT64(*)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
|
||||||
UINT64, UINT64, UINT64,
|
|
||||||
UINT64))(Utils::GetWeChatWinBase() + offset::kHookLog);
|
|
||||||
|
|
||||||
static UINT64 (*R_OnSnsTimeLineSceneFinish)(UINT64, UINT64, UINT64) =
|
|
||||||
(UINT64(*)(UINT64, UINT64, UINT64))(Utils::GetWeChatWinBase() +
|
|
||||||
offset::kOnSnsTimeLineSceneFinish);
|
|
||||||
|
|
||||||
VOID CALLBACK SendMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
|
||||||
PTP_WORK Work) {
|
|
||||||
common::InnerMessageStruct *msg = (common::InnerMessageStruct *)context;
|
|
||||||
if (msg == NULL) {
|
|
||||||
SPDLOG_INFO("add work:msg is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::unique_ptr<common::InnerMessageStruct> sms(msg);
|
|
||||||
nlohmann::json j_msg =
|
|
||||||
nlohmann::json::parse(msg->buffer, msg->buffer + msg->length, nullptr, false);
|
|
||||||
if (j_msg.is_discarded() == true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string jstr = j_msg.dump() + "\n";
|
|
||||||
|
|
||||||
if (kServerPort == 0) {
|
|
||||||
SPDLOG_ERROR("http server port error :{}", kServerPort);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
WSADATA was_data = {0};
|
|
||||||
int ret = WSAStartup(MAKEWORD(2, 2), &was_data);
|
|
||||||
if (ret != 0) {
|
|
||||||
SPDLOG_ERROR("WSAStartup failed:{}", ret);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
||||||
if (client_socket < 0) {
|
|
||||||
SPDLOG_ERROR("socket init fail");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BOOL status = false;
|
|
||||||
sockaddr_in client_addr;
|
|
||||||
memset(&client_addr, 0, sizeof(client_addr));
|
|
||||||
client_addr.sin_family = AF_INET;
|
|
||||||
client_addr.sin_port = htons((u_short)kServerPort);
|
|
||||||
InetPtonA(AF_INET, kServerIp, &client_addr.sin_addr.s_addr);
|
|
||||||
if (connect(client_socket, reinterpret_cast<sockaddr *>(&client_addr),
|
|
||||||
sizeof(sockaddr)) < 0) {
|
|
||||||
SPDLOG_ERROR("socket connect fail");
|
|
||||||
goto clean;
|
|
||||||
}
|
|
||||||
char recv_buf[1024] = {0};
|
|
||||||
ret = send(client_socket, jstr.c_str(), static_cast<int>(jstr.size()) , 0);
|
|
||||||
if (ret < 0) {
|
|
||||||
SPDLOG_ERROR("socket send fail ,ret:{}", ret);
|
|
||||||
goto clean;
|
|
||||||
}
|
|
||||||
ret = shutdown(client_socket, SD_SEND);
|
|
||||||
if (ret == SOCKET_ERROR) {
|
|
||||||
SPDLOG_ERROR("shutdown failed with erro:{}", ret);
|
|
||||||
goto clean;
|
|
||||||
}
|
|
||||||
ret = recv(client_socket, recv_buf, sizeof(recv_buf), 0);
|
|
||||||
if (ret < 0) {
|
|
||||||
SPDLOG_ERROR("socket recv fail ,ret:{}", ret);
|
|
||||||
goto clean;
|
|
||||||
}
|
|
||||||
clean:
|
|
||||||
closesocket(client_socket);
|
|
||||||
WSACleanup();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID CALLBACK SendHttpMsgCallback(PTP_CALLBACK_INSTANCE instance, PVOID context,
|
|
||||||
PTP_WORK Work) {
|
|
||||||
common::InnerMessageStruct *msg = (common::InnerMessageStruct *)context;
|
|
||||||
if (msg == NULL) {
|
|
||||||
SPDLOG_INFO("http msg is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<common::InnerMessageStruct> sms(msg);
|
|
||||||
nlohmann::json j_msg =
|
|
||||||
nlohmann::json::parse(msg->buffer, msg->buffer + msg->length, nullptr, false);
|
|
||||||
if (j_msg.is_discarded() == true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string jstr = j_msg.dump() + "\n";
|
|
||||||
HttpClient::GetInstance().SendRequest(jstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleSyncMsg(INT64 param1, INT64 param2, INT64 param3) {
|
|
||||||
nlohmann::json msg;
|
|
||||||
|
|
||||||
msg["pid"] = GetCurrentProcessId();
|
|
||||||
msg["fromUser"] = Utils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x18));
|
|
||||||
msg["toUser"] = Utils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x28));
|
|
||||||
msg["content"] = Utils::ReadSKBuiltinString(*(INT64 *)(param2 + 0x30));
|
|
||||||
msg["signature"] = Utils::ReadWeChatStr(*(INT64 *)(param2 + 0x48));
|
|
||||||
msg["msgId"] = *(INT64 *)(param2 + 0x60);
|
|
||||||
msg["msgSequence"] = *(DWORD *)(param2 + 0x5C);
|
|
||||||
msg["createTime"] = *(DWORD *)(param2 + 0x58);
|
|
||||||
msg["displayFullContent"] = Utils::ReadWeChatStr(*(INT64 *)(param2 + 0x50));
|
|
||||||
DWORD type = *(DWORD *)(param2 + 0x24);
|
|
||||||
msg["type"] = type;
|
|
||||||
if (type == 3) {
|
|
||||||
int a = 1;
|
|
||||||
std::string img =
|
|
||||||
Utils::ReadSKBuiltinBuffer(*(INT64 *)(param2 + 0x40));
|
|
||||||
SPDLOG_INFO("encode size:{}",img.size());
|
|
||||||
msg["base64Img"] = base64_encode(img);
|
|
||||||
a = 2;
|
|
||||||
}
|
|
||||||
std::string jstr = msg.dump() + '\n';
|
|
||||||
common::InnerMessageStruct *inner_msg = new common::InnerMessageStruct;
|
|
||||||
inner_msg->buffer = new char[jstr.size() + 1];
|
|
||||||
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
|
|
||||||
inner_msg->length = jstr.size();
|
|
||||||
if(kEnableHttp){
|
|
||||||
bool add = ThreadPool::GetInstance().AddWork(SendHttpMsgCallback,inner_msg);
|
|
||||||
SPDLOG_INFO("add http msg work:{}",add);
|
|
||||||
}else{
|
|
||||||
bool add = ThreadPool::GetInstance().AddWork(SendMsgCallback,inner_msg);
|
|
||||||
SPDLOG_INFO("add msg work:{}",add);
|
|
||||||
}
|
|
||||||
R_DoAddMsg(param1,param2,param3);
|
|
||||||
}
|
|
||||||
|
|
||||||
UINT64 HandlePrintLog(UINT64 param1, UINT64 param2, UINT64 param3, UINT64 param4,
|
|
||||||
UINT64 param5, UINT64 param6, UINT64 param7, UINT64 param8,
|
|
||||||
UINT64 param9, UINT64 param10, UINT64 param11,
|
|
||||||
UINT64 param12) {
|
|
||||||
UINT64 p = R_Log(param1, param2, param3, param4, param5, param6, param7, param8, param9,
|
|
||||||
param10, param11, param12);
|
|
||||||
if(p== 0 || p == 1){
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
char *msg = (char *)p;
|
|
||||||
if (msg != NULL) {
|
|
||||||
// INT64 size = *(INT64 *)(p - 0x8);
|
|
||||||
std::string str(msg);
|
|
||||||
std::wstring ws = Utils::UTF8ToWstring(str);
|
|
||||||
std::string out = Utils::WstringToAnsi(ws, CP_ACP);
|
|
||||||
spdlog::info("wechat log:{}", out);
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleSNSMsg(INT64 param1, INT64 param2, INT64 param3) {
|
|
||||||
nlohmann::json j_sns;
|
|
||||||
INT64 begin_addr = *(INT64 *)(param2 + 0x30);
|
|
||||||
INT64 end_addr = *(INT64 *)(param2 + 0x38);
|
|
||||||
if (begin_addr == 0) {
|
|
||||||
j_sns = {{"data", nlohmann::json::array()}};
|
|
||||||
} else {
|
|
||||||
while (begin_addr < end_addr) {
|
|
||||||
nlohmann::json j_item;
|
|
||||||
j_item["snsId"] = *(UINT64 *)(begin_addr);
|
|
||||||
j_item["createTime"] = *(DWORD *)(begin_addr + 0x38);
|
|
||||||
j_item["senderId"] = Utils::ReadWstringThenConvert(begin_addr + 0x18);
|
|
||||||
j_item["content"] = Utils::ReadWstringThenConvert(begin_addr + 0x48);
|
|
||||||
j_item["xml"] = Utils::ReadWstringThenConvert(begin_addr + 0x580);
|
|
||||||
j_sns["data"].push_back(j_item);
|
|
||||||
begin_addr += 0x11E0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::string jstr = j_sns.dump() + '\n';
|
|
||||||
common::InnerMessageStruct *inner_msg = new common::InnerMessageStruct;
|
|
||||||
inner_msg->buffer = new char[jstr.size() + 1];
|
|
||||||
memcpy(inner_msg->buffer, jstr.c_str(), jstr.size() + 1);
|
|
||||||
inner_msg->length = jstr.size();
|
|
||||||
if (kEnableHttp) {
|
|
||||||
bool add = ThreadPool::GetInstance().AddWork(SendHttpMsgCallback, inner_msg);
|
|
||||||
SPDLOG_INFO("hook sns add http msg work:{}", add);
|
|
||||||
} else {
|
|
||||||
bool add = ThreadPool::GetInstance().AddWork(SendMsgCallback, inner_msg);
|
|
||||||
SPDLOG_INFO("hook sns add msg work:{}", add);
|
|
||||||
}
|
|
||||||
R_OnSnsTimeLineSceneFinish(param1, param2, param3);
|
|
||||||
}
|
|
||||||
|
|
||||||
int HookSyncMsg(std::string client_ip, int port, std::string url,
|
|
||||||
uint64_t timeout, bool enable) {
|
|
||||||
if (kMsgHookFlag) {
|
|
||||||
SPDLOG_INFO("recv msg hook already called");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
kEnableHttp = enable;
|
|
||||||
if (kEnableHttp) {
|
|
||||||
HttpClient::GetInstance().SetConfig(url, timeout);
|
|
||||||
}
|
|
||||||
if (client_ip.size() < 1) {
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
kServerPort = port;
|
|
||||||
strcpy_s(kServerIp, client_ip.c_str());
|
|
||||||
UINT64 base = Utils::GetWeChatWinBase();
|
|
||||||
if (!base) {
|
|
||||||
SPDLOG_INFO("base addr is null");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DetourRestoreAfterWith();
|
|
||||||
DetourTransactionBegin();
|
|
||||||
DetourUpdateThread(GetCurrentThread());
|
|
||||||
DetourAttach(&(PVOID&)R_DoAddMsg, &HandleSyncMsg);
|
|
||||||
LONG ret = DetourTransactionCommit();
|
|
||||||
if(ret == NO_ERROR){
|
|
||||||
kMsgHookFlag = true;
|
|
||||||
}
|
|
||||||
SPDLOG_INFO("hook sync {}",ret);
|
|
||||||
DetourTransactionBegin();
|
|
||||||
DetourUpdateThread(GetCurrentThread());
|
|
||||||
DetourAttach(&(PVOID&)R_OnSnsTimeLineSceneFinish, &HandleSNSMsg);
|
|
||||||
ret = DetourTransactionCommit();
|
|
||||||
if(ret == NO_ERROR){
|
|
||||||
kSnsFinishHookFlag = true;
|
|
||||||
}
|
|
||||||
SPDLOG_INFO("hook sns {}",ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int UnHookSyncMsg() {
|
|
||||||
if (!kMsgHookFlag) {
|
|
||||||
kMsgHookFlag = false;
|
|
||||||
kEnableHttp = false;
|
|
||||||
strcpy_s(kServerIp, "127.0.0.1");
|
|
||||||
SPDLOG_INFO("hook sync msg reset");
|
|
||||||
return NO_ERROR;
|
|
||||||
}
|
|
||||||
UINT64 base = Utils::GetWeChatWinBase();
|
|
||||||
DetourTransactionBegin();
|
|
||||||
DetourUpdateThread(GetCurrentThread());
|
|
||||||
DetourDetach(&(PVOID&)R_DoAddMsg, &HandleSyncMsg);
|
|
||||||
LONG ret = DetourTransactionCommit();
|
|
||||||
if (ret == NO_ERROR) {
|
|
||||||
kMsgHookFlag = false;
|
|
||||||
kEnableHttp = false;
|
|
||||||
strcpy_s(kServerIp, "127.0.0.1");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int HookLog() {
|
|
||||||
if (kLogHookFlag) {
|
|
||||||
SPDLOG_INFO("log hook already called");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
UINT64 base = Utils::GetWeChatWinBase();
|
|
||||||
if (!base) {
|
|
||||||
SPDLOG_INFO("base addr is null");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DetourRestoreAfterWith();
|
|
||||||
DetourTransactionBegin();
|
|
||||||
DetourUpdateThread(GetCurrentThread());
|
|
||||||
UINT64 do_add_msg_addr = base + offset::kHookLog;
|
|
||||||
DetourAttach(&(PVOID &)R_Log, &HandlePrintLog);
|
|
||||||
LONG ret = DetourTransactionCommit();
|
|
||||||
if (ret == NO_ERROR) {
|
|
||||||
kLogHookFlag = true;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int UnHookLog() {
|
|
||||||
if (!kLogHookFlag) {
|
|
||||||
kLogHookFlag = false;
|
|
||||||
SPDLOG_INFO("hook log reset");
|
|
||||||
return NO_ERROR;
|
|
||||||
}
|
|
||||||
UINT64 base = Utils::GetWeChatWinBase();
|
|
||||||
DetourTransactionBegin();
|
|
||||||
DetourUpdateThread(GetCurrentThread());
|
|
||||||
UINT64 do_add_msg_addr = base + offset::kHookLog;
|
|
||||||
DetourDetach(&(PVOID &)R_Log, &HandlePrintLog);
|
|
||||||
LONG ret = DetourTransactionCommit();
|
|
||||||
if (ret == NO_ERROR) {
|
|
||||||
kLogHookFlag = false;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace hooks
|
|
||||||
} // namespace wxhelper
|
|
19
src/hooks.h
19
src/hooks.h
@ -1,19 +0,0 @@
|
|||||||
#ifndef WXHELPER_HOOKS_H_
|
|
||||||
#define WXHELPER_HOOKS_H_
|
|
||||||
#include "Windows.h"
|
|
||||||
#include "wechat_function.h"
|
|
||||||
namespace wxhelper {
|
|
||||||
namespace hooks {
|
|
||||||
|
|
||||||
int HookSyncMsg(std::string client_ip, int port, std::string url, uint64_t timeout,
|
|
||||||
bool enable);
|
|
||||||
|
|
||||||
int UnHookSyncMsg();
|
|
||||||
|
|
||||||
int HookLog();
|
|
||||||
|
|
||||||
int UnHookLog();
|
|
||||||
|
|
||||||
} // namespace hooks
|
|
||||||
} // namespace wxhelper
|
|
||||||
#endif
|
|
@ -1,65 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "http_client.h"
|
|
||||||
namespace wxhelper {
|
|
||||||
|
|
||||||
void HttpClient::SendRequest(std::string content) {
|
|
||||||
struct mg_mgr mgr;
|
|
||||||
Data data ;
|
|
||||||
data.done = false;
|
|
||||||
data.post_data = content;
|
|
||||||
mg_mgr_init(&mgr);
|
|
||||||
mg_http_connect(&mgr, url_.c_str(), OnHttpEvent, &data);
|
|
||||||
while (!data.done){
|
|
||||||
mg_mgr_poll(&mgr, 500);
|
|
||||||
}
|
|
||||||
mg_mgr_free(&mgr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void HttpClient::OnHttpEvent(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|
||||||
const char * s_url = GetInstance().url_.c_str();
|
|
||||||
Data data = *(Data*)fn_data;
|
|
||||||
if (ev == MG_EV_OPEN) {
|
|
||||||
// Connection created. Store connect expiration time in c->data
|
|
||||||
*(uint64_t *) c->data = mg_millis() + GetInstance().timeout_;
|
|
||||||
} else if (ev == MG_EV_POLL) {
|
|
||||||
if (mg_millis() > *(uint64_t *) c->data &&
|
|
||||||
(c->is_connecting || c->is_resolving)) {
|
|
||||||
mg_error(c, "Connect timeout");
|
|
||||||
}
|
|
||||||
} else if (ev == MG_EV_CONNECT) {
|
|
||||||
struct mg_str host = mg_url_host(s_url);
|
|
||||||
if (mg_url_is_ssl(s_url)) {
|
|
||||||
// no implement
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send request
|
|
||||||
size_t content_length = data.post_data.size();
|
|
||||||
mg_printf(c,
|
|
||||||
"POST %s HTTP/1.0\r\n"
|
|
||||||
"Host: %.*s\r\n"
|
|
||||||
"Content-Type: application/json\r\n"
|
|
||||||
"Content-Length: %d\r\n"
|
|
||||||
"\r\n",
|
|
||||||
mg_url_uri(s_url), (int) host.len,
|
|
||||||
host.ptr, content_length);
|
|
||||||
mg_send(c, data.post_data.c_str(), content_length);
|
|
||||||
} else if (ev == MG_EV_HTTP_MSG) {
|
|
||||||
// Response is received. Print it
|
|
||||||
#ifdef _DEBUG
|
|
||||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
|
||||||
printf("%.*s", (int) hm->message.len, hm->message.ptr);
|
|
||||||
#endif
|
|
||||||
c->is_closing = 1; // Tell mongoose to close this connection
|
|
||||||
data.done = true; // Tell event loop to stops
|
|
||||||
} else if (ev == MG_EV_ERROR) {
|
|
||||||
data.done = true; // Error, tell event loop to stop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HttpClient::SetConfig(std::string url,uint64_t timeout){
|
|
||||||
url_=url;
|
|
||||||
timeout_=timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace wxhelper
|
|
@ -1,24 +0,0 @@
|
|||||||
#ifndef WXHELPER_HTTP_CLIENT_H_
|
|
||||||
#define WXHELPER_HTTP_CLIENT_H_
|
|
||||||
#include "mongoose.h"
|
|
||||||
#include "singleton.h"
|
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
struct Data {
|
|
||||||
bool done;
|
|
||||||
std::string post_data;
|
|
||||||
};
|
|
||||||
class HttpClient : public Singleton<HttpClient> {
|
|
||||||
public:
|
|
||||||
void SendRequest(std::string content);
|
|
||||||
void SetConfig(std::string url,uint64_t timeout);
|
|
||||||
|
|
||||||
static void OnHttpEvent(struct mg_connection *c, int ev, void *ev_data,
|
|
||||||
void *fn_data);
|
|
||||||
private:
|
|
||||||
std::string url_;
|
|
||||||
uint64_t timeout_;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace wxhelper
|
|
||||||
#endif
|
|
@ -1,54 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "http_server_callback.h"
|
|
||||||
#include "http_server.h"
|
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
|
|
||||||
HttpServer::HttpServer(int port) {
|
|
||||||
port_ = port;
|
|
||||||
running_ = false;
|
|
||||||
mg_mgr_init(&mgr_);
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpServer::~HttpServer() {
|
|
||||||
if (thread_ != nullptr) {
|
|
||||||
CloseHandle(thread_);
|
|
||||||
}
|
|
||||||
mg_mgr_free(&mgr_);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HttpServer::HttpStart() {
|
|
||||||
if (running_) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#ifdef _DEBUG
|
|
||||||
Utils::CreateConsole();
|
|
||||||
#endif
|
|
||||||
running_ = true;
|
|
||||||
thread_ = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartHttpServer, this,
|
|
||||||
NULL, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HttpServer::HttpClose() {
|
|
||||||
if (!running_) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#ifdef _DEBUG
|
|
||||||
Utils::CloseConsole();
|
|
||||||
#endif
|
|
||||||
running_ = false;
|
|
||||||
if (thread_) {
|
|
||||||
WaitForSingleObject(thread_, -1);
|
|
||||||
CloseHandle(thread_);
|
|
||||||
thread_ = NULL;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int HttpServer::GetPort() { return port_; }
|
|
||||||
bool HttpServer::GetRunning() { return running_; }
|
|
||||||
|
|
||||||
const mg_mgr* HttpServer::GetMgr() { return &mgr_; }
|
|
||||||
|
|
||||||
} // namespace wxhelper
|
|
@ -1,29 +0,0 @@
|
|||||||
#ifndef WXHELPER_HTTP_SERVER_H_
|
|
||||||
#define WXHELPER_HTTP_SERVER_H_
|
|
||||||
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
class HttpServer {
|
|
||||||
public:
|
|
||||||
explicit HttpServer(int port);
|
|
||||||
HttpServer(const HttpServer&) = delete;
|
|
||||||
HttpServer(HttpServer &&)=delete;
|
|
||||||
HttpServer& operator=(const HttpServer&) = delete;
|
|
||||||
~HttpServer();
|
|
||||||
|
|
||||||
bool HttpStart();
|
|
||||||
bool HttpClose();
|
|
||||||
int GetPort();
|
|
||||||
bool GetRunning();
|
|
||||||
const mg_mgr* GetMgr();
|
|
||||||
|
|
||||||
private:
|
|
||||||
int port_;
|
|
||||||
bool running_;
|
|
||||||
struct mg_mgr mgr_;
|
|
||||||
HANDLE thread_;
|
|
||||||
};
|
|
||||||
} // namespace wxhelper
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,615 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "http_server_callback.h"
|
|
||||||
#include "http_server.h"
|
|
||||||
#include "export.h"
|
|
||||||
#include "global_context.h"
|
|
||||||
#include "hooks.h"
|
|
||||||
#include "db.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define STR2ULL(str) (wxhelper::Utils::IsDigit(str) ? stoull(str) : 0)
|
|
||||||
#define STR2LL(str) (wxhelper::Utils::IsDigit(str) ? stoll(str) : 0)
|
|
||||||
#define STR2I(str) (wxhelper::Utils::IsDigit(str) ? stoi(str) : 0)
|
|
||||||
namespace common = wxhelper::common;
|
|
||||||
|
|
||||||
int GetIntParam(nlohmann::json data, std::string key) {
|
|
||||||
int result;
|
|
||||||
try {
|
|
||||||
result = data[key].get<int>();
|
|
||||||
} catch (nlohmann::json::exception) {
|
|
||||||
result = STR2I(data[key].get<std::string>());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
INT64 GetINT64Param(nlohmann::json data, std::string key) {
|
|
||||||
INT64 result;
|
|
||||||
try {
|
|
||||||
result = data[key].get<INT64>();
|
|
||||||
} catch (nlohmann::json::exception) {
|
|
||||||
result = STR2LL(data[key].get<std::string>());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
INT64 GetUINT64Param(nlohmann::json data, std::string key) {
|
|
||||||
UINT64 result;
|
|
||||||
try {
|
|
||||||
result = data[key].get<UINT64>();
|
|
||||||
} catch (nlohmann::json::exception) {
|
|
||||||
result = STR2ULL(data[key].get<std::string>());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetStringParam(nlohmann::json data, std::string key) {
|
|
||||||
return data[key].get<std::string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring GetWStringParam(nlohmann::json data, std::string key) {
|
|
||||||
return wxhelper::Utils::UTF8ToWstring(data[key].get<std::string>());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::wstring> GetArrayParam(nlohmann::json data, std::string key) {
|
|
||||||
std::vector<std::wstring> result;
|
|
||||||
std::wstring param = GetWStringParam(data, key);
|
|
||||||
result = wxhelper::Utils::split(param, L',');
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void StartHttpServer(wxhelper::HttpServer *server) {
|
|
||||||
int port = server->GetPort();
|
|
||||||
std::string lsten_addr = "http://0.0.0.0:" + std::to_string(port);
|
|
||||||
if (mg_http_listen(const_cast<mg_mgr *>(server->GetMgr()), lsten_addr.c_str(),
|
|
||||||
EventHandler,
|
|
||||||
const_cast<mg_mgr *>(server->GetMgr())) == NULL) {
|
|
||||||
SPDLOG_INFO("http server listen fail.port:{}", port);
|
|
||||||
#ifdef _DEBUG
|
|
||||||
MG_INFO(("http server listen fail.port: %d", port));
|
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (;;) {
|
|
||||||
mg_mgr_poll(const_cast<mg_mgr *>(server->GetMgr()), 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventHandler(struct mg_connection *c, int ev, void *ev_data,
|
|
||||||
void *fn_data) {
|
|
||||||
if (ev == MG_EV_OPEN) {
|
|
||||||
} else if (ev == MG_EV_HTTP_MSG) {
|
|
||||||
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
|
||||||
if (mg_http_match_uri(hm, "/websocket")) {
|
|
||||||
mg_ws_upgrade(c, hm, NULL);
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/*")) {
|
|
||||||
HandleHttpRequest(c, hm);
|
|
||||||
} else {
|
|
||||||
nlohmann::json res = {{"code", 400},
|
|
||||||
{"msg", "invalid url, please check url"},
|
|
||||||
{"data", NULL}};
|
|
||||||
std::string ret = res.dump();
|
|
||||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n",
|
|
||||||
ret.c_str());
|
|
||||||
}
|
|
||||||
} else if (ev == MG_EV_WS_MSG) {
|
|
||||||
HandleWebsocketRequest(c, ev_data);
|
|
||||||
}
|
|
||||||
(void)fn_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleHttpRequest(struct mg_connection *c, void *ev_data) {
|
|
||||||
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
|
||||||
std::string ret = R"({"code":200,"msg":"success"})";
|
|
||||||
try {
|
|
||||||
ret = HttpDispatch(c, hm);
|
|
||||||
} catch (nlohmann::json::exception &e) {
|
|
||||||
nlohmann::json res = {{"code", "500"}, {"msg", e.what()}, {"data", NULL}};
|
|
||||||
ret = res.dump();
|
|
||||||
}
|
|
||||||
if (ret != "") {
|
|
||||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s\n",
|
|
||||||
ret.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleWebsocketRequest(struct mg_connection *c, void *ev_data) {
|
|
||||||
// Got websocket frame. Received data is wm->data. Echo it back!
|
|
||||||
struct mg_ws_message *wm = (struct mg_ws_message *)ev_data;
|
|
||||||
mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) {
|
|
||||||
std::string ret;
|
|
||||||
if (mg_vcasecmp(&hm->method, "GET") == 0) {
|
|
||||||
nlohmann::json ret_data = {{"code", 200},
|
|
||||||
{"data", {}},
|
|
||||||
{"msg", "not support get method,use post."}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json j_param = nlohmann::json::parse(
|
|
||||||
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
|
|
||||||
if (hm->body.len != 0 && j_param.is_discarded() == true) {
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", 200}, {"data", {}}, {"msg", "json string is invalid."}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (wxhelper::GlobalContext::GetInstance().state !=
|
|
||||||
wxhelper::GlobalContextState::INITIALIZED) {
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", 200}, {"data", {}}, {"msg", "global context is initializing"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (mg_http_match_uri(hm, "/api/checkLogin")) {
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->CheckLogin();
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/userInfo")) {
|
|
||||||
common::SelfInfoInner self_info;
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->GetSelfInfo(self_info);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
if (success) {
|
|
||||||
nlohmann::json j_info = {
|
|
||||||
{"name", self_info.name},
|
|
||||||
{"city", self_info.city},
|
|
||||||
{"province", self_info.province},
|
|
||||||
{"country", self_info.country},
|
|
||||||
{"account", self_info.account},
|
|
||||||
{"wxid", self_info.wxid},
|
|
||||||
{"mobile", self_info.mobile},
|
|
||||||
{"headImage", self_info.head_img},
|
|
||||||
{"signature", self_info.signature},
|
|
||||||
{"dataSavePath", self_info.data_save_path},
|
|
||||||
{"currentDataPath", self_info.current_data_path},
|
|
||||||
{"dbKey", self_info.db_key},
|
|
||||||
};
|
|
||||||
ret_data["data"] = j_info;
|
|
||||||
}
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/sendTextMsg")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring msg = GetWStringParam(j_param, "msg");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->SendTextMsg(wxid, msg);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/hookSyncMsg")) {
|
|
||||||
int port = GetIntParam(j_param, "port");
|
|
||||||
std::string ip = GetStringParam(j_param, "ip");
|
|
||||||
int enable = GetIntParam(j_param, "enableHttp");
|
|
||||||
std::string url = "";
|
|
||||||
int timeout = 0;
|
|
||||||
if (enable) {
|
|
||||||
url = GetStringParam(j_param, "url");
|
|
||||||
timeout = GetIntParam(j_param, "timeout");
|
|
||||||
}
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::hooks::HookSyncMsg(ip, port, url, timeout, enable);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/sendImagesMsg")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring path = GetWStringParam(j_param, "imagePath");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->SendImageMsg(wxid, path);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/sendFileMsg")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring path = GetWStringParam(j_param, "filePath");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->SendFileMsg(wxid, path);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getContactList")) {
|
|
||||||
std::vector<common::ContactInner> vec;
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->GetContacts(vec);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
for (unsigned int i = 0; i < vec.size(); i++) {
|
|
||||||
nlohmann::json item = {
|
|
||||||
{"customAccount", vec[i].custom_account},
|
|
||||||
{"encryptName", vec[i].encrypt_name},
|
|
||||||
{"type", vec[i].type},
|
|
||||||
{"verifyFlag", vec[i].verify_flag},
|
|
||||||
{"wxid", vec[i].wxid},
|
|
||||||
{"nickname", vec[i].nickname},
|
|
||||||
{"pinyin", vec[i].pinyin},
|
|
||||||
{"pinyinAll", vec[i].pinyin_all},
|
|
||||||
{"reserved1", vec[i].reserved1},
|
|
||||||
{"reserved2", vec[i].reserved2},
|
|
||||||
};
|
|
||||||
ret_data["data"].push_back(item);
|
|
||||||
}
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/unhookSyncMsg")) {
|
|
||||||
INT64 success = wxhelper::hooks::UnHookSyncMsg();
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"data", {}}, {"msg", "success"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getDBInfo")) {
|
|
||||||
std::vector<void *> v_ptr = wxhelper::DB::GetInstance().GetDbHandles();
|
|
||||||
nlohmann::json ret_data = {{"data", nlohmann::json::array()}};
|
|
||||||
for (unsigned int i = 0; i < v_ptr.size(); i++) {
|
|
||||||
nlohmann::json db_info;
|
|
||||||
db_info["tables"] = nlohmann::json::array();
|
|
||||||
common::DatabaseInfo *db =
|
|
||||||
reinterpret_cast<common::DatabaseInfo *>(v_ptr[i]);
|
|
||||||
db_info["handle"] = db->handle;
|
|
||||||
std::wstring dbname(db->db_name);
|
|
||||||
db_info["databaseName"] = wxhelper::Utils::WstringToUTF8(dbname);
|
|
||||||
for (auto table : db->tables) {
|
|
||||||
nlohmann::json table_info = {{"name", table.name},
|
|
||||||
{"tableName", table.table_name},
|
|
||||||
{"sql", table.sql},
|
|
||||||
{"rootpage", table.rootpage}};
|
|
||||||
db_info["tables"].push_back(table_info);
|
|
||||||
}
|
|
||||||
ret_data["data"].push_back(db_info);
|
|
||||||
}
|
|
||||||
ret_data["code"] = 1;
|
|
||||||
ret_data["msg"] = "success";
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/execSql")) {
|
|
||||||
UINT64 db_handle = GetINT64Param(j_param, "dbHandle");
|
|
||||||
std::string sql = GetStringParam(j_param, "sql");
|
|
||||||
std::vector<std::vector<std::string>> items;
|
|
||||||
int success =
|
|
||||||
wxhelper::DB::GetInstance().Select(db_handle, sql.c_str(), items);
|
|
||||||
nlohmann::json ret_data = {{"data", nlohmann::json::array()},
|
|
||||||
{"code", success},
|
|
||||||
{"msg", "success"}};
|
|
||||||
if (success == 0) {
|
|
||||||
ret_data["msg"] = "no data";
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
for (auto it : items) {
|
|
||||||
nlohmann::json temp_arr = nlohmann::json::array();
|
|
||||||
for (size_t i = 0; i < it.size(); i++) {
|
|
||||||
temp_arr.push_back(it[i]);
|
|
||||||
}
|
|
||||||
ret_data["data"].push_back(temp_arr);
|
|
||||||
}
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getChatRoomDetailInfo")) {
|
|
||||||
std::wstring chat_room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
common::ChatRoomInfoInner chat_room_detail;
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->GetChatRoomDetailInfo(
|
|
||||||
chat_room_id, chat_room_detail);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
|
|
||||||
nlohmann::json detail = {
|
|
||||||
{"chatRoomId", chat_room_detail.chat_room_id},
|
|
||||||
{"notice", chat_room_detail.notice},
|
|
||||||
{"admin", chat_room_detail.admin},
|
|
||||||
{"xml", chat_room_detail.xml},
|
|
||||||
};
|
|
||||||
ret_data["data"] = detail;
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/addMemberToChatRoom")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
std::vector<std::wstring> wxids = GetArrayParam(j_param, "memberIds");
|
|
||||||
std::vector<std::wstring> wxid_list;
|
|
||||||
for (unsigned int i = 0; i < wxids.size(); i++) {
|
|
||||||
wxid_list.push_back(wxids[i]);
|
|
||||||
}
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->AddMemberToChatRoom(
|
|
||||||
room_id, wxid_list);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/modifyNickname")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring nickName = GetWStringParam(j_param, "nickName");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->ModChatRoomMemberNickName(
|
|
||||||
room_id, wxid, nickName);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/delMemberFromChatRoom")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
std::vector<std::wstring> wxids = GetArrayParam(j_param, "memberIds");
|
|
||||||
std::vector<std::wstring> wxid_list;
|
|
||||||
for (unsigned int i = 0; i < wxids.size(); i++) {
|
|
||||||
wxid_list.push_back(wxids[i]);
|
|
||||||
}
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->DelMemberFromChatRoom(
|
|
||||||
room_id, wxid_list);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getMemberFromChatRoom")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
common::ChatRoomMemberInner member;
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->GetMemberFromChatRoom(
|
|
||||||
room_id, member);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
if (success >= 0) {
|
|
||||||
nlohmann::json member_info = {
|
|
||||||
{"admin", member.admin},
|
|
||||||
{"chatRoomId", member.chat_room_id},
|
|
||||||
{"members", member.member},
|
|
||||||
{"adminNickname", member.admin_nickname},
|
|
||||||
{"memberNickname", member.member_nickname},
|
|
||||||
};
|
|
||||||
ret_data["data"] = member_info;
|
|
||||||
}
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/topMsg")) {
|
|
||||||
INT64 msg_id = GetINT64Param(j_param, "msgId");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->SetTopMsg(msg_id);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/removeTopMsg")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
INT64 msg_id = GetINT64Param(j_param, "msgId");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->RemoveTopMsg(room_id,msg_id);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/InviteMemberToChatRoom")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
std::vector<std::wstring> wxids = GetArrayParam(j_param, "memberIds");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->InviteMemberToChatRoom(
|
|
||||||
room_id, wxids);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/hookLog")) {
|
|
||||||
int success = wxhelper::hooks::HookLog();
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/unhookLog")) {
|
|
||||||
int success = wxhelper::hooks::UnHookLog();
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/createChatRoom")) {
|
|
||||||
std::vector<std::wstring> wxids = GetArrayParam(j_param, "memberIds");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->CreateChatRoom(wxids);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/quitChatRoom")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->QuitChatRoom(room_id);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/forwardMsg")) {
|
|
||||||
INT64 msg_id = GetINT64Param(j_param, "msgId");
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->ForwardMsg(msg_id,wxid);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getSNSFirstPage")) {
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->GetSNSFirstPage();
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getSNSNextPage")) {
|
|
||||||
UINT64 snsid = GetUINT64Param(j_param, "snsId");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->GetSNSNextPage(snsid);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/addFavFromMsg")) {
|
|
||||||
UINT64 msg_id = GetUINT64Param(j_param, "msgId");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->AddFavFromMsg(msg_id);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/addFavFromImage")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring image_path = GetWStringParam(j_param, "imagePath");
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->AddFavFromImage(
|
|
||||||
wxid, image_path);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/sendAtText")) {
|
|
||||||
std::wstring chat_room_id = GetWStringParam(j_param, "chatRoomId");
|
|
||||||
std::vector<std::wstring> wxids = GetArrayParam(j_param, "wxids");
|
|
||||||
std::wstring msg = GetWStringParam(j_param, "msg");
|
|
||||||
std::vector<std::wstring> wxid_list;
|
|
||||||
for (unsigned int i = 0; i < wxids.size(); i++) {
|
|
||||||
wxid_list.push_back(wxids[i]);
|
|
||||||
}
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->SendAtText(
|
|
||||||
chat_room_id, wxid_list, msg);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getContactProfile")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
common::ContactProfileInner profile;
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->GetContactByWxid(wxid,
|
|
||||||
profile);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
if (success == 1) {
|
|
||||||
nlohmann::json contact_profile = {
|
|
||||||
{"account", profile.account}, {"headImage", profile.head_image},
|
|
||||||
{"nickname", profile.nickname}, {"v3", profile.v3},
|
|
||||||
{"wxid", profile.wxid},
|
|
||||||
};
|
|
||||||
ret_data["data"] = contact_profile;
|
|
||||||
}
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/downloadAttach")) {
|
|
||||||
UINT64 msg_id = GetUINT64Param(j_param, "msgId");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->DoDownloadTask(msg_id);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/forwardPublicMsg")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring appname = GetWStringParam(j_param, "appName");
|
|
||||||
std::wstring username = GetWStringParam(j_param, "userName");
|
|
||||||
std::wstring title = GetWStringParam(j_param, "title");
|
|
||||||
std::wstring url = GetWStringParam(j_param, "url");
|
|
||||||
std::wstring thumburl = GetWStringParam(j_param, "thumbUrl");
|
|
||||||
std::wstring digest = GetWStringParam(j_param, "digest");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->ForwardPublicMsg(
|
|
||||||
wxid, title, url, thumburl, username, appname, digest);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/forwardPublicMsgByMsgId")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
UINT64 msg_id = GetUINT64Param(j_param, "msgId");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->ForwardPublicMsgByMsgId(
|
|
||||||
wxid, msg_id);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/decodeImage")) {
|
|
||||||
std::wstring file_path = GetWStringParam(j_param, "filePath");
|
|
||||||
std::wstring store_dir = GetWStringParam(j_param, "storeDir");
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->DecodeImage(
|
|
||||||
file_path, store_dir);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/getVoiceByMsgId")) {
|
|
||||||
UINT64 msg_id = GetUINT64Param(j_param, "msgId");
|
|
||||||
std::wstring store_dir = GetWStringParam(j_param, "storeDir");
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->GetVoiceByDB(
|
|
||||||
msg_id, store_dir);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/sendCustomEmotion")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring file_path = GetWStringParam(j_param, "filePath");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->SendCustomEmotion(file_path,
|
|
||||||
wxid);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/sendApplet")) {
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
std::wstring waid_concat = GetWStringParam(j_param, "waidConcat");
|
|
||||||
std::string waid = GetStringParam(j_param, "waid");
|
|
||||||
std::string app_wxid = GetStringParam(j_param, "appletWxid");
|
|
||||||
std::string json_param = GetStringParam(j_param, "jsonParam");
|
|
||||||
std::string head_url = GetStringParam(j_param, "headImgUrl");
|
|
||||||
std::string main_img = GetStringParam(j_param, "mainImg");
|
|
||||||
std::string index_page = GetStringParam(j_param, "indexPage");
|
|
||||||
|
|
||||||
std::wstring waid_w = wxhelper::Utils::UTF8ToWstring(waid);
|
|
||||||
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->SendApplet(
|
|
||||||
wxid, waid_concat, waid_w, waid, app_wxid, json_param, head_url,
|
|
||||||
main_img, index_page);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/sendPatMsg")) {
|
|
||||||
std::wstring room_id = GetWStringParam(j_param, "receiver");
|
|
||||||
std::wstring wxid = GetWStringParam(j_param, "wxid");
|
|
||||||
INT64 success =
|
|
||||||
wxhelper::GlobalContext::GetInstance().mgr->SendPatMsg(room_id, wxid);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/ocr")) {
|
|
||||||
std::wstring image_path = GetWStringParam(j_param, "imagePath");
|
|
||||||
std::string text("");
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->DoOCRTask(image_path,text);
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", text}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else if (mg_http_match_uri(hm, "/api/test")) {
|
|
||||||
INT64 success = wxhelper::GlobalContext::GetInstance().mgr->Test();
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", success}, {"msg", "success"}, {"data", {}}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
} else {
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", 200}, {"data", {}}, {"msg", "not support url"}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
nlohmann::json ret_data = {
|
|
||||||
{"code", 200}, {"data", {}}, {"msg", "unreachable code."}};
|
|
||||||
ret = ret_data.dump();
|
|
||||||
return ret;
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
#ifndef WXHELPER_HTTP_SERVER_CALLBACK_H_
|
|
||||||
#define WXHELPER_HTTP_SERVER_CALLBACK_H_
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "http_server.h"
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
|
|
||||||
void StartHttpServer(wxhelper::HttpServer *server);
|
|
||||||
|
|
||||||
void EventHandler(struct mg_connection *c, int ev, void *ev_data,
|
|
||||||
void *fn_data);
|
|
||||||
void HandleHttpRequest(struct mg_connection *c, void *ev_data);
|
|
||||||
void HandleWebsocketRequest(struct mg_connection *c, void *ev_data);
|
|
||||||
std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm);
|
|
||||||
|
|
||||||
#endif
|
|
21
src/log.cc
21
src/log.cc
@ -1,21 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
|
||||||
namespace wxhelper {
|
|
||||||
Log::Log() {}
|
|
||||||
|
|
||||||
Log::~Log() {}
|
|
||||||
|
|
||||||
void Log::Initialize() {
|
|
||||||
auto logger =
|
|
||||||
spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 23, 59);
|
|
||||||
logger->flush_on(spdlog::level::err);
|
|
||||||
spdlog::set_default_logger(logger);
|
|
||||||
spdlog::flush_every(std::chrono::seconds(3));
|
|
||||||
spdlog::set_level(spdlog::level::debug);
|
|
||||||
spdlog::set_pattern("%Y-%m-%d %H:%M:%S [%l] [%t] - <%s>|<%#>|<%!>,%v");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace wxhelper
|
|
15
src/log.h
15
src/log.h
@ -1,15 +0,0 @@
|
|||||||
#ifndef WXHELPER_LOG_H_
|
|
||||||
#define WXHELPER_LOG_H_
|
|
||||||
namespace wxhelper {
|
|
||||||
class Log {
|
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
Log();
|
|
||||||
~Log();
|
|
||||||
void Initialize();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace wxhelper
|
|
||||||
|
|
||||||
#endif
|
|
862
src/lz4.h
862
src/lz4.h
@ -1,862 +0,0 @@
|
|||||||
/*
|
|
||||||
* LZ4 - Fast LZ compression algorithm
|
|
||||||
* Header File
|
|
||||||
* Copyright (C) 2011-2020, Yann Collet.
|
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
|
||||||
|
|
||||||
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
|
|
||||||
OWNER 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.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- LZ4 homepage : http://www.lz4.org
|
|
||||||
- LZ4 source repository : https://github.com/lz4/lz4
|
|
||||||
*/
|
|
||||||
#if defined (__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef LZ4_H_2983827168210
|
|
||||||
#define LZ4_H_2983827168210
|
|
||||||
|
|
||||||
/* --- Dependency --- */
|
|
||||||
#include <stddef.h> /* size_t */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Introduction
|
|
||||||
|
|
||||||
LZ4 is lossless compression algorithm, providing compression speed >500 MB/s per core,
|
|
||||||
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
|
||||||
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
|
||||||
|
|
||||||
The LZ4 compression library provides in-memory compression and decompression functions.
|
|
||||||
It gives full buffer control to user.
|
|
||||||
Compression can be done in:
|
|
||||||
- a single step (described as Simple Functions)
|
|
||||||
- a single step, reusing a context (described in Advanced Functions)
|
|
||||||
- unbounded multiple steps (described as Streaming compression)
|
|
||||||
|
|
||||||
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
|
||||||
Decompressing such a compressed block requires additional metadata.
|
|
||||||
Exact metadata depends on exact decompression function.
|
|
||||||
For the typical case of LZ4_decompress_safe(),
|
|
||||||
metadata includes block's compressed size, and maximum bound of decompressed size.
|
|
||||||
Each application is free to encode and pass such metadata in whichever way it wants.
|
|
||||||
|
|
||||||
lz4.h only handle blocks, it can not generate Frames.
|
|
||||||
|
|
||||||
Blocks are different from Frames (doc/lz4_Frame_format.md).
|
|
||||||
Frames bundle both blocks and metadata in a specified manner.
|
|
||||||
Embedding metadata is required for compressed data to be self-contained and portable.
|
|
||||||
Frame format is delivered through a companion API, declared in lz4frame.h.
|
|
||||||
The `lz4` CLI can only manage frames.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*^***************************************************************
|
|
||||||
* Export parameters
|
|
||||||
*****************************************************************/
|
|
||||||
/*
|
|
||||||
* LZ4_DLL_EXPORT :
|
|
||||||
* Enable exporting of functions when building a Windows DLL
|
|
||||||
* LZ4LIB_VISIBILITY :
|
|
||||||
* Control library symbols visibility.
|
|
||||||
*/
|
|
||||||
#ifndef LZ4LIB_VISIBILITY
|
|
||||||
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
|
||||||
# define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
|
|
||||||
# else
|
|
||||||
# define LZ4LIB_VISIBILITY
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
|
|
||||||
# define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
|
|
||||||
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
|
|
||||||
# define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
|
||||||
#else
|
|
||||||
# define LZ4LIB_API LZ4LIB_VISIBILITY
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*! LZ4_FREESTANDING :
|
|
||||||
* When this macro is set to 1, it enables "freestanding mode" that is
|
|
||||||
* suitable for typical freestanding environment which doesn't support
|
|
||||||
* standard C library.
|
|
||||||
*
|
|
||||||
* - LZ4_FREESTANDING is a compile-time switch.
|
|
||||||
* - It requires the following macros to be defined:
|
|
||||||
* LZ4_memcpy, LZ4_memmove, LZ4_memset.
|
|
||||||
* - It only enables LZ4/HC functions which don't use heap.
|
|
||||||
* All LZ4F_* functions are not supported.
|
|
||||||
* - See tests/freestanding.c to check its basic setup.
|
|
||||||
*/
|
|
||||||
#if defined(LZ4_FREESTANDING) && (LZ4_FREESTANDING == 1)
|
|
||||||
# define LZ4_HEAPMODE 0
|
|
||||||
# define LZ4HC_HEAPMODE 0
|
|
||||||
# define LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION 1
|
|
||||||
# if !defined(LZ4_memcpy)
|
|
||||||
# error "LZ4_FREESTANDING requires macro 'LZ4_memcpy'."
|
|
||||||
# endif
|
|
||||||
# if !defined(LZ4_memset)
|
|
||||||
# error "LZ4_FREESTANDING requires macro 'LZ4_memset'."
|
|
||||||
# endif
|
|
||||||
# if !defined(LZ4_memmove)
|
|
||||||
# error "LZ4_FREESTANDING requires macro 'LZ4_memmove'."
|
|
||||||
# endif
|
|
||||||
#elif ! defined(LZ4_FREESTANDING)
|
|
||||||
# define LZ4_FREESTANDING 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*------ Version ------*/
|
|
||||||
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
|
|
||||||
#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
|
|
||||||
#define LZ4_VERSION_RELEASE 4 /* for tweaks, bug-fixes, or development */
|
|
||||||
|
|
||||||
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
|
|
||||||
|
|
||||||
#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
|
|
||||||
#define LZ4_QUOTE(str) #str
|
|
||||||
#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
|
|
||||||
#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) /* requires v1.7.3+ */
|
|
||||||
|
|
||||||
LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; useful to check dll version; requires v1.3.0+ */
|
|
||||||
LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; useful to check dll version; requires v1.7.5+ */
|
|
||||||
|
|
||||||
|
|
||||||
/*-************************************
|
|
||||||
* Tuning parameter
|
|
||||||
**************************************/
|
|
||||||
#define LZ4_MEMORY_USAGE_MIN 10
|
|
||||||
#define LZ4_MEMORY_USAGE_DEFAULT 14
|
|
||||||
#define LZ4_MEMORY_USAGE_MAX 20
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* LZ4_MEMORY_USAGE :
|
|
||||||
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; )
|
|
||||||
* Increasing memory usage improves compression ratio, at the cost of speed.
|
|
||||||
* Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality.
|
|
||||||
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
|
|
||||||
*/
|
|
||||||
#ifndef LZ4_MEMORY_USAGE
|
|
||||||
# define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN)
|
|
||||||
# error "LZ4_MEMORY_USAGE is too small !"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX)
|
|
||||||
# error "LZ4_MEMORY_USAGE is too large !"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-************************************
|
|
||||||
* Simple Functions
|
|
||||||
**************************************/
|
|
||||||
/*! LZ4_compress_default() :
|
|
||||||
* Compresses 'srcSize' bytes from buffer 'src'
|
|
||||||
* into already allocated 'dst' buffer of size 'dstCapacity'.
|
|
||||||
* Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
|
||||||
* It also runs faster, so it's a recommended setting.
|
|
||||||
* If the function cannot compress 'src' into a more limited 'dst' budget,
|
|
||||||
* compression stops *immediately*, and the function result is zero.
|
|
||||||
* In which case, 'dst' content is undefined (invalid).
|
|
||||||
* srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
|
||||||
* dstCapacity : size of buffer 'dst' (which must be already allocated)
|
|
||||||
* @return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
|
||||||
* or 0 if compression fails
|
|
||||||
* Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
|
||||||
|
|
||||||
/*! LZ4_decompress_safe() :
|
|
||||||
* @compressedSize : is the exact complete size of the compressed block.
|
|
||||||
* @dstCapacity : is the size of destination buffer (which must be already allocated),
|
|
||||||
* is an upper bound of decompressed size.
|
|
||||||
* @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
|
||||||
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
|
||||||
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
|
||||||
* Note 1 : This function is protected against malicious data packets :
|
|
||||||
* it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
|
|
||||||
* even if the compressed block is maliciously modified to order the decoder to do these actions.
|
|
||||||
* In such case, the decoder stops immediately, and considers the compressed block malformed.
|
|
||||||
* Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
|
|
||||||
* The implementation is free to send / store / derive this information in whichever way is most beneficial.
|
|
||||||
* If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
|
|
||||||
|
|
||||||
|
|
||||||
/*-************************************
|
|
||||||
* Advanced Functions
|
|
||||||
**************************************/
|
|
||||||
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
|
|
||||||
#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
|
|
||||||
|
|
||||||
/*! LZ4_compressBound() :
|
|
||||||
Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
|
|
||||||
This function is primarily useful for memory allocation purposes (destination buffer size).
|
|
||||||
Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
|
|
||||||
Note that LZ4_compress_default() compresses faster when dstCapacity is >= LZ4_compressBound(srcSize)
|
|
||||||
inputSize : max supported value is LZ4_MAX_INPUT_SIZE
|
|
||||||
return : maximum output size in a "worst case" scenario
|
|
||||||
or 0, if input size is incorrect (too large or negative)
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_compressBound(int inputSize);
|
|
||||||
|
|
||||||
/*! LZ4_compress_fast() :
|
|
||||||
Same as LZ4_compress_default(), but allows selection of "acceleration" factor.
|
|
||||||
The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
|
|
||||||
It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
|
|
||||||
An acceleration value of "1" is the same as regular LZ4_compress_default()
|
|
||||||
Values <= 0 will be replaced by LZ4_ACCELERATION_DEFAULT (currently == 1, see lz4.c).
|
|
||||||
Values > LZ4_ACCELERATION_MAX will be replaced by LZ4_ACCELERATION_MAX (currently == 65537, see lz4.c).
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
|
||||||
|
|
||||||
|
|
||||||
/*! LZ4_compress_fast_extState() :
|
|
||||||
* Same as LZ4_compress_fast(), using an externally allocated memory space for its state.
|
|
||||||
* Use LZ4_sizeofState() to know how much memory must be allocated,
|
|
||||||
* and allocate it on 8-bytes boundaries (using `malloc()` typically).
|
|
||||||
* Then, provide this buffer as `void* state` to compression function.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_sizeofState(void);
|
|
||||||
LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
|
||||||
|
|
||||||
|
|
||||||
/*! LZ4_compress_destSize() :
|
|
||||||
* Reverse the logic : compresses as much data as possible from 'src' buffer
|
|
||||||
* into already allocated buffer 'dst', of size >= 'targetDestSize'.
|
|
||||||
* This function either compresses the entire 'src' content into 'dst' if it's large enough,
|
|
||||||
* or fill 'dst' buffer completely with as much data as possible from 'src'.
|
|
||||||
* note: acceleration parameter is fixed to "default".
|
|
||||||
*
|
|
||||||
* *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
|
|
||||||
* New value is necessarily <= input value.
|
|
||||||
* @return : Nb bytes written into 'dst' (necessarily <= targetDestSize)
|
|
||||||
* or 0 if compression fails.
|
|
||||||
*
|
|
||||||
* Note : from v1.8.2 to v1.9.1, this function had a bug (fixed un v1.9.2+):
|
|
||||||
* the produced compressed content could, in specific circumstances,
|
|
||||||
* require to be decompressed into a destination buffer larger
|
|
||||||
* by at least 1 byte than the content to decompress.
|
|
||||||
* If an application uses `LZ4_compress_destSize()`,
|
|
||||||
* it's highly recommended to update liblz4 to v1.9.2 or better.
|
|
||||||
* If this can't be done or ensured,
|
|
||||||
* the receiving decompression function should provide
|
|
||||||
* a dstCapacity which is > decompressedSize, by at least 1 byte.
|
|
||||||
* See https://github.com/lz4/lz4/issues/859 for details
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
|
|
||||||
|
|
||||||
|
|
||||||
/*! LZ4_decompress_safe_partial() :
|
|
||||||
* Decompress an LZ4 compressed block, of size 'srcSize' at position 'src',
|
|
||||||
* into destination buffer 'dst' of size 'dstCapacity'.
|
|
||||||
* Up to 'targetOutputSize' bytes will be decoded.
|
|
||||||
* The function stops decoding on reaching this objective.
|
|
||||||
* This can be useful to boost performance
|
|
||||||
* whenever only the beginning of a block is required.
|
|
||||||
*
|
|
||||||
* @return : the number of bytes decoded in `dst` (necessarily <= targetOutputSize)
|
|
||||||
* If source stream is detected malformed, function returns a negative result.
|
|
||||||
*
|
|
||||||
* Note 1 : @return can be < targetOutputSize, if compressed block contains less data.
|
|
||||||
*
|
|
||||||
* Note 2 : targetOutputSize must be <= dstCapacity
|
|
||||||
*
|
|
||||||
* Note 3 : this function effectively stops decoding on reaching targetOutputSize,
|
|
||||||
* so dstCapacity is kind of redundant.
|
|
||||||
* This is because in older versions of this function,
|
|
||||||
* decoding operation would still write complete sequences.
|
|
||||||
* Therefore, there was no guarantee that it would stop writing at exactly targetOutputSize,
|
|
||||||
* it could write more bytes, though only up to dstCapacity.
|
|
||||||
* Some "margin" used to be required for this operation to work properly.
|
|
||||||
* Thankfully, this is no longer necessary.
|
|
||||||
* The function nonetheless keeps the same signature, in an effort to preserve API compatibility.
|
|
||||||
*
|
|
||||||
* Note 4 : If srcSize is the exact size of the block,
|
|
||||||
* then targetOutputSize can be any value,
|
|
||||||
* including larger than the block's decompressed size.
|
|
||||||
* The function will, at most, generate block's decompressed size.
|
|
||||||
*
|
|
||||||
* Note 5 : If srcSize is _larger_ than block's compressed size,
|
|
||||||
* then targetOutputSize **MUST** be <= block's decompressed size.
|
|
||||||
* Otherwise, *silent corruption will occur*.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
|
|
||||||
|
|
||||||
|
|
||||||
/*-*********************************************
|
|
||||||
* Streaming Compression Functions
|
|
||||||
***********************************************/
|
|
||||||
typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
|
|
||||||
|
|
||||||
/**
|
|
||||||
Note about RC_INVOKED
|
|
||||||
|
|
||||||
- RC_INVOKED is predefined symbol of rc.exe (the resource compiler which is part of MSVC/Visual Studio).
|
|
||||||
https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros
|
|
||||||
|
|
||||||
- Since rc.exe is a legacy compiler, it truncates long symbol (> 30 chars)
|
|
||||||
and reports warning "RC4011: identifier truncated".
|
|
||||||
|
|
||||||
- To eliminate the warning, we surround long preprocessor symbol with
|
|
||||||
"#if !defined(RC_INVOKED) ... #endif" block that means
|
|
||||||
"skip this block when rc.exe is trying to read it".
|
|
||||||
*/
|
|
||||||
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
|
|
||||||
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
|
|
||||||
LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
|
|
||||||
LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
|
|
||||||
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*! LZ4_resetStream_fast() : v1.9.0+
|
|
||||||
* Use this to prepare an LZ4_stream_t for a new chain of dependent blocks
|
|
||||||
* (e.g., LZ4_compress_fast_continue()).
|
|
||||||
*
|
|
||||||
* An LZ4_stream_t must be initialized once before usage.
|
|
||||||
* This is automatically done when created by LZ4_createStream().
|
|
||||||
* However, should the LZ4_stream_t be simply declared on stack (for example),
|
|
||||||
* it's necessary to initialize it first, using LZ4_initStream().
|
|
||||||
*
|
|
||||||
* After init, start any new stream with LZ4_resetStream_fast().
|
|
||||||
* A same LZ4_stream_t can be re-used multiple times consecutively
|
|
||||||
* and compress multiple streams,
|
|
||||||
* provided that it starts each new stream with LZ4_resetStream_fast().
|
|
||||||
*
|
|
||||||
* LZ4_resetStream_fast() is much faster than LZ4_initStream(),
|
|
||||||
* but is not compatible with memory regions containing garbage data.
|
|
||||||
*
|
|
||||||
* Note: it's only useful to call LZ4_resetStream_fast()
|
|
||||||
* in the context of streaming compression.
|
|
||||||
* The *extState* functions perform their own resets.
|
|
||||||
* Invoking LZ4_resetStream_fast() before is redundant, and even counterproductive.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API void LZ4_resetStream_fast (LZ4_stream_t* streamPtr);
|
|
||||||
|
|
||||||
/*! LZ4_loadDict() :
|
|
||||||
* Use this function to reference a static dictionary into LZ4_stream_t.
|
|
||||||
* The dictionary must remain available during compression.
|
|
||||||
* LZ4_loadDict() triggers a reset, so any previous data will be forgotten.
|
|
||||||
* The same dictionary will have to be loaded on decompression side for successful decoding.
|
|
||||||
* Dictionary are useful for better compression of small data (KB range).
|
|
||||||
* While LZ4 accept any input as dictionary,
|
|
||||||
* results are generally better when using Zstandard's Dictionary Builder.
|
|
||||||
* Loading a size of 0 is allowed, and is the same as reset.
|
|
||||||
* @return : loaded dictionary size, in bytes (necessarily <= 64 KB)
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
|
|
||||||
|
|
||||||
/*! LZ4_compress_fast_continue() :
|
|
||||||
* Compress 'src' content using data from previously compressed blocks, for better compression ratio.
|
|
||||||
* 'dst' buffer must be already allocated.
|
|
||||||
* If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
|
|
||||||
*
|
|
||||||
* @return : size of compressed block
|
|
||||||
* or 0 if there is an error (typically, cannot fit into 'dst').
|
|
||||||
*
|
|
||||||
* Note 1 : Each invocation to LZ4_compress_fast_continue() generates a new block.
|
|
||||||
* Each block has precise boundaries.
|
|
||||||
* Each block must be decompressed separately, calling LZ4_decompress_*() with relevant metadata.
|
|
||||||
* It's not possible to append blocks together and expect a single invocation of LZ4_decompress_*() to decompress them together.
|
|
||||||
*
|
|
||||||
* Note 2 : The previous 64KB of source data is __assumed__ to remain present, unmodified, at same address in memory !
|
|
||||||
*
|
|
||||||
* Note 3 : When input is structured as a double-buffer, each buffer can have any size, including < 64 KB.
|
|
||||||
* Make sure that buffers are separated, by at least one byte.
|
|
||||||
* This construction ensures that each block only depends on previous block.
|
|
||||||
*
|
|
||||||
* Note 4 : If input buffer is a ring-buffer, it can have any size, including < 64 KB.
|
|
||||||
*
|
|
||||||
* Note 5 : After an error, the stream status is undefined (invalid), it can only be reset or freed.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
|
||||||
|
|
||||||
/*! LZ4_saveDict() :
|
|
||||||
* If last 64KB data cannot be guaranteed to remain available at its current memory location,
|
|
||||||
* save it into a safer place (char* safeBuffer).
|
|
||||||
* This is schematically equivalent to a memcpy() followed by LZ4_loadDict(),
|
|
||||||
* but is much faster, because LZ4_saveDict() doesn't need to rebuild tables.
|
|
||||||
* @return : saved dictionary size in bytes (necessarily <= maxDictSize), or 0 if error.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
|
|
||||||
|
|
||||||
|
|
||||||
/*-**********************************************
|
|
||||||
* Streaming Decompression Functions
|
|
||||||
* Bufferless synchronous API
|
|
||||||
************************************************/
|
|
||||||
typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
|
|
||||||
|
|
||||||
/*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() :
|
|
||||||
* creation / destruction of streaming decompression tracking context.
|
|
||||||
* A tracking context can be re-used multiple times.
|
|
||||||
*/
|
|
||||||
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
|
|
||||||
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
|
|
||||||
LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
|
|
||||||
LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
|
|
||||||
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*! LZ4_setStreamDecode() :
|
|
||||||
* An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
|
|
||||||
* Use this function to start decompression of a new stream of blocks.
|
|
||||||
* A dictionary can optionally be set. Use NULL or size 0 for a reset order.
|
|
||||||
* Dictionary is presumed stable : it must remain accessible and unmodified during next decompression.
|
|
||||||
* @return : 1 if OK, 0 if error
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
|
|
||||||
|
|
||||||
/*! LZ4_decoderRingBufferSize() : v1.8.2+
|
|
||||||
* Note : in a ring buffer scenario (optional),
|
|
||||||
* blocks are presumed decompressed next to each other
|
|
||||||
* up to the moment there is not enough remaining space for next block (remainingSize < maxBlockSize),
|
|
||||||
* at which stage it resumes from beginning of ring buffer.
|
|
||||||
* When setting such a ring buffer for streaming decompression,
|
|
||||||
* provides the minimum size of this ring buffer
|
|
||||||
* to be compatible with any source respecting maxBlockSize condition.
|
|
||||||
* @return : minimum ring buffer size,
|
|
||||||
* or 0 if there is an error (invalid maxBlockSize).
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
|
|
||||||
#define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
|
|
||||||
|
|
||||||
/*! LZ4_decompress_safe_continue() :
|
|
||||||
* This decoding function allows decompression of consecutive blocks in "streaming" mode.
|
|
||||||
* The difference with the usual independent blocks is that
|
|
||||||
* new blocks are allowed to find references into former blocks.
|
|
||||||
* A block is an unsplittable entity, and must be presented entirely to the decompression function.
|
|
||||||
* LZ4_decompress_safe_continue() only accepts one block at a time.
|
|
||||||
* It's modeled after `LZ4_decompress_safe()` and behaves similarly.
|
|
||||||
*
|
|
||||||
* @LZ4_streamDecode : decompression state, tracking the position in memory of past data
|
|
||||||
* @compressedSize : exact complete size of one compressed block.
|
|
||||||
* @dstCapacity : size of destination buffer (which must be already allocated),
|
|
||||||
* must be an upper bound of decompressed size.
|
|
||||||
* @return : number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
|
||||||
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
|
||||||
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
|
||||||
*
|
|
||||||
* The last 64KB of previously decoded data *must* remain available and unmodified
|
|
||||||
* at the memory position where they were previously decoded.
|
|
||||||
* If less than 64KB of data has been decoded, all the data must be present.
|
|
||||||
*
|
|
||||||
* Special : if decompression side sets a ring buffer, it must respect one of the following conditions :
|
|
||||||
* - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize).
|
|
||||||
* maxBlockSize is the maximum size of any single block. It can have any value > 16 bytes.
|
|
||||||
* In which case, encoding and decoding buffers do not need to be synchronized.
|
|
||||||
* Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize.
|
|
||||||
* - Synchronized mode :
|
|
||||||
* Decompression buffer size is _exactly_ the same as compression buffer size,
|
|
||||||
* and follows exactly same update rule (block boundaries at same positions),
|
|
||||||
* and decoding function is provided with exact decompressed size of each block (exception for last block of the stream),
|
|
||||||
* _then_ decoding & encoding ring buffer can have any size, including small ones ( < 64 KB).
|
|
||||||
* - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes.
|
|
||||||
* In which case, encoding and decoding buffers do not need to be synchronized,
|
|
||||||
* and encoding ring buffer can have any size, including small ones ( < 64 KB).
|
|
||||||
*
|
|
||||||
* Whenever these conditions are not possible,
|
|
||||||
* save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
|
|
||||||
* then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int
|
|
||||||
LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode,
|
|
||||||
const char* src, char* dst,
|
|
||||||
int srcSize, int dstCapacity);
|
|
||||||
|
|
||||||
|
|
||||||
/*! LZ4_decompress_safe_usingDict() :
|
|
||||||
* Works the same as
|
|
||||||
* a combination of LZ4_setStreamDecode() followed by LZ4_decompress_safe_continue()
|
|
||||||
* However, it's stateless: it doesn't need any LZ4_streamDecode_t state.
|
|
||||||
* Dictionary is presumed stable : it must remain accessible and unmodified during decompression.
|
|
||||||
* Performance tip : Decompression speed can be substantially increased
|
|
||||||
* when dst == dictStart + dictSize.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int
|
|
||||||
LZ4_decompress_safe_usingDict(const char* src, char* dst,
|
|
||||||
int srcSize, int dstCapacity,
|
|
||||||
const char* dictStart, int dictSize);
|
|
||||||
|
|
||||||
/*! LZ4_decompress_safe_partial_usingDict() :
|
|
||||||
* Behaves the same as LZ4_decompress_safe_partial()
|
|
||||||
* with the added ability to specify a memory segment for past data.
|
|
||||||
* Performance tip : Decompression speed can be substantially increased
|
|
||||||
* when dst == dictStart + dictSize.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API int
|
|
||||||
LZ4_decompress_safe_partial_usingDict(const char* src, char* dst,
|
|
||||||
int compressedSize,
|
|
||||||
int targetOutputSize, int maxOutputSize,
|
|
||||||
const char* dictStart, int dictSize);
|
|
||||||
|
|
||||||
#endif /* LZ4_H_2983827168210 */
|
|
||||||
|
|
||||||
|
|
||||||
/*^*************************************
|
|
||||||
* !!!!!! STATIC LINKING ONLY !!!!!!
|
|
||||||
***************************************/
|
|
||||||
|
|
||||||
/*-****************************************************************************
|
|
||||||
* Experimental section
|
|
||||||
*
|
|
||||||
* Symbols declared in this section must be considered unstable. Their
|
|
||||||
* signatures or semantics may change, or they may be removed altogether in the
|
|
||||||
* future. They are therefore only safe to depend on when the caller is
|
|
||||||
* statically linked against the library.
|
|
||||||
*
|
|
||||||
* To protect against unsafe usage, not only are the declarations guarded,
|
|
||||||
* the definitions are hidden by default
|
|
||||||
* when building LZ4 as a shared/dynamic library.
|
|
||||||
*
|
|
||||||
* In order to access these declarations,
|
|
||||||
* define LZ4_STATIC_LINKING_ONLY in your application
|
|
||||||
* before including LZ4's headers.
|
|
||||||
*
|
|
||||||
* In order to make their implementations accessible dynamically, you must
|
|
||||||
* define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifdef LZ4_STATIC_LINKING_ONLY
|
|
||||||
|
|
||||||
#ifndef LZ4_STATIC_3504398509
|
|
||||||
#define LZ4_STATIC_3504398509
|
|
||||||
|
|
||||||
#ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
|
|
||||||
#define LZ4LIB_STATIC_API LZ4LIB_API
|
|
||||||
#else
|
|
||||||
#define LZ4LIB_STATIC_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*! LZ4_compress_fast_extState_fastReset() :
|
|
||||||
* A variant of LZ4_compress_fast_extState().
|
|
||||||
*
|
|
||||||
* Using this variant avoids an expensive initialization step.
|
|
||||||
* It is only safe to call if the state buffer is known to be correctly initialized already
|
|
||||||
* (see above comment on LZ4_resetStream_fast() for a definition of "correctly initialized").
|
|
||||||
* From a high level, the difference is that
|
|
||||||
* this function initializes the provided state with a call to something like LZ4_resetStream_fast()
|
|
||||||
* while LZ4_compress_fast_extState() starts with a call to LZ4_resetStream().
|
|
||||||
*/
|
|
||||||
LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
|
||||||
|
|
||||||
/*! LZ4_attach_dictionary() :
|
|
||||||
* This is an experimental API that allows
|
|
||||||
* efficient use of a static dictionary many times.
|
|
||||||
*
|
|
||||||
* Rather than re-loading the dictionary buffer into a working context before
|
|
||||||
* each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
|
|
||||||
* working LZ4_stream_t, this function introduces a no-copy setup mechanism,
|
|
||||||
* in which the working stream references the dictionary stream in-place.
|
|
||||||
*
|
|
||||||
* Several assumptions are made about the state of the dictionary stream.
|
|
||||||
* Currently, only streams which have been prepared by LZ4_loadDict() should
|
|
||||||
* be expected to work.
|
|
||||||
*
|
|
||||||
* Alternatively, the provided dictionaryStream may be NULL,
|
|
||||||
* in which case any existing dictionary stream is unset.
|
|
||||||
*
|
|
||||||
* If a dictionary is provided, it replaces any pre-existing stream history.
|
|
||||||
* The dictionary contents are the only history that can be referenced and
|
|
||||||
* logically immediately precede the data compressed in the first subsequent
|
|
||||||
* compression call.
|
|
||||||
*
|
|
||||||
* The dictionary will only remain attached to the working stream through the
|
|
||||||
* first compression call, at the end of which it is cleared. The dictionary
|
|
||||||
* stream (and source buffer) must remain in-place / accessible / unchanged
|
|
||||||
* through the completion of the first compression call on the stream.
|
|
||||||
*/
|
|
||||||
LZ4LIB_STATIC_API void
|
|
||||||
LZ4_attach_dictionary(LZ4_stream_t* workingStream,
|
|
||||||
const LZ4_stream_t* dictionaryStream);
|
|
||||||
|
|
||||||
|
|
||||||
/*! In-place compression and decompression
|
|
||||||
*
|
|
||||||
* It's possible to have input and output sharing the same buffer,
|
|
||||||
* for highly constrained memory environments.
|
|
||||||
* In both cases, it requires input to lay at the end of the buffer,
|
|
||||||
* and decompression to start at beginning of the buffer.
|
|
||||||
* Buffer size must feature some margin, hence be larger than final size.
|
|
||||||
*
|
|
||||||
* |<------------------------buffer--------------------------------->|
|
|
||||||
* |<-----------compressed data--------->|
|
|
||||||
* |<-----------decompressed size------------------>|
|
|
||||||
* |<----margin---->|
|
|
||||||
*
|
|
||||||
* This technique is more useful for decompression,
|
|
||||||
* since decompressed size is typically larger,
|
|
||||||
* and margin is short.
|
|
||||||
*
|
|
||||||
* In-place decompression will work inside any buffer
|
|
||||||
* which size is >= LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize).
|
|
||||||
* This presumes that decompressedSize > compressedSize.
|
|
||||||
* Otherwise, it means compression actually expanded data,
|
|
||||||
* and it would be more efficient to store such data with a flag indicating it's not compressed.
|
|
||||||
* This can happen when data is not compressible (already compressed, or encrypted).
|
|
||||||
*
|
|
||||||
* For in-place compression, margin is larger, as it must be able to cope with both
|
|
||||||
* history preservation, requiring input data to remain unmodified up to LZ4_DISTANCE_MAX,
|
|
||||||
* and data expansion, which can happen when input is not compressible.
|
|
||||||
* As a consequence, buffer size requirements are much higher,
|
|
||||||
* and memory savings offered by in-place compression are more limited.
|
|
||||||
*
|
|
||||||
* There are ways to limit this cost for compression :
|
|
||||||
* - Reduce history size, by modifying LZ4_DISTANCE_MAX.
|
|
||||||
* Note that it is a compile-time constant, so all compressions will apply this limit.
|
|
||||||
* Lower values will reduce compression ratio, except when input_size < LZ4_DISTANCE_MAX,
|
|
||||||
* so it's a reasonable trick when inputs are known to be small.
|
|
||||||
* - Require the compressor to deliver a "maximum compressed size".
|
|
||||||
* This is the `dstCapacity` parameter in `LZ4_compress*()`.
|
|
||||||
* When this size is < LZ4_COMPRESSBOUND(inputSize), then compression can fail,
|
|
||||||
* in which case, the return code will be 0 (zero).
|
|
||||||
* The caller must be ready for these cases to happen,
|
|
||||||
* and typically design a backup scheme to send data uncompressed.
|
|
||||||
* The combination of both techniques can significantly reduce
|
|
||||||
* the amount of margin required for in-place compression.
|
|
||||||
*
|
|
||||||
* In-place compression can work in any buffer
|
|
||||||
* which size is >= (maxCompressedSize)
|
|
||||||
* with maxCompressedSize == LZ4_COMPRESSBOUND(srcSize) for guaranteed compression success.
|
|
||||||
* LZ4_COMPRESS_INPLACE_BUFFER_SIZE() depends on both maxCompressedSize and LZ4_DISTANCE_MAX,
|
|
||||||
* so it's possible to reduce memory requirements by playing with them.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
|
|
||||||
#define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize)) /**< note: presumes that compressedSize < decompressedSize. note2: margin is overestimated a bit, since it could use compressedSize instead */
|
|
||||||
|
|
||||||
#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
|
|
||||||
# define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
|
|
||||||
#define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN) /**< maxCompressedSize is generally LZ4_COMPRESSBOUND(inputSize), but can be set to any lower value, with the risk that compression can fail (return code 0(zero)) */
|
|
||||||
|
|
||||||
#endif /* LZ4_STATIC_3504398509 */
|
|
||||||
#endif /* LZ4_STATIC_LINKING_ONLY */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LZ4_H_98237428734687
|
|
||||||
#define LZ4_H_98237428734687
|
|
||||||
|
|
||||||
/*-************************************************************
|
|
||||||
* Private Definitions
|
|
||||||
**************************************************************
|
|
||||||
* Do not use these definitions directly.
|
|
||||||
* They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
|
|
||||||
* Accessing members will expose user code to API and/or ABI break in future versions of the library.
|
|
||||||
**************************************************************/
|
|
||||||
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
|
|
||||||
#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
|
|
||||||
#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
|
|
||||||
|
|
||||||
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
|
||||||
# include <stdint.h>
|
|
||||||
typedef int8_t LZ4_i8;
|
|
||||||
typedef uint8_t LZ4_byte;
|
|
||||||
typedef uint16_t LZ4_u16;
|
|
||||||
typedef uint32_t LZ4_u32;
|
|
||||||
#else
|
|
||||||
typedef signed char LZ4_i8;
|
|
||||||
typedef unsigned char LZ4_byte;
|
|
||||||
typedef unsigned short LZ4_u16;
|
|
||||||
typedef unsigned int LZ4_u32;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*! LZ4_stream_t :
|
|
||||||
* Never ever use below internal definitions directly !
|
|
||||||
* These definitions are not API/ABI safe, and may change in future versions.
|
|
||||||
* If you need static allocation, declare or allocate an LZ4_stream_t object.
|
|
||||||
**/
|
|
||||||
|
|
||||||
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
|
|
||||||
struct LZ4_stream_t_internal {
|
|
||||||
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32];
|
|
||||||
const LZ4_byte* dictionary;
|
|
||||||
const LZ4_stream_t_internal* dictCtx;
|
|
||||||
LZ4_u32 currentOffset;
|
|
||||||
LZ4_u32 tableType;
|
|
||||||
LZ4_u32 dictSize;
|
|
||||||
/* Implicit padding to ensure structure is aligned */
|
|
||||||
};
|
|
||||||
|
|
||||||
#define LZ4_STREAM_MINSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) /* static size, for inter-version compatibility */
|
|
||||||
union LZ4_stream_u {
|
|
||||||
char minStateSize[LZ4_STREAM_MINSIZE];
|
|
||||||
LZ4_stream_t_internal internal_donotuse;
|
|
||||||
}; /* previously typedef'd to LZ4_stream_t */
|
|
||||||
|
|
||||||
|
|
||||||
/*! LZ4_initStream() : v1.9.0+
|
|
||||||
* An LZ4_stream_t structure must be initialized at least once.
|
|
||||||
* This is automatically done when invoking LZ4_createStream(),
|
|
||||||
* but it's not when the structure is simply declared on stack (for example).
|
|
||||||
*
|
|
||||||
* Use LZ4_initStream() to properly initialize a newly declared LZ4_stream_t.
|
|
||||||
* It can also initialize any arbitrary buffer of sufficient size,
|
|
||||||
* and will @return a pointer of proper type upon initialization.
|
|
||||||
*
|
|
||||||
* Note : initialization fails if size and alignment conditions are not respected.
|
|
||||||
* In which case, the function will @return NULL.
|
|
||||||
* Note2: An LZ4_stream_t structure guarantees correct alignment and size.
|
|
||||||
* Note3: Before v1.9.0, use LZ4_resetStream() instead
|
|
||||||
**/
|
|
||||||
LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
|
|
||||||
|
|
||||||
|
|
||||||
/*! LZ4_streamDecode_t :
|
|
||||||
* Never ever use below internal definitions directly !
|
|
||||||
* These definitions are not API/ABI safe, and may change in future versions.
|
|
||||||
* If you need static allocation, declare or allocate an LZ4_streamDecode_t object.
|
|
||||||
**/
|
|
||||||
typedef struct {
|
|
||||||
const LZ4_byte* externalDict;
|
|
||||||
const LZ4_byte* prefixEnd;
|
|
||||||
size_t extDictSize;
|
|
||||||
size_t prefixSize;
|
|
||||||
} LZ4_streamDecode_t_internal;
|
|
||||||
|
|
||||||
#define LZ4_STREAMDECODE_MINSIZE 32
|
|
||||||
union LZ4_streamDecode_u {
|
|
||||||
char minStateSize[LZ4_STREAMDECODE_MINSIZE];
|
|
||||||
LZ4_streamDecode_t_internal internal_donotuse;
|
|
||||||
} ; /* previously typedef'd to LZ4_streamDecode_t */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-************************************
|
|
||||||
* Obsolete Functions
|
|
||||||
**************************************/
|
|
||||||
|
|
||||||
/*! Deprecation warnings
|
|
||||||
*
|
|
||||||
* Deprecated functions make the compiler generate a warning when invoked.
|
|
||||||
* This is meant to invite users to update their source code.
|
|
||||||
* Should deprecation warnings be a problem, it is generally possible to disable them,
|
|
||||||
* typically with -Wno-deprecated-declarations for gcc
|
|
||||||
* or _CRT_SECURE_NO_WARNINGS in Visual.
|
|
||||||
*
|
|
||||||
* Another method is to define LZ4_DISABLE_DEPRECATE_WARNINGS
|
|
||||||
* before including the header file.
|
|
||||||
*/
|
|
||||||
#ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
|
|
||||||
# define LZ4_DEPRECATED(message) /* disable deprecation warnings */
|
|
||||||
#else
|
|
||||||
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
|
||||||
# define LZ4_DEPRECATED(message) [[deprecated(message)]]
|
|
||||||
# elif defined(_MSC_VER)
|
|
||||||
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
|
|
||||||
# elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 45))
|
|
||||||
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 31)
|
|
||||||
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
|
|
||||||
# else
|
|
||||||
# pragma message("WARNING: LZ4_DEPRECATED needs custom implementation for this compiler")
|
|
||||||
# define LZ4_DEPRECATED(message) /* disabled */
|
|
||||||
# endif
|
|
||||||
#endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
|
|
||||||
|
|
||||||
/*! Obsolete compression functions (since v1.7.3) */
|
|
||||||
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress (const char* src, char* dest, int srcSize);
|
|
||||||
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress_limitedOutput (const char* src, char* dest, int srcSize, int maxOutputSize);
|
|
||||||
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
|
|
||||||
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
|
||||||
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
|
|
||||||
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
|
||||||
|
|
||||||
/*! Obsolete decompression functions (since v1.8.0) */
|
|
||||||
LZ4_DEPRECATED("use LZ4_decompress_fast() instead") LZ4LIB_API int LZ4_uncompress (const char* source, char* dest, int outputSize);
|
|
||||||
LZ4_DEPRECATED("use LZ4_decompress_safe() instead") LZ4LIB_API int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
|
|
||||||
|
|
||||||
/* Obsolete streaming functions (since v1.7.0)
|
|
||||||
* degraded functionality; do not use!
|
|
||||||
*
|
|
||||||
* In order to perform streaming compression, these functions depended on data
|
|
||||||
* that is no longer tracked in the state. They have been preserved as well as
|
|
||||||
* possible: using them will still produce a correct output. However, they don't
|
|
||||||
* actually retain any history between compression calls. The compression ratio
|
|
||||||
* achieved will therefore be no better than compressing each chunk
|
|
||||||
* independently.
|
|
||||||
*/
|
|
||||||
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API void* LZ4_create (char* inputBuffer);
|
|
||||||
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API int LZ4_sizeofStreamState(void);
|
|
||||||
LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStreamState(void* state, char* inputBuffer);
|
|
||||||
LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state);
|
|
||||||
|
|
||||||
/*! Obsolete streaming decoding functions (since v1.7.0) */
|
|
||||||
LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
|
|
||||||
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
|
|
||||||
|
|
||||||
/*! Obsolete LZ4_decompress_fast variants (since v1.9.0) :
|
|
||||||
* These functions used to be faster than LZ4_decompress_safe(),
|
|
||||||
* but this is no longer the case. They are now slower.
|
|
||||||
* This is because LZ4_decompress_fast() doesn't know the input size,
|
|
||||||
* and therefore must progress more cautiously into the input buffer to not read beyond the end of block.
|
|
||||||
* On top of that `LZ4_decompress_fast()` is not protected vs malformed or malicious inputs, making it a security liability.
|
|
||||||
* As a consequence, LZ4_decompress_fast() is strongly discouraged, and deprecated.
|
|
||||||
*
|
|
||||||
* The last remaining LZ4_decompress_fast() specificity is that
|
|
||||||
* it can decompress a block without knowing its compressed size.
|
|
||||||
* Such functionality can be achieved in a more secure manner
|
|
||||||
* by employing LZ4_decompress_safe_partial().
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* originalSize : is the uncompressed size to regenerate.
|
|
||||||
* `dst` must be already allocated, its size must be >= 'originalSize' bytes.
|
|
||||||
* @return : number of bytes read from source buffer (== compressed size).
|
|
||||||
* The function expects to finish at block's end exactly.
|
|
||||||
* If the source stream is detected malformed, the function stops decoding and returns a negative result.
|
|
||||||
* note : LZ4_decompress_fast*() requires originalSize. Thanks to this information, it never writes past the output buffer.
|
|
||||||
* However, since it doesn't know its 'src' size, it may read an unknown amount of input, past input buffer bounds.
|
|
||||||
* Also, since match offsets are not validated, match reads from 'src' may underflow too.
|
|
||||||
* These issues never happen if input (compressed) data is correct.
|
|
||||||
* But they may happen if input data is invalid (error or intentional tampering).
|
|
||||||
* As a consequence, use these functions in trusted environments with trusted data **only**.
|
|
||||||
*/
|
|
||||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
|
|
||||||
LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
|
|
||||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
|
|
||||||
LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
|
|
||||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
|
|
||||||
LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
|
|
||||||
|
|
||||||
/*! LZ4_resetStream() :
|
|
||||||
* An LZ4_stream_t structure must be initialized at least once.
|
|
||||||
* This is done with LZ4_initStream(), or LZ4_resetStream().
|
|
||||||
* Consider switching to LZ4_initStream(),
|
|
||||||
* invoking LZ4_resetStream() will trigger deprecation warnings in the future.
|
|
||||||
*/
|
|
||||||
LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* LZ4_H_98237428734687 */
|
|
||||||
|
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
|
||||||
}
|
|
||||||
#endif
|
|
1274
src/manager.cc
1274
src/manager.cc
File diff suppressed because it is too large
Load Diff
8413
src/mongoose.c
8413
src/mongoose.c
File diff suppressed because it is too large
Load Diff
1729
src/mongoose.h
1729
src/mongoose.h
File diff suppressed because it is too large
Load Diff
27
src/pch.h
27
src/pch.h
@ -1,27 +0,0 @@
|
|||||||
#ifndef PCH_H
|
|
||||||
#define PCH_H
|
|
||||||
|
|
||||||
|
|
||||||
#define GLOG_NO_ABBREVIATED_SEVERITIES
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <strstream>
|
|
||||||
#include <string>
|
|
||||||
#include <optional>
|
|
||||||
#include <sstream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <time.h>
|
|
||||||
#include <WinSock2.h>
|
|
||||||
#include "Windows.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
|
||||||
#include "spdlog/sinks/daily_file_sink.h"
|
|
||||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
|
||||||
#include <detours/detours.h>
|
|
||||||
#include <heapapi.h>
|
|
||||||
|
|
||||||
#endif // PCH_H
|
|
||||||
|
|
2994
src/tinyxml2.cpp
2994
src/tinyxml2.cpp
File diff suppressed because it is too large
Load Diff
2380
src/tinyxml2.h
2380
src/tinyxml2.h
File diff suppressed because it is too large
Load Diff
460
src/utils.cc
460
src/utils.cc
@ -1,460 +0,0 @@
|
|||||||
#include "pch.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <winternl.h>
|
|
||||||
#include <Psapi.h>
|
|
||||||
#define BUFSIZE 1024
|
|
||||||
#define JPEG0 0xFF
|
|
||||||
#define JPEG1 0xD8
|
|
||||||
#define JPEG2 0xFF
|
|
||||||
#define PNG0 0x89
|
|
||||||
#define PNG1 0x50
|
|
||||||
#define PNG2 0x4E
|
|
||||||
#define BMP0 0x42
|
|
||||||
#define BMP1 0x4D
|
|
||||||
#define GIF0 0x47
|
|
||||||
#define GIF1 0x49
|
|
||||||
#define GIF2 0x46
|
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
std::wstring Utils::UTF8ToWstring(const std::string &str) {
|
|
||||||
return Utils::AnsiToWstring(str, CP_UTF8);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::WstringToUTF8(const std::wstring &str) {
|
|
||||||
return Utils::WstringToAnsi(str, CP_UTF8);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring Utils::AnsiToWstring(const std::string &input, INT64 locale) {
|
|
||||||
int wchar_len = MultiByteToWideChar(locale, 0, input.c_str(), -1, NULL, 0);
|
|
||||||
if (wchar_len > 0) {
|
|
||||||
std::vector<wchar_t> temp(wchar_len);
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, &temp[0], wchar_len);
|
|
||||||
return std::wstring(&temp[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::wstring();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::WstringToAnsi(const std::wstring &input, INT64 locale) {
|
|
||||||
int char_len = WideCharToMultiByte(locale, 0, input.c_str(), -1, 0, 0, 0, 0);
|
|
||||||
if (char_len > 0) {
|
|
||||||
std::vector<char> temp(char_len);
|
|
||||||
WideCharToMultiByte(locale, 0, input.c_str(), -1, &temp[0], char_len, 0, 0);
|
|
||||||
return std::string(&temp[0]);
|
|
||||||
}
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
UINT64 Utils::GetWeChatWinBase() {
|
|
||||||
return (UINT64)GetModuleHandleA("WeChatWin.dll");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::CreateConsole() {
|
|
||||||
if (AllocConsole()) {
|
|
||||||
AttachConsole(GetCurrentProcessId());
|
|
||||||
FILE *retStream;
|
|
||||||
freopen_s(&retStream, "CONOUT$", "w", stdout);
|
|
||||||
if (!retStream) throw std::runtime_error("Stdout redirection failed.");
|
|
||||||
freopen_s(&retStream, "CONOUT$", "w", stderr);
|
|
||||||
if (!retStream) throw std::runtime_error("Stderr redirection failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::CloseConsole() {
|
|
||||||
fclose(stdin);
|
|
||||||
fclose(stdout);
|
|
||||||
fclose(stderr);
|
|
||||||
FreeConsole();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::EncodeHexString(const std::string &str) {
|
|
||||||
const std::string hex_table = "0123456789abcdef";
|
|
||||||
std::string sb;
|
|
||||||
for (int i = 0; i < str.length(); i++) {
|
|
||||||
sb += hex_table.at((str[i] & 0xf0) >> 4);
|
|
||||||
sb += hex_table.at((str[i] & 0x0f) >> 0);
|
|
||||||
}
|
|
||||||
return sb;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::Hex2String(const std::string &hex_str) {
|
|
||||||
std::string ret;
|
|
||||||
const std::string hex_table = "0123456789abcdef";
|
|
||||||
for (int i = 0; i < hex_str.length(); i += 2) {
|
|
||||||
ret += BYTE(hex_table.find(hex_str.at(i)) << 4 |
|
|
||||||
hex_table.find(hex_str.at(i + 1)));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::Bytes2Hex(const BYTE *bytes, const int length) {
|
|
||||||
if (bytes == NULL) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
std::string buff;
|
|
||||||
const int len = length;
|
|
||||||
for (int j = 0; j < len; j++) {
|
|
||||||
int high = bytes[j] / 16, low = bytes[j] % 16;
|
|
||||||
buff += (high < 10) ? ('0' + high) : ('a' + high - 10);
|
|
||||||
buff += (low < 10) ? ('0' + low) : ('a' + low - 10);
|
|
||||||
}
|
|
||||||
return buff;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::Hex2Bytes(const std::string &hex, BYTE *bytes) {
|
|
||||||
int byte_len = hex.length() / 2;
|
|
||||||
std::string str;
|
|
||||||
unsigned int n;
|
|
||||||
for (int i = 0; i < byte_len; i++) {
|
|
||||||
str = hex.substr(i * 2, 2);
|
|
||||||
sscanf_s(str.c_str(), "%x", &n);
|
|
||||||
bytes[i] = n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::IsDigit(std::string str) {
|
|
||||||
if (str.length() == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (auto it : str) {
|
|
||||||
if (it < '0' || it > '9') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::FindOrCreateDirectoryW(const wchar_t *path) {
|
|
||||||
WIN32_FIND_DATAW fd;
|
|
||||||
HANDLE hFind = ::FindFirstFileW(path, &fd);
|
|
||||||
if (hFind != INVALID_HANDLE_VALUE &&
|
|
||||||
(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
||||||
FindClose(hFind);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!::CreateDirectoryW(path, NULL)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::HookAnyAddress(DWORD hook_addr, LPVOID jmp_addr, char *origin) {
|
|
||||||
BYTE jmp_code[5] = {0};
|
|
||||||
jmp_code[0] = 0xE9;
|
|
||||||
*(DWORD *)&jmp_code[1] = (DWORD)jmp_addr - hook_addr - 5;
|
|
||||||
DWORD old_protext = 0;
|
|
||||||
VirtualProtect((LPVOID)hook_addr, 5, PAGE_EXECUTE_READWRITE, &old_protext);
|
|
||||||
ReadProcessMemory(GetCurrentProcess(), (LPVOID)hook_addr, origin, 5, 0);
|
|
||||||
memcpy((void *)hook_addr, jmp_code, 5);
|
|
||||||
VirtualProtect((LPVOID)hook_addr, 5, old_protext, &old_protext);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::UnHookAnyAddress(DWORD hook_addr, char *origin) {
|
|
||||||
DWORD old_protext = 0;
|
|
||||||
VirtualProtect((LPVOID)hook_addr, 5, PAGE_EXECUTE_READWRITE, &old_protext);
|
|
||||||
WriteProcessMemory(GetCurrentProcess(), (LPVOID)hook_addr, origin, 5, 0);
|
|
||||||
VirtualProtect((LPVOID)hook_addr, 5, old_protext, &old_protext);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring Utils::GetTimeW(long long timestamp) {
|
|
||||||
wchar_t *wstr = new wchar_t[20];
|
|
||||||
memset(wstr, 0, 20 * 2);
|
|
||||||
tm tm_out;
|
|
||||||
localtime_s(&tm_out, ×tamp);
|
|
||||||
swprintf_s(wstr, 20, L"%04d-%02d-%02d %02d:%02d:%02d", 1900 + tm_out.tm_year,
|
|
||||||
tm_out.tm_mon + 1, tm_out.tm_mday, tm_out.tm_hour, tm_out.tm_min,
|
|
||||||
tm_out.tm_sec);
|
|
||||||
std::wstring str_time(wstr);
|
|
||||||
delete[] wstr;
|
|
||||||
return str_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::WCharToUTF8(wchar_t *wstr) {
|
|
||||||
int c_size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, FALSE);
|
|
||||||
if (c_size > 0) {
|
|
||||||
char *buffer = new char[c_size];
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, buffer, c_size, NULL, FALSE);
|
|
||||||
std::string str(buffer);
|
|
||||||
delete[] buffer;
|
|
||||||
buffer = NULL;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::IsTextUtf8(const char *str,INT64 length) {
|
|
||||||
char endian = 1;
|
|
||||||
bool littlen_endian = (*(char *)&endian == 1);
|
|
||||||
|
|
||||||
size_t i;
|
|
||||||
int bytes_num;
|
|
||||||
unsigned char chr;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
bytes_num = 0;
|
|
||||||
while (i < length) {
|
|
||||||
if (littlen_endian) {
|
|
||||||
chr = *(str + i);
|
|
||||||
} else { // Big Endian
|
|
||||||
chr = (*(str + i) << 8) | *(str + i + 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytes_num == 0) {
|
|
||||||
if ((chr & 0x80) != 0) {
|
|
||||||
while ((chr & 0x80) != 0) {
|
|
||||||
chr <<= 1;
|
|
||||||
bytes_num++;
|
|
||||||
}
|
|
||||||
if ((bytes_num < 2) || (bytes_num > 6)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bytes_num--;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((chr & 0xC0) != 0x80) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bytes_num--;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (bytes_num == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::Hide(HMODULE module) {
|
|
||||||
PPEB peb = (PPEB)__readgsqword(0x60);
|
|
||||||
PPEB_LDR_DATA ldr = peb->Ldr;
|
|
||||||
|
|
||||||
void *cur_ptr = *((void **)((unsigned char *)ldr + 0x18));
|
|
||||||
void *next_ptr = cur_ptr;
|
|
||||||
do {
|
|
||||||
void *next = *((void **)((unsigned char *)next_ptr));
|
|
||||||
void *last = *((void **)((unsigned char *)next_ptr + 0x8));
|
|
||||||
void *base_addr = *((void **)((unsigned char *)next_ptr + 0x30));
|
|
||||||
if (base_addr == module) {
|
|
||||||
*((void **)((unsigned char *)last)) = next;
|
|
||||||
*((void **)((unsigned char *)next + 0x8)) = last;
|
|
||||||
cur_ptr = next;
|
|
||||||
}
|
|
||||||
next_ptr = *((void **)next_ptr);
|
|
||||||
} while (cur_ptr != next_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::ReadSKBuiltinString(INT64 addr) {
|
|
||||||
INT64 inner_string = *(INT64 *)(addr + 0x8);
|
|
||||||
if (inner_string == 0) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
return ReadWeChatStr(inner_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::ReadSKBuiltinBuffer(INT64 addr) {
|
|
||||||
INT64 len = *(INT64 *)(addr + 0x10);
|
|
||||||
if (len == 0) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
INT64 inner_string = *(INT64 *)(addr + 0x8);
|
|
||||||
if (inner_string == 0) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
return ReadWeChatStr(inner_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::ReadWeChatStr(INT64 addr) {
|
|
||||||
INT64 len = *(INT64 *)(addr + 0x10);
|
|
||||||
if (len == 0) {
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
INT64 max_len = *(INT64 *)(addr + 0x18);
|
|
||||||
if ((max_len | 0xF) == 0xF) {
|
|
||||||
return std::string((char *)addr, len);
|
|
||||||
}
|
|
||||||
char *char_from_user = *(char **)(addr);
|
|
||||||
return std::string(char_from_user, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Utils::ImageXor(std::string buf){
|
|
||||||
const char *origin = buf.c_str();
|
|
||||||
short key = 0;
|
|
||||||
if ((*origin ^ JPEG0) == (*(origin + 1) ^ JPEG1)) {
|
|
||||||
key = *origin ^ JPEG0;
|
|
||||||
} else if ((*origin ^ PNG1) == (*(origin + 1) ^ PNG2)) {
|
|
||||||
key = *origin ^ PNG1;
|
|
||||||
} else if ((*origin ^ GIF0) == (*(origin + 1) ^ GIF1)) {
|
|
||||||
key = *origin ^ GIF0;
|
|
||||||
} else if ((*origin ^ BMP0) == (*(origin + 1) ^ BMP1)) {
|
|
||||||
key = *origin ^ BMP0;
|
|
||||||
} else {
|
|
||||||
key = -1;
|
|
||||||
}
|
|
||||||
if (key > 0) {
|
|
||||||
char *img_buf = new char[buf.size()];
|
|
||||||
for (unsigned int i = 0; i < buf.size(); i++) {
|
|
||||||
img_buf[i] = *(origin + i) ^ key;
|
|
||||||
}
|
|
||||||
std::string str(img_buf);
|
|
||||||
delete[] img_buf;
|
|
||||||
img_buf = NULL;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring Utils::ReadWstring(INT64 addr){
|
|
||||||
DWORD len = *(DWORD *)(addr + 0x8);
|
|
||||||
if (len == 0) {
|
|
||||||
return std::wstring();
|
|
||||||
}
|
|
||||||
wchar_t * str = *(wchar_t **)(addr);
|
|
||||||
if (str == NULL) {
|
|
||||||
return std::wstring();
|
|
||||||
}
|
|
||||||
return std::wstring(str, len);
|
|
||||||
|
|
||||||
}
|
|
||||||
std::string Utils::ReadWstringThenConvert(INT64 addr){
|
|
||||||
std::wstring wstr = ReadWstring(addr);
|
|
||||||
return WstringToUTF8(wstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
INT64 Utils::DecodeImage(const wchar_t* file_path,const wchar_t* save_dir){
|
|
||||||
std::wstring save_path(save_dir);
|
|
||||||
std::wstring orign_file_path(file_path);
|
|
||||||
if (!Utils::FindOrCreateDirectoryW(save_path.c_str())) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
INT64 pos_begin = orign_file_path.find_last_of(L"\\") + 1;
|
|
||||||
INT64 pos_end = orign_file_path.find_last_of(L".");
|
|
||||||
std::wstring file_name =
|
|
||||||
orign_file_path.substr(pos_begin, pos_end - pos_begin);
|
|
||||||
HANDLE h_origin_file =
|
|
||||||
CreateFileW(file_path, GENERIC_READ, 0, NULL, OPEN_EXISTING,
|
|
||||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
char buffer[BUFSIZE] = {0};
|
|
||||||
DWORD bytes_read = 0;
|
|
||||||
DWORD bytes_write = 0;
|
|
||||||
unsigned char magic_head[4] = {0};
|
|
||||||
std::wstring suffix;
|
|
||||||
short key = 0;
|
|
||||||
if (ReadFile(h_origin_file, buffer, BUFSIZE, &bytes_read, NULL)) {
|
|
||||||
memcpy(magic_head, buffer, 3);
|
|
||||||
} else {
|
|
||||||
CloseHandle(h_origin_file);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if ((magic_head[0] ^ JPEG0) == (magic_head[1] ^ JPEG1)) {
|
|
||||||
key = magic_head[0] ^ JPEG0;
|
|
||||||
suffix = L".jpg";
|
|
||||||
} else if ((magic_head[0] ^ PNG1) == (magic_head[1] ^ PNG2)) {
|
|
||||||
key = magic_head[0] ^ PNG1;
|
|
||||||
suffix = L".png";
|
|
||||||
} else if ((magic_head[0] ^ GIF0) == (magic_head[1] ^ GIF1)) {
|
|
||||||
key = magic_head[0] ^ GIF0;
|
|
||||||
suffix = L".gif";
|
|
||||||
} else if ((magic_head[0] ^ BMP0) == (magic_head[1] ^ BMP1)) {
|
|
||||||
key = magic_head[0] ^ BMP0;
|
|
||||||
suffix = L".bmp";
|
|
||||||
} else {
|
|
||||||
key = -1;
|
|
||||||
suffix = L".dat";
|
|
||||||
}
|
|
||||||
std::wstring save_img_path = save_path + L"\\" + file_name + suffix;
|
|
||||||
HANDLE save_img = CreateFileW(save_img_path.c_str(), GENERIC_ALL, 0, NULL,
|
|
||||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
if (save_img == INVALID_HANDLE_VALUE) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (key > 0) {
|
|
||||||
for (unsigned int i = 0; i < bytes_read; i++) {
|
|
||||||
buffer[i] ^= key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!WriteFile(save_img, (LPCVOID)buffer, bytes_read, &bytes_write, 0)) {
|
|
||||||
CloseHandle(h_origin_file);
|
|
||||||
CloseHandle(save_img);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (ReadFile(h_origin_file, buffer, BUFSIZE, &bytes_read, NULL)) {
|
|
||||||
if (key > 0) {
|
|
||||||
for (unsigned int i = 0; i < bytes_read; i++) {
|
|
||||||
buffer[i] ^= key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!WriteFile(save_img, (LPCVOID)buffer, bytes_read, &bytes_write, 0)) {
|
|
||||||
CloseHandle(h_origin_file);
|
|
||||||
CloseHandle(save_img);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (bytes_read == BUFSIZE);
|
|
||||||
CloseHandle(h_origin_file);
|
|
||||||
CloseHandle(save_img);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<INT64> Utils::QWordScan(INT64 value, int align,
|
|
||||||
const wchar_t *module) {
|
|
||||||
MODULEINFO module_info;
|
|
||||||
std::vector<INT64> result;
|
|
||||||
if (GetModuleInformation(GetCurrentProcess(), GetModuleHandleW(module),
|
|
||||||
&module_info, sizeof(module_info))) {
|
|
||||||
auto start = static_cast<const char *>(module_info.lpBaseOfDll);
|
|
||||||
const auto end = start + module_info.SizeOfImage - 0x8;
|
|
||||||
|
|
||||||
auto current_addr = start;
|
|
||||||
while (current_addr < end) {
|
|
||||||
if (*(INT64*)current_addr == value) {
|
|
||||||
result.push_back(reinterpret_cast<INT64>(current_addr));
|
|
||||||
}
|
|
||||||
start += align;
|
|
||||||
current_addr = start;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<INT64> Utils::QWordScan(INT64 value, INT64 start,int align) {
|
|
||||||
SYSTEM_INFO sys_info;
|
|
||||||
GetSystemInfo(&sys_info);
|
|
||||||
std::vector<INT64> result;
|
|
||||||
INT64 min_addr =
|
|
||||||
reinterpret_cast<INT64>(sys_info.lpMinimumApplicationAddress);
|
|
||||||
INT64 max_addr =
|
|
||||||
reinterpret_cast<INT64>(sys_info.lpMaximumApplicationAddress);
|
|
||||||
const INT64 page_size = sys_info.dwPageSize;
|
|
||||||
min_addr = min_addr > start ? min_addr : start;
|
|
||||||
|
|
||||||
auto current_addr = min_addr;
|
|
||||||
MEMORY_BASIC_INFORMATION mem_info = {};
|
|
||||||
HANDLE handle = GetCurrentProcess();
|
|
||||||
while (current_addr < max_addr) {
|
|
||||||
VirtualQueryEx(handle, reinterpret_cast<LPVOID>(current_addr), &mem_info,
|
|
||||||
sizeof(MEMORY_BASIC_INFORMATION));
|
|
||||||
|
|
||||||
if ((INT64)mem_info.RegionSize <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
INT64 region_size = mem_info.RegionSize;
|
|
||||||
if ((mem_info.State & MEM_COMMIT) == MEM_COMMIT &&
|
|
||||||
(mem_info.Protect & PAGE_GUARD) != PAGE_GUARD &&
|
|
||||||
(mem_info.Protect & PAGE_NOACCESS) != PAGE_NOACCESS) {
|
|
||||||
for (INT64 i = 0; i < region_size; i += align) {
|
|
||||||
if (value == *(INT64 *)current_addr) {
|
|
||||||
result.push_back(current_addr);
|
|
||||||
}
|
|
||||||
current_addr += align;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
current_addr += region_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} // namespace wxhelper
|
|
100
src/utils.h
100
src/utils.h
@ -1,100 +0,0 @@
|
|||||||
#ifndef WXHELPER_UTILS_H_
|
|
||||||
#define WXHELPER_UTILS_H_
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#define STRING2INT(str) (Utils::IsDigit(str) ? stoi(str) : 0)
|
|
||||||
#define WS2LPWS(wstr) (LPWSTR) wstr.c_str()
|
|
||||||
|
|
||||||
|
|
||||||
namespace wxhelper {
|
|
||||||
|
|
||||||
class Utils {
|
|
||||||
public:
|
|
||||||
static std::wstring UTF8ToWstring(const std::string &str);
|
|
||||||
|
|
||||||
static std::string WstringToUTF8(const std::wstring &str);
|
|
||||||
|
|
||||||
static std::wstring AnsiToWstring(const std::string &input,
|
|
||||||
INT64 locale = CP_ACP);
|
|
||||||
|
|
||||||
static std::string WstringToAnsi(const std::wstring &input,
|
|
||||||
INT64 locale = CP_ACP);
|
|
||||||
|
|
||||||
static UINT64 GetWeChatWinBase();
|
|
||||||
|
|
||||||
static bool CreateConsole();
|
|
||||||
|
|
||||||
static void CloseConsole();
|
|
||||||
|
|
||||||
static std::string EncodeHexString(const std::string &str);
|
|
||||||
|
|
||||||
static std::string Hex2String(const std::string &hex_str);
|
|
||||||
|
|
||||||
static std::string Bytes2Hex(const BYTE *bytes, const int length);
|
|
||||||
|
|
||||||
static void Hex2Bytes(const std::string &hex, BYTE *bytes);
|
|
||||||
|
|
||||||
static bool IsDigit(std::string str);
|
|
||||||
|
|
||||||
static bool FindOrCreateDirectoryW(const wchar_t *path);
|
|
||||||
|
|
||||||
static void HookAnyAddress(DWORD hook_addr, LPVOID jmp_addr, char *origin);
|
|
||||||
static void UnHookAnyAddress(DWORD hook_addr, char *origin);
|
|
||||||
static std::wstring GetTimeW(long long timestamp);
|
|
||||||
|
|
||||||
static std::string WCharToUTF8(wchar_t *wstr);
|
|
||||||
|
|
||||||
static bool IsTextUtf8(const char *str, INT64 length);
|
|
||||||
|
|
||||||
static void Hide(HMODULE module);
|
|
||||||
|
|
||||||
static std::string ReadSKBuiltinString(INT64 addr);
|
|
||||||
static std::string ReadSKBuiltinBuffer(INT64 addr);
|
|
||||||
static std::string ReadWeChatStr(INT64 addr);
|
|
||||||
|
|
||||||
static std::string ImageXor(std::string buf);
|
|
||||||
static std::wstring ReadWstring(INT64 addr);
|
|
||||||
static std::string ReadWstringThenConvert(INT64 addr);
|
|
||||||
|
|
||||||
static INT64 DecodeImage(const wchar_t* file_path,const wchar_t* save_dir);
|
|
||||||
|
|
||||||
static std::vector<INT64> QWordScan(INT64 value, int align,
|
|
||||||
const wchar_t *module);
|
|
||||||
|
|
||||||
static std::vector<INT64> QWordScan(INT64 value, INT64 start,int align);
|
|
||||||
template <typename T1, typename T2>
|
|
||||||
static std::vector<T1> split(T1 str, T2 letter) {
|
|
||||||
std::vector<T1> arr;
|
|
||||||
size_t pos;
|
|
||||||
while ((pos = str.find_first_of(letter)) != T1::npos) {
|
|
||||||
T1 str1 = str.substr(0, pos);
|
|
||||||
arr.push_back(str1);
|
|
||||||
str = str.substr(pos + 1, str.length() - pos - 1);
|
|
||||||
}
|
|
||||||
arr.push_back(str);
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
|
||||||
static T1 replace(T1 source, T2 replaced, T1 replaceto) {
|
|
||||||
std::vector<T1> v_arr = split(source, replaced);
|
|
||||||
if (v_arr.size() < 2) return source;
|
|
||||||
T1 temp;
|
|
||||||
for (unsigned int i = 0; i < v_arr.size() - 1; i++) {
|
|
||||||
temp += v_arr[i];
|
|
||||||
temp += replaceto;
|
|
||||||
}
|
|
||||||
temp += v_arr[v_arr.size() - 1];
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static T *WxHeapAlloc(size_t n) {
|
|
||||||
return (T *)HeapAlloc(GetProcessHeap(), 0, n);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace wxhelper
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user