// File: /workspace/github_c_makefile_star2_O2/mikeakohn[P]print_pe/build/../src/imports.c
// Function: imports_print
int imports_print(
  FILE *in,
  int address,
  int size,
  int address_size,
  struct section_header_t *section_header)
{
  struct import_dir_t import_dir;
  char name[1024];
  long marker;
  int total_size;
  uint32_t virtual_address, raw_ptr;
  int func_addr;
  int t,ptr;

  virtual_address = section_header->VirtualAddress;
  raw_ptr = section_header->PointerToRawData;

  address = (address - virtual_address) + raw_ptr;

  marker = ftell(in);
  fseek(in, address, SEEK_SET);

  printf("  -- Imported Symbols --\n");

  total_size = 0;

  while (total_size < size)
  {
    import_dir_read(&import_dir, in);

    if (import_dir.FunctionNameList == 0) { break; }

    printf("  FunctionNameList: 0x%04x\n", import_dir.FunctionNameList);
    printf("     TimeDateStamp: %s", ctime((time_t *)&import_dir.TimeDateStamp));
    printf("      ForwardChain: %d\n", import_dir.ForwardChain);
    get_string(in, name, import_dir.ModuleName);
    printf("        ModuleName: ");
    print_string(in, (import_dir.ModuleName - virtual_address) + raw_ptr);
    printf("\n");
    printf("FunctionAddresList: 0x%04x\n", import_dir.FunctionAddressList);
    printf("\n");

    printf("     Function Name                   Address\n");

    t = 0;

    while (1)
    {
      func_addr = get_ptr(in, (import_dir.FunctionAddressList - virtual_address) + raw_ptr + t);

      if (func_addr == 0) { break; }

      ptr = get_ptr(in, (import_dir.FunctionNameList - virtual_address) + raw_ptr + t);
      get_string(in, name, (ptr - virtual_address) + raw_ptr + 2);
      printf("     %-30s  0x%08x\n", name, func_addr);

      t = t + address_size;
    }

    printf("\n");
    total_size = total_size + sizeof(import_dir);
  }

  fseek(in, marker, SEEK_SET);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movl %ecx, %ebp
movl %edx, 0x4(%rsp)
movl %esi, %r14d
movq %rdi, %rbx
movl 0x10(%r8), %r15d
movl 0x18(%r8), %r12d
subl %r15d, %r14d
addl %r12d, %r14d
callq 0x30f0
movq %rax, 0x20(%rsp)
movslq %r14d, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3110
leaq 0x434e(%rip), %rdi      # 0x972f
callq 0x3060
subl %r15d, %r12d
movq %r12, 0x28(%rsp)
leal 0x2(%r12), %r15d
leaq 0x30(%rsp), %r12
pushq $0xa
popq %r13
xorl %r14d, %r14d
cmpl 0x4(%rsp), %r14d
jge 0x552c
leaq 0xc(%rsp), %rdi
movq %rbx, %rsi
callq 0x554f
movl 0xc(%rsp), %esi
testl %esi, %esi
je 0x552c
movl %r14d, 0x8(%rsp)
leaq 0x4287(%rip), %rdi      # 0x96b6
xorl %eax, %eax
callq 0x3090
leaq 0x10(%rsp), %rdi
callq 0x3080
leaq 0x38f3(%rip), %rdi      # 0x8d3a
movq %rax, %rsi
xorl %eax, %eax
callq 0x3090
movl 0x14(%rsp), %esi
leaq 0x4276(%rip), %rdi      # 0x96d2
xorl %eax, %eax
callq 0x3090
movl 0x18(%rsp), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x52bb
leaq 0x4271(%rip), %rdi      # 0x96ea
xorl %eax, %eax
callq 0x3090
movl 0x18(%rsp), %esi
movq 0x28(%rsp), %r14
addl %r14d, %esi
movq %rbx, %rdi
callq 0x5270
movl %r13d, %edi
callq 0x3030
movl 0x1c(%rsp), %esi
leaq 0x4258(%rip), %rdi      # 0x96ff
xorl %eax, %eax
callq 0x3090
movl %r13d, %edi
callq 0x3030
leaq 0x428b(%rip), %rdi      # 0x9748
callq 0x3060
movl %r14d, %r13d
movl 0x1c(%rsp), %esi
addl %r13d, %esi
movq %rbx, %rdi
callq 0x531c
testl %eax, %eax
je 0x5512
movl %eax, %r14d
movl 0xc(%rsp), %esi
addl %r13d, %esi
movq %rbx, %rdi
callq 0x531c
leal (%rax,%r15), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x52bb
leaq 0x421b(%rip), %rdi      # 0x971b
movq %r12, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x3090
addl %ebp, %r13d
jmp 0x54c5
pushq $0xa
popq %r13
movl %r13d, %edi
callq 0x3030
movl 0x8(%rsp), %r14d
addl $0x14, %r14d
jmp 0x53ff
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x3110
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq