导航菜单

页面标题

页面副标题

SpinDisplay v2.0.2.6 - UdpService.java 源代码

正在查看: SpinDisplay v2.0.2.6 应用的 UdpService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.dmz.f20ad.connect;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import b.u.y;
import com.dmz.f20ad.App;
import com.dmz.f20ad.connect.UdpService;
import d.e.a.p.n0;
import d.e.a.p.p0;
import d.e.a.p.q0;
import d.e.a.t.h;
import d.e.a.t.j;
import g.a.e;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import me.zhanghai.android.materialprogressbar.BuildConfig;

public class UdpService extends Service {

    public static int f3078e;

    public static SharedPreferences f3082i;

    public Context f3086b;

    public g.a.n.a f3087c;

    public List<String> f3088d;

    public static HashMap<String, n0> f3079f = new HashMap<>();

    public static boolean f3080g = false;

    public static HashMap<String, j> f3081h = new HashMap<>();

    public static Handler f3083j = new a();

    public static HashMap<String, Timer> f3084k = new HashMap<>();

    public static boolean f3085l = false;

    public class a extends Handler {
        @Override
        @SuppressLint({"WrongConstant"})
        public void handleMessage(Message message) {
            super.handleMessage(message);
            y.e((String) message.obj);
        }
    }

    public class b extends TimerTask {
        public b() {
        }

        @Override
        public void run() {
            UdpService.this.f3088d.clear();
        }
    }

    public class c extends TimerTask {

        public final j f3090b;

        public c(j jVar) {
            this.f3090b = jVar;
        }

        @Override
        @SuppressLint({"WrongConstant"})
        public void run() {
            Message message = new Message();
            message.obj = App.f2838g.getApplicationContext().getString(2131755374, this.f3090b.f5390c);
            UdpService.f3083j.sendMessage(message);
            UdpService.f3081h.remove(this.f3090b.f5393f.toString());
        }
    }

    public static void a(Object obj) {
    }

    public static void b(Object obj) {
    }

    public void a(Throwable th) {
        StringBuilder a2 = d.b.a.a.a.a("startUDPBroadcast: ");
        a2.append(th.getMessage());
        Log.e("wyt UdpService", a2.toString());
        c();
    }

    public final void a(InetAddress inetAddress, j jVar) {
        n0 n0Var;
        if (!f3079f.containsKey(jVar.f5391d)) {
            n0Var = new n0();
            if (!n0Var.a(jVar.f5392e, inetAddress, jVar.f5391d)) {
                return;
            }
        } else {
            if (!f3079f.get(jVar.f5391d).F) {
                return;
            }
            n0Var = f3079f.get(jVar.f5391d);
            if (!n0Var.a(jVar.f5392e, inetAddress, jVar.f5391d)) {
                return;
            }
        }
        f3079f.put(jVar.f5391d, n0Var);
        a("deviceconnected", 0, jVar.f5391d, null);
    }

