360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0

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


package com.qihoo360.mobilesafe.pcdaemon.service;

import com.qihoo.speedometer.Config;
import com.qihoo360.mobilesafe.pcdaemon.data.FilePdu;
import com.qihoo360.mobilesafe.pcdaemon.data.InputStreamPdu;
import com.qihoo360.mobilesafe.pcdaemon.data.PduBase;
import com.qihoo360.mobilesafe.pcdaemon.data.SimpleBufferPdu;
import com.qihoo360.mobilesafe.pcdaemon.w;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.concurrent.atomic.AtomicInteger;

public class a implements Runnable {

    private static final AtomicInteger f5545a = new AtomicInteger(0);

    private final Socket f5546b;
    private DataOutputStream c;
    private DataInputStream d;
    private String h;
    private String i;
    private final d m;
    private String e = getClass().getSimpleName();
    private String f = Config.INVALID_IP;
    private String g = Config.INVALID_IP;
    private String j = null;
    private b k = null;
    private Thread l = null;

    public a(Socket socket, d dVar) {
        this.h = null;
        this.i = null;
        this.h = Config.INVALID_IP + f5545a.incrementAndGet();
        this.f5546b = socket;
        this.m = dVar;
        this.i = this.f5546b.getInetAddress().getHostAddress();
        this.e += "(" + a() + ")";
    }

    public com.qihoo360.mobilesafe.util.g a(com.qihoo360.mobilesafe.util.g gVar) {
        if (Thread.currentThread() != this.l) {
            throw new w("readFollowingPduDataBuffer Must Be Performed on Socket Reading Thread of Current Session");
        }
        int readLong = (int) this.d.readLong();
        if (gVar == null) {
            gVar = new com.qihoo360.mobilesafe.util.g();
        }
        if (gVar.f5649a == null || readLong > gVar.f5649a.length) {
            gVar.f5649a = new byte[readLong];
        }
        gVar.f5650b = 0;
        gVar.c = 0;
        this.d.readFully(gVar.f5649a, 0, readLong);
        gVar.c = readLong;
        if (g()) {
            m.d(readLong + 8);
        }
        return gVar;
    }

    public com.qihoo360.mobilesafe.util.g a(com.qihoo360.mobilesafe.util.g gVar, int i) {
        if (Thread.currentThread() != this.l) {
            throw new w("readFollowingPduDataBuffer Must Be Performed on Socket Reading Thread of Current Session");
        }
        if (gVar == null) {
            gVar = new com.qihoo360.mobilesafe.util.g();
        }
        if (gVar.f5649a == null || i > gVar.f5649a.length) {
            gVar.f5649a = new byte[i];
        }
        gVar.f5650b = 0;
        gVar.c = 0;
        this.d.readFully(gVar.f5649a, 0, i);
        gVar.c = i;
        if (g()) {
            m.d(i);
        }
        return gVar;
    }

    public String a() {
        return this.h;
    }

    public void a(String str) {
        this.j = str;
    }

