This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Goof's profile picture

[Prevent opening / modifying a file] [NOT solved.]

Started by Goof, 19 December 2012 - 09:09 AM
Goof #1
Posted 19 December 2012 - 10:09 AM
Hey i am figuring out how to lock specific files…

.. Well… now.. when running my startup script which turns the fs.isLocked to true then
when i try to edit a .@main@./uninstall then it says
Acces denied.. (Thats good.)
but… now it seems like it is still waiting for something, because when i type in "ls" (which is NOT locked) then it says:
File not found…


I have edited this code Thousands of times now, but still not working correct… can anyone explain me , why it says file not found?
This is the last edited code, so you can take this, and then tell me why and what to edit/modify…


code for the locker…
Spoiler


local attop = 0
local atdel = 0


local oldFsOpen = fs.open
local tArgs = {...}
fs.open = function(...)
tArgs = {...}
local lockFiles = {
"startup", "/startup", ".@main@.", "/.@main@.", ".@main@./Config.cfg", "/.@main@./Config.cfg", "/.@main@./doesNotRun.update", ".@main@./doesNotRun.update", "/.@main@./passwordSys", ".@main@./passwordSys", "/.@main@./Uninstall", ".@main@./Uninstall", "/.@main@./update", ".@main@./update", "/.@main@./version.ver", ".@main@./version.ver", "/.@main@./animations", ".@main@./animations", ".@main@./animations/LockTF", "/.@main@./animations/LockTF", ".@main@./animations/Uninstall", ".@main@./animations/Uninstall", ".@main@./Lock.op", "/.@main@./Lock.op", "/.@main@./animations/download", ".@main@./animations/download"
}
-- if fs.isLocked is false, allow ANY file
if not fs.isLocked then
return oldFsOpen(unpack(tArgs))
end
for j = 1, #lockFiles do
if string.lower(tArgs[1]) == string.lower(lockFiles[j]) then
error("Access denied! \n\[err.Num:1:\]", 3)
else
attop = attop + 1
end
end
if attop == tonumber(#lockFiles) then
attop = 0
return oldFsOpen(unpack(tArgs))
end
end

local oldFsDelete = fs.delete
local tArgs1 = {...}
fs.delete = function(...)
tArgs = {...}
local lockFiles = {
"startup", "/startup", ".@main@.", "/.@main@.", ".@main@./Config.cfg", "/.@main@./Config.cfg", "/.@main@./doesNotRun.update", ".@main@./doesNotRun.update", "/.@main@./passwordSys", ".@main@./passwordSys", "/.@main@./Uninstall", ".@main@./Uninstall", "/.@main@./update", ".@main@./update", "/.@main@./version.ver", ".@main@./version.ver", "/.@main@./animations", ".@main@./animations", ".@main@./animations/LockTF", "/.@main@./animations/LockTF", ".@main@./animations/Uninstall", ".@main@./animations/Uninstall", ".@main@./Lock.op", "/.@main@./Lock.op", "/.@main@./animations/download", ".@main@./animations/download"
}
-- if fs.isLocked is false, allow ANY file
if not fs.isLocked then
return oldFsDelete(unpack(tArgs1))
end
for j = 1, #lockFiles do
if string.lower(tArgs1[1]) == string.lower(lockFiles[j]) then
error("Access denied! \n\[err.Num:2:\]", 3)
else
atdel = atdel + 1
end
end
if atdel == tonumber(#lockFiles) then
atdel = 0
return oldFsDelete(unpack(tArgs1))
end
end


code for the startup file, which runs the locker, and then locks the files.
Spoiler



	   if fs.exists(".@main@./lock.op") then
		shell.run(".@main@./lock.op")
		fs.isLocked = true
		end






THANKS in advance…
Doyle3694 #2
Posted 19 December 2012 - 10:21 AM
2 things: you have locals there, which makes the "oldFsOpen" zoomed into only that function. second, you're overwriting that variable in the start.
remiX #3
Posted 19 December 2012 - 10:23 AM
Even though you said ignore all the if tArgs[1] etc but do this to shorten it:

for i = 1, 27 do
    if tArgs[1] == lockFiles[i] then
        error("Access denied!\[er.num:4:\]", 3)
        term.clear()
    else
        return oldFsOpen(unpack(tArgs))
    end
end
Doyle3694 #4
Posted 19 December 2012 - 10:25 AM
and also, instead of that looooooooooooooooooooooooooooooooooooong line;

for i = 1,27 do
   if tArgs[1] = lockFiles[i] then
	 error("Access denied!\[er.num:4:\]", 3)
   end
end
return oldFsOpen(unpack(tArgs))


Doyle3694 #5
Posted 19 December 2012 - 10:27 AM
remiX, since you have a return directly after the check, it will actually only run 1 loop, because the return exits the function, so it would only check in lockFiles[1]
remiX #6
Posted 19 December 2012 - 10:42 AM
remiX, since you have a return directly after the check, it will actually only run 1 loop, because the return exits the function, so it would only check in lockFiles[1]

Yeah I didn't really look through the rest of the function, just wanted to show him that he can use a for loop instead of a long line
Doyle3694 #7
Posted 19 December 2012 - 10:50 AM
oh yeah ;)/> Got ya ;)/>
Goof #8
Posted 19 December 2012 - 11:07 AM
well.. my code is:
(i didnt edit the if tArgs, yet… i will maybe do that later…)




