Beispiel #1
0
 public static void Pack(string exe, List <string> dlls, string outputPath, Magic.Dict addDict = null, bool?setGui = null)
 {
     using (var fs = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) {
         bool   extExe = exe != null;
         var    list   = new List <AddingFile>();
         byte[] exebuf;
         if (extExe)
         {
             exebuf = File.ReadAllBytes(exe);
             setGui = setGui ?? Magic.getSubsystem(exebuf) == 2;
             list.Add(new AddingFile(exe, ExeName));
         }
         int selfExeLength = GetSelfExeLength();
         var dict          = Magic.getMagicDict();
         if (addDict != null)
         {
             foreach (var item in addDict)
             {
                 if (item.Value == null)
                 {
                     dict.Remove(item.Key);
                 }
                 else
                 {
                     dict[item.Key] = item.Value;
                 }
             }
         }
         dict["pack"] = selfExeLength.ToString();
         char magicCh    = extExe ? 'm' : (dlls != null) ? 'd' : Magic.magic_char;
         var  selfexebuf = Magic.genExe(magicCh, setGui, dict.ToString(), selfExeLength);
         fs.Write(selfexebuf, 0, selfexebuf.Length);
         int i = 0;
         if (dlls != null)
         {
             foreach (var x in dlls)
             {
                 i++;
                 if (File.Exists(x))
                 {
                     var name = AssemblyName.GetAssemblyName(x).FullName;
                     list.Add(new AddingFile(x, NamePrefix + name));
                 }
                 else
                 {
                     throw new Exception("File not found: " + x);
                 }
             }
         }
         var curMagicCh = Magic.magic_char;
         if (exe != null || dlls != null)
         {
             NZ.Create(fs, list, Console.Out);
         }
         else
         {
             using (var self = File.Open(Magic.GetSelfPath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                 self.Position = selfExeLength;
                 self.CopyTo(fs, 64 * 1024);
             }
         }
     }
 }
Beispiel #2
0
 private static int GetPackOffset()
 {
     return(int.Parse(Magic.getMagicDict()["pack"]));
 }