/// <summary>
        /// Used for Live process Initialization
        /// </summary>
        /// <param name="cpuArchitecture"></param>
        public void Init(CPUArchitecture cpuArchitecture)
        {
            CpuArchitecture = cpuArchitecture;

            //SetWinVErsion((uint)Environment.OSVersion.Version.Major, (uint)Environment.OSVersion.Version.Minor);
            SetWinVErsion(MachineOsVersionHandler.WinMajorVersion, MachineOsVersionHandler.WinMinorVersion);
        }
Example #2
0
        public static bool AreRealTimeSignalsSafe()
        {
            ushort built_for_cpu;
            ushort running_on_cpu;
            bool   is64bit;

            detectCPUAndArchitecture(out built_for_cpu, out running_on_cpu, out is64bit);

            CPUArchitecture builtForCPU  = Enum.IsDefined(typeof(CPUArchitecture), built_for_cpu) ? (CPUArchitecture)built_for_cpu : CPUArchitecture.Unknown;
            CPUArchitecture runningOnCPU = Enum.IsDefined(typeof(CPUArchitecture), running_on_cpu) ? (CPUArchitecture)running_on_cpu : CPUArchitecture.Unknown;

            Log.Info(TAG, " Built for CPU: {0}", builtForCPU);
            Log.Info(TAG, "Running on CPU: {0}", runningOnCPU);
            Log.Info(TAG, "64-bit process: {0}", is64bit ? "yes" : "no");

            // For now real-time signals aren't safe at all, alas
            bool safe = false;

            Log.Info(TAG, "Real-time signals are {0}safe on this platform", safe ? String.Empty : "not ");

            return(safe);
        }
 /// <summary>
 /// Used for dump Files Initialization
 /// </summary>
 /// <param name="cpuArchitecture"></param>
 /// <param name="systemInfo"></param>
 public void Init(CPUArchitecture cpuArchitecture, MiniDumpSystemInfo systemInfo)
 {
     CpuArchitecture = cpuArchitecture;
     SetWinVErsion(systemInfo.MajorVersion, systemInfo.MinorVersion);
 }
Example #4
0
        //=========================================================================
        /// <summary>
        /// Determine if the file refered to is a native win32 or a CLR assembly.
        /// Mixed mode assemblies are CLR.
        /// Visual C++ Developer Center. http://msdn2.microsoft.com/en-us/library/c91d4yzb(VS.80).aspx
        /// </summary>
        /// <param name="filename">File name of the Assembly or native dll to probe.</param>
        /// <returns>Compilation mode.</returns>
        //=========================================================================
        static public CompilationMode isManaged(string filename, out CPUArchitecture arch)
        {
            try
            {
                arch = CPUArchitecture.Unknown;
                byte[]   data = new byte[4096];
                FileInfo file = new FileInfo(filename);
                Stream   fin  = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                /*Int32 iRead =*/ fin.Read(data, 0, 4096);
                fin.Close();

                // If we are running on Linux, the executable/so will start with the string 0x7f + 'ELF'
                // If the 5 byte is 1, it's a 32-bit image (2 indicates 64-bit)
                // If the 16th byte is 3, it's a shared object; 2 means it's an executable
                // If it's a Mono/.Net assembly, we should find the "Windows" header

                // For now, if we're on Linux just see if it has an "ELF" header
                if (Path.VolumeSeparatorChar == '/' && data[0] == 0x7f && data[1] == 'E' && data[2] == 'L' && data[3] == 'F')
                {
                    if (data[4] == 1)
                    {
                        arch = CPUArchitecture.x86;
                    }
                    else if (data[4] == 2)
                    {
                        arch = CPUArchitecture.x86_64;
                    }
                    return(CompilationMode.Native);
                }

                // Verify this is a executable/dll
                if (UInt16FromBytes(data, 0) != 0x5a4d)
                {
                    return(CompilationMode.Invalid);
                }

                uint headerOffset = UInt32FromBytes(data, 0x3c);  // This will get the address for the WinNT header

                //at the file offset specified at offset 0x3c, is a 4-byte
                //signature that identifies the file as a PE format image file. This signature is �PE\0\0�
                if (UInt32FromBytes(data, headerOffset) != 0x00004550)
                {
                    return(CompilationMode.Invalid);
                }
                uint machineType = UInt16FromBytes(data, headerOffset + 4);
                if (machineType == 0x14c)
                {
                    arch = CPUArchitecture.x86;
                }
                else if (machineType == 0x200 || machineType == 0x8664)
                {
                    arch = CPUArchitecture.x86_64;
                }

                //uint machineType = UInt16FromBytes(data, headerOffset + 4); //type of machine
                uint optionalHdrBase = headerOffset + 24;
                //uint exportTableAddr = UInt32FromBytes(data, optionalHdrBase + 96);     //.edata
                uint exportTableSize = UInt32FromBytes(data, optionalHdrBase + 96 + 4); //.edata size

                Int32 iLightningAddr = (int)headerOffset + 24 + 208;                    //CLR runtime header addr & size
                Int32 iSum           = 0;
                Int32 iTop           = iLightningAddr + 8;

                for (int i = iLightningAddr; i < iTop; ++i)
                {
                    iSum |= data[i];
                }

                if (iSum == 0)
                {
                    return(CompilationMode.Native);
                }
                else
                {
                    if (exportTableSize > 0)
                    {
                        return(CompilationMode.Mixed);
                    }
                    else
                    {
                        return(CompilationMode.CLR);
                    }
                    // CPUArchitecture won't be quite correct here. should check to see if it's x86 or AnyCPU
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }