示例#1
0
		static void BuildLoader(string[] args)
		{
			var config = new Config();

			var loader = typeof(Program).Assembly.Location;

			var go = false;
			foreach (var arg in args)
			{
				if (arg.StartsWith("-Start=", StringComparison.OrdinalIgnoreCase))
					config.SetStart(new Uri(new Uri(loader), arg.Substring("-Start=".Length)).LocalPath);
				else if (arg.StartsWith("-Path=", StringComparison.OrdinalIgnoreCase))
					config.SetPath(new Uri(new Uri(loader), arg.Substring("-Path=".Length)).LocalPath);
				else if (arg.StartsWith("-Output=", StringComparison.OrdinalIgnoreCase))
					config.Output = new Uri(new Uri(loader), arg.Substring("-Output=".Length)).LocalPath;
				else if (arg.StartsWith("-Match=", StringComparison.OrdinalIgnoreCase))
					config.Match = arg.Substring("-Match=".Length);
				else if (arg.StartsWith("-ExtractAction=", StringComparison.OrdinalIgnoreCase))
					config.ExtractAction = (ExtractActions)Enum.Parse(typeof(ExtractActions), arg.Substring("-ExtractAction=".Length), true);
				else if (arg.StartsWith("-NGen=", StringComparison.OrdinalIgnoreCase))
					switch (arg.Substring("-NGen=".Length).ToLowerInvariant()[0])
					{
						case '1': case 'y': case 't': config.NGen = true; break;
					}
				else if (arg.Equals("-GO", StringComparison.OrdinalIgnoreCase))
					go = true;
			}

			if ((!go) && (!GetConfig.Run(config)))
				return;

			Builder.Run(config);
		}
示例#2
0
		static ResourceReader()
		{
			Config = null;
			var data = GetBinary(1, false);
			if (data != null)
				Config = new Config { SerializedData = data };
		}
示例#3
0
 public static void Save(Config c)
 {
     using (XmlTextWriter xmlTextWriter = new XmlTextWriter("config.xml", Encoding.UTF8)
     {
         Formatting = Formatting.Indented
     })
     {
         xmlTextWriter.WriteStartDocument(false);
         new DataContractSerializer(typeof(Config)).WriteObject(xmlTextWriter, c);
         xmlTextWriter.Flush();
     }
 }
示例#4
0
 public static void Load(out Config c)
 {
     using (XmlTextReader xmlTextReader = new XmlTextReader("config.xml"))
     {
         DataContractSerializer contractSerializer = new DataContractSerializer(typeof(Config));
         c = contractSerializer.ReadObject(xmlTextReader) as Config;
     }
 }
示例#5
0
		public static void Run(Config config)
		{
			if (((!File.Exists(config.X32StartFull)) && (!File.Exists(config.X64StartFull))) || (config.Output == null) || (config.Match == null))
				throw new ArgumentException("Invalid parameter");

			var files = GetFiles(config.X32Path).Concat(GetFiles(config.X64Path)).Distinct(StringComparer.OrdinalIgnoreCase).Where(file => config.IsMatch(file)).ToList();
			// Make sure entry points are found
			if (config.X32Start != null)
				files.Single(file => file.Equals(config.X32Start, StringComparison.OrdinalIgnoreCase));
			if (config.X64Start != null)
				files.Single(file => file.Equals(config.X64Start, StringComparison.OrdinalIgnoreCase));

			var loader = typeof(Program).Assembly.Location;
			var bytes = File.ReadAllBytes(loader);
			var loaderPeInfo = new PEInfo(bytes);

			if (config.X64Path == null)
				loaderPeInfo.CorFlags |= Native.IMAGE_COR20_HEADER_FLAGS.x32BitRequired;

			if (config.IsConsole)
				loaderPeInfo.IsConsole = true;

			File.WriteAllBytes(config.Output, bytes);

			using (var nr = new ResourceWriter(config.Output))
			{
				var startFile = config.X64StartFull ?? config.X32StartFull;
				nr.CopyResources(new PEInfo(startFile), new List<IntPtr> { Native.RT_ICON, Native.RT_GROUP_ICON, Native.RT_VERSION });

				var currentID = 1;
				foreach (var file in files)
				{
					var x32File = config.X32Path == null ? null : Path.Combine(config.X32Path, file);
					if ((x32File == null) || (x32File.Equals(loader, StringComparison.OrdinalIgnoreCase)) || (!File.Exists(x32File)))
						x32File = null;
					var x32Res = Resource.CreateFromFile(file, x32File, BitDepths.x32);

					var x64File = config.X64Path == null ? null : Path.Combine(config.X64Path, file);
					if ((x64File == null) || (x64File.Equals(loader, StringComparison.OrdinalIgnoreCase)) || (!File.Exists(x64File)))
						x64File = null;
					var x64Res = x64File == x32File ? x32Res : Resource.CreateFromFile(file, x64File, BitDepths.x64);

					if (Resource.DataMatch(x32Res, x64Res))
						x64Res = x32Res;

					if (x32Res == x64Res)
					{
						x32Res.BitDepth = BitDepths.Any;
						x64Res = null;
					}

					if (x32Res != null)
					{
						x32Res.ResourceID = ++currentID;
						nr.AddBinary(x32Res.ResourceID, x32Res.CompressedData);
						x32Res.CompressedData = null;
						config.Resources.Add(x32Res);
					}
					if (x64Res != null)
					{
						x64Res.ResourceID = ++currentID;
						nr.AddBinary(x64Res.ResourceID, x64Res.CompressedData);
						x64Res.CompressedData = null;
						config.Resources.Add(x64Res);
					}
				}

				nr.AddBinary(1, config.SerializedData);
			}
		}