// File: sc0ty[P]CODExtract/src/codfile/codresource.cpp
// Function: CODResource::CODResource(TCODRESOURCE*, char*, unsigned short)
CODResource::CODResource(TCODRESOURCE *res, char *DataSeg, u16 DataSZ)
{
    // set data
    type = (char *)(DataSeg + res->type_ptr);
    size = res->size;
    data = (char *)(DataSeg + res->data_ptr);
    itype = CODRESTUndefined;

    // sanity check
    if ( (res->type_ptr + (strlen(type)) >= DataSZ) ||
         (res->data_ptr + size >= DataSZ))
        throw "Incorrect file format";

	#define CMPRES(res) ((strlen(type) == sizeof(res)) && \
						 (memcmp(res, (u8 *)type, sizeof(res)) == 0))

    // decode resource type
    if      (CMPRES(CODRESAppName))     itype = CODRESTAppName;
    else if (CMPRES(CODRESDescription)) itype = CODRESTDescription;
    else if (CMPRES(CODRESVendor))      itype = CODRESTVendor;
    else if (CMPRES(CODRESIcon))        itype = CODRESTIcon;
    else itype = CODRESTUnknown;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movw %cx, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rdx
movzwl (%rdx), %edx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movw 0x2(%rcx), %cx
movw %cx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rdx
movzwl 0x4(%rdx), %edx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x10(%rax)
movl $0x0, 0x18(%rax)
movq -0x10(%rbp), %rcx
movzwl (%rcx), %ecx
movq %rcx, -0x28(%rbp)
movq (%rax), %rdi
callq 0x30e0
movq %rax, %rcx
movq -0x28(%rbp), %rax
addq %rcx, %rax
movzwl -0x1a(%rbp), %ecx
cmpq %rcx, %rax
jae 0x60f0
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movzwl 0x4(%rax), %eax
movzwl 0x8(%rcx), %ecx
addl %ecx, %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jl 0x6117
movl $0x8, %edi
callq 0x3110
movq %rax, %rdi
leaq 0x109a(%rip), %rax      # 0x719e
movq %rax, (%rdi)
movq 0x3eba(%rip), %rsi      # 0x9fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x33e0
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30e0
cmpq $0x7, %rax
jne 0x6156
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq 0x114d(%rip), %rdi      # 0x7284
movl $0x7, %edx
callq 0x30f0
cmpl $0x0, %eax
jne 0x6156
movq -0x30(%rbp), %rax
movl $0x2, 0x18(%rax)
jmp 0x621a
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30e0
cmpq $0x7, %rax
jne 0x6195
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq 0x1115(%rip), %rdi      # 0x728b
movl $0x7, %edx
callq 0x30f0
cmpl $0x0, %eax
jne 0x6195
movq -0x30(%rbp), %rax
movl $0x3, 0x18(%rax)
jmp 0x6218
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30e0
cmpq $0x4, %rax
jne 0x61cd
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
subl $0x19c9765f, %eax       # imm = 0x19C9765F
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x61cd
movq -0x30(%rbp), %rax
movl $0x4, 0x18(%rax)
jmp 0x6216
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x30e0
cmpq $0x7, %rax
jne 0x6209
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq 0x10a9(%rip), %rdi      # 0x7296
movl $0x7, %edx
callq 0x30f0
cmpl $0x0, %eax
jne 0x6209
movq -0x30(%rbp), %rax
movl $0x5, 0x18(%rax)
jmp 0x6214
movq -0x30(%rbp), %rax
movl $0x1, 0x18(%rax)
jmp 0x6216
jmp 0x6218
jmp 0x621a
addq $0x30, %rsp
popq %rbp
retq