tdx解压临时
2021-12-19 本文已影响0人
代码很玄学
Test实例:
package cn.itwoods.core.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import sun.nio.cs.ext.GBK;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
import java.nio.charset.*;
import java.util.Set;
import static org.assertj.core.api.Fail.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Slf4j
public class ZLibUtilsTest {
@Test
public void test8() throws IOException {
String hexStr = "789c55550b5054e719fdfebbef65f9f7ee655d965dd86505591e02fb107617b48ae68101d6901854e8c46951eb4cd549c7d6186b476061e5a1f288bc5156414005415171a59256db686948da48b1a2898d364a8a9836be5fa5dfae4d32f9effcbb33e7ce9c3973be73be0ba00130992cc9764bbce0846803009caaf898de17b9fa455552da732ba3714878e897d0f59918ee8baa8b822047e843017e2104d00401dc5b00f0c95af8ee6c2100fbf19f40bc80249bcc36877d0bd343c7481ae4163cefa053f4fd0276a734aeeb5f994d3b24a7ef0ac133658129daee12408e5c87f03ba2fd313f0f58c9e607df8878ac3387bee02dc61b8677395e06b6307e6e936954dc2c79371b56d71475d22b929e9e6d2daa0beb3867c9786ad7c54570625f385c91543c50c298e823848774eb593b7b396059b0de60d46f0c7f419dfa7fe9017ed9a362a44e322799d731c78d133cc4bc373ae83de3e0055e33f344b72bb3e64be6603e343418e19e71e03e0375013ed40e9b660184c602dc4f01a8b47fef4829de02bfea750c7a6db69a6d56d2b3664ce2c37b46e8d49a230b3a99cfcf7e925160ee95c3c9af284cad692ce7814add8720409902e07814c0c45c8018e70bd29f31006368f53e1428062bf10dd1929c7406bcdaebf80a8e3f1ca18fb59da5a48ff93a724346d3d69d32182ae2c163ede96b3a1893fa4080011d404832800b87f82cfe7bc97b90229bf8dc3803e886c9ea485ecf6f14acc457bbdd9df4b2a0ec1cd7cfffdbc0ab9967c6e53b2618e86f0f82cb821d97e32047bc0f61809b8100230600e9cb00354ef8c159edff5dcf07ab098f792beb895fbb2261f5ce9b23142a2b7575e15f7e16e7ac18a6c57f9443458910487c056f0c6e22182087c022e532facfe8266d4fe8bc0880c5c8b41152c00e9910014fa619d8cafab2e130d9efd23af655a7ecf5faa71d748c757f14db144b277bb26af72a8ff5a848533a90f2f0c3a21c251fc16391f365ef0418f45b66bcab69d72485f1c80ba96ad08201e2408a5edca53ec149268b57d16d5f56488698a5855750f2e0f5e4cad8afe1bcb3a43164e04f61e0e90d02929290c3ae25e79d2f4b1fc8dbd8d0196e437478d7ace75a741b62f0d60105161f213e5e85cfe424bb69943dae4b4fb7e77a6f63e274071e191ae30e3fe2393d93f2929d1c949ec212196b3955403f826eaa15f52a1e4a8bf541da84d90b3078d7e135546b86449881770aad18653117a6a4647b8da2bc81f729192555e47371dbd3613adcc0ab9f9078b84b9e47ceaa49fef6e77cd831c88188574a72028e23b83264c58c7bf2f7b823a173f579ea1b6114c6d08c62980b5e888597e0c634811a858fde61b3c939976d3175911f1fba3a42cfd9da6f271e7c5b21e870b697a80b6f0543e9635e1ad88bf975721382dfc89a65a66013b77166b6c631f3a79891f3b0193df9144d6e05153c9de6839cf3c7ce66990a3cace32d0ec93af29f0e3aa96b7b202d92c60d1bb3aa2f086a8e0860673101c213d78902117b22d828592a4c093428d7859eb189be6be00cf0400ee4c2c36980a9405f51cc499685ec6e8e2f566736167e4c4739f787738fe50927a5ce8a8699833d1a683d2c498352e6247f4ce043f9bc8bea4bd2d95c8de60dfdaa9818e3ebc89a017390d50b0b311cbe6e2ff4a50e259bcb386fa444149ed652d9491f4716346ca83d4d2a574c3b9b4f383aaecf814a6f209093bfd9ae1953fe396fda1926490fee9625063dd2fccef0fbc81a430264a3c5e918e84d9007dbe039da5ce633c38a913e435b67cbd9c4974ee342ba36bbbb8fdd15d4756820abfa0fe296db22e8ad41335a9921fe18d787a8593649b705dee38eeaae1af506857fd7e5423704629ef3c08255c17653ffde98634ee53a9647bedd46a6c8f6c1117a7379e5c09ccab75e8b562ca96bd07af786404fbf0a48112355412682a95c9ab692f3c853f4fbc336699d5a07ec0342a2d1e93008c7c7d7c254ff04ed0eab9a6b5d9518d54c36badb51f5aaae2f340311e1b55dce9a4bb4be5c06e5e3d8ef6e61509d622e822d016fca9be96db973667a9459cbe2d28bc750a7a1cf19108c8e335843f50b669bc3c576c94442e9a292e90e3a213bf5efb4a3af64feea2f594d67235a8fe8e06823da51292ea2759c08d1347e6a4844e0a0d2abead3e519138d002f3e5ab1b01712708a13a8d9e59ba1d562b6ebe59d36abb58afcc43dda416fd90a1b645eb19b1eca1aa817551408d2f6fc03a92b18172f47d186683cbf5cf2234975d01d7549746c64b4f5dbe069c0854571c07fd169bddcdf4447f20669cb015eb7b080e9133c1055df19a6570ff0765c646a89d110e02c1926a565043c75b8fc19812ad88cd89b3457794e7a50394f9d17795fd3e1db1da0c79b8d5589060e7c8b6a83d4b799ac76eb38ed5569d4b18b869ee15efae099ae68560a3996d57b8badaea53074ce1790a05d823a6e36a22a613b8d129f55ee0f6d8bfa42ef4af856f629a88057d0115faac7fd2bcf6c4dae67fb8d56bd87c0e94964deebd2d724b077429d2ded0ad7b54068fa3b0ea64a302050c99f4c853a4b44ab940932ad2a5bfb96f11b5d016ee95e888279908f534c81f9186a3ed4fbfb9294e470738d1637d13591fcdf16e2a7c5d25998df3d4856bd17bae4831b095d7bb031c51a20fb98ed8c8af70cd1a5b21cf94d793eab0c1b0f9f13658fa88204128ffb2e099db6c02ce061c2ddfe88d84cd6cd9cdbde44dc643f59d479b1837e683ff8d70ccf1ee2ae152c291b89f5141bc0f394a6c1fbd213f355c23e44c3d9875199015fb1bf56c7854258ae2e062e8215fb9287ddd90d6ff84dd9ccfd0fa3889f0f";
byte[] bytes = hexStr2bytes(hexStr);
byte[] decompress = decompress(bytes);
String gbk = new String(decompress, "gbk");
String s1 = Hex.encodeHexString(decompress);
log.debug("tdx:{}", s1);
}
/*
* 十六进制字符串转byte[]数组
*/
public static byte[] hexStr2bytes(String hexStr) {
byte[] bytes = null;
try {
bytes = Hex.decodeHex(hexStr.trim());
} catch (DecoderException e) {
e.printStackTrace();
}
return bytes;
}
/**
* 解压缩
*
* @param data 减缩数据
* @return byte[] 解压缩后的数据
*/
public static byte[] decompress(byte[] data) {
byte[] output = new byte[0];
Inflater decompresser = new Inflater(false);
decompresser.setInput(data);
int i = 0;
try (ByteArrayOutputStream o = new ByteArrayOutputStream(data.length)) {
byte[] buf = new byte[1024];
while (!decompresser.finished()) {
i = decompresser.inflate(buf);
o.write(buf, 0, i);
}
decompresser.end();
output = o.toByteArray();
} catch (Exception e) {
output = data;
e.printStackTrace();
}
return output;
}
}
附上一个解压后的hex串
00001a00003030323638322d05b5076e000000b88bce0ef50783b307900a0eade74b99be06aa7400a8dd0800f5079182130056060eade74b0000710600001a130000f4400000cf68000000000000000000007a010000a200000001002d05013630313739387a02ad0ed60141005a80fda60eed0e9380108d0a2ba8ea4c9a8c09baf30600a0ed3200ed0ea4830500560f1ea8ea4c7007a2296b0b5f106317e323f91e311c000000000000840000001d0000005800000002007a0201363031373030d4089b09775100659282a70edb09adad7f9c16c86c124e85da3ba8d34300b5a12000db098bf61400d607cc6c124ebe1e6d103810d90b57171f21271f73200000000000003b000000000000000b0000000100d408013630353135316c02b427e803000000b9e3a60ef427bbc8039b02fa1e8e4c92e502a9630098982700f427b7f50200960bfa1e8e4c3800762500001c2a0000f53a00008f3800000000000000000000880000008000000002006c02003030313331373301ad66d60900000080adcd0eed66ae40a702dec2cf4b8031af0f00b6e90e00ed66998a03001618b0c2cf4b000089110000b4260000e83c0000294e00000000000067020000d6010000a10300000800330100303032323635bd00b91be202000000b4f7cd0ef91ba78801b002ef246e4b9a7c8d0c00be820300f91bbadf1e00d60aef246e4b0000b71e00001936000083400000fc2d000000000000000000009d020000510100000100bd00013630303339366d0499055f0000009486a70ed90589c312b304d5b7474cbdda0f8ce80200b3a41300d9058cd92b005608a1b7474c0000e60d0000cd2100000a450000924e00000000000000000000000000006500000000006d04003330303030317c10a02d68592e658de6cd0e008f8f1e9620e5dd2b4e8bca0e84c50f008b850600012d8b03d600e6dd2b4e0b0f000d8214570ee4289a1bad1c3d2300004900000073003a0038004c002300faff02007c1001363031393038f30e9610474e0c5097fba60ed61086cc2a9a2a0eebad4d959e14b2ad16019a4800018a20ab07561404ebad4db2243f0c700b211f7a15771aa41a351d030100000000000018001b0021002b000a000100f30e00333030353032b911ac38578101be025481dbcd0e00bbe2368f2aef00c74e859919b7c91d00a0af1300013a2e56106801c74e450af60fa3101c1586212820a825fd1b360000002900000096000e001000100006000600b91101363030353830d410b41e4848385ab9eca60ef41ea5f821992babf8034ea0eb0f858d120088b8014100279512160bb3f8034e860e1b07af11f70a841f131b2e2c402a0000e2004a001b0031002f0015002f00edff0200d4100030303035363892118a9803d201d4019001de08a3fbca0eca980397e809a012d7a0f84e90eb0487fd04008cbb120007038801560bb4a0f84e5f195915f40f7912ae1c3c1f5b18e31d0e00d600180084003c00b9002a004400e3ff01009211003030303937370f128337490e83015caadccd0ec337a4ec2fa95e1105a64ea4851881e7170088f9034100388404960f3005a64ef20c9b0c301730127322511a392262210000c70078002900d2000a009f001600fbff04000f1201363030333732ed0dab1e0349194daef1a60eeb1ea3f60a820a2bca274d91c80592ae05008d84010001030896070dca274dfa05730954063a0d21146c1cbd37073800000000000000001500a00056005a00f7ff0000ed0d00303032313532421094120408184c9981ce0ed41286c63cb25b06eb0a4e8b9822bbad1a009fab0941008802b604d60506eb0a4e0403d318d70a2c12921a521f64292927500000004b0034005600b90042002b00000002004210013630303033318912b924090720419c8fa70ef92480986e95ba018f59ff4e9bb539a6e234008fb90d0001b67d871ad614cb5bff4e1d094817ac0c2f13f81ac021c12492212e0051003c0048003a0076005b007f00fdff0100891201363033303139bd0e9f2c0f102f44bae3a60edf2cacb0108e13a8aab74d91c4089cec0700af920100019f02be04d612b0aab74d310ceb0e7f0df412b11edc271f211120000000005a00ac000d0021005b003200faff0100bd0e003030323234313b12a658245ea301ed0187bbcd0ee6588fb7348f554a28114f96981bb99e1900adb316000182020a16004c28114f3b12411b8f12a00f3a1fa21d761b4e1b3900a1000101280015001d0020002000faff02003b120136303038393318129f642f269b017386a4a60edf64a8e11ab7232095a84e92d70e978a0c008ada060001ac061396113c95a84e9c0b530f9b0eec0f4e224826311b102600002d004a004100b9004b0017003400020001001812013630303837398310a80c07060a4385ffa60ee80cb8f041b1464c75d04d9ac2239fae1e00b1990100018f08820e96120775d04d41043b19230dbb14b916b01e5b272f2700006800000000002a009e002e004200e8ff02008310013630333231381f0fa737333390016186d4a60ee73781980cb908860eaa4db797078b8005419de00100018b0283035611a30eaa4d2d048a093e099113ee1885282a24283300000000000000001a00830044003900feff01001f0f003030303539366e0a9ca503ac068002b005f60791eeca0edca5038cd302950127210b4e85ca0188890100a0960300160205161731210b4e530e5a14c30aa9143d185b24f51aa629000000001f0000005100160028001200010000006e0a00333030333833da0eaf161a182a43befccd0e00bffc1e82253a01b24dafe71091950e00bec30100019f138e0596122c01b24d1606a40e2608c214a21ca326e11f832e0000000000000000b8008b004600420000000200da0e003330303133369710b327331fa00100baebcd0e009e831f922e10ee1c4e9ca41183df0d009ad80200019005b705160ffaed1c4e850764142e0c1b16511b5527f21e80230000af0026003d0063004b003a003f00fdff04009710013630303535398612993286011e9a0163bc81a70ed932a78163acbb0164791c4fbfe32ea89d34008f841a0001a10287021603fc791c4f540c560fe60f6310141dda203426382390002e012d002f00350039003200250003000d00861201363030373033781286389a018601a20143a7d3a60ec638a9d14ba09d018695054f89cd2aa0842100a0fb0e4100930ab53f1606b095054f2010f7264c0be9107b182b1c001d5a1e2900d30033005b005b005a0094005200000002007812