标记内存可执行页面 [英] Marking a Page of Memory Executable

查看:60
本文介绍了标记内存可执行页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不完全确定这是一个合适的地方,但是我在B中做这件事,所以我在问,但如果我是错了,那么请不要这么多b $ b犹豫要纠正我并告诉我在哪里发帖。


我想做的是获得一个可执行文件可写的内存页面,所以

我可以(比方说)把机器代码写入它,然后将%eip(x86上的

指令指针)切换到该页面,这样它将执行

代码或类似的东西。


我试图弄清楚JIT如何设法运行代码? br />
运行时没有写入可执行文件,所以如果有人知道

那或者有一些建议我也想听听。
,但这似乎已存档,所以我不能在这里发布这个。

谢谢,如果这是错误发布的话,我很抱歉。


- Piesquared

解决方案

< blockquote>文章< 25 ********************************** @ m45g2000hsb。 googlegroups.com>,

Pie Squared< Pi ******** @ gmail.comwrote:


> I 我不完全确定这是一个合适的地方,但是我在C中这样做,所以我在问,但如果我错了,那么请不要
犹豫纠正我并告诉我在哪里发布这个。



这不是正确的地方;你要做的事情超出了c

语言,这超出了comp.lang.c的范围。


>我想要做的是获得一个可执行和可写的内存页面,所以我可以(比方说)将机器代码写入它然后切换%eip(
指令) x86上的指针到该页面,以便它将执行该代码或类似的东西。



因为你似乎在使用x86,x86汇编语言新闻组

(如果我是comp.lang.asm.x86)记住正确的名称)将是一个好的第一站




但是,你可能需要做一些特定于OS的事情来标记页面

可执行文件,所以:


>顺便说一下,我正在使用Ubuntu Hardy Heron,以防万一。我试着查看comp.os.linux,但这似乎是存档的,所以我不能在那里发布。



comp.os.linux.development下的东西可能是一个很好的地方,可以用
来寻找它。

如果你在那里找不到东西,那么comp.unix.programmer中的人们可能会给你一个比我更好的重定向。


>我正在试图弄清楚JIT如何在不写入可执行文件的情况下运行在运行期间运行的代码,所以如果有人知道<那个或者有一些建议我也想听听。



comp.compilers(主持人)是第一个想到讨论JIT的


除了所有这些,comp.programming是一个非常好的第一个

停止任何编程问题,你不知道哪个其他新闻组

发布到约。

dave


-

Dave Vandervies dj3vande在eskimo dot com

我没有''我有一个像我这样的错误,我记得。 (

当然有可能还有一些东西仍然没有被发现......) - 约翰·托马斯在comp.arch中/>


6月4日,11:36 * pm,Pie Squared< PieSqua ... @ gmail.comwrote:


我想要做的是获得一个可执行和可写的内存页面,所以我可以(比方说)将机器代码写入它然后切换%eip(
$ b)在x86上的$ b指令指针到该页面,以便它将执行

代码或类似的东西。



我不确定我是不是正在吠叫树,但是这个怎么样:


在你的程序中,有一个功能,包括很多地狱指令,以便占用相当大的内存。然后在程序中使用
,只需使用函数的地址来改变它:


void Func(void)

{

int volatile i;


i = 5;

i = 6;

i = 7;

i = 8;

}


int main(无效)

{

char my_machine_code [] = {65,43,24,233,1,43,211,13,21};


memcpy((void *)Func,

my_machine_code,

sizeof my_machine_code);


Func();

}

当然,C标准并不保证这会起作用,但也许

它会起作用......?


Pie Squared写道:


我不完全确定这是一个合适的地方,但是我是这样做的b $ b在C中,所以我在问,但如果我错了,那么请不要这么多b $ b犹豫要纠正我并告诉我在哪里发布这个。


我想要什么do是得到一个可执行和可写的内存页面,所以

我可以(比如说)写机器码然后切换%eip(

指令指针在x86上)到那个页面,这样就可以执行那个

代码,或者类似的代码。


我试图找出JIT的管理方式在没有写入可执行文件的情况下运行在
运行时期间生成的代码,所以如果有人知道

那个或者有一些建议我也想听听。


顺便说一下,如果重要的话,我正在使用Ubuntu Hardy Heron。我试图在comp.os.linux中查看
,但这似乎已存档,所以我不能在这里发布这个。

谢谢,对不起,如果这是错误发布的。


- Piesquared



Hi Piesquared( pipi for friends我想:-)


%man mmap

MMAP(2)Linux程序员手册MMAP(2)< br $>

名称

mmap,munmap - 将文件或设备映射或取消映射到内存中


概要

#include< unistd.h>

#include< sys / mman.h>


#ifdef _POSIX_MAPPED_FILES


void * mmap(void * start,size_t length,int prot,int

flags,int fd,off_t offset);


int munmap(void * start,size_t length);


#endif


描述

mmap函数问映射长度字节,从

偏移文件(或其他对象)的偏移量通过

将文件描述符fd强化到内存中,最好是在地址

start。后一个地址只是一个提示,并且通常是指定为0​​的
。映射对象的实际位置是由mmap返回的,并且永远不会为0. br />

prot参数描述了所需的内存保护

(并且不得与文件的打开模式冲突)。它是
是PROT_NONE还是其他PROT_ *标志中的一个或多个

