Merge pull request #553 from Arnie97/master

Minor fixes
This commit is contained in:
Iceman 2018-01-25 09:50:47 +01:00 committed by GitHub
commit 380e0d086c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 96 deletions

View file

@ -1907,7 +1907,7 @@ int CmdHF14AMfECFill(const char *Cmd)
default: numSectors = 16;
}
printf("--params: numSectors: %d, keyType:%d", numSectors, keyType);
printf("--params: numSectors: %d, keyType:%d\n", numSectors, keyType);
UsbCommand c = {CMD_MIFARE_EML_CARDLOAD, {numSectors, keyType, 0}};
SendCommand(&c);
return 0;

View file

@ -2,7 +2,7 @@
This is a library to read 14443a tags. It can be used something like this
local reader = require('read14a')
result, err = reader.read1443a()
result, err = reader.read14443a()
if not result then
print(err)
return
@ -43,11 +43,11 @@ ISO14443a_TYPES[0x88] = "Infineon MIFARE CLASSIC 1K"
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)
end
local function parse1443a(data)
local function parse14443a(data)
--[[
Based on this struct :
@ -66,8 +66,8 @@ local function parse1443a(data)
local count,uid,uidlen, atqa, sak, ats_len, ats= bin.unpack('H10CH2CC',data)
uid = uid:sub(1,2*uidlen)
--print("uid, atqa, sak: ",uid, atqa, sak)
--print("TYPE: ", tostring_1443a(sak))
return { uid = uid, atqa = atqa, sak = sak, name = tostring_1443a(sak)}
--print("TYPE: ", tostring_14443a(sak))
return { uid = uid, atqa = atqa, sak = sak, name = tostring_14443a(sak)}
end
--- Sends a USBpacket to the device
@ -114,7 +114,7 @@ local function read14443a(dont_disconnect, no_rats)
return nil, "iso14443a card select failed"
end
data = string.sub(result,count)
info, err = parse1443a(data)
info, err = parse14443a(data)
else
err ="No response from card"
end
@ -139,12 +139,12 @@ local function waitFor14443a()
end
return nil, "Aborted by user"
end
local library = {
read1443a = read14443a,
local library = {
read14443a = read14443a,
read = read14443a,
waitFor14443a = waitFor14443a,
parse1443a = parse1443a,
parse14443a = parse14443a,
sendToDevice = sendToDevice,
ISO14A_COMMAND = ISO14A_COMMAND,
}

View file

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

View file

@ -406,7 +406,7 @@ function main(args)
-- GET TAG UID
result, err = lib14a.read1443a(false, true)
result, err = lib14a.read14443a(false, true)
if not result then
return oops(err)
end

View file

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

View file

@ -14,50 +14,16 @@ local cmds = require('commands')
local keys = require('mf_default_keys')
-- Ability to read what card is there
local reader = require('read14a')
-- Asks the user for input
local utils = require('utils')
local desc =
("This script implements check keys. It utilises a large list of default keys (currently %d keys).\
local desc = ("This script implements check keys. \
It utilises a large list of default keys (currently %d keys).\
If you want to add more, just put them inside mf_default_keys.lua. "):format(#keys)
local TIMEOUT = 10000 -- 10 seconds
--[[This may be moved to a separate library at some point]]
local utils =
{
---
-- Asks the user for Yes or No
confirm = function(message, ...)
local answer
message = message .. " [y]/[n] ?"
repeat
io.write(message)
io.flush()
answer=io.read()
if answer == 'Y' or answer == "y" then
return true
elseif answer == 'N' or answer == 'n' then
return false
end
until false
end,
---
-- Asks the user for input
input = function (message , default)
local answer
if default ~= nil then
message = message .. " (default: ".. default.. " )"
end
message = message .." \n > "
io.write(message)
io.flush()
answer=io.read()
if answer == '' then answer = default end
return answer
end,
}
local function checkCommand(command)
@ -119,11 +85,12 @@ local function displayresults(results)
for sector,_ in pairs(results) do
blockNo, keyA, keyB = unpack(_)
print(("| %3d | %3d |%s|%s|"):format(sector, blockNo, keyA, keyB ))
print(("| %3d | %3d |%12s|%12s|"):format(sector, blockNo, keyA, keyB))
end
print("|--------------------------------------|")
end
-- A little helper to place an item first in the list
local function placeFirst(akey, list)
akey = akey:lower()
@ -140,6 +107,7 @@ local function placeFirst(akey, list)
end
return result
end
local function dumptofile(results)
local sector, blockNo, keyA, keyB,_
@ -170,7 +138,7 @@ local function main( args)
print(desc);
result, err = reader.read1443a(false, true)
result, err = reader.read14443a(false, true)
if not result then
print(err)
return
@ -193,7 +161,7 @@ local function main( args)
elseif 0x09 == result.sak then -- NXP MIFARE Mini 0.3k
-- MIFARE Classic mini offers 320 bytes split into five sectors.
numSectors = 5
elseif 0x10 == result.sak then-- "NXP MIFARE Plus 2k"
elseif 0x10 == result.sak then -- NXP MIFARE Plus 2k
numSectors = 32
else
print("I don't know how many sectors there are on this type of card, defaulting to 16")
@ -234,4 +202,3 @@ local function main( args)
end
main(args)

View file

@ -56,7 +56,7 @@ end
-- @return if unsuccessfull : nil, error
function wait_for_mifare()
while not core.ukbhit() do
res, err = reader.read1443a(false, true)
res, err = reader.read14443a(false, true)
if res then return res end
-- err means that there was no response from card
end

View file

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

View file

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