Guest User

Untitled

a guest
May 22nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. public class WZTool {
  2. private static Logger log = LoggerFactory.getLogger(WZTool.class);
  3. public static String text = "";
  4. public static byte key[] = HexTool.getByteArrayFromHexString("e9 59 6c 6c 41 18 5c af a1 b7 b5 de 7c 89 d5 15 47 13 23 56 ad b0 1 a0 af 5c 1 e6 81 b6 34 2f 97 1c 96 be 3a 98 5b de 84 1c d5 31 60 86 22 8d 9f d2 94 90 7d 81 11 a2 ea bf 81 b3 b9 17 32 31 87 8 71 dd 3b 6c b3 99 94 b8 50 70 c5 d0 71 dd ee 6 7 10 39 90 41 71 64 ce f9 bc f2 9c 86 71 73 45 80 a3 31 dc 93 c5 85 7b 29 bc dc a5 c8 58 70 57 7b 1e 91 6c 8f ac c3 9b 13 59 9d a 43 e5 c1 d1 df f7 45 82 82 3e e0 c1 3e 15 93 20 87 86 9d a 35 15 79 22 2b 7 32 a2 93 34 c1 77 1 c1 15 2e 92 34 5c 8f 27 7 f4 16 a5 65 31 73 66 bc fa 3e ae 98 7c 1d 5 6d e8 6b 7 2b 4a 6e 52 7 1f c4 ec c1 94 4c 72 73 5c 45 61 d1 29 fc b9 1f 44 6 3c 15 27 de 79 c1 1 f 5b 97 bc fe a9 a6 2 c3 c5 17 6d 24 13 6e6 6b bf 7d 75 60 bb 7e 4c 18 9e d4 47 e0 4a e9 bf 6d c4 a7 83 f3 5b 8f f7 b4 b3 67 69 61 d2 c0 10 d4 c 10 b3 79 a0 27 45 5a c6 5d ba ca 38 71 97 41 17 9c a9 8d b 68 88 89 23 42 5c fb 2f a6 64 65 68 36 45 58 2b 89 b0 4 fd d6 8d d9 6d 5c 2a 6a e6 1d b1 db bf 1e 89 e3 71 57 ab 97 68 3f e7 c7 7b 5e ae 95 10 d1 3c 18 4b c3 b0 15 7e fc f2 10 a2 ec ce c dc a4 26 52 d9 ad 47 12 c7 b9 ed 20 4b f4 fd af 54 4f c8 76 b7 47 2 33 42 bc 98 fb eb bb c5 71 be 93 b3 4b ef 82 13 42 d8 9b 7c 8f e6 57 ed bd fb e4 5c cb cf 2d e0 59 41 aa bd 50 ef 51 a7 70 c8 70 91 18 ed 19 f a 45 5f 8d 14 bc bc c6 14 32 3b b1 bb 93 89 d 9e 76 fb 7b f2 f0 1 d4 b7 22 c d1 d0 4 85 b6 86 86 b9 b3 8 20 c0 1d 46 e9 70 c5 f2 75 da 2e 79 7 c5 8a e0 cb a7 f7 ae 69 db 2e 66 76 8e 2 12 c5 6 a1 39 62 be ef 8c 53 9f 1d 6 37 42 7f 6e 78 f7 9a 3e db d2 f5 b3 23 b2 89 92 ad d1 35 1e 7 df 37 5a ea fc 4e 0d 51 5d 39 96 89 12 f9 59 9b e3 b8 77 41 56 60 67 d1 27 85 f2 ec c2 4 29 39 9b 5c f1 ec 5f a5 1d 11 fe 68 3a ec 10 9a 44 f7 f4 9f 58 c6 c 46 95 8b 15 a1 e8 a8 4a f3 e2 c5 30 e7 b1 62 e9 2e 42 d5 6 a0 7c 27 52 6c 9c 99 aa 63 c8 de fe 6 fc 1a bf 44 94 83");
  5.  
  6. public final static char[] MODERN_UNI_KEY = new char[] { (char) 26027, (char) 1353, (char) 52583, (char) 2647,
  7. (char) 31640, (char) 2695, (char) 26092, (char) 35591, (char) 29845, (char) 27702, (char) 22963, (char) 24105,
  8. (char) 22946, (char) 32259, (char) 32191, (char) 29899, (char) 21392, (char) 37926, (char) 28440, (char) 34657,
  9. (char) 54992, (char) 7801, (char) 21164, (char) 21225, (char) 31362, (char) 59422 };
  10. /**
  11. * Actually this is just modernUniKey but expanded to single byte chars
  12. */
  13. public final static char[] MODERN_KEY = new char[MODERN_UNI_KEY.length * 2];
  14.  
  15. static {
  16. for (int i = 0; i < MODERN_UNI_KEY.length; i++) {
  17. MODERN_KEY[i * 2 + 1] = (char) (MODERN_UNI_KEY[i] >> 8);
  18. MODERN_KEY[i * 2]= (char) ((MODERN_UNI_KEY[i]) & 0xFF);
  19. }
  20. }
  21.  
  22. private WZTool() {
  23.  
  24. }
  25.  
  26. public static char[] xorCharArray(char[] cypher, char[] key) {
  27. char[] ret = new char[cypher.length];
  28. for (int i = 0; i < cypher.length; i++) {
  29. ret[i] = (char) (cypher[i] ^ key[i]);
  30. }
  31. return ret;
  32. }
  33.  
  34. public static String dumpCharArray(char[] arr) {
  35. String ret = " new char[] {";
  36. for (char c : arr) {
  37. ret += "(char) " + ((int) c) + ", ";
  38. }
  39. ret = ret.substring(0, ret.length() - 2);
  40. ret += "};";
  41. return ret;
  42. }
  43.  
  44. public static void writeEncodedString(LittleEndianWriter leo, String s) throws IOException {
  45. writeEncodedString(leo, s, true);
  46. }
  47.  
  48. public static void writeEncodedString(LittleEndianWriter leo, String s, boolean unicode) throws IOException {
  49. if (s.equals("")) {
  50. leo.write(0);
  51. return;
  52. }
  53.  
  54.  
  55. if (unicode) {
  56. // do unicode
  57. short umask = (short) 0xAAAA;
  58.  
  59. if (s.length() < 0x7F)
  60. leo.write(s.length());
  61. else {
  62. leo.write(0x7F);
  63. leo.writeInt(s.length());
  64. }
  65.  
  66. for (int i = 0; i < s.length(); i++) {
  67. char chr = s.charAt(i);
  68.  
  69. chr ^= umask;
  70. umask++;
  71. leo.writeShort((short)chr);
  72. }
  73. } else {
  74. // non-unicode
  75. byte mask = (byte) 0xAA;
  76.  
  77. if (s.length() <= 127)
  78. leo.write(-s.length());
  79. else
  80. leo.writeInt(s.length());
  81.  
  82. char str[] = new char[s.length()];
  83. for (int i = 0; i < s.length(); i++) {
  84. byte b2 = (byte) s.charAt(i);
  85. b2 ^= mask;
  86. mask++;
  87. str[i] = (char) b2;
  88. }
  89. }
  90. }
  91.  
  92. public static String readDecodedString(LittleEndianAccessor llea, boolean modernImg) {
  93. if (text == ""){
  94. File check = new File("key.txt");
  95. if (check.exists()) {
  96. try {
  97. FileReader reader = new FileReader("key.txt");
  98. BufferedReader br = new BufferedReader(reader);
  99. text = br.readLine();
  100. br.close();
  101. reader.close();
  102. } catch (IOException e) { }
  103. @SuppressWarnings("unused")
  104. byte key[] = HexTool.getByteArrayFromHexString(text);
  105. }
  106. }
  107.  
  108. int strLength;
  109. byte b = llea.readByte();
  110.  
  111. if (b == 0x00) {
  112. return "";
  113. }
  114.  
  115. if (b >= 0) {
  116. // do unicode
  117. short umask = (short) 0xAAAA;
  118.  
  119. if (b == 0x7F)
  120. strLength = llea.readInt();
  121. else
  122. strLength = (int) b;
  123.  
  124. if (strLength < 0) {
  125. // int temp = ftell(m_fileIn);
  126. log.error("Strlength < 0");
  127. return "";
  128. }
  129.  
  130. char str[] = new char[strLength];
  131. for (int i = 0; i < strLength; i++) {
  132. char chr = llea.readChar();
  133.  
  134. chr ^= umask;
  135. umask++;
  136. str[i] = chr;
  137. }
  138.  
  139. if (modernImg) {
  140. str = xorCharArray(str, MODERN_UNI_KEY);
  141. }
  142. return String.valueOf(str);
  143. } else {
  144. // do non-unicode
  145.  
  146. byte mask = (byte) 0xAA;
  147.  
  148. if (b == -128)
  149. strLength = llea.readInt();
  150. else
  151. strLength = (int) (-b);
  152.  
  153. assert strLength >= 0 : "can never be < 0 (?)";
  154.  
  155. char str[] = new char[strLength];
  156. for (int i = 0; i < strLength; i++) {
  157. byte b2 = llea.readByte();
  158. if (key.length > 0) {
  159. b2 ^= key[i];
  160. } else {
  161. b2 ^= mask;
  162. mask++;
  163. }
  164. str[i] = (char) (b2 & 0xFF);
  165. }
  166.  
  167. if (modernImg) {
  168. str = xorCharArray(str, MODERN_KEY);
  169. }
  170. return String.valueOf(str);
  171. }
  172. }
  173.  
  174. public static String readDecodedStringAtOffset(SeekableLittleEndianAccessor slea, int offset, boolean modernImg) {
  175. slea.seek(offset);
  176. return readDecodedString(slea, modernImg);
  177. }
  178.  
  179. public static String readDecodedStringAtOffsetAndReset(SeekableLittleEndianAccessor slea, int offset, boolean modernImg) {
  180. long pos = 0;
  181. pos = slea.getPosition();
  182. slea.seek(offset);
  183. String ret = readDecodedString(slea, modernImg);
  184. slea.seek(pos);
  185. return ret;
  186. }
  187.  
  188. public static int readValue(LittleEndianAccessor lea) {
  189. byte b = lea.readByte();
  190. if (b == -128) {
  191. return lea.readInt();
  192. } else {
  193. return ((int) b);
  194. }
  195. }
  196.  
  197. public static void writeValue(LittleEndianWriter lew, int val) throws IOException {
  198. if (val <= 127)
  199. lew.write(val);
  200. else {
  201. lew.write(-128);
  202. lew.writeInt(val);
  203. }
  204. }
  205.  
  206. public static float readFloatValue(LittleEndianAccessor lea) {
  207. byte b = lea.readByte();
  208. if (b == -128) {
  209. return lea.readFloat();
  210. } else {
  211. return 0;
  212. }
  213. }
  214.  
  215. public static void writeFloatValue(LittleEndianWriter leo, float val) throws IOException {
  216. if (val == 0) {
  217. leo.write(-128);
  218. } else {
  219. leo.write(0);
  220. leo.writeInt(Float.floatToIntBits(val));
  221. }
  222. }
  223. }
Add Comment
Please, Sign In to add comment