Ejemplo n.º 1
0
        }                                                           // 3C File address of new exe header

        public static IMAGE_DOS_HEADER Deserialize(MultiPartFile file)
        {
            IMAGE_DOS_HEADER idh = new IMAGE_DOS_HEADER();

            idh.Magic                  = file.ReadUInt16();
            idh.LastPageBytes          = file.ReadUInt16();
            idh.Pages                  = file.ReadUInt16();
            idh.Relocations            = file.ReadUInt16();
            idh.HeaderParagraphSize    = file.ReadUInt16();
            idh.MinimumExtraParagraphs = file.ReadUInt16();
            idh.MaximumExtraParagraphs = file.ReadUInt16();
            idh.InitialSSValue         = file.ReadUInt16();
            idh.InitialSPValue         = file.ReadUInt16();
            idh.Checksum               = file.ReadUInt16();
            idh.InitialIPValue         = file.ReadUInt16();
            idh.InitialCSValue         = file.ReadUInt16();
            idh.RelocationTableAddr    = file.ReadUInt16();
            idh.OverlayNumber          = file.ReadUInt16();
            idh.Reserved1              = new ushort[Constants.ERES1WDS];
            for (int i = 0; i < Constants.ERES1WDS; i++)
            {
                idh.Reserved1[i] = file.ReadUInt16();
            }
            idh.OEMIdentifier  = file.ReadUInt16();
            idh.OEMInformation = file.ReadUInt16();
            idh.Reserved2      = new ushort[Constants.ERES2WDS];
            for (int i = 0; i < Constants.ERES2WDS; i++)
            {
                idh.Reserved2[i] = file.ReadUInt16();
            }
            idh.NewExeHeaderAddr = file.ReadInt32();

            return(idh);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempt to extract a Wise installer
        /// </summary>
        /// <param name="file">Possible Wise installer</param>
        /// <param name="outputPath">Output directory for extracted files</param>
        public bool ExtractTo(string file, string outputPath)
        {
            file       = Path.GetFullPath(file);
            outputPath = Path.GetFullPath(outputPath);
            Directory.CreateDirectory(outputPath);

            if (!Open(file))
            {
                return(false);
            }

            // Move to data and determine if this is a known format
            JumpToTheData();
            inputFile.Seek(dataBase + currentFormat.ExecutableOffset);
            for (int i = 0; i < knownFormats.Length; i++)
            {
                if (currentFormat.Equals(knownFormats[i]))
                {
                    currentFormat = knownFormats[i];
                    break;
                }
            }

            // Fall back on heuristics if we couldn't match
            if (currentFormat.ArchiveEnd == 0)
            {
                inputFile.Seek(0);
                Approximate();
                if (!pkzip)
                {
                    if (FindReal(outputPath))
                    {
                        ExtractFiles(outputPath);
                        RenameFiles(outputPath);
                        Close();
                        return(true);
                    }
                }
                else
                {
                    offsetReal = offsetApproximate;
                    ExtractFiles(outputPath);
                    RenameFiles(outputPath);
                    Close();
                    return(true);
                }

                Close();
                return(false);
            }

            // Skip over the addditional DLL name, if we expect it
            long dataStart = currentFormat.ExecutableOffset;

            if (currentFormat.Dll)
            {
                byte[] dll = new byte[256];
                inputFile.Read(dll, 0, 1);
                dataStart++;

                if (dll[0] != 0x00)
                {
                    inputFile.Read(dll, 1, dll[0]);
                    dataStart += dll[0];

                    int dllLength = inputFile.ReadInt32();
                    dataStart += 4;
                }
            }

            // Check if flags are consistent
            if (!currentFormat.NoCrc)
            {
                int flags = inputFile.ReadInt32();
                if ((flags & 0x0100) != 0)
                {
                    return(false);
                }
            }

            if (currentFormat.ArchiveEnd > 0)
            {
                inputFile.Seek(dataBase + dataStart + currentFormat.ArchiveEnd);
                int archiveEndLoaded = inputFile.ReadInt32();
                if (archiveEndLoaded != 0)
                {
                    currentFormat.ArchiveEnd = archiveEndLoaded + dataBase;
                }
            }

            inputFile.Seek(dataBase + dataStart + currentFormat.ArchiveStart);

            // Skip over the initialization text, if we expect it
            if (currentFormat.InitText)
            {
                byte[] waitingBytes = new byte[256];
                inputFile.Read(waitingBytes, 0, 1);
                inputFile.Read(waitingBytes, 1, waitingBytes[0]);
            }

            offsetReal = inputFile.Position;
            ExtractFiles(outputPath);
            RenameFiles(outputPath);

            Close();
            return(true);
        }