add src files decompiled via jad
[rsa2client.git] / src / mcsClient / McsTcpConnection.java
diff --git a/src/mcsClient/McsTcpConnection.java b/src/mcsClient/McsTcpConnection.java
new file mode 100644 (file)
index 0000000..7e73d71
--- /dev/null
@@ -0,0 +1,194 @@
+// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
+// Jad home page: http://www.kpdus.com/jad.html
+// Decompiler options: packimports(3) fieldsfirst nonlb space 
+
+package mcsClient;
+
+import Acme.Crypto.DesCipher;
+import java.io.*;
+import java.net.*;
+import java.util.Arrays;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+
+public class McsTcpConnection {
+
+    private DataInputStream socketInput;
+    private DataOutputStream socketOutput;
+    private boolean detectedPPP;
+    private int localPort;
+    private InetAddress localAddress;
+    Socket connection;
+    private boolean connected;
+    private boolean encrypt;
+    public DesCipher cipher1;
+    public DesCipher cipher2;
+    private boolean debug;
+
+    public McsTcpConnection(String s, int i, boolean flag, String s1) {
+        socketInput = null;
+        socketOutput = null;
+        detectedPPP = false;
+        connection = null;
+        connected = false;
+        debug = false;
+        Object obj = null;
+        Object obj1 = null;
+        Object obj2 = null;
+        encrypt = flag;
+        try {
+            connection = new Socket(s, i);
+            connection.setTcpNoDelay(true);
+            connection.setReceiveBufferSize(0x20000);
+            NetworkInterface networkinterface = NetworkInterface.getByInetAddress(connection.getLocalAddress());
+            if (networkinterface.getDisplayName().indexOf("PPP") != -1 || networkinterface.getDisplayName().indexOf("ppp") != -1)
+                detectedPPP = true;
+            localPort = connection.getLocalPort();
+            localAddress = connection.getLocalAddress();
+            java.io.InputStream inputstream = connection.getInputStream();
+            java.io.OutputStream outputstream = connection.getOutputStream();
+            System.out.println("Connected via socket: " + connection);
+            socketInput = new DataInputStream(new BufferedInputStream(inputstream));
+            socketOutput = new DataOutputStream(new BufferedOutputStream(outputstream));
+            connected = true;
+            if (flag) {
+                byte abyte0[] = new byte[8];
+                byte abyte1[] = {
+                    34, 17, 31, 76, 113, 30, 91, 115
+                };
+                for (int j = 0; j < 8; j++) {
+                    abyte0[j] = (byte)s1.toCharArray()[j];
+                    abyte1[j] = (byte)(abyte1[j] ^ (byte)s1.toCharArray()[j]);
+                }
+
+                if (debug)
+                    System.out.println("mcsTcpConnection: accessCode = " + s1);
+                cipher1 = new DesCipher(abyte0);
+                cipher2 = new DesCipher(abyte1);
+            }
+        }
+        catch (UnknownHostException unknownhostexception) {
+            close();
+            System.err.println(unknownhostexception);
+            JOptionPane.showMessageDialog(new JFrame(), "Unknown host: " + s, "Remote Console Connection Error", 0);
+        }
+        catch (ConnectException connectexception) {
+            close();
+            System.err.println(connectexception);
+            JOptionPane.showMessageDialog(new JFrame(), "Unable to connect to to " + s + ":" + i + ".", "Remote Console Connection Error", 0);
+        }
+        catch (IOException ioexception) {
+            close();
+            System.err.println(ioexception);
+            JOptionPane.showMessageDialog(new JFrame(), "Connection to " + s + " lost.", "Remote Console Connection Error", 0);
+        }
+    }
+
+    boolean getDetectedPPP() {
+        return detectedPPP;
+    }
+
+    DataInputStream getSocketInput() {
+        return socketInput;
+    }
+
+    int getLocalPort() {
+        return localPort;
+    }
+
+    InetAddress getLocalAddress() {
+        return localAddress;
+    }
+
+    public synchronized void sendMessage(int ai[], boolean flag) throws IOException {
+        if (encrypt) {
+            int l = ai.length * 4;
+            byte abyte0[] = new byte[l];
+            int i1 = 0;
+            for (int i = 0; i < ai.length; i++) {
+                int k = i * 4;
+                abyte0[k] = (byte)((ai[i] & 0xff000000) >> 24);
+                abyte0[k + 1] = (byte)((ai[i] & 0xff0000) >> 16);
+                abyte0[k + 2] = (byte)((ai[i] & 0xff00) >> 8);
+                abyte0[k + 3] = (byte)(ai[i] & 0xff);
+            }
+
+            if (l % 8 > 0)
+                i1 = 8 - l % 8;
+            int j1 = (l + i1) / 8;
+            byte abyte1[] = new byte[j1 * 8];
+            System.arraycopy(abyte0, 0, abyte1, 0, l);
+            if (i1 > 0) {
+                abyte1[abyte1.length - 1] = (byte)i1;
+                if (i1 > 1)
+                    Arrays.fill(abyte1, abyte1.length - i1, abyte1.length - 2, (byte)0);
+            }
+            try {
+                socketOutput.write(encrypt(abyte1, abyte1.length), 0, abyte1.length);
+                if (flag)
+                    socketOutput.flush();
+            }
+            catch (IOException ioexception1) {
+                close();
+                throw ioexception1;
+            }
+        } else {
+            try {
+                for (int j = 0; j < ai.length; j++)
+                    socketOutput.writeInt(ai[j]);
+
+                if (flag)
+                    socketOutput.flush();
+            }
+            catch (IOException ioexception) {
+                close();
+                throw ioexception;
+            }
+        }
+    }
+
+    public synchronized void sendMessage(int ai[]) throws IOException {
+        sendMessage(ai, true);
+    }
+
+    public void close() {
+        connected = false;
+        try {
+            if (connection != null) {
+                connection.close();
+                connection = null;
+            }
+        }
+        catch (IOException ioexception) {
+            System.err.println("Socket already closed.");
+        }
+    }
+
+    public boolean connected() {
+        return connected;
+    }
+
+    public boolean videoEncrypted() {
+        return encrypt;
+    }
+
+    public byte[] decrypt(byte abyte0[], int i, int j) {
+        for (int k = j; k < i + j; k += 8) {
+            cipher1.decrypt(abyte0, k, abyte0, k);
+            cipher2.encrypt(abyte0, k, abyte0, k);
+            cipher1.decrypt(abyte0, k, abyte0, k);
+        }
+
+        return abyte0;
+    }
+
+    public byte[] encrypt(byte abyte0[], int i) {
+        for (int j = 0; j < i; j += 8) {
+            cipher1.encrypt(abyte0, j, abyte0, j);
+            cipher2.decrypt(abyte0, j, abyte0, j);
+            cipher1.encrypt(abyte0, j, abyte0, j);
+        }
+
+        return abyte0;
+    }
+}