的按位OR。


PROT_EXEC Pages可能会执行。


等,没有复制其余的

-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32


I''m not completely sure that this is the right place to ask, but I''m
doing it in C, so I''m asking, but if I''m wrong, then please don''t
hesitate to correct me and tell me where to post this.

What I want to do is get an executable and writable page of memory, so
that I can (say) write machine code to it and then switch %eip (the
instruction pointer on x86) to that page so that it will execute that
code, or something similar.

I''m attempting to figure out how JIT''s manage to run code made during
run-time without writing to an executable file, so if anyone knows
that or has some suggestions I''d like to hear those too.

I''m using Ubuntu Hardy Heron, by the way, in case that matters. I
tried looking in comp.os.linux, but that seems to be archived, so I
can''t post this there.

Thanks, and sorry if this is mis-posted.

--Piesquared

解决方案

In article <25**********************************@m45g2000hsb. googlegroups.com>,
Pie Squared <Pi********@gmail.comwrote:

>I''m not completely sure that this is the right place to ask, but I''m
doing it in C, so I''m asking, but if I''m wrong, then please don''t
hesitate to correct me and tell me where to post this.

This isn''t the right place; what you''re trying to do goes beyond the C
language, which puts it outside the scope of comp.lang.c.

>What I want to do is get an executable and writable page of memory, so
that I can (say) write machine code to it and then switch %eip (the
instruction pointer on x86) to that page so that it will execute that
code, or something similar.

Since you seem to be using x86, the x86 assembly language newsgroup
(comp.lang.asm.x86 if I''m remembering the name correctly) would be a
good first stop.

But, you''ll probably need to do something OS-specific to mark the page
executable, so:

>I''m using Ubuntu Hardy Heron, by the way, in case that matters. I
tried looking in comp.os.linux, but that seems to be archived, so I
can''t post this there.

Something under comp.os.linux.development is probably a good place to
look for that.
If you can''t find something there, the people in comp.unix.programmer
may be able to give you a better redirection than I can.

>I''m attempting to figure out how JIT''s manage to run code made during
run-time without writing to an executable file, so if anyone knows
that or has some suggestions I''d like to hear those too.

comp.compilers (moderated) is the first place that comes to mind for
discussing JIT.
In addition to all of those, comp.programming is a pretty good first
stop for any programming problem you don''t know which other newsgroup
to post to about.
dave

--
Dave Vandervies dj3vande at eskimo dot com
I haven''t had an error like that get past me that I can remember. (Of
course that leaves the possibility that there are some that still
haven''t been found....) --Jonah Thomas in comp.arch


On Jun 4, 11:36*pm, Pie Squared <PieSqua...@gmail.comwrote:

What I want to do is get an executable and writable page of memory, so
that I can (say) write machine code to it and then switch %eip (the
instruction pointer on x86) to that page so that it will execute that
code, or something similar.


I''m not sure if I''m barking up the right tree, but how about this:

Within your program, have a function that consists of a hell of a lot
of instructions so that it takes up a sizeable piece of memory. Then
in your program, just use the function''s address to alter it:

void Func(void)
{
int volatile i;

i = 5;
i = 6;
i = 7;
i = 8;
}

int main(void)
{
char my_machine_code[] = {65,43,24,233,1,43,211,13,21};

memcpy( (void*)Func,
my_machine_code,
sizeof my_machine_code );

Func();
}
Of course, the C Standard doesn''t guarantee this will work, but maybe
it''ll work... ?


Pie Squared wrote:

I''m not completely sure that this is the right place to ask, but I''m
doing it in C, so I''m asking, but if I''m wrong, then please don''t
hesitate to correct me and tell me where to post this.

What I want to do is get an executable and writable page of memory, so
that I can (say) write machine code to it and then switch %eip (the
instruction pointer on x86) to that page so that it will execute that
code, or something similar.

I''m attempting to figure out how JIT''s manage to run code made during
run-time without writing to an executable file, so if anyone knows
that or has some suggestions I''d like to hear those too.

I''m using Ubuntu Hardy Heron, by the way, in case that matters. I
tried looking in comp.os.linux, but that seems to be archived, so I
can''t post this there.

Thanks, and sorry if this is mis-posted.

--Piesquared

Hi Piesquared (pipi for friends I suppose :-)

% man mmap

MMAP(2) Linux Programmer''s Manual MMAP(2)

NAME
mmap, munmap - map or unmap files or devices into memory

SYNOPSIS
#include <unistd.h>
#include <sys/mman.h>

#ifdef _POSIX_MAPPED_FILES

void * mmap(void *start, size_t length, int prot , int
flags, int fd, off_t offset);

int munmap(void *start, size_t length);

#endif

DESCRIPTION
The mmap function asks to map length bytes starting at
offset offset from the file (or other object) specified by
the file descriptor fd into memory, preferably at address
start. This latter address is a hint only, and is usually
specified as 0. The actual place where the object is
mapped is returned by mmap, and is never 0.

The prot argument describes the desired memory protection
(and must not conflict with the open mode of the file). It
is either PROT_NONE or is the bitwise OR of one or more of
the other PROT_* flags.

PROT_EXEC Pages may be executed.

etc, did not copy the rest
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32


这篇关于标记内存可执行页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