Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reader = peripheral.wrap("left")
- if not reader then
- error("No card reader found!")
- end
- reader.cancelWrite()
- local cardBackup = "/card-data"
- local function readCard()
- reader.setInsertCardLight(true)
- while true do
- local e, data, side = os.pullEvent()
- if e == "mag_swipe" then
- reader.setInsertCardLight(false)
- return data
- end
- end
- end
- local function writeCard(data, label)
- local success, err = reader.beginWrite(data, label)
- if success then
- while true do
- local e = os.pullEvent()
- if e == "mag_write_done" then
- reader.cancelWrite()
- return
- end
- end
- else
- error("Error while writing card: "..err)
- end
- end
- local args = {...}
- local arg = args[1]
- if not fs.exists(cardBackup) then
- print("A backup of your card is required")
- term.setTextColor(colors.yellow)
- print("Please insert your mag-card")
- cardData = readCard()
- local f = io.open(cardBackup, "w")
- f:write(cardData)
- f:close()
- print("Card data saved!")
- end
- if arg == "backup" then
- if fs.exists(cardBackup) then
- if fs.exists(cardBackup.."-old") then
- fs.delete(cardBackup.."-old")
- end
- fs.move(cardBackup, cardBackup.."-old")
- end
- term.setTextColor(colors.yellow)
- print("Insert the card you wish to backup")
- cardData = readCard()
- local f = io.open(cardBackup, "w")
- f:write(cardData)
- f:close()
- print("Card data saved!")
- elseif arg == "pattern" then
- term.setTextColor(colors.yellow)
- print("Insert card to write")
- writeCard("[", "Pattern Exploit Card")
- term.setTextColor(colors.white)
- print("Card written!")
- elseif arg == "exists" then
- term.setTextColor(colors.yellow)
- print("Insert card to write")
- writeCard("../rom/programs/help", "Exists Exploit Card")
- term.setTextColor(colors.white)
- print("Card written!")
- elseif arg == "restore" then
- local readLocation = cardBackup
- if args[2] then
- readLocation = args[2]
- end
- if fs.exists(readLocation) and not fs.isDir(readLocation) then
- local f = io.open(readLocation)
- local cardData = f:read("*a")
- f:close()
- term.setTextColor(colors.yellow)
- print("Insert card to write")
- writeCard(cardData, "Restored Card")
- term.setTextColor(colors.white)
- print("Card written!")
- else
- print("No card data found!")
- end
- elseif arg == "overwrite" then
- term.setTextColor(colors.yellow)
- print("Enter data to write")
- write("> ")
- local data = read()
- print("Insert card to write")
- writeCard(data, "Overwritten Card")
- term.setTextColor(colors.white)
- print("Card written!")
- elseif arg == "read" then
- term.setTextColor(colors.yellow)
- print("Insert the card to read")
- local data = readCard()
- term.setTextColor(colors.white)
- print("The card reads:")
- print(data)
- elseif arg == "label" then
- term.setTextColor(colors.yellow)
- write("Enter a label: ")
- local label = read()
- print("Insert the card you want to label twice")
- cardData = readCard()
- print("And again")
- writeCard(cardData, label)
- term.setTextColor(colors.white)
- print("Done! The new label has been written")
- else
- term.setTextColor(colors.white)
- print("Run the program with an argument:")
- print("backup, pattern, exists, restore, overwrite, read")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement