PE Encryptor/Decryptor: Solve the Error "Operand Types Do Not Match

  • Thread starter maple23
  • Start date
In summary, the PE encryptor/decryptor being worked on generates a random number to use as its key and attempts different keys until the first byte of the PE file is "M". However, there is an issue with using the XOR instruction and it is suggested to use the MOVZX instruction to convert the key to an 8-bit byte before performing the XOR operation.
  • #1
maple23
15
0
I am working on a PE encryptor / decryptor which doesn't use a static key. The encryptor generates a random number (1-255) to use as its key. Knowing that the first character in all PE files (excluding VxDs and 16-bit DLLs) is "M" (starting the DOS MZ header), the decryptor will keep trying different keys until the first byte of the PE is "M". Once we find the key, we decrypt the rest of the file. What I have written looks like this:

Code:
	lea	esi, offset FILE_CONTENTS	; ESI = contents of encrypted file
	xor	edi, edi			; EDI = 0 (encryption key)

FIND_KEY:
	inc	[edi]				; EDI++
	xor	byte ptr [esi], [edi]		; FILE_CONTENTS[ESI] = XOR FILE_CONTENTS[ESI], EDI
	cmp	byte ptr [esi], "M"		; did we find the key?
	jne	find_key			; if not, check again

	mov	ecx, FILE_SIZE - 1		; ECX = FILE_SIZE - 1 (we already decrypted the first byte)

DECRYPT:
	xor	byte ptr [esi], [edi]		; encrypt byte
	inc	esi				; get next byte
	loop	DECRYPT				; loop until ECX = 0

Unfortunately, this doesn't work. I get the error "Operand types do not match" in both of the XOR lines. Does anyone have any input or ideas on how to solve this problem?
 
Technology news on Phys.org
  • #2
Any help would be greatly appreciated.The issue here is that you are using the wrong instruction for the task. The XOR instruction requires two operands of the same size, and you are trying to xor a byte (8 bits) with a dword (32 bits). To fix this, you can use the MOVZX instruction to convert the dword value in edi to an 8-bit byte before performing the XOR operation: FIND_KEY: inc [edi] ; EDI++ movzx eax, byte ptr [edi] ; Convert EDI to a byte in EAX xor byte ptr [esi], al ; FILE_CONTENTS[ESI] = XOR FILE_CONTENTS[ESI], AL (the 8-bit result from MOVZX) cmp byte ptr [esi], "M" ; did we find the key? jne find_key ; if not, check againDECRYPT: xor byte ptr [esi], al ; encrypt byte inc esi ; get next byte loop DECRYPT ; loop until ECX = 0
 
  • #3


Thank you for sharing your code and the issue you are encountering. Based on the information provided, it seems like the error is related to the operands used in the XOR instruction. In order for the XOR operation to work, both operands must be of the same size and type. In your code, you are using a byte-sized operand for the first operand and a dword-sized operand for the second operand. This mismatch in operand sizes is causing the error.

One possible solution could be to declare the second operand as a byte as well, by using the "byte ptr" prefix before the second operand in the XOR instruction. This will ensure that both operands are of the same size and type, and the operation can be performed successfully.

Another possible solution could be to use a different instruction, such as "movzx" or "movsx", to move the value of the second operand into a byte-sized register before performing the XOR operation.

I hope this helps you to solve the issue and continue with your project. It is always important to carefully check the sizes and types of operands when working with assembly code to avoid such errors. Good luck!
 

1. What is a PE Encryptor/Decryptor?

A PE Encryptor/Decryptor is a software tool used to encrypt or decrypt files in the Portable Executable (PE) file format. This format is commonly used for executable files on Windows operating systems.

2. How does a PE Encryptor/Decryptor work?

A PE Encryptor/Decryptor works by using a specific algorithm to scramble or unscramble the data in a PE file. This algorithm typically requires a key or password to access the encrypted data.

3. What does the error "Operand Types Do Not Match" mean?

The error "Operand Types Do Not Match" means that the data types being used in the encryption or decryption process do not match. This could be due to a mistake in the code or a mismatch between the data types specified and the actual data being used.

4. How can I solve the "Operand Types Do Not Match" error?

To solve the "Operand Types Do Not Match" error, you will need to check the code and make sure that the data types being used are compatible. This may require adjusting the code or converting the data types to match.

5. Are there any common reasons for the "Operand Types Do Not Match" error?

Yes, there are a few common reasons for the "Operand Types Do Not Match" error. These include incorrect data type declarations, mismatched data types in different parts of the code, or attempting to perform an operation on incompatible data types.

Back
Top