Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 4b0bfe6
Author: j-hc <[email protected]>
Date:   Wed Jan 24 20:13:53 2024 +0300

    v1.11.0

commit c22fdf7
Author: j-hc <[email protected]>
Date:   Wed Jan 24 20:13:09 2024 +0300

    remove detach limit

commit 1a79ead
Author: j-hc <[email protected]>
Date:   Wed Jan 24 00:36:11 2024 +0300

    update readme

commit 2a65607
Author: j-hc <[email protected]>
Date:   Sun Jan 21 18:23:46 2024 +0300

    v1.10.1

commit 651a3c3
Author: j-hc <[email protected]>
Date:   Sun Jan 21 18:16:42 2024 +0300

    Revert "cli: fix some formatting bugs"

    This reverts commit bc7fe37.

commit 30e7dce
Author: j-hc <[email protected]>
Date:   Tue Jan 16 12:44:33 2024 +0300

    v1.10.0

commit 5232554
Author: j-hc <[email protected]>
Date:   Tue Jan 16 12:43:53 2024 +0300

    hook less

commit 563a7b0
Author: j-hc <[email protected]>
Date:   Fri Dec 29 22:16:22 2023 +0300

    loaded log

commit e4e28bd
Author: j-hc <[email protected]>
Date:   Thu Dec 28 19:23:21 2023 +0300

    few checks because some cant read

commit 95daee5
Author: j-hc <[email protected]>
Date:   Sat Dec 23 12:45:51 2023 +0300

    v1.9.1

commit 04287dd
Author: j-hc <[email protected]>
Date:   Sat Dec 23 12:44:13 2023 +0300

    whatever

commit e80c9de
Author: j-hc <[email protected]>
Date:   Fri Dec 22 14:39:16 2023 +0300

    v1.9

commit 283590c
Author: j-hc <[email protected]>
Date:   Fri Dec 22 14:09:02 2023 +0300

    increase detach limit

commit 7e69ad7
Author: j-hc <[email protected]>
Date:   Fri Dec 22 14:06:39 2023 +0300

    update cli and clarify readme

commit bc7fe37
Author: j-hc <[email protected]>
Date:   Wed Dec 13 20:06:00 2023 +0300

    cli: fix some formatting bugs
  • Loading branch information
kazimmt committed Feb 16, 2024
1 parent 28ad224 commit 119802f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 58 deletions.
6 changes: 5 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ assignees: ''

---

