// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/plist.c
// Function: do_one_object_by_offset
static int do_one_object_by_offset(deark *c, lctx *d, i64 pos1)
{
	i64 pos = pos1;
	u8 marker;
	u8 m1, m2;
	int has_size;
	i64 dlen_raw;
	const char *tn;

	// In this format, it is easy for an aggregate object to contain itself, or an
	// ancestor, making the number of objects infinite. We could detect this if we
	// wanted, but doesn't really solve the problem. Even without recursion, the
	// number of objects can grow exponentially, and a small file could easily
	// contain trillions of objects. Instead, we'll enforce an arbitrary limit to
	// the number of objects we decode.
	// TODO: If we were to decode each aggregate object only once, would that be a
	// good solution, or would it make the output less useful?
	if(d->exceeded_max_objects) return 0;
	if(d->object_count>=MAX_PLIST_OBJECTS) {
		d->exceeded_max_objects = 1;
		de_err(c, "Too many objects encountered (max=%d)", MAX_PLIST_OBJECTS);
		return 0;
	}

	de_dbg(c, "object at %"I64_FMT, pos);
	de_dbg_indent(c, 1);

	d->object_count++;

	if(pos<8 || pos>=c->infile->len-32) goto done;

	marker = de_getbyte_p(&pos);
	de_dbg(c, "marker: 0x%02x", (unsigned int)marker);

	m1 = (marker&0xf0)>>4;
	m2 = marker&0x0f;

	tn = "?";
	has_size = 0;
	dlen_raw = 0;

	switch(m1) {
	case 0x0:
		if(m2==0x8 || m2==0x9) {
			tn = "bool";
		}
		break;
	case 0x1:
		tn = "int";
		has_size = 1;
		break;
	case 0x2:
		tn = "real";
		has_size = 1;
		break;
	case 0x3:
		if(m2==0x3) {
			tn = "date";
		}
		break;
	case 0x4:
		tn = "binary data";
		has_size = 1;
		break;
	case 0x5:
		tn = "string";
		has_size = 1;
		break;
	case 0x6:
		tn = "UTF-16 string";
		has_size = 1;
		break;
	case 0x8: // TODO
		tn = "uid";
		has_size = 1;
		break;
	case 0xa:
		tn = "array";
		has_size = 1;
		break;
	case 0xc:
		tn = "set";
		has_size = 1;
		break;
	case 0xd:
		tn = "dict";
		has_size = 1;
		break;
	}

	de_dbg(c, "data type: %s", tn);

	if(has_size) {
		if(m2==0xf) {
			u8 x;
			unsigned int nbytes_in_len;
			x = de_getbyte_p(&pos);
			// 0x10 = size is a 1-byte int
			// 0x11 = 2-byte int, 0x12 = 4-byte int, 0x13 = 8-byte int
			if(x<0x10 || x>0x13) goto done;
			nbytes_in_len = 1U<<(unsigned int)(x-0x10);
			dlen_raw = dbuf_getint_ext(c->infile, pos, nbytes_in_len, 0, 0);
			dbuf_constrain_length(c->infile, 0, &dlen_raw);
			pos += (i64)nbytes_in_len;
		}
		else {
			dlen_raw = (i64)m2;
		}
		de_dbg(c, "size (logical): %"I64_FMT, dlen_raw);
	}

	if(m1==0x0 && (m2==0x8 || m2==0x9)) {
		de_dbg(c, "value: %s", (m2==0x8)?"false":"true");
	}
	else if(m1==0x1) {
		do_object_int(c, d, pos, dlen_raw);
	}
	else if(m1==0x2) {
		do_object_real(c, d, pos, dlen_raw);
	}
	else if(m1==0x3 && m2==0x3) {
		do_object_date(c, d, pos);
	}
	else if(m1==0x4) {
		de_dbg(c, "binary data at %"I64_FMT", len=%"I64_FMT, pos, dlen_raw);
		de_dbg_indent(c, 1);
		de_dbg_hexdump(c, c->infile, pos, dlen_raw, 256, NULL, 0x1);
		de_dbg_indent(c, -1);
	}
	else if(m1==0x5) {
		do_object_string(c, d, pos, dlen_raw);
	}
	else if(m1==0x6) {
		do_object_utf16string(c, d, pos, dlen_raw);
	}
	else if(m1==0xa) {
		do_object_array_or_set(c, d, tn, pos1, pos, dlen_raw);
	}
	else if(m1==0xc) {
		do_object_array_or_set(c, d, tn, pos1, pos, dlen_raw);
	}
	else if(m1==0xd) {
		do_object_dict(c, d, pos1, pos, dlen_raw);
	}
	else {
		de_dbg(c, "[don't know how to decode this data type]");
	}

done:
	de_dbg_indent(c, -1);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x11d562
movl $0x0, -0x4(%rbp)
jmp 0x11da46
movq -0x18(%rbp), %rax
cmpq $0xf4240, 0x8(%rax)     # imm = 0xF4240
jl 0x11d59e
movq -0x18(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x10(%rbp), %rdi
leaq 0xa8473(%rip), %rsi     # 0x1c59f9
movl $0xf4240, %edx          # imm = 0xF4240
movb $0x0, %al
callq 0x15bfb0
movl $0x0, -0x4(%rbp)
jmp 0x11da46
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x8122c(%rip), %rsi     # 0x19e7d9
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
cmpq $0x8, -0x28(%rbp)
jl 0x11d5f2
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
subq $0x20, %rcx
cmpq %rcx, %rax
jl 0x11d5f7
jmp 0x11da31
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rdi
movzbl -0x29(%rbp), %edx
leaq 0x8d16f(%rip), %rsi     # 0x1aa789
xorl %eax, %eax
callq 0x15b0d0
movzbl -0x29(%rbp), %eax
shrl $0x4, %eax
movb %al, -0x2a(%rbp)
movb -0x29(%rbp), %al
andb $0xf, %al
movb %al, -0x2b(%rbp)
leaq 0x9a5f3(%rip), %rax     # 0x1b7c2d
movq %rax, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movzbl -0x2a(%rbp), %eax
movq %rax, -0x50(%rbp)
subq $0xd, %rax
ja 0x11d766
movq -0x50(%rbp), %rax
leaq 0xa81e6(%rip), %rcx     # 0x1c5850
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl -0x2b(%rbp), %eax
cmpl $0x8, %eax
je 0x11d685
movzbl -0x2b(%rbp), %eax
cmpl $0x9, %eax
jne 0x11d690
leaq 0xa8393(%rip), %rax     # 0x1c5a1f
movq %rax, -0x40(%rbp)
jmp 0x11d766
leaq 0x83c58(%rip), %rax     # 0x1a12f4
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
leaq 0xa8371(%rip), %rax     # 0x1c5a24
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
movzbl -0x2b(%rbp), %eax
cmpl $0x3, %eax
jne 0x11d6d7
leaq 0x9babd(%rip), %rax     # 0x1b9190
movq %rax, -0x40(%rbp)
jmp 0x11d766
leaq 0xa8346(%rip), %rax     # 0x1c5a29
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
leaq 0xa8345(%rip), %rax     # 0x1c5a3c
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
leaq 0xa832a(%rip), %rax     # 0x1c5a35
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
leaq 0xa8324(%rip), %rax     # 0x1c5a43
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
leaq 0x9ed2a(%rip), %rax     # 0x1bc45d
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
leaq 0x8d016(%rip), %rax     # 0x1aa75d
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x11d766
leaq 0xa82ec(%rip), %rax     # 0x1c5a47
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0xa82d7(%rip), %rsi     # 0x1c5a4c
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x30(%rbp)
je 0x11d829
movzbl -0x2b(%rbp), %eax
cmpl $0xf, %eax
jne 0x11d80b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165170
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x10, %eax
jl 0x11d7b5
movzbl -0x41(%rbp), %eax
cmpl $0x13, %eax
jle 0x11d7ba
jmp 0x11da31
movzbl -0x41(%rbp), %ecx
subl $0x10, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x48(%rbp), %edx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x165a80
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdx
callq 0x164c90
movl -0x48(%rbp), %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x11d813
movzbl -0x2b(%rbp), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0xa8238(%rip), %rsi     # 0x1c5a5a
movb $0x0, %al
callq 0x15b0d0
movzbl -0x2a(%rbp), %eax
cmpl $0x0, %eax
jne 0x11d874
movzbl -0x2b(%rbp), %eax
cmpl $0x8, %eax
je 0x11d844
movzbl -0x2b(%rbp), %eax
cmpl $0x9, %eax
jne 0x11d874
movq -0x10(%rbp), %rdi
movzbl -0x2b(%rbp), %ecx
leaq 0xa822b(%rip), %rdx     # 0x1c5a7e
leaq 0xa821e(%rip), %rax     # 0x1c5a78
cmpl $0x8, %ecx
cmoveq %rax, %rdx
leaq 0xa8206(%rip), %rsi     # 0x1c5a6e
movb $0x0, %al
callq 0x15b0d0
jmp 0x11da2f
movzbl -0x2a(%rbp), %eax
cmpl $0x1, %eax
jne 0x11d897
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x11da50
jmp 0x11da2d
movzbl -0x2a(%rbp), %eax
cmpl $0x2, %eax
jne 0x11d8ba
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x11dad0
jmp 0x11da2b
movzbl -0x2a(%rbp), %eax
cmpl $0x3, %eax
jne 0x11d8e2
movzbl -0x2b(%rbp), %eax
cmpl $0x3, %eax
jne 0x11d8e2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x11db50
jmp 0x11da29
movzbl -0x2a(%rbp), %eax
cmpl $0x4, %eax
jne 0x11d951
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0xa8185(%rip), %rsi     # 0x1c5a83
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, (%rsp)
callq 0x15b840
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x11da27
movzbl -0x2a(%rbp), %eax
cmpl $0x5, %eax
jne 0x11d974
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x11dbe0
jmp 0x11da25
movzbl -0x2a(%rbp), %eax
cmpl $0x6, %eax
jne 0x11d997
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0x11dc70
jmp 0x11da23
movzbl -0x2a(%rbp), %eax
cmpl $0xa, %eax
jne 0x11d9bf
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x38(%rbp), %r9
callq 0x11dd00
jmp 0x11da21
movzbl -0x2a(%rbp), %eax
cmpl $0xc, %eax
jne 0x11d9e7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x38(%rbp), %r9
callq 0x11dd00
jmp 0x11da1f
movzbl -0x2a(%rbp), %eax
cmpl $0xd, %eax
jne 0x11da0b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %r8
callq 0x11de50
jmp 0x11da1d
movq -0x10(%rbp), %rdi
leaq 0xa8089(%rip), %rsi     # 0x1c5a9f
movb $0x0, %al
callq 0x15b0d0
jmp 0x11da1f
jmp 0x11da21
jmp 0x11da23
jmp 0x11da25
jmp 0x11da27
jmp 0x11da29
jmp 0x11da2b
jmp 0x11da2d
jmp 0x11da2f
jmp 0x11da31
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop