导航菜单

页面标题

页面副标题

Minits v4.9.3.32 - XoneNFCDriverActivity.java 源代码

正在查看: Minits v4.9.3.32 应用的 XoneNFCDriverActivity.java JAVA 源代码文件

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


package com.xone.android.nfc;

import android.app.Activity;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.Tag;
import android.nfc.tech.MifareClassic;
import android.nfc.tech.MifareUltralight;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.nfc.tech.NfcA;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import com.xone.android.nfc.runtimeobjects.XoneNFCRuntime;
import com.xone.android.utils.Utils;
import fb.q;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import k9.AbstractC0814a;
import k9.AbstractC0815b;
import m9.C0848a;
import ua.InterfaceC1038m0;

public final class XoneNFCDriverActivity extends Activity {
    public byte[] l;

    public static boolean e(Tag tag) {
        return Arrays.binarySearch(tag.getTechList(), MifareClassic.class.getName()) >= 0;
    }

    public final int[] a(String str) {
        if (TextUtils.isEmpty(str)) {
            return new int[0];
        }
        int indexOf = str.indexOf(40);
        if (indexOf <= 0) {
            return new int[0];
        }
        int indexOf2 = str.indexOf(41, indexOf);
        if (indexOf2 < indexOf) {
            indexOf2 = str.length();
        }
        if (Utils.d3(getApplicationContext())) {
            AbstractC0814a.a("getBlocks(): String value " + str + " - Read block from position " + (indexOf + 1) + " to position " + indexOf2);
        }
        String substring = str.substring(indexOf + 1, indexOf2);
        if (TextUtils.isEmpty(substring)) {
            return new int[0];
        }
        if (Utils.d3(getApplicationContext())) {
            AbstractC0814a.a("getBlocks(): Block value " + substring);
        }
        String[] split = substring.split(",");
        int[] iArr = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            iArr[i] = q.o(split[i]);
        }
        return iArr;
    }

    public final C0848a b() {
        String value = XoneNFCRuntime.getValue(this, XoneNFCRuntime.MIFARE_KEYS);
        if (TextUtils.isEmpty(value)) {
            return null;
        }
        return new C0848a(value);
    }

    public final int c(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        int indexOf = str.indexOf(124);
        return indexOf > 0 ? q.o(str.substring(0, indexOf)) : q.o(str);
    }

    public final int d(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        int indexOf = str.indexOf(40);
        return indexOf > 0 ? q.o(str.substring(0, indexOf)) : q.o(str);
    }

    public final String f(MifareUltralight mifareUltralight, int i, boolean z) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            if (!mifareUltralight.isConnected()) {
                throw new IllegalStateException("NFC disconnected");
            }
            byteArrayOutputStream.write(mifareUltralight.readPages(i));
            return z ? AbstractC0814a.h(byteArrayOutputStream.toByteArray()) : byteArrayOutputStream.toString().trim();
        } finally {
            Utils.N(byteArrayOutputStream);
        }
    }

    public final void g(Tag tag) {
        AbstractC0814a.a("NFC tag type MifareClassic");
        try {
            MifareClassic mifareClassic = MifareClassic.get(tag);
            mifareClassic.connect();
            String value = XoneNFCRuntime.getValue(this, XoneNFCRuntime.BLOCKS_TAG);
            if (TextUtils.isEmpty(value)) {
                return;
            }
            C0848a b = b();
            String[] split = value.split(";");
            ArrayList arrayList = new ArrayList();
            for (String str : split) {
                arrayList.add(AbstractC0814a.x(mifareClassic, d(str), a(str), AbstractC0814a.p(str), b));
            }
            n("readerror", "", "data", arrayList);
        } catch (Exception e) {
            e.printStackTrace();
            n("readerror", e.getMessage(), "data", null);
        }
    }

    public final void h(Tag tag) {
        AbstractC0814a.a("NFC tag type MifareUltralight");
        try {
            MifareUltralight mifareUltralight = MifareUltralight.get(tag);
            mifareUltralight.connect();
            String value = XoneNFCRuntime.getValue(this, XoneNFCRuntime.BLOCKS_TAG);
            if (TextUtils.isEmpty(value)) {
                return;
            }
            String[] split = value.split(";");
            ArrayList arrayList = new ArrayList();
            for (String str : split) {
                arrayList.add(f(mifareUltralight, c(str), AbstractC0814a.p(str)));
            }
            n("readerror", "", "data", arrayList);
        } catch (Exception e) {
            e.printStackTrace();
            n("readerror", e.getMessage(), "data", null);
        }
    }

    public final ArrayList i(Tag tag) {
        ArrayList arrayList = new ArrayList();
        Ndef ndef = Ndef.get(tag);
        if (ndef != null) {
            NdefMessage cachedNdefMessage = ndef.getCachedNdefMessage();
            if (cachedNdefMessage == null) {
                arrayList.add("##EMPTY_TAG##");
                return arrayList;
            }
            for (NdefRecord ndefRecord : cachedNdefMessage.getRecords()) {
                if (ndefRecord.getTnf() == 1) {
                    arrayList.add(AbstractC0814a.D(ndefRecord));
                }
            }
        }
        return arrayList;
    }

    public final String j(Tag tag) {
        Tag tag2;
        NdefFormatable ndefFormatable = NdefFormatable.get(tag);
        if (ndefFormatable == null || (tag2 = ndefFormatable.getTag()) == null) {
            return null;
        }
        return AbstractC0814a.h(tag2.getId());
    }

    public final void k(Tag tag) {
        try {
            AbstractC0814a.a("NFC tag type NDEF");
            for (String str : tag.getTechList()) {
                if (Ndef.class.getName().equals(str)) {
                    ArrayList i = i(tag);
                    if (i.isEmpty()) {
                        throw new Exception("No data found in NDEF message");
                    }
                    n("readerror", "", "data", i);
                    return;
                }
                if (NdefFormatable.class.getName().equals(str)) {
                    String j = j(tag);
                    if (TextUtils.isEmpty(j)) {
                        throw new Exception("No data found in NDEF message");
                    }
                    ArrayList arrayList = new ArrayList();
                    arrayList.add(j);
                    n("readerror", "", "data", arrayList);
                    return;
                }
                if (NfcA.class.getName().equals(str)) {
                    ArrayList i2 = i(tag);
                    if (!i2.isEmpty()) {
                        n("readerror", "", "data", i2);
                        return;
                    }
                } else if (MifareClassic.class.getName().equals(str)) {
                    g(tag);
                    return;
                } else if (MifareUltralight.class.getName().equals(str)) {
                    h(tag);
                    return;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            n("readerror", e.getMessage(), "data", null);
        }
    }

    public final void l(Intent intent) {
        Tag tag = (Tag) intent.getParcelableExtra("android.nfc.extra.TAG");
        if (tag == null) {
            return;
        }
        this.l = tag.getId();
        if (Utils.d3(getApplicationContext())) {
            AbstractC0814a.a("TAG ID: Len(" + this.l.length + ") value in HEX=" + AbstractC0814a.h(this.l));
        }
        if ("1".equals(XoneNFCRuntime.getValue(this, XoneNFCRuntime.NFC_WRITE_CHECK))) {
            if (o(tag)) {
                XoneNFCRuntime.setValue(this, XoneNFCRuntime.NFC_WRITE_CHECK, "0");
                return;
            }
            return;
        }
        String value = XoneNFCRuntime.getValue(this, XoneNFCRuntime.NFC_TYPE);
        if (Utils.d3(getApplicationContext())) {
            AbstractC0814a.a("NFC tag type: " + value);
        }
        if (value.equals(Ndef.class.getName())) {
            k(tag);
            return;
        }
        if (value.equals(MifareClassic.class.getName())) {
            g(tag);
        } else if (value.equals(MifareUltralight.class.getName())) {
            h(tag);
        } else if (e(tag)) {
            g(tag);
        }
    }

    public final void m(Intent intent) {
        if (intent == null) {
            finish();
            return;
        }
        String action = intent.getAction();
        if (TextUtils.isEmpty(action)) {
            finish();
            return;
        }
        action.getClass();
        if (action.equals("android.nfc.action.TECH_DISCOVERED") || action.equals("android.nfc.action.TAG_DISCOVERED")) {
            l(intent);
        } else {
            AbstractC0814a.a("Unhandled intent action: " + action);
        }
        finish();
    }

    public final void n(String str, String str2, String str3, ArrayList arrayList) {
        String[] strArr;
        Handler p = ((InterfaceC1038m0) getApplication()).p();
        if (p != null) {
            String value = XoneNFCRuntime.getValue(this, XoneNFCRuntime.CALLBACK_NODE_TAG);
            Message obtainMessage = p.obtainMessage();
            obtainMessage.what = 2022;
            Bundle bundle = new Bundle();
            bundle.putString("nodename", value);
            if (TextUtils.isEmpty(str3)) {
                strArr = new String[]{str, XoneNFCRuntime.TAG_ID_FIELD};
            } else {
                String[] strArr2 = {str, XoneNFCRuntime.TAG_ID_FIELD, str3};
                bundle.putStringArrayList("data", arrayList);
                strArr = strArr2;
            }
            bundle.putStringArray("params", strArr);
            bundle.putString(str, str2);
            bundle.putString(XoneNFCRuntime.TAG_ID_FIELD, AbstractC0814a.h(this.l));
            obtainMessage.setData(bundle);
            p.sendMessage(obtainMessage);
        }
    }

    public final boolean o(Tag tag) {
        String value = XoneNFCRuntime.getValue(this, XoneNFCRuntime.NFC_TYPE);
        if (value.equals(MifareClassic.class.getName())) {
            return p(tag);
        }
        if (value.equals(NdefFormatable.class.getName()) || value.equals(NdefMessage.class.getName())) {
            return q(tag);
        }
        throw new IllegalArgumentException("Unknown tag type set when writing data: " + value);
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(AbstractC0815b.a);
        m(getIntent());
    }

    @Override
    public void onNewIntent(Intent intent) {
        setIntent(intent);
        m(intent);
    }

    public final boolean p(Tag tag) {
        try {
            if (!AbstractC0814a.q(tag, MifareClassic.class)) {
                throw new UnsupportedOperationException("MifareClassic is not supported on this tag");
            }
            MifareClassic mifareClassic = MifareClassic.get(tag);
            mifareClassic.connect();
            String value = XoneNFCRuntime.getValue(this, XoneNFCRuntime.BLOCKS_TAG);
            if (TextUtils.isEmpty(value)) {
                return true;
            }
            String[] split = value.split(";");
            int i = 0;
            while (true) {
                String str = "";
                if (i >= split.length) {
                    n("writeerror", "", null, null);
                    return true;
                }
                int d = d(split[i]);
                int[] a = a(split[i]);
                String value2 = XoneNFCRuntime.getValue(this, XoneNFCRuntime.DATA_TAG, i);
                if (!TextUtils.isEmpty(value2)) {
                    str = value2;
                }
                byte[] copyOf = Arrays.copyOf(str.getBytes(), a.length * 16);
                C0848a b = b();
                if (!(b != null ? b.a(mifareClassic, d) : AbstractC0814a.b(mifareClassic, d))) {
                    throw new SecurityException("No tag access permission.");
                }
                int sectorToBlock = mifareClassic.sectorToBlock(d);
                int i2 = 0;
                while (i2 < a.length) {
                    int i3 = i2 + 1;
                    byte[] copyOfRange = Arrays.copyOfRange(copyOf, i2 * 16, i3 * 16);
                    if (!mifareClassic.isConnected()) {
                        throw new IllegalStateException("NFC disconnected");
                    }
                    mifareClassic.writeBlock(a[i2] + sectorToBlock, copyOfRange);
                    i2 = i3;
                }
                i++;
            }
        } catch (Exception e) {
            e.printStackTrace();
            n("writeerror", e.getMessage(), null, null);
            return false;
        }
    }

    public final boolean q(Tag tag) {
        if (AbstractC0814a.q(tag, Ndef.class)) {
            return s(tag);
        }
        if (AbstractC0814a.q(tag, NdefFormatable.class)) {
            return r(tag);
        }
        if (AbstractC0814a.q(tag, NfcA.class)) {
            return s(tag);
        }
        String str = "Incompatible tag. Available tech on tag: " + AbstractC0814a.c(tag);
        AbstractC0814a.a(str);
        n("writeerror", str, null, null);
        return false;
    }

    public final boolean r(Tag tag) {
        NdefFormatable ndefFormatable = NdefFormatable.get(tag);
        try {
            try {
                ndefFormatable.connect();
                ndefFormatable.format(AbstractC0814a.i(XoneNFCRuntime.getValue(this, XoneNFCRuntime.DATA_TAG)));
                n("writeerror", "", null, null);
                Utils.N(ndefFormatable);
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                n("writeerror", e.getMessage(), null, null);
                Utils.N(ndefFormatable);
                return false;
            }
        } catch (Throwable th) {
            Utils.N(ndefFormatable);
            throw th;
        }
    }

    public final boolean s(Tag tag) {
        Ndef ndef = Ndef.get(tag);
        try {
            try {
                ndef.connect();
                ndef.writeNdefMessage(AbstractC0814a.i(XoneNFCRuntime.getValue(this, XoneNFCRuntime.DATA_TAG)));
                n("writeerror", "", null, null);
                Utils.N(ndef);
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                n("writeerror", e.getMessage(), null, null);
                Utils.N(ndef);
                return false;
            }
        } catch (Throwable th) {
            Utils.N(ndef);
            throw th;
        }
    }
}