mirror of
https://github.com/ttttupup/wxhelper.git
synced 2024-11-25 19:59:24 +08:00
feat : 3.9.7.29
This commit is contained in:
parent
9f2b0f9925
commit
2767576351
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})
|
282
app/3rdparty/base64/base64.cpp
vendored
Normal file
282
app/3rdparty/base64/base64.cpp
vendored
Normal file
@ -0,0 +1,282 @@
|
||||
/*
|
||||
base64.cpp and base64.h
|
||||
|
||||
base64 encoding and decoding with C++.
|
||||
More information at
|
||||
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
|
||||
|
||||
Version: 2.rc.09 (release candidate)
|
||||
|
||||
Copyright (C) 2004-2017, 2020-2022 René Nyffenegger
|
||||
|
||||
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
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented; you must not
|
||||
claim that you wrote the original source code. If you use this source code
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original source code.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||
|
||||
*/
|
||||
|
||||
#include "base64.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
//
|
||||
// Depending on the url parameter in base64_chars, one of
|
||||
// two sets of base64 characters needs to be chosen.
|
||||
// They differ in their last two characters.
|
||||
//
|
||||
static const char* base64_chars[2] = {
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789"
|
||||
"+/",
|
||||
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789"
|
||||
"-_" };
|
||||
|
||||
static unsigned int pos_of_char(const unsigned char chr) {
|
||||
//
|
||||
// Return the position of chr within base64_encode()
|
||||
//
|
||||
|
||||
if (chr >= 'A' && chr <= 'Z') return chr - 'A';
|
||||
else if (chr >= 'a' && chr <= 'z') return chr - 'a' + ('Z' - 'A') + 1;
|
||||
else if (chr >= '0' && chr <= '9') 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
|
||||
//
|
||||
// 2020-10-23: Throw std::exception rather than const char*
|
||||
//(Pablo Martin-Gomez, https://github.com/Bouska)
|
||||
//
|
||||
throw std::runtime_error("Input is not valid base64-encoded data.");
|
||||
}
|
||||
|
||||
static std::string insert_linebreaks(std::string str, size_t distance) {
|
||||
//
|
||||
// Provided by https://github.com/JomaCorpFX, adapted by me.
|
||||
//
|
||||
if (!str.length()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t pos = distance;
|
||||
|
||||
while (pos < str.size()) {
|
||||
str.insert(pos, "\n");
|
||||
pos += distance + 1;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
template <typename String, unsigned int line_length>
|
||||
static std::string encode_with_line_breaks(String s) {
|
||||
return insert_linebreaks(base64_encode(s, false), line_length);
|
||||
}
|
||||
|
||||
template <typename String>
|
||||
static std::string encode_pem(String s) {
|
||||
return encode_with_line_breaks<String, 64>(s);
|
||||
}
|
||||
|
||||
template <typename String>
|
||||
static std::string encode_mime(String s) {
|
||||
return encode_with_line_breaks<String, 76>(s);
|
||||
}
|
||||
|
||||
template <typename String>
|
||||
static std::string encode(String s, bool 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) {
|
||||
|
||||
size_t len_encoded = (in_len + 2) / 3 * 4;
|
||||
|
||||
unsigned char trailing_char = url ? '.' : '=';
|
||||
|
||||
//
|
||||
// Choose set of base64 characters. They differ
|
||||
// for the last two positions, depending on the url
|
||||
// parameter.
|
||||
// A bool (as is the parameter url) is guaranteed
|
||||
// to evaluate to either 0 or 1 in C++ therefore,
|
||||
// the correct character set is chosen by subscripting
|
||||
// base64_chars with url.
|
||||
//
|
||||
const char* base64_chars_ = base64_chars[url];
|
||||
|
||||
std::string ret;
|
||||
ret.reserve(len_encoded);
|
||||
|
||||
unsigned int pos = 0;
|
||||
|
||||
while (pos < in_len) {
|
||||
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0xfc) >> 2]);
|
||||
|
||||
if (pos + 1 < in_len) {
|
||||
ret.push_back(base64_chars_[((bytes_to_encode[pos + 0] & 0x03) << 4) + ((bytes_to_encode[pos + 1] & 0xf0) >> 4)]);
|
||||
|
||||
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 + 2] & 0x3f]);
|
||||
}
|
||||
else {
|
||||
ret.push_back(base64_chars_[(bytes_to_encode[pos + 1] & 0x0f) << 2]);
|
||||
ret.push_back(trailing_char);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0x03) << 4]);
|
||||
ret.push_back(trailing_char);
|
||||
ret.push_back(trailing_char);
|
||||
}
|
||||
|
||||
pos += 3;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename String>
|
||||
static std::string decode(String const& encoded_string, bool remove_linebreaks) {
|
||||
//
|
||||
// decode(…) is templated so that it can be used with String = const std::string&
|
||||
// or std::string_view (requires at least C++17)
|
||||
//
|
||||
|
||||
if (encoded_string.empty()) return std::string();
|
||||
|
||||
if (remove_linebreaks) {
|
||||
|
||||
std::string copy(encoded_string);
|
||||
|
||||
copy.erase(std::remove(copy.begin(), copy.end(), '\n'), copy.end());
|
||||
|
||||
return base64_decode(copy, false);
|
||||
}
|
||||
|
||||
size_t length_of_string = encoded_string.length();
|
||||
size_t pos = 0;
|
||||
|
||||
//
|
||||
// The approximate length (bytes) of the decoded string might be one or
|
||||
// two bytes smaller, depending on the amount of trailing equal signs
|
||||
// in the encoded string. This approximation is needed to reserve
|
||||
// enough space in the string to be returned.
|
||||
//
|
||||
size_t approx_length_of_decoded_string = length_of_string / 4 * 3;
|
||||
std::string ret;
|
||||
ret.reserve(approx_length_of_decoded_string);
|
||||
|
||||
while (pos < length_of_string) {
|
||||
//
|
||||
// Iterate over encoded input string in chunks. The size of all
|
||||
// chunks except the last one is 4 bytes.
|
||||
//
|
||||
// The last chunk might be padded with equal signs or dots
|
||||
// in order to make it 4 bytes in size as well, but this
|
||||
// is not required as per RFC 2045.
|
||||
//
|
||||
// All chunks except the last one produce three output bytes.
|
||||
//
|
||||
// The last chunk produces at least one and up to three bytes.
|
||||
//
|
||||
|
||||
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:
|
||||
//
|
||||
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)
|
||||
encoded_string.at(pos + 2) != '=' &&
|
||||
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).
|
||||
//
|
||||
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)));
|
||||
|
||||
if ((pos + 3 < length_of_string) &&
|
||||
encoded_string.at(pos + 3) != '=' &&
|
||||
encoded_string.at(pos + 3) != '.'
|
||||
)
|
||||
{
|
||||
//
|
||||
// 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.at(pos + 3))));
|
||||
}
|
||||
}
|
||||
|
||||
pos += 4;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string base64_decode(std::string const& s, bool remove_linebreaks) {
|
||||
return decode(s, remove_linebreaks);
|
||||
}
|
||||
|
||||
std::string base64_encode(std::string const& s, bool url) {
|
||||
return encode(s, url);
|
||||
}
|
||||
|
||||
std::string base64_encode_pem(std::string const& s) {
|
||||
return encode_pem(s);
|
||||
}
|
||||
|
||||
std::string base64_encode_mime(std::string const& s) {
|
||||
return encode_mime(s);
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
//
|
||||
// Interface with std::string_view rather than const std::string&
|
||||
// Requires C++17
|
||||
// Provided by Yannic Bonenberger (https://github.com/Yannic)
|
||||
//
|
||||
|
||||
std::string base64_encode(std::string_view s, bool url) {
|
||||
return encode(s, url);
|
||||
}
|
||||
|
||||
std::string base64_encode_pem(std::string_view s) {
|
||||
return encode_pem(s);
|
||||
}
|
||||
|
||||
std::string base64_encode_mime(std::string_view s) {
|
||||
return encode_mime(s);
|
||||
}
|
||||
|
||||
std::string base64_decode(std::string_view s, bool remove_linebreaks) {
|
||||
return decode(s, remove_linebreaks);
|
||||
}
|
||||
|
||||
#endif // __cplusplus >= 201703L
|
35
app/3rdparty/base64/base64.h
vendored
Normal file
35
app/3rdparty/base64/base64.h
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// base64 encoding and decoding with C++.
|
||||
// Version: 2.rc.09 (release candidate)
|
||||
//
|
||||
|
||||
#ifndef BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
|
||||
#define BASE64_H_C0CE2A47_D10E_42C9_A27C_C883944E704A
|
||||
|
||||
#include <string>
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#include <string_view>
|
||||
#endif // __cplusplus >= 201703L
|
||||
|
||||
std::string base64_encode(std::string const& s, bool url = false);
|
||||
std::string base64_encode_pem(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_encode(unsigned char const*, size_t len, bool url = false);
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
//
|
||||
// Interface with std::string_view rather than const std::string&
|
||||
// Requires C++17
|
||||
// Provided by Yannic Bonenberger (https://github.com/Yannic)
|
||||
//
|
||||
std::string base64_encode(std::string_view s, bool url = false);
|
||||
std::string base64_encode_pem(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);
|
||||
#endif // __cplusplus >= 201703L
|
||||
|
||||
#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})
|
2823
app/3rdparty/lz4/lz4.c
vendored
Normal file
2823
app/3rdparty/lz4/lz4.c
vendored
Normal file
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
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
|
23
app/base/src/include/singleton.h
Normal file
23
app/base/src/include/singleton.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef BASE_SINGLETON_H_
|
||||
#define BASE_SINGLETON_H_
|
||||
namespace base {
|
||||
template <typename T>
|
||||
class Singleton {
|
||||
protected:
|
||||
Singleton() {}
|
||||
~Singleton() {}
|
||||
|
||||
Singleton(const Singleton&) = delete;
|
||||
Singleton& operator=(const Singleton&) = delete;
|
||||
|
||||
Singleton(Singleton&&) = delete;
|
||||
Singleton& operator=(Singleton&&) = delete;
|
||||
|
||||
public:
|
||||
static T& GetInstance() {
|
||||
static T instance{};
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
} // namespace base
|
||||
#endif
|
24
app/base/src/include/thread_pool.h
Normal file
24
app/base/src/include/thread_pool.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef BASE_THREAD_POOL_H_
|
||||
#define BASE_THREAD_POOL_H_
|
||||
#include "singleton.h"
|
||||
#include <windows.h>
|
||||
|
||||
namespace base {
|
||||
|
||||
class ThreadPool :public Singleton<ThreadPool>{
|
||||
public:
|
||||
~ThreadPool();
|
||||
|
||||
bool Create(unsigned long min = 1, unsigned long max = 4);
|
||||
|
||||
bool AddWork(PTP_WORK_CALLBACK callback,PVOID opt);
|
||||
|
||||
private:
|
||||
PTP_POOL pool_;
|
||||
PTP_CLEANUP_GROUP cleanup_group_;
|
||||
TP_CALLBACK_ENVIRON env_;
|
||||
};
|
||||
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
61
app/base/src/include/utils.h
Normal file
61
app/base/src/include/utils.h
Normal file
@ -0,0 +1,61 @@
|
||||
#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);
|
||||
} // 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
|
44
app/base/src/thread_pool.cc
Normal file
44
app/base/src/thread_pool.cc
Normal file
@ -0,0 +1,44 @@
|
||||
#include "include/thread_pool.h"
|
||||
|
||||
namespace base {
|
||||
ThreadPool::~ThreadPool() {
|
||||
if (cleanup_group_) {
|
||||
CloseThreadpoolCleanupGroupMembers(cleanup_group_, true, NULL);
|
||||
CloseThreadpoolCleanupGroup(cleanup_group_);
|
||||
}
|
||||
DestroyThreadpoolEnvironment(&env_);
|
||||
if (pool_) {
|
||||
CloseThreadpool(pool_);
|
||||
}
|
||||
}
|
||||
|
||||
bool ThreadPool::Create(unsigned long min, unsigned long max) {
|
||||
InitializeThreadpoolEnvironment(&env_);
|
||||
pool_ = CreateThreadpool(NULL);
|
||||
if (NULL == pool_) {
|
||||
return false;
|
||||
}
|
||||
SetThreadpoolThreadMaximum(pool_, max);
|
||||
BOOL ret = SetThreadpoolThreadMinimum(pool_, min);
|
||||
if (FALSE == ret) {
|
||||
return false;
|
||||
}
|
||||
cleanup_group_ = CreateThreadpoolCleanupGroup();
|
||||
if (NULL == cleanup_group_) {
|
||||
return false;
|
||||
}
|
||||
SetThreadpoolCallbackPool(&env_, pool_);
|
||||
SetThreadpoolCallbackCleanupGroup(&env_, cleanup_group_, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ThreadPool::AddWork(PTP_WORK_CALLBACK callback, PVOID opt) {
|
||||
PTP_WORK work = CreateThreadpoolWork(callback, opt, &env_);
|
||||
if (NULL == work) {
|
||||
return false;
|
||||
}
|
||||
SubmitThreadpoolWork(work);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace base
|
155
app/base/src/utils.cc
Normal file
155
app/base/src/utils.cc
Normal file
@ -0,0 +1,155 @@
|
||||
#include "include/utils.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <winternl.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
|
||||
}
|
||||
} // 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
|
19
app/wxhelper/src/config.h
Normal file
19
app/wxhelper/src/config.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef WXHELPER_CONFIG_H_
|
||||
#define WXHELPER_CONFIG_H_
|
||||
|
||||
namespace wxhelper {
|
||||
|
||||
class Config {
|
||||
public:
|
||||
Config();
|
||||
~Config();
|
||||
void Initialize();
|
||||
int GetPort();
|
||||
int GetHideDll();
|
||||
|
||||
private:
|
||||
int port_;
|
||||
int hidden_dll_;
|
||||
};
|
||||
} // namespace wxhelper
|
||||
#endif
|
22
app/wxhelper/src/dllMain.cc
Normal file
22
app/wxhelper/src/dllMain.cc
Normal file
@ -0,0 +1,22 @@
|
||||
#include "global_manager.h"
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved) {
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH: {
|
||||
DisableThreadLibraryCalls(hModule);
|
||||
wxhelper::GlobalManager::GetInstance().initialize(hModule);
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_ATTACH: {
|
||||
break;
|
||||
}
|
||||
case DLL_THREAD_DETACH: {
|
||||
break;
|
||||
}
|
||||
case DLL_PROCESS_DETACH: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
37
app/wxhelper/src/global_manager.cc
Normal file
37
app/wxhelper/src/global_manager.cc
Normal file
@ -0,0 +1,37 @@
|
||||
#include "global_manager.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();
|
||||
WechatService::GetInstance().SetBaseAddr(base);
|
||||
http_server = std::unique_ptr<http::HttpServer>(
|
||||
new http::HttpServer(config->GetPort()));
|
||||
http_server->AddHttpApiUrl("/api/sendTextMsg", SendTextMsg);
|
||||
http_server->Start();
|
||||
base::ThreadPool::GetInstance().Create(2, 8);
|
||||
|
||||
state = GlobalContextState::INITIALIZED;
|
||||
}
|
||||
|
||||
void GlobalManager::finally() {
|
||||
if (http_server) {
|
||||
http_server->Stop();
|
||||
}
|
||||
}
|
||||
} // namespace wxhelper
|
33
app/wxhelper/src/global_manager.h
Normal file
33
app/wxhelper/src/global_manager.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef WXHELPER_GLOBAL_MANAGER_H_
|
||||
#define WXHELPER_GLOBAL_MANAGER_H_
|
||||
#include <memory>
|
||||
|
||||
#include "config.h"
|
||||
#include "http_server.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace wxhelper {
|
||||
|
||||
enum class GlobalContextState { NOT_INITIALIZED, INITIALIZING, INITIALIZED };
|
||||
|
||||
class GlobalManager : public base::Singleton<GlobalManager> {
|
||||
friend class base::Singleton<GlobalManager>;
|
||||
~GlobalManager();
|
||||
|
||||
public:
|
||||
void initialize(HMODULE module);
|
||||
void finally();
|
||||
|
||||
public:
|
||||
std::unique_ptr<Config> config;
|
||||
std::unique_ptr<http::HttpServer> http_server;
|
||||
// std::unique_ptr<WechatService> service_;
|
||||
|
||||
GlobalContextState state = GlobalContextState::NOT_INITIALIZED;
|
||||
|
||||
private:
|
||||
HMODULE module_;
|
||||
};
|
||||
|
||||
} // namespace wxhelper
|
||||
#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
|
24
app/wxhelper/src/http_url_handler.cc
Normal file
24
app/wxhelper/src/http_url_handler.cc
Normal file
@ -0,0 +1,24 @@
|
||||
#include "http_url_handler.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "utils.h"
|
||||
#include "wechat_service.h"
|
||||
#include "windows.h"
|
||||
namespace wxhelper {
|
||||
std::wstring GetWStringParam(nlohmann::json data, std::string key) {
|
||||
return base::utils::Utf8ToWstring(data[key].get<std::string>());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
} // namespace wxhelper
|
10
app/wxhelper/src/http_url_handler.h
Normal file
10
app/wxhelper/src/http_url_handler.h
Normal file
@ -0,0 +1,10 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
#endif
|
500
app/wxhelper/src/wechat_function.h
Normal file
500
app/wxhelper/src/wechat_function.h
Normal file
@ -0,0 +1,500 @@
|
||||
#ifndef WXHELPER_WECHAT_FUNCTION_H_
|
||||
#define WXHELPER_WECHAT_FUNCTION_H_
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace wxhelper {
|
||||
namespace common {
|
||||
/***************************sqlite3***************************************/
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
/* beginning-of-error-codes */
|
||||
#define SQLITE_ERROR 1 /* Generic error */
|
||||
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
|
||||
#define SQLITE_PERM 3 /* Access permission denied */
|
||||
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SQLITE_BUSY 5 /* The database file is locked */
|
||||
#define SQLITE_LOCKED 6 /* A table in the database is locked */
|
||||
#define SQLITE_NOMEM 7 /* A malloc() failed */
|
||||
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
|
||||
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
|
||||
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
|
||||
#define SQLITE_FULL 13 /* Insertion failed because database is full */
|
||||
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
|
||||
#define SQLITE_EMPTY 16 /* Internal use only */
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
|
||||
#define SQLITE_AUTH 23 /* Authorization denied */
|
||||
#define SQLITE_FORMAT 24 /* Not used */
|
||||
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
|
||||
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
|
||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||
/* end-of-error-codes */
|
||||
|
||||
#define SQLITE_INTEGER 1
|
||||
#define SQLITE_FLOAT 2
|
||||
#define SQLITE_BLOB 4
|
||||
#define SQLITE_NULL 5
|
||||
#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 */
|
||||
sqlite3_callback, /* Callback function */
|
||||
void *, /* 1st argument to callback */
|
||||
char **errmsg /* Error msg written here */
|
||||
);
|
||||
|
||||
typedef int(__cdecl *sqlite3_prepare)(
|
||||
UINT64 db, /* Database handle */
|
||||
const char *zSql, /* SQL statement, UTF-8 encoded */
|
||||
int nByte, /* Maximum length of zSql in bytes. */
|
||||
UINT64 **ppStmt, /* OUT: Statement handle */
|
||||
const char **pzTail /* OUT: Pointer to unused portion of zSql */
|
||||
);
|
||||
typedef int(__cdecl *sqlite3_open)(const char *filename, UINT64 **ppDb);
|
||||
|
||||
typedef int(__cdecl *sqlite3_sleep)(int);
|
||||
typedef int(__cdecl *sqlite3_errcode)(UINT64 *db);
|
||||
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);
|
||||
|
||||
/***************************sqlite3 end*************************************/
|
||||
|
||||
struct TableInfo {
|
||||
char *name;
|
||||
INT64 name_len;
|
||||
char *table_name;
|
||||
INT64 table_name_len;
|
||||
char *sql;
|
||||
INT64 sql_len;
|
||||
char *rootpage;
|
||||
INT64 rootpage_len;
|
||||
};
|
||||
|
||||
struct DatabaseInfo {
|
||||
UINT64 handle = 0;
|
||||
wchar_t *db_name = NULL;
|
||||
INT64 db_name_len = 0;
|
||||
std::vector<TableInfo> tables;
|
||||
INT64 count = 0;
|
||||
INT64 extrainfo = 0;
|
||||
};
|
||||
|
||||
struct SqlResult {
|
||||
char *column_name;
|
||||
INT64 column_name_len;
|
||||
char *content;
|
||||
INT64 content_len;
|
||||
BOOL is_blob;
|
||||
};
|
||||
|
||||
struct InnerMessageStruct {
|
||||
char *buffer;
|
||||
INT64 length;
|
||||
~InnerMessageStruct() {
|
||||
if (this->buffer != NULL) {
|
||||
delete[] this->buffer;
|
||||
this->buffer = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct SelfInfoInner {
|
||||
std::string name;
|
||||
std::string city;
|
||||
std::string province;
|
||||
std::string country;
|
||||
std::string account;
|
||||
std::string wxid;
|
||||
std::string mobile;
|
||||
std::string head_img;
|
||||
std::string data_save_path;
|
||||
std::string signature;
|
||||
std::string current_data_path;
|
||||
std::string db_key;
|
||||
};
|
||||
|
||||
struct ContactInner {
|
||||
std::string wxid;
|
||||
std::string custom_account;
|
||||
std::string encrypt_name;
|
||||
std::string nickname;
|
||||
std::string pinyin;
|
||||
std::string pinyin_all;
|
||||
DWORD type;
|
||||
DWORD verify_flag;
|
||||
DWORD reserved1;
|
||||
DWORD reserved2;
|
||||
ContactInner() {
|
||||
wxid = "";
|
||||
custom_account = "";
|
||||
encrypt_name = "";
|
||||
nickname = "";
|
||||
pinyin = "";
|
||||
pinyin_all = "";
|
||||
type = -1;
|
||||
verify_flag = -1;
|
||||
reserved1 = -1;
|
||||
reserved2 = -1;
|
||||
}
|
||||
};
|
||||
|
||||
struct ChatRoomInfoInner {
|
||||
std::string chat_room_id;
|
||||
std::string notice;
|
||||
std::string admin;
|
||||
std::string xml;
|
||||
ChatRoomInfoInner() {
|
||||
chat_room_id = "";
|
||||
notice = "";
|
||||
admin = "";
|
||||
xml = "";
|
||||
}
|
||||
};
|
||||
|
||||
struct VectorInner {
|
||||
#ifdef _DEBUG
|
||||
INT64 head;
|
||||
#endif
|
||||
INT64 start;
|
||||
INT64 finsh;
|
||||
INT64 end;
|
||||
};
|
||||
|
||||
struct ChatRoomMemberInner {
|
||||
std::string chat_room_id;
|
||||
std::string admin;
|
||||
std::string admin_nickname;
|
||||
std::string member_nickname;
|
||||
std::string member;
|
||||
ChatRoomMemberInner()
|
||||
: chat_room_id(""),
|
||||
admin(""),
|
||||
admin_nickname(""),
|
||||
member_nickname(""),
|
||||
member("") {}
|
||||
};
|
||||
|
||||
struct ContactProfileInner {
|
||||
std::string wxid;
|
||||
std::string account;
|
||||
std::string v3;
|
||||
std::string nickname;
|
||||
std::string head_image;
|
||||
ContactProfileInner()
|
||||
: wxid(""), account(""), v3(""), nickname(""), head_image("") {}
|
||||
};
|
||||
|
||||
} // namespace common
|
||||
namespace V3_9_5_81 {
|
||||
namespace function {
|
||||
|
||||
typedef UINT64 (*__GetAccountService)();
|
||||
typedef UINT64 (*__GetDataSavePath)(UINT64);
|
||||
typedef UINT64 (*__GetCurrentDataPath)(UINT64);
|
||||
typedef UINT64 (*__GetSendMessageMgr)();
|
||||
typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64, UINT64);
|
||||
typedef UINT64 (*__FreeChatMsg)(UINT64);
|
||||
|
||||
typedef UINT64 (*__SendImageMsg)(UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewChatMsg)(UINT64);
|
||||
typedef UINT64 (*__SendFile)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64, UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetAppMsgMgr)();
|
||||
typedef UINT64 (*__OperatorNew)(UINT64);
|
||||
|
||||
typedef UINT64 (*__Free)();
|
||||
typedef UINT64 (*__GetContactMgr)();
|
||||
typedef UINT64 (*__GetContactList)(UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__GetChatRoomMgr)();
|
||||
typedef UINT64 (*__NewChatRoomInfo)(UINT64);
|
||||
typedef UINT64 (*__FreeChatRoomInfo)(UINT64);
|
||||
typedef UINT64 (*__GetChatRoomDetailInfo)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__DoAddMemberToChatRoom)(UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__DoModChatRoomMemberNickName)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__DoDelMemberFromChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetMemberFromChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewChatRoom)(UINT64);
|
||||
typedef UINT64 (*__FreeChatRoom)(UINT64);
|
||||
|
||||
typedef UINT64 (*__DoTopMsg)(UINT64, UINT64);
|
||||
typedef UINT64 (*__RemoveTopMsg)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__InviteMemberToChatRoom)(UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__CreateChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__QuitChatRoom)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__ForwardMsg)(UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__GetSNSFirstPage)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetSNSNextPageScene)(UINT64, UINT64);
|
||||
|
||||
typedef UINT64 (*__GetSNSDataMgr)();
|
||||
typedef UINT64 (*__GetSnsTimeLineMgr)();
|
||||
typedef UINT64 (*__GetMgrByPrefixLocalId)(UINT64, UINT64);
|
||||
typedef UINT64 (*__AddFavFromMsg)(UINT64, UINT64);
|
||||
typedef UINT64 (*__GetChatMgr)();
|
||||
typedef UINT64 (*__GetFavoriteMgr)();
|
||||
typedef UINT64 (*__AddFavFromImage)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetContact)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewContact)(UINT64);
|
||||
typedef UINT64 (*__FreeContact)(UINT64);
|
||||
typedef UINT64 (*__NewMMReaderItem)(UINT64);
|
||||
typedef UINT64 (*__FreeMMReaderItem)(UINT64);
|
||||
typedef UINT64 (*__ForwordPublicMsg)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__NewAppMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__FreeAppMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__ParseAppMsgXml)(UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetPreDownLoadMgr)();
|
||||
typedef UINT64 (*__PushAttachTask)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__GetCustomSmileyMgr)();
|
||||
typedef UINT64 (*__SendCustomEmotion)(UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__JsApiShareAppMessage)(UINT64);
|
||||
typedef UINT64 (*__InitJsConfig)(UINT64, UINT64);
|
||||
typedef UINT64 (*__SendApplet)(UINT64, UINT64, UINT64, UINT64);
|
||||
typedef UINT64 (*__SendAppletSecond)(UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64);
|
||||
typedef UINT64 (*__GetAppInfoByWaid)(UINT64, UINT64);
|
||||
typedef UINT64 (*__CopyShareAppMessageRequest)(UINT64, UINT64);
|
||||
typedef UINT64 (*__NewWAUpdatableMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__FreeWAUpdatableMsgInfo)(UINT64);
|
||||
typedef UINT64 (*__SendPatMsg)(UINT64, UINT64);
|
||||
typedef UINT64 (*__GetOCRManager)();
|
||||
typedef UINT64 (*__DoOCRTask)(UINT64, UINT64, UINT64, UINT64, UINT64);
|
||||
|
||||
} // namespace function
|
||||
namespace prototype {
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
struct WeChatStr {
|
||||
char *ptr;
|
||||
INT64 buf;
|
||||
INT64 len;
|
||||
INT64 maxlen;
|
||||
|
||||
WeChatStr(const char *p) {
|
||||
ptr = (char *)p;
|
||||
buf = 0;
|
||||
len = strlen(p);
|
||||
maxlen = len | 0xF;
|
||||
}
|
||||
WeChatStr() {
|
||||
ptr = NULL;
|
||||
buf = 0;
|
||||
len = 0;
|
||||
maxlen = 0xF;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace prototype
|
||||
namespace offset {
|
||||
const UINT64 kGetAccountServiceMgr = 0x8c1230;
|
||||
const UINT64 kSyncMsg = 0xc39680;
|
||||
const UINT64 kSyncMsgNext = 0xc39680;
|
||||
const UINT64 kGetCurrentDataPath = 0xf5d130;
|
||||
const UINT64 kGetAppDataSavePath = 0x12d7040;
|
||||
const UINT64 kGetSendMessageMgr = 0x8c00e0;
|
||||
const UINT64 kSendTextMsg = 0xfcd8d0;
|
||||
const UINT64 kFreeChatMsg = 0x8aaa00;
|
||||
|
||||
const UINT64 kDoAddMsg = 0x1010d80;
|
||||
const UINT64 kSendImageMsg = 0xfc3d30;
|
||||
const UINT64 kChatMsgInstanceCounter = 0x8c7fd0;
|
||||
const UINT64 kSendFileMsg = 0xdd27f0;
|
||||
const UINT64 kGetAppMsgMgr = 0x8c33f0;
|
||||
const UINT64 kGetContactMgr = 0x8ae3d0;
|
||||
const UINT64 kGetContactList = 0xeab270;
|
||||
|
||||
const UINT64 k_sqlite3_exec = 0x252e340;
|
||||
const UINT64 k_sqlite3_prepare = 0x2535eb0;
|
||||
const UINT64 k_sqlite3_open = 0x256d6b0;
|
||||
const UINT64 k_sqlite3_backup_init = 0x24e8450;
|
||||
const UINT64 k_sqlite3_errcode = 0x256bfb0;
|
||||
const UINT64 k_sqlite3_close = 0x256a110;
|
||||
const UINT64 k_sqlite3_step = 0x24f2350;
|
||||
const UINT64 k_sqlite3_column_count = 0x24f2b70;
|
||||
const UINT64 k_sqlite3_column_name = 0x24f3570;
|
||||
const UINT64 k_sqlite3_column_type = 0x24f33c0;
|
||||
const UINT64 k_sqlite3_column_blob = 0x24f2ba0;
|
||||
const UINT64 k_sqlite3_column_bytes = 0x24f2c90;
|
||||
const UINT64 k_sqlite3_finalize = 0x24f1400;
|
||||
|
||||
const UINT64 kGPInstance = 0x3a6f908;
|
||||
const UINT64 kMicroMsgDB = 0xb8;
|
||||
const UINT64 kChatMsgDB = 0x2c8;
|
||||
const UINT64 kMiscDB = 0x5f0;
|
||||
const UINT64 kEmotionDB = 0x838;
|
||||
const UINT64 kMediaDB = 0xef8;
|
||||
const UINT64 kBizchatMsgDB = 0x1a70;
|
||||
const UINT64 kFunctionMsgDB = 0x1b48;
|
||||
const UINT64 kDBName = 0x28;
|
||||
const UINT64 kStorageStart = 0x0;
|
||||
const UINT64 kStorageEnd = 0x0;
|
||||
const UINT64 kMultiDBMgr = 0x3acfb68;
|
||||
const UINT64 kPublicMsgMgr = 0x3acc268;
|
||||
const UINT64 kFavoriteStorageMgr = 0x3acf0d0;
|
||||
|
||||
const UINT64 kChatRoomMgr = 0x8e9d30;
|
||||
const UINT64 kGetChatRoomDetailInfo = 0xe73590;
|
||||
const UINT64 kNewChatRoomInfo = 0x12006b0;
|
||||
const UINT64 kFreeChatRoomInfo = 0x1200890;
|
||||
const UINT64 kDoAddMemberToChatRoom = 0xe63c70;
|
||||
const UINT64 kDoModChatRoomMemberNickName = 0xe6db00;
|
||||
const UINT64 kDelMemberFromChatRoom = 0xe64290;
|
||||
const UINT64 kGetMemberFromChatRoom = 0xe74de0;
|
||||
const UINT64 kNewChatRoom = 0x11fde50;
|
||||
const UINT64 kFreeChatRoom = 0x11fe030;
|
||||
|
||||
const UINT64 kTopMsg = 0xa5e4f0;
|
||||
const UINT64 kRemoveTopMsg = 0xe787b0;
|
||||
const UINT64 kInviteMember = 0xe63650;
|
||||
const UINT64 kHookLog = 0x1304e60;
|
||||
|
||||
const UINT64 kCreateChatRoom = 0xe63340;
|
||||
const UINT64 kQuitChatRoom = 0xe6e3b0;
|
||||
const UINT64 kForwardMsg = 0xfcd0f0;
|
||||
|
||||
const UINT64 kOnSnsTimeLineSceneFinish = 0x1a73150;
|
||||
const UINT64 kSNSGetFirstPage = 0x1a51dd0;
|
||||
const UINT64 kSNSGetNextPageScene = 0x1a77240;
|
||||
const UINT64 kSNSDataMgr = 0xeebda0;
|
||||
const UINT64 kSNSTimeLineMgr = 0x19e83a0;
|
||||
const UINT64 kGetMgrByPrefixLocalId = 0xe4add0;
|
||||
const UINT64 kAddFavFromMsg = 0x1601520;
|
||||
const UINT64 kGetChatMgr = 0x8f0400;
|
||||
const UINT64 kGetFavoriteMgr = 0x8c69b0;
|
||||
const UINT64 kAddFavFromImage = 0x160b920;
|
||||
const UINT64 kGetContact = 0xEA5F90;
|
||||
const UINT64 kNewContact = 0x1212e40;
|
||||
const UINT64 kFreeContact = 0x12134e0;
|
||||
const UINT64 kNewMMReaderItem = 0x8c79a0;
|
||||
const UINT64 kFreeMMReaderItem = 0x8c6da0;
|
||||
const UINT64 kForwordPublicMsg = 0xddc6c0;
|
||||
const UINT64 kParseAppMsgXml = 0x11b0a70;
|
||||
const UINT64 kNewAppMsgInfo = 0x91a550;
|
||||
const UINT64 kFreeAppMsgInfo = 0x8fd1a0;
|
||||
const UINT64 kGetPreDownLoadMgr = 0x9996f0;
|
||||
const UINT64 kPushAttachTask = 0x9c0080;
|
||||
const UINT64 kGetCustomSmileyMgr = 0x915c00;
|
||||
const UINT64 kSendCustomEmotion = 0xec0a40;
|
||||
const UINT64 kNewJsApiShareAppMessage = 0x13be1a0;
|
||||
const UINT64 kInitJsConfig = 0x137bc00;
|
||||
const UINT64 kSendApplet = 0x13c0920;
|
||||
const UINT64 kSendAppletSecond = 0x13c1150;
|
||||
const UINT64 kGetAppInfoByWaid = 0x13c5790;
|
||||
const UINT64 kCopyShareAppMessageRequest = 0x13c0670;
|
||||
const UINT64 kNewWAUpdatableMsgInfo = 0x919ca0;
|
||||
const UINT64 kFreeWAUpdatableMsgInfo = 0x8fc230;
|
||||
const UINT64 kSendPatMsg = 0x195f340;
|
||||
const UINT64 kGetOCRManager = 0x999780;
|
||||
const UINT64 kDoOCRTask = 0x190b2a0;
|
||||
|
||||
} // namespace offset
|
||||
} // 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 kGetSendMessageMgr = 0x8fe740;
|
||||
const UINT64 kFreeChatMsg = 0x8fffc0;
|
||||
const UINT64 kSendTextMsg = 0x1024370;
|
||||
} // namespace offset
|
||||
namespace function {
|
||||
typedef UINT64 (*__GetSendMessageMgr)();
|
||||
typedef UINT64 (*__SendTextMsg)(UINT64, UINT64, UINT64, UINT64, UINT64, UINT64,
|
||||
UINT64, UINT64);
|
||||
typedef UINT64 (*__FreeChatMsg)(UINT64);
|
||||
} // namespace function
|
||||
} // namespace V3_9_7_29
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
182
app/wxhelper/src/wechat_service.cc
Normal file
182
app/wxhelper/src/wechat_service.cc
Normal file
@ -0,0 +1,182 @@
|
||||
#include "wechat_service.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() { return INT64(); }
|
||||
|
||||
INT64 WechatService::GetSelfInfo(common::SelfInfoInner& out) { return INT64(); }
|
||||
|
||||
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) {
|
||||
return INT64();
|
||||
}
|
||||
|
||||
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
|
83
app/wxhelper/src/wechat_service.h
Normal file
83
app/wxhelper/src/wechat_service.h
Normal file
@ -0,0 +1,83 @@
|
||||
#ifndef WXHELPER_WECHAT_SERVICE_H_
|
||||
#define WXHELPER_WECHAT_SERVICE_H_
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "singleton.h"
|
||||
#include "wechat_function.h"
|
||||
namespace wxhelper {
|
||||
|
||||
class WechatService : public base::Singleton<WechatService> {
|
||||
friend class base::Singleton<WechatService>;
|
||||
~WechatService();
|
||||
|
||||
public:
|
||||
INT64 CheckLogin();
|
||||
INT64 GetSelfInfo(common::SelfInfoInner& out);
|
||||
INT64 SendTextMsg(const std::wstring& wxid, const std::wstring& msg);
|
||||
INT64 SendImageMsg(const std::wstring& wxid, const std::wstring& image_path);
|
||||
INT64 SendFileMsg(const std::wstring& wxid, const std::wstring& file_path);
|
||||
INT64 GetContacts(std::vector<common::ContactInner>& vec);
|
||||
INT64 GetChatRoomDetailInfo(const std::wstring& room_id,
|
||||
common::ChatRoomInfoInner& room_info);
|
||||
INT64 AddMemberToChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& members);
|
||||
|
||||
INT64 ModChatRoomMemberNickName(const std::wstring& room_id,
|
||||
const std::wstring& wxid,
|
||||
const std::wstring& nickname);
|
||||
INT64 DelMemberFromChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& members);
|
||||
INT64 GetMemberFromChatRoom(const std::wstring& room_id,
|
||||
common::ChatRoomMemberInner& member);
|
||||
INT64 SetTopMsg(ULONG64 msg_id);
|
||||
INT64 RemoveTopMsg(const std::wstring& room_id, ULONG64 msg_id);
|
||||
INT64 InviteMemberToChatRoom(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& wxids);
|
||||
INT64 CreateChatRoom(const std::vector<std::wstring>& wxids);
|
||||
INT64 QuitChatRoom(const std::wstring& room_id);
|
||||
INT64 ForwardMsg(UINT64 msg_id, const std::wstring& wxid);
|
||||
INT64 GetSNSFirstPage();
|
||||
INT64 GetSNSNextPage(UINT64 sns_id);
|
||||
INT64 AddFavFromMsg(UINT64 msg_id);
|
||||
INT64 AddFavFromImage(const std::wstring& wxid,
|
||||
const std::wstring& image_path);
|
||||
INT64 SendAtText(const std::wstring& room_id,
|
||||
const std::vector<std::wstring>& wxids,
|
||||
const std::wstring& msg);
|
||||
std::wstring GetContactOrChatRoomNickname(const std::wstring& wxid);
|
||||
INT64 GetContactByWxid(const std::wstring& wxid,
|
||||
common::ContactProfileInner& profile);
|
||||
INT64 DoDownloadTask(UINT64 msg_id);
|
||||
INT64 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);
|
||||
INT64 ForwardPublicMsgByMsgId(const std::wstring& wxid, UINT64 msg_id);
|
||||
|
||||
INT64 DecodeImage(const std::wstring& file_path,
|
||||
const std::wstring& save_dir);
|
||||
INT64 GetVoiceByDB(ULONG64 msg_id, const std::wstring& dir);
|
||||
INT64 SendCustomEmotion(const std::wstring& file_path,
|
||||
const std::wstring& wxid);
|
||||
INT64 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);
|
||||
INT64 SendPatMsg(const std::wstring& room_id, const std::wstring& wxid);
|
||||
INT64 DoOCRTask(const std::wstring& img_path, std::string& result);
|
||||
void SetBaseAddr(UINT64 addr);
|
||||
void SetJsApiAddr(UINT64 addr);
|
||||
|
||||
private:
|
||||
UINT64 base_addr_;
|
||||
UINT64 js_api_addr_;
|
||||
};
|
||||
|
||||
} // namespace wxhelper
|
||||
|
||||
#endif
|
7
app/wxhelper/src/wxutils.cc
Normal file
7
app/wxhelper/src/wxutils.cc
Normal file
@ -0,0 +1,7 @@
|
||||
#include "wxutils.h"
|
||||
|
||||
namespace wxhelper {
|
||||
namespace wxutils {
|
||||
UINT64 GetWeChatWinBase() { return (UINT64)GetModuleHandleA("WeChatWin.dll"); }
|
||||
} // namespace wxutils
|
||||
} // namespace wxhelper
|
10
app/wxhelper/src/wxutils.h
Normal file
10
app/wxhelper/src/wxutils.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef WXHELPER_WXUTILS_H_
|
||||
#define WXHELPER_WXUTILS_H_
|
||||
#include <windows.h>
|
||||
namespace wxhelper {
|
||||
namespace wxutils {
|
||||
UINT64 GetWeChatWinBase();
|
||||
}
|
||||
|
||||
} // namespace wxhelper
|
||||
#endif
|
0
doc/3.9.7.25.md
Normal file
0
doc/3.9.7.25.md
Normal file
Loading…
Reference in New Issue
Block a user