diff --git a/README.md b/README.md index de4d832..99f2125 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -# XlogDecoder -微信Mars中的xlog文件解密程序java版本,且增加支持多线程调用 +# Fxxk Python +## XlogDecoder +微信Mars中的xlog文件解密程序java版本 ### 友情链接 微信Mars库源码 [https://github.com/Tencent/mars/](!https://github.com/Tencent/mars/) diff --git a/libs/bcprov-jdk15on-159.jar b/libs/bcprov-jdk15on-159.jar index 9049e56..d34373c 100644 Binary files a/libs/bcprov-jdk15on-159.jar and b/libs/bcprov-jdk15on-159.jar differ diff --git a/src/com/meizu/sysmonitor/Main.java b/src/com/meizu/sysmonitor/Main.java index fe60e44..bc3fd84 100644 --- a/src/com/meizu/sysmonitor/Main.java +++ b/src/com/meizu/sysmonitor/Main.java @@ -13,6 +13,9 @@ public static void main(String[] args) { }else { outfile = args[1]; } + System.out.println("Task start..."); + long startTime = System.currentTimeMillis(); XlogFileDecoder.ParseFile(infile, outfile); + System.out.println(String.format("Task end and spent %d ms",System.currentTimeMillis() -startTime)); } } diff --git a/src/com/meizu/sysmonitor/XlogFileDecoder.java b/src/com/meizu/sysmonitor/XlogFileDecoder.java index 7997c64..ee9bb07 100644 --- a/src/com/meizu/sysmonitor/XlogFileDecoder.java +++ b/src/com/meizu/sysmonitor/XlogFileDecoder.java @@ -4,10 +4,11 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; -class RetData{ +class RetData { int startpos; int lastseq; - public RetData(int startpos, int lastseq){ + + public RetData(int startpos, int lastseq) { this.startpos = startpos; this.lastseq = lastseq; } @@ -41,12 +42,12 @@ private static boolean IsGoodLogBuffer(byte[] _buffer, int _offset, int count) { byte magic_start = _buffer[_offset]; if (MAGIC_NO_COMPRESS_START == magic_start || MAGIC_COMPRESS_START == magic_start || - MAGIC_COMPRESS_START1 == magic_start){ + MAGIC_COMPRESS_START1 == magic_start) { crypt_key_len = 4; } else if (MAGIC_COMPRESS_START2 == magic_start || MAGIC_NO_COMPRESS_START1 == magic_start || MAGIC_NO_COMPRESS_NO_CRYPT_START == magic_start || - MAGIC_COMPRESS_NO_CRYPT_START == magic_start){ + MAGIC_COMPRESS_NO_CRYPT_START == magic_start) { crypt_key_len = 64; } else { System.out.println(String.format("_buffer[%d]:%d != MAGIC_NUM_START", _offset, _buffer[_offset])); @@ -60,12 +61,12 @@ private static boolean IsGoodLogBuffer(byte[] _buffer, int _offset, int count) { return false; } int length = ByteBuffer.wrap(_buffer, _offset + headerLen - 4 - crypt_key_len, 4).order(ByteOrder.LITTLE_ENDIAN).getInt(); - long llength = length&0xffffffffL; - if (_offset + headerLen + llength + 1 > _buffer.length){ - System.out.println(String.format("log length:%d, end pos %d > len(buffer):%d",llength, _offset + headerLen + llength + 1, _buffer.length)); + long llength = length & 0xffffffffL; + if (_offset + headerLen + llength + 1 > _buffer.length) { + System.out.println(String.format("log length:%d, end pos %d > len(buffer):%d", llength, _offset + headerLen + llength + 1, _buffer.length)); return false; } - if(MAGIC_END != _buffer[_offset + headerLen + length]){ + if (MAGIC_END != _buffer[_offset + headerLen + length]) { System.out.println(String.format("log length:%d, buffer[%d]:%d != MAGIC_END", length, _offset + headerLen + length, _buffer[_offset + headerLen + length])); return false; } @@ -77,37 +78,37 @@ private static boolean IsGoodLogBuffer(byte[] _buffer, int _offset, int count) { } } - private static int GetLogStartPos(byte[] _buffer, int _count){ + private static int GetLogStartPos(byte[] _buffer, int _count) { int offset = 0; while (true) { if (offset >= _buffer.length) break; - if (MAGIC_NO_COMPRESS_START==_buffer[offset] || - MAGIC_NO_COMPRESS_START1==_buffer[offset] || - MAGIC_COMPRESS_START==_buffer[offset] || - MAGIC_COMPRESS_START1==_buffer[offset] || - MAGIC_COMPRESS_START2==_buffer[offset] || - MAGIC_COMPRESS_NO_CRYPT_START==_buffer[offset] || - MAGIC_NO_COMPRESS_NO_CRYPT_START==_buffer[offset]){ - if(IsGoodLogBuffer(_buffer, offset, _count)) return offset; + if (MAGIC_NO_COMPRESS_START == _buffer[offset] || + MAGIC_NO_COMPRESS_START1 == _buffer[offset] || + MAGIC_COMPRESS_START == _buffer[offset] || + MAGIC_COMPRESS_START1 == _buffer[offset] || + MAGIC_COMPRESS_START2 == _buffer[offset] || + MAGIC_COMPRESS_NO_CRYPT_START == _buffer[offset] || + MAGIC_NO_COMPRESS_NO_CRYPT_START == _buffer[offset]) { + if (IsGoodLogBuffer(_buffer, offset, _count)) return offset; } offset += 1; } - return -1; + return -1; } - private static RetData DecodeBuffer(byte[] _buffer, int _offset, int lastseq, StringBuffer _outbuffer){ + private static RetData DecodeBuffer(byte[] _buffer, int _offset, int lastseq, StringBuilder _outbuffer) { RetData retData = new RetData(_offset, lastseq); if (_offset >= _buffer.length) return new RetData(-1, lastseq); boolean ret = IsGoodLogBuffer(_buffer, _offset, 1); - byte[] tmpbuffer = new byte[_buffer.length - _offset]; if (!ret) { - System.arraycopy(_buffer, _offset, tmpbuffer,0, tmpbuffer.length); + byte[] tmpbuffer = new byte[_buffer.length - _offset]; + System.arraycopy(_buffer, _offset, tmpbuffer, 0, tmpbuffer.length); int fixpos = GetLogStartPos(tmpbuffer, 1); - if (-1 == fixpos){ + if (-1 == fixpos) { return new RetData(-1, lastseq); } else { _outbuffer.append(String.format("[F]decode_log_file.py decode error len=%d, result:%s \n", fixpos, ret)); @@ -116,14 +117,14 @@ private static RetData DecodeBuffer(byte[] _buffer, int _offset, int lastseq, St } int magic_start = _buffer[_offset]; int crypt_key_len; - if (MAGIC_NO_COMPRESS_START==magic_start || - MAGIC_COMPRESS_START==magic_start || - MAGIC_COMPRESS_START1==magic_start){ + if (MAGIC_NO_COMPRESS_START == magic_start || + MAGIC_COMPRESS_START == magic_start || + MAGIC_COMPRESS_START1 == magic_start) { crypt_key_len = 4; - } else if (MAGIC_COMPRESS_START2==magic_start || - MAGIC_NO_COMPRESS_START1==magic_start || - MAGIC_NO_COMPRESS_NO_CRYPT_START==magic_start || - MAGIC_COMPRESS_NO_CRYPT_START==magic_start){ + } else if (MAGIC_COMPRESS_START2 == magic_start || + MAGIC_NO_COMPRESS_START1 == magic_start || + MAGIC_NO_COMPRESS_NO_CRYPT_START == magic_start || + MAGIC_COMPRESS_NO_CRYPT_START == magic_start) { crypt_key_len = 64; } else { _outbuffer.append("in DecodeBuffer _buffer[%d]:%d != MAGIC_NUM_START", _offset, magic_start); @@ -131,33 +132,33 @@ private static RetData DecodeBuffer(byte[] _buffer, int _offset, int lastseq, St } int headerLen = 1 + 2 + 1 + 1 + 4 + crypt_key_len; - int length = ByteBuffer.wrap(_buffer, _offset + headerLen - 4 - crypt_key_len, 4).order(ByteOrder.LITTLE_ENDIAN).getInt(); + int length = ByteBuffer.wrap(_buffer, _offset + 5, 4).order(ByteOrder.LITTLE_ENDIAN).getInt(); - tmpbuffer = new byte[length]; + byte[] tmpbuffer = new byte[length]; - int seq = (ByteBuffer.wrap(_buffer, _offset + headerLen-4-crypt_key_len-2-2, 2).order(ByteOrder.LITTLE_ENDIAN).getShort())&0x0FFFF; - char begin_hour = (char)ByteBuffer.wrap(_buffer, _offset+headerLen-4-crypt_key_len-1-1, 1).order(ByteOrder.LITTLE_ENDIAN).get(); - char end_hour = (char)ByteBuffer.wrap(_buffer, _offset+headerLen-4-crypt_key_len-1, 1).order(ByteOrder.LITTLE_ENDIAN).get(); + int seq = (ByteBuffer.wrap(_buffer, retData.lastseq + 1, 2).order(ByteOrder.LITTLE_ENDIAN).getShort()) & 0x0FFFF; +// char begin_hour = (char)ByteBuffer.wrap(_buffer, _offset+headerLen-4-crypt_key_len-1-1, 1).order(ByteOrder.LITTLE_ENDIAN).get(); +// char end_hour = (char)ByteBuffer.wrap(_buffer, _offset+headerLen-4-crypt_key_len-1, 1).order(ByteOrder.LITTLE_ENDIAN).get(); - if (seq != 0 && seq != 1 && lastseq != 0 && seq != (lastseq+1)){ - _outbuffer.append(String.format("[F]decode_log_file.py log seq:%d-%d is missing\n",lastseq+1, seq-1)); + if (seq != 0 && seq != 1 && lastseq != 0 && seq != (lastseq + 1)) { + _outbuffer.append(String.format("[F]decode_log_file.py log seq:%d-%d is missing\n", lastseq + 1, seq - 1)); } - if (seq != 0){ + if (seq != 0) { retData.lastseq = seq; } - System.arraycopy(_buffer, _offset+headerLen, tmpbuffer,0, tmpbuffer.length); + System.arraycopy(_buffer, _offset + headerLen, tmpbuffer, 0, tmpbuffer.length); - try{ - if (MAGIC_NO_COMPRESS_START1 == _buffer[_offset]){ + try { + if (MAGIC_NO_COMPRESS_START1 == _buffer[_offset]) { } else if (MAGIC_COMPRESS_START2 == _buffer[_offset]) { byte[] byte_pubkey_x = new byte[32]; byte[] byte_pubkey_y = new byte[32]; - ByteBuffer.wrap(_buffer, _offset+headerLen-crypt_key_len, crypt_key_len>>1).order(ByteOrder.LITTLE_ENDIAN).get(byte_pubkey_x); - ByteBuffer.wrap(_buffer, _offset+headerLen-(crypt_key_len>>1), crypt_key_len>>1).order(ByteOrder.LITTLE_ENDIAN).get(byte_pubkey_y); + ByteBuffer.wrap(_buffer, _offset + headerLen - crypt_key_len, crypt_key_len >> 1).order(ByteOrder.LITTLE_ENDIAN).get(byte_pubkey_x); + ByteBuffer.wrap(_buffer, _offset + headerLen - (crypt_key_len >> 1), crypt_key_len >> 1).order(ByteOrder.LITTLE_ENDIAN).get(byte_pubkey_y); String pubkey_x = CommonUtils.bytesToHexString(byte_pubkey_x); String pubkey_y = CommonUtils.bytesToHexString(byte_pubkey_y); @@ -170,28 +171,40 @@ private static RetData DecodeBuffer(byte[] _buffer, int _offset, int lastseq, St tmpbuffer = CommonUtils.decompress(tmpbuffer); - } else if(MAGIC_COMPRESS_START == _buffer[_offset] || - MAGIC_COMPRESS_NO_CRYPT_START == _buffer[_offset]) { + } else if (MAGIC_COMPRESS_START == _buffer[_offset] || + MAGIC_COMPRESS_NO_CRYPT_START == _buffer[_offset]) { tmpbuffer = CommonUtils.decompress(tmpbuffer); - } else if(MAGIC_COMPRESS_START1 == _buffer[_offset]) { + } else if (MAGIC_COMPRESS_START1 == _buffer[_offset]) { } else { } - }catch (Exception e){ + _outbuffer.append(new String(tmpbuffer,"UTF-8")); + } catch (Exception e) { e.printStackTrace(); _outbuffer.append(String.format("[F]decode_log_file.py decompress err, %s\n", e.toString())); retData.startpos = _offset + headerLen + length + 1; return retData; } - _outbuffer.append(new String(tmpbuffer)); + retData.startpos = _offset + headerLen + length + 1; return retData; } - public static void ParseFile(String _file, String _outfile){ +// public static byte[] teaKey; +// public static byte[] getTeaKey(){ +// if(teaKey == null){ +// String pubkey_x = CommonUtils.bytesToHexString(byte_pubkey_x); +// String pubkey_y = CommonUtils.bytesToHexString(byte_pubkey_y); +// String pubkey = String.format("04%s%s", pubkey_x, pubkey_y); +// teaKey = ECDHUtils.GetECDHKey(CommonUtils.hexStringToByteArray(pubkey), BYTE_PRIV_KEY); +// } +// return teaKey; +// } + + public static void ParseFile(String _file, String _outfile) { FileInputStream fis = null; DataInputStream dis = null; @@ -199,7 +212,7 @@ public static void ParseFile(String _file, String _outfile){ OutputStreamWriter writer = null; BufferedWriter bw = null; try { - //创建输入流 + //创建输入流 fis = new FileInputStream(_file); dis = new DataInputStream(fis); @@ -209,15 +222,16 @@ public static void ParseFile(String _file, String _outfile){ int startpos = GetLogStartPos(_buffer, 2); - if (-1 == startpos){ + if (-1 == startpos) { return; } - StringBuffer outbuffer = new StringBuffer(); + StringBuilder outbuffer = new StringBuilder(); RetData retData = new RetData(startpos, 0); - while (true){ - System.out.println(retData.startpos+":"+retData.lastseq); + while (true) { +// System.out.println(retData.startpos+":"+retData.lastseq); + System.out.println("Working"); retData = DecodeBuffer(_buffer, retData.startpos, retData.lastseq, outbuffer); if (-1 == retData.startpos) break; } @@ -227,26 +241,26 @@ public static void ParseFile(String _file, String _outfile){ os = new FileOutputStream(_outfile); writer = new OutputStreamWriter(os); bw = new BufferedWriter(writer); - bw.write(outbuffer.toString()); + bw.append(outbuffer); bw.flush(); + System.out.println("work finish"); } catch (IOException e) { e.printStackTrace(); - } - finally{ + } finally { try { - if (fis!=null) { + if (fis != null) { fis.close(); } - if (dis!=null) { + if (dis != null) { dis.close(); } - if (os!=null){ + if (os != null) { os.close(); } - if (writer!=null){ + if (writer != null) { writer.close(); } - if (bw!=null){ + if (bw != null) { bw.close(); } } catch (IOException e) {