// File: /workspace/github_c_makefile_star2_O0/inflex[P]ripMIME/ripOLE/ole.c
// Function: OLE_decode_file
int OLE_decode_file( struct OLE_object *ole, char *fname, char *decode_path )
{
	unsigned char *current_property, *property_limit;
	int result = 0;
	int i;

	// Reject any bad paramters.
	if (ole == NULL) return OLEER_DECODE_NULL_OBJECT;
	if (fname == NULL) return OLEER_DECODE_NULL_FILENAME;
	if (decode_path == NULL) return OLEER_DECODE_NULL_PATH;

	// We need to gain access to the OLE2 data file, without
	//		this pretty much everything is pointless.
	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: opening %s", FL, fname );
	result = OLE_open_file( ole, fname );
	if (result != 0) return result;

	// Try create the output directory which we're using
	//		to write the decoded files out to.
	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: opening output directory %s", FL, decode_path);
	result = OLE_open_directory( ole, decode_path );
	if (result != 0) return result;

	// In order to successfully decode an OLE2 stream, we have to read
	//		and understand the first 512 bytes of the file, this is the 
	//		OLE2 header. 
	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Getting main header", FL);
	result = OLE_get_header( ole );
	if (result != 0) return result;

	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Converting main header", FL);
	result = OLE_convert_header( ole );
	if (result != 0) return result;

	result = OLE_header_sanity_check( ole );
	if (result > 0) return OLEER_INSANE_OLE_FILE;

	DOLE OLE_print_header( ole );

	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading FAT", FL);
	result = OLE_load_FAT( ole );
	if (result != 0) return result;

	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading miniFAT chain", FL);
	ole->miniFAT = OLE_load_chain( ole, ole->header.mini_fat_start );
	if (ole->miniFAT == NULL) return OLEER_MINIFAT_READ_FAIL;

	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading Directory stream chain", FL);
	ole->properties = OLE_load_chain( ole, ole->header.directory_stream_start_sector );
	if (ole->properties == NULL) return OLEER_PROPERTIES_READ_FAIL;

	i=0;
	current_property = ole->properties;
	property_limit = current_property +ole->last_chain_size ;
	// while(1)
	while (current_property < property_limit)
	{
		struct OLE_directory_entry a_dir_object, *adir;
		int property_value=0;

		adir = &a_dir_object;

		OLE_dir_init(adir);

		property_value = get_uint8((char *)current_property);
		if (property_value < 1) break;

		DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG:--------- DIRECTORY INDEX: %d",FL,i);

		OLE_convert_directory( ole, current_property, adir );

		DOLE {
			LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Printing directory details...",FL);
			OLE_print_directory( ole, adir);
			LOGGER_log("%s:%d:OLE_decode_file:DEBUG: End of directory details",FL);
		}

		if (adir->element_colour > 1) break;

		if ((adir->element_type == STGTY_INVALID)||(adir->element_type > STGTY_ROOT))
		{
			DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: breaking out due to element type %d",FL, adir->element_type);
			break;

		} else if (adir->element_type == STGTY_ROOT){
			/** ROOT DIRECTORY ENTRY **/
			/** ROOT DIRECTORY ENTRY **/
			/** ROOT DIRECTORY ENTRY **/
			DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Loading ministream/SmallBlockArray",FL);
			ole->ministream = OLE_load_chain( ole, adir->start_sector );
			if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL;
			DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: ministream done",FL);







		} else if (adir->element_type == STGTY_STORAGE) {
			/** STORAGE ELEMENT **/
			/** STORAGE ELEMENT **/
			/** STORAGE ELEMENT **/
			DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Item is directory, start child is at index %d\n",FL,i);
			ole->ministream = OLE_load_chain( ole, adir->start_sector );
			if (ole->ministream == NULL) return OLEER_MINISTREAM_READ_FAIL;
			DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: DIRECTORY ministream done",FL);




		} else if (adir->element_type == STGTY_STREAM) {
			/** STREAM ELEMENT **/
			/** STREAM ELEMENT **/
			/** STREAM ELEMENT **/
			OLE_decode_stream( ole, adir, decode_path );



		} else {
			/** If the element isn't of the above types then it's possibly 
			 ** an empty element or just one used for the MSAT/SAT
			 ** either way we just step over it and carry on **/
			DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Element type %d does not need to be handled",FL,adir->element_type);
		}

		// Jump to the next property record, which
		//		is always 128 bytes ahead.
		current_property += 128;
		i++;

	} // While there are still more directory entries to read in.

	DOLE LOGGER_log("%s:%d:OLE_decode_file:DEBUG: Finished",FL);

	/*
	//if (ole->f) fclose(ole->f);
	fclose(ole->f);
	if (ole->FAT) free(ole->FAT);
	if (ole->miniFAT) free(ole->miniFAT);
	if (ole->ministream) free(ole->ministream);
	if (ole->properties) free(ole->properties);
	 */

	return OLE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x34(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x16f61
movl $0xa, -0x4(%rbp)
jmp 0x17541
cmpq $0x0, -0x18(%rbp)
jne 0x16f74
movl $0xb, -0x4(%rbp)
jmp 0x17541
cmpq $0x0, -0x20(%rbp)
jne 0x16f87
movl $0xc, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16fb2
movq -0x18(%rbp), %rcx
leaq 0x9f4f(%rip), %rdi      # 0x20eee
leaq 0x8ca5(%rip), %rsi      # 0x1fc4b
movl $0x6ec, %edx            # imm = 0x6EC
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x16670
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x16fd3
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x16ffe
movq -0x20(%rbp), %rcx
leaq 0x9f2b(%rip), %rdi      # 0x20f16
leaq 0x8c59(%rip), %rsi      # 0x1fc4b
movl $0x6f2, %edx            # imm = 0x6F2
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x16810
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x1701f
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x17046
leaq 0x9f1c(%rip), %rdi      # 0x20f4f
leaq 0x8c11(%rip), %rsi      # 0x1fc4b
movl $0x6f9, %edx            # imm = 0x6F9
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
callq 0x15170
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x17063
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x1708a
leaq 0x9f09(%rip), %rdi      # 0x20f80
leaq 0x8bcd(%rip), %rsi      # 0x1fc4b
movl $0x6fd, %edx            # imm = 0x6FD
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
callq 0x151e0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x170a7
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rdi
callq 0x153c0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x170c5
movl $0x67, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x170db
movq -0x10(%rbp), %rdi
callq 0x15460
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x17102
leaq 0x9ec5(%rip), %rdi      # 0x20fb4
leaq 0x8b55(%rip), %rsi      # 0x1fc4b
movl $0x706, %edx            # imm = 0x706
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
callq 0x157b0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x1711f
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x17146
leaq 0x9eaa(%rip), %rdi      # 0x20fdd
leaq 0x8b11(%rip), %rsi      # 0x1fc4b
movl $0x70a, %edx            # imm = 0x70A
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x280(%rax), %esi
callq 0x163d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x1717b
movl $0x1e, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x171a2
leaq 0x9e81(%rip), %rdi      # 0x21010
leaq 0x8ab5(%rip), %rsi      # 0x1fc4b
movl $0x70e, %edx            # imm = 0x70E
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x278(%rax), %esi
callq 0x163d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x250(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x250(%rax)
jne 0x171dd
movl $0x1f, -0x4(%rbp)
jmp 0x17541
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x250(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
addq 0x18(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x17513
movl $0x0, -0xcc(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x14930
movq -0x28(%rbp), %rdi
callq 0x18120
movl %eax, -0xcc(%rbp)
cmpl $0x1, -0xcc(%rbp)
jge 0x17252
jmp 0x17513
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x1727c
movl -0x38(%rbp), %ecx
leaq 0x9de3(%rip), %rdi      # 0x2104c
leaq 0x89db(%rip), %rsi      # 0x1fc4b
movl $0x722, %edx            # imm = 0x722
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x15580
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x172e1
leaq 0x9de2(%rip), %rdi      # 0x21086
leaq 0x89a0(%rip), %rsi      # 0x1fc4b
movl $0x727, %edx            # imm = 0x727
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x15710
leaq 0x9df3(%rip), %rdi      # 0x210c1
leaq 0x8976(%rip), %rsi      # 0x1fc4b
movl $0x729, %edx            # imm = 0x729
movb $0x0, %al
callq 0x117c0
movq -0xc8(%rbp), %rax
movsbl 0x45(%rax), %eax
cmpl $0x1, %eax
jle 0x172f6
jmp 0x17513
movq -0xc8(%rbp), %rax
movsbl 0x44(%rax), %eax
cmpl $0x0, %eax
je 0x17316
movq -0xc8(%rbp), %rax
movsbl 0x44(%rax), %eax
cmpl $0x5, %eax
jle 0x1734d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x17348
movq -0xc8(%rbp), %rax
movsbl 0x44(%rax), %ecx
leaq 0x9dc2(%rip), %rdi      # 0x210f7
leaq 0x890f(%rip), %rsi      # 0x1fc4b
movl $0x730, %edx            # imm = 0x730
movb $0x0, %al
callq 0x117c0
jmp 0x17513
movq -0xc8(%rbp), %rax
movsbl 0x44(%rax), %eax
cmpl $0x5, %eax
jne 0x173f2
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x17388
leaq 0x9dc3(%rip), %rdi      # 0x21138
leaq 0x88cf(%rip), %rsi      # 0x1fc4b
movl $0x737, %edx            # imm = 0x737
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rax
movq 0x78(%rax), %rax
movl %eax, %esi
callq 0x163d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x248(%rax)
jne 0x173c6
movl $0x20, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x173ed
leaq 0x9d9e(%rip), %rdi      # 0x21178
leaq 0x886a(%rip), %rsi      # 0x1fc4b
movl $0x73a, %edx            # imm = 0x73A
movb $0x0, %al
callq 0x117c0
jmp 0x174f5
movq -0xc8(%rbp), %rax
movsbl 0x44(%rax), %eax
cmpl $0x1, %eax
jne 0x17497
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x17430
movl -0x38(%rbp), %ecx
leaq 0x9d88(%rip), %rdi      # 0x211a5
leaq 0x8827(%rip), %rsi      # 0x1fc4b
movl $0x746, %edx            # imm = 0x746
movb $0x0, %al
callq 0x117c0
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rax
movq 0x78(%rax), %rax
movl %eax, %esi
callq 0x163d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x248(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x248(%rax)
jne 0x1746e
movl $0x20, -0x4(%rbp)
jmp 0x17541
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x17495
leaq 0x9d6f(%rip), %rdi      # 0x211f1
leaq 0x87c2(%rip), %rsi      # 0x1fc4b
movl $0x749, %edx            # imm = 0x749
movb $0x0, %al
callq 0x117c0
jmp 0x174f3
movq -0xc8(%rbp), %rax
movsbl 0x44(%rax), %eax
cmpl $0x2, %eax
jne 0x174bd
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x16b10
jmp 0x174f1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x174ef
movq -0xc8(%rbp), %rax
movsbl 0x44(%rax), %ecx
leaq 0x9d4c(%rip), %rdi      # 0x21228
leaq 0x8768(%rip), %rsi      # 0x1fc4b
movl $0x75a, %edx            # imm = 0x75A
movb $0x0, %al
callq 0x117c0
jmp 0x174f1
jmp 0x174f3
jmp 0x174f5
jmp 0x174f7
movq -0x28(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x28(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x17203
movq -0x10(%rbp), %rax
cmpl $0x0, 0x444(%rax)
je 0x1753a
leaq 0x9d4a(%rip), %rdi      # 0x21271
leaq 0x871d(%rip), %rsi      # 0x1fc4b
movl $0x764, %edx            # imm = 0x764
movb $0x0, %al
callq 0x117c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)