-
Notifications
You must be signed in to change notification settings - Fork 11
/
Extensions.cs
47 lines (41 loc) · 1.72 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.IO;
using System.IO.Compression;
using AsmResolver.DotNet;
using static Costura_Decompressor.Logger;
namespace Costura_Decompressor
{
public static class Extensions
{
private static byte[] DecompressResource(this Stream input)
{
using var output = new MemoryStream();
using var deflateStream = new DeflateStream(input, CompressionMode.Decompress);
deflateStream.CopyTo(output);
return output.ToArray();
}
public static string GetOutputPath(this ModuleDefinition module)
{
if (module.FilePath == null) return null;
if (module.Assembly == null) return null;
string name = Path.GetFileName(module.FilePath);
return Path.Combine(module.FilePath.Remove(module.FilePath.Length - name.Length),
@$"{module.Assembly.Name}-decompressed-resources\");
}
public static byte[] Decompress(this byte[] data)
{
using var input = new MemoryStream(data);
using var output = new MemoryStream();
using var deflateStream = new DeflateStream(input, CompressionMode.Decompress);
deflateStream.CopyTo(output);
return output.ToArray();
}
public static void ProcessCompressedFile(this string inputFile)
{
string outputFileName = inputFile.Replace("costura.", null);
outputFileName = outputFileName.Replace(".compressed", null);
using (var bufferStream = File.OpenRead(inputFile))
File.WriteAllBytes(outputFileName, bufferStream.DecompressResource());
Log($"Decompressed costura file: {inputFile}", LogType.Success);
}
}
}