Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2><strong>Code example</strong></h2> <p>This is the complete code of a <code>C#</code> console application that can detect <code>dll</code> architectures that also includes the ones you wanted.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { MachineType type = GetDllMachineType("path/to/MyAssembly.dll"); if (type.Equals(MachineType.IMAGE_FILE_MACHINE_I386)) { Console.WriteLine("Dll architecture: x86/32bit"); } else if (type.Equals(MachineType.IMAGE_FILE_MACHINE_IA64)) { Console.WriteLine("Dll architecture: x64/64bit"); } Console.ReadKey(); } public static MachineType GetDllMachineType(string dllPath) { //see http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx //offset to PE header is always at 0x3C //PE header starts with "PE\0\0" = 0x50 0x45 0x00 0x00 //followed by 2-byte machine type field (see document above for enum) FileStream fs = new FileStream(dllPath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); fs.Seek(0x3c, SeekOrigin.Begin); Int32 peOffset = br.ReadInt32(); fs.Seek(peOffset, SeekOrigin.Begin); UInt32 peHead = br.ReadUInt32(); if (peHead != 0x00004550) // "PE\0\0", little-endian throw new Exception("Can't find PE header"); MachineType machineType = (MachineType)br.ReadUInt16(); br.Close(); fs.Close(); return machineType; } public enum MachineType : ushort { IMAGE_FILE_MACHINE_UNKNOWN = 0x0, IMAGE_FILE_MACHINE_AM33 = 0x1d3, IMAGE_FILE_MACHINE_AMD64 = 0x8664, IMAGE_FILE_MACHINE_ARM = 0x1c0, IMAGE_FILE_MACHINE_EBC = 0xebc, IMAGE_FILE_MACHINE_I386 = 0x14c, IMAGE_FILE_MACHINE_IA64 = 0x200, IMAGE_FILE_MACHINE_M32R = 0x9041, IMAGE_FILE_MACHINE_MIPS16 = 0x266, IMAGE_FILE_MACHINE_MIPSFPU = 0x366, IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466, IMAGE_FILE_MACHINE_POWERPC = 0x1f0, IMAGE_FILE_MACHINE_POWERPCFP = 0x1f1, IMAGE_FILE_MACHINE_R4000 = 0x166, IMAGE_FILE_MACHINE_SH3 = 0x1a2, IMAGE_FILE_MACHINE_SH3DSP = 0x1a3, IMAGE_FILE_MACHINE_SH4 = 0x1a6, IMAGE_FILE_MACHINE_SH5 = 0x1a8, IMAGE_FILE_MACHINE_THUMB = 0x1c2, IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169, } // returns true if the dll is 64-bit, false if 32-bit, and null if unknown public static bool? UnmanagedDllIs64Bit(string dllPath) { switch (GetDllMachineType(dllPath)) { case MachineType.IMAGE_FILE_MACHINE_AMD64: case MachineType.IMAGE_FILE_MACHINE_IA64: return true; case MachineType.IMAGE_FILE_MACHINE_I386: return false; default: return null; } } } } </code></pre> <hr> <h2><strong>Using Corflags...</strong></h2> <p>You wrote about this and, just to know, this will help you to get some information regarding your assembly (<code>dll</code>) but this is not <code>C#</code>! this is a tool that can be used in <code>Visual Studio</code> console.</p> <p>Just open <code>Visual Studio</code> console and use this command:</p> <blockquote> <pre><code>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC&gt;corflags C:/path/to/MyAssembly.dll </code></pre> </blockquote> <p>This will be the output:</p> <blockquote> <pre><code>Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 3.5.21022.8 Copyright (c) Microsoft Corporation. All rights reserved. Version : v2.0.50727 CLR Header: 2.5 PE : PE32 CorFlags : 24 ILONLY : 0 32BIT : 0 Signed : 1 </code></pre> </blockquote> <p>Then, focus on <code>PE:PE32</code>, this will describe your assembly architecture:</p> <p>So, according to this...</p> <ul> <li><p><strong>AnyCPU</strong> means -> PE: PE32 -> 32BIT: 0</p></li> <li><p><strong>x86</strong> means -> PE: PE32 -> 32BIT: 1</p></li> <li><p><strong>x64</strong> means -> PE: PE32+ -> 32BIT: 0</p></li> </ul> <p>The architecture of <code>MyAssembly.dll</code> is <code>32bit</code></p> <hr> <h2>Idea...</h2> <p>Well, if you want to simplify all this, an idea could be to create a background process using <code>C#</code> then in the arguments use the command I gave you above and print the output of <code>PE:XX</code> to get the assembly architecture and according to that value tell your application what to do.</p> <hr> <p>I just made some research, hope this helps :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload