Jump to content




making a program read-only


8 replies to this topic

#1 dan14941

  • Members
  • 45 posts

Posted 27 January 2013 - 01:46 PM

how to i make a program a read-only program so no one can modify it? would help allot

#2 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 27 January 2013 - 02:38 PM

There is no real way to make a file completely read only, and Cloudy has stated he will never add read only files to the mod. So it's not possible.

#3 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 27 January 2013 - 05:49 PM

Well, one way that you could go about making a file read only is by overwriting the global fs.open function to throw an error in the case that there is a call to get a handle on your file. However, this would only work if you had this code executing on startup and no one had a variable which was the old fs.open function value.

This is the code I'm talking about:

-- Making files almost entirely read only.
-- Place this as your startup program so the changes to the global
-- table will be made when the computer turns on.
-- NOTE: Other programs can also overwrite these changes if they have access to the memory locations where these
--       functions we are replacing exist.


local readOnlyPath     = "/myFile/"
local old_fsOpen       = _G["fs"]["open"]
local old_fsIsReadOnly = _G["fs"]["isReadOnly"]


_G["fs"]["open"] = function(path, mode)

    if shell.resolveProgram(path) ~= shell.resolveProgram(readOnlyPath) then
        return old_fsOpen(path, mode)
    elseif mode == 'w' then
        return nil
    else
        return old_fsOpen(path, 'r')
    end

end

_G["fs"]["isReadOnly"] = function(path)

    if shell.resolveProgram(path) ~= shell.resolveProgram(readOnlyPath) then
        return old_fsIsReadOnly(path)
    else
        return true
    end

end


#4 Zoinky

  • Members
  • 144 posts
  • LocationWellington, New Zealand

Posted 27 January 2013 - 06:37 PM

Well, if you're not on a server and you have windows it's pretty somewhat simple (If you know what you're doing).
Minecraft folder > saves > World > computer > computer id > program (Right click) > Properties > Attributes > Read-Only

Side note: I've never actually tried doing this. But I'm guessing it should work. Wouldn't hurt to try anyway.

#5 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 27 January 2013 - 06:39 PM

View PostZoinky, on 27 January 2013 - 06:37 PM, said:

Well, if you're not on a server and have windows it's pretty somewhat simple (If you know what you're doing).
Minecraft folder > saves > World > computer > computer id > program > Properties > Attributes > Read-Only

Side note: I've never actually tried doing this. But I'm guessing it should work. Wouldn't hurt to try anyway.
Nope. That will not work.

#6 Zoinky

  • Members
  • 144 posts
  • LocationWellington, New Zealand

Posted 27 January 2013 - 06:41 PM

View PostCranium, on 27 January 2013 - 06:39 PM, said:

View PostZoinky, on 27 January 2013 - 06:37 PM, said:

-snip-
Nope. That will not work.
Oh, okay. Never mind then :P

EDIT: Tested a bit with it on CCEmu, seems to have some odd behaviour. Images below.

Posted ImagePosted Image

Edited by Zoinky, 27 January 2013 - 07:01 PM.


#7 ChunLing

  • Members
  • 2,027 posts

Posted 28 January 2013 - 05:45 PM

Altering the fs API will work, but you also have to alter the io API, since that will be using the old fs.open (since it loaded before you changed it). As noted, any other rom\apis that use fs.open will also still be using the old versions.

It is really better to simply set up the server in a secure location and have it accessed only over rednet, so that you can fully control what actions are available.

#8 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 19 February 2013 - 07:53 AM

View PostChunLing, on 28 January 2013 - 05:45 PM, said:

Altering the fs API will work, but you also have to alter the io API, since that will be using the old fs.open (since it loaded before you changed it). As noted, any other rom\apis that use fs.open will also still be using the old versions.

It is really better to simply set up the server in a secure location and have it accessed only over rednet, so that you can fully control what actions are available.

Actually (sorry for bumping an old thread), the io API will be referencing the replaced fs API functions because we have changed them in _G table. I just tested this, but if you did the same and were able to get around it by simply using the io API, then I'd like to see.

#9 ChunLing

  • Members
  • 2,027 posts

Posted 19 February 2013 - 04:56 PM

Oh...I must have been thinking that the io API created a new reference for fs.open(), but it just uses whatever reference is the current reference.

Though if the fs api were altered in rom, then it wouldn't matter anyway since the fs.open redefinition would occur before io copied it (which it doesn't do, it just uses the currently referenced function).

Which is all to say...no you don't need to alter io, it's not doing what I thought.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users