2016-02-28 14:50:49 +01:00
local utils = require ( 'utils' )
local getopt = require ( 'getopt' )
2020-04-05 12:28:49 +02:00
local ansicolors = require ( 'ansicolors' )
2019-05-07 23:53:06 +02:00
-- this script writes bytes 8 to 256 on the Legic MIM256
copyright = ''
author = 'Mosci'
2020-04-05 12:28:49 +02:00
version = 'v1.0.2'
2019-05-07 23:53:06 +02:00
desc =
[[
This is a script which writes value 0x01 to bytes from position 0x07 until 0xFF on a Legic Prime Tag (MIM256 or MIM1024) -- (created with 'hf legic save my_dump.hex') --
]]
example = [[
2020-09-23 01:35:27 +02:00
script run hf_legic_buffer2card
2019-05-07 23:53:06 +02:00
]]
usage = [[
2020-09-23 01:35:27 +02:00
script run hf_legic_buffer2card -h
2020-04-05 12:28:49 +02:00
]]
arguments = [[
2019-05-07 23:53:06 +02:00
-h - Help text
]]
2019-03-09 10:34:43 +01:00
---
2016-02-28 14:50:49 +01:00
-- This is only meant to be used when errors occur
2019-05-07 23:53:06 +02:00
local function oops ( err )
print ( 'ERROR:' , err )
core.clearCommandBuffer ()
2019-03-09 10:34:43 +01:00
return nil , err
2019-05-07 23:53:06 +02:00
end
2019-03-09 10:34:43 +01:00
---
2016-02-28 14:50:49 +01:00
-- Usage help
2019-05-07 23:53:06 +02:00
local function help ()
print ( copyright )
print ( author )
print ( version )
2019-03-09 10:34:43 +01:00
print ( desc )
2020-04-05 12:28:49 +02:00
print ( ansicolors.cyan .. 'Usage' .. ansicolors.reset )
2019-05-07 23:53:06 +02:00
print ( usage )
2020-04-05 12:28:49 +02:00
print ( ansicolors.cyan .. 'Arguments' .. ansicolors.reset )
print ( arguments )
print ( ansicolors.cyan .. 'Example usage' .. ansicolors.reset )
print ( example )
2016-02-28 14:50:49 +01:00
end
--
-- simple loop-write from 0x07 to 0xff
function main ()
2019-03-09 10:34:43 +01:00
-- parse arguments for the script
for o , a in getopt.getopt ( args , 'h' ) do
2019-05-07 23:53:06 +02:00
if o == 'h' then return help () end
2019-03-09 10:34:43 +01:00
end
2016-02-28 14:50:49 +01:00
2019-03-09 10:34:43 +01:00
local cmd = ''
local i
for i = 7 , 255 do
2019-05-07 23:53:06 +02:00
cmd = ( 'hf legic write o %02x d 01' ): format ( i )
2019-03-09 10:34:43 +01:00
print ( cmd )
core.clearCommandBuffer ()
core.console ( cmd )
-- got a 'cmd-buffer overflow' on my mac - so just wait a little
-- works without that pause on my linux-box
utils.Sleep ( 0.1 )
end
2016-02-28 14:50:49 +01:00
end
main ()