如何使用ProGuard Retrace还原带时间格式的完整Logcat日志?
Short answer: Retrace doesn't automatically process regular Logcat log entries (like the one in your example) out of the box—its default behavior is only to deobfuscate stack trace lines. That's why your current command isn't changing the output at all.
Let's break down what's going on and how to fix it:
Why Your Current Command Isn't Working
Your Logcat entries look like this:
01-22 09:03:53.482 D/com.mydomain.myapp.g.a.c( 5255): Some logcat message
Retrace's default regex is built to match stack trace lines (e.g., at com.mydomain.myapp.g.a.c.someMethod(SourceFile:123)), not the standard Logcat entry format. The custom regex you used ((?:.*/)%c(?:.*)) is too vague—it doesn't properly target the obfuscated class name in your Logcat structure, so Retrace can't identify what needs to be replaced.
How to Deobfuscate Entire Logcat Entries
You can make Retrace process your Logcat logs by defining a precise custom regex that tells it exactly where the obfuscated class name sits in each line.
For your specific Logcat format, use this modified command:
.\retrace.bat -regex "^(\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}) [VDIWE]/%c\(\s*\d+\): (.*)$" .\mapping.txt .\test.log > .\test_retraced.log
Here's what the regex does:
^(\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}): Captures the timestamp at the start of each line[VDIWE]/: Matches the Logcat log level (Verbose/Debug/Info/Warning/Error)%c: The special placeholder Retrace uses to spot the obfuscated class name it needs to deobfuscate\(\s*\d+\): Matches the process ID wrapped in parentheses: (.*)$: Captures the rest of the log message
Critical Notes
- Use the correct mapping file: Your
mapping.txtmust be the exact file generated during the obfuscation of the app build that produced the Logcat logs. Using the wrong mapping will result in no deobfuscation or incorrect results. - Tweak the regex if needed: If your Logcat lines have minor variations (like extra spacing or custom tags), adjust the regex to match your actual log format. The key is placing
%cexactly where the obfuscated class name appears.
Alternative: Use a Custom Script
If Retrace's regex feels too rigid, you can write a simple script (Python, Shell, etc.) to handle deobfuscation manually:
- Parse
mapping.txtto create a dictionary mapping obfuscated class names to their original names. - Loop through each line in your Logcat file.
- Replace any obfuscated class names in the lines with their original counterparts using the dictionary.
This approach gives you more flexibility to handle edge cases or non-standard log formats.
内容的提问来源于stack exchange,提问作者JM Lord

