[英]Android's NfcA to python's pyscard (smartcard)
I am backwards-engineering an android application (written in java) into a python application, where nfc (apdu) commands are sent.我正在将 android 应用程序(用 java 编写)反向工程为 python 应用程序,其中发送了 nfc (apdu) 命令。 (ISO 14443-3A, if that helps)
(ISO 14443-3A,如果有帮助的话)
The android applications makes use of the android.nfc.tech.NfcA
library and sends commands such as: android 应用程序使用
android.nfc.tech.NfcA
库并发送如下命令:
import android.nfc.tech.NfcA;
NfcA nfca_tag;
byte[] message;
message = nfca_tag.transceive(new byte[]{48, 4});
// also with negative numbers:
message = nfca_tag.transceive(new byte[]{-51, 13};
On the python-side, using the pyscard module an example would look like this:在 python 端,使用 pyscard 模块的示例如下所示:
from smartcard.CardRequest import CardRequest
cardrequest = CardRequest( timeout=1,
cardType=cardtype )
cardservice = cardrequest.waitforcard()
cardservice.connection.connect()
data, sw1, sw2 = cardservice.connection.transmit([0xFF, 0xB0, 0x00, 0x00, 0x0F])
# respectively
data, sw1, sw2 = cardservice.connection.transmit([255, 176, 0, 0, 15])
What is the translation of the android NfcA's message (such as {48, 4}
) to python pyscard's message (such as `[0xFF, 0xB0, 0x00, 0x00, 0x0F]')? android NfcA 的消息(例如
{48, 4}
)到 python pyscard 的消息(例如 `[0xFF, 0xB0, 0x00, 0x00, 0x0F]')的翻译是什么?
Now i know, that java bytes go from -128 to 127 and therefore whatever byte we have in java, we can translate it using this function现在我知道,java 字节 go 从 -128 到 127,因此无论我们在 java 中有什么字节,我们都可以使用这个 function 来翻译它
def java_byte_to_python(java_byte: int):
return java_byte%256
However, it seems to me, that the NfcA module already has some bytes that are sent by default, as an apdu command requires at least 4 bytes?但是,在我看来,NfcA 模块已经有一些默认发送的字节,因为 apdu 命令至少需要 4 个字节?
Further information on the specific tag for this application:有关此应用程序特定标签的更多信息:
Android technology information: Android 技术资料:
Detailed protocol information详细的协议信息
The answer here is dependent on the smart card reader and tag that is used.这里的答案取决于所使用的智能卡读卡器和标签。
In my case, using an ACR1252U ( Product page & API documentation ) and a Mifare Ultralight C:就我而言,使用 ACR1252U( 产品页面和API 文档)和 Mifare Ultralight C:
cardservice.connection.transmit([0xFF, 0xC2, 0x00, 0x00, 0x02, 0x81, 0x00])
message_in_java_bytes = [48, 4]
message = [x%256 for x in message_in_java_bytes]
cardservice.connection.transmit([0xFF, 0xC2, 0x00, 0x01, len(message)+2, 0x95, len(message), *message])
(Card response format: C0 03 00 90 00 92 01 00 96 02 00 00 97 0C [Card Response] 90 00) (卡片响应格式:C0 03 00 90 00 92 01 00 96 02 00 00 97 0C 【卡片响应】 90 00)
cardservice.connection.transmit([0xFF, 0xC2, 0x00, 0x00, 0x02, 0x82, 0x00])
Android Tag Operation commands Android 标签操作命令
Relation between APDU and ISO 14443-A APDU 和 ISO 14443-A 之间的关系
NFC Forum Digital Protocol (this goes deep down the rabbit hole) NFC 论坛数字协议(深入兔子洞)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.