Ejemplo n.º 1
0
        private string Process(ModuleDef targetModule, string programId, string originalFileLocation)
        {
            //CreateFolderStructure(programId);

            ModuleWriterOptions writerOptions = new ModuleWriterOptions(targetModule)
            {
                Listener = this
            };

            targetModule.Write("A://BlankForm-protected.exe", writerOptions);

            targetModule.Dispose();
            Anti.Tamper.EncryptMethods("A://BlankForm-protected.exe", sectionrva);

            return(null);



            // TODO: This.
            //writerOptions.PEHeadersOptions.NumberOfRvaAndSizes = 10; // Set less than 14.
            //writerOptions.MetaDataOptions.TablesHeapOptions.ExtraData = 1337;

            string protectedFileLocation = Path.Combine(Path.GetTempPath(), "ByteGuard_Protected.exe");

            targetModule.Write(protectedFileLocation, writerOptions);

            SaveMarketplaceFiles(protectedFileLocation, programId, originalFileLocation);
            SaveByteGuardFiles(protectedFileLocation, programId, originalFileLocation);
            SaveCustomFiles(protectedFileLocation, programId, originalFileLocation);

            return(Runtime.ByteGuardHelper.GetMd5(null, File.ReadAllBytes(protectedFileLocation))); // MD5 hash.
        }
Ejemplo n.º 2
0
 public void Save(bool backup)
 {
     if (string.IsNullOrEmpty(_file))
     {
         throw new Exception("Assembly/module was loaded in memory, and no file was specified. Use Save(string) method to save the patched assembly.");
     }
     if (_keepOldMaxStack)
     {
         Module.Write(_file + ".tmp", new ModuleWriterOptions(Module)
         {
             MetaDataOptions = { Flags = MetaDataFlags.KeepOldMaxStack }
         });
     }
     else
     {
         Module.Write(_file + ".tmp");
     }
     Module.Dispose();
     if (backup)
     {
         if (File.Exists(_file + ".bak"))
         {
             File.Delete(_file + ".bak");
         }
         File.Move(_file, _file + ".bak");
     }
     else
     {
         File.Delete(_file);
     }
     File.Move(_file + ".tmp", _file);
 }
Ejemplo n.º 3
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && (components != null))
     {
         components.Dispose();
         _manifestModule?.Dispose();
         _process.Dispose();
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 4
0
 public void Dispose()
 {
     if (PEImage != null)
     {
         PEImage.Dispose();
     }
     if (ModuleDef != null)
     {
         ModuleDef.Dispose();
     }
 }
Ejemplo n.º 5
0
        LoadedAssembly TryLoadFromDir2(IAssembly asmName, bool exactCheck, string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(null);
            }

            var       loadedAsm = new LoadedAssembly(assemblyList, fileName);
            ModuleDef mod       = null;
            bool      error     = true;

            try {
                loadedAsm.IsAutoLoaded = true;
                mod = loadedAsm.ModuleDefinition;
                if (mod == null)
                {
                    return(null);
                }
                var asm = mod.Assembly;
                if (asm == null)
                {
                    return(null);
                }
                bool b = exactCheck ?
                         AssemblyNameComparer.CompareAll.Equals(asmName, asm) :
                         AssemblyNameComparer.NameAndPublicKeyTokenOnly.Equals(asmName, asm);
                if (!b)
                {
                    return(null);
                }

                error = false;
                return(loadedAsm);
            }
            finally {
                if (error)
                {
                    if (mod != null)
                    {
                        mod.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 6
0
 /// <inheritdoc/>
 public void Dispose() => ModuleDef.Dispose();
Ejemplo n.º 7
0
 private void InjectingForm_FormClosing(object sender, FormClosingEventArgs e) => _manifestModule.Dispose();