Function at 0x508667
Capabilities:
Encrypt data using speck

Disassembly:
push ebp
mov ebp, esp
sub esp, 0x38
push ebx
xor ebx, ebx
test byte [ebp + 0x10], 0x80
push esi
push edi
mov esi, eax
mov dword [ebp - 0x24], ebx
mov dword [ebp - 0x28], ebx
mov byte [ebp - 2], bl
mov dword [ebp - 0x38], 0xc
mov dword [ebp - 0x34], ebx
je 0x508696
mov dword [ebp - 0x30], ebx
mov byte [ebp - 1], 0x10
jmp 0x5086a0
mov dword [ebp - 0x30], 1
mov byte [ebp - 1], bl
lea eax, [ebp - 0x24]
push eax
call fcn.004f6d61
test eax, eax
pop ecx
je 0x5086bb
push ebx
push ebx
push ebx
push ebx
push ebx
call fcn.004ee7ee
add esp, 0x14
lea eax, [ebp - 0x28]
push eax
call fcn.004f461c
test eax, eax
pop ecx
je 0x5086d6
push ebx
push ebx
push ebx
push ebx
push ebx
call fcn.004ee7ee
add esp, 0x14
mov ecx, dword [ebp + 0x10]
mov eax, 0x8000
test eax, ecx
jne 0x5086f3
test ecx, 0x74000
jne 0x5086ef
cmp dword [ebp - 0x24], eax
je 0x5086f3
or byte [ebp - 1], 0x80
mov eax, ecx
and eax, 3
sub eax, ebx
mov edx, 0xc0000000
mov edi, SysReAllocString
je 0x50874d
dec eax
je 0x508737
dec eax
je 0x508732
call fcn.004f5c43
mov dword [eax], ebx
or dword [esi], 0xffffffff
call fcn.004f5c30
push 0x16
pop esi
push ebx
push ebx
push ebx
push ebx
push ebx
mov dword [eax], esi
call fcn.004ee8ea
add esp, 0x14
jmp 0x508d00
mov dword [ebp - 8], edx
jmp 0x508750
test cl, 8
je 0x508744
test ecx, 0x70000
jne 0x508732
mov dword [ebp - 8], 0x40000000
jmp 0x508750
mov dword [ebp - 8], edi
mov eax, dword [ebp + 0x14]
push 0x10
pop ecx
sub eax, ecx
je 0x508791
sub eax, ecx
je 0x508788
sub eax, ecx
je 0x50877f
sub eax, ecx
je 0x508776
sub eax, 0x40
jne 0x50870c
cmp dword [ebp - 8], edi
sete al
mov dword [ebp - 0x10], eax
jmp 0x508794
mov dword [ebp - 0x10], 3
jmp 0x508794
mov dword [ebp - 0x10], 2
jmp 0x508794
mov dword [ebp - 0x10], 1
jmp 0x508794
mov dword [ebp - 0x10], ebx
mov eax, dword [ebp + 0x10]
mov edx, 0x700
and eax, edx
mov ecx, 0x400
cmp eax, ecx
mov edi, 0x100
jg 0x5087e7
je 0x5087de
cmp eax, ebx
je 0x5087de
cmp eax, edi
je 0x5087d5
cmp eax, 0x200
je 0x50885a
cmp eax, 0x300
jne 0x50870c
mov dword [ebp - 0x14], 2
jmp 0x508804
mov dword [ebp - 0x14], 4
jmp 0x508804
mov dword [ebp - 0x14], 3
jmp 0x508804
cmp eax, 0x500
je 0x5087fd
cmp eax, 0x600
je 0x50885a
cmp eax, edx
jne 0x50870c
mov dword [ebp - 0x14], 1
mov eax, dword [ebp + 0x10]
test edi, eax
mov dword [ebp - 0xc], 0x80
je 0x508828
mov ecx, dword [0x55db74]
not ecx
and ecx, dword [ebp + 0x18]
test cl, cl
js 0x508828
mov dword [ebp - 0xc], 1
test al, 0x40
je 0x508844
or dword [ebp - 0xc], 0x4000000
or dword [ebp - 8], 0x10000
cmp dword [ebp - 0x28], 2
jne 0x508844
or dword [ebp - 0x10], 4
test ax, 0x1000
je 0x50884d
or dword [ebp - 0xc], edi
test al, 0x20
je 0x508863
or dword [ebp - 0xc], 0x8000000
jmp 0x50886e
mov dword [ebp - 0x14], 5
jmp 0x508804
test al, 0x10
je 0x50886e
or dword [ebp - 0xc], 0x10000000
call fcn.004f1b3b
cmp eax, 0xffffffff
mov dword [esi], eax
jne 0x508894
call fcn.004f5c43
mov dword [eax], ebx
or dword [esi], 0xffffffff
call fcn.004f5c30
mov dword [eax], 0x18
jmp 0x508922
mov eax, dword [ebp + 8]
mov edi, dword [sym.imp.KERNEL32.dll_CreateFileW]
push ebx
push dword [ebp - 0xc]
mov dword [eax], 1
push dword [ebp - 0x14]
lea eax, [ebp - 0x38]
push eax
push dword [ebp - 0x10]
push dword [ebp - 8]
push dword [ebp + 0xc]
call edi
cmp eax, 0xffffffff
mov dword [ebp - 0x1c], eax
jne 0x50892e
mov ecx, dword [ebp - 8]
mov eax, 0xc0000000
and ecx, eax
cmp ecx, eax
jne 0x5088fa
test byte [ebp + 0x10], 1
je 0x5088fa
and dword [ebp - 8], 0x7fffffff
push ebx
push dword [ebp - 0xc]
lea eax, [ebp - 0x38]
push dword [ebp - 0x14]
push eax
push dword [ebp - 0x10]
push dword [ebp - 8]
push dword [ebp + 0xc]
call edi
cmp eax, 0xffffffff
mov dword [ebp - 0x1c], eax
jne 0x50892e
mov esi, dword [esi]
mov eax, esi
and esi, 0x1f
imul esi, esi, 0x38
sar eax, 5
mov eax, dword [eax*4 + 0x55eec0]
lea eax, [eax + esi + 4]
and byte [eax], 0xfe
call dword [sym.imp.KERNEL32.dll_GetLastError]
push eax
call fcn.004f5c56
pop ecx
call fcn.004f5c30
mov eax, dword [eax]
jmp 0x508dbc
push dword [ebp - 0x1c]
call dword [sym.imp.KERNEL32.dll_GetFileType]
cmp eax, ebx
jne 0x50897f
mov esi, dword [esi]
mov eax, esi
and esi, 0x1f
imul esi, esi, 0x38
sar eax, 5
mov eax, dword [eax*4 + 0x55eec0]
lea eax, [eax + esi + 4]
and byte [eax], 0xfe
call dword [sym.imp.KERNEL32.dll_GetLastError]
mov esi, eax
push esi
call fcn.004f5c56
pop ecx
push dword [ebp - 0x1c]
call dword [sym.imp.KERNEL32.dll_CloseHandle]
cmp esi, ebx
jne 0x508922
call fcn.004f5c30
mov dword [eax], 0xd
jmp 0x508922
cmp eax, 2
jne 0x50898a
or byte [ebp - 1], 0x40
jmp 0x508993
cmp eax, 3
jne 0x508993
or byte [ebp - 1], 8
push dword [ebp - 0x1c]
push dword [esi]
call fcn.004f190a
mov eax, dword [esi]
mov edx, eax
and eax, 0x1f
imul eax, eax, 0x38
sar edx, 5
mov edx, dword [edx*4 + 0x55eec0]
pop ecx
pop ecx
mov cl, byte [ebp - 1]
or cl, 1
mov byte [edx + eax + 4], cl
mov eax, dword [esi]
mov edx, eax
and eax, 0x1f
imul eax, eax, 0x38
sar edx, 5
mov edx, dword [edx*4 + 0x55eec0]
lea eax, [edx + eax + 0x24]
and byte [eax], 0x80
mov byte [ebp - 3], cl
and byte [ebp - 3], 0x48
mov byte [ebp - 1], cl
jne 0x508a69
test cl, 0x80
je 0x508b39
test byte [ebp + 0x10], 2
je 0x508a69
push 2
or edi, 0xffffffff
push edi
push dword [esi]
call fcn.004fc0ec
add esp, 0xc
cmp eax, edi
mov dword [ebp - 0x18], eax
jne 0x508a27
call fcn.004f5c43
cmp dword [eax], 0x83
je 0x508a69
push dword [esi]
call fcn.004fbccb
jmp 0x508921
push 1
lea eax, [ebp - 0x2c]
push eax
push dword [esi]
mov dword [ebp - 0x2c], ebx
call fcn.004fd0b5
add esp, 0xc
test eax, eax
jne 0x508a59
cmp word [ebp - 0x2c], 0x1a
jne 0x508a59
mov eax, dword [ebp - 0x18]
cdq
push edx
push eax
push dword [esi]
call fcn.004f11e4
add esp, 0xc
cmp eax, edi
je 0x508a1b
push ebx
push ebx
push dword [esi]
call fcn.004fc0ec
add esp, 0xc
cmp eax, edi
je 0x508a1b
test byte [ebp - 1], 0x80
je 0x508b39
mov ecx, 0x74000
test dword [ebp + 0x10], ecx
mov edi, 0x4000
jne 0x508a91
mov eax, dword [ebp - 0x24]
and eax, ecx
jne 0x508a8e
or dword [ebp + 0x10], edi
jmp 0x508a91
or dword [ebp + 0x10], eax
mov eax, dword [ebp + 0x10]
and eax, ecx
cmp eax, edi
je 0x508ade
cmp eax, 0x10000
je 0x508aca
cmp eax, 0x14000
je 0x508aca
cmp eax, 0x20000
je 0x508ad8
cmp eax, 0x24000
je 0x508ad8
cmp eax, 0x40000
je 0x508ac4
cmp eax, 0x44000
jne 0x508ae1
mov byte [ebp - 2], 1
jmp 0x508ae1
mov ecx, dword [ebp + 0x10]
mov eax, 0x301
and ecx, eax
cmp ecx, eax
jne 0x508ae1
mov byte [ebp - 2], 2
jmp 0x508ae1
mov byte [ebp - 2], bl
test dword [ebp + 0x10], 0x70000
je 0x508b39
test byte [ebp - 1], 0x40
mov dword [ebp - 0x18], ebx
jne 0x508b39
mov eax, dword [ebp - 8]
mov ecx, 0xc0000000
and eax, ecx
cmp eax, 0x40000000
je 0x508c93
cmp eax, 0x80000000
je 0x508c5a
cmp eax, ecx
jne 0x508b39
mov eax, dword [ebp - 0x14]
cmp eax, ebx
jbe 0x508b39
cmp eax, 2
jbe 0x508d3b
cmp eax, 4
jbe 0x508c2c
cmp eax, 5
je 0x508d3b
mov eax, dword [esi]
mov ecx, eax
and eax, 0x1f
imul eax, eax, 0x38
sar ecx, 5
mov ecx, dword [ecx*4 + 0x55eec0]
lea eax, [ecx + eax + 0x24]
mov cl, byte [eax]
xor cl, byte [ebp - 2]
and cl, 0x7f
xor byte [eax], cl
mov eax, dword [esi]
mov ecx, eax
and eax, 0x1f
imul eax, eax, 0x38
sar ecx, 5
mov ecx, dword [ecx*4 + 0x55eec0]
lea eax, [ecx + eax + 0x24]
mov ecx, dword [ebp + 0x10]
mov dl, byte [eax]
shr ecx, 0x10
shl cl, 7
and dl, 0x7f
or cl, dl
cmp byte [ebp - 3], bl
mov byte [eax], cl
jne 0x508bab
test byte [ebp + 0x10], 8
je 0x508bab
mov eax, dword [esi]
mov ecx, eax
and eax, 0x1f
imul eax, eax, 0x38
sar ecx, 5
mov ecx, dword [ecx*4 + 0x55eec0]
lea eax, [ecx + eax + 4]
or byte [eax], 0x20
mov edi, dword [ebp - 8]
mov eax, 0xc0000000
mov ecx, edi
and ecx, eax
cmp ecx, eax
jne 0x508dba
test byte [ebp + 0x10], 1
je 0x508dba
push dword [ebp - 0x1c]
call dword [sym.imp.KERNEL32.dll_CloseHandle]
push ebx
push dword [ebp - 0xc]
lea eax, [ebp - 0x38]
push 3
push eax
push dword [ebp - 0x10]
and edi, 0x7fffffff
push edi
push dword [ebp + 0xc]
call dword [sym.imp.KERNEL32.dll_CreateFileW]
cmp eax, 0xffffffff
jne 0x508da3
call dword [sym.imp.KERNEL32.dll_GetLastError]
push eax
call fcn.004f5c56
mov eax, dword [esi]
mov ecx, eax
and eax, 0x1f
imul eax, eax, 0x38
sar ecx, 5
mov ecx, dword [ecx*4 + 0x55eec0]
lea eax, [ecx + eax + 4]
and byte [eax], 0xfe
push dword [esi]
call fcn.004f1987
pop ecx
jmp 0x508921
push 2
push ebx
push ebx
push dword [esi]
call fcn.005023de
add esp, 0x10
or eax, edx
je 0x508d3b
push ebx
push ebx
push ebx
push dword [esi]
call fcn.005023de
and eax, edx
add esp, 0x10
cmp eax, 0xffffffff
je 0x508a1b
push 3
lea eax, [ebp - 0x18]
push eax
push dword [esi]
call fcn.004fd0b5
add esp, 0xc
cmp eax, 0xffffffff
je 0x508a1b
cmp eax, 2
je 0x508cdf
cmp eax, 3
jne 0x508d2d
cmp dword [ebp - 0x18], 0xbfbbef
jne 0x508cdf
mov byte [ebp - 2], 1
jmp 0x508b39
mov eax, dword [ebp - 0x14]
cmp eax, ebx
jbe 0x508b39
cmp eax, 2
jbe 0x508d3b
cmp eax, 4
ja 0x508b30
push 2
push ebx
push ebx
push dword [esi]
call fcn.005023de
add esp, 0x10
or eax, edx
je 0x508d3b
push ebx
push ebx
push ebx
push dword [esi]
call fcn.005023de
add esp, 0x10
and eax, edx
cmp eax, 0xffffffff
jne 0x508b39
jmp 0x508a1b
mov eax, dword [ebp - 0x18]
and eax, 0xffff
cmp eax, 0xfffe
jne 0x508d07
push dword [esi]
call fcn.004fbccb
pop ecx
call fcn.004f5c30
push 0x16
pop esi
mov dword [eax], esi
mov eax, esi
jmp 0x508dbc
cmp eax, 0xfeff
jne 0x508d2d
push ebx
push 2
push dword [esi]
call fcn.004fc0ec
add esp, 0xc
cmp eax, 0xffffffff
je 0x508a1b
mov byte [ebp - 2], 2
jmp 0x508b39
push ebx
push ebx
push dword [esi]
call fcn.004fc0ec
add esp, 0xc
jmp 0x508cd1
movsx eax, byte [ebp - 2]
xor edi, edi
dec eax
je 0x508d5b
dec eax
jne 0x508b39
mov dword [ebp - 0x18], 0xfeff
mov dword [ebp - 0x14], 2
jmp 0x508d69
mov dword [ebp - 0x18], 0xbfbbef
mov dword [ebp - 0x14], 3
mov eax, dword [ebp - 0x14]
sub eax, edi
push eax
lea eax, [ebp + edi - 0x18]
push eax
push dword [esi]
call fcn.00502302
add esp, 0xc
cmp eax, 0xffffffff
je 0x508d8f
add edi, eax
cmp dword [ebp - 0x14], edi
jg 0x508d69
jmp 0x508b39
push dword [esi]
call fcn.004fbccb
pop ecx
call fcn.004f5c30
mov eax, dword [eax]
mov dword [ebp - 0x20], eax
jmp 0x508dbc
mov esi, dword [esi]
mov ecx, esi
sar ecx, 5
mov ecx, dword [ecx*4 + 0x55eec0]
and esi, 0x1f
imul esi, esi, 0x38
mov dword [esi + ecx], eax
mov eax, ebx
pop edi
pop esi
pop ebx
leave
ret