本文主要介紹xlog是什么文件格式(xlog可以用什么軟件打開)?,下面一起看看xlog是什么文件格式(xlog可以用什么軟件打開)?相關(guān)資訊。
前面已經(jīng)介紹了將日志打印為xlog文件的xlog。下面是如何將xlog文件解碼成正??勺x的日志文件。
解碼未加密的xlog如果在android代碼中初始化xlog,則使用未加密的方法,如下所示:
xlog.open(false,xlog。級別_調(diào)試,xlog。appednermodeasync 日志路徑dbxlog , );最后一個參數(shù)表示pubkey,null表示日志內(nèi)容沒有加密。
然后可以直接使用mars項目中的decode _ mars _ nocrypt _ log _ file . py文件進(jìn)行直接轉(zhuǎn)換,不過mars提供的python工具是python2版本。目前大部分用的是python3。如果您愿意在本地配置多個python版本,您可以配置python2,添加一些必需的庫并直接執(zhí)行。
如果你不 如果不想配置python2,您希望在python3中執(zhí)行它,或者您可以手動更改這個python文件,這就是我更改的內(nèi)容:
#!/usr/bin/python import sys import osi import glob import zlibimport struct import binasciiiimport tracebackmagic _ no _ compress _ start = 0x 03 magic _ no _ compress _ start 1 = 0x 06 magic _ no _ compress _ crypt _ start = 0x 08 magic _ compress _ start = 0x 04 magic _ compress _ start 1 = 0x 05 magic _ compress _ start 2 = 0x 07 magic _ no _ crypt _ star t = 0x 09 magic _ end = 0x 09 lastseq = 0 def isgoodlogbuffer(_; )magic _ start = _ buffer[_ offset]if magic _ no _ compress _ start == magic_start或magic _ compress _ start = = magic _ start或magic _ compress _ start 1 = = magic_start: crypt _ key _ len = 4 elif magic _ compress _ sta rt2 = = magic _ start或magic _ no _ compress _ start 1 = = magic _ start或magic _ no _ compress _ no _ crypt _ start = = magic _ start或magic _ compress _ no _ crypt _ start = = m agic_start: crypt _ k: r:%d!=魔法數(shù)字開始 % (_offset,_ buffer[_ offset]))header len = 1 2 1 1 4 crypt _ k:返回(fals: % d l: % d ;% (_offset,len(_ buffer)))start = _ offset header len4crypt _ key _ len length = struct . unpack _ from( 我 ,m: start 4]。tobyt:返回(false, log length cho 12@ . com % d,: % d ;% (l:返回(false, 日志長度15@.com%d,緩沖區(qū)[%d]:%d!=魔法終結(jié) % ( length,_offset headerlen length,_ buffer[_ offset header length]))if(1 = count):返回(tru:返回isgoodlogbuffer(_buffer,_ offset headerlen length 1,count1)def getlogstartpos(_ buffer,_count): offs: if offs: break if magic _ no _ compress _ start = = _ buffer[offset]或magic _ no _ compress _ start 1 = = _ buffer[offset]或magic _ compress _ start = = _ buffer[offset]或magic _ compress _ start 1 = = _ buffer[offset]或magic _ compress _ start 2 = = _ buffer[offset]或magic _buff: if _offs: r: r: fix pos = g:),1)if1 = = fixpos: r: _ out buffer . extend( [f]decod: % s \ n % (fixpos,ret[1])_ offset = fix pos magic _ start = _ buffer[_ offset]if magic _ no _ compress _ start = = magic _ start或magic _ compress _ start = = magic _ start或magic _ compress _ start 1 = = magic_start: crypt _ key _ len = 4 elif magic _ compress _ start 2 = = magic _ start或magic _ no _ compress _ start 1 = = magic _ start或magic _ no _ no _ crypt _ start = = magic _ start或magic _ co compress _ no _ crypt _ start = = magic_start:;在decod: % d!=魔法數(shù)字開始 % (_offset,magic_start)) return 1標(biāo)頭len = 1 2 1 1 4 crypt _ key _ len start = _ offset header len4crypt _ key _ len length = struct . unpack _ from( 我 ,m: start 4])[0]tmpbuffer = bytearray(length)seq = struct . unpack _ from( h ,m: start2])[0]begin _ hour = struct . unpack _ from( c ,m: start1])[0]end _ hour = struct . unpack _ from( c ,m: start])[0]global last s: _ out buffer . extend( [f]decod: % d% d丟失\ n % (lasts: last s:]= _ buffer[_ offset header lencho 44@ . com _ offs:解壓縮器= zlib . decompressor obj(zlib。max _ wbits)if magic _ no _ compress _ start 1 = = _ buffer[_ offset]或magic _ compress _ start 2 = = _ buffer[_ offset]echo 46@ 。com打印( 使用錯誤的解碼腳本)elif magic _ compress _ start = = _ buffer[_ offset]或magic _ compress _ no _ crypt _ start = = _ buff: tmpbuffer = decompressor . decompress(bytes(tmpbuffer))elif magic _ compr: decompr: single _ log _ len = struct . unpack _ from( h ,m: 2])[0]decompr: singl:]= tmp buff: len(tmp buffer)]tmp buffer = decompressor . decompress(str(decompr:通行證# _ out buff:%d,houre cho 56@ . com % d% d l: % d decompresse cho 58@ . com % d \ n ;%(s: trace back . print _ exc()_ out buffer . extend( [f]decod: fp = open(_ file, rb )_ buffer = bytearray(os . path . getsize(_ file))fp . readinto(_ buffer)fp . clos: r: start pos = decod: br:返回fpout = open(_outfile, 世界銀行 )fp out . write(out buffer)fp out . clos:全局last s: if os . path . isdir(args[0]): fil: last s:解析文件(args[0],args[0] 。日志 ):解析文件(args[0],args[1]):文件列表= glob . glob( *.xlog )for file path in filelistecho 72@ 。解析文件(文件路徑,文件路徑 。日志 )if _ _ nam: main(sys。argv [1:])其實很簡單。如果在python3中執(zhí)行,主要是因為python3中沒有了buffer()方法。
這是我修改文件的地址(decode _ mars _ nocrypt _ log _ fil
解碼的具體操作直接執(zhí)行,xlog文件作為參數(shù)傳入:
python decode _ mars _ nocrypt _ log _ file . py dbx log _ 20220514 . xlog對加密的xlog進(jìn)行解碼。mars已經(jīng)提供了一個加密工具:gen_key.py,可以直接執(zhí)行該工具獲得一組隨機(jī)的公鑰和私鑰:
通過gen_key.py獲得的密鑰
在android代碼中初始化xlog時,將公鑰傳遞給指定的參數(shù),輸出日志將被加密:
xlog.open(false,xlog。級別_調(diào)試,xlog。appednermodeasync 日志路徑dbxlog , 68 f 0 b 7d 5 c 8 a 792 e1 ea 94 cfc 5 aaad 0 db 0840282 e 2 b 8 f 5 a 82 f 369 a 996 f 681 c 6 cd 1292 f 2d 6d 06712 eaf 735459584819 c4 fa 71 b 94 f 2d 9 bd 53837782 ea 35 aef 52 ef 35 );解碼解密的工具是這樣的:decode_mars_crypt_log_file.py,mars也提供了,但是不能直接使用,里面的密鑰需要修改:
更新密鑰
需要注意的是,mars提供的這個工具也需要python2來執(zhí)行。我已經(jīng)修改成python3了。如果有必要,你可以看看:
#!/usr/bin/python import sys import osi import glob import zlibimport struct import binasciiiimport pyellipticimport tracebackmaric _ no _ compress _ start = 0x 03 magic _no _ compress _ start 1 = 0x 06 magic _ no _ compress _ no _ crypt _ start = 0x 08 magic _ compress _ start = 0x 04 magic _ compress _ start 1 = 0x 05 magic _ compress _ start 2 = 0x 07 magi c _ compress _ no _ crypt _ start = 0x 09 magic _ end = 0x 00 last seq = 0 priv _ key = b ;babff 40958d 0346 b 8 c 602 dff 415 e 082 e 94 ed 5872903 ed 0 ea 2 a3 b 198 cd 3 e 5d 454 ;pub _ key = b 68 f 0 b 7d 5 c 8 a 792 e1 ea 94 cfc 5 aaad 0 db 0840282 e 2 b 8 f5 a 82 f 369 a 996 f 681 c 6 cd 1 ;b 292 f 2d 6d 06712 eaf 735459584819 c4 fa 71 b 94 f 2d 9 bd 53837782 ea 35 aef 52ef 35 ;def tea _ deciph: op = 0x ffffffff v 0,v1 = struct . unpack( ;ll ,v[0:8]) k1,k2,k3,k4 = struct . unpack( ;llll ;,k[0 : 16])d: v1 =(v1(((v 0 4)k3)^(v 0s)^((v 0 5)k4)))op v 0 =(v 0(((v1 4)k1)^(v1 s)^((v1 5)k2)))op s =(sdelta)op return struct . pack( ;ll ,v0,v1)def tea_decrypt(v,k): num = int(l: vi = v[i:i 8]if l: continue x = tea _ deciph:]retdef is goodlogbuffer(_ buffer,_offset,count): if _ offs: return(true, )magic _ start = _ buffer[_ offset]if magic _ no _ compress _ start = = magic _ start或magic _ compress _ start = = magic _ start或magic _ compress _ start 1 = = magic_start: crypt _ key _ len = 4 elif magic _ compress _ start 2 = = magic _ start或magic _ no _ compress _ no _ crypt _ start = = magic _ start或magic _ co mpress _ no _ crypt _ start = = magic_start: crypt _ k:返回fals:%d!=魔法數(shù)字開始 % (_offset,_ buffer[_ offset])header len = 1 2 1 1 4 crypt _ k:返回fals: % d l: % d ;% (_offset,len(_ buffer))start = _ offset header len4crypt _ key _ len length = struct . unpack _ from( 我 ,m: start 4])[0]if _ offs:返回false, log length cho 95@ . com % d,: % d ;% ( length,_offset headerlen length 1,len(_buffer)) if magic_:返回false。;日志長度98@.com%d,緩沖區(qū)[%d]:%d!=魔法終結(jié) % ( length,_offset headerlen length,_ buffer[_ offset header length])if(1 = count):返回(tru:返回isgoodlogbuffer(_buffer,_ offset headerlen length 1,count1)def getlogstartpos(_ buffer,_count): offs: if offs: break if magic _ no _ compress _ start = = _ buffer[offset]或magic _ no _ compress _ start 1 = = _ buffer[offset]或magic _ compress _ start = = _ buffer[offset]或magic _ compress _ start 1 = = _ buffer[offset]或magic _ compress _ start 2 = = _ buffer[offset]或magic _ compress _ no _ crypt _ start = = _ buffer[offset]或magic _ no _ compress _ no _ crypt _ start = = _ buff: if is goodlogbuffer(_ buffer,offset,_count)[0]: return offset offset = 1 return1 def decod: if _offs: r: r: fix pos = g: % s \ n % (fixpos,ret[1])_ offset = fix pos magic _ start = _ buffer[_ offset]if magic _ no _ compress _ start = = magic _ start或magic _ compress _ start = = magic _ start \或magic _ compress _ start 1 = = magic_start: crypt _ key _ len = 4 elif magic _ compress _ start 2 = = magic _ start或magic _ no _ compress _ start 1 = = magic _ start \或者magic _ no _ compress _ no _ crypt _ start = = magic _ start或者magic _ compress _ no _ crypt _ start = = magic_start: crypt _ key _ len = 64 elseecho 117@ 。extend( ;在decod: % d!=魔法數(shù)字開始 % (_offset,magic _ start))return1 header len = 1 2 1 1 4 crypt _ key _ len start = _ offset header len4crypt _ key _ len length = struct . unpack _ from( 我 ,m: start 4])[0]tmpbuffer = bytearray(length)seq = struct . unpack _ from( h ,m: start2])[0]begin _ hour = struct . unpack _ from( c ,m: start1])[0]end _ hour = struct . unpack _ from( c ,m: start])[0]全局lasts: _ out buffer . extend( [f]decod: % d% d丟失\ n % (lasts: last s:]= _ buffer[_ offset header lencho 127@ . com _ offs:解壓縮器= zlib . decompressor obj(zlib。max _ wbits)if magic _ no _ compr:傳球elif magic _ compr: svr = pyelliptic。曲線= secp256k1 )client = pyelliptic。曲線= secp256k1 )start = _ offset header lencrypt _ key _ len cli: int(start crypt _ key _ len/2)]。tobytes()client . pubkey _ y = memory view(_ buffer)[int(start crypt _ k: start crypt _ key _ len]。tobytes()svr . privkey = binascii . unhexlify(priv _ key)tea _ key = svr . get _ ecdh _ key(client . get _ pubkey())tmp buffer = tea _ decrypt(tmp buffer,tea _ key)tmp buffer = decompressor . decompress(bytes(tmp buffer))elif magic _ compress _ start = = _ buffer[_ offset]或magic _ compress _ no _ crypt _ start = = _buff: tmp buffer = decompressor . decompress(bytes(tmp buffer))elif magic _ compr:解壓縮_data = byt: single _ log _ len = struct . unpack _ from( h ,m: 2])[0]decompr: singl:]= tmp buff: len(tmp buffer)]tmp buffer = decompressor . decompress(str(decompr: pass # _ out buff:%d,hour : % d% d l: % d解壓縮: % d \ n ;%(s: trace back . print _ exc()_ out buffer . extend( [f]decod: fp = open(_ file, rb )_buffer = bytearray(os.path。getsize(_ file))fp . readinto(_ buffer)fp . clos: r: startpos = decod: br: return fp out = open(_ outfile, 世界銀行 )fp out . write(out buffer)fp out . clos:全局last s: if os . path . isdir(args[0]): fil: last s:解析文件(args[0],args[0] 。日志 ):解析文件(args[0],args[1]):文件列表= glob . glob( *.xlog )for fil: last s:主(sys.argv [1:])文章標(biāo)簽:
了解更多xlog是什么文件格式(xlog可以用什么軟件打開)?相關(guān)內(nèi)容請關(guān)注本站點。