// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/arj.c
// Function: reloc_process_archive_hdr
static int reloc_process_archive_hdr(deark *c, struct arjreloc_ctx *d)
{
	struct de_crcobj *crco = NULL;
	int retval = 0;
	i64 basic_hdr_size;
	UI hdr_id;
	i32 newcrc;
	u8 flags;
	u8 file_type;

	hdr_id = (UI)de_getu16le(d->src_startpos);
	if(hdr_id!=0xea60) goto done;
	basic_hdr_size = de_getu16le(d->src_startpos+2);
	if(basic_hdr_size>ARJ_MAX_BASIC_HEADER_SIZE || basic_hdr_size<ARJ_MIN_BASIC_HEADER_SIZE) goto done;

	flags = de_getbyte(d->src_startpos+8);
	file_type = de_getbyte(d->src_startpos+10);
	if(file_type!=ARJ_FILETYPE_MAINHDR) goto done;

	if(flags & 0x40) {
		de_info(c, "Note: Disabling ARJ security envelope");
		flags -= 0x40;
	}
	else if(flags & 0x08) {
		de_info(c, "Note: Disabling ARJ-PROTECT");
		flags -= 0x08;
	}
	else {
		// Not secured, or not a problematic type of security. Just copy everything.
		retval = 1;
		goto done;
	}

	// Copy, with changes as needed
	dbuf_copy(c->infile, d->src_startpos, 8, d->ahdr);

	// Alter some of the bytes
	dbuf_writebyte(d->ahdr, flags);
	dbuf_writebyte(d->ahdr, 0); // security version
	dbuf_copy(c->infile, d->src_startpos+10, 10, d->ahdr); // filetype...modtime
	dbuf_writeu32le(d->ahdr, 0); // archive size
	dbuf_writeu32le(d->ahdr, 0); // security envelope or ARJPROT pos
	dbuf_copy(c->infile, d->src_startpos+28, 2, d->ahdr); // filespec pos
	dbuf_writeu16le(d->ahdr, 0); // security envelope len
	// (now at file offset 32) Copy the rest of the basic header
	dbuf_copy(c->infile, d->src_startpos+32, (4+basic_hdr_size)-32, d->ahdr);

	crco = de_crcobj_create(c, DE_CRCOBJ_CRC32_IEEE);
	de_crcobj_addslice(crco, d->ahdr, 4, basic_hdr_size);
	newcrc = de_crcobj_getval(crco);
	dbuf_writeu32le(d->ahdr, newcrc); // basic hdr crc

	// Note - This is not the end of the archive header, but anything after
	// this can remain unchanged.
	retval = 1;
done:
	de_crcobj_destroy(crco);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x165280
movl %eax, -0x2c(%rbp)
cmpl $0xea60, -0x2c(%rbp)    # imm = 0xEA60
je 0x47f44
jmp 0x48156
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, -0x28(%rbp)
cmpq $0xa28, -0x28(%rbp)     # imm = 0xA28
jg 0x47f71
cmpq $0x1e, -0x28(%rbp)
jge 0x47f76
jmp 0x48156
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x8, %rsi
callq 0x165060
movb %al, -0x31(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0xa, %rsi
callq 0x165060
movb %al, -0x32(%rbp)
movzbl -0x32(%rbp), %eax
cmpl $0x2, %eax
je 0x47fba
jmp 0x48156
movzbl -0x31(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x47fe4
movq -0x8(%rbp), %rdi
leaq 0x15bd63(%rip), %rsi    # 0x1a3d34
movb $0x0, %al
callq 0x15c0c0
movzbl -0x31(%rbp), %eax
subl $0x40, %eax
movb %al, -0x31(%rbp)
jmp 0x4801c
movzbl -0x31(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x4800e
movq -0x8(%rbp), %rdi
leaq 0x15bd5f(%rip), %rsi    # 0x1a3d5a
movb $0x0, %al
callq 0x15c0c0
movzbl -0x31(%rbp), %eax
subl $0x8, %eax
movb %al, -0x31(%rbp)
jmp 0x4801a
movl $0x1, -0x1c(%rbp)
jmp 0x48156
jmp 0x4801c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x8, %edx
callq 0x166070
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movzbl -0x31(%rbp), %esi
callq 0x168380
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x168380
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0xa, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0xa, %edx
callq 0x166070
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x168c30
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x168c30
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x1c, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x2, %edx
callq 0x166070
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x168a10
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x20, %rsi
movq -0x28(%rbp), %rdx
addq $0x4, %rdx
subq $0x20, %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
callq 0x166070
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x15eac0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x28(%rbp), %rcx
movl $0x4, %edx
callq 0x15f500
movq -0x18(%rbp), %rdi
callq 0x15f340
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x30(%rbp), %rsi
callq 0x168c30
movl $0x1, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x15f2e0
movl -0x1c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)