// File: /workspace/github_cpp_makefile_star2_O3/Vanuan[P]pocketbook_free_swupdate/PocketBookUpdate.cpp
// Function: PocketBookUpdate::PocketBookUpdate(char const*)
PocketBookUpdate::PocketBookUpdate(const char*filename) : mFilename(filename)
{
  // allocate buffer
  int size_of_header = sizeof(PocketBookUpdateHeader);
  buffer = new char[size_of_header];

  // read buffer
  fstream file;
  file.open(filename);
  file.read(buffer, size_of_header);
  file.close();

  // interpret buffer as header
  header = reinterpret_cast<PocketBookUpdateHeader*>(buffer);

  partsNames[SWUPDATE_TAR_GZ] = "swupdate.tar.gz";
  partsNames[ELF_IMG] = "elf.img";
  partsNames[APP_IMG] = "app.img";
  partsNames[ROOTFS_IMG] = "rootfs.img";
  partsNames[A_IMG] = "a.img";

  for(int i = 0; i < sizeof(header->fwParts)/sizeof(header->fwParts[0]); ++i)
  {
    if(0 == header->fwParts[i].size ) continue;
    string name;
    // printName
    map<PartitionType, const char*>::const_iterator partNameIter =
       partsNames.find(static_cast<PartitionType>(header->fwParts[i].type));
    if(partNameIter != partsNames.end())
    {
      name = partNameIter->second;
    }
    else
    {
      name = "unknownImg";
    }
    int nameCounter = 0;
    string tempName;
    map<string, FWPart>::iterator it = parts.end();
    do {
      tempName = name + convertInt(nameCounter);
      it = parts.find(string(tempName));
      nameCounter++;
    }
    while(it != parts.end());
    name = tempName;
    pair<map<string, FWPart>::iterator,bool> index = 
        parts.insert(pair<string, FWPart>(name, header->fwParts[i]));
    index.first->second.offset += sizeof(*header);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x36e0(%rip), %rax      # 0x5d88
movq %rax, (%rdi)
addq $0x18, %rdi
leaq 0xc8(%rsp), %rdx
callq 0x31ca
leaq 0x38(%rbx), %rax
movq %rax, 0x88(%rsp)
leaq 0x40(%rbx), %rcx
xorl %eax, %eax
movl %eax, 0x40(%rbx)
movq %rax, 0x48(%rbx)
movq %rcx, 0x50(%rbx)
movq %rcx, 0x90(%rsp)
movq %rcx, 0x58(%rbx)
movq %rax, 0x60(%rbx)
leaq 0x68(%rbx), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x70(%rbx), %r15
movl %eax, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movq %r15, 0x80(%rbx)
movq %r15, 0x88(%rbx)
movq %rax, 0x90(%rbx)
movl $0x400, %edi            # imm = 0x400
movq %rbx, 0x8(%rsp)
callq 0x2030
movq %rax, 0x8(%rbx)
leaq 0xc8(%rsp), %rdi
callq 0x2250
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
movl $0x18, %edx
callq 0x21b0
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0xc8(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x2270
leaq 0xc8(%rsp), %rdi
callq 0x2060
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq %rax, 0x10(%rcx)
leaq 0x38(%rsp), %rsi
movl $0x73, (%rsi)
movq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x3208
leaq 0x188f(%rip), %rcx      # 0x402d
movq %rcx, (%rax)
leaq 0x38(%rsp), %rsi
movl $0x40, (%rsi)
movq %rbx, %rdi
callq 0x3208
leaq 0x1882(%rip), %rcx      # 0x403d
movq %rcx, (%rax)
leaq 0x38(%rsp), %rsi
movl $0x65, (%rsi)
movq %rbx, %rdi
callq 0x3208
leaq 0x186d(%rip), %rcx      # 0x4045
movq %rcx, (%rax)
leaq 0x38(%rsp), %rsi
movl $0x72, (%rsi)
movq %rbx, %rdi
callq 0x3208
leaq 0x1858(%rip), %rcx      # 0x404d
movq %rcx, (%rax)
leaq 0x38(%rsp), %rsi
movl $0x61, (%rsi)
movq %rbx, %rdi
callq 0x3208
leaq 0x1846(%rip), %rcx      # 0x4058
movq %rcx, (%rax)
leaq 0x48(%rsp), %r14
xorl %ecx, %ecx
leaq 0xa8(%rsp), %rbp
leaq 0x38(%rsp), %r12
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rcx, %rdi
shlq $0x4, %rdi
cmpl $0x0, 0x10c(%rax,%rdi)
je 0x2a9e
movq %rcx, 0x98(%rsp)
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq 0x8(%rsp), %rcx
movq 0x48(%rcx), %rcx
testq %rcx, %rcx
movq %rdi, 0xa0(%rsp)
je 0x28b8
addq $0x100, %rax            # imm = 0x100
movl (%rax,%rdi), %edx
movq 0x90(%rsp), %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x288e
cmpq 0x90(%rsp), %rax
je 0x28b8
cmpl 0x20(%rax), %edx
jge 0x2aad
movl $0xa, %r8d
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x1790(%rip), %rcx      # 0x405e
callq 0x2300
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq $0x0, 0x70(%rsp)
movb $0x0, 0x78(%rsp)
xorl %r13d, %r13d
movq %rbp, %rdi
movl %r13d, %esi
callq 0x25ec
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2220
movq %r14, 0x38(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2932
movq %rdx, 0x38(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x48(%rsp)
jmp 0x2939
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x40(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x2260
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x2975
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x299a
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %r14, 0x38(%rsp)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x3340
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x3670
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x29db
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
incl %r13d
cmpq %r15, %rbx
jne 0x28ee
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x2110
movq 0xa0(%rsp), %r13
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rbx
movq %r14, 0x38(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x3340
movups 0x100(%rbx,%r13), %xmm0
movups %xmm0, 0x10(%r14)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x36fa
movq %rax, %r13
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x2a56
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
addl $0x400, 0x48(%r13)      # imm = 0x400
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2a7a
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2a96
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x98(%rsp), %rcx
incq %rcx
cmpq $0x30, %rcx
jne 0x2829
jmp 0x2ad2
movq 0x28(%rax), %rbx
movq %rbx, %rdi
callq 0x20f0
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2300
jmp 0x28d3
leaq 0xc8(%rsp), %rdi
callq 0x2090
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2b05
jmp 0x2b05
jmp 0x2b05
jmp 0x2b05
jmp 0x2b05
jmp 0x2afd
movq %rax, %rbx
jmp 0x2ba0
movq %rax, %rbx
jmp 0x2b93
jmp 0x2b3c
jmp 0x2b58
jmp 0x2b58
movq %rax, %rbx
jmp 0x2b77
jmp 0x2b58
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x2b5b
movq 0xb8(%rsp), %rsi
jmp 0x2b4e
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r14, %rdi
je 0x2b5b
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x2b5b
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2b77
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2b93
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0xc8(%rsp), %rdi
callq 0x2090
movq 0x30(%rsp), %rdi
callq 0x3278
movq 0x88(%rsp), %rdi
callq 0x32f0
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
addq $0x28, %rax
cmpq %rax, %rdi
je 0x2bd4
movq (%rax), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2350