FASM Encryption

FASM Encryption

FASM (flat assembler) is a popular self-hosted assembler with a clean syntax and fans in the OS-dev and sizecoding scenes. You get tiny binaries and full control over sections and imports—along with the usual problem that string data is trivial to spot in the file.

If you are shipping a crackme, a protector stub, or a small tool with embedded licence text, encrypting the literal and decrypting in place buys a little time against strings and friends. StringEncrypt outputs FASM-friendly code for Unicode or byte strings, matching the style of the examples on this page.

String encryption supports both UNICODE (DW type) and ANSI (DB type) strings.

You can read more about FASM at:

FASM encryption (UNICODE Example)

Plaintext reference: StringEncrypt sample

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

section '.data' data readable writable

	; myString = "StringEncrypt sample"
	myString dw 03D3Bh, 05B17h, 04214h, 0311Ah, 07012h, 05F16h, 05737h, 0B5EBh
                 dw 07413h, 0E3E1h, 06DF7h, 001FDh, 073F4h, 0ED27h, 059F1h, 025FEh
                 dw 05CF1h, 086CBh, 082CAh, 0A1CEh, 05F50h

section '.text' code readable executable

	mov	ecx, myString
	mov	eax, 21
	sub	ebx, ebx

@@:
	mov	dx, word [ecx + ebx]

	push	eax
	mov	eax, 3
HubBE:
	xor	edx, 0C091h
	dec	eax
	jne	HubBE
	pop	eax


	push	eax
	mov	eax, 3
eGjBd:

	push	eax
	mov	eax, 3
SdkaG:
	not	edx
	dec	eax
	jne	SdkaG
	pop	eax

	push	eax
	movzx	eax, dx
	shl	eax, 11
	and	ax, 0xFFFF
	xor	dx, ax
	pop	eax
	dec	eax
	jne	eGjBd
	pop	eax


	push	eax
	mov	eax, 3
NrPmt:
	dec	edx
	sub	edx, ebx
	rol	dx, 8
	dec	eax
	jne	NrPmt
	pop	eax

	dec	edx
	push	eax
	movzx	eax, dx
	shr	eax, 13
	xor	dx, ax
	pop	eax
	rol	dx, 8
	inc	edx
	sub	edx, ebx
	sub	edx, 05201h
	mov	word [ecx + ebx], dx
	inc	ebx
	dec	eax
	jne	@b

FASM encryption (ANSI Example)

Plaintext reference: StringEncrypt sample

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

section '.data' data readable writable

	; myString = "StringEncrypt sample"
	myString db 0B2h, 021h, 001h, 042h, 029h, 03Ch, 00Ch, 04Bh
                 db 052h, 04Fh, 078h, 09Dh, 09Fh, 075h, 0AAh, 0B2h
                 db 08Ch, 095h, 0A3h, 0E6h, 023h

section '.text' code readable executable

	mov	eax, myString
	mov	edx, 21
	and	ebx, 0

@@:
	mov	cl, byte [eax + ebx]

	push	edx
	mov	edx, 3
CnbuO:
	xor	ecx, ebx

	push	edx
	mov	edx, 4
EDhUX:
	sub	ecx, ebx
	dec	edx
	jne	EDhUX
	pop	edx

	dec	edx
	jne	CnbuO
	pop	edx

	sub	ecx, 0E4h
	neg	ecx

	push	edx
	mov	edx, 2
jtJNc:
	xor	ecx, 0F6h
	add	ecx, 007h
	dec	edx
	jne	jtJNc
	pop	edx

	xor	ecx, ebx
	not	ecx
	add	ecx, 0D2h
	xor	ecx, 034h
	add	ecx, 09Ah
	mov	byte [eax + ebx], cl
	inc	ebx
	dec	edx
	jne	@b