// File: /workspace/github_c_makefile_star2_O2/mikeakohn[P]print_pe/build/../src/exports.c
// Function: exports_print
int exports_print(
  FILE *in,
  int addr,
  int size,
  struct section_header_t *section_header,
  struct funct_t *funct)
{
  struct export_dir_t export_dir;
  char func_name[1024];
  int virtual_address,raw_ptr;
  int func_addr,name_ord;
  long marker;
  int t,ptr;

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

  addr = (addr - virtual_address) + raw_ptr;
  marker = ftell(in);
  fseek(in, addr, SEEK_SET);

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

  export_dir.Characteristics = read_uint32(in);
  export_dir.TimeDateStamp = read_uint32(in);
  export_dir.MajorVersion = read_uint16(in);
  export_dir.MinorVersion = read_uint16(in);
  export_dir.Name = read_uint32(in);
  export_dir.Base = read_uint32(in);
  export_dir.NumberOfFunctions = read_uint32(in);
  export_dir.NumberOfNames = read_uint32(in);
  export_dir.AddressOfFunctions = read_uint32(in);
  export_dir.AddressOfNames = read_uint32(in);
  export_dir.AddressOfNameOrdinals = read_uint32(in);

  printf("   Characteristics: 0x%08x\n", export_dir.Characteristics);
  printf("     TimeDateStamp: %s", ctime((time_t *)&export_dir.TimeDateStamp));
  printf("      MajorVersion: %d\n", export_dir.MajorVersion);
  printf("      MinorVersion: %d\n", export_dir.MinorVersion);
  printf("              Name: ");
  print_string(in, (export_dir.Name - virtual_address) + raw_ptr);
  printf("\n");
  printf("              Base: %d\n", export_dir.Base);
  printf(" NumberOfFunctions: %d\n", export_dir.NumberOfFunctions);
  printf("     NumberOfNames: %d\n", export_dir.NumberOfNames);
  printf("AddressOfFunctions: 0x%04x\n", export_dir.AddressOfFunctions);
  printf("    AddressOfNames: 0x%04x\n", export_dir.AddressOfNames);
  printf("AddrOfNameOrdinals: 0x%04x\n", export_dir.AddressOfNameOrdinals);
  printf("\n");

  printf("     Function Name                   Address     Ordinal\n");

  for (t = 0; t < export_dir.NumberOfNames; t++)
  {
    ptr = get_ptr(in, (export_dir.AddressOfNames - virtual_address) + raw_ptr + (t * 4));
    get_string(in, func_name, (ptr - virtual_address) + raw_ptr);

    func_addr = get_ptr(in, (export_dir.AddressOfFunctions - virtual_address) + raw_ptr + (t * 4));
    name_ord = get_ushort(in, (export_dir.AddressOfNameOrdinals - virtual_address) + raw_ptr + (t * 2));

    printf("     %-30s  0x%08x  0x%04x\n", func_name, func_addr, name_ord);

    if (funct->funct_name[0] != 0)
    {
      if (strcmp(funct->funct_name, func_name) == 0)
      {
        funct->funct_ptr = func_addr;
      }
    }
  }

  printf("\n");

  fseek(in, marker, SEEK_SET);

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %r8, %r15
movl %esi, %ebp
movq %rdi, %rbx
movl 0x10(%rcx), %r13d
movl 0x18(%rcx), %r14d
subl %r13d, %ebp
addl %r14d, %ebp
callq 0x30f0
movq %rax, 0x18(%rsp)
movslq %ebp, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3110
leaq 0x494f(%rip), %rdi      # 0x92a0
callq 0x3060
movq %rbx, %rdi
callq 0x5126
movl %eax, %ebp
leaq 0x2c(%rsp), %r12
movl %eax, -0x4(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, (%r12)
movq %rbx, %rdi
callq 0x5168
movw %ax, 0x4(%r12)
movq %rbx, %rdi
callq 0x5168
movw %ax, 0x6(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, 0x8(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, 0xc(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, 0x10(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, 0x14(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, 0x18(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, 0x1c(%r12)
movq %rbx, %rdi
callq 0x5126
movl %eax, 0x20(%r12)
leaq 0x47c3(%rip), %rdi      # 0x91b7
movl %ebp, %esi
xorl %eax, %eax
callq 0x3090
movq %r12, %rdi
callq 0x3080
leaq 0x432e(%rip), %rdi      # 0x8d3a
movq %rax, %rsi
xorl %eax, %eax
callq 0x3090
movzwl 0x4(%r12), %esi
leaq 0x432e(%rip), %rdi      # 0x8d51
xorl %eax, %eax
callq 0x3090
movzwl 0x6(%r12), %esi
leaq 0x4332(%rip), %rdi      # 0x8d69
xorl %eax, %eax
callq 0x3090
leaq 0x478e(%rip), %rdi      # 0x91d3
xorl %eax, %eax
callq 0x3090
subl %r13d, %r14d
movl 0x8(%r12), %esi
addl %r14d, %esi
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
callq 0x5270
pushq $0xa
popq %rbp
movl %ebp, %edi
callq 0x3030
movl 0xc(%r12), %esi
leaq 0x476e(%rip), %rdi      # 0x91e8
xorl %eax, %eax
callq 0x3090
movl 0x10(%r12), %esi
leaq 0x4773(%rip), %rdi      # 0x9200
xorl %eax, %eax
callq 0x3090
movl 0x14(%r12), %esi
leaq 0x4778(%rip), %rdi      # 0x9218
xorl %eax, %eax
callq 0x3090
movl 0x18(%r12), %esi
leaq 0x477d(%rip), %rdi      # 0x9230
xorl %eax, %eax
callq 0x3090
movl 0x1c(%r12), %esi
leaq 0x4786(%rip), %rdi      # 0x924c
xorl %eax, %eax
callq 0x3090
movl 0x20(%r12), %esi
leaq 0x478f(%rip), %rdi      # 0x9268
xorl %eax, %eax
callq 0x3090
movl %ebp, %edi
callq 0x3030
leaq 0x47cc(%rip), %rdi      # 0x92ba
callq 0x3060
movq %r15, %rcx
movl %r14d, %r15d
movq %r14, %rax
movq %r14, 0x20(%rsp)
movl %eax, 0xc(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %r13
cmpl 0x40(%rsp), %r14d
jae 0x4bb1
movl 0x48(%rsp), %esi
addl %r15d, %esi
movq %rcx, %r12
movq %r13, %rdi
callq 0x531c
movq 0x20(%rsp), %rcx
leal (%rax,%rcx), %edx
movq %r13, %rdi
leaq 0x50(%rsp), %rbx
movq %rbx, %rsi
callq 0x52bb
movl 0x44(%rsp), %esi
addl %r15d, %esi
movq %r13, %rdi
callq 0x531c
movl %eax, %ebp
movl 0x4c(%rsp), %esi
addl 0xc(%rsp), %esi
movq %r13, %rdi
callq 0x535a
leaq 0x471a(%rip), %rdi      # 0x9284
movq %rbx, %rsi
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x3090
movq %r12, %rcx
cmpb $0x0, (%r12)
je 0x4ba0
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
callq 0x30c0
movq %r12, %rcx
testl %eax, %eax
jne 0x4ba0
movslq %ebp, %rax
movq %rax, 0x408(%rcx)
incl %r14d
addl $0x2, 0xc(%rsp)
addl $0x4, %r15d
jmp 0x4b0d
pushq $0xa
popq %rdi
callq 0x3030
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x3110
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop