kotlin 使用终端Sdk-2.0.3.jar上的TLV实用程序从TLV中删除未知标记(C3、BF 40、C2)

nlejzf6q  于 2022-11-16  发布在  Kotlin
关注(0)|答案(1)|浏览(134)

我正在尝试使用TLVUtility(terminalSdk-2.0.3.jar的mastercard类)从ByteArray中删除一些Unknown tagsC3BF40C2),未从ByteArray中删除标签。我正在这样尝试,
这是我的TLV数据,

ppseResponse = ByteUtility.hexStringToByteArray("6F54840E325041592E5359532E4444463031C30F4920414D2054484520424553542033BF4003C20101A52BBF0C28610C4F07A0000000041010870101610C4F07A0000000043060870103610A4F05B0123456788701099000")

我正在尝试删除Unknown tags

"BEFORE << ${ByteUtility.byteArrayToHexString(ppseResponse)}".toLog(activity, TAG)  //To print Log

val unknownTags = byteArrayOf((0x00C3).toByte(),(0xBF40).toByte(), (0x00C2).toByte())

var removed = TLVUtility.removeTag(ppseResponse, ContentType.TLV,unknownTags)

"AFTER << ${ByteUtility.byteArrayToHexString(removed)}".toLog(activity, TAG) //To print Log

下面是terminalSdk-2.0.3.jar函数上的removeTag函数,

public static byte[] removeTag(byte[] var0, ContentType var1, byte[] var2) {
        int var10000;
        Throwable var10001;
        String var28;
        label698: {
            var10000 = 2 % 2;
            if (var0 != null) {
                label691: {
                    var10000 = g + 85;
                    f = var10000 % 128;
                    if (var10000 % 2 == 0) {
                        byte[] var26 = var2;

                        byte var27;
                        label676: {
                            label675: {
                                try {
                                    null.hashCode();
                                    if (var26 == null) {
                                        break label675;
                                    }
                                } catch (Throwable var25) {
                                    throw var25;
                                }

                                var27 = 42;
                                break label676;
                            }

                            var27 = 74;
                        }

                        switch(var27) {
                        case 42:
                            break;
                        case 74:
                        default:
                            break label691;
                        }
                    } else if (var2 == null) {
                        break label691;
                    }

                    var10000 = f + 55;
                    g = var10000 % 128;
                    switch(var10000 % 2 != 0 ? 0 : 1) {
                    case 0:
                    default:
                        if (var2.length >= 1) {
                            break label698;
                        }
                        break;
                    case 1:
                        if (var2.length >= 1) {
                            break label698;
                        }
                    }
                }
            }

            var28 = e(31, '卆', 490).intern();

            try {
                ((Class)q.b(38, 8595, '\ue0f7')).getMethod("e", String.class).invoke((Object)null, var28);
            } catch (Throwable var22) {
                var10001 = var22.getCause();
                if (var10001 != null) {
                    throw var10001;
                }

                throw var22;
            }

            throw new LibraryUncheckedException(ExceptionCode.X6F44);
        }

        label700: {
            if (var1 == ContentType.T) {
                var10000 = g + 15;
                f = var10000 % 128;
                if (var10000 % 2 == 0) {
                    if (var0.length < 0) {
                        break label700;
                    }
                } else if (var0.length < 1) {
                    break label700;
                }
            }

            switch(var1 != ContentType.TLV ? 81 : 64) {
            case 81:
                if (var1 != ContentType.TDO) {
                    break;
                }
            case 64:
            default:
                if (var0.length < 3) {
                    var28 = e(47, '\u0000', 560).intern();

                    try {
                        ((Class)q.b(38, 8595, '\ue0f7')).getMethod("e", String.class).invoke((Object)null, var28);
                    } catch (Throwable var23) {
                        var10001 = var23.getCause();
                        if (var10001 != null) {
                            throw var10001;
                        }

                        throw var23;
                    }

                    throw new LibraryUncheckedException(ExceptionCode.X6F43);
                }
            }

            ArrayList var3 = conditionalTlvParsing(var0, var1, e(1, '\u0000', 140).intern(), true);
            Iterator var4 = var3.iterator();

            while(var4.hasNext()) {
                BerTlv var5 = (BerTlv)var4.next();
                switch(var5.getTagObject().getNTag() == ByteUtility.byteArrayToInt(var2) ? 39 : 84) {
                case 39:
                default:
                    var4.remove();
                case 84:
                }
            }

            return formByteArrayFromTlvList(var3, var1);
        }

        var28 = e(39, '\u0000', 521).intern();

        try {
            ((Class)q.b(38, 8595, '\ue0f7')).getMethod("e", String.class).invoke((Object)null, var28);
        } catch (Throwable var24) {
            var10001 = var24.getCause();
            if (var10001 != null) {
                throw var10001;
            }

            throw var24;
        }

        throw new LibraryUncheckedException(ExceptionCode.X6F43);
    }
guicsvcw

guicsvcw1#

我通过创建新的自定义函数修复了这个问题。

private fun removeUnknownTags(ppseResponse: ByteArray): ByteArray {
    var ppseResp = ppseResponse;
    val unknownArrayList: ArrayList<ByteArray> = ArrayList()
    unknownArrayList.add(ByteUtility.hexStringToByteArray("C3"))
    unknownArrayList.add(ByteUtility.hexStringToByteArray("BF40"))
    unknownArrayList.add(ByteUtility.hexStringToByteArray("C2"))

    for (i in 0..unknownArrayList.size-1) {
        for (j in 0..ppseResp.size-1) {
            if (TLVUtility.getCurrentTag(ppseResp, j).contentEquals(unknownArrayList[i])) {
                val nextIndex = j + unknownArrayList[i].size;
                val tagLength = ByteUtility.byteArrayToInt(ppseResp[nextIndex])
                var temp = ppseResp.asList().subList(j, nextIndex + tagLength + 1).toByteArray()
                Log.d("***Tags***  =>", "Tag ${ByteUtility.byteArrayToHexString(unknownArrayList[i])} Found, Length is : ${tagLength}")
                Log.d("***Tags***  =>", "Replacement Tag, Length and Value is  ${ByteUtility.byteArrayToHexString(temp)}")

                var replacedString = ByteUtility.byteArrayToHexString(ppseResp).replace(ByteUtility.byteArrayToHexString(temp), "", false)
                ppseResp = ByteUtility.hexStringToByteArray(replacedString)
                ppseResp.set(1, (ppseResp.size - unknownArrayList[i].size).toByte())
                replacedString = ByteUtility.byteArrayToHexString(ppseResp)
                Log.d("***Tags***  =>", "RSP Length : ${ppseResp[1]} ,After Replacement : RSP<<  ${ByteUtility.byteArrayToHexString(ppseResp)}")
                break;
            }
        }

    }
    Log.e("***Tags***  =>", "Final OutCome RSP<<  ${ByteUtility.byteArrayToHexString(ppseResp)}")
    return ppseResp;
}

相关问题