No GetPC(), requires ESI=EIP
If carriage-return is not acceptable, then 105 bytes

Assemble with Yasm

bits 32
key1 equ 60h
key2 equ 60h
key3 equ 60h
key4 equ 60h
%define CR_ALLOWED;if carriage-return not acceptable, then comment out but costs 3 bytes
_decoder:
push(key4 << 18h) + (key3 << 10h) + (key2 << 8) + key1
popebx
sub[esi + 00h + b64decode - _decoder], bx
sub[esi + 00h + b64decode - _decoder], bl
sub[esi + 06h + b64decode - _decoder], bx
%ifndef CR_ALLOWED
sub[esi + 07h + b64decode - _decoder], bl
%endif
sub[esi + 09h + b64decode - _decoder], bx
sub[esi + 0fh + b64decode - _decoder], ebx
sub[esi + 18h + b64decode - _decoder], bx
sub[esi + 1eh + b64decode - _decoder], bl
sub[esi + 20h + b64decode - _decoder], bl
sub[esi + 23h + b64decode - _decoder], ebx
sub[esi + 24h + b64decode - _decoder], bl
sub[esi + 27h + b64decode - _decoder], ebx
sub[esi + 2bh + b64decode - _decoder], ebx
sub[esi + 2bh + b64decode - _decoder], ebx
b64decode:
;addesi, b64decode_end - _decoder
;00
db(83h + key1 + key1) & 0ffh, (0c6h + 1 + key2) & 0ffh, b64decode_end - _decoder
pushesi
popedi
b64_outer:
;push4
;06
db6ah, (04h + key1) & 0ffh
;lodsd
;07
%ifndef CR_ALLOWED
db(0adh + key2 + key1) & 0ffh
%else
db(0adh + key2) & 0ffh
%endif
popecx
b64_inner:
;roleax, 28h ;we want 8, CPU performs &1fh, so we can encode as ASCII to avoid decoding
;09
db(0c1h + key1) & 0ffh, (0c0h + 1 + key2) & 0ffh, 28h
cmpal, '0'
;jnbb64_testchar
;0f
db73h, (05h + key1) & 0ffh
;shral, 2 ;because '+' and '/' differ by only 1 bit
db(0c0h + key2) & 0ffh, (0e8h + 1 + key3) & 0ffh, (02h + 1 + key4) & 0ffh
xoral, '0' ;concatenate numbers and '+' and '/'
b64_testupr:
cmpal, 'A'
;jnbb64_testlwr
;18
db73h, (02h + key1) & 0ffh
;addal, ('z' + 1) - '0' ;concatenate lowercase and numbers
db(04h + key1) & 0ffh, ('z' + 1) - '0'
b64_testlwr:
cmpal, 'a'
;jbb64_store
;1e
db72h, (02h + key1) & 0ffh
;subal, 6 ;concatenate uppercase and lowercase
;20
db2ch, (06h + key1) & 0ffh
b64_store:
subal, 'A'
;shrdebx, eax, 6
;23, 24
db(0fh + key1) & 0ffh, (0ach + key1 + key2) & 0ffh, (0c3h + key3) & 0ffh, (06h + 1 + key4) & 0ffh
;loopb64_inner
;27
db(0e2h + key1) & 0ffh, (0e0h + 1 + key2) & 0ffh
;bswapebx
db(0fh + 1 + key3) & 0ffh, (0cbh + key4) & 0ffh
;2b
;nop;alignment
db(90h + key1 + key1) & 0ffh
;xchgebx, eax
db(93h + 1 + key2 + key2) & 0ffh
;stosd
db(0abh + 1 + key3 + key3) & 0ffh
;cmpbyte [esi], '+'
db(80h + 1 + key4 + key4) & 0ffh, 3eh, 2bh
;[decedi]
;[jnbb64_outer]
;the dec and branch are base64-encoded to reduce size
b64decode_end:
db"T3PR"
;append your base64 data here
;terminate with printable character less than '+'

Copyright (c) 2014 Peter Ferrie
All rights reserved

This site is hosted by 000webhost.com



Free web hostingWeb hosting