Advertisement
t0mm13b

Reading DOS Structure from file and stuff into struct

May 12th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. private bool LoadFileIntoBuf() {
  2.             bool bRv = false;
  3.             using (FileStream fStream = new FileStream(this._sFilename, FileMode.Open, FileAccess.Read)) {
  4.                 int nLen = (int)fStream.Length;
  5.                 this._bBuf = new byte[nLen];
  6.                 int nRead = fStream.Read(this._bBuf, 0, nLen);
  7.                 if (nRead == nLen) bRv = true;
  8.             }
  9.             return bRv;
  10.         }
  11.  
  12. private bool CheckDOSStub() {
  13.             PEDumper.Win32ExeLayout._IMAGE_DOS_HEADER tmpDosHdr = new Win32ExeLayout._IMAGE_DOS_HEADER(0);
  14.             byte[] bBuf = new byte[Marshal.SizeOf(tmpDosHdr)];
  15.             Array.Copy(this._bBuf, bBuf, bBuf.Length);
  16.             this._imgDosHdr = new Win32ExeLayout._IMAGE_DOS_HEADER(bBuf);
  17.             bool bUnknown = false;
  18.             switch (this._imgDosHdr.e_magic) {
  19.                 case Win32ExeLayout.IMAGE_DOS_SIGNATURE:
  20.                     if (this._pSwitches[(int)ParamSwitches.Bits.Verbose]) Console.WriteLine("FOUND DOS Signature...");
  21.                     break;
  22.                 case Win32ExeLayout.IMAGE_OS2_SIGNATURE:
  23.                     if (this._pSwitches[(int)ParamSwitches.Bits.Verbose]) Console.WriteLine("Found OS/2 Signature...");
  24.                     break;
  25.                 default:
  26.                     if (this._pSwitches[(int)ParamSwitches.Bits.Verbose]) Console.WriteLine("Unknown Signature! {0:X2}", this._imgDosHdr.e_magic);
  27.                     bUnknown = true;
  28.                     break;
  29.             }
  30.             return bUnknown;
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement