Don't use shell context to getprop (#1362)

* [core] Getprop

* [app] Remove getprop
This commit is contained in:
Howard Wu 2021-11-08 02:25:01 +08:00 committed by GitHub
parent 8c593f725a
commit 971bcc6946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 9 deletions

View File

@ -222,17 +222,9 @@ public class LogsFragment extends BaseFragment {
}
});
try (var is = Runtime.getRuntime().exec("getprop").getInputStream()) {
os.putNextEntry(new ZipEntry("system_props.log"));
FileUtils.copy(is, os);
os.closeEntry();
} catch (IOException e) {
Log.w(TAG, "system_props.log", e);
}
var now = LocalDateTime.now();
var name = "app_" + now.toString() + ".log";
try (var is = Runtime.getRuntime().exec("logcat -d").getInputStream()) {
try (var is = new ProcessBuilder("logcat", "-d").start().getInputStream()) {
os.putNextEntry(new ZipEntry(name));
FileUtils.copy(is, os);
os.closeEntry();

View File

@ -170,6 +170,11 @@ public class ConfigFileManager {
return logDirPath.resolve(getNewLogFileName("modules")).toFile();
}
static File getpropsLogPath() throws IOException {
createLogDirPath();
return logDirPath.resolve("props.log").toFile();
}
static Map<String, ParcelFileDescriptor> getLogs() {
var map = new LinkedHashMap<String, ParcelFileDescriptor>();
try {

View File

@ -796,6 +796,7 @@ public class ConfigManager {
}
public boolean isAddShortcut() {
Log.d(TAG, "Auto add shortcut=" + autoAddShortcut);
return autoAddShortcut;
}

View File

@ -3,16 +3,20 @@ 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.File;
import java.io.IOException;
import java.io.InputStream;
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;
public class LogcatService implements Runnable {
private static final String TAG = "LSPosedLogcat";
@ -102,6 +106,39 @@ public class LogcatService implements Runnable {
start();
});
thread.start();
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 propsLogPath = ConfigFileManager.getpropsLogPath();
Files.copy(is, propsLogPath.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException | InterruptedException e) {
Log.e(TAG, "getprop: " + e);
}
}
public void startVerbose() {