453 lines
14 KiB
Java
453 lines
14 KiB
Java
package com.ubt.jimu.unity.bluetooth;
|
||
|
||
import com.ijm.dataencryption.de.DataDecryptTool;
|
||
import java.io.File;
|
||
import java.io.FileInputStream;
|
||
import java.security.MessageDigest;
|
||
import java.text.DecimalFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Calendar;
|
||
import java.util.Formatter;
|
||
import java.util.regex.Pattern;
|
||
|
||
/* loaded from: classes2.dex */
|
||
public class ByteHexHelper {
|
||
private static boolean D = false;
|
||
|
||
public static String RandomMethod() {
|
||
String hexString = Integer.toHexString((int) (Math.random() * 100.0d));
|
||
int length = hexString.length();
|
||
while (length < 2) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexString;
|
||
}
|
||
|
||
public static String XOR(String str) {
|
||
byte b;
|
||
if (str.length() > 0) {
|
||
b = 0;
|
||
for (int i = 0; i < str.length() / 2; i++) {
|
||
int i2 = i * 2;
|
||
b = (byte) (b ^ hexStringToByte(str.substring(i2, i2 + 2)));
|
||
}
|
||
} else {
|
||
b = 0;
|
||
}
|
||
return bytesToHexString(new byte[]{b});
|
||
}
|
||
|
||
public static byte[] appendByteArray(byte[] bArr, byte[] bArr2) {
|
||
if (bArr.length <= 0 || bArr2.length <= 0) {
|
||
throw new IllegalArgumentException("<EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
}
|
||
byte[] bArr3 = new byte[bArr.length + bArr2.length];
|
||
System.arraycopy(bArr, 0, bArr3, 0, bArr.length);
|
||
System.arraycopy(bArr2, 0, bArr3, bArr.length, bArr2.length);
|
||
return bArr3;
|
||
}
|
||
|
||
public static String binaryString2hexString(String str) {
|
||
if (str == null || str.equals("")) {
|
||
return "";
|
||
}
|
||
if (str.length() % 8 != 0) {
|
||
int length = 8 - (str.length() % 8);
|
||
String str2 = str;
|
||
for (int i = 0; i < length; i++) {
|
||
str2 = str2 + "0";
|
||
}
|
||
System.out.println("choiceItem = " + str2);
|
||
str = str2;
|
||
}
|
||
StringBuffer stringBuffer = new StringBuffer();
|
||
for (int i2 = 0; i2 < str.length(); i2 += 4) {
|
||
int i3 = 0;
|
||
for (int i4 = 0; i4 < 4; i4++) {
|
||
int i5 = i2 + i4;
|
||
i3 += Integer.parseInt(str.substring(i5, i5 + 1)) << ((4 - i4) - 1);
|
||
}
|
||
stringBuffer.append(Integer.toHexString(i3));
|
||
}
|
||
System.out.println("tmp.toString() = " + stringBuffer.toString());
|
||
return stringBuffer.toString();
|
||
}
|
||
|
||
public static String byteToHexString(byte b) {
|
||
StringBuilder sb = new StringBuilder("");
|
||
String hexString = Integer.toHexString(b & 255);
|
||
if (hexString.length() < 2) {
|
||
sb.append(0);
|
||
}
|
||
sb.append(hexString);
|
||
return sb.toString();
|
||
}
|
||
|
||
public static int byteToInt(byte b) {
|
||
return b & 255;
|
||
}
|
||
|
||
public static String bytesToHexString(byte[] bArr) {
|
||
StringBuilder sb = new StringBuilder("");
|
||
if (bArr == null || bArr.length <= 0) {
|
||
return "";
|
||
}
|
||
for (byte b : bArr) {
|
||
String hexString = Integer.toHexString(b & 255);
|
||
if (hexString.length() < 2) {
|
||
sb.append(0);
|
||
}
|
||
sb.append(hexString);
|
||
sb.append(" ");
|
||
}
|
||
return sb.toString();
|
||
}
|
||
|
||
public static String calculateSingleFileMD5sum(File file) throws Exception {
|
||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||
FileInputStream fileInputStream = new FileInputStream(file);
|
||
try {
|
||
byte[] bArr = new byte[DataDecryptTool.DECRYPT_ALL_FILE];
|
||
while (true) {
|
||
int read = fileInputStream.read(bArr);
|
||
if (read == -1) {
|
||
break;
|
||
}
|
||
messageDigest.update(bArr, 0, read);
|
||
}
|
||
fileInputStream.close();
|
||
StringBuilder sb = new StringBuilder();
|
||
byte[] digest = messageDigest.digest();
|
||
Formatter formatter = new Formatter();
|
||
try {
|
||
for (byte b : digest) {
|
||
sb.append(formatter.format("%02x", Byte.valueOf(b)));
|
||
}
|
||
formatter.close();
|
||
return sb.toString();
|
||
} finally {
|
||
}
|
||
} catch (Throwable th) {
|
||
try {
|
||
throw th;
|
||
} catch (Throwable th2) {
|
||
try {
|
||
fileInputStream.close();
|
||
} catch (Throwable th3) {
|
||
th.addSuppressed(th3);
|
||
}
|
||
throw th2;
|
||
}
|
||
}
|
||
}
|
||
|
||
private static byte charToByte(char c) {
|
||
return (byte) "0123456789ABCDEF".indexOf(c);
|
||
}
|
||
|
||
public static String checkedSite(int i) {
|
||
String hexString = Integer.toHexString(i);
|
||
int length = hexString.length();
|
||
while (length < 2) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexString;
|
||
}
|
||
|
||
public static String currentData() {
|
||
StringBuffer stringBuffer = new StringBuffer();
|
||
DecimalFormat decimalFormat = new DecimalFormat("00");
|
||
Calendar calendar = Calendar.getInstance();
|
||
String format = decimalFormat.format(calendar.get(1));
|
||
String format2 = decimalFormat.format(calendar.get(2) + 1);
|
||
String format3 = decimalFormat.format(calendar.get(5));
|
||
String format4 = decimalFormat.format(calendar.get(11));
|
||
String format5 = decimalFormat.format(calendar.get(12));
|
||
String format6 = decimalFormat.format(calendar.get(13));
|
||
String format7 = decimalFormat.format(calendar.get(7) - 1);
|
||
stringBuffer.append(format.substring(2, format.length()));
|
||
stringBuffer.append(format2);
|
||
stringBuffer.append(format3);
|
||
stringBuffer.append(format4);
|
||
stringBuffer.append(format5);
|
||
stringBuffer.append(format6);
|
||
stringBuffer.append(format7);
|
||
System.out.println(stringBuffer.toString());
|
||
return stringBuffer.toString();
|
||
}
|
||
|
||
public static String dpuString(String str) {
|
||
if (str == null || str.length() <= 0) {
|
||
return "";
|
||
}
|
||
String bytesToHexString = bytesToHexString((str + "\u0000").getBytes());
|
||
String str2 = packLength(bytesToHexString) + bytesToHexString;
|
||
System.out.println("resultLength==" + str2);
|
||
return str2;
|
||
}
|
||
|
||
public static String hexString2binaryString(String str) {
|
||
if (str == null || str.length() % 2 != 0) {
|
||
return null;
|
||
}
|
||
int i = 0;
|
||
String str2 = "";
|
||
while (i < str.length()) {
|
||
StringBuilder sb = new StringBuilder();
|
||
sb.append("0000");
|
||
int i2 = i + 1;
|
||
sb.append(Integer.toBinaryString(Integer.parseInt(str.substring(i, i2), 16)));
|
||
str2 = str2 + sb.toString().substring(r0.length() - 4);
|
||
i = i2;
|
||
}
|
||
return str2;
|
||
}
|
||
|
||
public static byte hexStringToByte(String str) {
|
||
String upperCase = str.toUpperCase();
|
||
int length = upperCase.length() / 2;
|
||
char[] charArray = upperCase.toCharArray();
|
||
byte[] bArr = new byte[length];
|
||
for (int i = 0; i < length; i++) {
|
||
int i2 = i * 2;
|
||
bArr[i] = (byte) ((charToByte(charArray[i2 + 1]) & 255) | (charToByte(charArray[i2]) << 4));
|
||
}
|
||
return bArr[0];
|
||
}
|
||
|
||
/* JADX WARN: Removed duplicated region for block: B:11:0x004c */
|
||
/* JADX WARN: Removed duplicated region for block: B:15:0x0052 */
|
||
/*
|
||
Code decompiled incorrectly, please refer to instructions dump.
|
||
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
||
*/
|
||
public static byte[] hexStringToBytes(java.lang.String r8) {
|
||
/*
|
||
java.lang.String r0 = " "
|
||
java.lang.String r1 = ""
|
||
java.lang.String r8 = r8.replace(r0, r1)
|
||
java.io.PrintStream r0 = java.lang.System.out
|
||
r0.println(r8)
|
||
int r0 = r8.length()
|
||
int r0 = r0 / 2
|
||
byte[] r0 = new byte[r0]
|
||
r1 = 0
|
||
r2 = 0
|
||
L17:
|
||
int r3 = r8.length()
|
||
if (r2 >= r3) goto L61
|
||
int r3 = r2 + 1
|
||
java.lang.String r2 = r8.substring(r2, r3)
|
||
byte[] r2 = r2.getBytes()
|
||
r2 = r2[r1]
|
||
r4 = 64
|
||
r5 = 96
|
||
if (r2 <= r5) goto L36
|
||
int r2 = r2 + (-97)
|
||
L31:
|
||
int r2 = r2 + 10
|
||
L33:
|
||
int r2 = r2 * 16
|
||
goto L3e
|
||
L36:
|
||
if (r2 <= r4) goto L3b
|
||
int r2 = r2 + (-65)
|
||
goto L31
|
||
L3b:
|
||
int r2 = r2 + (-48)
|
||
goto L33
|
||
L3e:
|
||
int r6 = r3 + 1
|
||
java.lang.String r7 = r8.substring(r3, r6)
|
||
byte[] r7 = r7.getBytes()
|
||
r7 = r7[r1]
|
||
if (r7 <= r5) goto L52
|
||
int r7 = r7 + (-97)
|
||
L4e:
|
||
int r7 = r7 + 10
|
||
L50:
|
||
int r2 = r2 + r7
|
||
goto L5a
|
||
L52:
|
||
if (r7 <= r4) goto L57
|
||
int r7 = r7 + (-65)
|
||
goto L4e
|
||
L57:
|
||
int r7 = r7 + (-48)
|
||
goto L50
|
||
L5a:
|
||
int r3 = r3 / 2
|
||
byte r2 = (byte) r2
|
||
r0[r3] = r2
|
||
r2 = r6
|
||
goto L17
|
||
L61:
|
||
return r0
|
||
*/
|
||
throw new UnsupportedOperationException("Method not decompiled: com.ubt.jimu.unity.bluetooth.ByteHexHelper.hexStringToBytes(java.lang.String):byte[]");
|
||
}
|
||
|
||
public static byte[] hexStringToBytes2(String str) {
|
||
if (str == null || str.equals("")) {
|
||
return new byte[0];
|
||
}
|
||
String upperCase = str.toUpperCase();
|
||
int length = upperCase.length() / 2;
|
||
char[] charArray = upperCase.toCharArray();
|
||
byte[] bArr = new byte[length];
|
||
for (int i = 0; i < length; i++) {
|
||
int i2 = i * 2;
|
||
bArr[i] = (byte) ((charToByte(charArray[i2 + 1]) & 255) | (charToByte(charArray[i2]) << 4));
|
||
}
|
||
return bArr;
|
||
}
|
||
|
||
public static int intPackLength(String str) {
|
||
return Integer.valueOf(str, 16).intValue();
|
||
}
|
||
|
||
public static byte[] intToFourHexBytes(int i) {
|
||
String hexString = Integer.toHexString(i);
|
||
int length = hexString.length();
|
||
while (length < 8) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexStringToBytes(hexString);
|
||
}
|
||
|
||
public static byte[] intToFourHexBytesTwo(int i) {
|
||
String hexString = Integer.toHexString(i);
|
||
int length = hexString.length();
|
||
if (length < 2) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
while (length < 8) {
|
||
hexString = hexString + "0";
|
||
length = hexString.length();
|
||
}
|
||
return hexStringToBytes(hexString);
|
||
}
|
||
|
||
public static byte intToHexByte(int i) {
|
||
String hexString = Integer.toHexString(i);
|
||
int length = hexString.length();
|
||
while (length < 2) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexStringToByte(hexString);
|
||
}
|
||
|
||
public static byte[] intToHexBytes(int i) {
|
||
String hexString = Integer.toHexString(i);
|
||
int length = hexString.length();
|
||
while (length < 2) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexStringToBytes(hexString);
|
||
}
|
||
|
||
public static byte[] intToTwoHexBytes(int i) {
|
||
String hexString = Integer.toHexString(i);
|
||
int length = hexString.length();
|
||
while (length < 4) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexStringToBytes(hexString);
|
||
}
|
||
|
||
public static String packLength(String str) {
|
||
String hexString = Integer.toHexString(str.length() / 2);
|
||
int length = hexString.length();
|
||
while (length < 4) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexString;
|
||
}
|
||
|
||
public static String packVerify(String str, String str2, String str3, String str4, String str5, String str6) {
|
||
return XOR(str + str2 + str3 + str4 + str5 + str6);
|
||
}
|
||
|
||
public static String parseAscii(String str) {
|
||
StringBuilder sb = new StringBuilder();
|
||
for (byte b : str.getBytes()) {
|
||
sb.append(toHex(b));
|
||
}
|
||
return sb.toString();
|
||
}
|
||
|
||
public static String replaceBlank(String str) {
|
||
return (str != null ? Pattern.compile("\t|\r|\n").matcher(str).replaceAll("") : "").trim();
|
||
}
|
||
|
||
public static String toHex(int i) {
|
||
StringBuilder sb = new StringBuilder();
|
||
int i2 = i / 16;
|
||
if (i2 == 0) {
|
||
return toHexUtil(i);
|
||
}
|
||
sb.append(toHex(i2));
|
||
sb.append(toHexUtil(i % 16));
|
||
return sb.toString();
|
||
}
|
||
|
||
private static String toHexUtil(int i) {
|
||
switch (i) {
|
||
case 10:
|
||
return "A";
|
||
case 11:
|
||
return "B";
|
||
case 12:
|
||
return "C";
|
||
case 13:
|
||
return "D";
|
||
case 14:
|
||
return "E";
|
||
case 15:
|
||
return "F";
|
||
default:
|
||
return "" + i;
|
||
}
|
||
}
|
||
|
||
public static ArrayList<String> toStringArray(byte[] bArr) {
|
||
int length;
|
||
if (bArr == null || (length = bArr.length) < 3) {
|
||
return null;
|
||
}
|
||
ArrayList<String> arrayList = new ArrayList<>();
|
||
int i = 0;
|
||
while (i < length - 1) {
|
||
int i2 = (bArr[i] << 8) | (bArr[i + 1] & 255);
|
||
int i3 = i2 - 1;
|
||
byte[] bArr2 = new byte[i3];
|
||
System.arraycopy(bArr, i + 2, bArr2, 0, i3);
|
||
arrayList.add(new String(bArr2));
|
||
i += i2 + 2;
|
||
}
|
||
return arrayList;
|
||
}
|
||
|
||
public static int intPackLength(byte[] bArr) {
|
||
return Integer.valueOf(bytesToHexString(bArr), 16).intValue();
|
||
}
|
||
|
||
public static String packLength(int i) {
|
||
String hexString = Integer.toHexString(i);
|
||
int length = hexString.length();
|
||
while (length < 4) {
|
||
hexString = "0" + hexString;
|
||
length = hexString.length();
|
||
}
|
||
return hexString;
|
||
}
|
||
}
|