// File: Vanuan[P]pocketbook_free_swupdate/PocketBookUpdate.cpp
// Function: PocketBookUpdate::extract(char const*)
void PocketBookUpdate::extract(const char * outputDir)
{
  struct stat st;
  if(stat(outputDir,&st) != 0)
  {
    cout << "Directory " << outputDir << " doesn't exist" << endl;
    return;
  }
  ifstream infile(mFilename.c_str(), ifstream::binary);
  map<string, FWPart>::const_iterator it;
  for ( it=parts.begin(); it != parts.end(); it++ )
  {
    infile.seekg(it->second.offset);
    string outputFilename = string(outputDir) + string("/") + it->first;
    ofstream outfile(outputFilename.c_str(), ofstream::binary);
    long unsigned int size = it->second.size;
    char*buf = new char[size];
    infile.read(buf, size);
    outfile.write(buf, size);
    delete[] buf;
    outfile.close();
  }
  infile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5d0, %rsp            # imm = 0x5D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x5a0(%rbp)
movq -0x10(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3220
cmpl $0x0, %eax
je 0x3fd5
movq 0x8036(%rip), %rdi      # 0xbfd0
leaq 0x40c8(%rip), %rsi      # 0x8069
callq 0x3250
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x3250
movq %rax, %rdi
leaq 0x40b8(%rip), %rsi      # 0x8074
callq 0x3250
movq %rax, %rdi
movq 0x7ff5(%rip), %rsi      # 0xbfc0
callq 0x3290
jmp 0x4393
movq -0x5a0(%rbp), %rdi
addq $0x18, %rdi
callq 0x3110
movq %rax, %rsi
leaq -0x2a8(%rbp), %rdi
movl $0x4, %edx
callq 0x3440
leaq -0x2b0(%rbp), %rdi
callq 0x4d10
movq -0x5a0(%rbp), %rdi
addq $0x68, %rdi
callq 0x4d30
movq %rax, -0x2c0(%rbp)
leaq -0x2b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x4d60
movq -0x2b8(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movq -0x5a0(%rbp), %rdi
addq $0x68, %rdi
callq 0x4b20
movq %rax, -0x2d0(%rbp)
leaq -0x2c8(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x4d60
leaq -0x2b0(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x4d80
testb $0x1, %al
jne 0x4083
jmp 0x4379
leaq -0x2b0(%rbp), %rdi
callq 0x4db0
movl 0x28(%rax), %eax
movl %eax, %esi
leaq -0x2e0(%rbp), %rdi
callq 0x4dd0
jmp 0x40a2
movq -0x2e0(%rbp), %rsi
movq -0x2d8(%rbp), %rdx
leaq -0x2a8(%rbp), %rdi
callq 0x3340
jmp 0x40be
movq -0x10(%rbp), %rax
movq %rax, -0x5b0(%rbp)
leaq -0x351(%rbp), %rdi
movq %rdi, -0x5a8(%rbp)
callq 0x3420
movq -0x5b0(%rbp), %rsi
movq -0x5a8(%rbp), %rdx
leaq -0x350(%rbp), %rdi
callq 0x4860
jmp 0x40f8
leaq -0x379(%rbp), %rdi
movq %rdi, -0x5b8(%rbp)
callq 0x3420
movq -0x5b8(%rbp), %rdx
leaq 0x3f6a(%rip), %rsi      # 0x8083
leaq -0x378(%rbp), %rdi
callq 0x4860
jmp 0x4127
leaq -0x330(%rbp), %rdi
leaq -0x350(%rbp), %rsi
leaq -0x378(%rbp), %rdx
callq 0x4e60
jmp 0x4143
leaq -0x2b0(%rbp), %rdi
callq 0x4db0
movq %rax, %rdx
leaq -0x310(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x4e10
jmp 0x4167
leaq -0x330(%rbp), %rdi
callq 0x3160
leaq -0x378(%rbp), %rdi
callq 0x3160
leaq -0x379(%rbp), %rdi
callq 0x32b0
leaq -0x350(%rbp), %rdi
callq 0x3160
leaq -0x351(%rbp), %rdi
callq 0x32b0
leaq -0x310(%rbp), %rdi
callq 0x3110
movq %rax, %rsi
leaq -0x580(%rbp), %rdi
movl $0x4, %edx
callq 0x32c0
jmp 0x41c5
leaq -0x2b0(%rbp), %rdi
callq 0x4db0
movl 0x2c(%rax), %eax
movq %rax, -0x588(%rbp)
movq -0x588(%rbp), %rdi
callq 0x3030
movq %rax, -0x5c0(%rbp)
jmp 0x41f0
movq -0x5c0(%rbp), %rax
movq %rax, -0x590(%rbp)
movq -0x590(%rbp), %rsi
movq -0x588(%rbp), %rdx
leaq -0x2a8(%rbp), %rdi
callq 0x3330
jmp 0x421a
movq -0x590(%rbp), %rsi
movq -0x588(%rbp), %rdx
leaq -0x580(%rbp), %rdi
callq 0x3360
jmp 0x4236
movq -0x590(%rbp), %rax
movq %rax, -0x5c8(%rbp)
cmpq $0x0, %rax
je 0x4256
movq -0x5c8(%rbp), %rdi
callq 0x3350
leaq -0x580(%rbp), %rdi
callq 0x33a0
jmp 0x4264
leaq -0x580(%rbp), %rdi
callq 0x33c0
leaq -0x310(%rbp), %rdi
callq 0x3160
leaq -0x2b0(%rbp), %rdi
xorl %esi, %esi
callq 0x4f30
movq %rax, -0x598(%rbp)
jmp 0x403d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e8(%rbp)
movl %eax, -0x2ec(%rbp)
jmp 0x439c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e8(%rbp)
movl %eax, -0x2ec(%rbp)
jmp 0x432b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e8(%rbp)
movl %eax, -0x2ec(%rbp)
jmp 0x4313
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e8(%rbp)
movl %eax, -0x2ec(%rbp)
jmp 0x4307
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e8(%rbp)
movl %eax, -0x2ec(%rbp)
leaq -0x330(%rbp), %rdi
callq 0x3160
leaq -0x378(%rbp), %rdi
callq 0x3160
leaq -0x379(%rbp), %rdi
callq 0x32b0
leaq -0x350(%rbp), %rdi
callq 0x3160
leaq -0x351(%rbp), %rdi
callq 0x32b0
jmp 0x439c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e8(%rbp)
movl %eax, -0x2ec(%rbp)
jmp 0x436b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e8(%rbp)
movl %eax, -0x2ec(%rbp)
leaq -0x580(%rbp), %rdi
callq 0x33c0
leaq -0x310(%rbp), %rdi
callq 0x3160
jmp 0x439c
leaq -0x2a8(%rbp), %rdi
callq 0x30a0
jmp 0x4387
leaq -0x2a8(%rbp), %rdi
callq 0x30c0
addq $0x5d0, %rsp            # imm = 0x5D0
popq %rbp
retq
leaq -0x2a8(%rbp), %rdi
callq 0x30c0
movq -0x2e8(%rbp), %rdi
callq 0x3410
nopw %cs:(%rax,%rax)