Use process builder for logcat

This commit is contained in:
M66B 2023-12-12 17:36:06 +01:00
parent 409d18a8cd
commit 1fa5c7cb59
2 changed files with 9 additions and 17 deletions

View File

@ -247,8 +247,6 @@ public class Log {
public static native void jni_safe_write(OutputStream os, byte[] data);
public static native Process jni_safe_runtime_exec(Runtime runtime, String[] cmd);
public static native long[] jni_safe_runtime_stats();
public static void setLevel(Context context) {
@ -3132,15 +3130,18 @@ public class Log {
attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment);
// https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html#java
ProcessBuilder pb = new ProcessBuilder("logcat",
"-d",
"-v", "threadtime",
//"-t", "1000",
Log.TAG + ":I");
pb.directory(context.getFilesDir());
Process proc = null;
File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
String[] cmd = new String[]{"logcat",
"-d",
"-v", "threadtime",
//"-t", "1000",
Log.TAG + ":I"};
proc = proc = jni_safe_runtime_exec(Runtime.getRuntime(), cmd);
proc = pb.start();
long size = 0;
try (BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()))) {

View File

@ -83,15 +83,6 @@ Java_eu_faircode_email_Log_jni_1safe_1write(JNIEnv *env, jclass clazz,
env->CallVoidMethod(os, mid, data);
}
extern "C"
JNIEXPORT jobject JNICALL
Java_eu_faircode_email_Log_jni_1safe_1runtime_1exec(JNIEnv *env, jclass clazz,
jobject runtime, jobjectArray cmd) {
jclass cls = env->FindClass("java/lang/Runtime");
jmethodID mid = env->GetMethodID(cls, "exec", "([Ljava/lang/String;)Ljava/lang/Process;");
return env->CallObjectMethod(runtime, mid, cmd);
}
extern "C"
JNIEXPORT jlongArray JNICALL
Java_eu_faircode_email_Log_jni_1safe_1runtime_1stats(JNIEnv *env, jclass clazz) {