local linktoAdvUninstall = "pastebin get a1b6TrrK Uninstall"
local termX, termY = term.getSize()
function cPrint(text, yPos)
if yPos then
term.setCursorPos(1, yPos)
end
term.setCursorPos(math.ceil((termX / 2) - (text:len() / 2)), yPos)
print(text)
end

local oldFsOpen = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"/.@main@./Uninstall",
".@main@./Uninstall"
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldFsOpen(unpack(tArgs))
end
end

if fs.exists(".@main@./Uninstall") then
shell.run(".@main@./Uninstall")
else
print("You Cannot Uninstall, because the uninstaller does not exists.",
"to uninstall on a more advanced way, type in \""..linktoAdvUninstall.."\"")
local file_error = "uninstall"
local error_report = "AdvLock has found a problem, that could not be solved, automatically! \n\nStart of report: \n\nat AdvLock_/.@main@./ the base directory does have the problem in \".@main@./"..file_error.."\""
term.clear()
term.setCursorPos(1,1)

print("\nYou Cannot Uninstall, because the uninstaller does not exists. to uninstall, again, type in \"Y\" or \"N\"")
write("Y or N : ")
input = string.lower(read())
if input == "y" then
print("Downloading...")
resp = shell.run(linktoAdvUninstall)
term.clear()
term.setCursorPos(1,1)
if resp then
print("Type in Uninstall")
else
if not http then
print("enable HTTP!")
else
term.clear()
term.setCursorPos(1,1)
print("\nERROR!!! please contact \"mikk809h\" to show him this bug: (take screenshot and upload to the forum)")
cPrint("AdvLock has crashed!\n\n", 5)
print(error_report)

end
end
end
end

local oldFsOpen1 = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"/.@main@./Uninstall",
".@main@./Uninstall"
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:4:\]", 3)
term.clear()
else
return oldFsOpen1(unpack(tArgs))
end
end


but when i type in "uninstall" then nothing happens.. and. if i type in anything ,,, then it just says File not found..


What?

Thanks:D
remiX #9
Posted 19 December 2012 - 11:47 AM
Where's the part for when you type in 'uninstall'? Or is the the Y/N part?

Edit: Oh it's in the other pastebin program…
Goof #10
Posted 19 December 2012 - 08:03 PM
well.. i still dont know why? the local-based stuff, in the lockFiles, should only be local, in the function. and when i run "uninstall" shortcut, then
it Acces Denied… (because the startup program locks it.)

i know you really want my full code, but i CANT do that. because last time i did that, i saw someone who stole it, and told everyone, it was himself, that did made it..
so i can only post some parts:

startup:
Spoiler


