Jump to content




Overwrite all functions in a stock API at once?


  • You cannot reply to this topic
11 replies to this topic

#1 Cloud Ninja

  • Members
  • 361 posts

Posted 21 February 2016 - 05:19 PM

I'm writing an SU API for my root method TKO for the operating system O, and I'm trying to overwrite all FS functions in batch. Is there a way i can do something like

for k,v in pairs(fs) do
  vBackup = v
  function v()
	  v = vBackup
	  --Whatever i want to do here---
	  return v()
    end
end


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 21 February 2016 - 08:30 PM

for k, v in pairs(fs) do
  local b = v
  fs[k] = function( ... ) return b( ... ) end
end


#3 Cloud Ninja

  • Members
  • 361 posts

Posted 21 February 2016 - 11:49 PM

View PostKingofGamesYami, on 21 February 2016 - 08:30 PM, said:

for k, v in pairs(fs) do
  local b = v
  fs[k] = function( ... ) return b( ... ) end
end
Thanks Yami!

#4 Cloud Ninja

  • Members
  • 361 posts

Posted 22 February 2016 - 01:07 AM

View PostKingofGamesYami, on 21 February 2016 - 08:30 PM, said:

for k, v in pairs(fs) do
  local b = v
  fs[k] = function( ... ) return b( ... ) end
end
This worked, but i also need one more thing. I need to pass shell.getRunningProgram into an api, but i dont want the person to be able to put any program in, so i want no interaction other than checkSU(), and then in the code it checks with shell.getRunningProgram, but shell doesnt work in apis so i need some form of workaround.

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 22 February 2016 - 03:01 AM

Why not load stick a copy of checkSU() into the sandboxed environment table, instead of into _G?

#6 Cloud Ninja

  • Members
  • 361 posts

Posted 22 February 2016 - 03:06 AM

View PostBomb Bloke, on 22 February 2016 - 03:01 AM, said:

Why not load stick a copy of checkSU() into the sandboxed environment table, instead of into _G?
I'm sorry, i dont understand this. What do you mean?

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 22 February 2016 - 08:28 AM

The shell API isn't loaded into _G, but rather into the environment table of the shell which "loaded" it (that is to say, the shell script simply defines a global shell table and starts sticking functions into it).

This means regular APIs can't touch it (and with good reason - given that a system can run multiple instances of shell at once, which one should they try to interact with?).

So I'm suggesting you do the same: stick a pointer to your checkSU() function into the environment table for your sandbox. Since the shell table's also in there they'll be able to play with each other.

#8 Cloud Ninja

  • Members
  • 361 posts

Posted 22 February 2016 - 11:23 AM

So do something like ' local SU = {} ' and then throw functions in there? How would i go about doing so and allowing anything to execute those functions?

#9 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 22 February 2016 - 06:26 PM

View PostCloudNinja, on 22 February 2016 - 11:23 AM, said:

So do something like ' local SU = {} ' and then throw functions in there? How would i go about doing so and allowing anything to execute those functions?

I think, you have to deny all other functions with setfenv(func, env), but it will be removed in CC 2.0. You will have to use _ENV.

#10 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 February 2016 - 12:53 AM

View PostCloudNinja, on 22 February 2016 - 11:23 AM, said:

So do something like ' local SU = {} ' and then throw functions in there? How would i go about doing so and allowing anything to execute those functions?

Have a think about how shell does it. That is to say, have your sandboxes autorun a certain script file when they start, and have that handle it.

#11 Cloud Ninja

  • Members
  • 361 posts

Posted 23 February 2016 - 01:34 AM

View PostBomb Bloke, on 23 February 2016 - 12:53 AM, said:

View PostCloudNinja, on 22 February 2016 - 11:23 AM, said:

So do something like ' local SU = {} ' and then throw functions in there? How would i go about doing so and allowing anything to execute those functions?

Have a think about how shell does it. That is to say, have your sandboxes autorun a certain script file when they start, and have that handle it.
I dont know how shell does it, thats my issue. I havn't messed with too much heavy sandboxing or environments too much other than _G getfenv() hacking back in 1.73 and before.

#12 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 February 2016 - 01:37 AM

View PostBomb Bloke, on 23 February 2016 - 12:53 AM, said:

have your sandboxes autorun a certain script file when they start, and have that handle it.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users