开发者

accessing code space on memory?

is it possible but I guess that memory is read only. I tried something like that

void (*b)();

b = *test;

char * z = (char * )b;

and when I print开发者_Python百科 contents of z, it prints constants from test function.

but that memory is read only and I get segfaults when I edit them and call test. I tried this.

char x[100];

for(i=0; i<100; i++) x[i] = z[i];

b = (void(*)())x;

b();

and segfault again.

I know this is kinda stupid, but is there a way to do this? I think there is a way to change code memory to read/write but what I really need is being able to send functions over network and make a remote machine to run them.

edit: this is not for malicious use. what I trying to achieve creating a network which can share code parts between them and run a program parallelly on different part of same input


The ability to modify executable code (during execution) depends on the operating system and all operating systems differ at this level. Some require high levels of protection (*nix), while others may have code in ROM (embedded systems).

Executing code on a remote computer is not standard either. You'll have to investigate the operating system and figure out how to do this. I know the Unix operating system allows execution of programs on remote Unix machines.

Post more details about what you are trying to accomplish, so we may better assist you.


It's possible to write code into memory and then execute it. JIT compilers for Java and .NET do this regularly.

Wikipedia has some background information here.

As far as sending the code and having it execute remotely, you need the assistance of the remote machine (it should be designed to receive code, put it into memory, then run it, protected by appropriate security of course).


Normally, functions are stored inside read-only memory sections (on ELF systems, that's the .text section inside the ELF file; almost always gets mmap'ed read-only). And as long as the function isn't PIC (Position Independent Code, as in UNIX shared libraries) you can't copy and execute it (or if you can, then by pure chance).


You're looking for the ability to write a loader.

The target architecture/host is going to determine the ease of use for that.

E.g., if you are sending Lisp, it's just strings, then a command to eval them. OTOH, if you are doing this with Windows 7 and managed C# code, this could be a real grief.

Technically, yes, this is very doable with a von Neumann architecture. It's also sort of a security hole.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