Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Is there a way to programatically determine if a binary is managed code?

Is there a way to programatically determine if a binary is managed code?

Scheduled Pinned Locked Moved C#
sysadminquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Throckmorton
    wrote on last edited by
    #1

    So i think it would be handy if I could write a function that does this: If \\server\share\binary.exe is managed code Do this Otherwise it is not managed code Do that Is such a thing possible? Thanks, Ian

    N 1 Reply Last reply
    0
    • T Throckmorton

      So i think it would be handy if I could write a function that does this: If \\server\share\binary.exe is managed code Do this Otherwise it is not managed code Do that Is such a thing possible? Thanks, Ian

      N Offline
      N Offline
      Nathan Blomquist
      wrote on last edited by
      #2

      I know this function works with managed and unmanaged dlls. You could try it with executables though:public bool IsManaged(string filePath) { byte[] Data = new byte[4096]; FileInfo file = new FileInfo(filePath); FileStream fin = file.OpenRead(); int read = fin.Read(Data,0,Data.Length); fin.Close(); // Verify this is a executable/dll if ((Data[1] << 8 | Data[0]) != 0x5a4d) return false; // This will get the address for the WinNT header Int32 iWinNTHdr = Data[63]<<24 | Data[62]<<16 | Data[61] << 8 | Data[60]; // Verify this is an NT address if ((Data[iWinNTHdr+3] << 24 | Data[iWinNTHdr+2] << 16 | Data[iWinNTHdr+1] << 8 | Data[iWinNTHdr]) != 0x00004550) return false; Int32 iLightningAddr = iWinNTHdr + 24 + 208; Int32 iSum=0; Int32 iTop = iLightningAddr + 8; for (int i = iLightningAddr; i < iTop; i++) iSum|=Data[i]; if (iSum == 0) return false; else return true; }
      Got this from a blog entry here: http://blogs.msdn.com/adam_nathan/archive/2003/10/26/56786.aspx[^] Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups