diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 60b657388..58124a9db 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2305,7 +2305,7 @@ int CmdHF14AMfECFill(const char *Cmd) { c = param_getchar(Cmd, 1); 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}}; clearCommandBuffer(); SendCommand(&cmd); diff --git a/client/lualibs/read14a.lua b/client/lualibs/read14a.lua index 5891c644d..bc58914db 100644 --- a/client/lualibs/read14a.lua +++ b/client/lualibs/read14a.lua @@ -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 : @@ -67,17 +67,16 @@ local function parse1443a(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)} + return { uid = uid, atqa = atqa, sak = sak, name = tostring_14443a(sak)} end --- Sends a USBpacket to the device -- @param command - the usb packet to send --- @param ignoreresponse - if set to true, we don't read the device answer packet --- which is usually recipe for fail. If not sent, the host will wait 2s for a +-- @param ignoreresponse - if set to true, we don't read the device answer packet +-- which is usually recipe for fail. If not sent, the host will wait 2s for a -- response of type CMD_ACK -- @return packet,nil if successfull -- nil, errormessage if unsuccessfull - local function sendToDevice(command, ignoreresponse) --core.clearCommandBuffer() local err = core.SendCommand(command:getBytes()) @@ -98,35 +97,36 @@ end local function read14443a(dont_disconnect, no_rats) local command, result, info, err, data - command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, - arg1 = ISO14A_COMMAND.ISO14A_CONNECT } + command = Command:new{cmd = cmds.CMD_READER_ISO_14443a, arg1 = ISO14A_COMMAND.ISO14A_CONNECT } + if dont_disconnect then command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_DISCONNECT end if no_rats then command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_RATS end + local result,err = sendToDevice(command) if result then local count,cmd,arg0,arg1,arg2 = bin.unpack('LLLL',result) - if arg0 == 0 then + if arg0 == 0 then 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 - if err then - print(err) + if err then + print(err) return nil, err end return info end --- --- Waits for a mifare card to be placed within the vicinity of the reader. +-- Waits for a mifare card to be placed within the vicinity of the reader. -- @return if successfull: an table containing card info -- @return if unsuccessfull : nil, error local function waitFor14443a() @@ -139,12 +139,12 @@ local function waitFor14443a() return nil, "Aborted by user" end local library = { - read1443a = read14443a, + read = read14443a, read = read14443a, waitFor14443a = waitFor14443a, - parse1443a = parse1443a, + parse14443a = parse14443a, sendToDevice = sendToDevice, ISO14A_COMMAND = ISO14A_COMMAND, } -return library \ No newline at end of file +return library diff --git a/client/scripts/14araw.lua b/client/scripts/14araw.lua index 21412ceff..01af5422e 100644 --- a/client/scripts/14araw.lua +++ b/client/scripts/14araw.lua @@ -98,7 +98,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.read(true, no_rats) if err then return oops(err) end print(("Connected to card, uid = %s"):format(info.uid)) diff --git a/client/scripts/calc_di.lua b/client/scripts/calc_di.lua index 62b126e67..fc14b7040 100644 --- a/client/scripts/calc_di.lua +++ b/client/scripts/calc_di.lua @@ -152,7 +152,7 @@ local function main(args) if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end else -- 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 core.clearCommandBuffer() diff --git a/client/scripts/calc_ev1_it.lua b/client/scripts/calc_ev1_it.lua index ae46861b5..9d2ccbe3f 100644 --- a/client/scripts/calc_ev1_it.lua +++ b/client/scripts/calc_ev1_it.lua @@ -161,7 +161,7 @@ local function main(args) if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end else -- 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 core.clearCommandBuffer() uid = tag.uid diff --git a/client/scripts/calc_mizip.lua b/client/scripts/calc_mizip.lua index e2a09608c..374eec9ea 100644 --- a/client/scripts/calc_mizip.lua +++ b/client/scripts/calc_mizip.lua @@ -173,7 +173,7 @@ local function main(args) if #uid ~= 8 then return oops('uid wrong length. Should be 4 hex bytes') end else -- 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 core.clearCommandBuffer() diff --git a/client/scripts/didump.lua b/client/scripts/didump.lua index 3663a8429..b63d2ed07 100644 --- a/client/scripts/didump.lua +++ b/client/scripts/didump.lua @@ -561,7 +561,7 @@ function main(args) setdevicedebug(false) -- GET TAG UID - tag, err = lib14a.read1443a(false, true) + tag, err = lib14a.read(false, true) if not tag then return oops(err) end core.clearCommandBuffer() diff --git a/client/scripts/formatMifare.lua b/client/scripts/formatMifare.lua index bbb6ec32f..44d5bb97a 100644 --- a/client/scripts/formatMifare.lua +++ b/client/scripts/formatMifare.lua @@ -81,7 +81,7 @@ end -- -- Read information from a card function GetCardInfo() - result, err = lib14a.read1443a(false, true) + result, err = lib14a.read(false, true) if not result then print(err) return diff --git a/client/scripts/mfkeys.lua b/client/scripts/mfkeys.lua index 4ba7640bf..085390526 100644 --- a/client/scripts/mfkeys.lua +++ b/client/scripts/mfkeys.lua @@ -1,11 +1,11 @@ --[[ This is an example of Lua-scripting within proxmark3. This is a lua-side - implementation of hf mf chk + implementation of hf mf chk This code is licensed to you under the terms of the GNU GPL, version 2 or, at your option, any later version. See the LICENSE.txt file for the text of the license. - + Copyright (C) 2013 m h swende <martin at swende.se> --]] -- Loads the commands-library @@ -15,6 +15,7 @@ local keylist = require('mf_default_keys') -- Ability to read what card is there local lib14a = require('read14a') local getopt = require('getopt') +-- Asks the user for input local utils = require('utils') example =[[ @@ -22,7 +23,8 @@ example =[[ ]] author = "Holiman" 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) .. [[ @@ -84,10 +86,10 @@ local function checkBlock(blockno, testkeys, keytype) local d1 = table.concat(testkeys, "", start, n) print(("Testing block %d, keytype %d, with %d keys"):format(blockno, keytype, chunksize)) - local command = Command:new{cmd = cmds.CMD_MIFARE_CHKKEYS, + local command = Command:new{cmd = cmds.CMD_MIFARE_CHKKEYS, arg1 = arg1, - arg2 = 0, - arg3 = chunksize, + arg2 = 0, + arg3 = chunksize, data = d1} local status = checkCommand(command) if status then return status, blockno end @@ -116,8 +118,8 @@ local function display_results(keys) end -- A little helper to place an item first in the list local function placeFirst(akey, list) - akey = akey:lower() - if list[1] == akey then + akey = akey:lower() + if list[1] == akey then -- Already at pole position return list end @@ -155,17 +157,17 @@ end -- -- dumps all keys to file local function dumptofile(keys) - if utils.confirm('Do you wish to save the keys to dumpfile?') then + if utils.confirm('Do you wish to save the keys to dumpfile?') then local destination = utils.input('Select a filename to store to', 'dumpkeys.bin') local file = io.open(destination, 'wb') - if file == nil then + if file == nil then print('Could not write to file ', destination) return end local key_a = '' local key_b = '' - + --for sector,_ in pairs(keys) do for sector = 0, #keys do local succA, succB, keyA, keyB = unpack(keys[sector]) @@ -205,18 +207,18 @@ local function perform_check(numsectors) local succA, succB, keyA, keyB = unpack(keys[sector]) local keyA = checkBlock(targetblock, keylist, 0) - if keyA then succA = 1; keylist = placeFirst(keyA, keylist) end + if keyA then succA = 1; keylist = placeFirst(keyA, keylist) end keyA = keyA or '------------' - + local keyB = checkBlock(targetblock, keylist, 1) - if keyB then succB = 1; keylist = placeFirst(keyB, keylist) end + if keyB then succB = 1; keylist = placeFirst(keyB, keylist) end keyB = keyB or '------------' - keys[sector] = {succA, succB, keyA, keyB } + keys[sector] = {succA, succB, keyA, keyB} end display_results(keys) - + -- save to dumpkeys.bin dumptofile(keys) end @@ -224,13 +226,13 @@ end -- shows tag information local function taginfo(tag) - local sectors = 16 + local sectors = 16 -- Show tag info print((' Found tag %s'):format(tag.name)) - + if 0x18 == tag.sak then --NXP MIFARE Classic 4k | Plus 4k - -- MIFARE Classic 4K offers 4096 bytes split into forty sectors, - -- of which 32 are same size as in the 1K with eight more that are quadruple size sectors. + -- MIFARE Classic 4K offers 4096 bytes split into forty sectors, + -- of which 32 are same size as in the 1K with eight more that are quadruple size sectors. sectors = 40 elseif 0x08 == tag.sak then -- NXP MIFARE CLASSIC 1k | Plus 2k -- 1K offers 1024 bytes of data storage, split into 16 sector @@ -245,31 +247,29 @@ local function taginfo(tag) end return sectors end ---- +--- -- The main entry point -local function main( args) +local function main(args) local start_time = os.time() - local numSectors = 16 - + local numSectors = 16 + -- Arguments for the script for o, a in getopt.getopt(args, 'hp') do - if o == "h" then return help() end + if o == "h" then return help() end if o == "p" then return printkeys() end end - -- identify tag - tag, err = lib14a.read1443a(false, true) + tag, err = lib14a.read(false, true) if not tag then return oops(err) end -- detect sectors and print taginfo numsectors = taginfo(tag) - + perform_check(numsectors) - + local end_time = os.time() - print('mfkeys - Total execution time: '..os.difftime(end_time, start_time)..' sec') + print('mfkeys - Total execution time: '..os.difftime(end_time, start_time)..' sec') end -main( args) - +main( args) \ No newline at end of file diff --git a/client/scripts/mifare_autopwn.lua b/client/scripts/mifare_autopwn.lua index d8734a60f..8eea7376f 100644 --- a/client/scripts/mifare_autopwn.lua +++ b/client/scripts/mifare_autopwn.lua @@ -1,5 +1,5 @@ local getopt = require('getopt') -local reader = require('read14a') +local lib14a = require('read14a') local cmds = require('commands') local utils = require('utils') @@ -61,7 +61,7 @@ end -- @return if unsuccessfull : nil, error local function wait_for_mifare() while not core.ukbhit() do - res, err = reader.read1443a() + res, err = lib14a.read() if res then return res end -- err means that there was no response from card end diff --git a/client/scripts/ntag_3d.lua b/client/scripts/ntag_3d.lua index 7b04edbd1..278f800be 100644 --- a/client/scripts/ntag_3d.lua +++ b/client/scripts/ntag_3d.lua @@ -359,7 +359,7 @@ local function main(args) if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end else -- 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 core.clearCommandBuffer() uid = tag.uid diff --git a/client/scripts/tnp3clone.lua b/client/scripts/tnp3clone.lua index 2a8d2763b..2e1ee7019 100644 --- a/client/scripts/tnp3clone.lua +++ b/client/scripts/tnp3clone.lua @@ -122,7 +122,7 @@ local function main(args) -- find tag - result, err = lib14a.read1443a(false, true) + result, err = lib14a.read(false, true) if not result then return oops(err) end -- load keys diff --git a/client/scripts/tnp3dump.lua b/client/scripts/tnp3dump.lua index 9b93aa62a..8c354ef89 100644 --- a/client/scripts/tnp3dump.lua +++ b/client/scripts/tnp3dump.lua @@ -126,7 +126,7 @@ local function main(args) local cmdSetDbgOff = "hf mf dbg 0" core.console( cmdSetDbgOff) - result, err = lib14a.read1443a(false, true) + result, err = lib14a.read(false, true) if not result then return oops(err) end diff --git a/client/scripts/ufodump.lua b/client/scripts/ufodump.lua index c2e080a09..a77bb6c92 100644 --- a/client/scripts/ufodump.lua +++ b/client/scripts/ufodump.lua @@ -125,7 +125,7 @@ function main(args) endblock = endblock or 20 -- First of all, connect - info, err = lib14a.read1443a(true, true) + info, err = lib14a.read(true, true) if err then disconnect() return oops(err) end core.clearCommandBuffer()