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

Bypass disk override?

Started by Mackan90096, 20 May 2015 - 09:31 AM
Mackan90096 #1
Posted 20 May 2015 - 11:31 AM
So. We all know that a file named startup will override the one on the computer. I'm wondering if there's any way to bypass this? Like, make the startup file on the computer run regardless of the startup file on the disk.

Thanks - Mackan
flaghacker #2
Posted 20 May 2015 - 11:51 AM
There's no ingame way, but you (or the server owner in multiplayer) can edit the computercraft rom to prevent it.
theoriginalbit #3
Posted 20 May 2015 - 12:00 PM
A disk with a higher "priority" could be used to with a startup script to run the computer's startup script. The highest "priority" disk drive is the top as it is the first place checked for a startup.
HDeffo #4
Posted 20 May 2015 - 12:28 PM
Depending on what version of ComputerCraft you are using contrary to popular belief all but the newest versions you can actually bypass disk/startup files. The string metatable is exposed in older versions of the mod and when you edit this it remains until the server restarts or someone else changes the metatable. There is a section just before disk/startup is run that uses gsub which will run your metatable program effectively bypassing the disk if you make it do that.


Please note this would be slightly hackish and dirty code but if we are being honest since most modpacks aren't fully up to date yet, yes it is possible
Edited on 20 May 2015 - 10:29 AM
valithor #5
Posted 20 May 2015 - 02:19 PM
There's no ingame way, but you (or the server owner in multiplayer) can edit the computercraft rom to prevent it.

For most new versions you no longer edit the jar to make changes. Instead the new method is to put a resource pack in a resource pack folder in the server files, and it will automatically use whatever you put in the resource pack to overwrite the original (with the exception of the bios). In order to prevent disk startup the program you would want to modify is /rom/startup
Edited on 20 May 2015 - 12:20 PM
Lyqyd #6
Posted 20 May 2015 - 05:28 PM
There is a section just before disk/startup is run that uses gsub […]

Where, exactly, is this call you refer to? A quick glance through the current /rom/startup and the current /rom/programs/shell turned up nothing.
HDeffo #7
Posted 20 May 2015 - 05:58 PM
There is a section just before disk/startup is run that uses gsub […]

Where, exactly, is this call you refer to? A quick glance through the current /rom/startup and the current /rom/programs/shell turned up nothing.

I am not exactly sure honestly….

(please note all of the following is outdated so if you are trying to bypass the disk on the current version ignore the following)
Spoilerwhile first tests would show that it isn't triggered on startup example being this code

getmetatable("").__index.gsub = function(...)
   print("gsub attempted")
   return string.gsub(...)
end

the above wont run at all when you turn the computer on so nothing will be printed HOWEVER doing the code below this


getmetatable("").__index = function(t,k)
   print(k)
   return string[k]
end

this will print 'gsub' when the computer attempts to turn on…..so this will show that gsub runs at some point during booting but for some reason it behaves very strange. I have found a call to gsub within the bios but I am not really sure if thats where its coming from as running code inside of this string index "function" still has access to all APIs and everything as if rom/startup has already run. Anyways more directly on topic to override disk startup you will want code something like this


getmetatable("").__index = function(t,k)
   --#your code would go here

   return string[k]
end
Anavrins #8
Posted 20 May 2015 - 09:35 PM
Depending on what version of ComputerCraft you are using contrary to popular belief all but the newest versions you can actually bypass disk/startup files. The string metatable is exposed in older versions of the mod and when you edit this it remains until the server restarts or someone else changes the metatable. There is a section just before disk/startup is run that uses gsub which will run your metatable program effectively bypassing the disk if you make it do that.


Please note this would be slightly hackish and dirty code but if we are being honest since most modpacks aren't fully up to date yet, yes it is possible
You're almost right, there is a string.sub being used in "/rom/startup", however the metatable bug could only be used again calls that uses the metatable, in other words, with a colon, example: str:sub(1,3).
KingofGamesYami #9
Posted 20 May 2015 - 11:51 PM
The only way to not call the __index metamethod would be to use rawget. string.sub, str:sub, string["sub"] will all call the __index metamathod. (This is, of course, assuming they are already indexes - setting an index would trigger __newindex).
HDeffo #10
Posted 21 May 2015 - 02:18 AM
It isn't a matter of me being almost right. I actually use this method on a server I run for cross computer communication so I know it works.

@avavrins: that's a different function and not what triggers my code. The function that triggers it is :gsub although I don't know in which program it is is I only know it somehow happens only if __index is a function and not a table and happens before disk/startup.

@KingofGamesYami: the string table and the string metatable are two different tables calling one will not trigger the other. The metatable exists within each string and exists within that string. The string table is a table of functions within the global table _G. In standard computercraft string.len() does not call str:len() and visa versa. My code takes advantage of this and makes it so str:len() DOES call string.len() but this still doesn't occur the way so there isn't a loop.