// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/bmff.c
// Function: do_box_data
static void do_box_data(deark *c, lctx *d, struct de_boxesctx *bctx)
{
	unsigned int type_field, type_namespace, wkt;
	unsigned int cntry, lang;
	i64 vlen;
	struct de_boxdata *curbox = bctx->curbox;
	struct de_boxdata *par;
	struct de_boxdata *gpar;
	i64 pos = curbox->payload_pos;
	de_ucstring *s = NULL;

	par = curbox->parent;
	if(!par) goto done;
	gpar = par->parent;
	if(!gpar) goto done;
	if(gpar->boxtype != BOX_ilst) goto done;

	if(curbox->payload_len<8) goto done;
	type_field = (unsigned int)dbuf_getu32be_p(bctx->f, &pos);
	type_namespace = type_field>>24;
	wkt = (type_field & 0x00ffffff); // well-known type (if namespace==0)
	de_dbg(c, "type: %u, %u (%s)", type_namespace, wkt,
		get_ilst_type_name(type_namespace, wkt));

	cntry = (unsigned int)dbuf_getu16be_p(bctx->f, &pos);
	lang = (unsigned int)dbuf_getu16be_p(bctx->f, &pos);
	de_dbg(c, "locale: %u, %u", cntry, lang);

	if(type_namespace!=0) goto done;
	vlen = curbox->payload_pos + curbox->payload_len - pos;

	if(wkt==1 || wkt==4) { // UTF-8
		s = ucstring_create(c);
		dbuf_read_to_ucstring_n(bctx->f, pos, vlen,
			DE_DBG_MAX_STRLEN, s, 0, DE_ENCODING_UTF8);
		de_dbg(c, "value: \"%s\"", ucstring_getpsz_d(s));
	}
	else if(wkt==21 && vlen==1) { // 1-byte signed int
		int n;
		n = (int)(signed char)dbuf_getbyte(bctx->f, pos);
		de_dbg(c, "value: %d", n);
	}
	else if(wkt==21 && vlen==2) { // 2-byte BE signed int
		int n;
		n = (int)dbuf_geti16be(bctx->f, pos);
		de_dbg(c, "value: %d", n);
	}
	else if(wkt==0) {
		de_dbg_hexdump(c, bctx->f, pos, vlen, 256, "value", 0x1);
	}
	// TODO: There are lots more types

done:
	ucstring_destroy(s);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x28(%rdx), %r13
movq 0x38(%r13), %rax
movq %rax, 0x8(%rsp)
movq (%r13), %rax
testq %rax, %rax
je 0x2a17b
movq (%rax), %rax
testq %rax, %rax
je 0x2a17b
cmpl $0x696c7374, 0xc(%rax)  # imm = 0x696C7374
jne 0x2a17b
cmpq $0x8, 0x40(%r13)
jge 0x2a195
xorl %r14d, %r14d
movq %r14, %rdi
callq 0xeaf3c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r15
movq %rdi, %rbx
movq 0x10(%rdx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe4071
movq %rax, %r12
movl %r12d, %edx
shrl $0x18, %edx
movl $0xffffff, %eax         # imm = 0xFFFFFF
movl %r12d, %ebp
andl %eax, %ebp
cmpl %eax, %r12d
ja 0x2a1de
cmpl $0x1c, %ebp
ja 0x2a236
movl %r12d, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
leaq 0xdf1ab(%rip), %rcx     # 0x109380
movslq (%rcx,%rax,4), %r8
addq %rcx, %r8
jmp 0x2a23d
leaq 0xde1e1(%rip), %rsi     # 0x1083c6
leaq 0xf4cf5(%rip), %r8      # 0x11eee1
xorl %r14d, %r14d
movq %rbx, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xde896
movq 0x10(%r15), %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0xe3f6e
movq %rax, %r13
movq 0x10(%r15), %rdi
movq %r12, %rsi
callq 0xe3f6e
leaq 0xde1b6(%rip), %rsi     # 0x1083d8
movq %rbx, %rdi
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xde896
jmp 0x2a17e
leaq 0xf4ca4(%rip), %r8      # 0x11eee1
leaq 0xde182(%rip), %rsi     # 0x1083c6
xorl %r14d, %r14d
movq %rbx, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xde896
movq 0x10(%r15), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe3f6e
movq %rax, 0x10(%rsp)
movq 0x10(%r15), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe3f6e
leaq 0xde15d(%rip), %rsi     # 0x1083d8
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0xde896
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
ja 0x2a17e
movq 0x40(%r13), %r12
addq 0x38(%r13), %r12
movq 0x8(%rsp), %rdx
subq %rdx, %r12
cmpl $0x4, %ebp
je 0x2a2b3
cmpl $0x1, %ebp
jne 0x2a302
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r14
movq 0x10(%r15), %rdi
movq 0x8(%rsp), %rsi
movl $0x2, (%rsp)
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r12, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xe4ced
movq %r14, %rdi
callq 0xeb877
leaq 0xdb45b(%rip), %rsi     # 0x10574b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
jmp 0x2a17e
cmpl $0x15, %ebp
jne 0x2a32b
cmpq $0x1, %r12
jne 0x2a32b
movq 0x10(%r15), %rdi
movq %rdx, %rsi
callq 0xe3eb4
movsbl %al, %edx
leaq 0xf3791(%rip), %rsi     # 0x11dab4
xorl %r14d, %r14d
movq %rbx, %rdi
jmp 0x2a351
cmpl $0x15, %ebp
jne 0x2a35d
cmpq $0x2, %r12
jne 0x2a35d
movq 0x10(%r15), %rdi
movq %rdx, %rsi
callq 0xe3fee
leaq 0xf376b(%rip), %rsi     # 0x11dab4
xorl %r14d, %r14d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
jmp 0x2a17e
testl %ebp, %ebp
jne 0x2a17b
movq 0x10(%r15), %rsi
movl $0x1, (%rsp)
leaq 0xfc4c2(%rip), %r9      # 0x126839
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r12, %rcx
callq 0xded3a
jmp 0x2a17b