-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
122 lines (105 loc) · 4.69 KB
/
Program.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Unity Package Extractor By Zuxi https://github.com/imZuxi :: https://imzuxi.com
using SharpCompress.Archives;
using SharpCompress.Common;
using System.IO.Compression;
namespace UnityPackageExtractor
{
internal class Program
{
static List<string> SusFiles = new List<string>();
static void Main(string[] args)
{
// Check if a Unity package file is provided as a command-line argument
if (args.Length == 0)
{
Console.WriteLine("Please drag the Unity package file onto this executable.");
Thread.Sleep(10000); // Pause for 10 seconds before exiting
return;
}
Console.WriteLine("This Could Take a While Please wait ");
// Create a working directory
Directory.CreateDirectory(".working");
// Extract the Unity package file
byte[] tarFileBytes = ExtractGzipFileAndReturnBytes(args[0]);
ExtractTarFile(tarFileBytes, ".working");
// Start the main loop to copy the files
try
{
string directoryName = Path.GetFileNameWithoutExtension(args[0]);
DoLoopOfDFile(directoryName);
}
catch (Exception e)
{
Console.WriteLine($"Error in main loop: {e}");
}
// Clean up: delete the working directory
Directory.Delete(".working", true);
if (SusFiles.Count > 0 )
{
Console.WriteLine("Found Some Sus files.");
foreach (string susFile in SusFiles) { Console.WriteLine(susFile); }
}
Console.WriteLine("Done");
Console.ReadKey();
}
static void DoLoopOfDFile(string savepath)
{
// Ensure the save path exists, create it if not
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
// Loop through subdirectories in the working directory
foreach (string subDirectory in Directory.GetDirectories(".working"))
{
// Get file path from the 'pathname' file in the current subdirectory
string file_path = File.ReadAllText(Path.Combine(subDirectory, "pathname"));
// Ensure the directory for the file exists in the save path
string fileDirectory = Path.Combine(savepath, Path.GetDirectoryName(file_path));
if (!Directory.Exists(fileDirectory))
Directory.CreateDirectory(fileDirectory);
// Copy the asset file to the save path if it exists
string assetFilePath = Path.Combine(subDirectory, "asset");
if (file_path.Contains(".cs") || file_path.Contains(".dll"))
if (File.Exists(assetFilePath))
{
File.Copy(assetFilePath, Path.Combine(savepath, file_path));
}
else
{
Console.WriteLine($"Failed to find the file associated with {file_path} note may have already been copyed");
}
if (file_path.Contains(".cs") || file_path.Contains(".dll")) SusFiles.Add(file_path);
}
}
static byte[] ExtractGzipFileAndReturnBytes(string gzipFilePath)
{
using (FileStream fileStream = new FileStream(gzipFilePath, FileMode.Open, FileAccess.Read))
using (MemoryStream memoryStream = new MemoryStream())
{
using (GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Decompress))
{
// Extract the contents of the gzip file into a MemoryStream
gzipStream.CopyTo(memoryStream);
}
// Return the extracted content as a byte array
return memoryStream.ToArray();
}
}
static void ExtractTarFile(byte[] tarFileBytes, string extractFolderPath)
{
using (var stream = new MemoryStream(tarFileBytes))
using (var archive = ArchiveFactory.Open(stream))
{
// Ensure the extract folder exists
if (!Directory.Exists(extractFolderPath))
{
Directory.CreateDirectory(extractFolderPath);
}
// Extract each entry in the tar archive
foreach (var entry in archive.Entries.Where(e => !e.IsDirectory))
{
entry.WriteToDirectory(extractFolderPath, new ExtractionOptions { ExtractFullPath = true, Overwrite = true });
}
}
}
}
}