Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pullArg()
- condition = read()
- prog = tonumber(string.sub(condition,1,string.find(condition,"%s")-1))
- type = string.sub(condition,string.find(condition,"%s")+1)
- if prog == 0 then
- return 0, "nil"
- end
- if not (type == "nil" or type == "bin" or type == "int" or type == "str" or prog == nil) then
- print("Invalid argument, format should be as follows:")
- print("\"<number> <type [nil,bin,int,str]>\"")
- print("input \"0 nil\" to exit")
- return pullArg()
- end
- return prog, type
- end
- local tArgs = { ... }
- if #tArgs<1 then
- print("No File")
- return
- end
- print("is " .. tArgs[1] .. " a File?")
- if not fs.exists(tArgs[1]) or (fs.exists(tArgs[1]) and fs.isDir(tArgs[1])) then
- print("Wrong File Bozo")
- return
- end
- print(fs.getName(tArgs[1]) .. " Exists!")
- bin = fs.open(tArgs[1],"rb").readAll()
- print(#bin .. "b")
- i=1
- while i < #bin do
- prog, type = pullArg()
- if prog == 0 then
- print("Reading cut short at byte "..i)
- return
- end
- buffer = nil
- if type =="bin" then
- for j=1,prog do
- buffer = buffer .. " " .. string.byte(bin,i+j-1)
- end
- print(buffer)
- elseif type =="int" then
- -- print(buffer)
- for j=1,prog do
- if buffer == nil then
- buffer = 0
- end
- buffer = string.byte(bin,i+j-1)*math.pow(16,2*(j-1)) + buffer
- end
- print(buffer)
- elseif type =="str" then
- for j=1,prog do
- if buffer == nil then
- buffer = ""
- end
- buffer = buffer .. "" .. string.char(string.byte(bin,i+j-1))
- end
- print(buffer)
- end
- i=i+prog
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement