Posted 15 August 2015 - 12:52 AM
The following code is not working:
Expected Result: It should make the fs api be the vFs api, and backup the old fs api into oldFs. From there it creates a sandboxed environment. Then, it should make sure that the FS api is constantly the same as the vFs api to prevent modification (thus creating a permanently unlocked filesystem).
Actual Result: On ComputerCraft it crashes the computer after lagging for some time, in CCemuredux it crashes the java vm and gives me an out of bounds error and crashes all computers in that session.
Does anyone know what is causing this, and if so, how does one fix this?
Bootloader Script
local function customParse(parseString, parseCharacter)
local parseResults = {}
local stringCycle = ""
for i = 1, #parseString do
local c = parseString:sub(i,i)
if c == parseCharacter then
if stringCycle == "" then
else
table.insert(parseResults, stringCycle)
stringCycle = ""
end
else
stringCycle = stringCycle .. c
end
if i == #parseString and c ~= parseCharacter then
table.insert(parseResults, stringCycle)
stringCycle = ""
end
end
return parseResults
end
print("Unlocker Bootloader v0")
print("Created by cyanisaac")
-- fs.normalize function created by Lignum.
fs.normalise=function(a)if a==nil then error("path can't be nil",2)end;local b=a;if b~=nil then local c=true;if b==""then b="/"c=false end;if b=="/"or b=="\\"then b="/"c=false end;if c then b=b:gsub("\\","/")if b:sub(1,1)~="/"then b="/"..b end;if b:sub(#b,#B)/>=="/"then b=b:sub(1,#b-1)end end end;return b end;fs.normalize=fs.normalise
local safeNormalize = fs.normalize
fs.normalize = nil
fs.normalise = nil
local oldFs = fs
local vFs = oldFs -- This is changed for compatibility reasons, to keep the unlocker from being affected as a file.
local vDirectory = "/.vhdd"
-- Functions for virtual filesystem
local function resolvePath(path)
local path = safeNormalize(path)
local customParsedTable = customParse(path, "/")
if customParsedTable[1] == "rom" then
return path
else
return vDirectory .. path
end
end
function vFs.list(path)
return oldFs.list(resolvePath(path))
end
function vFs.exists(path)
return oldFs.exists(resolvePath(path))
end
function vFs.isDir(path)
return oldFs.isDir(resolvePath(path))
end
function vFs.isReadOnly(path)
return oldFs.isReadOnly(resolvePath(path))
end
function vFs.getName(path)
return oldFs.getName(resolvePath(path))
end
function vFs.getDrive(path)
return oldFs.getDrive(resolvePath(path))
end
function vFs.getSize(path)
return oldFs.getSize(resolvePath(path))
end
function vFs.getFreeSpace(path)
return oldFs.getFreeSpace(resolvePath(path))
end
function vFs.makeDir(path)
return oldFs.makeDir(resolvePath(path))
end
function vFs.move(toPath, fromPath)
return oldFs.move(resolvePath(fromPath), resolvePath(toPath))
end
function vFs.copy(toPath, fromPath)
return oldFs.copy(resolvePath(fromPath), resolvePath(toPath))
end
function vFs.delete(path)
return oldFs.delete(resolvePath(path))
end
vFs.combine = fs.combine
function vFs.open(path, mode)
return oldFs.open(resolvePath(path), mode)
end
function vFs.find(wildcard)
return oldFs.find(resolvePath(wildcard))
end
vFs.getDir = fs.getDir
function vFs.complete()
return "" --temporary until I can figure out how to get this to work well
end
-- Functions to unlock filesystem
local function mainProcess()
if oldFs.exists(vDirectory .. "/startup") then
shell.run("/startup")
end
shell.run("/rom/programs/shell")
end
local function restoreFs()
while true do
if fs ~= vFs then
fs = vFs
end
coroutine.yield()
end
end
parallel.waitForAny(restoreFs, mainProcess)
Expected Result: It should make the fs api be the vFs api, and backup the old fs api into oldFs. From there it creates a sandboxed environment. Then, it should make sure that the FS api is constantly the same as the vFs api to prevent modification (thus creating a permanently unlocked filesystem).
Actual Result: On ComputerCraft it crashes the computer after lagging for some time, in CCemuredux it crashes the java vm and gives me an out of bounds error and crashes all computers in that session.
Does anyone know what is causing this, and if so, how does one fix this?