Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Collect modules in log and close fds (#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Feb 2, 2022
1 parent 253fc2e commit b81caac
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,54 @@ static void getLogs(ParcelFileDescriptor zipFd) throws RemoteException {
Log.w(TAG, name, e);
}
});
var name = "full.log";
try (var is = new ProcessBuilder("logcat", "-d").start().getInputStream()) {
os.putNextEntry(new ZipEntry(name));
transfer(is, os);
os.closeEntry();
} catch (IOException e) {
Log.w(TAG, name, e);
{
var name = "full.log";
try (var is = new ProcessBuilder("logcat", "-d").start().getInputStream()) {
os.putNextEntry(new ZipEntry(name));
transfer(is, os);
os.closeEntry();
} catch (IOException e) {
Log.w(TAG, name, e);
}
}
name = "dmesg.log";
try (var is = new ProcessBuilder("dmesg").start().getInputStream()) {
os.putNextEntry(new ZipEntry(name));
transfer(is, os);
os.closeEntry();
} catch (IOException e) {
Log.w(TAG, name, e);
{
var name = "dmesg.log";
try (var is = new ProcessBuilder("dmesg").start().getInputStream()) {
os.putNextEntry(new ZipEntry(name));
transfer(is, os);
os.closeEntry();
} catch (IOException 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) {
Log.w(TAG, "get log", 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 {
Expand Down
24 changes: 24 additions & 0 deletions daemon/src/main/java/org/lsposed/lspd/service/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -75,7 +76,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

public class ConfigManager {
private static ConfigManager instance = null;
Expand Down Expand Up @@ -1015,4 +1018,25 @@ public void setApi(String api) {
public String getApi() {
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();
}
}

0 comments on commit b81caac

Please sign in to comment.