This commit is contained in:
Philippe Teuwen 2019-04-28 22:54:00 +02:00
parent f1deb865db
commit 69f8d81f4e
12 changed files with 42 additions and 43 deletions

View file

@ -92,13 +92,13 @@ Command = {
end end
o.data = data o.data = data
return o return o
end, end,
parse = function (packet) parse = function (packet)
local count, cmd, arg1, arg2, arg3, data = bin.unpack('LLLLH511', packet) local count, cmd, arg1, arg2, arg3, data = bin.unpack('LLLLH511', packet)
return Command:new{cmd = cmd, arg1 = arg1, arg2 = arg2, arg3 = arg3, data = data} return Command:new{cmd = cmd, arg1 = arg1, arg2 = arg2, arg3 = arg3, data = data}
end end
} }
-- commented out, not used. -- commented out, not used.
function Command:__tostring() function Command:__tostring()
local output = ("%s\r\nargs : (%s, %s, %s)\r\ndata:\r\n%s\r\n"):format( local output = ("%s\r\nargs : (%s, %s, %s)\r\ndata:\r\n%s\r\n"):format(
_commands.tostring(self.cmd), _commands.tostring(self.cmd),
@ -128,7 +128,7 @@ function Command:__responsetostring()
tostring(self.resp_arg1), tostring(self.resp_arg1),
tostring(self.resp_arg2), tostring(self.resp_arg2),
tostring(self.resp_arg3))) tostring(self.resp_arg3)))
print('NG ::', self.resp_ng) print('NG ::', self.resp_ng)
print('package ::', self.resp_response) print('package ::', self.resp_response)
end end
@ -144,10 +144,10 @@ function Command:sendMIX( ignore_response, timeout )
local data = self.data local data = self.data
local cmd = self.cmd local cmd = self.cmd
local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3 local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3
local err, msg = core.SendCommandMIX(cmd, arg1, arg2, arg3, data) local err, msg = core.SendCommandMIX(cmd, arg1, arg2, arg3, data)
if err == nil then return err, msg end if err == nil then return err, msg end
if ignore_response then return true, nil end if ignore_response then return true, nil end
if timeout == nil then timeout = TIMEOUT end if timeout == nil then timeout = TIMEOUT end
@ -156,13 +156,13 @@ function Command:sendMIX( ignore_response, timeout )
if response == nil then if response == nil then
return nil, 'Error, waiting for response timed out :: '..msg return nil, 'Error, waiting for response timed out :: '..msg
end end
-- lets digest -- lets digest
local data local data
local count, cmd, length, magic, status, crc, arg1, arg2, arg3 = bin.unpack('SSIsSLLL', response) local count, cmd, length, magic, status, crc, arg1, arg2, arg3 = bin.unpack('SSIsSLLL', response)
count, data, ng = bin.unpack('H'..length..'C', response, count) count, data, ng = bin.unpack('H'..length..'C', response, count)
--[[ uncomment if you want to debug --[[ uncomment if you want to debug
self.resp_cmd = cmd self.resp_cmd = cmd
self.resp_length = length self.resp_length = length
self.resp_magic = magic self.resp_magic = magic
@ -181,20 +181,20 @@ function Command:sendMIX( ignore_response, timeout )
end end
function Command:sendNG( ignore_response, timeout ) function Command:sendNG( ignore_response, timeout )
local data = self.data local data = self.data
local cmd = self.cmd local cmd = self.cmd
local err, msg = core.SendCommandNG(cmd, data) local err, msg = core.SendCommandNG(cmd, data)
if err == nil then return err, msg end if err == nil then return err, msg end
if ignore_response then return true, nil end if ignore_response then return true, nil end
if timeout == nil then timeout = TIMEOUT end if timeout == nil then timeout = TIMEOUT end
local response, msg = core.WaitForResponseTimeout(cmd, timeout) local response, msg = core.WaitForResponseTimeout(cmd, timeout)
if response == nil then if response == nil then
return nil, 'Error, waiting for response timed out :: '..msg return nil, 'Error, waiting for response timed out :: '..msg
end end
-- lets digest -- lets digest
local data local data
local count, cmd, length, magic, status, crc, arg1, arg2, arg3 = bin.unpack('SSIsSLLL', response) local count, cmd, length, magic, status, crc, arg1, arg2, arg3 = bin.unpack('SSIsSLLL', response)
count, data, ng = bin.unpack('H'..length..'C', response, count) count, data, ng = bin.unpack('H'..length..'C', response, count)

View file

@ -89,7 +89,7 @@ local function read14443a(dont_disconnect, no_rats)
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 = command:sendMIX() local result,err = command:sendMIX()
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)

View file

@ -183,11 +183,11 @@ main_loop(char *script_cmds_file, char *script_cmd, bool pm3_present) {
cmd[--l] = '\0'; cmd[--l] = '\0';
} }
// ltrim // ltrim
size_t off=0; size_t off = 0;
while ((cmd[off] != '\0') && isspace(cmd[off])) while ((cmd[off] != '\0') && isspace(cmd[off]))
off++; off++;
for (size_t i=0; i < strlen(cmd) - off; i++) for (size_t i = 0; i < strlen(cmd) - off; i++)
cmd[i] = cmd[i+off]; cmd[i] = cmd[i + off];
cmd[strlen(cmd) - off] = '\0'; cmd[strlen(cmd) - off] = '\0';
if (cmd[0] != '\0') { if (cmd[0] != '\0') {

View file

@ -73,10 +73,10 @@ static int l_SendCommandOLD(lua_State *L) {
} }
// parse input // parse input
cmd = luaL_checknumber(L, 1); cmd = luaL_checknumber(L, 1);
arg0 = luaL_checknumber(L, 2); arg0 = luaL_checknumber(L, 2);
arg1 = luaL_checknumber(L, 3); arg1 = luaL_checknumber(L, 3);
arg2 = luaL_checknumber(L, 4); arg2 = luaL_checknumber(L, 4);
// data // data
const char *p_data = luaL_checklstring(L, 5, &size); const char *p_data = luaL_checklstring(L, 5, &size);
@ -93,7 +93,7 @@ static int l_SendCommandOLD(lua_State *L) {
} }
SendCommandOLD(cmd, arg0, arg1, arg2, data, len); SendCommandOLD(cmd, arg0, arg1, arg2, data, len);
lua_pushboolean(L, true); lua_pushboolean(L, true);
return 1; return 1;
} }
@ -120,10 +120,10 @@ static int l_SendCommandMIX(lua_State *L) {
return returnToLuaWithError(L, "You need to supply five parameters"); return returnToLuaWithError(L, "You need to supply five parameters");
// parse input // parse input
cmd = luaL_checknumber(L, 1); cmd = luaL_checknumber(L, 1);
arg0 = luaL_checknumber(L, 2); arg0 = luaL_checknumber(L, 2);
arg1 = luaL_checknumber(L, 3); arg1 = luaL_checknumber(L, 3);
arg2 = luaL_checknumber(L, 4); arg2 = luaL_checknumber(L, 4);
// data // data
const char *p_data = luaL_checklstring(L, 5, &size); const char *p_data = luaL_checklstring(L, 5, &size);
@ -162,7 +162,7 @@ static int l_SendCommandNG(lua_State *L) {
return returnToLuaWithError(L, "You need to supply two parameters"); return returnToLuaWithError(L, "You need to supply two parameters");
// parse input // parse input
uint64_t cmd = luaL_checknumber(L, 1); uint64_t cmd = luaL_checknumber(L, 1);
// data // data
const char *p_data = luaL_checklstring(L, 2, &size); const char *p_data = luaL_checklstring(L, 2, &size);

View file

@ -174,7 +174,7 @@ local function main( args)
local blocks, err = getBlock(0) local blocks, err = getBlock(0)
if err then if err then
close() close()
return oops(err) return oops(err)
end end
-- Block 3 contains number of blocks -- Block 3 contains number of blocks
local b3chars = {string.byte(blocks[4], 1,4)} local b3chars = {string.byte(blocks[4], 1,4)}

View file

@ -80,7 +80,7 @@ local function help()
print(desc) print(desc)
print("Example usage") print("Example usage")
print(example) print(example)
print(usage) print(usage)
end end
--- ---
-- Exit message -- Exit message
@ -261,7 +261,7 @@ local function test(modulation)
, arg2 = block , arg2 = block
} }
local response, err = wc:sendMIX(false) local response, err = wc:sendMIX(false)
if not response then return oops(err) end if not response then return oops(err) end
-- Detect -- Detect
local res, msg = core.t55xx_detect() local res, msg = core.t55xx_detect()
@ -323,7 +323,7 @@ local function main(args)
end end
exitMsg('Tests finished') exitMsg('Tests finished')
core.console( core.console(
format('rem [SUMMARY] Success rate: %d/%d tests passed%s' format('rem [SUMMARY] Success rate: %d/%d tests passed%s'
, total_pass , total_pass
, total_tests , total_tests

View file

@ -63,7 +63,7 @@ local function getblockdata(response)
if not response then if not response then
return nil, 'No response from device' return nil, 'No response from device'
end end
local count, cmd, arg0 = bin.unpack('LL', response) local count, cmd, arg0 = bin.unpack('LL', response)
if arg0 == 1 then if arg0 == 1 then
local count, arg1, arg2, data = bin.unpack('LLH511', response, count) local count, arg1, arg2, data = bin.unpack('LLH511', response, count)
@ -81,7 +81,7 @@ local function readblock( blocknum, keyA )
return b return b
end end
--- ---
-- decode response and get the blockdata from backdoor magic command -- decode response and get the blockdata from backdoor magic command
local function readmagicblock( blocknum ) local function readmagicblock( blocknum )
-- Read block N -- Read block N
local CSETBLOCK_SINGLE_OPERATION = 0x1F local CSETBLOCK_SINGLE_OPERATION = 0x1F

View file

@ -91,7 +91,7 @@ local function getblockdata(response)
if not response then if not response then
return nil, 'No response from device' return nil, 'No response from device'
end end
local count, cmd, arg0 = bin.unpack('LL', response) local count, cmd, arg0 = bin.unpack('LL', response)
if arg0 == 1 then if arg0 == 1 then
local count, arg1, arg2, data = bin.unpack('LLH511', response, count) local count, arg1, arg2, data = bin.unpack('LLH511', response, count)
@ -132,7 +132,7 @@ local function main(args)
local cmdSetDbgOff = "hf mf dbg 0" local cmdSetDbgOff = "hf mf dbg 0"
core.console( cmdSetDbgOff) core.console( cmdSetDbgOff)
utils.Sleep(0.5) utils.Sleep(0.5)
result, err = lib14a.read(false, true) result, err = lib14a.read(false, true)
if not result then return oops(err) end if not result then return oops(err) end
@ -170,7 +170,7 @@ local function main(args)
cmd = Command:newMIX{cmd = cmds.CMD_MIFARE_READBL, arg1 = 0, data = keyA} cmd = Command:newMIX{cmd = cmds.CMD_MIFARE_READBL, arg1 = 0, data = keyA}
block0, err = getblockdata(cmd:sendMIX(false)) block0, err = getblockdata(cmd:sendMIX(false))
if not block0 then return oops(err) end if not block0 then return oops(err) end
core.clearCommandBuffer() core.clearCommandBuffer()
-- Read block 1 -- Read block 1

View file

@ -242,7 +242,7 @@ local function LoadEmulator(uid, blocks)
blockdata = AddKey(keys, _, blockdata) blockdata = AddKey(keys, _, blockdata)
end end
end end
io.write( _..',') io.write( _..',')
io.flush() io.flush()
core.clearCommandBuffer() core.clearCommandBuffer()

View file

@ -15,7 +15,7 @@ xor: the first three block (0,1,2) is not XORED. The rest seems to be xored.
example = [[ example = [[
-- default -- default
script run ufodump script run ufodump
-- stop at block 10 -- stop at block 10
script run ufodump -b 10 script run ufodump -b 10
]] ]]
@ -48,7 +48,7 @@ end
local function oops(err) local function oops(err)
print('ERROR:', err) print('ERROR:', err)
core.clearCommandBuffer() core.clearCommandBuffer()
return nil, err return nil, err
end end
--- ---
-- Usage help -- Usage help
@ -59,7 +59,7 @@ local function help()
print(desc) print(desc)
print('Example usage') print('Example usage')
print(example) print(example)
print(usage) print(usage)
end end
-- --
-- writes data to ascii textfile. -- writes data to ascii textfile.
@ -122,7 +122,7 @@ function sendRaw(rawdata, options)
-- of the ASCII-string rawdata -- of the ASCII-string rawdata
arg2 = string.len(rawdata)/2, arg2 = string.len(rawdata)/2,
data = rawdata} data = rawdata}
return command:sendMIX(options.ignore_response) return command:sendMIX(options.ignore_response)
end end
-- --

View file

@ -57,7 +57,7 @@ local function help()
print(desc) print(desc)
print('Example usage') print('Example usage')
print(example) print(example)
print(usage) print(usage)
end end
-- --
--- Set UID on magic command enabled --- Set UID on magic command enabled

View file

@ -832,8 +832,7 @@ bool str_startswith(const char *s, const char *pre) {
bool str_endswith(const char *s, const char *suffix) { bool str_endswith(const char *s, const char *suffix) {
size_t ls = strlen(s); size_t ls = strlen(s);
size_t lsuffix = strlen(suffix); size_t lsuffix = strlen(suffix);
if (ls >= lsuffix) if (ls >= lsuffix) {
{
return strncmp(suffix, s + (ls - lsuffix), lsuffix) == 0; return strncmp(suffix, s + (ls - lsuffix), lsuffix) == 0;
} }
return false; return false;