小马软件库 v4.3版本的 MD5 值为:5bdc4b93cc4814bc786c18efbaeb25d1

以下内容为反编译后的 ServerSocket.java 源代码,内容仅作参考


package i.app;

import android.content.Context;
import i.runlibrary.a.o;
import i.runlibrary.a.s;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ServerSocket {
    private List a;
    private Context b;
    public String bm;
    private java.net.ServerSocket c;
    private int d;
    private int e;
    private int f;
    private String g;
    private socketServer h;

    private OnMessagesListener f256i;
    private int j;
    public boolean jsqq;

    public interface OnMessagesListener {
        void Accept(ServerSocket serverSocket, socketServer socketserver);

        void Message(socketServer socketserver, int i2, String str, byte[] bArr);
    }

    public class socketServer {
        private Socket b;
        public Object obj = null;
        public Object[] objsz = null;

        public socketServer(Socket socket) {
            this.b = socket;
            a();
        }

        private void a() {
            new f(this).start();
        }

        public static void a(socketServer socketserver, InputStream inputStream, int i2, byte[] bArr) {
            int i3;
            int i4 = i2;
            while (true) {
                if (i4 < 32 || !i.runlibrary.a.f.c(bArr)) {
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    byteArrayOutputStream.write(bArr, 0, i4);
                    boolean z = false;
                    while (true) {
                        if (socketserver.b.isClosed() || inputStream.available() <= 0) {
                            break;
                        }
                        i4 = inputStream.read(bArr);
                        if (i4 > 0) {
                            if (i4 >= 32 && i.runlibrary.a.f.c(bArr)) {
                                z = true;
                                break;
                            }
                            byteArrayOutputStream.write(bArr, 0, i4);
                        }
                    }
                    ServerSocket.this.f256i.Message(socketserver, 0, null, byteArrayOutputStream.toByteArray());
                    byteArrayOutputStream.close();
                    if (!z) {
                        return;
                    }
                } else {
                    byte b = bArr[6];
                    int a = i.runlibrary.a.f.a(bArr);
                    String b2 = b == 2 ? i.runlibrary.a.f.b(bArr) : null;
                    if (a <= 0) {
                        return;
                    }
                    ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
                    if (i4 > 32) {
                        i3 = i4 - 32;
                        if (i3 <= a) {
                            byteArrayOutputStream2.write(bArr, 32, i3);
                            if (a > i3) {
                                a -= i3;
                            }
                        } else {
                            byteArrayOutputStream2.write(bArr, 32, a);
                        }
                        if (a <= i3) {
                            byte[] byteArray = byteArrayOutputStream2.toByteArray();
                            OnMessagesListener onMessagesListener = ServerSocket.this.f256i;
                            if (b == 1) {
                                b2 = new String(byteArray, ServerSocket.this.bm);
                            }
                            onMessagesListener.Message(socketserver, b, b2, byteArray);
                            byteArrayOutputStream2.close();
                            if (i3 <= a) {
                                return;
                            }
                            byte[] bArr2 = new byte[i3 - a];
                            int i5 = 0;
                            for (int i6 = a + 32; i6 < i4; i6++) {
                                bArr2[i5] = bArr[i6];
                                i5++;
                            }
                            i4 = bArr2.length;
                            bArr = bArr2;
                        }
                    } else {
                        i3 = i4;
                    }
                    while (true) {
                        if (socketserver.b.isClosed()) {
                            break;
                        }
                        i3 = inputStream.read(bArr);
                        if (i3 > 0) {
                            if (i3 > a) {
                                byteArrayOutputStream2.write(bArr, 0, a);
                                break;
                            }
                            byteArrayOutputStream2.write(bArr, 0, i3);
                            if (a == i3) {
                                break;
                            } else {
                                a -= i3;
                            }
                        }
                    }
                    if (a > i3) {
                        return;
                    }
                    byte[] byteArray2 = byteArrayOutputStream2.toByteArray();
                    OnMessagesListener onMessagesListener2 = ServerSocket.this.f256i;
                    if (b == 1) {
                        b2 = new String(byteArray2, ServerSocket.this.bm);
                    }
                    onMessagesListener2.Message(socketserver, b, b2, byteArray2);
                    byteArrayOutputStream2.close();
                    if (i3 <= a) {
                        return;
                    }
                    byte[] bArr3 = new byte[i3 - a];
                    int i7 = 0;
                    while (a < i3) {
                        bArr3[i7] = bArr[a];
                        i7++;
                        a++;
                    }
                    bArr = bArr3;
                    i4 = bArr3.length;
                }
            }
        }

        public int bjdk() {
            return this.b.getLocalPort();
        }

        public String bjip() {
            return this.b.getLocalAddress().getHostAddress();
        }

        public boolean cq() {
            try {
                if (this.b.isClosed()) {
                    if (ServerSocket.this.e > 0) {
                        this.b.connect(this.b.getRemoteSocketAddress(), ServerSocket.this.e);
                    } else {
                        this.b.connect(this.b.getRemoteSocketAddress());
                    }
                    if (!this.b.isClosed()) {
                        if (!ServerSocket.this.a.contains(this)) {
                            ServerSocket.this.a.add(this);
                        }
                        a();
                    }
                    return true;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return false;
        }

        public int dk() {
            return this.b.getPort();
        }

        public void gb() {
            if (this.b.isClosed()) {
                return;
            }
            ServerSocket.this.a.remove(this);
            try {
                this.b.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public String ip() {
            return this.b.getInetAddress().getHostAddress();
        }

        public Socket ljdx() {
            return this.b;
        }

        public boolean sc(Object obj) {
            return ServerSocket.this.a(this, obj);
        }

        public boolean sc(Object obj, Object obj2) {
            return ServerSocket.this.a(this, obj, obj2);
        }

        public boolean sfgb() {
            return this.b.isClosed();
        }

        public Object sj() {
            return this.obj;
        }

        public void sj(Object obj) {
            this.obj = obj;
        }

        public void szsj(Object obj) {
            this.objsz = s.c(obj);
        }

        public Object[] szsj() {
            return this.objsz;
        }
    }

    public ServerSocket(Context context, int i2, int i3, int i4, boolean z, OnMessagesListener onMessagesListener) {
        this.a = new ArrayList();
        this.c = null;
        this.jsqq = true;
        this.d = 0;
        this.e = 0;
        this.bm = "utf-8";
        this.h = null;
        this.f256i = null;
        this.j = 0;
        this.j = 1;
        this.b = context;
        try {
            this.c = new java.net.ServerSocket(i2);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (i3 > 0) {
            try {
                this.c.setSoTimeout(i3);
            } catch (SocketException e2) {
                e2.printStackTrace();
            }
        }
        this.f = i2;
        this.d = i3;
        this.e = i4;
        this.jsqq = z;
        this.f256i = onMessagesListener;
    }

    public ServerSocket(Context context, String str, int i2, int i3, OnMessagesListener onMessagesListener) {
        this.a = new ArrayList();
        this.c = null;
        this.jsqq = true;
        this.d = 0;
        this.e = 0;
        this.bm = "utf-8";
        this.h = null;
        this.f256i = null;
        this.j = 0;
        this.j = 2;
        this.b = context;
        this.g = str;
        this.f = i2;
        this.e = i3;
        this.f256i = onMessagesListener;
    }

    public boolean a(socketServer socketserver, Object obj) {
        byte[] bytes = o.toBytes(obj, this.bm, null);
        if (bytes != null) {
            return a(socketserver.b, bytes);
        }
        return false;
    }

    public boolean a(socketServer socketserver, Object obj, Object obj2) {
        Object obj3;
        File file;
        int d = s.d(obj);
        if (d == 2) {
            file = obj2 instanceof File ? (File) obj2 : new File(i.runlibrary.a.d.a(this.b, obj2.toString()));
            if (!file.exists() || !file.isFile()) {
                return false;
            }
            obj3 = file;
        } else {
            obj3 = obj2;
            file = null;
        }
        byte[] bytes = o.toBytes(obj3, this.bm, null);
        if (bytes != null) {
            return a(socketserver.b, i.runlibrary.a.f.a(bytes, d, file)) && a(socketserver.b, bytes);
        }
        return false;
    }

    private static boolean a(Socket socket, byte[] bArr) {
        try {
            socket.getOutputStream().write(bArr);
            socket.getOutputStream().flush();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

    public int bjdk() {
        if (this.c != null) {
            return this.c.getLocalPort();
        }
        if (this.h != null) {
            return this.h.b.getLocalPort();
        }
        return -1;
    }

    public String bjip() {
        if (this.c != null) {
            return "127.0.0.1";
        }
        if (this.h != null) {
            return this.h.b.getLocalAddress().getHostAddress();
        }
        return null;
    }

    public void cq() {
        if (this.j != 1) {
            if (this.j == 2 && this.h.sfgb()) {
                ks();
                return;
            }
            return;
        }
        if (this.c.isClosed()) {
            try {
                this.c = new java.net.ServerSocket(this.f);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (this.d > 0) {
                try {
                    this.c.setSoTimeout(this.d);
                } catch (SocketException e2) {
                    e2.printStackTrace();
                }
            }
            ks();
        }
    }

    public java.net.ServerSocket fwd() {
        return this.c;
    }

    public void gb() {
        this.jsqq = false;
        Iterator it = this.a.iterator();
        while (it.hasNext()) {
            try {
                ((socketServer) it.next()).gb();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        this.a.clear();
        if (this.c == null || this.c.isClosed()) {
            return;
        }
        try {
            this.c.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }

    public void ks() {
        if (this.j != 1) {
            if (this.j == 2) {
                try {
                    Socket socket = new Socket(this.g, this.f);
                    if (this.e != 0) {
                        socket.setSoTimeout(this.e);
                    }
                    this.h = new socketServer(socket);
                    this.a.add(this.h);
                    return;
                } catch (IOException e) {
                    e.printStackTrace();
                    return;
                }
            }
            return;
        }
        while (!this.c.isClosed()) {
            try {
                Socket accept = this.c.accept();
                if (this.jsqq) {
                    if (this.e > 0) {
                        accept.setSoTimeout(this.e);
                    }
                    socketServer socketserver = new socketServer(accept);
                    this.a.add(socketserver);
                    this.f256i.Accept(this, socketserver);
                } else {
                    accept.close();
                }
            } catch (SocketTimeoutException e2) {
                e2.printStackTrace();
            } catch (IOException e3) {
                e3.printStackTrace();
            }
        }
        try {
            this.c.close();
        } catch (IOException e4) {
            e4.printStackTrace();
        }
    }

    public socketServer lj(Object obj) {
        int d = s.d(obj);
        if (d < 0 || this.a.size() <= d) {
            return null;
        }
        return (socketServer) this.a.get(d);
    }

    public List lj() {
        return this.a;
    }

    public void ljqk() {
        if (this.c != null) {
            Iterator it = this.a.iterator();
            while (it.hasNext()) {
                try {
                    ((socketServer) it.next()).gb();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            this.a.clear();
        }
    }

    public int ljzs() {
        return this.a.size();
    }

    public int sc(Object obj) {
        int i2 = 0;
        Iterator it = this.a.iterator();
        while (true) {
            int i3 = i2;
            if (!it.hasNext()) {
                return i3;
            }
            socketServer socketserver = (socketServer) it.next();
            if (!socketserver.sfgb() && a(socketserver, obj)) {
                i3++;
            }
            i2 = i3;
        }
    }

    public int sc(Object obj, Object obj2) {
        int i2 = 0;
        Iterator it = this.a.iterator();
        while (true) {
            int i3 = i2;
            if (!it.hasNext()) {
                return i3;
            }
            socketServer socketserver = (socketServer) it.next();
            if (!socketserver.sfgb() && a(socketserver, obj, obj2)) {
                i3++;
            }
            i2 = i3;
        }
    }

    public boolean sfgb() {
        if (this.c != null) {
            return this.c.isClosed();
        }
        if (this.h != null) {
            return this.h.sfgb();
        }
        return true;
    }
}