How to write MifareClassic with Custom Key

允我心安 提交于 2019-12-06 09:08:48
NFC guy

You authenticate to sector 4 and then you try to write to block 3. Block 3 is in sector 0, so this will always fail. Try authenticating to sector 0 instead.

BTW: Please, don't write random data to a sector trailer (such as block 3). It will likely lock up the sector with no way to recover.

If I understand correctly, the question is how to edit block 3 in sector 4.
After authentication you try to write to block 3. But:
A blocks number does not start at 0 in every block. Sector 0 has blocks 0-3, sector 1 has blocks 4-7, and so on. Sector 4 has a block-offset of 4*4=16. So the block you want to write to is block 19.

There is a function available that calculates this offset for you. sectorToBlock(4) yields 16.
For writing to block 3 in sector 4 I would use the following:
getMfc().writeBlock(getMfc().sectorToBlock(4)+3, data)

The accepted answer does only provide the alternative that leaves the questioner unable to understand the block-indexing beyond sector 0.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!