// File: chenhn123[P]wdt_util_src/wdt_ct/wif2_handler.cpp
// Function: do_show_wif2_info_chunk(WifFile2*)
int do_show_wif2_info_chunk(WIF_FILE2 *pcur_wif)
{
	if (!pcur_wif)
		return 0;
	WIF2_Info_Chunk *pchunk_info_ex;
	pchunk_info_ex = (WIF2_Info_Chunk *)malloc(sizeof(WIF2_Info_Chunk));
	if (!pchunk_info_ex)
		return 0;
	int ret = 1;
	UINT32 chunk_start_pos = 0 + sizeof(ChunkHeader);
	WIF2_Chunk_Header *pchunk_data = NULL;

	while (chunk_start_pos < pcur_wif->data_len) {
		pchunk_data = (WIF2_Chunk_Header *)&pcur_wif->pdata[chunk_start_pos];
		/* we got it */
		if (pchunk_data->FourCC == FOURCC_ID_INFO) {
			pchunk_info_ex->Header.FourCC = pchunk_data->FourCC;
			pchunk_info_ex->Header.Size = pchunk_data->Size;
			pchunk_info_ex->BinaryData = (BYTE *)malloc(pchunk_data->Size);
			if (!pchunk_info_ex->BinaryData) {
				ret = 0;
				goto finish;
			}

			memcpy((BYTE *)pchunk_info_ex->BinaryData, (BYTE *)&pcur_wif->pdata[chunk_start_pos],
			       pchunk_data->Size);
			for (size_t i = 0; i < pchunk_data->Size; i++)
				printf("%c", (unsigned char)(pchunk_info_ex->BinaryData[i]));
			printf("\n");

			chunk_start_pos = chunk_start_pos + pchunk_data->Size + 8;
			if (pchunk_info_ex->BinaryData)
				free(pchunk_info_ex->BinaryData);

		} else {
			/* 8 is the header size */
			chunk_start_pos = chunk_start_pos + pchunk_data->Size + 8;
		}
	}
finish:
	if (pchunk_info_ex)
		free(pchunk_info_ex);

	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xe21f
movl $0x0, -0x4(%rbp)
jmp 0xe39d
movl $0x10, %edi
callq 0x21f0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xe240
movl $0x0, -0x4(%rbp)
jmp 0xe39d
movl $0x1, -0x1c(%rbp)
movl $0xc, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xe385
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x20(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x4f464e49, (%rax)     # imm = 0x4F464E49
jne 0xe370
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
callq 0x21f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xe2d1
movl $0x0, -0x1c(%rbp)
jmp 0xe387
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movl -0x20(%rbp), %eax
addq %rax, %rsi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
callq 0x2150
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jae 0xe338
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %esi
leaq 0x299e(%rip), %rdi      # 0x10cc1
movb $0x0, %al
callq 0x2050
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xe2fc
leaq 0x1988(%rip), %rdi      # 0xfcc7
movb $0x0, %al
callq 0x2050
movl -0x20(%rbp), %eax
movq -0x28(%rbp), %rcx
addl 0x4(%rcx), %eax
addl $0x8, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xe36e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x21e0
jmp 0xe380
movl -0x20(%rbp), %eax
movq -0x28(%rbp), %rcx
addl 0x4(%rcx), %eax
addl $0x8, %eax
movl %eax, -0x20(%rbp)
jmp 0xe256
jmp 0xe387
cmpq $0x0, -0x18(%rbp)
je 0xe397
movq -0x18(%rbp), %rdi
callq 0x21e0
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)