This commit is contained in:
iceman1001 2019-05-18 17:55:11 +02:00
commit cba5d18124

View file

@ -10,18 +10,18 @@ local Emulator = {
} }
function Emulator:set_mem (data, clear_first) function Emulator:set_mem (data, clear_first)
if clear_first then if clear_first then
-- Clear out the emulator memory first -- Clear out the emulator memory first
local emuMemclearCmd = Command:new{cmd = cmds.CMD_MIFARE_EML_MEMCLR, arg1 = 0, arg2 = 0, arg3 = 0} local memclrCmd = Command:newMIX{cmd = cmds.CMD_MIFARE_EML_MEMCLR}
local _, err = reader.sendToDevice(emuMemclearCmd) local _, err = memclrCmd.sendMIX()
if err then if err then
print('Failed to clear emulator memory:', err) print('Failed to clear emulator memory:', err)
return false return false
else else
print('Cleared emulator memory') print('Cleared emulator memory')
end end
end end
-- Can fit 32 16 byte blocks per command (512 total bytes max) -- Can fit 32 16 byte blocks per command (512 total bytes max)
for i = 0, (data:len() / self.BLOCK_SZ) do for i = 0, (data:len() / self.BLOCK_SZ) do
@ -30,13 +30,13 @@ function Emulator:set_mem (data, clear_first)
-- arg1: start block number -- arg1: start block number
-- arg2: block count -- arg2: block count
local emuMemsetCmd = Command:new{cmd = cmds.CMD_MIFARE_EML_MEMSET, local memsetCmd = Command:newMIX{cmd = cmds.CMD_MIFARE_EML_MEMSET,
data = utils.hexlify(cur_out_block), data = utils.hexlify(cur_out_block),
arg1 = i * self.BLOCK_COUNT, arg1 = i * self.BLOCK_COUNT,
arg2 = self.BLOCK_COUNT} arg2 = self.BLOCK_COUNT}
-- Send command and wait for response -- Send command and wait for response
local _, err = reader.sendToDevice(emuMemsetCmd) local _, err = memsetCmd.sendMIX()
if err then if err then
print('Failed setting memory', err) print('Failed setting memory', err)
return false return false
@ -57,12 +57,12 @@ function Emulator:get_mem (size)
for i = 0, (size / (MAX_BLOCKS * 16)) do for i = 0, (size / (MAX_BLOCKS * 16)) do
-- arg1: start block number -- arg1: start block number
-- arg2: block count (max 4) -- arg2: block count (max 4)
local emuMemGetCmd = Command:new{cmd = cmds.CMD_MIFARE_EML_MEMGET, local getmemCmd = Command:newMIX{cmd = cmds.CMD_MIFARE_EML_MEMGET,
arg1 = i * MAX_BLOCKS, arg1 = i * MAX_BLOCKS,
arg2 = MAX_BLOCKS, arg2 = MAX_BLOCKS,
arg3 = 0} arg3 = 0}
local response, err = reader.sendToDevice(emuMemGetCmd) local response, err = getmemCmd.sendMIX()
if err then if err then
print('Failed getting memory:', err) print('Failed getting memory:', err)
return false return false