Function at 0x401820
Capabilities:
Contain obfuscated stackstrings
Resolve function by parsing pe exports
Write file on windows

Disassembly:
push ebp
mov ebp, esp
and esp, 0xfffffff8
sub esp, 0xf8
mov eax, dword [0x405010]
xor eax, esp
mov dword [esp + 0xf4], eax
push esi
push edi
push 0x70
lea eax, [esp + 0x2c]
mov edi, edx
mov esi, ecx
mov dword [esp + 0x10], edi
push 0
push eax
mov dword [esp + 0x28], esi
call sub.ntdll.dll_memset
mov ecx, 1
mov dword [esp + 0x20], 0
xor eax, eax
mov dword [esp + 0x30], ecx
add esp, 0xc
mov dword [esp + 8], eax
cmp esi, ecx
jle 0x4019e7
mov dl, byte [esp + 0x2c]
mov esi, dword [sym.imp.ntdll.dll_strchr]
mov dword [esp + 0x18], edx
nop word [eax + eax]
mov edi, dword [edi + ecx*4]
cmp byte [edi], 0x2d
jne 0x401991
push 0x3f
push edi
call esi
add esp, 8
test eax, eax
jne 0x4023da
push 0x68
push edi
call esi
add esp, 8
test eax, eax
jne 0x4023da
push 0x64
push edi
call esi
mov ecx, dword [esp + 0x20]
test eax, eax
movzx ecx, cl
mov eax, 1
cmovne ecx, eax
push 0x66
push edi
mov dword [esp + 0x28], ecx
mov byte [esp + 0x3c], cl
call esi
mov esi, dword [esp + 0x18]
add esp, 0x10
test eax, eax
je 0x4018f1
or esi, 3
mov dword [esp + 8], esi
push 0x63
push edi
call dword [sym.imp.ntdll.dll_strchr]
add esp, 8
test eax, eax
je 0x401908
or esi, 2
mov dword [esp + 8], esi
push 0x6b
push edi
call dword [sym.imp.ntdll.dll_strchr]
add esp, 8
test eax, eax
je 0x40191f
or esi, 0xc
mov dword [esp + 8], esi
push 0x6c
push edi
call dword [sym.imp.ntdll.dll_strchr]
add esp, 8
test eax, eax
je 0x401936
or esi, 8
mov dword [esp + 8], esi
push 0x6d
push edi
call dword [sym.imp.ntdll.dll_strchr]
add esp, 8
test eax, eax
je 0x40194d
or esi, 0x10
mov dword [esp + 8], esi
push 0x6e
push edi
call dword [sym.imp.ntdll.dll_strchr]
add esp, 8
test eax, eax
je 0x401964
or esi, 0x20
mov dword [esp + 8], esi
mov esi, dword [sym.imp.ntdll.dll_strchr]
push 0x77
push edi
call esi
add esp, 8
test eax, eax
mov eax, dword [esp + 8]
je 0x401981
or eax, 0x40
mov dword [esp + 8], eax
mov edx, dword [esp + 0x14]
mov ecx, dword [esp + 0x24]
or edx, eax
mov dword [esp + 0x14], edx
jmp 0x4019cf
test al, 2
je 0x4019a3
test al, 0x18
jne 0x4023cd
mov dword [esp + 0x30], edi
jmp 0x4019c5
test al, 8
je 0x4019b5
test al, 0x12
jne 0x4023cd
mov dword [esp + 0x44], edi
jmp 0x4019c5
test al, 0x10
je 0x4019c5
test al, 0xa
jne 0x4023cd
mov dword [esp + 0x58], edi
mov edx, dword [esp + 0x14]
xor eax, eax
mov dword [esp + 8], eax
inc ecx
mov dword [esp + 0x24], ecx
cmp ecx, dword [esp + 0x1c]
jge 0x4019e3
mov edi, dword [esp + 0xc]
jmp 0x401890
test edx, edx
jne 0x401a05
push str.USB_programmer_for_WCH_MCUs_n
call fcn.00402680
add esp, 4
push str.use__h_for_command_line_help_n_n
call fcn.00402680
mov edx, dword [esp + 0x18]
add esp, 4
mov edi, edx
mov esi, 1
and edi, 0x40
je 0x401a23
push str.Waiting_for_device_..
mov esi, 0x28
call fcn.00402680
add esp, 4
lea ecx, [esp + 0x28]
call fcn.00401150
test al, al
jne 0x401a8e
sub esi, 1
je 0x4023e9
push 0x1f4
call dword [sym.imp.KERNEL32.dll_GetCurrentProcess]
push eax
call dword [sym.imp.KERNEL32.dll_WaitForSingleObject]
push 0
lea eax, [esp + 0x10]
mov dword [esp + 0x20], 0x2e
push eax
push 1
lea eax, [esp + 0x28]
mov dword [esp + 0x18], 1
push eax
push dword [0x4050a4]
call dword [sym.imp.KERNEL32.dll_WriteFile]
push dword [0x4050a4]
call dword [sym.imp.KERNEL32.dll_FlushFileBuffers]
lea ecx, [esp + 0x28]
call fcn.00401150
test al, al
je 0x401a30
test edi, edi
je 0x401abc
push 0
lea eax, [esp + 0x10]
mov dword [esp + 0x20], 0xa
push eax
push 1
lea eax, [esp + 0x28]
mov dword [esp + 0x18], 1
push eax
push dword [0x4050a4]
call dword [sym.imp.KERNEL32.dll_WriteFile]
push 6
lea eax, [esp + 0x10]
mov byte [esp + 0xa2], 0xa1
push eax
push 0x15
lea edx, [esp + 0xaa]
mov dword [esp + 0xab], 0x12
lea ecx, [esp + 0x34]
mov dword [esp + 0xaf], 0x2055434d
mov dword [esp + 0xb3], 0x20505349
mov dword [esp + 0xb7], 0x43572026
mov dword [esp + 0xbb], 0x4e432e48
call fcn.004012b0
test eax, eax
jne 0x4023df
mov dl, byte [esp + 0x11]
test dl, dl
je 0x40240e
cmp dword [str.CH551], eax
mov ecx, 0x403a20
mov al, byte [esp + 0x10]
mov dword [esp + 0x24], ecx
je 0x402418
cmp byte [ecx + 5], dl
jne 0x401b4b
cmp byte [ecx + 4], al
je 0x401b5d
add ecx, 0x18
mov dword [esp + 0x24], ecx
cmp dword [ecx], 0
je 0x402418
jmp 0x401b41
mov eax, dword [ecx + 0xc]
push dword [ecx]
mov dword [esp + 0x40], eax
mov eax, dword [ecx + 0x10]
push str.Found_device__s_n
mov dword [esp + 0x30], ecx
mov dword [esp + 0x58], eax
mov dword [esp + 0x6c], eax
call fcn.00402680
add esp, 8
mov byte [esp + 0xc], 0xa7
lea eax, [esp + 0x9e]
mov dword [esp + 0xd], 0x1f0002
lea edx, [esp + 0xc]
lea ecx, [esp + 0x28]
push 0x1e
push eax
push 5
call fcn.004012b0
test eax, eax
jne 0x40242a
mov ecx, dword [esp + 0x24]
lea esi, [esp + 0xb4]
mov eax, dword [esp + 0xb0]
lea edi, [esp + 0x78]
bswap eax
mov dword [esp + 0x74], eax
mov ecx, dword [ecx + 8]
rep movsb byte es:[edi], byte [esi]
lea esi, [esp + 0xa4]
mov ecx, 0xc
lea edi, [esp + 0x80]
rep movsb byte es:[edi], byte [esi]
movzx eax, byte [esp + 0x74]
mov edi, dword [esp + 0x74]
push eax
mov eax, edi
shr eax, 8
movzx eax, al
push eax
mov eax, edi
shr eax, 0x10
movzx eax, al
push eax
push str.Bootloader_version__d._d._d
call fcn.00402680
push str.Chip_ID:
call fcn.00402680
mov eax, dword [esp + 0x3c]
xor esi, esi
add esp, 0x14
cmp dword [eax + 8], esi
jle 0x401c52
test esi, esi
jle 0x401c35
push 0x4039b4
call fcn.00402680
add esp, 4
movzx eax, byte [esp + esi + 0x78]
push eax
push str._02x
call fcn.00402680
mov eax, dword [esp + 0x30]
inc esi
add esp, 8
cmp esi, dword [eax + 8]
jl 0x401c24
push 0
lea eax, [esp + 0x10]
mov dword [esp + 0x20], 0xa
push eax
push 1
lea eax, [esp + 0x28]
mov dword [esp + 0x18], 1
push eax
push dword [0x4050a4]
call dword [sym.imp.KERNEL32.dll_WriteFile]
cmp edi, 0x20600
ja 0x401ca8
je 0x401cbc
cmp edi, 0x20301
je 0x401c9e
cmp edi, 0x20400
je 0x401c9e
cmp edi, 0x20500
jmp 0x401cb6
mov byte [esp + 0x94], 0
jmp 0x401cc4
cmp edi, 0x20800
je 0x401cbc
cmp edi, 0x20900
jne 0x402434
mov byte [esp + 0x94], 1
mov esi, dword [esp + 0x28]
xor cl, cl
xor dl, dl
xor ch, ch
xor eax, eax
mov edi, dword [esi + 8]
cmp edi, 2
jl 0x401cf3
lea esi, [edi - 1]
nop dword [eax + eax]
add cl, byte [esp + eax + 0x78]
add dl, byte [esp + eax + 0x79]
add eax, 2
cmp eax, esi
jl 0x401ce0
mov esi, dword [esp + 0x28]
cmp eax, edi
jge 0x401cfb
mov ch, byte [esp + eax + 0x78]
mov al, byte [esi + 4]
add cl, dl
add ch, cl
mov cl, ch
movzx ecx, cl
imul ecx, ecx, 0x1010101
mov dword [esp + 0x90], ecx
add byte [esp + 0x93], al
mov eax, dword [esp + 0x14]
mov dword [esp + 0x8c], ecx
test al, 0x1c
je 0x401d34
cmp dword [esi + 0x10], 0
je 0x40243e
test al, 3
je 0x401d7b
lea edx, [esp + 0x30]
call fcn.004013a0
mov esi, dword [esp + 0x38]
xor edx, edx
mov ecx, dword [esp + 0x40]
test esi, esi
jle 0x401d6d
nop
mov eax, edx
and eax, 0x80000007
jns 0x401d5e
dec eax
or eax, 0xfffffff8
inc eax
mov al, byte [esp + eax + 0x8c]
inc edx
xor byte [ecx], al
inc ecx
cmp edx, esi
jl 0x401d50
cmp byte [esp + 0x34], 0
mov eax, dword [esp + 0x14]
sete byte [esp + 0x34]
test al, 0xc
je 0x401d8c
lea edx, [esp + 0x44]
call fcn.004013a0
mov eax, dword [esp + 0x14]
test al, 1
je 0x401ed9
lea ecx, [esp + 0x28]
call fcn.004014b0
mov edx, dword [esp + 0x28]
lea esi, [esp + 0x80]
xorps xmm0, xmm0
mov byte [esp + 0x9e], 0xa8
mov dword [esp + 0x9f], 0x7000e
lea edi, [esp + 0xa3]
movq qword [esp + 0xa3], xmm0
mov ecx, 0xc
mov dword [esp + 0xab], 0
rep movsb byte es:[edi], byte [esi]
cmp byte [edx + 0x14], 0
mov esi, 0xa5
je 0x401e05
cmp byte [esp + 0xa3], 0xff
movzx ecx, byte [esp + 0xa3]
cmove ecx, esi
mov byte [esp + 0xa3], cl
cmp byte [edx + 0x16], 0
je 0x401e13
and byte [esp + 0xab], 0x7f
push 6
lea eax, [esp + 0x10]
push eax
push 0x11
lea edx, [esp + 0xaa]
lea ecx, [esp + 0x34]
call fcn.004012b0
test eax, eax
jne 0x402448
mov eax, 4
mov byte [esp + 0x1c], 0xa4
mov word [esp + 0x1d], ax
mov ecx, 8
xor eax, eax
mov word [esp + 0x21], ax
mov eax, dword [esp + 0x38]
add eax, 0x3ff
and eax, 0xfffffc00
cdq
and edx, 0x3ff
add eax, edx
lea edx, [esp + 0x1c]
sar eax, 0xa
cmp eax, ecx
push 6
cmovl eax, ecx
lea ecx, [esp + 0x2c]
mov word [esp + 0x23], ax
lea eax, [esp + 0x10]
push eax
push 7
call fcn.004012b0
test eax, eax
jne 0x402452
cmp word [esp + 0x10], ax
jne 0x40245c
push str.Write_code_flash_..
call fcn.00402680
add esp, 4
lea eax, [esp + 0xc]
mov edx, esi
lea ecx, [esp + 0x28]
push 1
push eax
lea eax, [esp + 0x38]
push eax
call fcn.004015d0
test eax, eax
jne 0x402466
push str.done_n
call fcn.00402680
mov eax, dword [esp + 0x18]
add esp, 4
test al, 2
je 0x401f26
lea ecx, [esp + 0x28]
call fcn.004014b0
push str.Verify_code_flash_..
call fcn.00402680
add esp, 4
lea eax, [esp + 0xc]
mov edx, 0xa6
lea ecx, [esp + 0x28]
push 1
push eax
lea eax, [esp + 0x38]
push eax
call fcn.004015d0
test eax, eax
jne 0x402474
push str.done_n
call fcn.00402680
mov eax, dword [esp + 0x18]
add esp, 4
test al, 4
je 0x402013
lea ecx, [esp + 0x28]
call fcn.004014b0
mov esi, dword [esp + 0x4c]
xor edx, edx
mov ecx, dword [esp + 0x54]
test esi, esi
jle 0x401f62
mov eax, edx
and eax, 0x80000007
jns 0x401f53
dec eax
or eax, 0xfffffff8
inc eax
mov al, byte [esp + eax + 0x8c]
inc edx
xor byte [ecx], al
inc ecx
cmp edx, esi
jl 0x401f45
cmp byte [esp + 0x48], 0
mov byte [esp + 0x1c], 0xa9
sete byte [esp + 0x48]
xor eax, eax
mov word [esp + 0x1d], ax
mov dword [esp + 0x1f], eax
mov eax, dword [esp + 0x28]
push 6
mov eax, dword [eax + 0x10]
add eax, 0x3ff
and eax, 0xfffffc00
cdq
and edx, 0x3ff
add eax, edx
lea edx, [esp + 0x20]
sar eax, 0xa
movzx ecx, al
cmp al, 1
mov eax, 1
cmovb ecx, eax
lea eax, [esp + 0x10]
push eax
mov byte [esp + 0x2b], cl
lea ecx, [esp + 0x30]
push 8
call fcn.004012b0
test eax, eax
jne 0x402482
cmp word [esp + 0x10], ax
jne 0x40248c
push str.Write_data_flash_..
call fcn.00402680
add esp, 4
lea eax, [esp + 0xc]
mov edx, 0xaa
lea ecx, [esp + 0x28]
push 0
push eax
lea eax, [esp + 0x4c]
push eax
call fcn.004015d0
test eax, eax
jne 0x402496
push str.done_n
call fcn.00402680
mov eax, dword [esp + 0x18]
add esp, 4
test al, 0x18
je 0x4021f7
push str.Read_data_flash_..
call fcn.00402680
mov esi, dword [esp + 0x68]
add esp, 4
xor eax, eax
mov byte [esp + 0x9e], 0xab
mov word [esp + 0x9f], ax
mov dword [esp + 0xa1], eax
push esi
push 8
push dword [0x4050a0]
mov word [esp + 0xb1], ax
mov dword [esp + 0x30], esi
mov dword [esp + 0x6c], esi
call dword [sym.imp.KERNEL32.dll_HeapAlloc]
mov dword [esp + 0x18], eax
test eax, eax
je 0x4024a4
mov dword [esp + 0x68], eax
xor edi, edi
mov dword [esp + 0x1c], edi
test esi, esi
je 0x4021e0
mov ecx, dword [esp + 0x70]
mov eax, 0x3a
cmp esi, eax
mov dword [esp + 0xa1], edi
mov dword [esp + 8], 0
cmovl eax, esi
mov dword [esp + 0xc], eax
mov word [esp + 0xa5], ax
lea eax, [esp + 8]
cmp ecx, 0xffffffff
je 0x40211d
push eax
lea eax, [esp + 0xa2]
mov dword [esp + 0xc], 9
push eax
push 2
push ecx
call dword [sym.imp.ch375dll.dll_CH375WriteEndP]
test al, al
je 0x4024ae
cmp byte [esp + 0x2c], 0
je 0x4020f2
push dword [esp + 8]
lea edx, [esp + 0xa2]
mov ecx, str.request
call fcn.004010b0
lea eax, [esp + 8]
mov dword [esp + 8], 0x40
push eax
lea eax, [esp + 0xc0]
push eax
push 2
push dword [esp + 0x7c]
call dword [sym.imp.ch375dll.dll_CH375ReadEndP]
test al, al
je 0x4024ae
jmp 0x40218d
push 0x1388
push eax
push 9
lea eax, [esp + 0xaa]
push eax
push 2
push dword [esp + 0x80]
call dword [sym.imp.libusb_1.0.dll_libusb_bulk_transfer]
test eax, eax
jne 0x4024ae
cmp byte [esp + 0x2c], al
je 0x40215f
push dword [esp + 8]
lea edx, [esp + 0xa2]
mov ecx, str.request
call fcn.004010b0
push 0x1388
lea eax, [esp + 0xc]
push eax
push 0x40
lea eax, [esp + 0xc8]
push eax
push 0x82
push dword [esp + 0x80]
call dword [sym.imp.libusb_1.0.dll_libusb_bulk_transfer]
test eax, eax
jne 0x4024ae
cmp byte [esp + 0x2c], 0
je 0x4021a9
push dword [esp + 8]
lea edx, [esp + 0xc0]
mov ecx, str.response
call fcn.004010b0
cmp word [esp + 0xc0], 0
jne 0x4024ae
mov eax, dword [esp + 0xc]
lea esi, [esp + 0xc2]
add edi, dword [esp + 0x18]
mov ecx, eax
rep movsb byte es:[edi], byte [esi]
mov esi, dword [esp + 0x24]
mov edi, dword [esp + 0x1c]
sub esi, eax
mov dword [esp + 0x24], esi
add edi, eax
jmp 0x402076
push str.done_n
call fcn.00402680
mov eax, dword [esp + 0x18]
add esp, 4
mov edi, dword [esp + 0x18]
jmp 0x4021ff
mov edi, dword [esp + 0x68]
mov dword [esp + 0x18], edi
test al, 8
je 0x4022c7
push str.Verify_data_flash_..
call fcn.00402680
mov al, byte [esp + 0x4c]
add esp, 4
mov edx, dword [esp + 0x54]
mov ecx, dword [esp + 0x4c]
test al, al
je 0x40225c
xor edi, edi
mov esi, edx
test ecx, ecx
jle 0x402251
nop dword [eax]
mov eax, edi
and eax, 0x80000007
jns 0x40223e
dec eax
or eax, 0xfffffff8
inc eax
mov al, byte [esp + eax + 0x8c]
inc edi
xor byte [esi], al
inc esi
cmp edi, ecx
jl 0x402230
mov al, byte [esp + 0x48]
mov edi, dword [esp + 0x18]
test al, al
sete byte [esp + 0x48]
mov esi, edi
sub ecx, 4
jb 0x402274
mov eax, dword [edx]
cmp eax, dword [esi]
jne 0x402279
add edx, 4
add esi, 4
sub ecx, 4
jae 0x402263
cmp ecx, 0xfffffffc
je 0x4022b6
mov al, byte [edx]
cmp al, byte [esi]
jne 0x4024b9
cmp ecx, 0xfffffffd
je 0x4022b6
mov al, byte [edx + 1]
cmp al, byte [esi + 1]
jne 0x4024b9
cmp ecx, 0xfffffffe
je 0x4022b6
mov al, byte [edx + 2]
cmp al, byte [esi + 2]
jne 0x4024b9
cmp ecx, 0xffffffff
je 0x4022b6
mov al, byte [edx + 3]
cmp al, byte [esi + 3]
jne 0x4024b9
push str.done_n
call fcn.00402680
mov eax, dword [esp + 0x18]
add esp, 4
test al, 0x10
je 0x40236b
push str.Dump_data_flash_..
call fcn.00402680
mov ecx, dword [esp + 0x5c]
add esp, 4
mov edx, 0x403758
call fcn.00402510
mov esi, eax
test esi, esi
je 0x4024c3
push 0
lea eax, [esp + 0x20]
mov dword [esp + 0x20], 0
push eax
push dword [esp + 0x58]
push edi
push dword [esi]
call dword [sym.imp.KERNEL32.dll_WriteFile]
test eax, eax
je 0x4024e5
mov ecx, dword [esp + 0x1c]
test ecx, ecx
je 0x4024e5
mov eax, dword [esp + 0x28]
cmp ecx, dword [eax + 0x10]
jne 0x4024e5
push dword [esi]
call dword [sym.imp.KERNEL32.dll_FlushFileBuffers]
mov eax, dword [esi]
test eax, eax
je 0x40234b
cmp eax, 0xffffffff
je 0x40234b
push eax
call dword [sym.imp.KERNEL32.dll_CloseHandle]
push esi
push 0
push dword [0x4050a0]
call dword [sym.imp.KERNEL32.dll_HeapFree]
push str.done_n
call fcn.00402680
mov eax, dword [esp + 0x18]
add esp, 4
and al, 0x21
cmp al, 1
jne 0x4023b7
mov eax, 1
mov byte [esp + 0x18], 0xa2
mov word [esp + 0x19], ax
lea edx, [esp + 0x18]
mov byte [esp + 0x1b], al
lea ecx, [esp + 0x28]
push 6
lea eax, [esp + 0x10]
push eax
push 4
call fcn.004012b0
cmp byte [esp + 0x94], 0
je 0x4023b7
test eax, eax
jne 0x4024db
cmp word [esp + 0x10], ax
jne 0x4024ef
mov ecx, dword [esp + 0xfc]
xor eax, eax
pop edi
pop esi
xor ecx, esp
call fcn.004028b0
mov esp, ebp
pop ebp
ret
push str.Invalid_command_line._n
call fcn.00402680
add esp, 4
call fcn.004017a0
push str.Cant_get_the_device_type._n
call fcn.00401090
test edi, edi
je 0x4023f7
mov ecx, 0xa
call fcn.00402650
push str.Device_not_found._n
call fcn.00402680
add esp, 4
mov ecx, 1
call fcn.00402840
push str.Chip_is_hosed._Reset_or_power_cycle_it._n
call fcn.00401090
movzx eax, al
push eax
movzx eax, dl
push eax
push str.Device_family_0x_02x_type_0x_02x_is_not_supported._n
call fcn.00401090
push str.Cant_get_the_device_configuration._n
call fcn.00401090
push str.This_bootloader_version_is_not_supported._n
call fcn.00401090
push str.This_device_does_not_have_a_data_flash._n
call fcn.00401090
push str.Cant_write_the_new_configuration._n
call fcn.00401090
push str.Cant_erase_the_code_flash._n
call fcn.00401090
push str.The_device_refused_to_erase_the_code_flash._n
call fcn.00401090
push dword [esp + 0xc]
push str.failure_at_offset__d._n
call fcn.00401090
push dword [esp + 0xc]
push str.failure_at_offset__d._n
call fcn.00401090
push str.Cant_erase_the_data_flash._n
call fcn.00401090
push str.The_device_refused_to_erase_the_data_flash._n
call fcn.00401090
push dword [esp + 0xc]
push str.failure_at_offset__d._n
call fcn.00401090
push str.Memory_allocation_error_n
call fcn.00401090
push edi
push str.failure_at_offset__d._n
call fcn.00401090
push str.data_doesnt_match._n
call fcn.00401090
call dword [sym.imp.KERNEL32.dll_GetLastError]
mov ecx, eax
call fcn.004025b0
push eax
push str.create_file_error:__s_n
call fcn.00401090
push str.Cant_reboot_the_device._n
call fcn.00401090
push str.write_file_error._n
call fcn.00401090
push str.The_device_refused_to_reboot._n
call fcn.00401090
int3