function hideLS()
if not fs.hide then
local ls=fs.list
local tHidden={}
fs.list=function(...)
local results=ls(...)
for k,v in ipairs(results) do
if tHidden[shell.resolve(v)]==true then
table.remove(results,k)
end
end
return results
end
rawset(fs, 'hide', function(dir)
if fs.exists(dir) then
tHidden[shell.resolve(dir)]=true
return true
else
return false
end
end)
end
fs.hide(".@Main@.")
fs.hide("startup")
end

function sEdit()
oldFsOpen = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys",
".@main@./passwordSys",
".@main@./version.ver",
"/.@main@./version.ver",
".@main@./Uninstall",
"/.@main@./Uninstall",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF",
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:1:\]", 3)
term.clear()
else
return oldFsOpen(unpack(tArgs))
end
end
local oldDelete = fs.delete
fs.delete = function(...)
local tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys",
".@main@./passwordSys",
".@main@./version.ver",
"/.@main@./version.ver",
".@main@./Uninstall",
"/.@main@./Uninstall",
"pass",
"/pass",
"update",
"/update",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF",
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:2:\]", 2)
term.clear()
else
return oldDelete(unpack(tArgs))
end
end

end

clear(1,1)

if not http then
print("HttpAPI, must be enabled, if you want to update...")
sleep(4)
else
if fs.exists(".@main@./update") then
shell.run(".@main@./update")
elseif fs.exists("update") then
shell.run("update")
else
print("Cant find \"updater\"")
sleep(0.5)
end
end

hideLS()

_tLoad()

_sPass()

sEdit()

Uninstall-shortcut
Spoiler


local linktoAdvUninstall = "pastebin get a1b6TrrK Uninstall"
local termX, termY = term.getSize()
function cPrint(text, yPos)
if yPos then
term.setCursorPos(1, yPos)
end
term.setCursorPos(math.ceil((termX / 2) - (text:len() / 2)), yPos)
print(text)
end

local oldFsOpen = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"/.@main@./Uninstall",
".@main@./Uninstall"
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldFsOpen(unpack(tArgs))
end
end

if fs.exists(".@main@./Uninstall") then
shell.run(".@main@./Uninstall")
else
print("You Cannot Uninstall, because the uninstaller does not exists.",
"to uninstall on a more advanced way, type in \""..linktoAdvUninstall.."\"")
local file_error = "uninstall"
local error_report = "AdvLock has found a problem, that could not be solved, automatically! \n\nStart of report: \n\nat AdvLock_/.@main@./ the base directory does have the problem in \".@main@./"..file_error.."\""
term.clear()
term.setCursorPos(1,1)

print("\nYou Cannot Uninstall, because the uninstaller does not exists. to uninstall, again, type in \"Y\" or \"N\"")
write("Y or N : ")
input = string.lower(read())
if input == "y" then
print("Downloading...")
resp = shell.run(linktoAdvUninstall)
term.clear()
term.setCursorPos(1,1)
if resp then
print("Type in Uninstall")
else
if not http then
print("enable HTTP!")
else
term.clear()
term.setCursorPos(1,1)
print("\nERROR!!! please contact \"mikk809h\" to show him this bug: (take screenshot and upload to the forum)")
cPrint("AdvLock has crashed!\n\n", 5)
print(error_report)

end
end
end
end

local oldFsOpen1 = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"/.@main@./Uninstall",
".@main@./Uninstall"
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:4:\]", 3)
term.clear()
else
return oldFsOpen1(unpack(tArgs))
end
end


and the Uninstaller(not the shortcut)
Spoiler


local loadCfg = false
function clear()
term.clear()
term.setCursorPos(1,1)
end

function lock()
oldFsOpen = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"/.@main@./Config.cfg",
".@main@./Config.cfg"
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldFsOpen(unpack(tArgs))
end
end
end

function ask()
oldDog = os.pullEvent
os.pullEvent = os.pullEventRaw

tCfg = fs.open(".@main@./Config.cfg", "r")
Pass = tCfg.readLine()
if tCfg then
loadCfg = true
else
loadCfg = false
end

tCfg.close()
tVer = fs.open(".@main@./version.ver", "r")
ver = tVer.readLine()
tVer.close()

print("Are you sure you want to uninstall AdvLock v "..ver.." ?")
write("Y / N ? > ")

UnIn = read()
if UnIn == "Y" or UnIn == "y" then
if loadCfg then
print("This requirres a Password...")
write(" Password > ")
PassUn = read("#")
if PassUn == Pass then
term.clear()
term.setCursorPos(1,1)
shell.run(".@main@./animations/LockTF true")
print("Uninstalling AdvLock...")
sleep(1)
if fs.exists(".@main@./animations/Uninstall") then
shell.run(".@main@./animations/Uninstall")
else
print("I cant find my Uninstaller... please contact Forums...")
end
else
term.clear()
term.setCursorPos(1,1)
shell.run(".@main@./animations/LockTF false")
end
end
elseif UnIn == "N" or UnIn == "n" then
print("Okay. you will be safe:D")
sleep(2)
else
print("Wrong input ? ")
sleep(2)
end
os.pullEvent = oldDog
end

function Lock1()
oldFsOpen = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"/.@main@./Config.cfg",
".@main@./Config.cfg"
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:4:\]", 3)
term.clear()
else
return oldFsOpen(unpack(tArgs))
end
end
end
Lock()
ask()
Lock1()
PLEASE NOTE, that you may NOT copy/edit this into your own OS'es, or programs! if you do then (you are bad)
thanks.

Well… i hope you can see the problem now, in my code..

-Thanks in advance
immibis #11
Posted 19 December 2012 - 08:13 PM
For one thing, I think it works with duplicated slashes. I could open //.@main@./Uninstall and get your uninstall program (can't test it right now though).

You need to remember that every time you override fs.open you could be overriding a previous override.
For example:
1. Startup runs, and overrides fs.open only unlocked filenames get through.
2. Uninstall shortcut runs, and overrides fs.open so only locked filenames get through.

Result: You can't open any files, because locked ones are caught by startup's override (throwing an error) and unlocked ones are caught by the uninstall shortcut's override (which acts like they don't exist)

Your uninstall shortcut's override doesn't return anything for unlocked files, which is what normally happens when a file doesn't exist. It sounds like that's a bug.

If you want to be able to bypass the first override (the one set in startup) then you'll need to make a way to tell it to stop blocking locked files.
Goof #12
Posted 19 December 2012 - 08:26 PM
you cant open with double slashes, (i have tested)..



and i want to bypass.. but if i should … hey wait a min… i could make a ´file called "Lock.op" then when i run it i need a argument, which would be True, or False.. if true then it will Lock ALL the files in the Lock program, and if False, then the opposite.. am i right on this?

i will try to make that, and then post back if worked, or not.



Thanks..
Goof #13
Posted 19 December 2012 - 08:33 PM
Well.. now i've made this file: (called "lock.op") i hope this would work
EDIT2: edited to newer code. but when i run ".@main@./lock.op false" and then run anything it just diplays Acces denied, press any key to continue…


Spoiler



function Lock()
oldFsOpen = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver",
".@main@./Uninstall", 
"/.@main@./Uninstall",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:1:\]", 3)
else
return oldFsOpen(unpack(tArgs))
end
end


oldDelete = fs.delete
fs.delete = function(...)
local tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver", 
".@main@./Uninstall", 
"/.@main@./Uninstall",
"pass", 
"/pass",
"update", 
"/update",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:2:\]", 2)
term.clear()
else
return oldDelete(unpack(tArgs))
end
end 

end

function unLock()
oldFsOpens = fs.open
fs.open = function(...)
local tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver",
".@main@./Uninstall", 
"/.@main@./Uninstall",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldFsOpens(unpack(tArgs))
else
error("Access denied!\[er.num:1:\]", 3)
end
end


olddDelete = fs.delete
fs.delete = function(...)
local tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver", 
".@main@./Uninstall", 
"/.@main@./Uninstall",
"pass", 
"/pass",
"update", 
"/update",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:2:\]", 2)
term.clear()
else
return olddDelete(unpack(tArgs))
end
end 

end