    public synchronized boolean a(PduBase pduBase) {
        boolean z;
        BufferedInputStream bufferedInputStream;
        BufferedInputStream bufferedInputStream2;
        if (this.c == null || this.f5546b == null || this.f5546b.isOutputShutdown()) {
            com.qihoo360.mobilesafe.util.h.c(this.e, "Socket Closed When Sending < %s >", pduBase);
            z = false;
        } else {
            com.qihoo360.mobilesafe.util.h.b(this.e, "Sending < %s >", pduBase);
            try {
                if (pduBase instanceof FilePdu) {
                    this.c.writeInt(3539808);
                    this.c.writeShort(pduBase.c);
                    if (pduBase.d != null) {
                        this.c.writeInt(pduBase.d.length);
                        this.c.write(pduBase.d);
                    }
                    this.c.flush();
                    if (g()) {
                        m.b(10L);
                        if (pduBase.d != null) {
                            m.b(pduBase.d.length);
                        }
                    }
                    FilePdu filePdu = (FilePdu) pduBase;
                    File a2 = filePdu.a();
                    if (a2 != null && a2.exists() && a2.isFile()) {
                        try {
                            bufferedInputStream2 = new BufferedInputStream(new FileInputStream(a2));
                        } catch (Throwable th) {
                            th = th;
                            bufferedInputStream = null;
                        }
                        try {
                            this.c.writeLong(bufferedInputStream2.available());
                            byte[] bArr = new byte[1048576];
                            while (true) {
                                int read = bufferedInputStream2.read(bArr);
                                if (read == -1) {
                                    break;
                                }
                                this.c.write(bArr, 0, read);
                            }
                            if (bufferedInputStream2 != null) {
                                try {
                                    bufferedInputStream2.close();
                                } catch (Exception e) {
                                }
                            }
                            this.c.flush();
                            if (filePdu.f5501b) {
                                a2.delete();
                            }
                            if (g()) {
                                m.b(8 + a2.length());
                            }
                        } catch (Throwable th2) {
                            th = th2;
                            bufferedInputStream = bufferedInputStream2;
                            if (bufferedInputStream != null) {
                                try {
                                    bufferedInputStream.close();
                                } catch (Exception e2) {
                                }
                            }
                            throw th;
                        }
                    }
                } else if (pduBase instanceof InputStreamPdu) {
                    this.c.writeInt(3539808);
                    this.c.writeShort(pduBase.c);
                    if (pduBase.d != null) {
                        this.c.writeInt(pduBase.d.length);
                        this.c.write(pduBase.d);
                    }
                    this.c.flush();
                    if (g()) {
                        m.b(10L);
                        if (pduBase.d != null) {
                            m.b(pduBase.d.length);
                        }
                    }
                    InputStream inputStream = ((InputStreamPdu) pduBase).f5502a;
                    if (inputStream != null && inputStream.available() > 0) {
                        long j = 0;
                        this.c.writeLong(inputStream.available());
                        byte[] bArr2 = new byte[1024000];
                        while (true) {
                            int read2 = inputStream.read(bArr2);
                            if (read2 != -1) {
                                this.c.write(bArr2, 0, read2);
                                j += read2;
                            } else {
                                try {
                                    break;
                                } catch (Exception e3) {
                                }
                            }
                        }
                        inputStream.close();
                        this.c.flush();
                        if (g()) {
                            m.b(j + 8);
                        }
                    }
                } else if (pduBase instanceof SimpleBufferPdu) {
                    this.c.writeInt(3539808);
                    this.c.writeShort(pduBase.c);
                    this.c.writeInt(pduBase.d.length);
                    this.c.write(pduBase.d);
                    byte[] a3 = ((SimpleBufferPdu) pduBase).a(this);
                    this.c.writeLong(a3.length);
                    this.c.write(a3);
                    this.c.flush();
                    if (g()) {
                        m.b(10L);
                        if (pduBase.d != null) {
                            m.b(pduBase.d.length);
                        }
                        if (a3 != null) {
                            m.b(a3.length + 8);
                        }
                    }
                } else {
                    this.c.writeInt(3539808);
                    this.c.writeShort(pduBase.c);
                    if (pduBase.d != null) {
                        this.c.writeInt(pduBase.d.length);
                        this.c.write(pduBase.d);
                    }
                    this.c.flush();
                    if (g()) {
                        m.b(10L);
                        if (pduBase.d != null) {
                            m.b(pduBase.d.length);
                        }
                    }
                }
                com.qihoo360.mobilesafe.util.h.b(this.e, "End Send Pdu < %s >", pduBase);
                z = true;
            } catch (IOException e4) {
                com.qihoo360.mobilesafe.util.h.c(this.e, e4, "Error When Sending < %s >", pduBase);
                z = false;
            }
        }
        return z;
    }

    public String b() {
        return this.i;
    }

    public void b(String str) {
        this.g = str;
    }

    public String c() {
        return this.j;
    }

    public String d() {
        return this.i + "-" + this.j;
    }

    public String e() {
        return this.g;
    }

    public Socket f() {
        return this.f5546b;
    }

    public boolean g() {
        return "127.0.0.1".equalsIgnoreCase(this.i);
    }

    public DataInputStream h() {
        return this.d;
    }