    public Object b() {
        j jVar;
        j jVar2;
        Message message;
        String string;
        DatagramSocket datagramSocket = new DatagramSocket((SocketAddress) null);
        int i2 = 0;
        datagramSocket.setSoTimeout(0);
        datagramSocket.setReuseAddress(true);
        datagramSocket.bind(new InetSocketAddress(50105));
        byte[] bArr = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bArr, bArr.length);
        while (true) {
            datagramSocket.receive(datagramPacket);
            byte[] copyOf = Arrays.copyOf(datagramPacket.getData(), datagramPacket.getLength());
            StringBuilder a2 = d.b.a.a.a.a("startUDPListen: ");
            a2.append(d.e.a.u.c.a(copyOf));
            Log.d("wyt UdpService", a2.toString());
            if (copyOf.length >= 7 && copyOf[i2] == 104) {
                byte b2 = copyOf[1];
                if (b2 == 1) {
                    if (copyOf[1] != 1 || copyOf.length < 45) {
                        jVar = null;
                    } else {
                        byte[] bArr2 = new byte[copyOf.length - 6];
                        System.arraycopy(copyOf, 4, bArr2, i2, bArr2.length);
                        ByteBuffer order = ByteBuffer.wrap(bArr2).order(ByteOrder.LITTLE_ENDIAN);
                        jVar = new j();
                        jVar.f5388a = order.get() & 255;
                        jVar.f5389b = order.get();
                        byte[] bArr3 = new byte[25];
                        order.get(bArr3);
                        jVar.f5390c = new String(bArr3, Charset.forName("UTF-8")).trim();
                        byte[] bArr4 = new byte[6];
                        order.get(bArr4);
                        jVar.f5391d = d.e.a.u.c.a(bArr4, '-');
                        jVar.f5392e = order.get();
                        order.get();
                        order.get(new byte[4]);
                    }
                    if (jVar == null) {
                        Log.d("wyt UdpService", "startUDPListen: device null");
                    } else {
                        jVar.f5393f = datagramPacket.getAddress();
                        datagramPacket.getPort();
                        if (jVar.f5388a != 255) {
                            if (!this.f3088d.contains(jVar.f5391d) && !f3079f.containsKey(jVar.f5391d)) {
                                String string2 = getString(2131755373);
                                int i3 = jVar.f5388a;
                                if (i3 == 1) {
                                    string2 = "PC";
                                } else if (i3 == 2) {
                                    string2 = "Android";
                                } else if (i3 == 3) {
                                    string2 = "Iphone";
                                }
                                Message message2 = new Message();
                                message2.obj = getString(2131755372, new Object[]{jVar.f5390c, string2});
                                f3083j.sendMessage(message2);
                                this.f3088d.add(jVar.f5391d);
                            }
                        } else if (jVar.f5389b != 1) {
                            a(datagramPacket.getAddress(), jVar);
                        } else if (!f3080g && !f3081h.containsKey(jVar.f5393f.toString()) && (!f3079f.containsKey(jVar.f5391d) || f3079f.get(jVar.f5391d).F)) {
                            f3080g = true;
                            f3081h.put(jVar.f5393f.toString(), jVar);
                            SharedPreferences sharedPreferences = f3082i;
                            StringBuilder a3 = d.b.a.a.a.a("login_");
                            a3.append(jVar.f5391d);
                            String string3 = sharedPreferences.getString(a3.toString(), BuildConfig.FLAVOR);
                            if (string3 == BuildConfig.FLAVOR) {
                                a("checkudppassword", 0, jVar.f5391d, jVar);
                                f3080g = false;
                            } else {
                                StringBuilder a4 = d.b.a.a.a.a("startUDPListen: 密码验证:");
                                a4.append(jVar.f5393f.toString());
                                Log.d("wyt UdpService", a4.toString());
                                byte[] a5 = h.a(string3, f3078e);
                                datagramSocket.send(new DatagramPacket(a5, a5.length, datagramPacket.getAddress(), 50100));
                                f3080g = false;
                                String inetAddress = jVar.f5393f.toString();
                                Timer timer = new Timer();
                                timer.schedule(new q0(this, inetAddress), 10000L);
                                f3084k.put(jVar.f5393f.toString(), timer);
                            }
                        }
                    }
                } else if (b2 == 2 && (jVar2 = f3081h.get(datagramPacket.getAddress().toString())) != null) {
                    Timer timer2 = f3084k.get(jVar2.f5393f.toString());
                    if (timer2 != null) {
                        timer2.cancel();
                        f3084k.remove(jVar2.f5393f.toString());
                    }
                    if (copyOf[1] == 2 && copyOf.length >= 7 && copyOf[4] == 0) {
                        Log.d("wyt UdpService", "startUDPListen: 登录成功");
                        a(datagramPacket.getAddress(), jVar2);
                        message = new Message();
                        Object[] objArr = new Object[1];
                        objArr[i2] = jVar2.f5390c;
                        string = getString(2131755376, objArr);
                    } else {
                        SharedPreferences.Editor edit = f3082i.edit();
                        StringBuilder a6 = d.b.a.a.a.a("login_");
                        a6.append(jVar2.f5391d);
                        edit.remove(a6.toString());
                        edit.commit();
                        message = new Message();
                        Object[] objArr2 = new Object[1];
                        objArr2[i2] = jVar2.f5390c;
                        string = getString(2131755375, objArr2);
                    }
                    message.obj = string;
                    f3083j.sendMessage(message);
                    f3081h.remove(jVar2.f5393f.toString());
                }
            }
            i2 = 0;
        }
    }

    public void b(Throwable th) {
        StringBuilder a2 = d.b.a.a.a.a("startUDPListen: ");
        a2.append(th.getMessage());
        Log.e("wyt UdpService", a2.toString());
        d();
    }

    public final void c() {
        f3085l = false;
        this.f3087c.c(e.a(new Callable() {
            @Override
            public final Object call() {
                return UdpService.this.a();
            }
        }).b(g.a.s.b.b()).a(new g.a.p.b() {
            @Override
            public final void a(Object obj) {
                UdpService.a(obj);
            }
        }, new g.a.p.b() {
            @Override
            public final void a(Object obj) {
                UdpService.this.a((Throwable) obj);
            }
        }));
    }

    @SuppressLint({"WrongConstant"})
    public final void d() {
        this.f3087c.c(e.a(new Callable() {
            @Override
            public final Object call() {
                return UdpService.this.b();
            }
        }).b(g.a.s.b.b()).a(new g.a.p.b() {
            @Override
            public final void a(Object obj) {
                UdpService.b(obj);
            }
        }, new g.a.p.b() {
            @Override
            public final void a(Object obj) {
                UdpService.this.b((Throwable) obj);
            }
        }));
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("wyt UdpService", "onCreate: ");
        this.f3086b = this;
        this.f3087c = new g.a.n.a();
        if (f3078e == 0) {
            f3078e = new Random().nextInt();
        }
        this.f3088d = new ArrayList();
        f3082i = getSharedPreferences("F20AD", 0);
        d();
        c();
        new Timer().schedule(new b(), 500L, 60000L);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("wyt UdpService", "onDestroy: ");
        this.f3087c.a();
    }

    @Override
    public int onStartCommand(Intent intent, int i2, int i3) {
        Log.d("wyt UdpService", "onStartCommand: ");
        return 1;
    }

    public Object a() {
        String sb;
        while (!f3085l) {
            try {
                int ipAddress = ((WifiManager) this.f3086b.getSystemService("wifi")).getConnectionInfo().getIpAddress();
                if (ipAddress == 0) {
                    sb = "255.255.255.255";
                } else {
                    sb = (ipAddress & 255) + "." + ((ipAddress >> 8) & 255) + "." + ((ipAddress >> 16) & 255) + ".255";
                }
            } catch (Exception e2) {
                StringBuilder a2 = d.b.a.a.a.a(" 获取IP出错鸟!!!!请保证是WIFI,或者请重新打开网络!\n");
                a2.append(e2.getMessage());
                sb = a2.toString();
            }
            DatagramSocket datagramSocket = new DatagramSocket();
            int i2 = f3078e;
            ByteBuffer a3 = d.b.a.a.a.a(ByteBuffer.allocate(10), ByteOrder.LITTLE_ENDIAN, (byte) 104, (byte) 0, (short) 4);
            a3.putInt(i2);
            a3.putShort((short) d.e.a.t.b.a(a3.array(), 0, 8));
            byte[] array = a3.array();
            datagramSocket.send(new DatagramPacket(array, array.length, InetAddress.getByName(sb), 50100));
            Thread.sleep(1000L);
            datagramSocket.close();
            Thread.sleep(1000L);
        }
        return new Object();
    }

    @SuppressLint({"WrongConstant"})
    public static void a(String str, String str2) {
        Log.d("wyt UdpService", "loginCheck: " + str);
        j jVar = f3081h.get(str);
        if (jVar == null) {
            return;
        }
        StringBuilder a2 = d.b.a.a.a.a("loginCheck: ");
        a2.append(jVar.f5390c);
        Log.d("wyt UdpService", a2.toString());
        SharedPreferences.Editor edit = f3082i.edit();
        StringBuilder a3 = d.b.a.a.a.a("login_");
        a3.append(jVar.f5391d);
        edit.putString(a3.toString(), str2);
        edit.commit();
        try {
            byte[] a4 = h.a(str2, f3078e);
            new DatagramSocket().send(new DatagramPacket(a4, a4.length, jVar.f5393f, 50100));
            Timer timer = new Timer();
            timer.schedule(new c(jVar), 20000L);
            f3084k.put(jVar.f5393f.toString(), timer);
        } catch (Exception e2) {
            d.b.a.a.a.a(e2, d.b.a.a.a.a("loginCheck: "), "wyt UdpService");
            y.e(App.f2838g.getApplicationContext().getString(2131755374, jVar.f5390c));
            f3081h.remove(jVar.f5393f.toString());
        }
        f3080g = false;
    }

    public static <T> void a(String str, int i2, String str2, T t) {
        p0 p0Var = new p0();
        p0Var.f5197a = str;
        p0Var.f5198b = str2;
        p0Var.f5199c = t;
        l.a.a.c.c().a(p0Var);
    }
}