**Are you sure you read the [readme](https://github.com/j-hc/zygisk-detach#usage)?**

**Android version and skin (MIUI etc... is MIUI still a thing? idk):**

**Screenshot of Play Store page of the app you are trying to detach:**

**Screenshot of the helper CLI showing detached apps (from Option 2):**

**Logs taken with `su -c logcat -s "zygisk-detach" > /sdcard/log.txt`:**
**Logs taken with `su -c logcat -d -s "zygisk-detach" > /sdcard/log.txt`:**

Not providing this information will get your issue closed
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
Detaches installed apps from Play Store against its aggressive updating policy which ignores the auto-update option user sets.

### How
Hooks libbinder with zygisk instead of applying SQL queries to database files
Hooks libbinder with zygisk

### Usage
* Enable **zygisk** in magisk or [ZygiskOnKernelSU](https://github.com/Dr-TSNG/ZygiskOnKernelSU/releases/tag/v4-0.7.1) module if you are using **KernelSU**
* Enable zygisk in Magisk **or** [ZygiskNext](https://github.com/Dr-TSNG/ZygiskNext) module if you are using KernelSU
* Flash zygisk-detach module
* Reboot
* Run helper cli in termux:
`$ detach` or `$ su -c detach`
* Run the cli in termux: `su -c detach`
or use [zygisk-detach-app](https://github.com/j-hc/zygisk-detach-app) if you dont wanna use the terminal
* Select apps you wish to detach. Changes are applied immediately, no need to reboot.

### Notes
To make the usage portable, zygisk-detach reads `detach.bin` in the magisk module folder (`/data/adb/modules/zygisk-detach/detach.bin`) which means by putting your cli generated `detach.bin` inside the module zip, you can flash and detach apps without needing to run the cli again. You can copy your generated `detach.bin` using the cli or from magisk module folder.
Or the same way you can put a `detach.txt` with the package names inside the module and it will be serialized into a `detach.bin`.
zygisk-detach reads the generated `detach.bin` in the magisk module folder (`/data/adb/modules/zygisk-detach/detach.bin`) which means to make the usage portable, by putting your cli generated `detach.bin` inside the module zip, you can flash and detach apps without needing to run the cli again (for example between switching roms). You can get your generated `detach.bin` using the cli or from magisk module folder.

Or the same way you can put a `detach.txt` with the package names inside the module zip and it will be serialized into a `detach.bin` when flashing
55 changes: 26 additions & 29 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![feature(iter_intersperse, print_internals)]

use std::error::Error;
use std::fmt::{Debug, Display};
use std::fs::{self, OpenOptions};
use std::fs::{self, File, OpenOptions};
use std::io::{self, Seek};
use std::io::{BufWriter, Read, Write};
use std::mem::size_of;
Expand All @@ -12,7 +10,7 @@ use std::process::{Command, ExitCode};
use termion::raw::IntoRawMode;

use termion::event::Key;
use termion::{clear, cursor};
use termion::{clear, cursor, terminal_size};

mod colorize;
use colorize::ToColored;
Expand All @@ -34,22 +32,22 @@ extern "C" {
fn kill(pid: i32, sig: i32) -> i32;
}

struct CLIErr<E: Error> {
struct LocErr<E: Error> {
source: E,
loc: &'static Location<'static>,
}
impl<E: Error> Error for CLIErr<E> {}
impl<E: Error> Debug for CLIErr<E> {
impl<E: Error> Error for LocErr<E> {}
impl<E: Error> Debug for LocErr<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}\r\nat {}", self.source, self.loc)
}
}
impl<E: Error> Display for CLIErr<E> {
impl<E: Error> Display for LocErr<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Debug::fmt(self, f)
}
}
impl From<io::Error> for CLIErr<io::Error> {
impl From<io::Error> for LocErr<io::Error> {
#[track_caller]
fn from(err: io::Error) -> Self {
Self {
Expand All @@ -58,8 +56,7 @@ impl From<io::Error> for CLIErr<io::Error> {
}
}
}

type IOResult<T> = Result<T, CLIErr<io::Error>>;
type IOResult<T> = Result<T, LocErr<io::Error>>;

fn main() -> ExitCode {
std::panic::set_hook(Box::new(|panic| {
Expand Down Expand Up @@ -133,19 +130,18 @@ fn detach_bin_changed() {
}

fn serialize_txt(txt: &str, bin: &str) -> IOResult<()> {
let detach_bin = OpenOptions::new()
let mut detach_bin = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(bin)?;
let mut sink = BufWriter::new(detach_bin);
for app in std::fs::read_to_string(txt)?
.lines()
.map(|s| s.trim())
.filter(|l| !l.is_empty() && !l.starts_with('#'))
{
println!(" '{}'", app);
bin_serialize(app, &mut sink)?;
bin_serialize(app, &mut detach_bin)?;
}
Ok(())
}
Expand Down Expand Up @@ -246,7 +242,7 @@ fn get_detached_apps(menus: &mut Menus, detach_txt: &[u8]) -> Vec<(String, Range

#[cfg(target_os = "linux")]
fn get_installed_apps() -> IOResult<Vec<u8>> {
Ok("package:com.app1\npackage:org.xxx2".as_bytes().to_vec())
Ok("package:com.app1\npackage:org.xxx2\ncom.apppppppp.tooolonnggggtooolonnggggtooolonnggggtooolonngggg".as_bytes().to_vec())
}

#[cfg(target_os = "android")]
Expand Down Expand Up @@ -306,19 +302,18 @@ fn main_menu(menus: &mut Menus) -> IOResult<Op> {
}
}

fn bin_serialize(app: &str, sink: impl Write) -> IOResult<()> {
let w = app
.as_bytes()
.iter()
.intersperse(&0)
.cloned()
.collect::<Vec<u8>>();
let mut f = BufWriter::new(sink);
f.write_all(std::slice::from_ref(
&w.len()
.try_into()
.expect("app name cannot be longer than 255"),
))?;
fn bin_serialize(app: &str, f: &mut File) -> IOResult<()> {
let mut w = Vec::with_capacity(2 * app.as_bytes().len() - 1);
for b in app.as_bytes()[..app.len() - 1].iter().cloned() {
w.push(b);
w.push(0);
}
w.push(app.as_bytes()[app.len() - 1]);
let mut f = BufWriter::new(f);
f.write(&[w
.len()
.try_into()
.expect("app name cannot be longer than 255")])?;
f.write_all(&w)?;
f.flush()?;
Ok(())
Expand All @@ -335,6 +330,7 @@ fn detach_menu(menus: &mut Menus) -> IOResult<()> {
.map(|e| std::str::from_utf8(e).expect("non utf-8 package names?"))
.collect();
menus.cursor_show()?;
let col = terminal_size().expect("could not get terminal size").0 as usize - 2;
let selected = menus.select_menu_with_input(
|input| {
let input = input.trim();
Expand All @@ -345,6 +341,7 @@ fn detach_menu(menus: &mut Menus) -> IOResult<()> {
.contains(&input.to_ascii_lowercase())
})
.take(5)
.map(|s| &s[..col.min(s.bytes().len())])
.collect()
} else {
Vec::new()
Expand All @@ -367,7 +364,7 @@ fn detach_menu(menus: &mut Menus) -> IOResult<()> {
.iter()
.any(|(s, _)| s == detach_app)
{
bin_serialize(detach_app, f)?;
bin_serialize(detach_app, &mut f)?;
textln!(menus, "{} {}", "detach:".green(), detach_app);
textln!(menus, "Changes are applied. No need for a reboot!");
detach_bin_changed();
Expand Down
7 changes: 6 additions & 1 deletion magisk/customize.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/system/bin/sh

if [ -n "$KSU_VER" ] && [ ! -d "$NVBASE/modules/zygisksu" ]; then
abort "You do not have ZygiskNext installed. Bye."
fi

mv -f "$MODPATH/system/bin/detach-${ARCH}" "$MODPATH/system/bin/detach"
rm "$MODPATH"/system/bin/detach-*

Expand All @@ -17,7 +21,8 @@ fi

ALIAS="alias detach='su -c detach'"
BASHRC="/data/data/com.termux/files/home/.bashrc"
if grep -qxF "$ALIAS" "$BASHRC" || echo "$ALIAS" >>"$BASHRC"; then
if [ -d "/data/data/com.termux/files/home/" ]; then
grep -qxF "$ALIAS" "$BASHRC" || echo "$ALIAS" >>"$BASHRC"
ui_print "- Run 'detach' in termux after the reboot"
else
ui_print "- Run 'su -c detach' in terminal after the reboot"
Expand Down
4 changes: 2 additions & 2 deletions magisk/module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=zygisk-detach
name=zygisk-detach
version=v1.9
versionCode=10
version=v1.11.0
versionCode=14
author=j-hc
description=Detaches installed apps from Play Store
updateJson=https://raw.githubusercontent.com/kazimmt/zygisk-detach/master/update.json
8 changes: 4 additions & 4 deletions update.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "v1.9",
"versionCode": 10,
"zipUrl": "https://github.com/kazimmt/zygisk-detach/releases/latest/download/zygisk-detach-v1.9.zip",
"changelog": "https://raw.githubusercontent.com/kazimmt/zygisk-detach/master/README.md"
"version": "v1.11.0",
"versionCode": 14,
"zipUrl": "https://github.com/j-hc/zygisk-detach/releases/latest/download/zygisk-detach-v1.11.0.zip",
"changelog": "https://raw.githubusercontent.com/j-hc/zygisk-detach/master/README.md"
}
28 changes: 13 additions & 15 deletions zygisk/jni/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ using zygisk::ServerSpecializeArgs;

#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "zygisk-detach", __VA_ARGS__)

#define DETACH_CAP 512
static unsigned char DETACH_TXT[DETACH_CAP] = {0};
static unsigned char* DETACH_TXT;
static uint8_t HEADERS_COUNT;

void handle_transact(uint8_t* data, size_t data_size) {
static inline void handle_transact(uint8_t* data, size_t data_size) {
auto p = FakeParcel{data, 0};
if (!p.enforceInterface(data_size, HEADERS_COUNT)) return;
uint32_t pkg_len = p.readInt32();
Expand Down Expand Up @@ -64,7 +63,7 @@ class Sigringe : public zygisk::ModuleBase {

void preAppSpecialize(AppSpecializeArgs* args) override {
const char* process = env->GetStringUTFChars(args->nice_name, nullptr);
if (memcmp(process, "com.android.vending", 19)) {
if (memcmp(process, "com.android.vending\0", 20)) {
env->ReleaseStringUTFChars(args->nice_name, process);
api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);
return;
Expand Down Expand Up @@ -96,7 +95,7 @@ class Sigringe : public zygisk::ModuleBase {
this->api->pltHookRegister(dev, inode, "_ZN7android14IPCThreadState8transactEijRKNS_6ParcelEPS1_j",
(void**)&transact_hook, (void**)&transact_orig);
if (this->api->pltHookCommit()) {
// LOGD("Loaded!");
LOGD("Loaded!");
} else {
LOGD("ERROR: pltHookCommit");
api->setOption(zygisk::Option::DLCLOSE_MODULE_LIBRARY);
Expand Down Expand Up @@ -139,19 +138,18 @@ class Sigringe : public zygisk::ModuleBase {
if (size <= 0) {
LOGD("ERROR: detach.bin <= 0");
return 0;
} else if (size > DETACH_CAP - 1) { // -1 because of the null terminator
LOGD("ERROR: detach.bin > %d", DETACH_CAP - 1);
}
DETACH_TXT = (unsigned char*)malloc(size + 1);
auto r = read(fd, DETACH_TXT, size);
if (r < 0) {
LOGD("ERROR: read companion");
return 0;
}
int received = 0;
while (received < size) {
auto red = read(fd, DETACH_TXT + received, size - received);
if (red < 0) {
LOGD("ERROR: read companion");
return 0;
}
received += red;
if (r != size) {
LOGD("ERROR: read companion not whole");
return 0;
}
DETACH_TXT[size] = 0;
return (size_t)size;
}
};
Expand Down

0 comments on commit 119802f

Please sign in to comment.