是否可以使用NASM中的DB指令在.text段中创建可写变量? [英] Is it possible to make writeable variables in .text segment using DB directive in NASM?

查看:151
本文介绍了是否可以使用NASM中的DB指令在.text段中创建可写变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用例如在.text段中声明变量file_handle: dd 0.

I've tried declaring variables in .text segment using e.g. file_handle: dd 0.

但是,尝试在mov [file_handle], eax这样的变量中存储内容会导致写入错误.

However, trying to store something in this variable like mov [file_handle], eax results in a write error.

我知道,我可以在.data段中声明可写变量,但是为了使代码更紧凑,我想按上面的方法尝试.

I know, I could declare writeable variables in the .data segment, but to make the code more compact I'd like to try it as above.

使用堆栈存储这些值(例如文件句柄)是唯一的可能性,还是我可以通过某种方式写入上面的变量?

Is the only possibility to use the stack for storing these value (e.g. the file handle), or could I somehow write to my variable above?

推荐答案

默认情况下,可执行代码段不可写.这是基本的安全预防措施.不,这不是一个好主意.但是,如果您坚持要这么做,因为这还是一个玩具项目,那就继续吧.

Executable code segments are not writable by default. This is a basic security precaution. No, it's not a good idea. But if you insist, as this is a toy project anyway, go ahead.

您可以通过告诉链接器将其标记为可写的方式来使其可写,例如将以下参数提供给MS链接器:

You can make yours writable by letting the linker know to mark it so, e.g. give the following argument to the MS linker:

link /SECTION:.text,EWR ....

这篇关于是否可以使用NASM中的DB指令在.text段中创建可写变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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