Advertisement
IVDZ

PE Information

Jul 27th, 2014
2,991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 4.58 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2.  
  3. Public Class Form1
  4.  
  5.     <StructLayout(LayoutKind.Sequential, Pack:=1)> _
  6.     Public Structure IMAGE_DOS_HEADER
  7.         Public e_magic As UInt16
  8.         Public e_cblp As UInt16
  9.         Public e_cp As UInt16
  10.         Public e_crlc As UInt16
  11.         Public e_cparhdr As UInt16
  12.         Public e_minalloc As UInt16
  13.         Public e_maxalloc As UInt16
  14.         Public e_ss As UInt16
  15.         Public e_sp As UInt16
  16.         Public e_csum As UInt16
  17.         Public e_ip As UInt16
  18.         Public e_cs As UInt16
  19.         Public e_lfarlc As UInt16
  20.         Public e_ovno As UInt16
  21.         Public e_res_0 As UInt16
  22.         Public e_res_1 As UInt16
  23.         Public e_res_2 As UInt16
  24.         Public e_res_3 As UInt16
  25.         Public e_oemid As UInt16
  26.         Public e_oeminfo As UInt16
  27.         Public e_res2_0 As UInt16
  28.         Public e_res2_1 As UInt16
  29.         Public e_res2_2 As UInt16
  30.         Public e_res2_3 As UInt16
  31.         Public e_res2_4 As UInt16
  32.         Public e_res2_5 As UInt16
  33.         Public e_res2_6 As UInt16
  34.         Public e_res2_7 As UInt16
  35.         Public e_res2_8 As UInt16
  36.         Public e_res2_9 As UInt16
  37.         Public e_lfanew As UInt32
  38.     End Structure
  39.     <StructLayout(LayoutKind.Sequential, Pack:=1)> _
  40.         Public Structure IMAGE_FILE_HEADER
  41.         Public Machine As UInt16
  42.         Public NumberOfSections As UInt16
  43.         Public TimeDateStamp As UInt32
  44.         Public PointerToSymbolTable As UInt32
  45.         Public NumberOfSymbols As UInt32
  46.         Public SizeOfOptionalHeader As UInt16
  47.         Public Characteristics As UInt16
  48.  
  49.     End Structure
  50.     <StructLayout(LayoutKind.Sequential, Pack:=1)> _
  51.         Public Structure IMAGE_OPTIONAL_HEADER
  52.         Public Magic As UInt16
  53.         Public MajorLinkerVersion As Byte
  54.         Public MinorLinkerVersion As Byte
  55.         Public SizeOfCode As UInt32
  56.         Public SizeOfInitializedData As UInt32
  57.         Public SizeOfUninitializedData As UInt32
  58.         Public AddressOfEntryPoint As UInt32
  59.         Public BaseOfCode As UInt32
  60.         Public BaseOfData As UInt32
  61.         Public ImageBase As UInt32
  62.         Public SectionAlignment As UInt32
  63.         Public FileAlignment As UInt32
  64.         Public MajorOperatingSystemVersion As UInt16
  65.         Public MinorOperatingSystemVersion As UInt16
  66.         Public MajorImageVersion As UInt16
  67.         Public MinorImageVersion As UInt16
  68.         Public MajorSubsystemVersion As UInt16
  69.         Public MinorSubsystemVersion As UInt16
  70.         Public Win32VersionValue As UInt32
  71.         Public SizeOfImage As UInt32
  72.         Public SizeOfHeaders As UInt32
  73.         Public CheckSum As UInt32
  74.         Public Subsystem As UInt16
  75.         Public DllCharacteristics As UInt16
  76.         Public SizeOfStackReserve As UInt32
  77.         Public SizeOfStackCommit As UInt32
  78.         Public SizeOfHeapReserve As UInt32
  79.         Public SizeOfHeapCommit As UInt32
  80.         Public LoaderFlags As UInt32
  81.         Public NumberOfRvaAndSizes As UInt32
  82.     End Structure
  83.     <StructLayout(LayoutKind.Sequential)> _
  84.         Public Structure IMAGE_NT_HEADERS
  85.         Public Signature As UInt32
  86.         Public FileHeader As IMAGE_FILE_HEADER
  87.         Public OptionalHeader As IMAGE_OPTIONAL_HEADER
  88.     End Structure
  89.  
  90.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  91.         Dim x As New OpenFileDialog
  92.         x.Filter = "Executable File |*.exe"
  93.         If x.ShowDialog = Windows.Forms.DialogResult.OK Then
  94.             FlatTextBox1.Text = x.FileName
  95.         End If
  96.         '---------------
  97.        Dim data As Byte() = IO.File.ReadAllBytes(FlatTextBox1.Text)
  98.        Dim g As GCHandle = GCHandle.Alloc(data, GCHandleType.Pinned)
  99.        Dim Pointer As IntPtr = g.AddrOfPinnedObject
  100.        Dim DosHeader As New IMAGE_DOS_HEADER
  101.        DosHeader = Marshal.PtrToStructure(Pointer, GetType(IMAGE_DOS_HEADER))
  102.        Pointer = Pointer.ToInt32 + DosHeader.e_lfanew
  103.        Dim PE As New IMAGE_NT_HEADERS
  104.        PE = Marshal.PtrToStructure(Pointer, GetType(IMAGE_NT_HEADERS))
  105.        '-----------------
  106.         TextBox1.Text = PE.FileHeader.NumberOfSections
  107.         TextBox2.Text = PE.FileHeader.TimeDateStamp.ToString("X")
  108.         TextBox3.Text = PE.FileHeader.Characteristics.ToString("X")
  109.         TextBox4.Text = PE.OptionalHeader.AddressOfEntryPoint.ToString("X")
  110.         TextBox5.Text = PE.OptionalHeader.SizeOfCode
  111.         TextBox6.Text = PE.OptionalHeader.ImageBase.ToString("X")
  112.         TextBox7.Text = PE.OptionalHeader.BaseOfCode.ToString("X")
  113.         TextBox8.Text = PE.OptionalHeader.BaseOfData.ToString("X")
  114.  
  115.  
  116.     End Sub
  117. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement