Exemple #1
0
		static int Main(string[] args)
		{
			Help.PrintLogo();
			try
			{
				genData = new GenData();
				ArrayList files = InputParser.Parse(ref genData, args);
				if((files != null) && (files.Count >= 0))
				{
					if(InputParser.externalResourceMode)
					{
						ProcessCreateXRes(files);
					}
					else
					{
						Proceed(files);
					}
				}
			}
			catch(Exception ex)
			{
				PrintErr(null, ex);
				return 1;
			}
			return 0;
		}
Exemple #2
0
 private static void AppendFile(ref ArrayList files, string file, ref GenData genData, bool mangleName, string resourceName)
 {
     string[] f = null;
     if (mangleName)
     {
         f = ExpandFiles(file);
     }
     else
     {
         f = new string[] { file };
     }
     if ((f == null) || (f.Length <= 0))
     {
         throw new Exception("E1006 No such file(s): " + file);
     }
     for (int i = 0; i < f.Length; i++)
     {
         if (f[i].ToLower().EndsWith(".exe"))
         {
             SetExeOutPath(f[i], ref genData);
         }
         AddFile(ref files, f[i], mangleName, resourceName);
     }
 }
Exemple #3
0
 static void Main(string[] args)
 {
     Help.PrintLogo();
     try
     {
         genData = new GenData();
         ArrayList files = InputParser.Parse(ref genData, args);
         if ((files != null) && (files.Count >= 0))
         {
             if (InputParser.externalResourceMode)
             {
                 ProcessCreateXRes(files);
             }
             else
             {
                 Proceed(files);
             }
         }
     }
     catch (Exception ex)
     {
         PrintErr(null, ex);
     }
 }
		private static void SetExeOutPath(string file, ref GenData genData)
		{
			if(exeFileSet)
				throw new Exception("E1007 A single EXE must be specified");
			exeFileSet = true;
			string pfile = Path.GetFullPath(file);
			if(genData.Auto)
			{
				try
				{
					int ss = subsys.Win32PESubSystem.GetSubSystem(pfile);
					if(ss == subsys.Win32PESubSystem.IMAGE_SUBSYSTEM_WINDOWS_CUI)
					{
						genData.Console = true;
					}
					else if(ss == subsys.Win32PESubSystem.IMAGE_SUBSYSTEM_WINDOWS_GUI)
					{
						genData.Console = false;
					}
					else throw new Exception("E1008 Unsupported PE subsystem (KB Q90493): " + ss);
					Logger.Log("PE subsystem    : " + (genData.Console ? "CUI" : "GUI") );
				}
				catch(Exception ex)
				{
					netz.Netz.PrintWarning("1004 Cannot determine EXE's subsystem (default is GUI windows EXE) The packed application will fail!: ", ex);
				}
			}
			OutDirMan.OutDir = pfile + ".netz";
		}
		private static void AppendFile(ref ArrayList files, string file, ref GenData genData, bool mangleName, string resourceName)
		{
			string[] f = null;
			if(mangleName)
			{
				f = ExpandFiles(file);
			}
			else
			{
				f = new string[]{ file };	
			}
			if((f == null) || (f.Length <= 0))
			{
				throw new Exception("E1006 No such file(s): " + file);
			}
			for(int i = 0; i < f.Length; i++)
			{
				if(f[i].ToLower().EndsWith(".exe"))
				{
					SetExeOutPath(f[i], ref genData);
				}
				AddFile(ref files, f[i], mangleName, resourceName);
			}
		}
		private static void ValidateInput(GenData genData)
		{
			if(!exeFileSet)
			{
				string err = "an EXE file must be specified for the -";
				bool throwit = false;
				if(genData.SingleExe)
				{
					throwit = true;
					err += "s";
				}
				else if(genData.PackZipDll)
				{
					throwit = true;
					err += "z";
				}
				if(throwit) throw new Exception("E1004 " + err + " option");
			}
			if(genData.UserIconFile && !File.Exists(genData.IconFile))
				throw new Exception("icon file not found: " + genData.IconFile);
		}
		public static ArrayList Parse(ref GenData genData, string[] args)
		{
			ArrayList files = new ArrayList(); // of InputFile
			if(args.Length <= 0)
			{
				Help.ShowHelp();
				return null;
			}
            string outDirPath = null;
			for(int i = 0; i < args.Length; i++)
			{
				if((args[i][0] == '-') || (args[i][0] == '/'))
				{
					string arg = args[i].Substring(1, args[i].Length - 1).ToLower();
					switch(arg)
					{
						case "?":
							Help.ShowHelp();
							return null;
						case "v":
							printStackStrace = true;
							break;
						case "s":
							genData.SingleExe = true;
							break;
						case "c":
							genData.Console = true;
							genData.Auto = false;
							break;
						case "w":
							genData.Console = false;
							genData.Auto = false;
							break;
						case "i":
							genData.IconFile = args[++i];
							genData.UserIconFile = true;
							break;
                        case "o":
                            outDirPath = args[++i];
                            break;
						case "b":
							genData.BatchMode = true;
							break;
						case "p":
							genData.PrivatePath = args[++i];
							break;
						case "z":
							genData.PackZipDll = true;
							break;
						case "l":
							genData.ZipDllName = args[++i];
							break;
						case "r":
							genData.CompressProviderDLL = args[++i];
							break;
						case "n":
							genData.SetNetzVersion = true;
							break;
						case "!":
							PrintInternalVersion(genData.CompressProviderDLL);
							return null;
						case "so":
							genData.Optimize = true;
							break;
						case "a":
							using(StreamReader sr = new StreamReader(args[++i]))
							{
								if(sr == null) break;
								string t = sr.ReadToEnd();
								if(t != null)
                                    genData.UserAssemblyAttributes = t.Trim();
							}
							break;
						case "aw":
							genData.ReportEXEAttributes = true;
							break;
						case "mta":
							genData.MtaAttribute = true;
							break;
						case "kf":
							genData.KeyGetFromAttributes = false;
							genData.KeyFile = args[++i]; //Path.GetFullPath();
							if(!File.Exists(genData.KeyFile)) throw new Exception("Key file not found: " + genData.KeyFile);
							break;
						case "kn":
							genData.KeyGetFromAttributes = false;
							genData.KeyName = args[++i];
							break;
						case "kd":
							genData.KeyDelay = true;
							break;
						case "ka":
							genData.KeyGetFromAttributes = true;
							break;
						case "pl":
							genData.XPlatform = args[++i];
							break;
						case "x86":
							genData.XPlatform = "x86";
							break;
						case "d":
							break;
						case "xr":
							externalResourceMode = true;
							if(i != 0) throw new Exception("-xr must be first");
							if(args.Length < 2) throw new Exception("-xr name required");
							externalResourceName = args[++i];
							if(externalResourceName.IndexOf(' ') >= 0) throw new Exception("-xr name must not contain spaces");
							break;
						case "sr":
							genData.IsService = true;
							break;
						case "csc":
							genData.OtherCompOptions = args[++i];
							break;
						case "srp":
							genData.serviceParams = GetMap(args[++i]);
							break;
						default:
						  if(arg.StartsWith("d:")) break;
							throw new Exception("E1003 Unknown argument: " + args[i]);
					}
				}
				else
				{
					bool mangleName = true;
					string resourceName = null;
					if((i > 0) && (args[i - 1].ToLower().StartsWith("-d") || args[i - 1].ToLower().StartsWith("/d")))
					{
						mangleName = false;
						int k = args[i - 1].IndexOf(':');
						if(k >= 0)
						{
							if((k != 2) || (args[i -1].Length < 4)) throw new Exception("E1003 Unknown argument: " + args[i]);
							resourceName = args[i - 1].ToLower().Substring(k + 1, args[i - 1].Length - k - 1);
						}
					}
					AppendFile(ref files, args[i], ref genData, mangleName, resourceName);
				}
			}
			Logger.Log(".NET Runtime    : " + Environment.Version.ToString());
			ValidateInput(genData);
            if (outDirPath != null)
            {
                OutDirMan.OutDir = outDirPath;
            }

			genData.CompressProvider = new CompressProvider(genData.CompressProviderDLL);
			if(genData.ZipDllName == null)
			{
				genData.ZipDllName = genData.CompressProvider.Provider.GetRedistributableDLLPath();
				if((genData.ZipDllName != null) && Path.GetFileName(genData.ZipDllName).ToLower().Equals(genData.ZipDllName))
				{
					genData.ZipDllName = GenData.GetFullPath(genData.ZipDllName);
				}
			}
			return files;
		}
