fileHandle = fs.open("derp","r")
contents = fileHandle.readAll()
fileHandle.close()
function newReadAll()
derpAround()
end
I want to make it so that calling fileHandle.readAll() will call newReadAll(). Is this possible?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Modifying file handle functions
Started by The Blue daNoob, 16 December 2012 - 02:09 PMPosted 16 December 2012 - 03:09 PM
For a security system, I am trying to replace the functions of file handles. e.g.
Posted 16 December 2012 - 03:12 PM
you could try this
but I'm not sure if you are allowed to override fs
fileHandle:readAll() = newReadAll()
but I'm not sure if you are allowed to override fs
Posted 16 December 2012 - 03:40 PM
Hold on… is fs just a wrapper to io? It seems like if it is, then that would be easier to modify, as it uses "proper" Lua OOP.
Posted 16 December 2012 - 03:49 PM
yes fs is an io wrapper.
Posted 16 December 2012 - 10:57 PM
yes fs is an io wrapper.
Nope. Reverse.
Posted 16 December 2012 - 11:15 PM
yes fs is an io wrapper.
Nope. Reverse.
really? ok
Posted 17 December 2012 - 02:29 AM
yes fs is an io wrapper.
Nope. Reverse.
I cant find any Lua documentation to confirm this.
Posted 17 December 2012 - 02:35 AM
fs and other APIS are built java-side, because CC's Lua runs on Java, so official Lua documentation won't talk about it. Regarding CC docs, since it is a mod for a game (e.g. not real work / releasing technical info might increase chances of hacking), most technical or more complicated aspects are left undocumented. But, hey, you can contribute for the wiki!Btw, when Cloudy is telling you something, you would better believe it.snip
Posted 17 December 2012 - 02:47 AM
as well as to successfully secure this you should not edit an existing file handle, you should edit the fs.open function and make it return your function in stead
oh and
local function myread()
--your code
end
local oldopen=fs.open
fs.open=function(...)
local temp=oldopen(...)
if temp.read then
temp.read=myread
end
end
oh and
you should not call the function you are modifying or replacing with. no brackets thereyou could try thisfileHandle:readAll() = newReadAll()
but I'm not sure if you are allowed to override fs
Posted 17 December 2012 - 03:18 AM
oh andyou should not call the function you are modifying or replacing with. no brackets thereyou could try thisfileHandle:readAll() = newReadAll()
but I'm not sure if you are allowed to override fs
yeh i realised my typo too late.
Posted 17 December 2012 - 07:44 AM
Well, here is the whole idea of modifying the file handles. I want to encode all data written, and decode all data read. This is not possible without modifying the functions called by file handles. Oh well, it was a good idea.
Posted 17 December 2012 - 11:11 AM
well. why cant there be an encode process then the encoded string parsed the the existing file handler?
and the same for decode, read data, use that data, decode with a function, done.
why do you have to modify the handles?
and the same for decode, read data, use that data, decode with a function, done.
why do you have to modify the handles?
Posted 20 December 2012 - 01:06 PM
This is for a secure operating system. The idea is that when programs are running in it, they write encoded data and decode data that is read. That way, if someone bypasses the operating system, then all they would get is meaningless gibberish.