Collect modules in log and close fds (#1610)

This commit is contained in:
LoveSy 2022-02-02 20:27:21 +08:00 committed by GitHub
parent 253fc2e0d1
commit b81caac913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 14 deletions

View File

@ -226,6 +226,7 @@ public class ConfigFileManager {
Log.w(TAG, name, e); Log.w(TAG, name, e);
} }
}); });
{
var name = "full.log"; var name = "full.log";
try (var is = new ProcessBuilder("logcat", "-d").start().getInputStream()) { try (var is = new ProcessBuilder("logcat", "-d").start().getInputStream()) {
os.putNextEntry(new ZipEntry(name)); os.putNextEntry(new ZipEntry(name));
@ -234,7 +235,9 @@ public class ConfigFileManager {
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, name, e); Log.w(TAG, name, e);
} }
name = "dmesg.log"; }
{
var name = "dmesg.log";
try (var is = new ProcessBuilder("dmesg").start().getInputStream()) { try (var is = new ProcessBuilder("dmesg").start().getInputStream()) {
os.putNextEntry(new ZipEntry(name)); os.putNextEntry(new ZipEntry(name));
transfer(is, os); transfer(is, os);
@ -242,10 +245,35 @@ public class ConfigFileManager {
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, name, e); Log.w(TAG, name, e);
} }
}
var magiskDataDir = Paths.get("/data/adb");
Files.list(magiskDataDir.resolve("modules")).forEach(p -> {
if (!Files.exists(p.resolve("disable"))) {
var prop = p.resolve("module.prop");
if (Files.exists(prop)) {
var name = magiskDataDir.relativize(prop).toString();
try (var is = new FileInputStream(prop.toFile())) {
os.putNextEntry(new ZipEntry(name));
transfer(is, os);
os.closeEntry();
} catch (IOException e) {
Log.w(TAG, name, e);
}
}
}
});
ConfigManager.getInstance().exportScopes(os);
} catch (Throwable e) { } catch (Throwable e) {
Log.w(TAG, "get log", e); Log.w(TAG, "get log", e);
throw new RemoteException(Log.getStackTraceString(e)); throw new RemoteException(Log.getStackTraceString(e));
} }
logs.forEach((name, fd) -> {
try {
fd.close();
} catch (IOException e) {
Log.w(TAG, name, e);
}
});
} }
private static void putFds(Map<String, ParcelFileDescriptor> map, Path path) throws IOException { private static void putFds(Map<String, ParcelFileDescriptor> map, Path path) throws IOException {

View File

@ -55,6 +55,7 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -75,7 +76,9 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
public class ConfigManager { public class ConfigManager {
private static ConfigManager instance = null; private static ConfigManager instance = null;
@ -1015,4 +1018,25 @@ public class ConfigManager {
public String getApi() { public String getApi() {
return api; return api;
} }
public void exportScopes(ZipOutputStream os) throws IOException {
os.putNextEntry(new ZipEntry("scopes.txt"));
cachedScope.forEach((scope, modules) -> {
try {
os.write((scope.processName + "/" + scope.uid + "\n").getBytes(StandardCharsets.UTF_8));
for (var module : modules) {
os.write(("\t" + module.packageName + "\n").getBytes(StandardCharsets.UTF_8));
for (var cn : module.file.moduleClassNames) {
os.write(("\t\t" + cn + "\n").getBytes(StandardCharsets.UTF_8));
}
for (var ln : module.file.moduleLibraryNames) {
os.write(("\t\t" + ln + "\n").getBytes(StandardCharsets.UTF_8));
}
}
} catch (IOException e) {
Log.w(TAG, scope.processName, e);
}
});
os.closeEntry();
}
} }