2009-10-09 79 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