diff --git a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt index 566f2bf20f..9490279fa8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/EnhancedSessionLogShare.kt @@ -5,6 +5,7 @@ import android.os.ParcelFileDescriptor import android.system.Os import android.system.OsConstants import com.droiddeck.launcher.core.LogRedactor +import com.droiddeck.launcher.frontend.Library import com.droiddeck.launcher.runtime.BattleNet import com.droiddeck.launcher.runtime.LinuxRuntime import org.json.JSONArray @@ -25,6 +26,7 @@ import java.nio.channels.SeekableByteChannel import java.nio.file.FileVisitResult import java.nio.file.Files import java.nio.file.LinkOption +import java.nio.file.NoSuchFileException import java.nio.file.Path import java.nio.file.SimpleFileVisitor import java.nio.file.StandardOpenOption @@ -221,7 +223,7 @@ internal object EnhancedSessionLogShare { Category.values().map { category -> val budget = budgets.getValue(category) val records = ArrayList() - val selected = candidates.filter { it.category == category } + val selected = candidates.filter { it.category == category }.sortedBy(::sharePriority) val zip = File(out, "DroidDeck-${folder.name}-${category.suffix}.zip") ZipOutputStream(zip.outputStream().buffered()).use { archive -> val names = HashSet() @@ -616,7 +618,8 @@ internal object EnhancedSessionLogShare { redactionLearningComplete: Boolean, ) { val entries = JSONArray() - records.take(MAX_MANIFEST_RECORDS).forEach { record -> + val (discovery, rest) = records.partition { it.origin == "discovery" } + (discovery + rest).take(MAX_MANIFEST_RECORDS).forEach { record -> entries.put(JSONObject().apply { put("entry", record.entry) put("origin", record.origin) @@ -680,6 +683,15 @@ internal object EnhancedSessionLogShare { categoryCounts[category] = (categoryCounts[category] ?: 0) + 1 } } + fun addRecentLogs(root: File, entryPrefix: String, origin: String) { + val scan = walk(root, remaining(maxFiles, out.size)) + truncated = truncated || scan.truncated + partial = partial || scan.partial + val base = root.toPath().toAbsolutePath().normalize() + scan.files.asSequence().filter { recent(it) && it.name.endsWith(".log", true) }.forEach { file -> + add(file, root, "$entryPrefix/${base.relativize(file.toPath().toAbsolutePath().normalize()).joinToString("/")}", origin) + } + } CRITICAL_SESSION_FILES.forEach { name -> File(folder, name).takeIf { it.exists() }?.let { add(it, folder, "${folder.name}/$name", "session-critical") } } @@ -713,16 +725,7 @@ internal object EnhancedSessionLogShare { add(source.file, source.root, source.entry, "battlenet") } } else { - battleNetRoots(context).forEach { (prefix, root) -> - val scan = walk(root, remaining(maxFiles, out.size)) - truncated = truncated || scan.truncated - partial = partial || scan.partial - scan.files.asSequence().filter { recent(it) && it.name.endsWith(".log", true) } - .forEach { file -> - val relative = root.toPath().toAbsolutePath().normalize().relativize(file.toPath().toAbsolutePath().normalize()).joinToString("/") - add(file, root, "battlenet/$prefix/$relative", "battlenet") - } - } + battleNetRoots(context).forEach { (prefix, root) -> addRecentLogs(root, "battlenet/$prefix", "battlenet") } } val sessionScan = walk(folder, remaining(maxFiles, out.size)) truncated = truncated || sessionScan.truncated @@ -733,6 +736,9 @@ internal object EnhancedSessionLogShare { if (relative == EnhancedDiagnostics.MANIFEST_FILE) return@forEach add(file, folder, "${folder.name}/$relative", "session") } + val antiCheat = antiCheatRoots(context) + partial = partial || antiCheat.partial + antiCheat.roots.forEach { (appId, root) -> addRecentLogs(root, "anticheat/$appId", "anticheat") } if (SessionPaths.current()?.canonicalFile == folder.canonicalFile && !File(folder, "steam").exists()) { val steam = File(SessionPrefs.activeSteamRoot(context), "logs") val scan = directFiles(steam, remaining(maxFiles, out.size)) @@ -748,7 +754,8 @@ internal object EnhancedSessionLogShare { private fun sharePriority(candidate: Candidate): Int = when { candidate.origin == "session-critical" -> 0 candidate.origin == "session" && candidate.category == Category.GAMES -> 1 - else -> 2 + candidate.origin == "anticheat" -> 2 + else -> 3 } private fun remaining(maxFiles: Int, found: Int): Int = (maxFiles - found + 1).coerceAtLeast(0) @@ -822,6 +829,39 @@ internal object EnhancedSessionLogShare { return ScanResult(files, truncated, partial) } + private class AntiCheatRoots(val roots: List>, val partial: Boolean) + + private fun antiCheatRoots(context: Context): AntiCheatRoots { + var partial = false + val seen = HashSet() + val dirs = runCatching { Library.compatdataDirs(context) }.getOrElse { partial = true; emptyList() } + val roots = dirs.flatMapIndexed { library, compatdata -> + val prefixes = compatdata.listFiles() ?: run { partial = true; emptyArray() } + prefixes.filter { !Files.isSymbolicLink(it.toPath()) }.mapNotNull { prefix -> + val appId = steamAppId(prefix.name) ?: return@mapNotNull null + val root = File(prefix, EAC_LOG_DIR) + val directory = try { + Files.readAttributes(root.toPath(), BasicFileAttributes::class.java, LinkOption.NOFOLLOW_LINKS).isDirectory + } catch (_: NoSuchFileException) { + false + } catch (_: Exception) { + partial = true + false + } + if (!directory) return@mapNotNull null + val base = "$appId/library${library + 1}" + val key = base.takeIf { seen.add(it) } ?: "$base-${prefix.name}".takeIf { seen.add(it) } + if (key != null) key to root else { partial = true; null } + } + } + return AntiCheatRoots(roots, partial) + } + + private fun steamAppId(name: String): String? = + name.takeIf { SIGNED_APP_ID.matches(it) }?.toLongOrNull() + ?.takeIf { it in Int.MIN_VALUE.toLong()..0xffffffffL } + ?.let { (it and 0xffffffffL).toString() } + private fun battleNetRoots(context: Context): List> { val drive = File(BattleNet.prefix(context), "pfx/drive_c") val data = File(drive, "ProgramData/Battle.net") @@ -928,7 +968,9 @@ internal object EnhancedSessionLogShare { val normalized = name.replace('\\', '/').trimStart('/') val parts = normalized.split('/') if (normalized.isEmpty() || parts.any { it.isEmpty() || it == "." || it == ".." }) return null - return parts.joinToString("/") { safeComponent(it) } + return parts.mapIndexed { index, part -> + if (index == 1 && parts[0] == "anticheat" && APP_ID.matches(part)) part else safeComponent(part) + }.joinToString("/") } private fun safeComponent(value: String): String { @@ -941,7 +983,7 @@ internal object EnhancedSessionLogShare { private fun category(entry: String): Category { val value = entry.lowercase(Locale.US) - if (value.startsWith("battlenet/") || value.startsWith("stores/") || value.startsWith("tools/") || value.startsWith("rpcs3/") || + if (value.startsWith("battlenet/") || value.startsWith("anticheat/") || value.startsWith("stores/") || value.startsWith("tools/") || value.startsWith("rpcs3/") || value.contains("droiddeck-esync/") || GAME_LOG.matches(value.substringAfterLast('/')) || listOf("proton", "wine", "dxvk", "vkd3d", "battle.net", "game-debug", "bionic").any(value::contains)) return Category.GAMES if (listOf("wayland", "gamescope", "xwayland", "vulkan", "gpu", "mesa", "egl", "glx", "drm", "compositor", "frame-trace").any(value::contains)) return Category.GRAPHICS @@ -950,7 +992,7 @@ internal object EnhancedSessionLogShare { private val GAME_LOG = Regex("steam-[0-9]+\\.(log|txt)") private val KNOWN_COMPONENTS = setOf( - "steam", "graphics", "games", "battlenet", "client", "agent", "setup", "stores", "tools", + "steam", "graphics", "games", "battlenet", "anticheat", "anticheatlauncher.log", "client", "agent", "setup", "stores", "tools", "droiddeck", "droiddeck-esync", "session.log", "app.log", "wayland.log", "audio.log", "device.txt", "network.txt", "events.jsonl", "memory.csv", "capture.json", "crash.log", "frame-trace.log", "process-trace.log", "game-lifecycle.log", "launches.log", "tools.tsv", "wanted.tsv", "prefixes.json", @@ -961,11 +1003,15 @@ internal object EnhancedSessionLogShare { private val KNOWN_COMPONENT_PATTERNS = listOf( Regex("[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2,}-[a-z0-9-]{1,24}"), Regex("steam-[0-9]+\\.(?:log|txt)"), + Regex("library[0-9]+(?:--?[0-9]{1,10})?"), Regex("(?:battle\\.net-[0-9]+|battle\\.net-setup-[0-9]+|Agent-[0-9]+)\\.log"), Regex("(?:Agent\\.[0-9]+|bna_[0-9]+)"), Regex("stores-[0-9]{4}-[0-9]{2}-[0-9]{2}\\.log"), + Regex("library[0-9]{1,3}"), Regex("entry-[0-9a-f]{16}(?:\\.[a-z0-9]{1,8})?"), ) + private val APP_ID = Regex("[0-9]{1,10}") + private val SIGNED_APP_ID = Regex("-?[0-9]{1,10}") private val SAFE_SUFFIX = Regex("\\.[A-Za-z0-9]{1,8}$") private val CRITICAL_SESSION_FILES = listOf( "session.log", "app.log", "wayland.log", "audio.log", "device.txt", "network.txt", @@ -973,6 +1019,7 @@ internal object EnhancedSessionLogShare { ) private const val RECENT_MILLIS = 7L * 24 * 60 * 60 * 1000 private const val STORE_LOG_SCAN = 512 + private const val EAC_LOG_DIR = "pfx/drive_c/users/steamuser/AppData/Roaming/EasyAntiCheat" private const val COPY_BUFFER_BYTES = 64 * 1024 private const val TRACE_SCAN_BYTES = 16L * 1024 * 1024 private const val LEGACY_LOG_MAX_BYTES = 8L * 1024 * 1024 diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index 94537df59b..eb4a002df5 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.session +import com.droiddeck.launcher.assumeFilePermissionsEnforced import com.droiddeck.launcher.runtime.LinuxRuntime import java.io.File import java.text.SimpleDateFormat @@ -8,6 +9,7 @@ import java.util.Date import java.util.Locale import java.util.concurrent.TimeUnit import java.util.zip.ZipFile +import org.json.JSONObject import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull @@ -144,6 +146,136 @@ class SessionLogShareZipTest { } } + @Test fun theEasyAntiCheatLauncherLogsFromGamePrefixesComeAlong() { + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + val session = File(LinuxRuntime.logDir(app), "2026-12-05-09-steam").apply { mkdirs() } + val out = File(app.getExternalFilesDir(null), "agent-logs/anticheat") + val prefix = File(SessionPrefs.steamRoot(app, SessionPrefs.activeSteamClientArch(app)), "steamapps/compatdata/976730") + val second = File(app.getExternalFilesDir(null), "second-library-${UUID.randomUUID()}").apply { mkdirs() } + val library = SteamLibraries.add(app, second.path) as SteamLibraries.AddResult.Added + try { + File(session, "session.log").writeText("booted\n") + val eac = File(prefix, "pfx/drive_c/users/steamuser/AppData/Roaming/EasyAntiCheat/4815162342").apply { mkdirs() } + File(eac, "anticheatlauncher.log").writeText("[Error] Launch Error: 261\n") + File(eac, "old.log").apply { + writeText("stale\n") + setLastModified(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30)) + } + val secondEac = File(second, "steamapps/compatdata/976730/pfx/drive_c/users/steamuser/AppData/Roaming/EasyAntiCheat/b1d0a8c3").apply { mkdirs() } + File(secondEac, "anticheatlauncher.log").writeText("[Error] Launch Error: 206\n") + val signedEac = File(prefix.parentFile, "-1768546955/pfx/drive_c/users/steamuser/AppData/Roaming/EasyAntiCheat/0a1b").apply { mkdirs() } + File(signedEac, "anticheatlauncher.log").writeText("[Error] Launch Error: 30005\n") + val unsignedEac = File(prefix.parentFile, "2526420341/pfx/drive_c/users/steamuser/AppData/Roaming/EasyAntiCheat/0a1b").apply { mkdirs() } + File(unsignedEac, "anticheatlauncher.log").writeText("[Error] Launch Error: 30007\n") + + val zip = EnhancedSessionLogShare.createLegacy(app, session, outputDirectory = out)!! + ZipFile(zip).use { archive -> + val logs = archive.entries().toList().filter { it.name.startsWith("anticheat/976730/") } + assertEquals(2, logs.size) + assertTrue(logs.all { it.name.endsWith("/anticheatlauncher.log") && !it.name.contains("4815162342") }) + val texts = logs.map { archive.getInputStream(it).bufferedReader().readText() } + assertTrue(texts.any { it.contains("Launch Error: 261") }) + assertTrue(texts.any { it.contains("Launch Error: 206") }) + val aliases = archive.entries().toList().filter { it.name.startsWith("anticheat/2526420341/") } + assertEquals(2, aliases.size) + assertEquals(2, aliases.map { it.name.split('/')[2] }.filter { it.startsWith("library1") }.toSet().size) + val aliasTexts = aliases.map { archive.getInputStream(it).bufferedReader().readText() } + assertTrue(aliasTexts.any { it.contains("Launch Error: 30005") }) + assertTrue(aliasTexts.any { it.contains("Launch Error: 30007") }) + } + } finally { + SteamLibraries.remove(app, library.entry.id) + out.deleteRecursively() + session.deleteRecursively() + prefix.deleteRecursively() + File(prefix.parentFile, "-1768546955").deleteRecursively() + File(prefix.parentFile, "2526420341").deleteRecursively() + second.deleteRecursively() + } + } + + @Test fun theSessionsGameLogComesAlongWhenManyAntiCheatLogsAreFound() { + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + val session = File(LinuxRuntime.logDir(app), "2026-12-05-11-steam").apply { mkdirs() } + val out = File(app.getExternalFilesDir(null), "agent-logs/anticheat-flood") + val compatdata = File(SessionPrefs.steamRoot(app, SessionPrefs.activeSteamClientArch(app)), "steamapps/compatdata") + val prefixes = (0 until 300).map { File(compatdata, "${900000 + it}") } + try { + File(session, "session.log").writeText("booted\n") + File(session, "steam-976730.log").writeText("proton: game started\n") + prefixes.forEach { prefix -> + val eac = File(prefix, "pfx/drive_c/users/steamuser/AppData/Roaming/EasyAntiCheat/0a1b").apply { mkdirs() } + File(eac, "anticheatlauncher.log").writeText("[Error] Launch Error: 206\n" + "x".repeat(64 * 1024)) + } + + val zip = EnhancedSessionLogShare.createLegacy(app, session, outputDirectory = out)!! + ZipFile(zip).use { archive -> + val game = archive.entries().toList().single { it.name.endsWith("/steam-976730.log") } + assertTrue(archive.getInputStream(game).bufferedReader().readText().contains("game started")) + } + } finally { + out.deleteRecursively() + session.deleteRecursively() + prefixes.forEach { it.deleteRecursively() } + } + } + + @Test fun aDiscoveryFailureStaysInTheManifestWhenRecordsPassTheLimit() { + assumeFilePermissionsEnforced() + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + val session = File(LinuxRuntime.logDir(app), "2026-12-05-10-steam").apply { mkdirs() } + val out = File(app.getExternalFilesDir(null), "agent-logs/manifest-limit") + val compatdata = File(SessionPrefs.steamRoot(app, SessionPrefs.activeSteamClientArch(app)), "steamapps/compatdata").apply { mkdirs() } + try { + repeat(300) { + File(session, "part-$it.log").writeText("line $it\n") + File(session, "wayland-$it.log").writeText("line $it\n") + File(session, "proton-$it.log").writeText("line $it\n") + } + assertTrue(compatdata.setReadable(false, false)) + val zip = EnhancedSessionLogShare.createLegacy(app, session, outputDirectory = out)!! + ZipFile(zip).use { archive -> + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")).bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + val reasons = (0 until entries.length()).map { entries.getJSONObject(it) } + .filter { it.optString("origin") == "discovery" }.map { it.optString("reason") } + assertTrue(entries.length() > 512) + assertTrue(reasons.toString(), "filesystem-error" in reasons) + } + } finally { + compatdata.setReadable(true, false) + out.deleteRecursively() + session.deleteRecursively() + } + } + + @Test fun aPrefixThatDeniesTheAntiCheatFolderIsRecordedAsADiscoveryFailure() { + assumeFilePermissionsEnforced() + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + val session = File(LinuxRuntime.logDir(app), "2026-12-05-12-steam").apply { mkdirs() } + val out = File(app.getExternalFilesDir(null), "agent-logs/anticheat-denied") + val compatdata = File(SessionPrefs.steamRoot(app, SessionPrefs.activeSteamClientArch(app)), "steamapps/compatdata") + val prefix = File(compatdata, "976731") + val users = File(prefix, "pfx/drive_c/users").apply { mkdirs() } + try { + File(session, "session.log").writeText("booted\n") + assertTrue(users.setExecutable(false, false)) + val zip = EnhancedSessionLogShare.createLegacy(app, session, outputDirectory = out)!! + ZipFile(zip).use { archive -> + val manifest = JSONObject(archive.getInputStream(archive.getEntry("diagnostics-manifest.json")).bufferedReader().readText()) + val entries = manifest.getJSONArray("entries") + val reasons = (0 until entries.length()).map { entries.getJSONObject(it) } + .filter { it.optString("origin") == "discovery" }.map { it.optString("reason") } + assertTrue(reasons.toString(), "filesystem-error" in reasons) + } + } finally { + users.setExecutable(true, false) + out.deleteRecursively() + session.deleteRecursively() + prefix.deleteRecursively() + } + } + @Test fun everyTextFileInTheZipIsScrubbedAndTheStoresAndToolsLogsComeAlong() { val logs = LinuxRuntime.logDir(app) val session = File(logs, "2026-10-08-01-steam").apply { mkdirs() }