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
Related
I wrote a simple program in C that displays the string. I compiled it for the ARM architect and sent it via FTP to my rooted Leagoo M5.
I mounted the memory as RW and moved the program to /data/local.
I used 'chmod + x armexe' to add execute attributes. Despite this, after executing './armexe' the message './sh: ./data/local/armexe: No drunk file or directory' pops up.
This section from the terminal probably shows it best:
root#M5:/data/local # ls && ./armexe
armexe
tmp
sush: ./armexe: No such file or directory
This error seems strange to me, and somehow I could not find the answer to other forums.
Sorry for my English. I hope you understood me :)
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
I installed androguard to help me analyze my own apps to verify that proguard is doing its job (like removing Log.* messages.)
It works well in general, but I have a problem with commands with long outputs. Two examples are with AnalyzeAPK():
get_strings()
get_classes_names()
When I run these commands, I get a bunch of output relating to the support library, and it abruptly ends with an ellipsis before getting to the classes or strings that I created:
u'Landroid/support/v7/graphics/drawable/DrawerArrowDrawable;',
u'Landroid/support/v7/text/AllCapsTransformationMethod;',
...]
The same thing happens trying to dump the strings.
My question is - what do I have to do to get the full output of the commands?
Fedora 25 - Python 2.7.13 - ipython 5.0 - Androguard 3.0dev
The failure message:
failed to copy 'D:\My Documents\桌面\hello你好.txt' to '/storage/sdcard0/hello你好.txt': Invalid argument
The other problem I have suffered from is similar to this one, which the message displayed in the command line "adb shell ls" is weird and totally wrong when it comes to chinese file items, however the english items are displayed normally.
android
test.txt
鎴戠殑鐓х墖
鎴戠殑瑙嗛
鎴戠殑闊充箰
root#android:/storage/sdcard0 #
The first problem is:
D:\My Documents\桌面\hello你好.txt
The above path format is for Windows. And:
/storage/sdcard0/hello你好.txt
path format is for *NIX.
You could try replace D:\My Documents\桌面\hello你好.txt with D:/My Documents/桌面/hello你好.txt or /D/My Documents/桌面/hello你好.txt.
The second problem is because the encoding, try change your Terminal encoding.
I'm getting below error with systrace tool provided by android Jelly bean SDK on windows 2003 PC with python 2.7
executing below command in cygwin editor
python systrace.py --time=10 -o mynewtrace.html
▒GS{▒&▒izAr ▒▒9▒Zww▒▒▒Hj▒▒K▒[X▒▒▒4▒i▒▒D▒▒#▒"▒▒▒]▒lJ▒!▒▒)K▒dKY▒▒:\▒?▒ ▒?w%{D▒g▒?Q&▒wQ▒▒p%'T▒▒oE▒(▒:▒▒k▒▒◄▒▒)▒2▒?▒%▒▒4▒w^▒ ▒~▒▒/▒g▒7?M?▒c▒r#/▒oDE▒tg▒▒N▒▒S'\▒▒▒▒↓▒▒GY▒x▒↓▒2D'↓CN▒{▒f2?pu▒▒?▒▒▒▒(g▒▒9▒f▒<A▒Hz▒+P/▒▒sTU▒b▒?{▒/▒▒▒▒4u_▒▒?▒!0▒▒▒▒1▒▒▒▒#1 ▒▒▒s ▒↓
Y▒;♥♥▒▒3G▒H ▒▒&v▒▒:♦▒{▒▒*▒?7▒▒=▒"▒♥▒▒▒▒▒♥▒▒▒<▒:n?♥<i▒▒► ▒v/▒▒↓▒/♣c▒.▒)#Ou/▒▒O▒▒?▒▒▒%▒A,4+▒x▒▒▒#▒*gfσ▒7▒♣▒▒EtV▒3▒▒▒▒▒r♦▒kQ▒a♦↓▒▒|/:Iy▒{▒◄x8y▒▒▒h▒M▒▒▒G|▒▒"#⌂▒▒gK-▒▒▒'▒▒(▒▒FfN▒▒▒▒▒↑▒▒~4▒⌂▒T?r▒▒▒▒▒▒!▒?▒?▒▒▒▒~CaO▒
ho▒▒L▒H▒9▒▒▒Lh▒▒▒iY▒$4▒d▒▒.C▒▒►#!↓↑▒▒▒▒RQ▒;c▒▒▒?#3▒g▒▒▒▒?G▒y▒▒?Fb▒B=▒▒W|▒%Zc▒▒Q▒UY?♣▒c▒▒$v▒▒▒?▒8▒4v▒h▒▒▒I↑▒`▒Kb▒,▒▒Y▒▒#▒+▒▒▒▒=▒▒▒▒▒▒▒▒
e▒*▒e⌂▒▒"▒P▒!↑▒}▒n♦▒IW ▒▒▒
▒⌂▒)♠K▒?ln▒D♠:z▒:♥▒xA>▒▒LGX↑▒O▒▒W9Z▒▒p▒8▒xG$?▒▒;▒,▒M▒▒▒▒`▒kH▒▒▒kd9▒4t6▒xQH%o▒▒▒▒▒▒O▒▒▒#▒▒▒x▒3▒▒0◄~▒♦▒▒*#W▒▒▒_▒▒_y▒▒▒04▒▒▒▒P-R2K▒▒▒(?B▒e9▒g▒8M37A4▒▒n▒▒#▒▒m▒I▒.▒=▒3▒c▒▒?▒▒s▒▒▒j▒4e▒▒*E▒Q1N▒▒▒▒▒▒▒qy▒▒▒▒▒▒▒▒▒▒▒▒aN?▒_▒▒▒▒▒28_~▒]e♦▒▒▒▒&g♥v3►p▒p▒`▒J▒/▒X⌂▒{▒▒▒-▒▒▒rI▒%Q▒⌂▒▒q▒▒▒▒?▒▒▒▒/hE▒▒▒?▒▒▒▒▒▒▒7▒6▒W▒j▒▒▒w▒▒O▒▒>▒▒▒▒?▒xy▒▒v▒▒▒⌂?4▒T▒a▒◄▒c▒▒▒O7▒⌂v⌂|▒▒rL▒*▒♠▒▒▒#▒▒▒▒~}▒▒
▒K▒H2▒▒▒^l▒RI▒c^$9S$▒=▒▒BI:▒6cj+▒▒▒#
>▒▒▒&f ▒▒▒$▒▒◄▒?▒r▒C▒Ze♥↓▒%▒▒&▒#6▒CE▒▒◄+G♣-▒▒]▒ ▒▒[c▒b\▒MBhu▒O▒▒2▒!+y▒▒▒▒lDt▒U▒▒e▒I5▒\▒▒=▒▒▒▒▒▒T▒T▒▒▒♦^▒▒v▒k▒?▒-▒▒*▒)▒9▒t?▒▒cq▒,$▒▒▒
▒▒+▒▒OM▒#▒▒▒=?▒,?d;k▒♥p▒▒sd▒w▒▒▒▒▒I▒▒p▒nk▒▒D▒▒J▒Gh▒AJ▒B
▒t▒?%D▒q▒yUfyb▒?▒▒▒o▒/q*▒▒▒%i▒▒▒▒▒?>▒v▒/▒>_-▒▒~▒▒▒▒cu▒▒▒▒▒/▒▒|▒~▒▒v3▒▒▒_▒v▒~y"▒▒?▒▒▒▒▒▒_?▒▒▒/Oj▒>▒▒▒▒~▒\▒▒▒▒▒▒▒#▒▒t▒▒2Z▒K▒8_▒▒▒J▒*▒▒▒▒^a▒▒▒4W-▒▒▒TAn error occured while capturing the trace. Output file was not written.
Any environment variable should be added for python?? if yes which variable has to be added?
Can anyone help me in resolving this issue?
Thanks & regards
The reason it's not working on Cygwin is because the stream coming from the device actually
has two carriage returns before every line feed. You can see this by putting in a call to 'print repr(out) after reading from adb.stdout.
You just need to update systrace.py as follows to work around this:
if sys.platform == 'cygwin':
out = out.replace('\r\r\n', '\n')
else:
out = out.replace('\r\n', '\n')
I posted a patch at https://android-review.googlesource.com/55170 to fix this.