Switch the getprop context to `u:r:untrusted_app:s0` (#1371)
Co-authored-by: LoveSy <shana@zju.edu.cn> Co-authored-by: 南宫雪珊 <26996262+vvb2060@users.noreply.github.com>
This commit is contained in:
parent
c0c1da28df
commit
0d08926eae
|
|
@ -3,20 +3,23 @@ package org.lsposed.lspd.service;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.SystemProperties;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.util.Log;
|
||||
|
||||
import org.lsposed.lspd.BuildConfig;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LogcatService implements Runnable {
|
||||
private static final String TAG = "LSPosedLogcat";
|
||||
|
|
@ -109,35 +112,33 @@ public class LogcatService implements Runnable {
|
|||
getprop();
|
||||
}
|
||||
|
||||
private static class GetProp implements Runnable {
|
||||
private volatile InputStream is;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Os.setuid(9999); // AID_NOBODY
|
||||
is = new ProcessBuilder("getprop").start().getInputStream();
|
||||
} catch (ErrnoException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getValue() {
|
||||
return is;
|
||||
}
|
||||
}
|
||||
|
||||
private void getprop() {
|
||||
try {
|
||||
var get = new GetProp();
|
||||
var thread = new Thread(get);
|
||||
thread.start();
|
||||
thread.join();
|
||||
var is = get.getValue();
|
||||
var sb = new StringBuilder();
|
||||
var t = new Thread(() -> {
|
||||
try (var magiskPathReader = new BufferedReader(new InputStreamReader(new ProcessBuilder("magisk", "--path").start().getInputStream()))) {
|
||||
var magiskPath = magiskPathReader.readLine();
|
||||
var sh = magiskPath + "/.magisk/busybox/sh";
|
||||
var pid = Os.getpid();
|
||||
var tid = Os.gettid();
|
||||
try (var exec = new FileOutputStream("/proc/" + pid + "/task/" + tid + "/attr/exec")) {
|
||||
var untrusted = "u:r:untrusted_app:s0";
|
||||
exec.write(untrusted.getBytes());
|
||||
}
|
||||
try (var is = new ProcessBuilder(sh, "-c", "getprop").start().getInputStream()) {
|
||||
sb.append(new BufferedReader(new InputStreamReader(is)).readLine());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "GetProp: " + e + ": " + Arrays.toString(e.getStackTrace()));
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
t.join();
|
||||
var propsLogPath = ConfigFileManager.getpropsLogPath();
|
||||
Files.copy(is, propsLogPath.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
Log.e(TAG, "getprop: " + e);
|
||||
var writer = new BufferedWriter(new FileWriter(propsLogPath));
|
||||
writer.append(sb);
|
||||
} catch (IOException | InterruptedException | NullPointerException e) {
|
||||
Log.e(TAG, "GetProp: " + Arrays.toString(e.getStackTrace()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue