Advertisement
t0mm13b

Sample Struct

May 12th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  2.         public unsafe struct _IMAGE_DOS_HEADER {      // DOS .EXE header
  3.             public WORD e_magic;                     // Magic number
  4.             public WORD e_cblp;                      // Bytes on last page of file
  5.             public WORD e_cp;                        // Pages in file
  6.             public WORD e_crlc;                      // Relocations
  7.             public WORD e_cparhdr;                   // Size of header in paragraphs
  8.             public WORD e_minalloc;                  // Minimum extra paragraphs needed
  9.             public WORD e_maxalloc;                  // Maximum extra paragraphs needed
  10.             public WORD e_ss;                        // Initial (relative) SS value
  11.             public WORD e_sp;                        // Initial SP value
  12.             public WORD e_csum;                      // Checksum
  13.             public WORD e_ip;                        // Initial IP value
  14.             public WORD e_cs;                        // Initial (relative) CS value
  15.             public WORD e_lfarlc;                    // File address of relocation table
  16.             public WORD e_ovno;                      // Overlay number
  17.             [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 4, ArraySubType = System.Runtime.InteropServices.UnmanagedType.I2)]
  18.             public WORD[] e_res;                     // Reserved words
  19.             public WORD e_oemid;                     // OEM identifier (for e_oeminfo)
  20.             public WORD e_oeminfo;                   // OEM information; e_oemid specific
  21.             [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 10, ArraySubType = System.Runtime.InteropServices.UnmanagedType.I2)]
  22.             public WORD[] e_res2;                     // Reserved words
  23.             public LONG e_lfanew;                    // File address of new exe header
  24.             //
  25.             public _IMAGE_DOS_HEADER(int nFakeArgs) {
  26.                 this.e_cblp = this.e_cp = this.e_cparhdr = this.e_crlc = 0;
  27.                 this.e_cs = this.e_csum = this.e_ip = this.e_lfarlc = 0;
  28.                 this.e_magic = this.e_maxalloc = this.e_minalloc = this.e_oemid = 0;
  29.                 this.e_oeminfo = this.e_ovno = this.e_sp = this.e_ss = 0;
  30.                 this.e_lfanew = 0;
  31.                 this.e_res = new WORD[4];
  32.                 this.e_res2 = new WORD[10];
  33.             }
  34.             public _IMAGE_DOS_HEADER(byte[] data)
  35.                 : this(0) {
  36.                 unsafe {
  37.                     GCHandle hImgDosHdr = GCHandle.Alloc(data, GCHandleType.Pinned);
  38.                     IntPtr pImgDosHdr = hImgDosHdr.AddrOfPinnedObject();
  39.                     this = (_IMAGE_DOS_HEADER)Marshal.PtrToStructure(pImgDosHdr, this.GetType());
  40.                     hImgDosHdr.Free();
  41.                 }
  42.             }
  43.         };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement