// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/olepropset.c
// Function: do_decode_PropertySetStream
static void do_decode_PropertySetStream(deark *c, lctx *d)
{
	i64 n;
	int saved_indent_level;
	i64 nsets;
	i64 k;
	i64 pos = 0;
	u8 clsid[16];
	char clsid_string[50];

	de_dbg_indent_save(c, &saved_indent_level);

	// expecting 48 (or more?) bytes of header info.
	n = dbuf_getu16le_p(d->f, &pos);
	de_dbg(c, "byte order code: 0x%04x", (unsigned int)n);
	if(n != 0xfffe) goto done;

	d->propset_version = (unsigned int)dbuf_getu16le_p(d->f, &pos);
	de_dbg(c, "property set version: %u", d->propset_version);

	n = dbuf_getu16le_p(d->f, &pos);
	de_dbg(c, "OS ver: 0x%04x", (unsigned int)n);
	n = dbuf_getu16le_p(d->f, &pos);
	de_dbg(c, "OS: 0x%04x", (unsigned int)n);

	dbuf_read(d->f, clsid, pos, 16);
	pos += 16;
	fmtutil_guid_to_uuid(clsid);
	fmtutil_render_uuid(c, clsid, clsid_string, sizeof(clsid_string));
	de_dbg(c, "clsid: {%s}", clsid_string);

	nsets = dbuf_getu32le_p(d->f, &pos);
	de_dbg(c, "number of property sets: %d", (int)nsets);
	if(nsets>2) goto done;

	for(k=0; k<nsets; k++) {
		struct propset_struct *si = NULL;
		const struct fmtid_info_entry *fmtid_info;

		si = de_malloc(c, sizeof(struct propset_struct));
		si->encoding = DE_ENCODING_ASCII;

		dbuf_read(d->f, clsid, pos, 16);
		pos += 16;
		fmtutil_guid_to_uuid(clsid);
		fmtid_info = find_fmtid_info(clsid);
		fmtutil_render_uuid(c, clsid, clsid_string, sizeof(clsid_string));
		de_dbg(c, "fmtid[%d]: {%s} (%s)", (int)k, clsid_string, fmtid_info?fmtid_info->name:"?");

		si->sfmtid = fmtid_info ? fmtid_info->sfmtid : SFMTID_UNKNOWN;

		// This is supposed to be a DWORD, but I've seen some with only two valid
		// bytes. And it shouldn't be much bigger than 48.
		si->tbloffset = dbuf_getu16le_p(d->f, &pos);
		pos += 2;

		de_dbg(c, "PropertySet[%d] table at %d", (int)k, (int)si->tbloffset);
		de_dbg_indent(c, 1);
		do_PropertySet(c, d, si, k);
		de_dbg_indent(c, -1);

		destroy_propset_struct(c, si);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xdb3ca(%rip), %rsi     # 0x1a5537
movb $0x0, %al
callq 0x15b0d0
cmpq $0xfffe, -0x18(%rbp)    # imm = 0xFFFE
je 0xca183
jmp 0xca494
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0xeeb19(%rip), %rsi     # 0x1b8cc7
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xeeb06(%rip), %rsi     # 0x1b8ce0
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xeeae9(%rip), %rsi     # 0x1b8cef
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x10, %ecx
callq 0x164d10
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x174010
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movl $0x32, %ecx
callq 0x173ee0
movq -0x8(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq 0xeea94(%rip), %rsi     # 0x1b8cfa
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165580
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0xeea74(%rip), %rsi     # 0x1b8d06
movb $0x0, %al
callq 0x15b0d0
cmpq $0x2, -0x28(%rbp)
jle 0xca2a5
jmp 0xca494
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0xca492
movq $0x0, -0x98(%rbp)
movq -0x8(%rbp), %rdi
movl $0x28, %esi
callq 0x15b780
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x10, %ecx
callq 0x164d10
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x174010
leaq -0x50(%rbp), %rdi
callq 0xca4b0
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movl $0x32, %ecx
callq 0x173ee0
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
movl %eax, -0xac(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0xca381
movq -0xa0(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0xca391
leaq 0xed8a5(%rip), %rax     # 0x1b7c2d
movq %rax, -0xc0(%rbp)
jmp 0xca391
movq -0xa8(%rbp), %rcx
movl -0xac(%rbp), %edx
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %r8
leaq 0xee96f(%rip), %rsi     # 0x1b8d22
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0xa0(%rbp)
je 0xca3d6
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xc4(%rbp)
jmp 0xca3e0
xorl %eax, %eax
movl %eax, -0xc4(%rbp)
jmp 0xca3e0
movl -0xc4(%rbp), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x98(%rbp), %rax
movq (%rax), %rax
movl %eax, %ecx
leaq 0xee901(%rip), %rsi     # 0x1b8d37
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0xca540
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0xca8e0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xca2ad
jmp 0xca494
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x15b5a0
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)