// File: /workspace/github_c_makefile_star2_O1/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 $0x448, %rsp            # imm = 0x448
movl %ecx, 0x8(%rsp)
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %rbx
movl 0x10(%r8), %r14d
movl 0x18(%r8), %eax
subl %r14d, %r15d
movq %rax, %r13
addl %eax, %r15d
callq 0x30f0
movq %rax, 0x30(%rsp)
movslq %r15d, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3100
leaq 0x426a(%rip), %rdi      # 0x972f
callq 0x3060
movl %r12d, 0xc(%rsp)
testl %r12d, %r12d
jle 0x5638
subl %r14d, %r13d
movq %r13, 0x28(%rsp)
leal 0x2(%r13), %eax
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %r14
xorl %ebp, %ebp
movq 0x38(%rsp), %r12
leaq 0x14(%rsp), %rdi
movq %rbx, %rsi
callq 0x565b
movl 0x14(%rsp), %esi
testl %esi, %esi
je 0x5638
movl %ebp, 0x10(%rsp)
leaq 0x419d(%rip), %rdi      # 0x96b6
xorl %eax, %eax
callq 0x3090
leaq 0x18(%rsp), %rdi
callq 0x3080
leaq 0x3809(%rip), %rdi      # 0x8d3a
movq %rax, %rsi
xorl %eax, %eax
callq 0x3090
movl 0x1c(%rsp), %esi
leaq 0x418c(%rip), %rdi      # 0x96d2
xorl %eax, %eax
callq 0x3090
movl 0x20(%rsp), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x536d
leaq 0x4187(%rip), %rdi      # 0x96ea
xorl %eax, %eax
callq 0x3090
movl 0x20(%rsp), %esi
movq 0x28(%rsp), %r15
addl %r15d, %esi
movq %rbx, %rdi
callq 0x5313
movl $0xa, %edi
callq 0x3030
movl 0x24(%rsp), %esi
leaq 0x416c(%rip), %rdi      # 0x96ff
xorl %eax, %eax
callq 0x3090
movl $0xa, %edi
callq 0x3030
leaq 0x419d(%rip), %rdi      # 0x9748
callq 0x3060
movl 0x24(%rsp), %esi
addl %r15d, %esi
movq %rbx, %rdi
callq 0x53e0
testl %eax, %eax
movl 0x8(%rsp), %ebp
je 0x561d
movl %eax, %r13d
movq 0x28(%rsp), %rax
movl %eax, %r15d
movl 0x14(%rsp), %esi
addl %r15d, %esi
movq %rbx, %rdi
callq 0x53e0
leal (%rax,%r12), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x536d
leaq 0x4124(%rip), %rdi      # 0x971b
movq %r14, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3090
addl %ebp, %r15d
movl 0x24(%rsp), %esi
addl %r15d, %esi
movq %rbx, %rdi
callq 0x53e0
movl %eax, %r13d
testl %eax, %eax
jne 0x55d2
movl $0xa, %edi
callq 0x3030
movl 0x10(%rsp), %ebp
addl $0x14, %ebp
cmpl 0xc(%rsp), %ebp
jl 0x54f5
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x3100
xorl %eax, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq