Skip to content

Commit

Permalink
Merge pull request #3 from BC-SECURITY/compression_removal
Browse files Browse the repository at this point in the history
Moved assembly compression to after compilation
  • Loading branch information
Cx01N authored Oct 29, 2024
2 parents 2ef3ae5 + 4c162b0 commit f8796ea
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 1,311 deletions.
13 changes: 2 additions & 11 deletions EmpireCompiler/Core/Common.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;


namespace EmpireCompiler.Core
{
public static class Common
{
public static Encoding EmpireEncoding = Encoding.UTF8;
public static int AesIVLength = 16;
public static CipherMode AesCipherMode = CipherMode.CBC;
public static PaddingMode AesPaddingMode = PaddingMode.PKCS7;

public static string EmpireDirectory = Assembly.GetExecutingAssembly().Location.Split("bin")[0].Split("EmpireCompiler.dll")[0];

Check warning on line 10 in EmpireCompiler/Core/Common.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.

Check warning on line 10 in EmpireCompiler/Core/Common.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64)

'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.
public static string EmpireDataDirectory = EmpireDirectory + "Data" + Path.DirectorySeparatorChar;
public static string EmpireDatabaseFile = EmpireDataDirectory + "covenant.db";
public static string EmpireTempDirectory = EmpireDataDirectory + "Temp" + Path.DirectorySeparatorChar;

public static string EmpireAssemblyReferenceDirectory = EmpireDataDirectory + "AssemblyReferences" + Path.DirectorySeparatorChar;
Expand All @@ -24,12 +17,10 @@ public static class Common
public static string EmpireAssemblyReferenceNet45Directory = EmpireAssemblyReferenceDirectory + "net45" + Path.DirectorySeparatorChar;
public static string EmpireEmbeddedResourcesDirectory = EmpireDataDirectory + "EmbeddedResources" + Path.DirectorySeparatorChar;
public static string EmpireReferenceSourceLibraries = EmpireDataDirectory + "ReferenceSourceLibraries" + Path.DirectorySeparatorChar;
public static string EmpireSharpSploitDirectory = EmpireReferenceSourceLibraries + "SharpSploit" + Path.DirectorySeparatorChar;
public static string EmpireRubeusDirectory = EmpireReferenceSourceLibraries + "Rubeus" + Path.DirectorySeparatorChar;

public static string EmpireTaskDirectory = EmpireDataDirectory + "Tasks" + Path.DirectorySeparatorChar;
public static string EmpireTaskCSharpDirectory = EmpireTaskDirectory + "CSharp" + Path.DirectorySeparatorChar;
public static string EmpireTaskCSharpNetCoreApp30Directory = EmpireTaskCSharpDirectory + "netcoreapp3.0" + Path.DirectorySeparatorChar;
// public static string EmpireTaskCSharpNetCoreApp30Directory = EmpireTaskCSharpDirectory + "netcoreapp3.0" + Path.DirectorySeparatorChar;
public static string EmpireTaskCSharpCompiledDirectory = EmpireTaskCSharpDirectory + "Compiled" + Path.DirectorySeparatorChar;
public static string EmpireTaskCSharpCompiledNet35Directory = EmpireTaskCSharpCompiledDirectory + "net35" + Path.DirectorySeparatorChar;
public static string EmpireTaskCSharpCompiledNet40Directory = EmpireTaskCSharpCompiledDirectory + "net40" + Path.DirectorySeparatorChar;
Expand Down
16 changes: 12 additions & 4 deletions EmpireCompiler/Core/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,17 @@ private static byte[] CompileCSharpRoslyn(CsharpFrameworkCompilationRequest requ
.Select(R => MetadataReference.CreateFromFile(R.File))
.ToList();

string entryPointClass = "Program";

// Use specified OutputKind and Platform
CSharpCompilationOptions options = new CSharpCompilationOptions(outputKind: request.OutputKind, optimizationLevel: OptimizationLevel.Release, platform: request.Platform, allowUnsafe: request.UnsafeCompile);
// Compile to obtain SemanticModel
CSharpCompilationOptions options = new CSharpCompilationOptions(
outputKind: request.OutputKind,
optimizationLevel: OptimizationLevel.Release,
platform: request.Platform,
allowUnsafe: request.UnsafeCompile,
mainTypeName: entryPointClass
);

CSharpCompilation compilation = CSharpCompilation.Create(
request.AssemblyName == null ? Path.GetRandomFileName() : request.AssemblyName,
compilationTrees,
Expand Down Expand Up @@ -171,7 +179,6 @@ private static byte[] CompileCSharpRoslyn(CsharpFrameworkCompilationRequest requ
);
}

// Emit compilation
EmitResult emitResult;
byte[] ILbytes = null;
using (var ms = new MemoryStream())
Expand All @@ -184,7 +191,8 @@ private static byte[] CompileCSharpRoslyn(CsharpFrameworkCompilationRequest requ
}).Where(ER => ER.Enabled).Select(ER =>
{
return new ResourceDescription(ER.Name, () => File.OpenRead(ER.File), true);
}).ToList()
}).ToList(),
cancellationToken: default
);
if (emitResult.Success)
{
Expand Down
63 changes: 0 additions & 63 deletions EmpireCompiler/Core/Context.cs

This file was deleted.

Loading

0 comments on commit f8796ea

Please sign in to comment.