// File: /workspace/github_c_makefile_star2_O1/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 $0x448, %rsp            # imm = 0x448
movq %r8, (%rsp)
movl %esi, %ebp
movq %rdi, %rbx
movl 0x10(%rcx), %r13d
movl 0x18(%rcx), %r14d
subl %r13d, %ebp
addl %r14d, %ebp
callq 0x30f0
movq %rax, 0x10(%rsp)
movslq %ebp, %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3100
leaq 0x48be(%rip), %rdi      # 0x92a0
callq 0x3060
movq %rbx, %rdi
callq 0x51ca
leaq 0x1c(%rsp), %r12
movl %eax, -0x4(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, (%r12)
movq %rbx, %rdi
callq 0x520c
movw %ax, 0x4(%r12)
movq %rbx, %rdi
callq 0x520c
movw %ax, 0x6(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, 0x8(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, 0xc(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, 0x10(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, 0x14(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, 0x18(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, 0x1c(%r12)
movq %rbx, %rdi
callq 0x51ca
movl %eax, 0x20(%r12)
movl -0x4(%r12), %esi
leaq 0x472f(%rip), %rdi      # 0x91b7
xorl %eax, %eax
callq 0x3090
movq %r12, %rdi
callq 0x3080
leaq 0x429c(%rip), %rdi      # 0x8d3a
movq %rax, %rsi
xorl %eax, %eax
callq 0x3090
movzwl 0x4(%r12), %esi
leaq 0x429c(%rip), %rdi      # 0x8d51
xorl %eax, %eax
callq 0x3090
movzwl 0x6(%r12), %esi
leaq 0x42a0(%rip), %rdi      # 0x8d69
xorl %eax, %eax
callq 0x3090
leaq 0x46fc(%rip), %rdi      # 0x91d3
xorl %eax, %eax
callq 0x3090
subl %r13d, %r14d
movl 0x8(%r12), %esi
movq %r14, 0x8(%rsp)
addl %r14d, %esi
movq %rbx, %rdi
callq 0x5313
movl $0xa, %edi
callq 0x3030
movl 0xc(%r12), %esi
leaq 0x46dc(%rip), %rdi      # 0x91e8
xorl %eax, %eax
callq 0x3090
movl 0x10(%r12), %esi
leaq 0x46e1(%rip), %rdi      # 0x9200
xorl %eax, %eax
callq 0x3090
movl 0x14(%r12), %esi
leaq 0x46e6(%rip), %rdi      # 0x9218
xorl %eax, %eax
callq 0x3090
movl 0x18(%r12), %esi
leaq 0x46eb(%rip), %rdi      # 0x9230
xorl %eax, %eax
callq 0x3090
movl 0x1c(%r12), %esi
leaq 0x46f4(%rip), %rdi      # 0x924c
xorl %eax, %eax
callq 0x3090
movl 0x20(%r12), %esi
leaq 0x46fd(%rip), %rdi      # 0x9268
xorl %eax, %eax
callq 0x3090
movl $0xa, %edi
callq 0x3030
leaq 0x4737(%rip), %rdi      # 0x92ba
callq 0x3060
cmpl $0x0, 0x14(%r12)
je 0x4c3b
leaq 0x40(%rsp), %r12
movq 0x8(%rsp), %rax
movl %eax, %r15d
movl %eax, %r13d
xorl %r14d, %r14d
movl 0x38(%rsp), %esi
addl %r15d, %esi
movq %rbx, %rdi
callq 0x53e0
movq 0x8(%rsp), %rcx
leal (%rax,%rcx), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x536d
movl 0x34(%rsp), %esi
addl %r15d, %esi
movq %rbx, %rdi
callq 0x53e0
movl %eax, %ebp
movl 0x3c(%rsp), %esi
addl %r13d, %esi
movq %rbx, %rdi
callq 0x541e
leaq 0x4694(%rip), %rdi      # 0x9284
movq %r12, %rsi
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x3090
movq (%rsp), %rax
cmpb $0x0, (%rax)
je 0x4c25
movq (%rsp), %rdi
movq %r12, %rsi
callq 0x30c0
movq (%rsp), %rcx
testl %eax, %eax
jne 0x4c25
movslq %ebp, %rax
movq %rax, 0x408(%rcx)
incl %r14d
addl $0x2, %r13d
addl $0x4, %r15d
cmpl 0x30(%rsp), %r14d
jb 0x4ba7
movl $0xa, %edi
callq 0x3030
movq %rbx, %rdi
movq 0x10(%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