feature: Add customize spoof build vars support

Signed-off-by: GarfieldHan <2652609017@qq.com>
This commit is contained in:
GarfieldHan
2024-07-18 08:20:39 +08:00
parent 11e77147a5
commit 95ad2d5a32
5 changed files with 88 additions and 29 deletions

3
.gitmodules vendored
View File

@@ -4,3 +4,6 @@
[submodule "module/src/main/cpp/external/LSPlt"] [submodule "module/src/main/cpp/external/LSPlt"]
path = module/src/main/cpp/external/LSPlt path = module/src/main/cpp/external/LSPlt
url = https://github.com/LSPosed/LSPlt url = https://github.com/LSPosed/LSPlt
[submodule "module/src/main/cpp/external/glaze"]
path = module/src/main/cpp/external/glaze
url = https://github.com/stephenberry/glaze

View File

@@ -40,5 +40,5 @@ target_link_libraries(${MODULE_NAME} log binder utils elf_util my_logging)
target_compile_options(${MODULE_NAME} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) target_compile_options(${MODULE_NAME} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
add_library(tszygisk SHARED zygisk/main.cpp) add_library(tszygisk SHARED zygisk/main.cpp)
target_link_libraries(tszygisk log my_logging) target_link_libraries(tszygisk log my_logging glaze::glaze)
target_compile_options(tszygisk PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden) target_compile_options(tszygisk PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)

View File

@@ -10,6 +10,8 @@ target_include_directories(lsplt PRIVATE LSPlt/lsplt/src/main/jni)
target_link_libraries(lsplt PUBLIC my_logging cxx) target_link_libraries(lsplt PUBLIC my_logging cxx)
# end lsplt # end lsplt
add_subdirectory(glaze)
# cxx # cxx
set(LIBCXX_SOURCES set(LIBCXX_SOURCES
algorithm.cpp algorithm.cpp
@@ -23,16 +25,16 @@ set(LIBCXX_SOURCES
condition_variable_destructor.cpp condition_variable_destructor.cpp
# debug.cpp # debug.cpp
exception.cpp exception.cpp
# filesystem/directory_iterator.cpp filesystem/directory_iterator.cpp
# filesystem/int128_builtins.cpp filesystem/int128_builtins.cpp
# filesystem/operations.cpp filesystem/operations.cpp
functional.cpp functional.cpp
future.cpp future.cpp
hash.cpp hash.cpp
# ios.cpp ios.cpp
# ios.instantiations.cpp ios.instantiations.cpp
# iostream.cpp iostream.cpp
# locale.cpp locale.cpp
memory.cpp memory.cpp
mutex.cpp mutex.cpp
mutex_destructor.cpp mutex_destructor.cpp
@@ -65,7 +67,6 @@ set(LIBCXX_EXPORT_FLAGS
-D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_BUILDING_LIBRARY
-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
-D_LIBCXXABI_NO_EXCEPTIONS -D_LIBCXXABI_NO_EXCEPTIONS
-D_LIBCPP_HAS_NO_LOCALIZATION
) )
set(LIBCXX_FLAGS set(LIBCXX_FLAGS
-fvisibility-global-new-delete-hidden -fvisibility-global-new-delete-hidden

View File

@@ -3,7 +3,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <android/log.h> #include <android/log.h>
#include <string_view> #include <string_view>
#include <utility>
#include "glaze/glaze.hpp"
#include "logging.hpp" #include "logging.hpp"
#include "zygisk.hpp" #include "zygisk.hpp"
@@ -12,6 +14,21 @@ using zygisk::AppSpecializeArgs;
using zygisk::ServerSpecializeArgs; using zygisk::ServerSpecializeArgs;
using namespace std::string_view_literals; using namespace std::string_view_literals;
struct spoof_config {
std::string manufacturer{"Google"};
std::string model{"Pixel"};
std::string fingerprint{"google/sailfish/sailfish:8.1.0/OPM1.171019.011/4448085:user/release-keys"};
std::string brand{"google"};
std::string product{"sailfish"};
std::string device{"sailfish"};
std::string release{"8.1.0"};
std::string id{"OPM1.171019.011"};
std::string incremental{"4448085"};
std::string security_patch{"2017-12-05"};
std::string type{"user"};
std::string tags{"release-keys"};
};
class TrickyStore : public zygisk::ModuleBase { class TrickyStore : public zygisk::ModuleBase {
public: public:
void onLoad(Api *api, JNIEnv *env) override { void onLoad(Api *api, JNIEnv *env) override {
@@ -21,15 +38,30 @@ public:
void preAppSpecialize(AppSpecializeArgs *args) override { void preAppSpecialize(AppSpecializeArgs *args) override {
api_->setOption(zygisk::DLCLOSE_MODULE_LIBRARY); api_->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
int enabled = 0; int enabled = 0;
spoof_config spoofConfig{};
{ {
auto fd = api_->connectCompanion(); auto fd = api_->connectCompanion();
if (fd >= 0) { if (fd >= 0) [[likely]] {
// read enabled
read(fd, &enabled, sizeof(enabled)); read(fd, &enabled, sizeof(enabled));
if (enabled) {
size_t bufferSize = 0;
std::string buffer;
// read size first
read(fd, &bufferSize, sizeof(bufferSize));
// resize and receive
buffer.resize(bufferSize);
read(fd, buffer.data(), bufferSize);
// parse
if (glz::read_json(spoofConfig, buffer)) [[unlikely]] {
LOGE("[preAppSpecialize] spoofConfig parse error");
}
}
close(fd); close(fd);
} }
} }
if (!enabled) return; if (!enabled) return;
if (args->app_data_dir == nullptr) { if (args->app_data_dir == nullptr) {
return; return;
@@ -47,23 +79,18 @@ public:
auto buildClass = env_->FindClass("android/os/Build"); auto buildClass = env_->FindClass("android/os/Build");
auto buildVersionClass = env_->FindClass("android/os/Build$VERSION"); auto buildVersionClass = env_->FindClass("android/os/Build$VERSION");
#define SET_FIELD(CLAZZ, FIELD, VALUE) ({ \ setField(buildClass, "MANUFACTURER", std::move(spoofConfig.manufacturer));
auto id = env_->GetStaticFieldID(CLAZZ, FIELD, "Ljava/lang/String;"); \ setField(buildClass, "MODEL", std::move(spoofConfig.model));
env_->SetStaticObjectField(buildClass, id, env_->NewStringUTF(VALUE)); }) setField(buildClass, "FINGERPRINT", std::move(spoofConfig.fingerprint));
setField(buildClass, "BRAND", std::move(spoofConfig.brand));
SET_FIELD(buildClass, "MANUFACTURER", "Google"); setField(buildClass, "PRODUCT", std::move(spoofConfig.product));
SET_FIELD(buildClass, "MODEL", "Pixel"); setField(buildClass, "DEVICE", std::move(spoofConfig.device));
SET_FIELD(buildClass, "FINGERPRINT", setField(buildVersionClass, "RELEASE", std::move(spoofConfig.release));
"google/sailfish/sailfish:8.1.0/OPM1.171019.011/4448085:user/release-keys"); setField(buildClass, "ID", std::move(spoofConfig.id));
SET_FIELD(buildClass, "BRAND", "google"); setField(buildVersionClass, "INCREMENTAL", std::move(spoofConfig.incremental));
SET_FIELD(buildClass, "PRODUCT", "sailfish"); setField(buildVersionClass, "SECURITY_PATCH", std::move(spoofConfig.security_patch));
SET_FIELD(buildClass, "DEVICE", "sailfish"); setField(buildClass, "TYPE", std::move(spoofConfig.type));
SET_FIELD(buildVersionClass, "RELEASE", "8.1.0"); setField(buildClass, "TAGS", std::move(spoofConfig.tags));
SET_FIELD(buildClass, "ID", "OPM1.171019.011");
SET_FIELD(buildVersionClass, "INCREMENTAL", "4448085");
SET_FIELD(buildVersionClass, "SECURITY_PATCH", "2017-12-05");
SET_FIELD(buildClass, "TYPE", "user");
SET_FIELD(buildClass, "TAGS", "release-keys");
} }
env_->ReleaseStringUTFChars(args->nice_name, nice_name); env_->ReleaseStringUTFChars(args->nice_name, nice_name);
@@ -77,14 +104,41 @@ public:
private: private:
Api *api_; Api *api_;
JNIEnv *env_; JNIEnv *env_;
inline void setField(jclass clazz, const char* field, std::string&& value) {
auto id = env_->GetStaticFieldID(clazz, field, "Ljava/lang/String;");
env_->SetStaticObjectField(clazz, id, env_->NewStringUTF(value.c_str()));
}
}; };
static void companion_handler(int fd) { static void companion_handler(int fd) {
int enabled = access("/data/adb/tricky_store/spoof_build_vars", F_OK) == 0; int enabled = access("/data/adb/tricky_store/spoof_build_vars", F_OK) == 0;
write(fd, &enabled, sizeof(enabled)); write(fd, &enabled, sizeof(enabled));
if (!enabled) {
return;
}
spoof_config spoofConfig{};
auto ec = glz::read_file_json(spoofConfig, "/data/adb/tricky_store/spoof_build_vars"sv, std::string{});
if (ec) [[unlikely]] {
LOGW("[companion_handler] Failed to parse spoof_build_vars, writing and using default spoof config...");
ec = glz::write_file_json<glz::opts{.prettify = true}>(spoofConfig, "/data/adb/tricky_store/spoof_build_vars"sv, std::string{});
if (ec) [[unlikely]] {
LOGW("[companion_handler] Failed to write spoof_build_vars");
}
LOGI("[write_spoof_configs@companion_handler] write done!");
}
std::string buffer = glz::write_json(spoofConfig).value_or("");
size_t bufferSize = buffer.size();
// Send buffer size first
write(fd, &bufferSize, sizeof(bufferSize));
// client resize string stl and receive buffer
write(fd, buffer.data(), bufferSize);
} }
// Register our module class and the companion handler function // Register our module class and the companion handler function
REGISTER_ZYGISK_MODULE(TrickyStore) REGISTER_ZYGISK_MODULE(TrickyStore)
REGISTER_ZYGISK_COMPANION(companion_handler) REGISTER_ZYGISK_COMPANION(companion_handler)