Retracing proguard whole logcat with time option - android

I have a logcat generated with the following command:
adb logcat -d -v time > logcat.log
Which results in an output formatted as follows:
01-22 09:03:53.482 D/com.mydomain.myapp.g.a.c( 5255): Some logcat message
Then I retrace with the following command :
.\retrace.bat -regex "(?:.*/)%c(?:.*)" .\mapping.txt .\test.log > .\test_retraced.log
However, the output remains the same as the original file. The manuel seems to refer only to stack trace outputs : https://www.guardsquare.com/en/proguard/manual/retrace
Is it possible to retrace whole file?

After struggling a while with the regex option I came to a simple regex which covers my case (see format above) :
.\retrace.bat -regex "(?:.*/)%c(?:.*)" .\mapping.txt .\test.log > .\test_retraced.log
This regex will only retrace the class names used as tags. You can play around with the regex for you own logging convention. For some reason the "/" is important, if removed it did not match.
The output was such :
01-22 09:03:53.482 D/com.mydomain.myapp.package.package.Class( 5255): Some logcat message

Related

UnicodeDecodeError when reading from terminal process

I am retrieving Logcat of Android device from command line by using adb logcat command. I have no idea of Android device logs encoding (actually trying to find this information for last 3 months) - as there can be many languages in device logs e.g Chinese, Japanese, Arabic or special characters like Emoji or © and more.
My Python3 script looks as follows:
import subprocess
ADB_LOCATION = "/Users/F1sherKK/Library/Android/sdk/platform-tools/adb"
ADB_DEVCE = "-s emulator-5554"
ADB_LOGCAT = "logcat"
LOGCAT_MONITOR_CMD = "{} {} {}".format(ADB_LOCATION, ADB_DEVCE, ADB_LOGCAT)
with subprocess.Popen(LOGCAT_MONITOR_CMD, shell=True,
stdout=subprocess.PIPE, bufsize=1,
universal_newlines=True, encoding='utf-8') as p:
for line in p.stdout:
line_cleaned = line.strip()
# do something with Logcat line
But at some point this line crashes:
for line in p.stdout:
With following error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position
89: invalid start byte
I am not sure anymore where is the error. I think that I am using wrong encoding as I don't know encoding of Android Logcat. Tried various common encodings like UTF-32, UTF-16 or ASCII but it always crashes.
How to fix this or at least make partially work - e.g. make it ignore characters it cannot decode?
Better late than never:
The "problem" is that you have non-decodable bytes in the logcat output. There's nothing wrong from the Python perspective, it's just invalid data.
As far as I can tell, adb logcat output should never be non-decodable bytes. If you're seeing bytes that can't be decoded by UTF-8, then your logcat data is probably just corrupt and your best bet is to clear it and try again:
$ adb logcat -c

Android log deobfuscation/retrace

I need some help with Android log file deobfuscation .
The problem is that if I have an exception like:
...
10-16 10:03:10.488: E/AndroidRuntime(25723): Caused by: java.lang.NullPointerException
10-16 10:03:10.488: E/AndroidRuntime(25723): at proguard.test.a.a(Unknown Source)
...
the retrace return original log but if I paste to log function name and line like:
...
10-16 10:03:10.480: I/ghghghg(25723): Crash in function [proguard.test.a.a() Line : -1 ]
...
the retrace doesn't deofescates that log line.
I know that there is an -regex parameter to retrace command but I can't find any explanation or sample. The Proguard retrace manual is unavailable on http://proguard.sourceforge.net/manual/retrace/usage.html.
How can I configure the retrace to deobfuscate custom lines in log?
The ProGuard manual (online, and also included in the ProGuard distribution) contains an example. It uses java.util.regex syntax with some additional wildcards for class names, etc.
You can try recat. It's a python script based on logcat-color, made exactly for this scenario, on-the-fly logcat deobfuscation (doesn't work on Windows though).

"Run Command" file editing (i.e. " *.rc " files): Echoing to the terminal like Linux?

I am editing the Android phone file "init.tuna.rc" so that it prints to me some basic debugging checkpoint messages so I can analyze how far the phone gets in the boot process.
Does anyone know if you can simply insert the shell scripting syntax for console printing into a "run command" file (.rc)?
(I need to know this if someone can help me before I rebuild all of my code for the Android tree to test this debugging code, given the process can a while)
Will the following work? I want to insert in the following code snippet into the "init.tuna.rc" file:
# Boot debugging Checkpoint #2
echo "Check #2: Successfully wrote the file system data, including the wifi directories!"
If this does not work, what can I do to get the "rc" file to print messages to the actual terminal as it executes?
Android Boot Language is documented in a readme.txt file in the source tree under <android>/system/core/init.
No echo is mentioned, but you can try. Also remember that you should write to a file because stderr and stdout are redirected to /dev/null.
See https://github.com/aosp-mirror/platform_system_core/blob/master/init/README.md

how to see more infomation in ndk-gdb when the program breakdown

I use eclipse and ndk-gdb to debug my AndroidNDK program,but i find a problem,the ndk-gdb tools seems do not have the function of "saving the stack" when the program breakdown,i cannot find detail infomation from the ndk-gdb,it does not point which function,which class and which line,just give the info like this:*Program received signal SIGSEGV, Segmentation fault.0xafd0cda4 in memcpy ()
from D:/android/ndk/samples/mango_d/obj/local/armeabi/libc.so*
so , i was wondering if there is a way to see more infomation(the last sentence the program called or others) when the program breakdown,thank you fist
You could try utilize the ndk-stack program, consult to the doc in the ndk, docs/NDK-STACK.html
If you compile the c source by
ndk-build NDK_DEBUG=1 APP_OPTIM=debug
you should be able to call something similar like this one
adb -s %TARGET_INSTALL% logcat DEBUG:I | ndk-stack -sym ./obj/local/armeabi-v7a
that one will give you the source code and line stack trace for the seg-fault.

Android - Can't use traceview

I am trying to use traceview to run some profiling against an Android application. I have wrapped the code that I want to trace with the following lines:
Debug.startMethodTracing("xxx");
// code
Debug.stopMethodTracing();
It successfully generated a trace file, that I pulled from sdcard using the following command line:
./adb pull /sdcard/xxx.trace
However when running traceview like this:
./traceview /.../xxx.trace
I am getting the following error message:
Usage: java
com.android.traceview.MainWindow [-r]
trace -r regression only
I cannot understand this error message and I didn't find anything useful on Google.
Any help would be much appreciated.
Thanks!
make sure that Debug class you imported is this one : android.os.Debug
or do this :
android.os.Debug.startMethodTracing("xxx");
android.os.Debug.stopMethodTracing();

Categories

Resources