CHG: applied https://github.com/Proxmark/proxmark3/pull/553 (@arnie97) and in some more places

This commit is contained in:
iceman1001 2018-01-25 09:51:49 +01:00
parent aad1e65b97
commit a13ecc4a4e
14 changed files with 62 additions and 62 deletions

View file

@ -2305,7 +2305,7 @@ int CmdHF14AMfECFill(const char *Cmd) {
c = param_getchar(Cmd, 1); c = param_getchar(Cmd, 1);
numSectors = NumOfSectors(c); numSectors = NumOfSectors(c);
printf("--params: numSectors: %d, keyType:%d", numSectors, keyType); printf("--params: numSectors: %d, keyType: %c\n", numSectors, (keyType==0) ? 'A' : 'B');
UsbCommand cmd = {CMD_MIFARE_EML_CARDLOAD, {numSectors, keyType, 0}}; UsbCommand cmd = {CMD_MIFARE_EML_CARDLOAD, {numSectors, keyType, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&cmd); SendCommand(&cmd);

View file

@ -2,7 +2,7 @@
This is a library to read 14443a tags. It can be used something like this This is a library to read 14443a tags. It can be used something like this
local reader = require('read14a') local reader = require('read14a')
result, err = reader.read1443a() result, err = reader.read14443a()
if not result then if not result then
print(err) print(err)
return return
@ -43,11 +43,11 @@ ISO14443a_TYPES[0x88] = "Infineon MIFARE CLASSIC 1K"
ISO14443a_TYPES[0x98] = "Gemplus MPCOS" ISO14443a_TYPES[0x98] = "Gemplus MPCOS"
local function tostring_1443a(sak) local function tostring_14443a(sak)
return ISO14443a_TYPES[sak] or ("Unknown (SAK=%x)"):format(sak) return ISO14443a_TYPES[sak] or ("Unknown (SAK=%x)"):format(sak)
end end
local function parse1443a(data) local function parse14443a(data)
--[[ --[[
Based on this struct : Based on this struct :
@ -67,7 +67,7 @@ local function parse1443a(data)
uid = uid:sub(1,2*uidlen) uid = uid:sub(1,2*uidlen)
--print("uid, atqa, sak: ",uid, atqa, sak) --print("uid, atqa, sak: ",uid, atqa, sak)
--print("TYPE: ", tostring_1443a(sak)) --print("TYPE: ", tostring_1443a(sak))
return { uid = uid, atqa = atqa, sak = sak, name = tostring_1443a(sak)} return { uid = uid, atqa = atqa, sak = sak, name = tostring_14443a(sak)}
end end
--- Sends a USBpacket to the device --- Sends a USBpacket to the device
@ -77,7 +77,6 @@ end
-- response of type CMD_ACK -- response of type CMD_ACK
-- @return packet,nil if successfull -- @return packet,nil if successfull
-- nil, errormessage if unsuccessfull -- nil, errormessage if unsuccessfull
local function sendToDevice(command, ignoreresponse) local function sendToDevice(command, ignoreresponse)
--core.clearCommandBuffer() --core.clearCommandBuffer()
local err = core.SendCommand(command:getBytes()) local err = core.SendCommand(command:getBytes())
@ -98,14 +97,15 @@ end
local function read14443a(dont_disconnect, no_rats) local function read14443a(dont_disconnect, no_rats)
local command, result, info, err, data local command, result, info, err, data
command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, arg1 = ISO14A_COMMAND.ISO14A_CONNECT }
arg1 = ISO14A_COMMAND.ISO14A_CONNECT }
if dont_disconnect then if dont_disconnect then
command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_DISCONNECT command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_DISCONNECT
end end
if no_rats then if no_rats then
command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_RATS command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_RATS
end end
local result,err = sendToDevice(command) local result,err = sendToDevice(command)
if result then if result then
local count,cmd,arg0,arg1,arg2 = bin.unpack('LLLL',result) local count,cmd,arg0,arg1,arg2 = bin.unpack('LLLL',result)
@ -113,7 +113,7 @@ local function read14443a(dont_disconnect, no_rats)
return nil, "iso14443a card select failed" return nil, "iso14443a card select failed"
end end
data = string.sub(result,count) data = string.sub(result,count)
info, err = parse1443a(data) info, err = parse14443a(data)
else else
err ="No response from card" err ="No response from card"
end end
@ -139,10 +139,10 @@ local function waitFor14443a()
return nil, "Aborted by user" return nil, "Aborted by user"
end end
local library = { local library = {
read1443a = read14443a, read = read14443a,
read = read14443a, read = read14443a,
waitFor14443a = waitFor14443a, waitFor14443a = waitFor14443a,
parse1443a = parse1443a, parse14443a = parse14443a,
sendToDevice = sendToDevice, sendToDevice = sendToDevice,
ISO14A_COMMAND = ISO14A_COMMAND, ISO14A_COMMAND = ISO14A_COMMAND,
} }

View file

@ -98,7 +98,7 @@ function main(args)
dbg("doconnect") dbg("doconnect")
-- We reuse the connect functionality from a -- We reuse the connect functionality from a
-- common library -- common library
info, err = lib14a.read1443a(true, no_rats) info, err = lib14a.read(true, no_rats)
if err then return oops(err) end if err then return oops(err) end
print(("Connected to card, uid = %s"):format(info.uid)) print(("Connected to card, uid = %s"):format(info.uid))

View file

@ -152,7 +152,7 @@ local function main(args)
if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end
else else
-- GET TAG UID -- GET TAG UID
local tag, err = lib14a.read1443a(false, true) local tag, err = lib14a.read(false, true)
if not tag then return oops(err) end if not tag then return oops(err) end
core.clearCommandBuffer() core.clearCommandBuffer()

View file

@ -161,7 +161,7 @@ local function main(args)
if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end
else else
-- GET TAG UID -- GET TAG UID
local tag, err = lib14a.read1443a(false, true) local tag, err = lib14a.read(false, true)
if not tag then return oops(err) end if not tag then return oops(err) end
core.clearCommandBuffer() core.clearCommandBuffer()
uid = tag.uid uid = tag.uid

View file

@ -173,7 +173,7 @@ local function main(args)
if #uid ~= 8 then return oops('uid wrong length. Should be 4 hex bytes') end if #uid ~= 8 then return oops('uid wrong length. Should be 4 hex bytes') end
else else
-- GET TAG UID -- GET TAG UID
local tag, err = lib14a.read1443a(false, true) local tag, err = lib14a.read(false, true)
if not tag then return oops(err) end if not tag then return oops(err) end
core.clearCommandBuffer() core.clearCommandBuffer()

View file

@ -561,7 +561,7 @@ function main(args)
setdevicedebug(false) setdevicedebug(false)
-- GET TAG UID -- GET TAG UID
tag, err = lib14a.read1443a(false, true) tag, err = lib14a.read(false, true)
if not tag then return oops(err) end if not tag then return oops(err) end
core.clearCommandBuffer() core.clearCommandBuffer()

View file

@ -81,7 +81,7 @@ end
-- --
-- Read information from a card -- Read information from a card
function GetCardInfo() function GetCardInfo()
result, err = lib14a.read1443a(false, true) result, err = lib14a.read(false, true)
if not result then if not result then
print(err) print(err)
return return

View file

@ -15,6 +15,7 @@ local keylist = require('mf_default_keys')
-- Ability to read what card is there -- Ability to read what card is there
local lib14a = require('read14a') local lib14a = require('read14a')
local getopt = require('getopt') local getopt = require('getopt')
-- Asks the user for input
local utils = require('utils') local utils = require('utils')
example =[[ example =[[
@ -22,7 +23,8 @@ example =[[
]] ]]
author = "Holiman" author = "Holiman"
usage = "script run mfkeys" usage = "script run mfkeys"
desc = ("This script implements Mifare check keys. It utilises a large list of default keys (currently %d keys).\ desc = ("This script implements Mifare check keys.\
It utilises a large list of default keys (currently %d keys).\
If you want to add more, just put them inside /lualibs/mf_default_keys.lua\n"):format(#keylist) .. If you want to add more, just put them inside /lualibs/mf_default_keys.lua\n"):format(#keylist) ..
[[ [[
@ -257,9 +259,8 @@ local function main( args)
if o == "h" then return help() end if o == "h" then return help() end
if o == "p" then return printkeys() end if o == "p" then return printkeys() end
end end
-- identify tag -- identify tag
tag, err = lib14a.read1443a(false, true) tag, err = lib14a.read(false, true)
if not tag then return oops(err) end if not tag then return oops(err) end
-- detect sectors and print taginfo -- detect sectors and print taginfo
@ -272,4 +273,3 @@ local function main( args)
end end
main( args) main( args)

View file

@ -1,5 +1,5 @@
local getopt = require('getopt') local getopt = require('getopt')
local reader = require('read14a') local lib14a = require('read14a')
local cmds = require('commands') local cmds = require('commands')
local utils = require('utils') local utils = require('utils')
@ -61,7 +61,7 @@ end
-- @return if unsuccessfull : nil, error -- @return if unsuccessfull : nil, error
local function wait_for_mifare() local function wait_for_mifare()
while not core.ukbhit() do while not core.ukbhit() do
res, err = reader.read1443a() res, err = lib14a.read()
if res then return res end if res then return res end
-- err means that there was no response from card -- err means that there was no response from card
end end

View file

@ -359,7 +359,7 @@ local function main(args)
if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end
else else
-- GET TAG UID -- GET TAG UID
local tag, err = lib14a.read1443a(false, true) local tag, err = lib14a.read(false, true)
if not tag then return oops(err) end if not tag then return oops(err) end
core.clearCommandBuffer() core.clearCommandBuffer()
uid = tag.uid uid = tag.uid

View file

@ -122,7 +122,7 @@ local function main(args)
-- find tag -- find tag
result, err = lib14a.read1443a(false, true) result, err = lib14a.read(false, true)
if not result then return oops(err) end if not result then return oops(err) end
-- load keys -- load keys

View file

@ -126,7 +126,7 @@ local function main(args)
local cmdSetDbgOff = "hf mf dbg 0" local cmdSetDbgOff = "hf mf dbg 0"
core.console( cmdSetDbgOff) core.console( cmdSetDbgOff)
result, err = lib14a.read1443a(false, true) result, err = lib14a.read(false, true)
if not result then if not result then
return oops(err) return oops(err)
end end

View file

@ -125,7 +125,7 @@ function main(args)
endblock = endblock or 20 endblock = endblock or 20
-- First of all, connect -- First of all, connect
info, err = lib14a.read1443a(true, true) info, err = lib14a.read(true, true)
if err then disconnect() return oops(err) end if err then disconnect() return oops(err) end
core.clearCommandBuffer() core.clearCommandBuffer()