tArgsI = {...}
if tArgsI == nil then
error("i need 1 parametre")
else
if tArgsI[1] == "true" then
Lock()
elseif tArgsI[1] == "false" then
unLock()
end
end





am i right on this code? (just so i can be sure, not to edit everything, if i dont have to…)


EDIT: Well. in CCEMU it works, when locking… but now i cant unlock files? :o/> ehhm?

thanks :D/>
immibis #14
Posted 19 December 2012 - 08:50 PM
Well, first the tArgs needs to be outside the function, or it will get the arguments to the function instead of the arguments to the program.
Second, each time you run Lock.op it still just adds another layer. You need to override the function once and make the override check something else (for example fs.isLocked, then you can set that to true or false)
Goof #15
Posted 19 December 2012 - 08:59 PM
Well..right now im totally lost…. well..
my tArgs inside the function is now outside. ( at the top )

should i then make a new

local tArgs = {...}
local oldFsLock = fs.open
fs.isLocked = function(...) -- now i dont know what i should do...


my code right now is:
Spoiler


local tArgs = {...}

function Lock()
oldFsOpen = fs.open
fs.open = function(...)
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys",
".@main@./passwordSys",
".@main@./version.ver",
"/.@main@./version.ver",
".@main@./Uninstall",
"/.@main@./Uninstall",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF",
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:1:\]", 3)
else
return oldFsOpen(unpack(tArgs))
end
end


oldDelete = fs.delete
fs.delete = function(...)
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys",
".@main@./passwordSys",
".@main@./version.ver",
"/.@main@./version.ver",
".@main@./Uninstall",
"/.@main@./Uninstall",
"pass",
"/pass",
"update",
"/update",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF",
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:2:\]", 2)
term.clear()
else
return oldDelete(unpack(tArgs))
end
end

end

function unLock()
oldFsOpen = fs.open
fs.open = function(...)
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys",
".@main@./passwordSys",
".@main@./version.ver",
"/.@main@./version.ver",
".@main@./Uninstall",
"/.@main@./Uninstall",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF",
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldFsOpen(unpack(tArgs))
else
return oldFsOpen(unpack(tArgs))
end
end


oldDelete = fs.delete
fs.delete = function(...)
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys",
".@main@./passwordSys",
".@main@./version.ver",
"/.@main@./version.ver",
".@main@./Uninstall",
"/.@main@./Uninstall",
"pass",
"/pass",
"update",
"/update",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF",
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldDelete(unpack(tArgs))
else
return oldDelete(unpack(tArgs))
end
end

end

tArgsI = {...}
if tArgsI == nil then
error("i need 1 parametre")
else
if tArgsI[1] == "true" then
Lock()
elseif tArgsI[1] == "false" then
unLock()
end
end
edit: i edited the same code, but now it works fine…
i type in.
>.@main@./Lock.op true
> edit startup
Bios:358: Acces denied![er.num1]
> .@main@./Lock.op false
> edit startup – now when i run this… the screen turns off, ( i could not see any errors, because it was turning off to quick, after showing error.. (IF it was an error))

Spoiler


local tArgs = {}

function Lock()
oldFsOpen = fs.open
fs.open = function(...)
tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver",
".@main@./Uninstall", 
"/.@main@./Uninstall",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:1:\]", 3)
else
return oldFsOpen(unpack(tArgs))
end
end


oldDelete = fs.delete
fs.delete = function(...)
tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver", 
".@main@./Uninstall", 
"/.@main@./Uninstall",
"pass", 
"/pass",
"update", 
"/update",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:2:\]", 2)
term.clear()
else
return oldDelete(unpack(tArgs))
end
end 

end

function unLock()
oldFsOpen = fs.open
fs.open = function(...)
tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver",
".@main@./Uninstall", 
"/.@main@./Uninstall",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldFsOpen(unpack(tArgs))
else
return oldFsOpen(unpack(tArgs))
end
end


