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
o.data = data
return o
end,
end,
parse = function (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}
end
end
}
-- commented out, not used.
-- commented out, not used.
function Command:__tostring()
local output = ("%s\r\nargs : (%s, %s, %s)\r\ndata:\r\n%s\r\n"):format(
_commands.tostring(self.cmd),
@ -128,7 +128,7 @@ function Command:__responsetostring()
tostring(self.resp_arg1),
tostring(self.resp_arg2),
tostring(self.resp_arg3)))
print('NG ::', self.resp_ng)
print('NG ::', self.resp_ng)
print('package ::', self.resp_response)
end
@ -144,10 +144,10 @@ function Command:sendMIX( ignore_response, timeout )
local data = self.data
local cmd = self.cmd
local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3
local err, msg = core.SendCommandMIX(cmd, arg1, arg2, arg3, data)
if err == nil then return err, msg end
if ignore_response then return true, nil end
if timeout == nil then timeout = TIMEOUT end
@ -156,13 +156,13 @@ function Command:sendMIX( ignore_response, timeout )
if response == nil then
return nil, 'Error, waiting for response timed out :: '..msg
end
-- lets digest
-- lets digest
local data
local count, cmd, length, magic, status, crc, arg1, arg2, arg3 = bin.unpack('SSIsSLLL', response)
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_length = length
self.resp_magic = magic
@ -181,20 +181,20 @@ function Command:sendMIX( ignore_response, timeout )
end
function Command:sendNG( ignore_response, timeout )
local data = self.data
local cmd = self.cmd
local cmd = self.cmd
local err, msg = core.SendCommandNG(cmd, data)
if err == nil then return err, msg end
if ignore_response then return true, nil end
if timeout == nil then timeout = TIMEOUT end
local response, msg = core.WaitForResponseTimeout(cmd, timeout)
if response == nil then
return nil, 'Error, waiting for response timed out :: '..msg
end
-- lets digest
-- lets digest
local data
local count, cmd, length, magic, status, crc, arg1, arg2, arg3 = bin.unpack('SSIsSLLL', response)
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
command.arg1 = command.arg1 + ISO14A_COMMAND.ISO14A_NO_RATS
end
local result,err = command:sendMIX()
if result then
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';
}
// ltrim
size_t off=0;
size_t off = 0;
while ((cmd[off] != '\0') && isspace(cmd[off]))
off++;
for (size_t i=0; i < strlen(cmd) - off; i++)
cmd[i] = cmd[i+off];
for (size_t i = 0; i < strlen(cmd) - off; i++)
cmd[i] = cmd[i + off];
cmd[strlen(cmd) - off] = '\0';
if (cmd[0] != '\0') {

View file

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

View file

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

View file

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

View file

@ -63,7 +63,7 @@ local function getblockdata(response)
if not response then
return nil, 'No response from device'
end
local count, cmd, arg0 = bin.unpack('LL', response)
if arg0 == 1 then
local count, arg1, arg2, data = bin.unpack('LLH511', response, count)
@ -81,7 +81,7 @@ local function readblock( blocknum, keyA )
return b
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 )
-- Read block N
local CSETBLOCK_SINGLE_OPERATION = 0x1F

View file

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

View file

@ -242,7 +242,7 @@ local function LoadEmulator(uid, blocks)
blockdata = AddKey(keys, _, blockdata)
end
end
io.write( _..',')
io.flush()
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 = [[
-- default
script run ufodump
-- stop at block 10
script run ufodump -b 10
]]
@ -48,7 +48,7 @@ end
local function oops(err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
return nil, err
end
---
-- Usage help
@ -59,7 +59,7 @@ local function help()
print(desc)
print('Example usage')
print(example)
print(usage)
print(usage)
end
--
-- writes data to ascii textfile.
@ -122,7 +122,7 @@ function sendRaw(rawdata, options)
-- of the ASCII-string rawdata
arg2 = string.len(rawdata)/2,
data = rawdata}
return command:sendMIX(options.ignore_response)
end
--

View file

@ -57,7 +57,7 @@ local function help()
print(desc)
print('Example usage')
print(example)
print(usage)
print(usage)
end
--
--- 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) {
size_t ls = strlen(s);
size_t lsuffix = strlen(suffix);
if (ls >= lsuffix)
{
if (ls >= lsuffix) {
return strncmp(suffix, s + (ls - lsuffix), lsuffix) == 0;
}
return false;