Jump to content




Top Level


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

#1 Imque

  • Members
  • 134 posts

Posted 18 April 2013 - 02:06 AM

Hai.


I have seen some programs which allow you to kill the parent shell but I am not understanding the code used. What steps are taken and what needs to be done to kill the parent shell?

#2 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 18 April 2013 - 02:41 AM

When you say "shell" your referring to a program that will open another program right?

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 18 April 2013 - 02:50 AM

View PostSpongy141, on 18 April 2013 - 02:41 AM, said:

When you say "shell" your referring to a program that will open another program right?
Thats what I'm understanding it as, since I believe he is talking about this great hack by NeverCast

#4 Imque

  • Members
  • 134 posts

Posted 18 April 2013 - 04:21 PM

Yes like how NeverCast has completed the task.

#5 Imque

  • Members
  • 134 posts

Posted 21 April 2013 - 02:54 AM

Cough

#6 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 21 April 2013 - 03:42 AM

To understand NeverCast's code, you have to understand how the stack works in Lua. The stack is like a pile of dishes. When a new program is run, or a function is called, the function/program is put on the top of the stack, just like a new dirty dish is put on top of the pile. When a function or program ends, it's like its dish has been cleaned, and taken off the pile. The function/program will be taken off the stack.

The first step to his code is looking through the pile of dirty dishes for the shell. The shell is the thing you see when you start the computer up (CraftOS basically). When he finds it, he tells it to exit, which basically means it tells the shell to clean all the dishes on top of it, then clean itself, so the shell or anything run inside of it is no longer on the stack.

You know when you type exit into CraftOS, and it says press any key to continue, then shuts down the computer? The next step is to override the key press and shutdown methods (os.pullEvent and os.shutdown) and basically simulate them, and make the computer believe they've behaved normally. Note, he doesn't actually shut the computer down, he just makes the shell think the computer's shut down, but it actually hasn't.

Then he resets everything back to normal, and voila! The program is now above CraftOS, above Rednet, etc...

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 21 April 2013 - 03:50 AM

View PostGravityScore, on 21 April 2013 - 03:42 AM, said:

-snip-
Nice explanation, much more low-level and easier to understand than the massive one I was working on :)

#8 Imque

  • Members
  • 134 posts

Posted 22 April 2013 - 01:27 AM

Okay, to become "top level" I need to trick the computer into shutting down then run my program and the shell again?

#9 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 22 April 2013 - 01:51 AM

View PostImque, on 22 April 2013 - 01:27 AM, said:

Okay, to become "top level" I need to trick the computer into shutting down then run my program and the shell again?
Almost, you need to trick the computer into thinking it shut down. ^_^

#10 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 22 April 2013 - 02:14 PM

View PostEspen, on 22 April 2013 - 01:51 AM, said:

View PostImque, on 22 April 2013 - 01:27 AM, said:

Okay, to become "top level" I need to trick the computer into shutting down then run my program and the shell again?
Almost, you need to trick the computer into thinking it shut down. ^_^

Yes, but you can't just override os.shutdown and call it, because it won't shut anything down. NeverCast's method is basically the only way I can think of, unless there's another method of getting the computer to shut down.

#11 Imque

  • Members
  • 134 posts

Posted 22 April 2013 - 07:11 PM

Eg.

os.shutdown = function()
  do
	sleep(0)
  end
end

Wont work?

#12 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 22 April 2013 - 08:29 PM

View PostGravityScore, on 22 April 2013 - 02:14 PM, said:

View PostEspen, on 22 April 2013 - 01:51 AM, said:

Almost, you need to trick the computer into thinking it shut down. ^_^

Yes, but you can't just override os.shutdown and call it, because it won't shut anything down. NeverCast's method is basically the only way I can think of, unless there's another method of getting the computer to shut down.
Where did I say anything to the contrary?

Forcing the shell exit is making the bios.lua continue with its code after the parallel.waitForAny() that startet the top level shell.
Then the bios.lua presents the user with a message to "Press any key to continue" and wait for a key event, which we intercept and simply return just that event.
After that the bios.lua's last step would be to call os.shutdown(), which we intercept as well and instead recover everything to our heart's desire.
So after our successful injection bios.lua is waiting for its last call to return, namely that one from os.shutdown()

I didn't go into all the other necessary steps in my previous answer, because I was trying to give a direct answer to his question, concentrating only on the difference between actually shutting down the computer and making it only think we shut it down.
That's what I meant with "you need to trick the computer into thinking it shut down".
It was just a clarification of Imque's misunderstanding that we actually shut down the computer. Which we don't, we just make it think we did.

#13 Imque

  • Members
  • 134 posts

Posted 22 April 2013 - 09:22 PM

Does this work?

prev = {
shutdown = os.shutdown
}
os.shutdown = function()
term.clear()
term.setCursorPos(1, 1)
print("Booted before shell")
shell.run("rom/programs/shell")
os.shutdown = prev.shutdown
end

#14 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 23 April 2013 - 12:06 AM

@Imque:
I'm afraid it wouldn't. The only thing you're essentially doing is to start another shell on top of your running program.
And when that shell ends, you'll be back in your program, which then would end and land you right back in the top level shell, from which your program started to begin with.

Let me try to explain how to do it ...
Spoiler

Edited by Espen, 23 April 2013 - 01:03 AM.


#15 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 23 April 2013 - 12:30 AM

View PostEspen, on 22 April 2013 - 08:29 PM, said:

View PostGravityScore, on 22 April 2013 - 02:14 PM, said:

View PostEspen, on 22 April 2013 - 01:51 AM, said:

Almost, you need to trick the computer into thinking it shut down. ^_^

Yes, but you can't just override os.shutdown and call it, because it won't shut anything down. NeverCast's method is basically the only way I can think of, unless there's another method of getting the computer to shut down.

Forcing the shell exit is making the bios.lua continue with its code after the parallel.waitForAny() that startet the top level shell.
Then the bios.lua presents the user with a message to "Press any key to continue" and wait for a key event, which we intercept and simply return just that event.
After that the bios.lua's last step would be to call os.shutdown(), which we intercept as well and instead recover everything to our heart's desire.
So after our successful injection bios.lua is waiting for its last call to return, namely that one from os.shutdown()

I didn't go into all the other necessary steps in my previous answer, because I was trying to give a direct answer to his question, concentrating only on the difference between actually shutting down the computer and making it only think we shut it down.
That's what I meant with "you need to trick the computer into thinking it shut down".
It was just a clarification of Imque's misunderstanding that we actually shut down the computer. Which we don't, we just make it think we did.

I'm sorry, I quoted the wrong post :P I was ment to quote Imque's post.

I was directing it to Imque, just to make sure he/she understood that the way NeverCast did it is probably the only way.

#16 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 23 April 2013 - 12:32 AM

View PostGravityScore, on 23 April 2013 - 12:30 AM, said:

I'm sorry, I quoted the wrong post :P I was ment to quote Imque's post.

I was directing it to Imque, just to make sure he/she understood that the way NeverCast did it is probably the only way.
Hey, honest mistake, no problem. The derp is strong in us humans, no shame in that. ^^





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users