oldDelete = fs.delete
fs.delete = function(...)
tArgs = {...}
local lockFiles = {
"startup",
"/startup",
"/.@main@./config.cfg",
".@main@./config.cfg",
"/.@main@./passwordSys", 
".@main@./passwordSys", 
".@main@./version.ver", 
"/.@main@./version.ver", 
".@main@./Uninstall", 
"/.@main@./Uninstall",
"pass", 
"/pass",
"update", 
"/update",
".@main@./update",
"/.@main@./update",
".@main@./animations/LockTF",
"/.@main@./animations/LockTF", 
".@main@./animations/Uninstall",
"/.@main@./animations/Uninstall",
".@main@./animations/download",
"/.@main@./animations/download",
"/.@main@.",
".@main@."
}

if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
return oldDelete(unpack(tArgs))
else
return oldDelete(unpack(tArgs))
end
end 

end

tArgsI = {...}
if tArgsI == nil then
error("i need 1 parametre")
else
if tArgsI[1] == "true" then
Lock()
elseif tArgsI[1] == "false" then
unLock()
end
end

i know you should not make the code for me, but can you give a little example on the fs.isLocked? i dont know where to start..

Thanks :)/>
immibis #16
Posted 19 December 2012 - 09:42 PM
Oops, forget the tArgs bit. I misread your code and thought tArgs was trying to do what tArgsI does.

What I mean by using a variable like fs.isLocked:
Run this once:

local oldFsOpen = fs.open
fs.open = function(...)
local lockFiles = {
<list of locked files here>
}
-- if fs.isLocked is false, allow ANY file
if not fs.isLocked then
return oldFsOpen(unpack(tArgs))
end
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied!\[er.num:1:\]", 3)
else
return oldFsOpen(unpack(tArgs))
end
end

fs.isLocked = true

To lock:

fs.isLocked = true

To unlock:

fs.isLocked = false

This works because there's only one override. The problem you have before is that every time you override a function that way, it gets "layered" on top of any previous ones and doesn't know about the real fs.open, and so the previous overrides are still there.
bjaorndvinCoder #17
Posted 19 December 2012 - 10:06 PM
Wrong section, sry!
Goof #18
Posted 19 December 2012 - 10:10 PM
Well. Immibis. I will try that ASAP
thank you :D/>
Goof #19
Posted 20 December 2012 - 07:51 AM
Thank you Immibis! That worked out fine (Sry for late answer but i couldnt test, before now. )

Keep working :D/>

to admins… could this topic be deleted, since it contains some codes that noone else, may see.. (its used in AdvLock which may not be seen, so hackers cant kill the program)…
Lyqyd #20
Posted 20 December 2012 - 08:18 AM
There's nothing you can do to prevent the code getting into their hands if you use it at all, anywhere, ever, so the only thing deleting the topic would do is prevent other people from being able to find the answer if they have a similar question.
Goof #21
Posted 20 December 2012 - 10:09 AM
yeah.. but. may i then edit the codes, for the parts, they may NOT see?
and, immibis?

on that code… can i then do it, so only if you type in "EDIT test" it will prevent.. but then if you just type in "test" then it wont prevent that… i somehow know that i think that it is the fs.isReadOnly() but not sure….


local oldFsOpen = fs.open
local tArgs = {...}
fs.open = function(...)
tArgs = {...}
local lockFiles = {
"test",
"/test"
}
-- if fs.isLocked is false, allow ANY file
if not fs.isLocked then
return oldFsOpen(unpack(tArgs))
end
if tArgs[1] == lockFiles[1] or tArgs[1] == lockFiles[2] or tArgs[1] == lockFiles[3] or tArgs[1] == lockFiles[4] or tArgs[1] == lockFiles[5] or tArgs[1] == lockFiles[6] or tArgs[1] == lockFiles[7] or tArgs[1] == lockFiles[8] or tArgs[1] == lockFiles[9] or tArgs[1] == lockFiles[10] or tArgs[1] == lockFiles[11] or tArgs[1] == lockFiles[12] or tArgs[1] == lockFiles[13] or tArgs[1] == lockFiles[14] or tArgs[1] == lockFiles[15] or tArgs[1] == lockFiles[16] or tArgs[1] == lockFiles[17] or tArgs[1] == lockFiles[18] or tArgs[1] == lockFiles[19] or tArgs[1] == lockFiles[20] or tArgs[1] == lockFiles[21] or tArgs[1] == lockFiles[22] or tArgs[1] == lockFiles[23] or tArgs[1] == lockFiles[24] or tArgs[1] == lockFiles[25] or tArgs[1] == lockFiles[26] or tArgs[1] == lockFiles[27] then
error("Access denied! \n\[err.Num:1:\]", 3)
else
return oldFsOpen(unpack(tArgs))
end
end

