List of usage examples for io.netty.buffer ByteBuf writeBytes
public abstract int writeBytes(ScatteringByteChannel in, int length) throws IOException;
From source file:com.vethrfolnir.game.network.mu.crypt.MuDecoder.java
License:Open Source License
/** * @param decrypted/* w ww . jav a2 s . c om*/ * @param encrypted * @param decServerKeys * @return */ private static int BlockDecode(ByteBuf decrypted, short[] InBuf, ByteBuf converter, long[] Keys) { long[] Ring = new long[4]; short[] Shift = new short[4]; ShiftBytes(Shift, 0x00, InBuf, 0x00, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x10, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); ShiftBytes(Shift, 0x00, InBuf, 0x12, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x22, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); ShiftBytes(Shift, 0x00, InBuf, 0x24, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x34, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); ShiftBytes(Shift, 0x00, InBuf, 0x36, 0x10); ShiftBytes(Shift, 0x16, InBuf, 0x46, 0x02); writeByteArray(converter, Shift); flushArray(Shift, 0, 4); // for (int i = 0; i < Ring.length; i++) { // System.err.print(Integer.toHexString((int) Ring[i])+" ");; // } // System.err.println(); for (int i = 0; i < Ring.length; i++) { Ring[i] = converter.readInt(); } converter.clear(); Ring[2] = Ring[2] ^ Keys[10] ^ (Ring[3] & 0xFFFF); Ring[1] = Ring[1] ^ Keys[9] ^ (Ring[2] & 0xFFFF); Ring[0] = Ring[0] ^ Keys[8] ^ (Ring[1] & 0xFFFF); // System.err.println("Finished Ring: "); // for (int i = 0; i < Ring.length; i++) { // System.err.print(Integer.toHexString((int) Ring[i])+" ");; // } // System.err.println(); int[] CryptBuf = new int[4]; // Had ushort cast here. CryptBuf[0] = (int) (Keys[8] ^ ((Ring[0] * Keys[4]) % Keys[0])); CryptBuf[1] = (int) (Keys[9] ^ ((Ring[1] * Keys[5]) % Keys[1]) ^ (Ring[0] & 0xFFFF)); CryptBuf[2] = (int) (Keys[10] ^ ((Ring[2] * Keys[6]) % Keys[2]) ^ (Ring[1] & 0xFFFF)); CryptBuf[3] = (int) (Keys[11] ^ ((Ring[3] * Keys[7]) % Keys[3]) ^ (Ring[2] & 0xFFFF)); // System.err.println("Pre done: " + PrintData.printData(CryptBuf)); short[] Finale = new short[2]; ShiftBytes(Finale, 0x00, InBuf, 0x48, 0x10); Finale[0] ^= Finale[1]; Finale[0] ^= 0x3D; converter.clear(); for (int i = 0; i < CryptBuf.length; i++) { converter.writeShort(CryptBuf[i]); } decrypted.writeBytes(converter, Finale[0]); converter.clear(); //System.out.println(PrintData.printData(decrypted.nioBuffer())); // System.err.println("Finale: "+ Finale[0]); short Check = 0xF8; for (int i = 0; i < Finale[0]; ++i) Check = (short) (Check ^ decrypted.getUnsignedByte(i)); if (Finale[1] == Check) return Finale[0]; //System.err.println("Finale["+Finale[0]+"] And done: "+PrintData.printData(decrypted.nioBuffer())); return Finale[0]; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuKeyFactory.java
License:Open Source License
private static void readFile(String path, long[] out_dat) { AssetManager assetManager = Corax.fetch(AssetManager.class); ByteBuf buff = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); try (InputStream is = assetManager.loadAsset(FileKey.class, path)) { buff.writeBytes(is, is.available()); } catch (IOException e) { e.printStackTrace();//w ww . ja v a 2s .c o m } buff.readerIndex(6); int pointer = 0; for (int i = 0; i < 3; i++) { long[] buf = new long[4]; for (int j = 0; j < 4; j++) { buf[j] = buff.readUnsignedInt(); } out_dat[pointer++] = buf[0] ^ (xor_tab_datfile[0]); out_dat[pointer++] = buf[1] ^ (xor_tab_datfile[1] & 0xFFFFFFFFL); out_dat[pointer++] = buf[2] ^ (xor_tab_datfile[2] & 0xFFFFFFFFL); out_dat[pointer++] = buf[3] ^ (xor_tab_datfile[3]); } }