Function at 0x509be2
Capabilities:
Encode data using xor

Disassembly:
push ebp
mov ebp, esp
sub esp, 0x20
push edi
mov edi, dword [ebp + 0x14]
push edi
mov dword [ebp - 0x1c], edx
mov dword [ebp - 0x20], ecx
call fcn.00508bd9
pop ecx
test eax, eax
jne 0x509e6f
mov ecx, dword [ebp + 0x10]
call fcn.00509bca
test eax, eax
jne 0x509e6f
mov edx, dword [ebp + 0x18]
imul edi, edi, 0x68
test byte [ebp + 0x18], 7
mov eax, dword [edi + 0x567a68]
push ebx
mov ebx, dword [ebp + 8]
push esi
push 0
pop ecx
setne cl
shr edx, 3
mov dword [ebp - 0x14], eax
add ecx, edx
mov esi, ecx
cmp ebx, esi
ja 0x509e6a
lea eax, [eax + ebx + 2]
cmp esi, eax
jb 0x509e6a
push esi
call sub.msvcrt.dll_malloc
push esi
mov dword [ebp - 4], eax
call sub.msvcrt.dll_malloc
push esi
mov dword [ebp - 0xc], eax
call sub.msvcrt.dll_malloc
push esi
mov dword [ebp - 8], eax
call sub.msvcrt.dll_malloc
xor ecx, ecx
add esp, 0x10
mov dword [ebp - 0x10], eax
cmp dword [ebp - 4], ecx
je 0x509e39
cmp dword [ebp - 0xc], ecx
je 0x509e30
cmp dword [ebp - 8], ecx
je 0x509e30
cmp eax, ecx
je 0x509e30
cmp ebx, ecx
jbe 0x509cbc
mov eax, dword [ebp + 0x10]
push dword [ebp + 0xc]
imul eax, eax, 0x28
push ebx
push dword [ebp - 8]
call dword [eax + 0x8b16c4]
add esp, 0xc
cmp eax, ebx
je 0x509cbc
push 9
pop ebx
jmp 0x509e09
lea eax, [ebp - 0x18]
push eax
call dword [edi + fcn.00567ab4]
mov ebx, eax
pop ecx
test ebx, ebx
jne 0x509e09
push 8
push dword [ebp - 4]
call fcn.00508bbf
push 8
push dword [ebp - 4]
lea eax, [ebp - 0x18]
push eax
call dword [edi + fcn.00567ab8]
mov ebx, eax
add esp, 0x14
test ebx, ebx
jne 0x509e09
push dword [ebp - 0x1c]
lea eax, [ebp - 0x18]
push dword [ebp - 0x20]
push eax
call dword [edi + fcn.00567ab8]
mov ebx, eax
add esp, 0xc
test ebx, ebx
jne 0x509e09
push dword [ebp + 8]
lea eax, [ebp - 0x18]
push dword [ebp - 8]
push eax
call dword [edi + fcn.00567ab8]
mov ebx, eax
add esp, 0xc
test ebx, ebx
jne 0x509e09
push dword [ebp - 0x10]
lea eax, [ebp - 0x18]
push eax
call dword [edi + fcn.00567abc]
mov ebx, eax
pop ecx
pop ecx
test ebx, ebx
jne 0x509e09
mov edi, esi
sub edi, dword [ebp - 0x14]
mov eax, edi
sub eax, dword [ebp + 8]
dec eax
dec eax
push eax
push ebx
mov ebx, dword [ebp - 4]
push ebx
call sub.msvcrt.dll_memset
mov eax, dword [ebp - 0x14]
push dword [ebp + 8]
neg eax
push dword [ebp - 8]
mov dword [ebp + 0x10], eax
sub eax, dword [ebp + 8]
lea eax, [eax + esi - 2]
add eax, ebx
mov byte [eax], 1
inc eax
push eax
call sub.msvcrt.dll_memcpy
mov edx, dword [ebp - 0x10]
mov ecx, dword [ebp + 0x14]
add esp, 0x18
dec edi
push edi
push dword [ebp - 0xc]
push dword [ebp - 0x14]
call fcn.0050c4f3
mov ebx, eax
test ebx, ebx
jne 0x509e09
test edi, edi
jbe 0x509db5
mov eax, dword [ebp - 4]
mov ecx, dword [ebp - 0xc]
sub ecx, eax
mov edx, edi
mov bl, byte [ecx + eax]
xor byte [eax], bl
inc eax
dec edx
jne 0x509dac
mov eax, dword [ebp + 0x20]
cmp dword [eax], esi
jae 0x509dc1
push 6
pop ebx
jmp 0x509e07
push edi
push dword [ebp - 4]
mov edi, dword [ebp + 0x1c]
push edi
call sub.msvcrt.dll_memcpy
mov eax, dword [ebp + 0x10]
push dword [ebp - 0x14]
lea ebx, [eax + esi - 1]
push dword [ebp - 0x10]
lea eax, [ebx + edi]
push eax
call sub.msvcrt.dll_memcpy
mov eax, dword [ebp - 0x14]
mov ecx, esi
shl ecx, 3
sub ecx, dword [ebp + 0x18]
add ebx, eax
add esp, 0x18
inc ecx
mov eax, 0xff
sar eax, cl
mov byte [ebx + edi], 0xbc
and byte [edi], al
mov eax, dword [ebp + 0x20]
xor ebx, ebx
mov dword [eax], esi
push dword [ebp - 0x10]
call sub.msvcrt.dll_free
push dword [ebp - 8]
call sub.msvcrt.dll_free
push dword [ebp - 0xc]
call sub.msvcrt.dll_free
push dword [ebp - 4]
call sub.msvcrt.dll_free
add esp, 0x10
mov eax, ebx
jmp 0x509e6d
push dword [ebp - 4]
call sub.msvcrt.dll_free
pop ecx
cmp dword [ebp - 0xc], 0
je 0x509e48
push dword [ebp - 0xc]
call sub.msvcrt.dll_free
pop ecx
cmp dword [ebp - 8], 0
je 0x509e57
push dword [ebp - 8]
call sub.msvcrt.dll_free
pop ecx
cmp dword [ebp - 0x10], 0
je 0x509e66
push dword [ebp - 0x10]
call sub.msvcrt.dll_free
pop ecx
push 0xd
jmp 0x509e6c
push 0x16
pop eax
pop esi
pop ebx
pop edi
leave
ret 0x1c