local oldDelete = fs.delete
local tArgs1 = {...}
fs.delete = function(...)
tArgs1 = {...}
local lockFiles = {
"test",
"/test"
}
-- if fs.isLocked is false, allow ANY file
if not fs.isLocked then
return oldDelete(unpack(tArgs1))
end
if tArgs1[1] == lockFiles[1] or tArgs1[1] == lockFiles[2] or tArgs1[1] == lockFiles[3] or tArgs1[1] == lockFiles[4] or tArgs1[1] == lockFiles[5] or tArgs1[1] == lockFiles[6] or tArgs1[1] == lockFiles[7] or tArgs1[1] == lockFiles[8] or tArgs1[1] == lockFiles[9] or tArgs1[1] == lockFiles[10] or tArgs1[1] == lockFiles[11] or tArgs1[1] == lockFiles[12] or tArgs1[1] == lockFiles[13] or tArgs1[1] == lockFiles[14] or tArgs1[1] == lockFiles[15] or tArgs1[1] == lockFiles[16] or tArgs1[1] == lockFiles[17] or tArgs1[1] == lockFiles[18] or tArgs1[1] == lockFiles[19] or tArgs1[1] == lockFiles[20] or tArgs1[1] == lockFiles[21] or tArgs1[1] == lockFiles[22] or tArgs1[1] == lockFiles[23] or tArgs1[1] == lockFiles[24] or tArgs1[1] == lockFiles[25] or tArgs1[1] == lockFiles[26] or tArgs1[1] == lockFiles[27] then
error("Access denied! \n\[err.Num:1:\]", 2)
else
return oldDelete(unpack(tArgs1))
end
end

tArgsI = {...}
if tArgsI == nil then
print("i need 1 parametre")
else
if tArgsI[1] == "true" then
fs.isLocked = true
elseif tArgsI[1] == "false" then
fs.isLocked = false
end
end

