I just implemented RSA encryption and now i cannot connect to my server. I received no errors when adding. Where should i start looking? I also have UUID implementation but modified it so that it will comply with the RSA. HELP!!!!
PS yes i did make a back up
EDIT
RS2LoginProtocolDecoder.java
please note i removed some of the RSA Keys since im too lazy to make new ones now that these are public.
Original
Code:
package server.net;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoFuture;
import org.apache.mina.common.IoFutureListener;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import server.Config;
import server.Connection;
import server.Server;
import server.model.players.Client;
import server.model.players.PlayerHandler;
import server.model.players.PlayerSave;
import server.util.ISAACRandomGen;
/**
* Login protocol decoder.
* @author Graham
* @author Ryan / Lmctruck30 <- login Protocol fixes
*
*/
public class RS2LoginProtocolDecoder extends CumulativeProtocolDecoder {
/**
* Parses the data in the provided byte buffer and writes it to
* <code>out</code> as a <code>Packet</code>.
*
* @param session The IoSession the data was read from
* @param in The buffer
* @param out The decoder output stream to which to write the <code>Packet</code>
* @return Whether enough data was available to create a packet
*/
@Override
public boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) {
synchronized(session) {
Object loginStageObj = session.getAttribute("LOGIN_STAGE");
int loginStage = 0;
if(loginStageObj != null) {
loginStage = (Integer)loginStageObj;
}
//Logger.log("recv login packet, stage: "+loginStage);
switch(loginStage) {
case 0:
if(2 <= in.remaining()) {
int protocol = in.get() & 0xff;
@SuppressWarnings("unused")
int nameHash = in.get() & 0xff;
if(protocol == 14) {
long serverSessionKey = ((long) (java.lang.Math.random() * 99999999D) << 32) + (long) (java.lang.Math.random() * 99999999D);
StaticPacketBuilder s1Response = new StaticPacketBuilder();
s1Response.setBare(true).addBytes(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }).addByte((byte) 0).addLong(serverSessionKey);
session.setAttribute("SERVER_SESSION_KEY", serverSessionKey);
session.write(s1Response.toPacket());
session.setAttribute("LOGIN_STAGE", 1);
}
return true;
} else {
in.rewind();
return false;
}
case 1:
@SuppressWarnings("unused")
int loginType = -1, loginPacketSize = -1, loginEncryptPacketSize = -1;
if(2 <= in.remaining()) {
loginType = in.get() & 0xff; //should be 16 or 18
loginPacketSize = in.get() & 0xff;
loginEncryptPacketSize = loginPacketSize-(36+1+1+2);
if(loginPacketSize <= 0 || loginEncryptPacketSize <= 0) {
System.out.println("Zero or negative login size.");
session.close();
return false;
}
} else {
in.rewind();
return false;
}
if(loginPacketSize <= in.remaining()) {
int magic = in.get() & 0xff;
int version = in.getUnsignedShort();
if(magic != 255) {
//System.out.println("Wrong magic id.");
session.close();
return false;
}
if(version != 1) {
//Dont Add Anything
}
@SuppressWarnings("unused")
int lowMem = in.get() & 0xff;
for(int i = 0; i < 9; i++) {
in.getInt();
}
loginEncryptPacketSize--;
if(loginEncryptPacketSize != (in.get() & 0xff)) {
System.out.println("Encrypted size mismatch.");
session.close();
return false;
}
if((in.get() & 0xff) != 10) {
System.out.println("Encrypted id != 10.");
session.close();
return false;
}
long clientSessionKey = in.getLong();
long serverSessionKey = in.getLong();
int uid = in.getInt();
if(uid == 0 || uid == 99735086) {
session.close();
return false;
}
String name = readRS2String(in);
String pass = readRS2String(in);
int sessionKey[] = new int[4];
sessionKey[0] = (int)(clientSessionKey >> 32);
sessionKey[1] = (int)clientSessionKey;
sessionKey[2] = (int)(serverSessionKey >> 32);
sessionKey[3] = (int)serverSessionKey;
ISAACRandomGen inC = new ISAACRandomGen(sessionKey);
for(int i = 0; i < 4; i++) sessionKey[i] += 50;
ISAACRandomGen outC = new ISAACRandomGen(sessionKey);
load(session, uid, name, pass, inC, outC, version);
// WorkerThread.load(session, name, pass, inC, outC);
session.getFilterChain().remove("protocolFilter");
session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC)));
return true;
} else {
in.rewind();
return false;
}
}
}
return false;
}
private synchronized void load(final IoSession session, final int uid, String name, String pass, final ISAACRandomGen inC, ISAACRandomGen outC, int version) {
session.setAttribute("opcode", -1);
session.setAttribute("size", -1);
int loginDelay = 1;
int returnCode = 2;
name = name.trim();
name = name.toLowerCase();
pass = pass.toLowerCase();
if(!name.matches("[A-Za-z0-9 ]+")) {
returnCode = 4;
}
if(name.length() > 12) {
returnCode = 8;
}
Client cl = new Client(session, -1);
cl.playerName = name;
cl.playerName2 = cl.playerName;
cl.playerPass = pass;
cl.setInStreamDecryption(inC);
cl.setOutStreamDecryption(outC);
cl.outStream.packetEncryption = outC;
cl.saveCharacter = false;
char first = name.charAt(0);
cl.properName = Character.toUpperCase(first)+ name.substring(1, name.length());
if(Connection.isNamedBanned(cl.playerName)) {
returnCode = 4;
}
if(PlayerHandler.isPlayerOn(name)) {
returnCode = 5;
}
//if(Config.CLIENT_VERSION != version) {
//returnCode = 6;
//}
if(PlayerHandler.playerCount >= Config.MAX_PLAYERS) {
returnCode = 7;
}
// Login Limit Exceeded
// if() {
// returnCode = 9;
// }
if(Server.UpdateServer) {
returnCode = 14;
}
// if(Connection.checkLoginList(loginIp)) {
// returnCode = 16;
// }
// Just Left World Login Delay Included
// if() {
// returnCode = 21;
// }
if(returnCode == 2) {
int load = PlayerSave.loadGame(cl, cl.playerName, cl.playerPass);
if (load == 0)
cl.addStarter = true;
if(load == 3) {
returnCode = 3;
cl.saveFile = false;
} else {
for(int i = 0; i < cl.playerEquipment.length; i++) {
if(cl.playerEquipment[i] == 0) {
cl.playerEquipment[i] = -1;
cl.playerEquipmentN[i] = 0;
}
}
if(!Server.playerHandler.newPlayerClient(cl)) {
returnCode = 7;
cl.saveFile = false;
} else {
cl.saveFile = true;
}
}
}
cl.packetType = -1;
cl.packetSize = 0;
StaticPacketBuilder bldr = new StaticPacketBuilder();
bldr.setBare(true);
bldr.addByte((byte) returnCode);
if(returnCode == 2) {
cl.saveCharacter = true;
if(cl.playerRights == 3) {
bldr.addByte((byte) 2);
} else {
bldr.addByte((byte) cl.playerRights);
}
//cl.playerServer = "riotscape.no-ip.info";
} else if(returnCode == 21) {
bldr.addByte((byte) loginDelay);
} else {
bldr.addByte((byte) 0);
}
cl.isActive = true;
bldr.addByte((byte) 0);
Packet pkt = bldr.toPacket();
final Client fcl = cl;
session.setAttachment(cl);
session.write(pkt).addListener(new IoFutureListener() {
@Override
public void operationComplete(IoFuture arg0) {
session.getFilterChain().remove("protocolFilter");
session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC)));
}
});
}
private synchronized String readRS2String(ByteBuffer in) {
StringBuilder sb = new StringBuilder();
byte b;
while((b = in.get()) != 10) {
sb.append((char) b);
}
return sb.toString();
}
/**
* Releases the buffer used by the given session.
*
* @param session The session for which to release the buffer
* @throws Exception if failed to dispose all resources
*/
@Override
public void dispose(IoSession session) throws Exception {
super.dispose(session);
}
}
Code:
package server.net;
import java.math.BigInteger;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoFuture;
import org.apache.mina.common.IoFutureListener;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import server.Config;
import server.Connection;
import server.Server;
import server.model.players.Client;
import server.model.players.PlayerHandler;
import server.model.players.PlayerSave;
import server.util.ISAACRandomGen;
/**
* Login protocol decoder.
* @author Graham
* @author Ryan / Lmctruck30 <- login Protocol fixes
*
*/
public class RS2LoginProtocolDecoder extends CumulativeProtocolDecoder {
private static final BigInteger RSA_MODULUS = new BigInteger("10152560989075604785346988528228472933614916891876586244752983095099290722933020991012848761880678215721115152633411890946396857494741915005860885613572313951071680854686760286527447904395433363611646058048500190657153790149891672295773971780936779008784201861833949");
private static final BigInteger RSA_EXPONENT = new BigInteger("65512886495873678436962959070262923289527264805752602696278995848413721206774411051762115162417242434479143049707339192841161954842704973617629255626283331755767732053965371971613636240320289318352284388571604152078452336105434449605563943717082873");
/**
* Parses the data in the provided byte buffer and writes it to
* <code>out</code> as a <code>Packet</code>.
*
* @param session The IoSession the data was read from
* @param in The buffer
* @param out The decoder output stream to which to write the <code>Packet</code>
* @return Whether enough data was available to create a packet
*/
@Override
public boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) {
synchronized(session) {
Object loginStageObj = session.getAttribute("LOGIN_STAGE");
int loginStage = 0;
if(loginStageObj != null) {
loginStage = (Integer)loginStageObj;
}
//Logger.log("recv login packet, stage: "+loginStage);
switch(loginStage) {
case 0:
if(2 <= in.remaining()) {
int protocol = in.get() & 0xff;
@SuppressWarnings("unused")
int nameHash = in.get() & 0xff;
if(protocol == 14) {
long serverSessionKey = ((long) (java.lang.Math.random() * 99999999D) << 32) + (long) (java.lang.Math.random() * 99999999D);
StaticPacketBuilder s1Response = new StaticPacketBuilder();
s1Response.setBare(true).addBytes(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }).addByte((byte) 0).addLong(serverSessionKey);
session.setAttribute("SERVER_SESSION_KEY", serverSessionKey);
session.write(s1Response.toPacket());
session.setAttribute("LOGIN_STAGE", 1);
}
return true;
} else {
in.rewind();
return false;
}
case 1:
@SuppressWarnings("unused")
int loginType = -1, loginPacketSize = -1, loginEncryptPacketSize = -1;
if(2 <= in.remaining()) {
loginType = in.get() & 0xff; //should be 16 or 18
loginPacketSize = in.get() & 0xff;
loginEncryptPacketSize = loginPacketSize-(36+1+1+2);
if(loginPacketSize <= 0 || loginEncryptPacketSize <= 0) {
System.out.println("Zero or negative login size.");
session.close();
return false;
}
} else {
in.rewind();
return false;
}
if(loginPacketSize <= in.remaining()) {
int magic = in.get() & 0xff;
int version = in.getUnsignedShort();
if(magic != 255) {
//System.out.println("Wrong magic id.");
session.close();
return false;
}
if(version != 1) {
//Dont Add Anything
}
@SuppressWarnings("unused")
int lowMem = in.get() & 0xff;
for(int i = 0; i < 9; i++) {
in.getInt();
}
loginEncryptPacketSize--;
if(loginEncryptPacketSize != (in.get() & 0xff)) {
System.out.println("Encrypted size mismatch.");
session.close();
return false;
}
//RSA Shit
byte[] encryptionBytes = new byte[loginEncryptPacketSize];
in.get(encryptionBytes);
ByteBuffer rsaBuffer = ByteBuffer.wrap(new BigInteger(encryptionBytes)
.modPow(RSA_EXPONENT, RSA_MODULUS).toByteArray());
//END RSA Shit
if((rsaBuffer.get() & 0xff) != 10) {
System.out.println("Encrypted id != 10.");
session.close();
return false;
}
long clientSessionKey = rsaBuffer.getLong();
long serverSessionKey = rsaBuffer.getLong();
int uid = in.getInt();
if(uid == 0 || uid == 99735086) {
session.close();
return false;
}
UUID = readRS2String(rsaBuffer);
String name = readRS2String(rsaBuffer);
String pass = readRS2String(rsaBuffer);
int sessionKey[] = new int[4];
sessionKey[0] = (int)(clientSessionKey >> 32);
sessionKey[1] = (int)clientSessionKey;
sessionKey[2] = (int)(serverSessionKey >> 32);
sessionKey[3] = (int)serverSessionKey;
ISAACRandomGen inC = new ISAACRandomGen(sessionKey);
for(int i = 0; i < 4; i++) sessionKey[i] += 50;
ISAACRandomGen outC = new ISAACRandomGen(sessionKey);
load(session, uid, name, pass, inC, outC, version, UUID);
// WorkerThread.load(session, name, pass, inC, outC);
session.getFilterChain().remove("protocolFilter");
session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC)));
return true;
} else {
in.rewind();
return false;
}
}
}
return false;
}
private synchronized void load(final IoSession session, final int uid, String name, String pass, final ISAACRandomGen inC, ISAACRandomGen outC, int version, String UUID) {
session.setAttribute("opcode", -1);
session.setAttribute("size", -1);
int loginDelay = 1;
int returnCode = 2;
name = name.trim();
name = name.toLowerCase();
pass = pass.toLowerCase();
if(!name.matches("[A-Za-z0-9 ]+")) {
returnCode = 4;
}
if(name.length() > 12) {
returnCode = 8;
}
Client cl = new Client(session, -1);
cl.playerName = name;
cl.playerName2 = cl.playerName;
cl.playerPass = pass;
cl.setInStreamDecryption(inC);
cl.setOutStreamDecryption(outC);
cl.outStream.packetEncryption = outC;
cl.saveCharacter = false;
char first = name.charAt(0);
cl.properName = Character.toUpperCase(first)+ name.substring(1, name.length());
if(Connection.isNamedBanned(cl.playerName)) {
returnCode = 4;
}
if(Connection.isUidBanned(UUID)) {
returnCode = 22;
}
if(PlayerHandler.isPlayerOn(name)) {
returnCode = 5;
}
//if(Config.CLIENT_VERSION != version) {
//returnCode = 6;
//}
if(PlayerHandler.playerCount >= Config.MAX_PLAYERS) {
returnCode = 7;
}
// Login Limit Exceeded
// if() {
// returnCode = 9;
// }
if(Server.UpdateServer) {
returnCode = 14;
}
// if(Connection.checkLoginList(loginIp)) {
// returnCode = 16;
// }
// Just Left World Login Delay Included
// if() {
// returnCode = 21;
// }
if(returnCode == 2) {
int load = PlayerSave.loadGame(cl, cl.playerName, cl.playerPass);
if (load == 0)
cl.addStarter = true;
if(load == 3) {
returnCode = 3;
cl.saveFile = false;
} else {
for(int i = 0; i < cl.playerEquipment.length; i++) {
if(cl.playerEquipment[i] == 0) {
cl.playerEquipment[i] = -1;
cl.playerEquipmentN[i] = 0;
}
}
if(!Server.playerHandler.newPlayerClient(cl)) {
returnCode = 7;
cl.saveFile = false;
} else {
cl.saveFile = true;
}
}
}
cl.packetType = -1;
cl.packetSize = 0;
StaticPacketBuilder bldr = new StaticPacketBuilder();
bldr.setBare(true);
bldr.addByte((byte) returnCode);
if(returnCode == 2) {
cl.saveCharacter = true;
if(cl.playerRights == 3) {
bldr.addByte((byte) 2);
} else {
bldr.addByte((byte) cl.playerRights);
}
//cl.playerServer = "riotscape.no-ip.info";
} else if(returnCode == 21) {
bldr.addByte((byte) loginDelay);
} else {
bldr.addByte((byte) 0);
}
cl.isActive = true;
bldr.addByte((byte) 0);
Packet pkt = bldr.toPacket();
final Client fcl = cl;
session.setAttachment(cl);
session.write(pkt).addListener(new IoFutureListener() {
@Override
public void operationComplete(IoFuture arg0) {
session.getFilterChain().remove("protocolFilter");
session.getFilterChain().addFirst("protocolFilter", new ProtocolCodecFilter(new GameCodecFactory(inC)));
}
});
}
private synchronized String readRS2String(ByteBuffer rsaBuffer) {
StringBuilder sb = new StringBuilder();
byte b;
while((b = rsaBuffer.get()) != 10) {
sb.append((char) b);
}
return sb.toString();
}
/**
* Releases the buffer used by the given session.
*
* @param session The session for which to release the buffer
* @throws Exception if failed to dispose all resources
*/
@Override
public void dispose(IoSession session) throws Exception {
super.dispose(session);
}
//UID Stuff
public static String UUID;
}
Stream.java
again i deleted part of keys
ORIGINAL STREAM.JAVA
Code:
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
import java.math.BigInteger;
import sign.signlink;
public final class Stream extends NodeSub {
public static Stream create() {
synchronized(nodeList) {
Stream stream = null;
if(anInt1412 > 0) {
anInt1412--;
stream = (Stream) nodeList.popHead();
}
if(stream != null) {
stream.currentOffset = 0;
return stream;
}
}
Stream stream_1 = new Stream();
stream_1.currentOffset = 0;
stream_1.buffer = new byte[5000];
return stream_1;
}
private Stream() {
}
public Stream(byte abyte0[]) {
buffer = abyte0;
currentOffset = 0;
}
public void createFrame(int i) {
//System.out.println("Frame: " + i);
buffer[currentOffset++] = (byte)(i + encryption.getNextKey());
}
public void writeWordBigEndian(int i) {
buffer[currentOffset++] = (byte)i;
}
public void writeWord(int i) {
buffer[currentOffset++] = (byte)(i >> 8);
buffer[currentOffset++] = (byte)i;
}
public void method400(int i) {
buffer[currentOffset++] = (byte)i;
buffer[currentOffset++] = (byte)(i >> 8);
}
public void writeDWordBigEndian(int i) {
buffer[currentOffset++] = (byte)(i >> 16);
buffer[currentOffset++] = (byte)(i >> 8);
buffer[currentOffset++] = (byte)i;
}
public void writeDWord(int i) {
buffer[currentOffset++] = (byte)(i >> 24);
buffer[currentOffset++] = (byte)(i >> 16);
buffer[currentOffset++] = (byte)(i >> 8);
buffer[currentOffset++] = (byte)i;
}
public void method403(int j) {
buffer[currentOffset++] = (byte)j;
buffer[currentOffset++] = (byte)(j >> 8);
buffer[currentOffset++] = (byte)(j >> 16);
buffer[currentOffset++] = (byte)(j >> 24);
}
public void writeQWord(long l) {
try {
buffer[currentOffset++] = (byte)(int)(l >> 56);
buffer[currentOffset++] = (byte)(int)(l >> 48);
buffer[currentOffset++] = (byte)(int)(l >> 40);
buffer[currentOffset++] = (byte)(int)(l >> 32);
buffer[currentOffset++] = (byte)(int)(l >> 24);
buffer[currentOffset++] = (byte)(int)(l >> 16);
buffer[currentOffset++] = (byte)(int)(l >> 8);
buffer[currentOffset++] = (byte)(int)l;
} catch(RuntimeException runtimeexception) {
signlink.reporterror("14395, " + 5 + ", " + l + ", " + runtimeexception.toString());
throw new RuntimeException();
}
}
public void writeString(String s) {
//s.getBytes(0, s.length(), buffer, currentOffset); //deprecated
System.arraycopy(s.getBytes(), 0, buffer, currentOffset, s.length());
currentOffset += s.length();
buffer[currentOffset++] = 10;
}
public void writeBytes(byte abyte0[], int i, int j) {
for(int k = j; k < j + i; k++)
buffer[currentOffset++] = abyte0[k];
}
public void writeBytes(int i) {
buffer[currentOffset - i - 1] = (byte)i;
}
public int readUnsignedByte() {
return buffer[currentOffset++] & 0xff;
}
public byte readSignedByte() {
return buffer[currentOffset++];
}
public int readUnsignedWord() {
currentOffset += 2;
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
}
public int readSignedWord() {
currentOffset += 2;
int i = ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
if(i > 32767)
i -= 0x10000;
return i;
}
public int read3Bytes() {
currentOffset += 3;
return ((buffer[currentOffset - 3] & 0xff) << 16) + ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
}
public int readDWord() {
currentOffset += 4;
return ((buffer[currentOffset - 4] & 0xff) << 24) + ((buffer[currentOffset - 3] & 0xff) << 16) + ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
}
public long readQWord() {
long l = (long) readDWord() & 0xffffffffL;
long l1 = (long) readDWord() & 0xffffffffL;
return (l << 32) + l1;
}
public String readString() {
int i = currentOffset;
while(buffer[currentOffset++] != 10) ;
return new String(buffer, i, currentOffset - i - 1);
}
public byte[] readBytes() {
int i = currentOffset;
while(buffer[currentOffset++] != 10) ;
byte abyte0[] = new byte[currentOffset - i - 1];
System.arraycopy(buffer, i, abyte0, i - i, currentOffset - 1 - i);
return abyte0;
}
public void readBytes(int i, int j, byte abyte0[]) {
for(int l = j; l < j + i; l++)
abyte0[l] = buffer[currentOffset++];
}
public void initBitAccess() {
bitPosition = currentOffset * 8;
}
public int readBits(int i) {
int k = bitPosition >> 3;
int l = 8 - (bitPosition & 7);
int i1 = 0;
bitPosition += i;
for(; i > l; l = 8)
{
i1 += (buffer[k++] & anIntArray1409[l]) << i - l;
i -= l;
}
if(i == l)
i1 += buffer[k] & anIntArray1409[l];
else
i1 += buffer[k] >> l - i & anIntArray1409[i];
return i1;
}
public void finishBitAccess() {
currentOffset = (bitPosition + 7) / 8;
}
public int method421() {
int i = buffer[currentOffset] & 0xff;
if(i < 128)
return readUnsignedByte() - 64;
else
return readUnsignedWord() - 49152;
}
public int method422() {
int i = buffer[currentOffset] & 0xff;
if(i < 128)
return readUnsignedByte();
else
return readUnsignedWord() - 32768;
}
public void doKeys() {
int i = currentOffset;
currentOffset = 0;
byte abyte0[] = new byte[i];
readBytes(i, 0, abyte0);
BigInteger biginteger2 = new BigInteger(abyte0);
BigInteger biginteger3 = biginteger2/*.modPow(biginteger, biginteger1)*/;
byte abyte1[] = biginteger3.toByteArray();
currentOffset = 0;
writeWordBigEndian(abyte1.length);
writeBytes(abyte1, abyte1.length, 0);
}
public void method424(int i) {
buffer[currentOffset++] = (byte)(-i);
}
public void method425(int j) {
buffer[currentOffset++] = (byte)(128 - j);
}
public int method426() {
return buffer[currentOffset++] - 128 & 0xff;
}
public int method427() {
return -buffer[currentOffset++] & 0xff;
}
public int method428() {
return 128 - buffer[currentOffset++] & 0xff;
}
public byte method429() {
return (byte)(-buffer[currentOffset++]);
}
public byte method430() {
return (byte)(128 - buffer[currentOffset++]);
}
public void method431(int i) {
buffer[currentOffset++] = (byte)i;
buffer[currentOffset++] = (byte)(i >> 8);
}
public void method432(int j) {
buffer[currentOffset++] = (byte)(j >> 8);
buffer[currentOffset++] = (byte)(j + 128);
}
public void method433(int j) {
buffer[currentOffset++] = (byte)(j + 128);
buffer[currentOffset++] = (byte)(j >> 8);
}
public int method434() {
currentOffset += 2;
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
}
public int method435() {
currentOffset += 2;
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] - 128 & 0xff);
}
public int method436() {
currentOffset += 2;
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
}
public int method437() {
currentOffset += 2;
int j = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
if(j > 32767)
j -= 0x10000;
return j;
}
public int method438() {
currentOffset += 2;
int j = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
if(j > 32767)
j -= 0x10000;
return j;
}
public int method439() {
currentOffset += 4;
return ((buffer[currentOffset - 2] & 0xff) << 24) + ((buffer[currentOffset - 1] & 0xff) << 16) + ((buffer[currentOffset - 4] & 0xff) << 8) + (buffer[currentOffset - 3] & 0xff);
}
public int method440() {
currentOffset += 4;
return ((buffer[currentOffset - 3] & 0xff) << 24) + ((buffer[currentOffset - 4] & 0xff) << 16) + ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
}
public void method441(int i, byte abyte0[], int j) {
for(int k = (i + j) - 1; k >= i; k--)
buffer[currentOffset++] = (byte)(abyte0[k] + 128);
}
public void method442(int i, int j, byte abyte0[]) {
for(int k = (j + i) - 1; k >= j; k--)
abyte0[k] = buffer[currentOffset++];
}
public byte buffer[];
public int currentOffset;
public int bitPosition;
private static final int[] anIntArray1409 = {
0, 1, 3, 7, 15, 31, 63, 127, 255, 511,
1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff,
0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff,
0x3fffffff, 0x7fffffff, -1
};
public ISAACRandomGen encryption;
private static int anInt1412;
private static final NodeList nodeList = new NodeList();
}
Stream.java with RSA
Code:
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: kpdus.com
// Decompiler options: packimports(3)
import java.math.BigInteger;
import sign.signlink;
public final class Stream extends NodeSub {
private static final BigInteger RSA_MODULUS = new BigInteger("1015256098907560478534698852822847293361491689187658624475298309509929072293302099101284876188067821572111515263341189094639685749474191500586088561357231395107168085468676028652744790449891672295773971780936779008784201861833949");
private static final BigInteger RSA_EXPONENT = new BigInteger("65537");
public static Stream create() {
synchronized(nodeList) {
Stream stream = null;
if(anInt1412 > 0) {
anInt1412--;
stream = (Stream) nodeList.popHead();
}
if(stream != null) {
stream.currentOffset = 0;
return stream;
}
}
Stream stream_1 = new Stream();
stream_1.currentOffset = 0;
stream_1.buffer = new byte[5000];
return stream_1;
}
private Stream() {
}
public Stream(byte abyte0[]) {
buffer = abyte0;
currentOffset = 0;
}
public void createFrame(int i) {
//System.out.println("Frame: " + i);
buffer[currentOffset++] = (byte)(i + encryption.getNextKey());
}
public void writeWordBigEndian(int i) {
buffer[currentOffset++] = (byte)i;
}
public void writeWord(int i) {
buffer[currentOffset++] = (byte)(i >> 8);
buffer[currentOffset++] = (byte)i;
}
public void method400(int i) {
buffer[currentOffset++] = (byte)i;
buffer[currentOffset++] = (byte)(i >> 8);
}
public void writeDWordBigEndian(int i) {
buffer[currentOffset++] = (byte)(i >> 16);
buffer[currentOffset++] = (byte)(i >> 8);
buffer[currentOffset++] = (byte)i;
}
public void writeDWord(int i) {
buffer[currentOffset++] = (byte)(i >> 24);
buffer[currentOffset++] = (byte)(i >> 16);
buffer[currentOffset++] = (byte)(i >> 8);
buffer[currentOffset++] = (byte)i;
}
public void method403(int j) {
buffer[currentOffset++] = (byte)j;
buffer[currentOffset++] = (byte)(j >> 8);
buffer[currentOffset++] = (byte)(j >> 16);
buffer[currentOffset++] = (byte)(j >> 24);
}
public void writeQWord(long l) {
try {
buffer[currentOffset++] = (byte)(int)(l >> 56);
buffer[currentOffset++] = (byte)(int)(l >> 48);
buffer[currentOffset++] = (byte)(int)(l >> 40);
buffer[currentOffset++] = (byte)(int)(l >> 32);
buffer[currentOffset++] = (byte)(int)(l >> 24);
buffer[currentOffset++] = (byte)(int)(l >> 16);
buffer[currentOffset++] = (byte)(int)(l >> 8);
buffer[currentOffset++] = (byte)(int)l;
} catch(RuntimeException runtimeexception) {
signlink.reporterror("14395, " + 5 + ", " + l + ", " + runtimeexception.toString());
throw new RuntimeException();
}
}
public void writeString(String s) {
//s.getBytes(0, s.length(), buffer, currentOffset); //deprecated
System.arraycopy(s.getBytes(), 0, buffer, currentOffset, s.length());
currentOffset += s.length();
buffer[currentOffset++] = 10;
}
public void writeBytes(byte abyte0[], int i, int j) {
for(int k = j; k < j + i; k++)
buffer[currentOffset++] = abyte0[k];
}
public void writeBytes(int i) {
buffer[currentOffset - i - 1] = (byte)i;
}
public int readUnsignedByte() {
return buffer[currentOffset++] & 0xff;
}
public byte readSignedByte() {
return buffer[currentOffset++];
}
public int readUnsignedWord() {
currentOffset += 2;
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
}
public int readSignedWord() {
currentOffset += 2;
int i = ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
if(i > 32767)
i -= 0x10000;
return i;
}
public int read3Bytes() {
currentOffset += 3;
return ((buffer[currentOffset - 3] & 0xff) << 16) + ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
}
public int readDWord() {
currentOffset += 4;
return ((buffer[currentOffset - 4] & 0xff) << 24) + ((buffer[currentOffset - 3] & 0xff) << 16) + ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
}
public long readQWord() {
long l = (long) readDWord() & 0xffffffffL;
long l1 = (long) readDWord() & 0xffffffffL;
return (l << 32) + l1;
}
public String readString() {
int i = currentOffset;
while(buffer[currentOffset++] != 10) ;
return new String(buffer, i, currentOffset - i - 1);
}
public byte[] readBytes() {
int i = currentOffset;
while(buffer[currentOffset++] != 10) ;
byte abyte0[] = new byte[currentOffset - i - 1];
System.arraycopy(buffer, i, abyte0, i - i, currentOffset - 1 - i);
return abyte0;
}
public void readBytes(int i, int j, byte abyte0[]) {
for(int l = j; l < j + i; l++)
abyte0[l] = buffer[currentOffset++];
}
public void initBitAccess() {
bitPosition = currentOffset * 8;
}
public int readBits(int i) {
int k = bitPosition >> 3;
int l = 8 - (bitPosition & 7);
int i1 = 0;
bitPosition += i;
for(; i > l; l = 8)
{
i1 += (buffer[k++] & anIntArray1409[l]) << i - l;
i -= l;
}
if(i == l)
i1 += buffer[k] & anIntArray1409[l];
else
i1 += buffer[k] >> l - i & anIntArray1409[i];
return i1;
}
public void finishBitAccess() {
currentOffset = (bitPosition + 7) / 8;
}
public int method421() {
int i = buffer[currentOffset] & 0xff;
if(i < 128)
return readUnsignedByte() - 64;
else
return readUnsignedWord() - 49152;
}
public int method422() {
int i = buffer[currentOffset] & 0xff;
if(i < 128)
return readUnsignedByte();
else
return readUnsignedWord() - 32768;
}
public void doKeys() {
int i = currentOffset;
currentOffset = 0;
byte abyte0[] = new byte[i];
readBytes(i, 0, abyte0);
BigInteger biginteger2 = new BigInteger(abyte0);
BigInteger biginteger3 = biginteger2.modPow(RSA_EXPONENT, RSA_MODULUS);
byte abyte1[] = biginteger3.toByteArray();
currentOffset = 0;
writeWordBigEndian(abyte1.length);
writeBytes(abyte1, abyte1.length, 0);
}
public void method424(int i) {
buffer[currentOffset++] = (byte)(-i);
}
public void method425(int j) {
buffer[currentOffset++] = (byte)(128 - j);
}
public int method426() {
return buffer[currentOffset++] - 128 & 0xff;
}
public int method427() {
return -buffer[currentOffset++] & 0xff;
}
public int method428() {
return 128 - buffer[currentOffset++] & 0xff;
}
public byte method429() {
return (byte)(-buffer[currentOffset++]);
}
public byte method430() {
return (byte)(128 - buffer[currentOffset++]);
}
public void method431(int i) {
buffer[currentOffset++] = (byte)i;
buffer[currentOffset++] = (byte)(i >> 8);
}
public void method432(int j) {
buffer[currentOffset++] = (byte)(j >> 8);
buffer[currentOffset++] = (byte)(j + 128);
}
public void method433(int j) {
buffer[currentOffset++] = (byte)(j + 128);
buffer[currentOffset++] = (byte)(j >> 8);
}
public int method434() {
currentOffset += 2;
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
}
public int method435() {
currentOffset += 2;
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] - 128 & 0xff);
}
public int method436() {
currentOffset += 2;
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
}
public int method437() {
currentOffset += 2;
int j = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
if(j > 32767)
j -= 0x10000;
return j;
}
public int method438() {
currentOffset += 2;
int j = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
if(j > 32767)
j -= 0x10000;
return j;
}
public int method439() {
currentOffset += 4;
return ((buffer[currentOffset - 2] & 0xff) << 24) + ((buffer[currentOffset - 1] & 0xff) << 16) + ((buffer[currentOffset - 4] & 0xff) << 8) + (buffer[currentOffset - 3] & 0xff);
}
public int method440() {
currentOffset += 4;
return ((buffer[currentOffset - 3] & 0xff) << 24) + ((buffer[currentOffset - 4] & 0xff) << 16) + ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
}
public void method441(int i, byte abyte0[], int j) {
for(int k = (i + j) - 1; k >= i; k--)
buffer[currentOffset++] = (byte)(abyte0[k] + 128);
}
public void method442(int i, int j, byte abyte0[]) {
for(int k = (j + i) - 1; k >= j; k--)
abyte0[k] = buffer[currentOffset++];
}
public byte buffer[];
public int currentOffset;
public int bitPosition;
private static final int[] anIntArray1409 = {
0, 1, 3, 7, 15, 31, 63, 127, 255, 511,
1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff,
0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff,
0x3fffffff, 0x7fffffff, -1
};
public ISAACRandomGen encryption;
private static int anInt1412;
private static final NodeList nodeList = new NodeList();
public int v(int i) {
// TODO Auto-generated method stub
return 0;
}
}