Beispiel #1
0
        // Old CS versions
        byte[] UnpackNativeFile1(IPEImage peImage)
        {
            const int dataDirNum   = 6;                 // debug dir
            const int dotNetDirNum = 14;

            var optHeader = peImage.ImageNTHeaders.OptionalHeader;

            if (optHeader.DataDirectories[dataDirNum].VirtualAddress == 0)
            {
                return(null);
            }
            if (optHeader.DataDirectories[dataDirNum].Size != 0x48)
            {
                return(null);
            }

            var  fileData          = peImage.GetImageAsByteArray();
            long dataDirBaseOffset = (long)optHeader.DataDirectories[0].StartOffset;
            int  dataDir           = (int)dataDirBaseOffset + dataDirNum * 8;
            int  dotNetDir         = (int)dataDirBaseOffset + dotNetDirNum * 8;

            WriteUInt32(fileData, dotNetDir, BitConverter.ToUInt32(fileData, dataDir));
            WriteUInt32(fileData, dotNetDir + 4, BitConverter.ToUInt32(fileData, dataDir + 4));
            WriteUInt32(fileData, dataDir, 0);
            WriteUInt32(fileData, dataDir + 4, 0);
            ModuleBytes = fileData;
            return(fileData);
        }
		// Old CS versions
		byte[] UnpackNativeFile1(IPEImage peImage) {
			const int dataDirNum = 6;	// debug dir
			const int dotNetDirNum = 14;

			var optHeader = peImage.ImageNTHeaders.OptionalHeader;
			if (optHeader.DataDirectories[dataDirNum].VirtualAddress == 0)
				return null;
			if (optHeader.DataDirectories[dataDirNum].Size != 0x48)
				return null;

			var fileData = peImage.GetImageAsByteArray();
			long dataDirBaseOffset = (long)optHeader.DataDirectories[0].StartOffset;
			int dataDir = (int)dataDirBaseOffset + dataDirNum * 8;
			int dotNetDir = (int)dataDirBaseOffset + dotNetDirNum * 8;
			WriteUInt32(fileData, dotNetDir, BitConverter.ToUInt32(fileData, dataDir));
			WriteUInt32(fileData, dotNetDir + 4, BitConverter.ToUInt32(fileData, dataDir + 4));
			WriteUInt32(fileData, dataDir, 0);
			WriteUInt32(fileData, dataDir + 4, 0);
			ModuleBytes = fileData;
			return fileData;
		}