thanks :D/>
ChunLing #22
Posted 20 December 2012 - 07:09 PM
Really, you should just have a client program that receives the program over rednet (for security, you send a program that rewrites the startup as the current client, deletes everything else on the computer, reboots the computer, and then receives your super-secret program and runs it without ever storing it to disk…but even that can be beaten by a smart hacker).
Goof #23
Posted 20 December 2012 - 07:27 PM
Ehm. I actually dont know why you would receive the program over rednet.
But with this, i will just do it harder to hack/delete
ChunLing #24
Posted 20 December 2012 - 07:48 PM
So that the user doesn't have access to a computer that contains the program file, of course. If the program is stored on a file on the computer they can reach, they can place a drive with a steal-everything-on-the-computer startup floppy. Then they can dissect your secrets at their leisure.
Goof #25
Posted 21 December 2012 - 12:32 AM
yeah but how can I prevent that? well.. if i should make a client, then it would be easy just to delete that, and then put virusses into the computer… only if CC get the PREVENT disk boot, thing, into the CC mod, THEN i can prevent, that… else i cannot prevent anything that has any usage of a disk drive… :(/> (but it would be great if we would be able to prevent disk booting )

-thanks
theoriginalbit #26
Posted 21 December 2012 - 12:36 AM
So that the user doesn't have access to a computer that contains the program file, of course. If the program is stored on a file on the computer they can reach, they can place a drive with a steal-everything-on-the-computer startup floppy. Then they can dissect your secrets at their leisure.


Or better yet, they come here to the forum and download his code and read it. done. no writing of programs, just download and open.
ChunLing #27
Posted 21 December 2012 - 01:41 AM
Like I said, you prevent (or at least deter it) by not having anything stored on the computer they can access except for the client that downloads the program over rednet and runs it using loadstring rather than having it as a file on the computer. Then you use a two step download, the first rewrites the client to be the correct version, the second is the actual program you're trying to keep secret.

You can make it difficult enough to hack so that anyone able to hack it probably already has samples of the code you're trying to protect. Which is to say, as difficult to hack as there is any point making it.

Probably more so, really.
Goof #28
Posted 21 December 2012 - 07:53 AM
Well.. i just found a fail/bug when i tried to edit something in a dir. and then i CAN do it… but i told "lock.op" to lock .@main@./uninstall but it doesnt…

Spoiler

	 
	 
	local oldFsOpen = fs.open
	local tArgs = {...}
	fs.open = function(...)
	tArgs = {...}
	local lockFiles = {
	"startup", "/startup", ".@main@.", "/.@main@.", ".@main@./Config.cfg", "/.@main@./Config.cfg", "/.@main@./doesNotRun.update", ".@main@./doesNotRun.update", "/.@main@./passwordSys", ".@main@./passwordSys", "/.@main@./Uninstall", ".@main@./Uninstall", "/.@main@./update", ".@main@./update", "/.@main@./version.ver", ".@main@./version.ver", "/.@main@./animations", ".@main@./animations", ".@main@./animations/LockTF", "/.@main@./animations/LockTF", ".@main@./animations/Uninstall", ".@main@./animations/Uninstall", ".@main@./Lock.op", "/.@main@./Lock.op", "/.@main@./animations/download", ".@main@./animations/download"
	}
	-- if fs.isLocked is false, allow ANY file
	if not fs.isLocked then
	return oldFsOpen(unpack(tArgs))
	end
	for j = 1, #lockFiles do
	if tArgs[1] == lockFiles[j] then
	error("Access denied! \n\[err.Num:1:\]", 3)
	else
	return oldFsOpen(unpack(tArgs))
	end
	end
	end
	 
	local oldDelete = fs.delete
	local tArgs1 = {...}
	fs.delete = function(...)
	tArgs1 = {...}
	local lockFiles = {
	"startup", "/startup", ".@main@.", "/.@main@.", ".@main@./Config.cfg", "/.@main@./Config.cfg", "/.@main@./doesNotRun.update", ".@main@./doesNotRun.update", "/.@main@./passwordSys", ".@main@./passwordSys", "/.@main@./Uninstall", ".@main@./Uninstall", "/.@main@./update", ".@main@./update", "/.@main@./version.ver", ".@main@./version.ver", "/.@main@./animations", ".@main@./animations", ".@main@./animations/LockTF", "/.@main@./animations/LockTF", ".@main@./animations/Uninstall", ".@main@./animations/Uninstall", ".@main@./Lock.op", "/.@main@./Lock.op", "/.@main@./animations/download", ".@main@./animations/download"
	}
	-- if fs.isLocked is false, allow ANY file
	if not fs.isLocked then
	return oldDelete(unpack(tArgs1))
	end
	for i = 1, #lockFiles do
	if tArgs1[1] == lockFiles[i] then
	error("Access denied! \n\[err.Num:1:\]", 2)
	else
	return oldDelete(unpack(tArgs1))
	end
	end
	end
	 
	

and in startup i run this:


	if fs.exists(".@main@./lock.op") then
	shell.run(".@main@./lock.op")
	fs.isLocked = true
	end
	


but when i did that, i can still edit / delete programs in the dir .@main@.

-thanks
Goof #29
Posted 23 December 2012 - 02:25 AM
well. i still didnt get any answer on that ? i can still edit/delete anything in the .@main@./ … dir…

and i dont know why… did i miss something like an \ or / ???

Thanks :D/>
Goof #30
Posted 23 December 2012 - 08:51 AM
Now the newest code is on the Main post… please read that…
please help me out of this problem :(/>

(quick: when everything works fine, and i type in "edit .@main@./uninstall" it says Acces denied (which is good) but.. when i enter something else ( a program like "ls" or "list" or "dir") then it just say
File not Found..


Please help…
Thanks in advance