POV-Ray : Newsgroups : povray.off-topic : Dynamic loading : Re: Dynamic loading Server Time
29 Jul 2024 20:25:32 EDT (-0400)
  Re: Dynamic loading  
From: Patrick Elliott
Date: 20 May 2011 05:00:48
Message: <4dd62dc0$1@news.povray.org>
On 5/19/2011 2:50 AM, Invisible wrote:
> Depending on which operating system you're using, the OS provides
> various ways to load code into memory and execute it. My question is
> this: How hard would it be to write a subroutine that can read raw
> machine code from a flat file and make it execute?
Think I will give a slightly different answer here than most, which is, 
"In most modern operating systems, short of using a buffer overflow, or 
other method, you can't." Now, for something clear back to the days of 
say DOS (or even Win3.11, probably), you didn't have any protections, so 
nothing stopped you from loading what ever your wanted into some bit of 
memory, then jumping to it. On even older things, like Apple IIs, this 
was actually how such loading of parts of applications took place, more 
or less. You set the "write to" bank to bank 1, while the "execute" was 
set to bank 0, then read and parsed the file from disk, wrote it into 
bank 1 at your location, then set things up so that when the execute 
flag changed to bank 1, the machine would simply start execution code at 
the location you loaded the binary data into.

The closest you could get on a modern machine would be something like an 
emulator, which would allocate a known amount of memory, then let you 
play the same games, as though the machine you where dealing with was 
one that allowed such things, and didn't have an OS installed that 
protected from this.

In principle, a modern OS will only allow you to execute code it 
"recognizes" as valid executables, and only under its rules, and 
disallows certain methods of modification, which would allow you to play 
those sorts of games. However... At least in principle, if you could 
dump the address of a data array to the stack for a program, and then 
somehow trick the CPU and OS into looking there for the next place to 
run... But, in general, you are not allowed to mess with the stack that 
directly in most languages.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.