汇编 如何将 REP STOS 转换为 C 代码

发布于 2024-12-09 22:35:57 字数 558 浏览 3 评论 0原文

我已经调试 REP STOS DWORD PTR ES:[EDI] 一段时间了,

从我的结论来看,它总是使用

ECX 作为计数器。 EAX 作为将通过 EDI 复制的值,然后附加 ECX 次 因此,在放入 EDI 的指向转储后,

它似乎会用以下内容覆盖 EDI 中的指向数据: 似乎它总是只使用 ECX 作为计数器,同时将 EDI 更改 4 个字节。 当计数器达到 0 时它停止工作

所以我想出了这种代码

while(regs.d.ecx != 0)
{
    *(unsigned int *)(regs.d.edi) = regs.d.eax;
    regs.d.edi += 4;
    regs.d.ecx--;
}

似乎可以工作..但我很担心,因为我只是靠运气和猜测工作做到了这一点。是固体吗?就像它总是ECX作为计数器,EAX作为数据,并且它总是复制4个字节不少于?

I been debugging REP STOS DWORD PTR ES:[EDI] for a while now

From my conclusion it always uses

ECX as counter.
EAX as the value that will be copied over EDI and then appended ECX times
so after putting in the pointed dump of EDI

it seems to overwrite the pointed data at EDI with what's
it seems it always only uses ECX as a counter, while changing EDI by 4 bytes.
it stops working when counter hits 0

So I came up with this kind of code

while(regs.d.ecx != 0)
{
    *(unsigned int *)(regs.d.edi) = regs.d.eax;
    regs.d.edi += 4;
    regs.d.ecx--;
}

Seems to work.. but i'm concerned since I just did this by luck and guess work. Is it solid? like will it always be ECX as counter, EAX as data, and it always copies 4 bytes never less?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2024-12-16 22:35:57

你几乎是正确的。唯一的区别是方向标志 (DF) 控制是否从 EDI 中添加或减去 4(它实际上是相对于 ES 的偏移量)段基数,但您可能不关心这一点):

for (; regs.d.ecx != 0; regs.d.ecx--)
{
    *(unsigned int *)(regs.d.edi) = regs.d.eax;
    regs.d.edi += regs.eflags.df ? -4 : 4;
}

请注意,for (; regs.d.ecx != 0; regs.d.ecx--) { } 的操作是代表前缀,循环体是 STOS DWORD... 的操作。

由于您问了很多这些问题,我想您会找到Intel 64 和 IA-32 架构软件开发人员手册,第 2A 卷和2B 有用。其中包含每条指令和前缀的描述,包括伪代码描述。

You are almost correct. The only difference is that the direction flag (DF) controls whether 4 is added or subtracted from EDI (and it actually is offset from the ES segment base, but you probably don't care about that):

for (; regs.d.ecx != 0; regs.d.ecx--)
{
    *(unsigned int *)(regs.d.edi) = regs.d.eax;
    regs.d.edi += regs.eflags.df ? -4 : 4;
}

Note that the for (; regs.d.ecx != 0; regs.d.ecx--) { } is the action of the REP prefix, and the body of the loop is the action of STOS DWORD....

Since you are asking a lot of these questions, I think you will find the Intel 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A and 2B to be useful. These contain descriptions of each instruction and prefix, including pseudo-code descriptions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文