Пример #1
0
        private void ReflectPESubsytemType(string archivePath, string uri, CompileProcess compileProcess)
        {
            try
            {
                string iconOutputPath = null;

                if (Helper.IsNullOrEmpty(compileProcess.IconFile))
                {
                    iconOutputPath = Application.UserAppDataPath + @"\" + Guid.NewGuid().GetHashCode().ToString() + ".ico";

                    compileProcess.IconFile           = iconOutputPath;
                    compileProcess.DeleteIconWhenDone = true;
                }

                PEFileInfo info;

                if (!PEFileInterrogator.TryGetPEFileInfo(archivePath, uri, iconOutputPath, out info))
                {
                    throw new Exception(string.Format(Rpx.Strings.Reflector_CouldNotReadPE, uri));
                }

                if (iconOutputPath != null && !File.Exists(iconOutputPath))
                {
                    compileProcess.IconFile           = null;
                    compileProcess.DeleteIconWhenDone = false;
                }

                if (compileProcess.ExecutableTypeLookupMode == ExecutableTypeMode.Reflected)
                {
                    if (info.Subsystem == SubsystemTypes.WindowsCni)
                    {
                        compileProcess.ExecutableType = ExecutableType.Console;
                    }
                    else if (info.Subsystem == SubsystemTypes.WindowsGui)
                    {
                        compileProcess.ExecutableType = ExecutableType.Forms;
                    }
                    else
                    {
                        SubsystemTypes SubsystemType = info.Subsystem;

                        throw new Exception(string.Format(Rpx.Strings.Error_0107, SubsystemType.ToString()));
                    }
                }
            }
            finally
            {
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the PE header from the bytes of an assembly
        /// </summary>
        /// <param name="bytes"></param>
        public PEHeader(byte[] bytes)
        {
            m_FoundSection = false;

            // Read in the DLL or EXE and get the timestamp
            using (MemoryStream stream = new MemoryStream(bytes, false))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    m_DosHeader = FromBinaryReader <ImageDosHeader>(reader);

                    // Add 4 bytes to the offset
                    stream.Seek(m_DosHeader.ExeHeaderAddress, SeekOrigin.Begin);

                    UInt32 ntHeadersSignature = reader.ReadUInt32();

                    m_FileHeader = FromBinaryReader <ImageFileHeader>(reader);

                    if (this.Is32BitHeader)
                    {
                        m_OptionalHeader32 = FromBinaryReader <ImageOptionalHeader32>(reader);
                        m_SubsystemType    = (SubsystemTypes)m_OptionalHeader32.Subsystem;

                        ReourcesDataTable = m_OptionalHeader32.Data_ResourceTable;
                    }
                    else
                    {
                        m_OptionalHeader64 = FromBinaryReader <ImageOptionalHeader64>(reader);
                        m_SubsystemType    = (SubsystemTypes)m_OptionalHeader64.Subsystem;

                        ReourcesDataTable = m_OptionalHeader32.Data_ResourceTable;
                    }

                    for (int i = 0; i < m_FileHeader.NumberOfSections; i++)
                    {
                        ImageSectionHeader section = FromBinaryReader <ImageSectionHeader>(reader);

                        if (section.ToString() == ".rsrc")
                        {
                            m_Section      = section;
                            m_FoundSection = true;
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="SubsystemType"></param>
        /// <returns></returns>
        private static bool TryGetSubsystemType(byte[] bytes, out SubsystemTypes SubsystemType)
        {
            SubsystemType = SubsystemTypes.Unknown;

            try
            {
                PEHeader header = new PEHeader(bytes);

                SubsystemType = header.SubsystemType;

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="SubsystemType"></param>
        /// <returns></returns>
        private static bool TryGetSubsystemType(byte[] bytes, out SubsystemTypes SubsystemType)
        {
            SubsystemType = SubsystemTypes.Unknown;

            try
            {
                PEHeader header = new PEHeader(bytes);

                SubsystemType = header.SubsystemType;

                return true;
            }
            catch 
            {
                return false;
            }
        }