Skip to content

Commit

Permalink
improve target decision compatibility (#5)
Browse files Browse the repository at this point in the history
* clean up the tmp directory

* move target decision to postAppSpecialize

* upload build artifacts
  • Loading branch information
lico-n authored Jul 19, 2023
1 parent e55f451 commit 84af8d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ jobs:
run: |
chmod +x ./gradlew
./gradlew :module:assembleRelease
- uses: actions/upload-artifact@v3
with:
name: ZygiskFrida
path: out/magisk_module_release/
2 changes: 1 addition & 1 deletion module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
moduleName = "ZygiskFrida"
moduleAuthor = "lico-n"
moduleDescription = "Injects frida gadget via zygisk."
moduleVersion = "v1.0.0"
moduleVersion = "v1.1.0"
moduleVersionCode = 1
modulePackageName = "re.zyg.fri"

Expand Down
24 changes: 8 additions & 16 deletions module/src/jni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,28 @@ class MyModule : public zygisk::ModuleBase {
this->env = env;
}

void preAppSpecialize(AppSpecializeArgs *args) override {
auto raw_app_name = env->GetStringUTFChars(args->nice_name, nullptr);
this->app_name = std::string(raw_app_name);
void postAppSpecialize(const AppSpecializeArgs *args) override {
const char* raw_app_name = env->GetStringUTFChars(args->nice_name, nullptr);
std::string app_name = std::string(raw_app_name);
this->env->ReleaseStringUTFChars(args->nice_name, raw_app_name);

std::string module_dir = std::string("/data/local/tmp/") + ModulePackageName;
this->gadget_path = module_dir + "/" + GadgetLibraryName;
std::string gadget_path = module_dir + "/" + GadgetLibraryName;

this->inject = should_inject(module_dir, this->app_name);
if (!this->inject) {
if (!should_inject(module_dir, app_name)) {
this->api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);
return;
}

LOGI("App detected: %s", this->app_name.c_str());
}
LOGI("App detected: %s", app_name.c_str());

void postAppSpecialize(const AppSpecializeArgs *) override {
if (this->inject) {
std::thread inject_thread(inject_gadget, this->gadget_path, this->app_name);
inject_thread.detach();
}
std::thread inject_thread(inject_gadget, gadget_path, app_name);
inject_thread.detach();
}

private:
Api *api;
JNIEnv *env;
bool inject;
std::string gadget_path;
std::string app_name;
};

REGISTER_ZYGISK_MODULE(MyModule)
2 changes: 2 additions & 0 deletions template/magisk_module/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mkdir -p \$TMP_MODULE_DIR

cp \$MODPATH/gadget/libgadget-\$ARCH.so.xz \$TMP_MODULE_DIR/${gadgetLibraryName}.xz
/data/adb/magisk/busybox unxz \$TMP_MODULE_DIR/${gadgetLibraryName}.xz
rm \$TMP_MODULE_DIR/${gadgetLibraryName}.xz

touch \$TMP_MODULE_DIR/target_packages

set_perm_recursive \$TMP_MODULE_DIR 0 0 0755 0644

0 comments on commit 84af8d9

Please sign in to comment.