// File: sc0ty[P]CODExtract/src/codfile/codfile.cpp
// Function: CODFile::getVersion[abi:cxx11]()
string CODFile::getVersion()
{
    if (!isOpen) throw "Load file first";

    // data segment header
    TDATASEGHEADER *dh = (TDATASEGHEADER *)DataSeg;

    // sanity check - classes and modules list
    u16 tmp = dh->num_classes + 2*dh->num_modules;
    tmp *= sizeof(u16);
    tmp += sizeof(TDATASEGHEADER);
    if (tmp > dh->exported_string_offset) throw "Incorrect file format";

    // there is no modules on the list
    if (dh->num_modules == 0) throw "No version string in module";

    // module version ptr array
    u16 *modv = (u16 *)(DataSeg + sizeof(TDATASEGHEADER) +
                        sizeof(u16)*dh->num_classes +
                        sizeof(u16)*dh->num_modules);

    // check if ptr are in data section
    if (*modv >= HeadSeg->data_size)
            throw "Incorrect file format";

    return &DataSeg[ *modv ];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x58(%rbp)
movq %rdi, %rax
movq %rax, -0x50(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
testb $0x1, 0x48(%rax)
jne 0x4d10
movl $0x8, %edi
callq 0x3110
movq %rax, %rdi
leaq 0x24b7(%rip), %rax      # 0x71b4
movq %rax, (%rdi)
movq 0x52c1(%rip), %rsi      # 0x9fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x33e0
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x5(%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x4(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movw %ax, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
shlq %rax
movw %ax, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
addq $0x34, %rax
movw %ax, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0x6(%rcx), %ecx
cmpl %ecx, %eax
jle 0x4d82
movl $0x8, %edi
callq 0x3110
movq %rax, %rdi
leaq 0x242f(%rip), %rax      # 0x719e
movq %rax, (%rdi)
movq 0x524f(%rip), %rsi      # 0x9fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x33e0
movq -0x18(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x0, %eax
jne 0x4db6
movl $0x8, %edi
callq 0x3110
movq %rax, %rdi
leaq 0x2429(%rip), %rax      # 0x71cc
movq %rax, (%rdi)
movq 0x521b(%rip), %rsi      # 0x9fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x33e0
movq -0x48(%rbp), %rcx
movq 0x38(%rcx), %rax
addq $0x34, %rax
movq -0x18(%rbp), %rdx
movzbl 0x5(%rdx), %edx
shlq %rdx
addq %rdx, %rax
movq -0x18(%rbp), %rdx
movzbl 0x4(%rdx), %edx
shlq %rdx
addq %rdx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
movq 0x28(%rcx), %rcx
movzwl 0x28(%rcx), %ecx
cmpl %ecx, %eax
jl 0x4e1c
movl $0x8, %edi
callq 0x3110
movq %rax, %rdi
leaq 0x2395(%rip), %rax      # 0x719e
movq %rax, (%rdi)
movq 0x51b5(%rip), %rsi      # 0x9fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x33e0
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x28(%rbp), %rcx
movzwl (%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x60(%rbp)
callq 0x3400
movq -0x58(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x55d0
jmp 0x4e52
leaq -0x29(%rbp), %rdi
callq 0x3260
movq -0x50(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x3260
movq -0x38(%rbp), %rdi
callq 0x33f0
nopw %cs:(%rax,%rax)