#!/usr/local/bin/lua51 ----------------------------------------------------------------------- -- Checking arguments ----------------------------------------------------------------------- progname = "mbrsign" if arg[1] == nil then print("usage: " .. progname .. " file") os.exit(1) end local function perror(msg) print(progname .. ": " .. msg) os.exit(1) end local file = io.open(arg[1], "rb") if file == nil then perror("failed to open file " .. arg[1]) end ----------------------------------------------------------------------- -- Check file size ----------------------------------------------------------------------- local size = file:seek("end") if size > 512 then perror("boot file " .. arg[1] .. " size is more than 512 bytes : " .. size .. " bytes") end file:close() ----------------------------------------------------------------------- -- Filling 0s ----------------------------------------------------------------------- file = io.open(arg[1], "r+") if file == nil then perror("faile to open file " .. arg[1] .. " for writting") end if size < 512 then file:seek("set", size) for i = size, 509 do file:write(string.char(0)) end end file:seek("set", 510) file:write(string.char("0x55")) file:write(string.char("0xaa")) file:close()