汇编 如何将 REP STOS 转换为 C 代码
我已经调试 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你几乎是正确的。唯一的区别是方向标志 (
DF
) 控制是否从EDI
中添加或减去 4(它实际上是相对于ES
的偏移量)段基数,但您可能不关心这一点):请注意,
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 fromEDI
(and it actually is offset from theES
segment base, but you probably don't care about that):Note that the
for (; regs.d.ecx != 0; regs.d.ecx--) { }
is the action of theREP
prefix, and the body of the loop is the action ofSTOS 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.