2009-10-09 49 views
1

如何异或存储在EAX中的值?异或存储在EAX中的地址

的问题是在这条线:

xor eax, key 

EAX包含我想XOR值的地址。我怎样才能做到这一点?我虽然这将是沿着线的东西:

xor [eax], key 

但不起作用(语法错误)

decrypt proc startAddress:DWORD , sizeOfSegment:DWORD , key:DWORD 


    xor ecx, ecx ; clear the ecx register for the counter 
    mov eax, startAddress ; copy the start address to eax 
    .while ecx < sizeOfSegment ; loop through the code 
    xor eax, key ; XOR decrypt the word 
    inc eax 
    inc ecx 
    .endw 

    ret 

    decrypt endp 
+1

对你没有太大的帮助(并且可以随意嘲笑我),但是这会在nasm中起作用。 nasm很棒。 – 2009-10-09 01:15:05

回答

8

你说你做...

xor eax, key ; XOR decrypt the word 

...但我猜这是一个错字,你实际上正在尝试做...

xor [eax], key ; XOR decrypt the word 

这个原因不起作用的原因是key不是注册表:它可能是我不知道的,像[ebp+4]之类的东西的同义词。

x86(不只是MASM,但也是nasm:x86指令集)允许寄存器到寄存器,寄存器到存储器和存储器到寄存器操作数,但不允许从存储器到存储器。

所以,你需要钥匙装入一些备用的寄存器,例如:

mov eax, startAddress 
    mov ebx, key ; move key into a register, which can be XORed with [eax] 
    .while ecx < sizeOfSegment 
    xor [eax], ebx 

在一个单独的事情,你真的想这样做inc eax还是应add eax,4?我的意思是,你说“XOR解密单词”:你的意思是“单词”,“字节”还是“双字”?

+0

哦,你说得对。 D'哦。 – 2009-10-09 01:26:26