    public PduBase i() {
        if (Thread.currentThread() != this.l) {
            throw new w("readFollowingPduBase Must Be Performed on Socket Reading Thread of Current Session");
        }
        int readInt = this.d.readInt();
        if (g()) {
            m.d(4L);
        }
        if (readInt != 3539808) {
            com.qihoo360.mobilesafe.util.h.d(this.e, "Reading Following Command of Bad Magic Code: %d", Integer.valueOf(readInt));
            throw new w("readFollowingPduBase Magic Code Error");
        }
        short readShort = this.d.readShort();
        int readInt2 = this.d.readInt();
        if (g()) {
            m.d(6L);
        }
        if (readInt2 <= 0 || readInt2 > 3145728) {
            com.qihoo360.mobilesafe.util.h.d(this.e, "Reading Following Command of Illegal Length: %d and PduType: %d", Integer.valueOf(readInt2), Short.valueOf(readShort));
            throw new w("readFollowingPduBase Received Illegal Length");
        }
        byte[] bArr = new byte[readInt2];
        this.d.readFully(bArr);
        PduBase pduBase = new PduBase();
        pduBase.c = readShort;
        pduBase.d = bArr;
        com.qihoo360.mobilesafe.util.h.b(this.e, "Reading Following < %s >", pduBase);
        if (g()) {
            m.d(readInt2);
        }
        return pduBase;
    }

    public void j() {
        Socket socket = this.f5546b;
        if (socket != null) {
            try {
                socket.close();
            } catch (Exception e) {
            }
        }
    }

