MASM Encryption

MASM Encryption

MASM is Microsoft’s macro assembler for x86 and x64—think device drivers, shellcode-sized utilities, and die-hard Win32 projects that still speak directly to the CPU. You control every byte in the PE; that also means your db/dw data segments are obvious in a hex editor.

Serial algorithms, patch URLs, and debug passwords have nowhere to hide when they live as raw bytes next to your code. StringEncrypt emits MASM that rebuilds the text at runtime instead of leaving a readable blob in .data. Nested loops use the usual push/pop label dance the engine generates—see the samples below.

You can additionally use a dedicated assembler obfuscator to protect the entire source code.

String encryption supports both UNICODE (dw type) and ANSI (db type) strings.

You can read more about MASM at at:

MASM encryption (UNICODE Example)

Plaintext reference: StringEncrypt sample

; encrypted with https://www.stringencrypt.com (v1.5.0) [MASM Assembler (32 bit)]

.data

	; myString = "StringEncrypt sample"
	myString	dw 05492h, 0C1AEh, 0BBD1h, 01191h, 09659h, 0AB6Bh, 04842h, 01311h
                        dw 0F06Bh, 0D6A1h, 00B86h, 026BDh, 01D9Dh, 0A81Eh, 05436h, 04F8Fh
                        dw 06B23h, 0D64Dh, 0AF1Eh, 0B9FEh, 063D3h

.code
	mov	edx, offset myString
	mov	ebx, 21
	xor	ecx, ecx

@@:
	mov	ax, word ptr [edx + ecx]

	push	ebx
	mov	ebx, 4
JSnGx:

	push	ebx
	mov	ebx, 4
BhRVd:

	push	ebx
	mov	ebx, 2
rlXQK:
	sub	eax, ecx
	xor	eax, 02E60h
	dec	eax
	dec	ebx
	jne	rlXQK
	pop	ebx

	push	eax
	mov	cl, cl
	ror	word ptr [esp], cl
	pop	eax
	dec	ebx
	jne	BhRVd
	pop	ebx


	push	ebx
	mov	ebx, 2
weEfI:
	inc	eax
	dec	ebx
	jne	weEfI
	pop	ebx

	dec	ebx
	jne	JSnGx
	pop	ebx

	not	eax
	push	eax
	mov	cl, cl
	ror	word ptr [esp], cl
	pop	eax
	xor	eax, ecx
	sub	eax, ecx
	push	ebx
	movzx	ebx, ax
	shr	ebx, 13
	xor	ax, bx
	pop	ebx

	push	ebx
	mov	ebx, 3
yphJv:
	neg	eax

	push	ebx
	mov	ebx, 4
HEZpK:

	push	ebx
	mov	ebx, 4
NcHjl:
	sub	eax, 02903h
	rol	ax, 8
	dec	ebx
	jne	NcHjl
	pop	ebx

	not	eax
	dec	ebx
	jne	HEZpK
	pop	ebx

	dec	ebx
	jne	yphJv
	pop	ebx


	push	ebx
	mov	ebx, 3
MRUEB:

	push	ebx
	mov	ebx, 2
PMYSk:
	neg	eax
	dec	ebx
	jne	PMYSk
	pop	ebx

	dec	ebx
	jne	MRUEB
	pop	ebx

	add	eax, ecx
	rol	ax, 8
	mov	word ptr [edx + ecx], ax
	inc	ecx
	dec	ebx
	jne	@b

MASM encryption (ANSI Example)

Plaintext reference: StringEncrypt sample

; encrypted with https://www.stringencrypt.com (v1.5.0) [MASM Assembler (32 bit)]

.data

	; myString = "StringEncrypt sample"
	myString	db 0CFh, 0AAh, 0DDh, 0D5h, 0D5h, 005h, 008h, 0A9h, 0A5h, 0A0h, 028h, 0A3h, 0A8h, 073h, 0FEh, 041h
                        db 044h, 024h, 0DFh, 052h, 0FAh

.code
	mov	ecx, offset myString
	mov	ebx, 21
	and	eax, 0

@@:
	mov	dl, byte ptr [ecx + eax]
	push	ebx
	movzx	ebx, dl
	shr	ebx, 6
	xor	dl, bl
	pop	ebx
	dec	edx
	neg	edx

	push	ebx
	mov	ebx, 2
xFJnC:

	push	ebx
	mov	ebx, 3
IPaMj:

	push	ebx
	mov	ebx, 3
dKmVn:
	dec	edx
	dec	ebx
	jne	dKmVn
	pop	ebx

	dec	ebx
	jne	IPaMj
	pop	ebx

	add	edx, 043h

	push	ebx
	mov	ebx, 4
TDLqN:
	sub	edx, eax
	dec	ebx
	jne	TDLqN
	pop	ebx

	dec	ebx
	jne	xFJnC
	pop	ebx

	push	edx
	mov	cl, al
	ror	byte ptr [esp], cl
	pop	edx

	push	ebx
	mov	ebx, 2
CAaGy:
	push	ebx
	movzx	ebx, dl
	shl	ebx, 4
	and	bl, 0xFF
	xor	dl, bl
	pop	ebx
	inc	edx
	dec	ebx
	jne	CAaGy
	pop	ebx

	xor	edx, 0CFh
	push	edx
	mov	cl, al
	rol	byte ptr [esp], cl
	pop	edx

	push	ebx
	mov	ebx, 3
hPmrL:
	push	ebx
	movzx	ebx, dl
	shr	ebx, 5
	xor	dl, bl
	pop	ebx
	dec	edx
	dec	ebx
	jne	hPmrL
	pop	ebx

	mov	byte ptr [ecx + eax], dl
	inc	eax
	dec	ebx
	jne	@b