Exemple #8
0
        public static ArrayList Parse(ref GenData genData, string[] args)
        {
            ArrayList files = new ArrayList();             // of InputFile

            if (args.Length <= 0)
            {
                Help.ShowHelp();
                return(null);
            }
            string outDirPath = null;

            for (int i = 0; i < args.Length; i++)
            {
                if ((args[i][0] == '-') || (args[i][0] == '/'))
                {
                    string arg = args[i].Substring(1, args[i].Length - 1).ToLower();
                    switch (arg)
                    {
                    case "?":
                        Help.ShowHelp();
                        return(null);

                    case "v":
                        printStackStrace = true;
                        break;

                    case "s":
                        genData.SingleExe = true;
                        break;

                    case "c":
                        genData.Console = true;
                        genData.Auto    = false;
                        break;

                    case "w":
                        genData.Console = false;
                        genData.Auto    = false;
                        break;

                    case "i":
                        genData.IconFile     = args[++i];
                        genData.UserIconFile = true;
                        break;

                    case "o":
                        outDirPath = args[++i];
                        break;

                    case "b":
                        genData.BatchMode = true;
                        break;

                    case "p":
                        genData.PrivatePath = args[++i];
                        break;

                    case "z":
                        genData.PackZipDll = true;
                        break;

                    case "l":
                        genData.ZipDllName = args[++i];
                        break;

                    case "r":
                        genData.CompressProviderDLL = args[++i];
                        break;

                    case "n":
                        genData.SetNetzVersion = true;
                        break;

                    case "!":
                        PrintInternalVersion(genData.CompressProviderDLL);
                        return(null);

                    case "so":
                        genData.Optimize = true;
                        break;

                    case "a":
                        using (StreamReader sr = new StreamReader(args[++i]))
                        {
                            if (sr == null)
                            {
                                break;
                            }
                            string t = sr.ReadToEnd();
                            if (t != null)
                            {
                                genData.UserAssemblyAttributes = t.Trim();
                            }
                        }
                        break;

                    case "aw":
                        genData.ReportEXEAttributes = true;
                        break;

                    case "mta":
                        genData.MtaAttribute = true;
                        break;

                    case "kf":
                        genData.KeyGetFromAttributes = false;
                        genData.KeyFile = args[++i];                                 //Path.GetFullPath();
                        if (!File.Exists(genData.KeyFile))
                        {
                            throw new Exception("Key file not found: " + genData.KeyFile);
                        }
                        break;

                    case "kn":
                        genData.KeyGetFromAttributes = false;
                        genData.KeyName = args[++i];
                        break;

                    case "kd":
                        genData.KeyDelay = true;
                        break;

                    case "ka":
                        genData.KeyGetFromAttributes = true;
                        break;

                    case "pl":
                        genData.XPlatform = args[++i];
                        break;

                    case "x86":
                        genData.XPlatform = "x86";
                        break;

                    case "d":
                        break;

                    case "xr":
                        externalResourceMode = true;
                        if (i != 0)
                        {
                            throw new Exception("-xr must be first");
                        }
                        if (args.Length < 2)
                        {
                            throw new Exception("-xr name required");
                        }
                        externalResourceName = args[++i];
                        if (externalResourceName.IndexOf(' ') >= 0)
                        {
                            throw new Exception("-xr name must not contain spaces");
                        }
                        break;

                    case "sr":
                        genData.IsService = true;
                        break;

                    case "csc":
                        genData.OtherCompOptions = args[++i];
                        break;

                    case "srp":
                        genData.serviceParams = GetMap(args[++i]);
                        break;

                    default:
                        if (arg.StartsWith("d:"))
                        {
                            break;
                        }
                        throw new Exception("E1003 Unknown argument: " + args[i]);
                    }
                }
                else
                {
                    bool   mangleName   = true;
                    string resourceName = null;
                    if ((i > 0) && (args[i - 1].ToLower().StartsWith("-d") || args[i - 1].ToLower().StartsWith("/d")))
                    {
                        mangleName = false;
                        int k = args[i - 1].IndexOf(':');
                        if (k >= 0)
                        {
                            if ((k != 2) || (args[i - 1].Length < 4))
                            {
                                throw new Exception("E1003 Unknown argument: " + args[i]);
                            }
                            resourceName = args[i - 1].ToLower().Substring(k + 1, args[i - 1].Length - k - 1);
                        }
                    }
                    AppendFile(ref files, args[i], ref genData, mangleName, resourceName);
                }
            }
            Logger.Log(".NET Runtime    : " + Environment.Version.ToString());
            ValidateInput(genData);
            if (outDirPath != null)
            {
                OutDirMan.OutDir = outDirPath;
            }

            genData.CompressProvider = new CompressProvider(genData.CompressProviderDLL);
            if (genData.ZipDllName == null)
            {
                genData.ZipDllName = genData.CompressProvider.Provider.GetRedistributableDLLPath();
                if ((genData.ZipDllName != null) && Path.GetFileName(genData.ZipDllName).ToLower().Equals(genData.ZipDllName))
                {
                    genData.ZipDllName = GenData.GetFullPath(genData.ZipDllName);
                }
            }
            return(files);
        }
		public static void ZipFile(string file, string zipFile, GenData genData)
		{
			if(genData.CompressProvider.Provider == null) throw new Exception("E1013 Compress provider is not initialized");
			Netz.LogZipSize(genData.CompressProvider.Provider.Compress(file, zipFile));
		}