你能不能帮我解释一下这个ASM code? [英] Can you help me to explain this asm code?

查看:709
本文介绍了你能不能帮我解释一下这个ASM code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一块小code的,我不明白这意味着什么。谁能帮我解释吗?

  MOV ECX,[ESP + 8]
MOV EDX,[ECX]
INC EDX
MOV [ECX],EDX
十二月EDX
MOV人,[ESP + 4]
MOV [EDX],人
MOV EAX,[ESP + 4]
和EAX,0FFh的
RETN


解决方案

(我的程序集是一个有点生疏,有人请纠正我,如果我错了):


  1. 尤其是当前栈指针,这就是当地人和参数通常居住。 ESP + 8 将访问即8个字节,从当前栈帧地址偏移量的项目。在 [X] 表示取消引用,所以当地是一个指针类型。

  2. 此值被复制到 ECX 通用寄存器。

  3. 的值 ECX 是PTED为指针,然后跨$ P $和取消引用到 EDX ,表示这是一个指针到指针类型。

  4. 的值 EDX 递增(可能指向下一个元素与1字节大小的元素的数组)。

  5. EDX 复制回地址是 ECX 所指向该值

  6. EDX 然后递减。

  7. 在偏移4被复制到 A 寄存器的低8位的堆栈值(也就是 EAX 报名)。

  8. 然后,这个值被复制到徘徊无论 EDX 指向。

  9. 从第7步相同的值重新使用,并为0xFF相与 - 这实际上是一样的东西复制到(既是只处理的低8位值)。

  10. 最后 RETN 从堆栈中得到返回地址并从该地址起恢复执行。

在C,我觉得这是非常接近:

  ...
字符* A = ... //本地偏移+4
焦炭** B = ... //本地偏移+8
字符* C = * B;
C ++;
(*C) - ;
* C = A; //低8位隐若无的sizeof`(焦)== 1`和1个字节为8位(非字节的系统确实存在)
字符* D = A和0xFF的;
返回;

我不能完全肯定这是怎么回事就在这里,因为它看起来像你缺少你发布什么之前就说明。

I have a piece of small code and I can't understand what it means. Can anyone help me to explain it?

mov     ecx, [esp+8]
mov     edx, [ecx]
inc     edx
mov     [ecx], edx
dec     edx
mov     al, [esp+4]
mov     [edx], al
mov     eax, [esp+4]
and     eax, 0FFh
retn

解决方案

(My assembly is a bit rusty, anyone please correct me if I'm wrong):

  1. esp is the current stack-pointer, which is where locals and parameters typically live. esp+8 would access an item that is 8 bytes offset from the current stack-frame address. The [x] denotes a dereferencing, so the local is a pointer type.
  2. This value is copied into the ecx general-purpose register.
  3. The value of ecx is then interpreted as a pointer and is dereferenced into edx, indicating it's a pointer-to-pointer type.
  4. The value of edx is incremented (possibly pointing to the next element in an array with 1-byte sized elements).
  5. The value of edx is copied back into the address that ecx is pointing at.
  6. edx is then decremented.
  7. The stack value at offset 4 is copied into the lower 8 bits of the a register (which is a different view of the eax and ax register).
  8. This value is then copied into whereever edx is pointing to.
  9. The same value from step 7 is re-used and ANDed with 0xFF - which is effectively the same thing as copying into al (as both only handles the lower 8 bits of the value).
  10. Finally retn gets the return address from the stack and resumes execution from that address onward.

In C, I think this is a close approximation:

...
char* a = ... // local at offset +4
char** b = ... // local at offset +8
char* c = *b;
c++;
(*c)--;
*c = a; // lower 8-bits implicit if `sizeof(char) == 1` and 1 byte is 8 bits (non-octet systems do exist)
char* d = a & 0xFF;
return;

I'm not entirely sure what's going on here as it looks like you're missing instructions that came before what you posted.

这篇关于你能不能帮我解释一下这个ASM code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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