Skip to content

Commit

Permalink
Merge pull request #178 from irsdl/master
Browse files Browse the repository at this point in the history
Minor refactoring
  • Loading branch information
irsdl authored Dec 23, 2024
2 parents f570387 + c10ef53 commit 4d6a465
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PayloadClassFromFile(string file, int variant_number, InputArgs inputArgs
{
this.variant_number = variant_number;
this.inputArgs = inputArgs;
base.assemblyBytes = LocalCodeCompiler.CompileToAsmBytes(file);
base.assemblyBytes = LocalCodeCompiler.GetAsmBytes(file);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override OptionSet Options()
public override object Generate(string formatter, InputArgs inputArgs)
{
var files = inputArgs.Cmd;
byte[] asmData = LocalCodeCompiler.CompileToAsmBytes(files);
byte[] asmData = LocalCodeCompiler.GetAsmBytes(files);
string xmlResourceDict = "";

if (isCompressed)
Expand Down
2 changes: 1 addition & 1 deletion ysoserial/Generators/XamlAssemblyLoadFromFileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override OptionSet Options()
public override object Generate(string formatter, InputArgs inputArgs)
{
var files = inputArgs.Cmd;
byte[] asmData = LocalCodeCompiler.CompileToAsmBytes(files);
byte[] asmData = LocalCodeCompiler.GetAsmBytes(files);
byte[] gzipAsmData = Gzip(asmData);
string base64GzipAsmData = Convert.ToBase64String(gzipAsmData);

Expand Down
8 changes: 5 additions & 3 deletions ysoserial/Helpers/LocalCodeCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ namespace ysoserial.Helpers
public static class LocalCodeCompiler
{

public static byte[] CompileToAsmBytes(string fileChain)
public static byte[] GetAsmBytes(string fileChain)
{
if (fileChain.EndsWith(".dll") && !fileChain.Contains(".cs;"))
{
return GetAsmBytes(fileChain);
// we have a DLL file
return GetAsmBytesFromDLL(fileChain);
}
else
{
// we need to compile the code
return CompileToAsmBytes(fileChain, "", "");
}
}

private static byte[] GetAsmBytes(string filePath)
private static byte[] GetAsmBytesFromDLL(string filePath)
{
if (!File.Exists(filePath))
{
Expand Down

0 comments on commit 4d6a465

Please sign in to comment.