// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/exectext.c
// Function: de_run_textlife
static void de_run_textlife(deark *c, de_module_params *mparams)
{
	struct textlife_ctx *tctx = NULL;
	lctx *d = NULL;

	d = create_lctx(c);
	tctx = de_malloc(c, sizeof(struct textlife_ctx));
	tctx->msgpfx = "[TextLife] ";
	tctx->ei = de_malloc(c, sizeof(struct fmtutil_exe_info));

	exectext_set_common_enc_opts(c, d, DE_ENCODING_CP437);

	// TextLife filters/optimizes the data before storing it. Known filters:
	// * Convert CR+LF to CR.
	// * Replace runs of 8 spaces with TAB.
	// I don't think extracting the raw bytes from the file is a useful thing
	// to do. So we always at least undo the filtering.
	// Files can contain C0 control characters used for special purposes (e.g.
	// italics), but I don't think they will cause serious problems with
	// encoding translation. So we just leave them as-is.
	if(d->proctype==ET_PROCTYPE_RAW) {
		d->proctype = ET_PROCTYPE_FMTCONV_ONLY;
	}

	d->chartypes[3] = ETCT_CONTROL;
	d->chartypes[4] = ETCT_CONTROL;
	d->chartypes[5] = ETCT_CONTROL;
	d->chartypes[6] = ETCT_CONTROL;
	d->chartypes[9] = ETCT_8SPACES;
	d->chartypes[0x0d] = ETCT_CRLF;
	d->chartypes[0x0f] = ETCT_CONTROL;
	d->chartypes[0x10] = ETCT_CONTROL;
	d->chartypes[0x11] = ETCT_CONTROL;

	fmtutil_collect_exe_info(c, c->infile, tctx->ei);

	tctx->edd.restrict_to_fmt = DE_SPECIALEXEFMT_TEXTLIFE;
	fmtutil_detect_specialexe(c, tctx->ei, &tctx->edd);
	if(tctx->edd.detected_fmt!=DE_SPECIALEXEFMT_TEXTLIFE) {
		d->need_errmsg = 1;
		goto done;
	}

	de_dbg(c, "text marker pos: %"I64_FMT, tctx->edd.special_pos_1);
	d->tpos = tctx->edd.special_pos_1+6;
	de_dbg(c, "tpos: %"I64_FMT, d->tpos);
	d->tlen = de_getu16le(tctx->edd.special_pos_1 - 2) - 1;
	de_dbg(c, "tlen: %"I64_FMT, d->tlen);

	exectext_extract_default(c, d);

done:
	if(d) {
		if(d->need_errmsg && tctx) {
			de_err(c, "%sBad or unsupported TextLife file", tctx->msgpfx);
		}
		de_free(c, d);
		d = NULL;
	}
	if(tctx) {
		de_free(c, tctx->ei);
		de_free(c, tctx);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl $0x138, %esi            # imm = 0x138
callq 0xe969b
movq %rax, %r15
movq 0x18(%rbx), %rax
movq %rax, 0x20(%r15)
movl $0x88, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
leaq 0xc0844(%rip), %rax     # 0x123be2
movq %rax, (%r14)
movl $0xf0, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x634f2
cmpl $0x1, 0x18(%r15)
jne 0x633cc
movl $0x2, 0x18(%r15)
movl $0x1010101, 0x3b(%r15)  # imm = 0x1010101
movb $0x64, 0x41(%r15)
movb $0x66, 0x45(%r15)
movw $0x101, 0x47(%r15)      # imm = 0x101
movb $0x1, 0x49(%r15)
movq 0x18(%rbx), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x1053ee
movq %r14, %rdx
addq $0x10, %rdx
movb $-0x33, 0x10(%r14)
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x105ccc
cmpb $-0x33, 0x11(%r14)
jne 0x63482
movq 0x30(%r14), %rdx
leaq 0xc07ca(%rip), %rsi     # 0x123bee
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x30(%r14), %rdx
addq $0x6, %rdx
movq %rdx, 0x28(%r15)
leaq 0xc061f(%rip), %rsi     # 0x123a60
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq 0x30(%r14), %rsi
addq $-0x2, %rsi
callq 0xef1ca
leaq -0x1(%rax), %rdx
movq %rdx, 0x30(%r15)
leaq 0xc03e1(%rip), %rsi     # 0x12384c
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movq %r15, %rsi
callq 0x63581
jmp 0x63487
movb $0x1, 0x13(%r15)
testq %r15, %r15
je 0x634b2
cmpb $0x0, 0x13(%r15)
je 0x634a7
movq (%r14), %rdx
leaq 0xc0766(%rip), %rsi     # 0x123c03
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xe9752
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xe9752