// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/zip.c
// Function: ef_infozipmac
static void ef_infozipmac(deark *c, lctx *d, struct extra_item_info_struct *eii)
{
	i64 pos = eii->dpos;
	i64 dpos;
	i64 ulen;
	i64 cmpr_attr_size;
	UI flags;
	int cmpr_meth;
	const struct cmpr_meth_info *cmi = NULL;
	struct de_fourcc filetype;
	struct de_fourcc creator;
	de_ucstring *flags_str = NULL;
	dbuf *attr_data = NULL;
	int ret;
	i64 create_time_raw;
	i64 create_time_offset;
	i64 mod_time_raw;
	i64 mod_time_offset;
	i64 backup_time_raw;
	i64 backup_time_offset;
	struct de_timestamp tmp_timestamp;
	int charset;
	u32 crc_reported = 0;
	UI dcflags = 0;
	struct de_stringreaderdata *srd;

	if(eii->dlen<14) goto done;

	ulen = de_getu32le_p(&pos);
	de_dbg(c, "uncmpr. finder attr. size: %d", (int)ulen);

	flags = (UI)de_getu16le_p(&pos);
	flags_str = ucstring_create(c);
	if(flags&0x0001) ucstring_append_flags_item(flags_str, "data_fork");
	if(flags&0x0002) ucstring_append_flags_item(flags_str, "0x0002"); // something about the filename
	ucstring_append_flags_item(flags_str,
		(flags&0x0004)?"uncmpressed_attribute_data":"compressed_attribute_data");
	if(flags&0x0008) ucstring_append_flags_item(flags_str, "64-bit_times");
	if(flags&0x0010) ucstring_append_flags_item(flags_str, "no_timezone_offsets");
	de_dbg(c, "flags: 0x%04x (%s)", flags, ucstring_getpsz(flags_str));

	dbuf_read_fourcc(c->infile, pos, &filetype, 4, 0x0);
	de_dbg(c, "filetype: '%s'", filetype.id_dbgstr);
	pos += 4;
	dbuf_read_fourcc(c->infile, pos, &creator, 4, 0x0);
	de_dbg(c, "creator: '%s'", creator.id_dbgstr);
	pos += 4;

	if(eii->is_central) goto done;

	if(flags&0x0004) { // Uncompressed attribute data
		cmpr_meth = 0;
	}
	else {
		dcflags |= 0x1; // CRC is known
		cmpr_meth = (int)de_getu16le_p(&pos);
		cmi = get_cmpr_meth_info(cmpr_meth);
		de_dbg(c, "finder attr. cmpr. method: %d (%s)", cmpr_meth, (cmi ? cmi->name : "?"));

		crc_reported = (u32)de_getu32le_p(&pos);
		de_dbg(c, "finder attr. data crc (reported): 0x%08x", (UI)crc_reported);
	}

	// The rest of the data is Finder attribute data
	cmpr_attr_size = eii->dpos+eii->dlen - pos;
	de_dbg(c, "cmpr. finder attr. size: %d", (int)cmpr_attr_size);
	if(ulen<1 || ulen>1000000) goto done;

	// Type 6 (implode) compression won't work here, because it needs
	// additional parameters seemingly not provided by the Finder attr data.
	if(cmpr_meth==6 || !is_compression_method_supported(d, cmi)) {
		de_warn(c, "Finder attribute data: Unsupported compression method: %d (%s)",
			cmpr_meth, (cmi ? cmi->name : "?"));
		goto done;
	}

	// Decompress and decode the Finder attribute data
	attr_data = dbuf_create_membuf(c, ulen, 0x1);
	ret = do_decompress_attrib_data(c, d, pos, cmpr_attr_size,
		attr_data, ulen, crc_reported, cmpr_meth, cmi, dcflags, "finder attr. data");
	if(!ret) {
		de_warn(c, "Failed to decompress finder attribute data");
		goto done;
	}

	dpos = 0;
	dpos += 2; // Finder flags
	dpos += 4; // Icon location
	dpos += 2; // Folder
	dpos += 16; // FXInfo
	dpos += 1; // file version number
	dpos += 1; // dir access rights

	if(flags&0x0008) goto done; // We don't support 64-bit times
	if(flags&0x0010) goto done; // We want timezone offsets
	if(attr_data->len - dpos < 6*4) goto done;

	create_time_raw = dbuf_getu32le_p(attr_data, &dpos);
	mod_time_raw    = dbuf_getu32le_p(attr_data, &dpos);
	backup_time_raw = dbuf_getu32le_p(attr_data, &dpos);
	create_time_offset = dbuf_geti32le(attr_data, dpos); dpos += 4;
	mod_time_offset    = dbuf_geti32le(attr_data, dpos); dpos += 4;
	backup_time_offset = dbuf_geti32le(attr_data, dpos); dpos += 4;

	handle_mac_time(c, d, create_time_raw, create_time_offset, &tmp_timestamp, "create time");
	if(create_time_raw>0) {
		apply_timestamp(c, d, eii->md, DE_TIMESTAMPIDX_CREATE, &tmp_timestamp, 40);
	}
	handle_mac_time(c, d, mod_time_raw,    mod_time_offset,    &tmp_timestamp, "mod time   ");
	if(mod_time_raw>0) {
		apply_timestamp(c, d, eii->md, DE_TIMESTAMPIDX_MODIFY, &tmp_timestamp, 40);
	}
	handle_mac_time(c, d, backup_time_raw, backup_time_offset, &tmp_timestamp, "backup time");
	if(backup_time_raw>0) {
		apply_timestamp(c, d, eii->md, DE_TIMESTAMPIDX_BACKUP, &tmp_timestamp, 40);
	}

	// Expecting 2 bytes for charset, and at least 2 more for the 2 NUL-terminated
	// strings that follow.
	if(attr_data->len - dpos < 4) goto done;

	charset = (int)dbuf_getu16le_p(attr_data, &dpos);
	de_dbg(c, "charset for fullpath/comment: %d", charset);

	// TODO: Can we use the correct encoding?
	srd = dbuf_read_string(attr_data, dpos, attr_data->len-dpos, DE_DBG_MAX_STRLEN,
		DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_ASCII);
	de_dbg(c, "fullpath: \"%s\"", ucstring_getpsz(srd->str));
	dpos += srd->bytes_consumed;
	de_destroy_stringreaderdata(c, srd);

	srd = dbuf_read_string(attr_data, dpos, attr_data->len-dpos, DE_DBG_MAX_STRLEN,
		DE_CONVFLAG_STOP_AT_NUL, DE_ENCODING_ASCII);
	de_dbg(c, "comment: \"%s\"", ucstring_getpsz(srd->str));
	dpos += srd->bytes_consumed;
	de_destroy_stringreaderdata(c, srd);

done:
	ucstring_destroy(flags_str);
	dbuf_close(attr_data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
movl $0x0, -0x118(%rbp)
movl $0x0, -0x11c(%rbp)
movq -0x28(%rbp), %rax
cmpq $0xe, 0x10(%rax)
jge 0x14b468
jmp 0x14bbfa
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x84850(%rip), %rsi     # 0x1cfcde
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1711d0
movq %rax, -0xc0(%rbp)
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x14b4d7
movq -0xc0(%rbp), %rdi
leaq 0x8482a(%rip), %rsi     # 0x1cfcfc
callq 0x172680
movl -0x4c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x14b4f5
movq -0xc0(%rbp), %rdi
leaq 0x84816(%rip), %rsi     # 0x1cfd06
callq 0x172680
movq -0xc0(%rbp), %rdi
movl -0x4c(%rbp), %ecx
andl $0x4, %ecx
leaq 0x8481f(%rip), %rsi     # 0x1cfd28
leaq 0x847fd(%rip), %rax     # 0x1cfd0d
cmpl $0x0, %ecx
cmovneq %rax, %rsi
callq 0x172680
movl -0x4c(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x14b53a
movq -0xc0(%rbp), %rdi
leaq 0x8480d(%rip), %rsi     # 0x1cfd42
callq 0x172680
movl -0x4c(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x14b558
movq -0xc0(%rbp), %rdi
leaq 0x847fc(%rip), %rsi     # 0x1cfd4f
callq 0x172680
movq -0x18(%rbp), %rax
movq %rax, -0x138(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x12c(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x172500
movq -0x138(%rbp), %rdi
movl -0x12c(%rbp), %edx
movq %rax, %rcx
leaq 0x858df(%rip), %rsi     # 0x1d0e6e
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
leaq -0x88(%rbp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x18(%rbp), %rdi
leaq -0x88(%rbp), %rdx
addq $0x10, %rdx
leaq 0x5513b(%rip), %rsi     # 0x1a0707
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x18(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
addq $0x10, %rdx
leaq 0x7471d(%rip), %rsi     # 0x1bfd32
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x14b637
jmp 0x14bbfa
movl -0x4c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x14b64e
movl $0x0, -0x50(%rbp)
jmp 0x14b70a
movl -0x11c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x11c(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %edi
callq 0x14a230
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x148(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x13c(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x14b6a9
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x150(%rbp)
jmp 0x14b6b9
leaq 0x6c57d(%rip), %rax     # 0x1b7c2d
movq %rax, -0x150(%rbp)
jmp 0x14b6b9
movl -0x13c(%rbp), %edx
movq -0x148(%rbp), %rdi
movq -0x150(%rbp), %rcx
leaq 0x8468f(%rip), %rsi     # 0x1cfd63
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movl %eax, -0x118(%rbp)
movq -0x18(%rbp), %rdi
movl -0x118(%rbp), %edx
leaq 0x84683(%rip), %rsi     # 0x1cfd86
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
addq 0x10(%rcx), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0x845ad(%rip), %rsi     # 0x1cfce0
movb $0x0, %al
callq 0x15b0d0
cmpq $0x1, -0x40(%rbp)
jl 0x14b74b
cmpq $0xf4240, -0x40(%rbp)   # imm = 0xF4240
jle 0x14b750
jmp 0x14bbfa
cmpl $0x6, -0x50(%rbp)
je 0x14b768
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x14c480
cmpl $0x0, %eax
jne 0x14b7cb
movq -0x18(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x154(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x14b794
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x168(%rbp)
jmp 0x14b7a4
leaq 0x6c492(%rip), %rax     # 0x1b7c2d
movq %rax, -0x168(%rbp)
jmp 0x14b7a4
movl -0x154(%rbp), %edx
movq -0x160(%rbp), %rdi
movq -0x168(%rbp), %rcx
leaq 0x845f0(%rip), %rsi     # 0x1cfdaf
movb $0x0, %al
callq 0x15bc10
jmp 0x14bbfa
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x168020
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0xc8(%rbp), %r8
movq -0x40(%rbp), %r9
movl -0x118(%rbp), %r14d
movl -0x50(%rbp), %ebx
movq -0x58(%rbp), %r11
movl -0x11c(%rbp), %r10d
leaq 0x845d3(%rip), %rax     # 0x1cfdee
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x14c4c0
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
jne 0x14b85d
movq -0x18(%rbp), %rdi
leaq 0x845af(%rip), %rsi     # 0x1cfe00
movb $0x0, %al
callq 0x15bc10
jmp 0x14bbfa
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movl -0x4c(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x14b8bd
jmp 0x14bbfa
movl -0x4c(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x14b8cd
jmp 0x14bbfa
movq -0xc8(%rbp), %rax
movq 0x18(%rax), %rax
subq -0x38(%rbp), %rax
cmpq $0x18, %rax
jge 0x14b8e7
jmp 0x14bbfa
movq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165580
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165580
movq %rax, -0xe8(%rbp)
movq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165580
movq %rax, -0xf8(%rbp)
movq -0xc8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x165600
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0xc8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x165600
movq %rax, -0xf0(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0xc8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x165600
movq %rax, -0x100(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq -0xe0(%rbp), %rcx
leaq -0x110(%rbp), %r8
leaq 0x6f563(%rip), %r9      # 0x1baf1c
callq 0x14c7b0
cmpq $0x0, -0xd8(%rbp)
jle 0x14b9ef
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdx
movl $0x1, %ecx
leaq -0x110(%rbp), %r8
movl $0x28, %r9d
callq 0x14a470
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movq -0xf0(%rbp), %rcx
leaq -0x110(%rbp), %r8
leaq 0x6c455(%rip), %r9      # 0x1b7e68
callq 0x14c7b0
cmpq $0x0, -0xe8(%rbp)
jle 0x14ba46
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdx
xorl %ecx, %ecx
leaq -0x110(%rbp), %r8
movl $0x28, %r9d
callq 0x14a470
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0xf8(%rbp), %rdx
movq -0x100(%rbp), %rcx
leaq -0x110(%rbp), %r8
leaq 0x843c1(%rip), %r9      # 0x1cfe2b
callq 0x14c7b0
cmpq $0x0, -0xf8(%rbp)
jle 0x14baa0
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdx
movl $0x4, %ecx
leaq -0x110(%rbp), %r8
movl $0x28, %r9d
callq 0x14a470
movq -0xc8(%rbp), %rax
movq 0x18(%rax), %rax
subq -0x38(%rbp), %rax
cmpq $0x4, %rax
jge 0x14baba
jmp 0x14bbfa
movq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x114(%rbp)
movq -0x18(%rbp), %rdi
movl -0x114(%rbp), %edx
leaq 0x84356(%rip), %rsi     # 0x1cfe37
movb $0x0, %al
callq 0x15b0d0
movq -0xc8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0xc8(%rbp), %rax
movq 0x18(%rax), %rdx
subq -0x38(%rbp), %rdx
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x1664c0
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x128(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x178(%rbp), %rdi
movq %rax, %rdx
leaq 0x84310(%rip), %rsi     # 0x1cfe58
movb $0x0, %al
callq 0x15b0d0
movq -0x128(%rbp), %rax
movq (%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x166830
movq -0xc8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0xc8(%rbp), %rax
movq 0x18(%rax), %rdx
subq -0x38(%rbp), %rdx
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x1664c0
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x128(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172500
movq -0x170(%rbp), %rdi
movq %rax, %rdx
leaq 0x54a7b(%rip), %rsi     # 0x1a064c
movb $0x0, %al
callq 0x15b0d0
movq -0x128(%rbp), %rax
movq (%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x166830
movq -0xc0(%rbp), %rdi
callq 0x171750
movq -0xc8(%rbp), %rdi
callq 0x1676a0
addq $0x190, %rsp            # imm = 0x190
popq %rbx
popq %r14
popq %rbp
retq
nop