Skip to content

Commit

Permalink
1,增加zstd解压支持
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanlan123 committed Apr 11, 2023
1 parent 5a6e868 commit 3a11e9b
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 29 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

XLog 的解码服务,可解码不加密、加密两种。可以在UI界面中添加解密私钥。

核心代码来自:https://github.com/wustMeiming/XlogDecoder
核心代码来自:https://github.com/wustMeiming/XlogDecoder,更改了一些代码和增加了zstd支持

已经提供exe包自带jre,可以直接运行。

**兼容 mars-xlog的版本:1.0.5, 1.0.6, 1.0.7, 1.2.3, 1.2.4, 1.2.5, 1.2.6;不支持zstd压缩方式,只支持zip压缩方式**
**支持zstd, zip压缩格式**
**兼容 mars-xlog的版本:1.0.5, 1.0.6, 1.0.7, 1.2.3, 1.2.4, 1.2.5, 1.2.6**

![UI界面一](img/helpOne.jpg)
![UI界面二](img/helpTwo.jpg)
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val releaseVersion = "1.4"
val developmentVersion = "1.4"
val releaseVersion = "1.5"
val developmentVersion = "1.5"

version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion

Expand Down
2 changes: 2 additions & 0 deletions decode-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ dependencies {
implementation("org.bouncycastle:bcprov-jdk18on:1.71")
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation("org.apache.commons:commons-lang3:3.12.0")
// https://mvnrepository.com/artifact/com.github.luben/zstd-jni
implementation("com.github.luben:zstd-jni:1.5.4-2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package top.yinlingfeng.xlog.decode.core;

import java.io.ByteArrayOutputStream;
import com.github.luben.zstd.*;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.zip.Inflater;
Expand Down Expand Up @@ -150,7 +151,26 @@ public static byte[] decompress(byte[] encdata) {
}

public static byte[] zstdDecompress(byte[] encodeData) {
byte[] writeByte = new byte[1];
return writeByte;
// 创建一个ByteArrayInputStream对象来读取压缩数据
ByteArrayInputStream bin = new ByteArrayInputStream(encodeData);
// 创建一个ByteArrayOutputStream对象以写入解压缩后的数据
ByteArrayOutputStream bout = new ByteArrayOutputStream();
// 创建一个ZstdInputStream对象进行流式解压缩
ZstdInputStream zin = null;
try {
zin = new ZstdInputStream(bin);
// 缓冲区大小,可以根据您的需求进行调整
byte[] buffer = new byte[1000000];
int bytesRead = zin.read(buffer, 0, 1000000);
// 将解压缩后的数据写入ByteArrayOutputStream对象
bout.write(buffer, 0, bytesRead);
// 关闭输入、输出流
zin.close();
bin.close();
bout.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return bout.toByteArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.net.URISyntaxException;

public class DecodeTest {

@Test
public void test() throws IOException, URISyntaxException {
test_1_0_5();
test_1_0_6();
test_1_0_7();
test_1_2_3();
test_1_2_4();
test_1_2_5();
test_1_2_6();
test_zip_1_0_5();
test_zip_1_0_6();
test_zip_1_0_7();
test_zip_1_2_3();
test_zip_1_2_4();
test_zip_1_2_5();
test_zip_1_2_6();
test_zstd_1_2_4();
}

@Test
public void test_1_0_5() throws IOException, URISyntaxException {
public void test_zip_1_0_5() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680140145234_20230330_1.0.5.xlog").toURI());
String inFilePath, outFilePath;
Expand All @@ -38,7 +38,7 @@ public void test_1_0_5() throws IOException, URISyntaxException {
}

@Test
public void test_1_0_6() throws IOException, URISyntaxException {
public void test_zip_1_0_6() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680140306482_20230330_1.0.6.xlog").toURI());
String inFilePath, outFilePath;
Expand All @@ -56,7 +56,7 @@ public void test_1_0_6() throws IOException, URISyntaxException {
}

@Test
public void test_1_0_7() throws IOException, URISyntaxException {
public void test_zip_1_0_7() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680140676841_20230330_1.0.7.xlog").toURI());
String inFilePath, outFilePath;
Expand All @@ -74,7 +74,7 @@ public void test_1_0_7() throws IOException, URISyntaxException {
}

@Test
public void test_1_2_3() throws IOException, URISyntaxException {
public void test_zip_1_2_3() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680140788774_20230330_1.2.3.xlog").toURI());
String inFilePath, outFilePath;
Expand All @@ -92,7 +92,7 @@ public void test_1_2_3() throws IOException, URISyntaxException {
}

@Test
public void test_1_2_4() throws IOException, URISyntaxException {
public void test_zip_1_2_4() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680140991265_20230330_1.2.4.xlog").toURI());
String inFilePath, outFilePath;
Expand All @@ -110,7 +110,7 @@ public void test_1_2_4() throws IOException, URISyntaxException {
}

@Test
public void test_1_2_5() throws IOException, URISyntaxException {
public void test_zip_1_2_5() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680141201353_20230330_1.2.5.xlog").toURI());
String inFilePath, outFilePath;
Expand All @@ -128,7 +128,7 @@ public void test_1_2_5() throws IOException, URISyntaxException {
}

@Test
public void test_1_2_6() throws IOException, URISyntaxException {
public void test_zip_1_2_6() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680141337138_20230330_1.2.6.xlog").toURI());
String inFilePath, outFilePath;
Expand All @@ -144,4 +144,23 @@ public void test_1_2_6() throws IOException, URISyntaxException {
XLogFileDecode.ParseFile(inFilePath, outFilePath, privateKey);
Assertions.assertTrue(outFile.exists());
}

@Test
public void test_zstd_1_2_4() throws IOException, URISyntaxException {
String privateKey = "05cb6f67b111a49660d706b15875b1ffc840db68e3545bd2786f02ac9a1233ef";
File inFile = new File(getClass().getClassLoader().getResource("Release_1680767342752_20230406_1.2.4_zstd.xlog").toURI());
String inFilePath, outFilePath;
inFilePath = inFile.getAbsolutePath();
outFilePath = inFile.getAbsolutePath() + ".log";
File outFile = new File(outFilePath);
if (outFile.exists()) {
boolean deleteResult = outFile.delete();
System.out.println("deleteResult:" + deleteResult);
}
System.out.println("inFilePath:" + inFilePath);
System.out.println("outFilePath:" + outFilePath);
XLogFileDecode.ParseFile(inFilePath, outFilePath, privateKey);
Assertions.assertTrue(outFile.exists());
}

}
Binary file not shown.
2 changes: 1 addition & 1 deletion decode-ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ application {
applicationName = 'decode-ui'
mainClass.set('top.yinlingfeng.xlog.decode.ui.XLogDecodeUi')
// The option -XX:+UseG1GC is only relevant for Java 8. Starting with Java 9 G1GC is already the default GC
applicationDefaultJvmArgs = ['-Xms128M', '-XX:MaxRAMPercentage=70.0', '-XX:+UseG1GC',
applicationDefaultJvmArgs = ['-Xms128M', '-XX:MaxRAMPercentage=70.0', '-XX:+UseG1GC', '-Dfile.encoding=utf-8',
'-Dawt.useSystemAAFontSettings=lcd', '-Dswing.aatext=true',
'-Djava.util.Arrays.useLegacyMergeSort=true']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,15 +698,15 @@ private void deleteDecodePrivateKey(String name) {
*/
private void decodeLogDecompressionTypeSelectView() {
//统计提示label
JLabel decodeHintDecompressionLabelTest = new JLabel("解压方式:");
JLabel decodeHintDecompressionLabelTest = new JLabel("支持的解压格式:");
decodeHintDecompressionLabelTest.setFont(commonFont);
contentPane.add(decodeHintDecompressionLabelTest);

//选择日志流式解压方式
selectDecompressionComboBox = new JComboBox<>();
selectDecompressionComboBox.setFont(commonFont);
selectDecompressionComboBox.setEditable(false);
selectDecompressionComboBox.setEnabled(false);
selectDecompressionComboBox.setEnabled(true);
selectDecompressionComboBox.setMaximumRowCount(5);
selectDecompressionComboBox.addItem(DecompressionType.ZIP);
selectDecompressionComboBox.addItem(DecompressionType.ZSTD);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package top.yinlingfeng.xlog.decode.ui;

import com.formdev.flatlaf.FlatLaf;

import javax.swing.*;

public class XLogDecodeUi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public enum DecompressionType {

ZIP("zip流式解压"),
ZSTD("zstd流式解压");
ZIP("zip格式"),
ZSTD("zstd格式");

private String decompressionName;

Expand Down

0 comments on commit 3a11e9b

Please sign in to comment.