// File: /workspace/github_c_makefile_star2_O0/mikeakohn[P]print_pe/build/../src/vb.c
// Function: vb_info_print
int vb_info_print(
  FILE *in,
  struct optional_header_t *optional_header,
  struct section_header_t *section_header)
{
  struct vb_header_t vb_header;
  struct com_reg_data_t com_reg_data;
  struct reg_info_t reg_info;
  int marker,ptr;
  int t;
  int addr;

  marker = ftell(in);
  fseek(in, (optional_header->AddressOfEntryPoint - section_header->VirtualAddress) + section_header->PointerToRawData, SEEK_SET);

  ptr = getc(in);
  /* Compiled VB executables / DLLs have a couple of entry point signitures. */
  /* 0x68, 0x90, 0x5A */
  switch (ptr)
  {
    case 0x5a: /* 0x5A = POP EDX, this means the file might be a VB DLL or OCX. */
	    /* The pointer to the VB5! data stuff is in the first exported function. Usually DllCanUnloadNow()
	     * Once we get to that address it turns into case 0x68 again. */
	    /* Get the address to the export directory */
	    addr = (optional_header->directory_entry[0].virtual_address - section_header->VirtualAddress) + section_header->PointerToRawData;
	    /* ExportDirectory->AddressOfFunctions = addr+28; */
	    addr = get_ptr(in, get_ptr(in,(addr + 28)));
	    fseek(in, addr + 2, SEEK_SET); /* read past 0x58, 0x68 */
	    ptr = read_uint16(in);
	    break;
    case 0x90: /* 0x90 = NOP, then it's case 0x68 */
	    getc(in); /* read the NOP then fall through to case 0x68 */
    case 0x68: /* 0x68 = PUSH (word) */
	    ptr = read_uint16(in);
	    break;
    default:
	    fseek(in, marker, SEEK_SET);
	    return -2;
	    break;
  }

  if (section_header->VirtualAddress <= ptr &&
      ptr < section_header->VirtualAddress + section_header->SizeOfRawData)
  {
    fseek(in, (ptr - section_header->VirtualAddress) + section_header->PointerToRawData, SEEK_SET);
  }
    else
  {
    fseek(in, marker, SEEK_SET);
    return -3;
  }

  read_chars(in, vb_header.szVbMagic, 4);

  if (strcmp(vb_header.szVbMagic, "VB5!") != 0)
  {
    fseek(in, marker, SEEK_SET);
    return -1;
  }

  vb_header.wRuntimeBuild = read_uint16(in);
  read_chars(in, vb_header.szLangDll, 14);
  read_chars(in, vb_header.szSecLangDll, 14);
  vb_header.wRuntimeRevision = read_uint16(in);
  vb_header.dwLCID = read_uint32(in);
  vb_header.dwSecLCID = read_uint32(in);
  vb_header.lpSubMain = read_uint32(in);
  vb_header.lpProjectData = read_uint32(in);
  vb_header.fMdlIntCtls = read_uint32(in);
  vb_header.fMdlIntCtls2 = read_uint32(in);
  vb_header.dwThreadFlags = read_uint32(in);
  vb_header.dwThreadCount = read_uint32(in);
  vb_header.wFormCount = read_uint16(in);
  vb_header.wExternalCount = read_uint16(in);
  vb_header.dwThunkCount = read_uint32(in);
  vb_header.lpGuiTable = read_uint32(in);
  vb_header.lpExternalTable = read_uint32(in);
  vb_header.lpComRegisterData = read_uint32(in);
  vb_header.bSzProjectDescription = read_uint32(in);
  vb_header.bSzProjectExeName = read_uint32(in);
  vb_header.bSzProjectHelpFile = read_uint32(in);
  vb_header.bSzProjectName = read_uint32(in);

  printf("  -- VB Header --\n");
  printf("         szVbMagic: %s\n", vb_header.szVbMagic);
  printf("     wRuntimeBuild: %d\n", vb_header.wRuntimeBuild);
  printf("         szLangDll: %s\n", vb_header.szLangDll);
  printf("      szSecLangDll: %s\n", vb_header.szSecLangDll);
  printf("  wRuntimeRevision: %d\n", vb_header.wRuntimeRevision);
  printf("            dwLCID: %d\n", vb_header.dwLCID);
  printf("         dwSecLCID: %d\n", vb_header.dwSecLCID);
  printf("         lpSubMain: %d\n", vb_header.lpSubMain);
  printf("     lpProjectData: %d\n", vb_header.lpProjectData);
  printf("       fMdlIntCtls: 0x%08x\n", vb_header.fMdlIntCtls);
  printf("      fMdlIntCtls2: 0x%08x\n", vb_header.fMdlIntCtls2);
  printf("     dwThreadFlags: %d", vb_header.dwThreadFlags);
  printf(" (");

  if ((vb_header.dwThreadFlags & 1) == 1) printf(" ApartmentModel");
  if ((vb_header.dwThreadFlags & 2) == 2) printf(" RequireLicense");
  if ((vb_header.dwThreadFlags & 4) == 4) printf(" Unattended");
  if ((vb_header.dwThreadFlags & 8) == 8) printf(" SingleThreaded");
  if ((vb_header.dwThreadFlags & 16) == 16) printf(" Retained");

  printf(" )\n");
  printf("     dwThreadCount: %d\n", vb_header.dwThreadCount);
  printf("        wFormCount: %d\n", vb_header.wFormCount);
  printf("    wExternalCount: %d\n", vb_header.wExternalCount);
  printf("      dwThunkCount: %d\n", vb_header.dwThunkCount);
  printf("        lpGuiTable: %d\n", vb_header.lpGuiTable);
  printf("   lpExternalTable: %d\n", vb_header.lpExternalTable);
  printf(" lpComRegisterData: %d\n", vb_header.lpComRegisterData);
  printf("    bSzProjectDesc: %d (", vb_header.bSzProjectDescription);
  print_string(in, ((vb_header.bSzProjectDescription+ptr)-section_header->VirtualAddress)+section_header->PointerToRawData);
  printf(")\n");
  printf(" bSzProjectExeName: %d (",vb_header.bSzProjectExeName);
  print_string(in, ((vb_header.bSzProjectExeName + ptr) - section_header->VirtualAddress) + section_header->PointerToRawData);
  printf(")\n");
  printf("bSzProjectHelpFile: %d (",vb_header.bSzProjectHelpFile);
  print_string(in, ((vb_header.bSzProjectHelpFile + ptr) - section_header->VirtualAddress) + section_header->PointerToRawData);
  printf(")\n");
  printf("    bSzProjectName: %d (",vb_header.bSzProjectName);
  print_string(in, ((vb_header.bSzProjectName + ptr) - section_header->VirtualAddress) + section_header->PointerToRawData);
  printf(")\n");
  printf("\n");

  if (vb_header.lpComRegisterData != 0)
  {
    com_reg_data_read(&com_reg_data, in, vb_header.lpComRegisterData - optional_header->ImageBase);

    com_reg_data_print(&com_reg_data);

    if (com_reg_data.bRegInfo != 0)
    {
      t = com_reg_data.bRegInfo;

      while (1)
      {
        reg_info_read(&reg_info, in, vb_header.lpComRegisterData - optional_header->ImageBase + t);

        get_string(in, (char *)reg_info.szObjectName, vb_header.lpComRegisterData - optional_header->ImageBase + reg_info.bObjectName);

        reg_info_print(&reg_info);

        if (reg_info.bNextObject == 0) { break; }

        t = reg_info.bNextObject;
      }
    }
  }

  fseek(in, marker, SEEK_SET);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x520, %rsp            # imm = 0x520
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30e0
movl %eax, -0x504(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %edx
movl 0x18(%rcx), %ecx
subl %edx, %eax
addl %ecx, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x3100
movq -0x10(%rbp), %rdi
callq 0x3150
movl %eax, -0x508(%rbp)
movl -0x508(%rbp), %eax
movl %eax, -0x514(%rbp)
subl $0x5a, %eax
je 0x898d
jmp 0x896a
movl -0x514(%rbp), %eax
subl $0x68, %eax
je 0x8a0a
jmp 0x897b
movl -0x514(%rbp), %eax
subl $0x90, %eax
je 0x8a01
jmp 0x8a1b
movq -0x18(%rbp), %rax
movl 0x7c(%rax), %eax
movq -0x20(%rbp), %rcx
subl 0x10(%rcx), %eax
movq -0x20(%rbp), %rcx
addl 0x18(%rcx), %eax
movl %eax, -0x510(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x520(%rbp)
movq -0x10(%rbp), %rdi
movl -0x510(%rbp), %esi
addl $0x1c, %esi
callq 0x6330
movq -0x520(%rbp), %rdi
movl %eax, %esi
callq 0x6330
movl %eax, -0x510(%rbp)
movq -0x10(%rbp), %rdi
movl -0x510(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
xorl %edx, %edx
callq 0x3100
movq -0x10(%rbp), %rdi
callq 0x6070
movl %eax, -0x508(%rbp)
jmp 0x8a39
movq -0x10(%rbp), %rdi
callq 0x3150
movq -0x10(%rbp), %rdi
callq 0x6070
movl %eax, -0x508(%rbp)
jmp 0x8a39
movq -0x10(%rbp), %rdi
movslq -0x504(%rbp), %rsi
xorl %edx, %edx
callq 0x3100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x9005
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x508(%rbp), %eax
ja 0x8a85
movl -0x508(%rbp), %eax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq -0x20(%rbp), %rdx
addl 0x14(%rdx), %ecx
cmpl %ecx, %eax
jae 0x8a85
movq -0x10(%rbp), %rdi
movl -0x508(%rbp), %eax
movq -0x20(%rbp), %rcx
subl 0x10(%rcx), %eax
movq -0x20(%rbp), %rcx
addl 0x18(%rcx), %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x3100
jmp 0x8aa3
movq -0x10(%rbp), %rdi
movslq -0x504(%rbp), %rsi
xorl %edx, %edx
callq 0x3100
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x9005
movq -0x10(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
movl $0x4, %edx
callq 0x60e0
leaq -0x8c(%rbp), %rdi
leaq 0x4049(%rip), %rsi      # 0xcb0f
callq 0x30b0
cmpl $0x0, %eax
je 0x8aee
movq -0x10(%rbp), %rdi
movslq -0x504(%rbp), %rsi
xorl %edx, %edx
callq 0x3100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9005
movq -0x10(%rbp), %rdi
callq 0x6070
movw %ax, -0x86(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
addq $0x8, %rsi
movl $0xe, %edx
callq 0x60e0
movq -0x10(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
addq $0x17, %rsi
movl $0xe, %edx
callq 0x60e0
movq -0x10(%rbp), %rdi
callq 0x6070
movw %ax, -0x66(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6070
movw %ax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6070
movw %ax, -0x42(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6010
movl %eax, -0x24(%rbp)
leaq 0x3ef6(%rip), %rdi      # 0xcb14
movb $0x0, %al
callq 0x3080
leaq -0x8c(%rbp), %rsi
leaq 0x3ef4(%rip), %rdi      # 0xcb27
movb $0x0, %al
callq 0x3080
movzwl -0x86(%rbp), %esi
leaq 0x3ef7(%rip), %rdi      # 0xcb3f
movb $0x0, %al
callq 0x3080
leaq -0x8c(%rbp), %rsi
addq $0x8, %rsi
leaq 0x3ef6(%rip), %rdi      # 0xcb57
movb $0x0, %al
callq 0x3080
leaq -0x8c(%rbp), %rsi
addq $0x17, %rsi
leaq 0x3ef5(%rip), %rdi      # 0xcb6f
movb $0x0, %al
callq 0x3080
movzwl -0x66(%rbp), %esi
leaq 0x3efb(%rip), %rdi      # 0xcb87
movb $0x0, %al
callq 0x3080
movl -0x64(%rbp), %esi
leaq 0x3f02(%rip), %rdi      # 0xcb9f
movb $0x0, %al
callq 0x3080
movl -0x60(%rbp), %esi
leaq 0x3f09(%rip), %rdi      # 0xcbb7
movb $0x0, %al
callq 0x3080
movl -0x5c(%rbp), %esi
leaq 0x3f10(%rip), %rdi      # 0xcbcf
movb $0x0, %al
callq 0x3080
movl -0x58(%rbp), %esi
leaq 0x3f17(%rip), %rdi      # 0xcbe7
movb $0x0, %al
callq 0x3080
movl -0x54(%rbp), %esi
leaq 0x3f1e(%rip), %rdi      # 0xcbff
movb $0x0, %al
callq 0x3080
movl -0x50(%rbp), %esi
leaq 0x3f29(%rip), %rdi      # 0xcc1b
movb $0x0, %al
callq 0x3080
movl -0x4c(%rbp), %esi
leaq 0x3f34(%rip), %rdi      # 0xcc37
movb $0x0, %al
callq 0x3080
leaq 0x4045(%rip), %rdi      # 0xcd56
movb $0x0, %al
callq 0x3080
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x1, %eax
jne 0x8d31
leaq 0x3f24(%rip), %rdi      # 0xcc4e
movb $0x0, %al
callq 0x3080
movl -0x4c(%rbp), %eax
andl $0x2, %eax
cmpl $0x2, %eax
jne 0x8d4a
leaq 0x3f1b(%rip), %rdi      # 0xcc5e
movb $0x0, %al
callq 0x3080
movl -0x4c(%rbp), %eax
andl $0x4, %eax
cmpl $0x4, %eax
jne 0x8d63
leaq 0x3f12(%rip), %rdi      # 0xcc6e
movb $0x0, %al
callq 0x3080
movl -0x4c(%rbp), %eax
andl $0x8, %eax
cmpl $0x8, %eax
jne 0x8d7c
leaq 0x3f05(%rip), %rdi      # 0xcc7a
movb $0x0, %al
callq 0x3080
movl -0x4c(%rbp), %eax
andl $0x10, %eax
cmpl $0x10, %eax
jne 0x8d95
leaq 0x3efc(%rip), %rdi      # 0xcc8a
movb $0x0, %al
callq 0x3080
leaq 0x3ef8(%rip), %rdi      # 0xcc94
movb $0x0, %al
callq 0x3080
movl -0x48(%rbp), %esi
leaq 0x3eeb(%rip), %rdi      # 0xcc98
movb $0x0, %al
callq 0x3080
movzwl -0x44(%rbp), %esi
leaq 0x3ef1(%rip), %rdi      # 0xccb0
movb $0x0, %al
callq 0x3080
movzwl -0x42(%rbp), %esi
leaq 0x3ef7(%rip), %rdi      # 0xccc8
movb $0x0, %al
callq 0x3080
movl -0x40(%rbp), %esi
leaq 0x3efe(%rip), %rdi      # 0xcce0
movb $0x0, %al
callq 0x3080
movl -0x3c(%rbp), %esi
leaq 0x3f05(%rip), %rdi      # 0xccf8
movb $0x0, %al
callq 0x3080
movl -0x38(%rbp), %esi
leaq 0x3f0c(%rip), %rdi      # 0xcd10
movb $0x0, %al
callq 0x3080
movl -0x34(%rbp), %esi
leaq 0x3f13(%rip), %rdi      # 0xcd28
movb $0x0, %al
callq 0x3080
movl -0x30(%rbp), %esi
leaq 0x3f1a(%rip), %rdi      # 0xcd40
movb $0x0, %al
callq 0x3080
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
addl -0x508(%rbp), %esi
movq -0x20(%rbp), %rax
subl 0x10(%rax), %esi
movq -0x20(%rbp), %rax
addl 0x18(%rax), %esi
callq 0x6230
leaq 0x3e41(%rip), %rdi      # 0xcc95
movb $0x0, %al
callq 0x3080
movl -0x2c(%rbp), %esi
leaq 0x3ef4(%rip), %rdi      # 0xcd59
movb $0x0, %al
callq 0x3080
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
addl -0x508(%rbp), %esi
movq -0x20(%rbp), %rax
subl 0x10(%rax), %esi
movq -0x20(%rbp), %rax
addl 0x18(%rax), %esi
callq 0x6230
leaq 0x3e02(%rip), %rdi      # 0xcc95
movb $0x0, %al
callq 0x3080
movl -0x28(%rbp), %esi
leaq 0x3ece(%rip), %rdi      # 0xcd72
movb $0x0, %al
callq 0x3080
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %esi
addl -0x508(%rbp), %esi
movq -0x20(%rbp), %rax
subl 0x10(%rax), %esi
movq -0x20(%rbp), %rax
addl 0x18(%rax), %esi
callq 0x6230
leaq 0x3dc3(%rip), %rdi      # 0xcc95
movb $0x0, %al
callq 0x3080
movl -0x24(%rbp), %esi
leaq 0x3ea8(%rip), %rdi      # 0xcd8b
movb $0x0, %al
callq 0x3080
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
addl -0x508(%rbp), %esi
movq -0x20(%rbp), %rax
subl 0x10(%rax), %esi
movq -0x20(%rbp), %rax
addl 0x18(%rax), %esi
callq 0x6230
leaq 0x3d84(%rip), %rdi      # 0xcc95
movb $0x0, %al
callq 0x3080
leaq 0x120d(%rip), %rdi      # 0xa12c
movb $0x0, %al
callq 0x3080
cmpl $0x0, -0x34(%rbp)
je 0x8fec
movq -0x10(%rbp), %rsi
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
subq 0x20(%rcx), %rax
movl %eax, %edx
leaq -0xb8(%rbp), %rdi
callq 0x4320
leaq -0xb8(%rbp), %rdi
callq 0x4410
cmpl $0x0, -0xb8(%rbp)
je 0x8fea
movl -0xb8(%rbp), %eax
movl %eax, -0x50c(%rbp)
movq -0x10(%rbp), %rsi
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
subq 0x20(%rcx), %rax
movslq -0x50c(%rbp), %rcx
addq %rcx, %rax
movl %eax, %edx
leaq -0x500(%rbp), %rdi
callq 0x3fe0
movq -0x10(%rbp), %rdi
leaq -0x500(%rbp), %rsi
addq $0x48, %rsi
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
subq 0x20(%rcx), %rax
movl -0x4fc(%rbp), %ecx
addq %rcx, %rax
movl %eax, %edx
callq 0x62a0
leaq -0x500(%rbp), %rdi
callq 0x4160
cmpl $0x0, -0x500(%rbp)
jne 0x8fda
jmp 0x8fe8
movl -0x500(%rbp), %eax
movl %eax, -0x50c(%rbp)
jmp 0x8f72
jmp 0x8fea
jmp 0x8fec
movq -0x10(%rbp), %rdi
movslq -0x504(%rbp), %rsi
xorl %edx, %edx
callq 0x3100
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x520, %rsp            # imm = 0x520
popq %rbp
retq