Analiza kodu źródłowego w javie.

0

Witajcie,

Czy potrafi ktoś mi pomóc, chodzi o to jakie dane wysyła do kontrolera, sterującego taśmą RGB, podany niżej kod źródłowy aplikacji, za pomocą pakietów TCP?

package com.hoion.thread;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.hoion.protocol.Protocol;
import com.hoion.staticclass.staticclass;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Timer;
import java.util.TimerTask;

public class SendMSGThread
  extends Thread
{
  public Bundle cacheData = new Bundle();
  public Bundle data;
  private DataOutputStream mPrintWriter = null;
  Protocol pt = new Protocol();
  Socket socket = null;
  private Timer timer;
  private Timer timer1;
  private TimerTask timerTask;
  private TimerTask timerTask1;
  
  public void LinkSocket()
  {
    try
    {
      if (this.socket != null) {
        this.socket.close();
      }
      boolean bool1 = staticclass.isWifi_Connect;
      i = 0;
      if (bool1)
      {
        this.socket = new Socket(InetAddress.getByName(staticclass.IP), staticclass.PORT);
        boolean bool2 = this.socket.isConnected();
        i = 0;
        if (bool2)
        {
          this.mPrintWriter = new DataOutputStream(this.socket.getOutputStream());
          this.socket.setSoTimeout(20000);
          this.socket.setSendBufferSize(20);
          this.socket.setTcpNoDelay(true);
          this.socket.setOOBInline(true);
          i = 1;
        }
      }
    }
    catch (IOException localIOException)
    {
      for (;;)
      {
        staticclass.isSocet_Connect = false;
        Log.d("SendMSGThread.java", "LinkSocket()连接失败");
        int i = 0;
        continue;
        Log.d("SendMSGThread.java", "LinkSocket()连接成功");
        staticclass.isSocet_Connect = true;
      }
    }
    if (i == 0)
    {
      Log.d("SendMSGThread.java", "LinkSocket()连接失败");
      staticclass.isSocet_Connect = false;
      return;
    }
  }
  
  public void SendSocketData(Bundle paramBundle)
  {
    this.data = paramBundle;
    int i = this.data.getInt("product");
    int j = this.data.getInt("product_mode");
    int k = this.data.getInt("static_dynamic");
    int m = this.data.getInt("switch_on");
    int n = this.data.getInt("bar_no");
    int i1 = this.data.getInt("red");
    int i2 = this.data.getInt("green");
    int i3 = this.data.getInt("blue");
    int i4 = this.data.getInt("speed");
    int i5 = this.data.getInt("pause");
    int i6 = this.data.getInt("dynamic_mode");
    int i7 = this.data.getInt("dynamic_effect");
    int i8 = this.data.getInt("controller");
    int i9 = this.data.getInt("RGB_sort");
    int i10 = this.data.getInt("IC_number");
    this.pt.setProduct(i);
    this.pt.setProduct_mode(j);
    this.pt.setStatic_dynamic(k);
    this.pt.setSwith_on(m);
    this.pt.setBar_no(n);
    this.pt.setColorRGB(i1, i2, i3);
    this.pt.setSpeed(i4);
    this.pt.setPause(i5);
    this.pt.setDynamic_mode(i6);
    this.pt.setDynamic_effect(i7);
    this.pt.setController(i8);
    this.pt.setRGB_sort(i9);
    this.pt.setIC_number(i10);
    this.pt.setCurCheckValue(n, i1, i2, i3, m, j);
    this.pt.setAll();
    this.pt.exchangeBytes();
    byte[] arrayOfByte = this.pt.getAll();
    try
    {
      if (staticclass.isSocet_Connect)
      {
        this.mPrintWriter.write(arrayOfByte);
        this.mPrintWriter.flush();
        String str = "";
        for (int i11 = 0;; i11++)
        {
          if (i11 >= 20)
          {
            Log.d("发送的数组:", str);
            break;
          }
          str = str + this.pt.printHexString(arrayOfByte[i11]) + "*";
        }
      }
      LinkSocket();
    }
    catch (IOException localIOException)
    {
      LinkSocket();
    }
  }
  
  public void getDataFromUI(Message paramMessage)
  {
    this.cacheData = paramMessage.getData();
  }
  
  public void run()
  {
    this.timer = new Timer();
    this.timerTask = new MyTimerTask();
    this.timer.schedule(this.timerTask, 0L, 50L);
    this.timer1 = new Timer();
    this.timerTask1 = new MyTimerTask1();
    this.timer1.schedule(this.timerTask1, 0L, staticclass.HeartTimerTask.longValue());
    Looper.prepare();
    LinkSocket();
    staticclass.mThreadHandle = new Handler()
    {
      public void handleMessage(Message paramAnonymousMessage)
      {
        super.handleMessage(paramAnonymousMessage);
        switch (paramAnonymousMessage.what)
        {
        }
        for (;;)
        {
          return;
          SendMSGThread.this.getDataFromUI(paramAnonymousMessage);
          continue;
          Log.d("SendMSGTread", "MSG_SOCKET_CLOSE");
          if (staticclass.isSocet_Connect)
          {
            try
            {
              if (SendMSGThread.this.socket == null) {
                continue;
              }
              SendMSGThread.this.socket.close();
            }
            catch (IOException localIOException)
            {
              localIOException.printStackTrace();
            }
            continue;
            Log.d("SendMSGThread", "MSG_AGAIN");
            SendMSGThread.this.LinkSocket();
          }
        }
      }
    };
    Looper.loop();
  }
  
  public void sendMsg(int paramInt)
  {
    Message localMessage = new Message();
    localMessage.what = paramInt;
    staticclass.mMainHandle.sendMessage(localMessage);
  }
  
  public class MyTimerTask
    extends TimerTask
  {
    int b = 0;
    int g = 0;
    int r = 0;
    
    public MyTimerTask() {}
    
    public void run()
    {
      if ((!staticclass.M_KEY) && (this.r == SendMSGThread.this.cacheData.getInt("red")) && (this.g == SendMSGThread.this.cacheData.getInt("green")) && (this.b == SendMSGThread.this.cacheData.getInt("blue"))) {}
      for (;;)
      {
        return;
        this.r = SendMSGThread.this.cacheData.getInt("red");
        this.g = SendMSGThread.this.cacheData.getInt("green");
        this.b = SendMSGThread.this.cacheData.getInt("blue");
        SendMSGThread.this.SendSocketData(SendMSGThread.this.cacheData);
        staticclass.M_KEY = false;
      }
    }
  }
  
  public class MyTimerTask1
    extends TimerTask
  {
    public MyTimerTask1() {}
    
    public void run()
    {
      try
      {
        if (staticclass.isSocet_Connect)
        {
          byte[] arrayOfByte = new byte[20];
          SendMSGThread.this.mPrintWriter.write(arrayOfByte);
          SendMSGThread.this.mPrintWriter.flush();
          String str = "";
          for (int i = 0;; i++)
          {
            if (i >= 20)
            {
              Log.d("发送的数组:", str);
              break;
            }
            str = str + SendMSGThread.this.pt.printHexString(arrayOfByte[i]) + "*";
          }
        }
        SendMSGThread.this.LinkSocket();
      }
      catch (IOException localIOException)
      {
        SendMSGThread.this.LinkSocket();
      }
    }
  }
}


**LUB OD TEGO:
**
package com.hoion.protocol;

import java.io.PrintStream;

public class Protocol
{
  public byte[] IC_number = new byte[2];
  private byte RGB_sort;
  private byte Reserve = 0;
  private byte[] all = new byte[20];
  private byte bar_no;
  private byte checkValue;
  private byte[] colorRGB = new byte[3];
  private byte controller;
  private byte dynamic_effect;
  private byte dynamic_mode;
  private final byte[] frameHead = { -99, 98 };
  private byte pause;
  private byte product;
  private byte product_mode;
  private byte speed;
  private byte static_dynamic;
  private byte switch_on;
  
  public static int byte2int(byte[] paramArrayOfByte)
  {
    return 0xFF & paramArrayOfByte[1] | 0xFF00 & paramArrayOfByte[0] << 8;
  }
  
  private void exchangeInt(int[] paramArrayOfInt)
  {
    int i = paramArrayOfInt[0];
    int j = paramArrayOfInt[1];
    int k = i & 0xF0;
    int m = (i & 0xF) << 4;
    int n = j & 0xF0;
    int i1 = j & 0xF;
    int i2 = k + (n >> 4);
    int i3 = m + i1;
    paramArrayOfInt[0] = i2;
    paramArrayOfInt[1] = i3;
  }
  
  public static byte getCheckValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6)
  {
    int i = 255 + (paramInt1 + (paramInt2 + (paramInt3 + (paramInt4 + (paramInt6 + paramInt5)))));
    if (i == 0) {}
    int j = i % 255;
    if (j == 0) {
      j = 255;
    }
    return (byte)j;
  }
  
  public static void main(String[] paramArrayOfString)
  {
    Protocol localProtocol = new Protocol();
    localProtocol.setProduct(0);
    localProtocol.setProduct_mode(0);
    localProtocol.setStatic_dynamic(1);
    localProtocol.setSwith_on(1);
    localProtocol.setBar_no(50);
    localProtocol.setColorRGB(255, 6, 32);
    localProtocol.setSpeed(0);
    localProtocol.setPause(0);
    localProtocol.setDynamic_mode(0);
    localProtocol.setDynamic_effect(0);
    localProtocol.setController(0);
    localProtocol.setRGB_sort(0);
    localProtocol.setIC_number(0);
    localProtocol.setCurCheckValue(50, 255, 6, 32, 1, 0);
    localProtocol.setAll();
    byte[] arrayOfByte1 = localProtocol.getAll();
    String str1 = "";
    int i = 0;
    byte[] arrayOfByte2;
    String str2;
    if (i >= 20)
    {
      System.out.println("###########:" + str1);
      localProtocol.exchangeBytes();
      arrayOfByte2 = localProtocol.getAll();
      str2 = "";
    }
    for (int j = 0;; j++)
    {
      if (j >= 20)
      {
        System.out.println("###########:" + str2);
        return;
        str1 = str1 + localProtocol.printHexString(arrayOfByte1[i]) + "*";
        i++;
        break;
      }
      str2 = str2 + localProtocol.printHexString(arrayOfByte2[j]) + "*";
    }
  }
  
  public static byte[] shortToByteArray(short paramShort)
  {
    byte[] arrayOfByte = new byte[2];
    for (int i = 0;; i++)
    {
      if (i >= 2) {
        return arrayOfByte;
      }
      arrayOfByte[i] = ((byte)(0xFF & paramShort >>> 8 * (-1 + arrayOfByte.length - i)));
    }
  }
  
  public void exchangeBytes()
  {
    int[] arrayOfInt = new int[2];
    for (int i = 2;; i++)
    {
      if (i >= 11) {
        return;
      }
      arrayOfInt[0] = this.all[i];
      arrayOfInt[1] = this.all[(21 - i)];
      exchangeInt(arrayOfInt);
      this.all[i] = ((byte)arrayOfInt[0]);
      this.all[(21 - i)] = ((byte)arrayOfInt[1]);
    }
  }
  
  public byte[] getAll()
  {
    return this.all;
  }
  
  public String printHexString(byte paramByte)
  {
    String str = Integer.toHexString(paramByte & 0xFF);
    if (str.length() == 1) {
      str = '0' + str;
    }
    return str.toUpperCase();
  }
  
  public void setAll()
  {
    this.all[0] = this.frameHead[0];
    this.all[1] = this.frameHead[1];
    this.all[2] = this.product;
    this.all[3] = this.product_mode;
    this.all[4] = this.static_dynamic;
    this.all[5] = this.switch_on;
    this.all[6] = this.bar_no;
    this.all[7] = this.colorRGB[0];
    this.all[8] = this.colorRGB[1];
    this.all[9] = this.colorRGB[2];
    this.all[10] = this.speed;
    this.all[11] = this.pause;
    this.all[12] = this.dynamic_mode;
    this.all[13] = this.dynamic_effect;
    this.all[14] = this.controller;
    this.all[15] = this.RGB_sort;
    this.all[16] = this.IC_number[0];
    this.all[17] = this.IC_number[1];
    this.all[18] = this.Reserve;
    this.all[19] = this.checkValue;
  }
  
  public void setBar_no(int paramInt)
  {
    this.bar_no = ((byte)paramInt);
  }
  
  public void setColorRGB(int paramInt1, int paramInt2, int paramInt3)
  {
    this.colorRGB[0] = ((byte)paramInt1);
    this.colorRGB[1] = ((byte)paramInt2);
    this.colorRGB[2] = ((byte)paramInt3);
  }
  
  public void setController(int paramInt)
  {
    this.controller = ((byte)paramInt);
  }
  
  public void setCurCheckValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6)
  {
    int i = 255 + (paramInt1 + (paramInt2 + (paramInt3 + (paramInt4 + (paramInt6 + paramInt5)))));
    if (i == 0) {}
    for (;;)
    {
      return;
      int j = i % 255;
      if (j == 0) {
        j = 255;
      }
      this.checkValue = ((byte)j);
    }
  }
  
  public void setDynamic_effect(int paramInt)
  {
    this.dynamic_effect = ((byte)paramInt);
  }
  
  public void setDynamic_mode(int paramInt)
  {
    this.dynamic_mode = ((byte)paramInt);
  }
  
  public void setIC_number(int paramInt)
  {
    this.IC_number = shortToByteArray((short)paramInt);
  }
  
  public void setPause(int paramInt)
  {
    this.pause = ((byte)paramInt);
  }
  
  public void setProduct(int paramInt)
  {
    this.product = ((byte)paramInt);
  }
  
  public void setProduct_mode(int paramInt)
  {
    this.product_mode = ((byte)paramInt);
  }
  
  public void setRGB_sort(int paramInt)
  {
    this.RGB_sort = ((byte)paramInt);
  }
  
  public void setSpeed(int paramInt)
  {
    this.speed = ((byte)paramInt);
  }
  
  public void setStatic_dynamic(int paramInt)
  {
    this.static_dynamic = ((byte)paramInt);
  }
  
  public void setSwith_on(int paramInt)
  {
    this.switch_on = ((byte)paramInt);
  }
}
0

Po próbach wysyłania pakietów udało mi się dojść, że urządzenie reaguje na np. pakiety 21 00 ff 00 aa. Tzn. wyłącza się.

0

kod wygląda jak mega WTF,

0

Ten kod to jakiś żart. Pobaw się debugerem najlepiej.

0

Ten kod źródłowy jest częścią kodu aplikacji, która prawdopodobnie odpowiada za instrukcję wysyłania pakietu po kliknięciu jakiegoś przycisku w aplikacji. Mam małe pojęcie o programowaniu. Wysyła on jakiś pakiet podobnie jak w tym urządzeniu.
http://blog.stedmeister.co.uk/2014/05/controlling-the-wifi370/
Próbowałem działać ze snifferem na androida w celu przechwycenia pakietu, ale bezskutecznie. Ogarnia to ktoś?

1 użytkowników online, w tym zalogowanych: 0, gości: 1