// File: /workspace/github_c_makefile_star2_O1/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), %rbp
movq 0x38(%rbp), %rax
movq %rax, 0x8(%rsp)
movq (%rbp), %rax
testq %rax, %rax
je 0x2ad9b
movq (%rax), %rax
testq %rax, %rax
je 0x2ad9b
cmpl $0x696c7374, 0xc(%rax)  # imm = 0x696C7374
jne 0x2ad9b
cmpq $0x8, 0x40(%rbp)
jge 0x2adb5
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xf6bb0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rdi, %rbx
movq 0x10(%rdx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef34e
movq %rax, %r12
movl %r12d, %edx
shrl $0x18, %edx
movl %r12d, %ecx
andl $0xffffff, %ecx         # imm = 0xFFFFFF
cmpl $0x1000000, %r12d       # imm = 0x1000000
setae %al
cmpl $0x1d, %ecx
setae %sil
orb %al, %sil
jne 0x2ae09
movl %r12d, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
leaq 0xeb560(%rip), %rsi     # 0x116360
movslq (%rsi,%rax,4), %r8
addq %rsi, %r8
jmp 0x2ae10
leaq 0x101059(%rip), %r8     # 0x12be69
leaq 0xea58f(%rip), %rsi     # 0x1153a6
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
movl %ecx, 0x14(%rsp)
callq 0xe9226
movq 0x10(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef193
movq %rax, %r13
movq 0x10(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef193
leaq 0xea56a(%rip), %rsi     # 0x1153b8
movq %rbx, %rdi
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xe9226
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
ja 0x2ad9e
movq 0x40(%rbp), %r12
addq 0x38(%rbp), %r12
movq 0x8(%rsp), %rdx
subq %rdx, %r12
movl 0x14(%rsp), %eax
cmpl $0x4, %eax
je 0x2ae88
cmpl $0x1, %eax
jne 0x2aed7
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r15
movq 0x10(%r14), %rdi
movq 0x8(%rsp), %rsi
movl $0x2, (%rsp)
movl $0x1f4, %ecx            # imm = 0x1F4
movq %r12, %rdx
movq %rax, %r8
xorl %r9d, %r9d
callq 0xf0203
movq %r15, %rdi
callq 0xf7557
leaq 0xe7896(%rip), %rsi     # 0x11275b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x2ad9e
cmpl $0x15, %eax
jne 0x2af00
cmpq $0x1, %r12
jne 0x2af00
movq 0x10(%r14), %rdi
movq %rdx, %rsi
callq 0xef0d5
movsbl %al, %edx
leaq 0xffb5c(%rip), %rsi     # 0x12aa54
xorl %r15d, %r15d
movq %rbx, %rdi
jmp 0x2af26
cmpl $0x15, %eax
jne 0x2af32
cmpq $0x2, %r12
jne 0x2af32
movq 0x10(%r14), %rdi
movq %rdx, %rsi
callq 0xef219
leaq 0xffb36(%rip), %rsi     # 0x12aa54
xorl %r15d, %r15d
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
jmp 0x2ad9e
testl %eax, %eax
jne 0x2ad9b
movq 0x10(%r14), %rsi
movl $0x1, (%rsp)
leaq 0x1087cd(%rip), %r9     # 0x133719
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r12, %rcx
callq 0xe975a
jmp 0x2ad9b