    @Override
    public void run() {
        if (this.f5546b == null) {
            return;
        }
        com.qihoo360.mobilesafe.util.h.b(this.e, "Session Started of Socket, Local: %s, INet: %s", this.f5546b.getLocalAddress(), this.f5546b.getInetAddress());
        try {
            try {
                try {
                    this.d = new DataInputStream(new BufferedInputStream(this.f5546b.getInputStream(), 8096));
                    this.c = new DataOutputStream(new BufferedOutputStream(this.f5546b.getOutputStream(), 8096));
                    byte[] bArr = new byte[4];
                    this.l = Thread.currentThread();
                    this.k = new b(this, this.l, 200L, 1000L);
                    while (!this.f5546b.isClosed()) {
                        if (this.d.available() <= 0 || this.d.available() >= 4) {
                            int readInt = this.d.readInt();
                            if (g()) {
                                m.d(4L);
                            }
                            if (readInt != 3539808) {
                                com.qihoo360.mobilesafe.util.h.d(this.e, "Cleaning Bad Magic Code: %d", Integer.valueOf(readInt));
                            } else {
                                short readShort = this.d.readShort();
                                if (g()) {
                                    m.d(2L);
                                }
                                if (readShort == 3) {
                                    if (this.f == Config.INVALID_IP) {
                                        this.f = "L";
                                        this.e += this.f;
                                    }
                                    int readInt2 = this.d.readInt();
                                    if (g()) {
                                        m.d(4L);
                                    }
                                    if (readInt2 <= 0 || readInt2 > 3145728) {
                                        com.qihoo360.mobilesafe.util.h.d(this.e, "Reading Command of Illegal Length: %d", Integer.valueOf(readInt2));
                                        break;
                                    }
                                    byte[] bArr2 = new byte[readInt2];
                                    this.d.readFully(bArr2);
                                    if (g()) {
                                        m.d(readInt2);
                                    }
                                    PduBase pduBase = new PduBase(readShort, bArr2);
                                    com.qihoo360.mobilesafe.util.h.b(this.e, "Reading < %s >", pduBase);
                                    this.k.a();
                                    PduBase a2 = this.m.a(this, pduBase);
                                    if (a2 != null) {
                                        a(a2);
                                    }
                                    this.k.a("Cmd: < %s >, Ret: < %s >", pduBase, a2);
                                } else if (readShort == 1 || readShort == 2) {
                                    this.f5546b.setSoTimeout(20000);
                                    int readInt3 = this.d.readInt();
                                    if (g()) {
                                        m.d(4L);
                                    }
                                    if (readInt3 <= 0 || readInt3 > 3145728) {
                                        com.qihoo360.mobilesafe.util.h.d(this.e, "Reading Command of Illegal Length: %d", Integer.valueOf(readInt3));
                                        break;
                                    }
                                    byte[] bArr3 = new byte[readInt3];
                                    this.d.readFully(bArr3);
                                    if (g()) {
                                        m.d(readInt3);
                                    }
                                    PduBase pduBase2 = new PduBase();
                                    pduBase2.c = readShort;
                                    pduBase2.d = bArr3;
                                    com.qihoo360.mobilesafe.util.h.b(this.e, "Reading < %s >", pduBase2);
                                    this.k.a();
                                    PduBase a3 = this.m.a(this, pduBase2);
                                    if (a3 != null) {
                                        a(a3);
                                    }
                                    this.k.a("Cmd: < %s >, Ret: < %s >", pduBase2, a3);
                                }
                            }
                        } else {
                            com.qihoo360.mobilesafe.util.h.d(this.e, "Cleaning Bad Data of %d Bytes", Integer.valueOf(this.d.read(bArr)));
                        }
                    }
                    try {
                        if (this.d != null) {
                            this.d.close();
                        }
                        if (this.c != null) {
                            this.c.close();
                        }
                        if (this.f5546b != null) {
                            this.f5546b.shutdownInput();
                            this.f5546b.shutdownOutput();
                            this.f5546b.close();
                        }
                    } catch (Exception e) {
                    }
                    com.qihoo360.mobilesafe.util.h.b(this.e, "On Session Closed", new Object[0]);
                    this.m.a(this);
                } catch (Exception e2) {
                }
            } catch (EOFException e3) {
                com.qihoo360.mobilesafe.util.h.b(this.e, e3, "EOFException Causing Session Closing:" + e3.toString(), new Object[0]);
                try {
                    if (this.d != null) {
                        this.d.close();
                    }
                    if (this.c != null) {
                        this.c.close();
                    }
                    if (this.f5546b != null) {
                        this.f5546b.shutdownInput();
                        this.f5546b.shutdownOutput();
                        this.f5546b.close();
                    }
                } catch (Exception e4) {
                }
                com.qihoo360.mobilesafe.util.h.b(this.e, "On Session Closed", new Object[0]);
                this.m.a(this);
            } catch (SocketTimeoutException e5) {
                com.qihoo360.mobilesafe.util.h.b(this.e, e5, "SocketTimeoutException Causing Session Closing:" + e5.toString(), new Object[0]);
                try {
                    if (this.d != null) {
                        this.d.close();
                    }
                    if (this.c != null) {
                        this.c.close();
                    }
                    if (this.f5546b != null) {
                        this.f5546b.shutdownInput();
                        this.f5546b.shutdownOutput();
                        this.f5546b.close();
                    }
                } catch (Exception e6) {
                }
                com.qihoo360.mobilesafe.util.h.b(this.e, "On Session Closed", new Object[0]);
                this.m.a(this);
            } catch (Throwable th) {
                com.qihoo360.mobilesafe.util.h.c(this.e, th, "Unexpected Exception Causing Session Closing:" + th.toString(), new Object[0]);
                try {
                    if (this.d != null) {
                        this.d.close();
                    }
                    if (this.c != null) {
                        this.c.close();
                    }
                    if (this.f5546b != null) {
                        this.f5546b.shutdownInput();
                        this.f5546b.shutdownOutput();
                        this.f5546b.close();
                    }
                } catch (Exception e7) {
                }
                com.qihoo360.mobilesafe.util.h.b(this.e, "On Session Closed", new Object[0]);
                this.m.a(this);
            }
        } catch (Throwable th2) {
            try {
                if (this.d != null) {
                    this.d.close();
                }
                if (this.c != null) {
                    this.c.close();
                }
                if (this.f5546b != null) {
                    this.f5546b.shutdownInput();
                    this.f5546b.shutdownOutput();
                    this.f5546b.close();
                }
            } catch (Exception e8) {
            }
            try {
                com.qihoo360.mobilesafe.util.h.b(this.e, "On Session Closed", new Object[0]);
                this.m.a(this);
                throw th2;
            } catch (Exception e9) {
                throw th2;
            }
        }
    }
}