-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilesystemProber.cs
More file actions
60 lines (52 loc) · 1.74 KB
/
FilesystemProber.cs
File metadata and controls
60 lines (52 loc) · 1.74 KB
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
using System;
using System.IO;
namespace ProcessorEmulator.Tools
{
public class FilesystemProber
{
public static string Probe(string filePath)
{
byte[] fileData = File.ReadAllBytes(filePath);
if (fileData.Length > 2 && fileData[0] == 0x1F && fileData[1] == 0x8B)
{
return "GZIP";
}
if (fileData.Length > 4 && fileData[0] == 0x7F && fileData[1] == 'E' && fileData[2] == 'L' && fileData[3] == 'F')
{
return "ELF";
}
return "Unknown";
}
public static void ProbeDrive(string drivePath)
{
Console.WriteLine($"Probing drive: {drivePath}");
if (!Directory.Exists(drivePath))
{
Console.WriteLine("Drive path does not exist.");
return;
}
foreach (var file in Directory.GetFiles(drivePath))
{
Console.WriteLine($"Found file: {file}");
ProbeFile(file);
}
}
public static void ProbeFile(string filePath)
{
Console.WriteLine($"Probing file: {filePath}");
byte[] fileData = File.ReadAllBytes(filePath);
if (fileData.Length > 0 && fileData[0] == 0x7F && fileData[1] == 'E' && fileData[2] == 'L' && fileData[3] == 'F')
{
Console.WriteLine("Detected ELF binary.");
}
else if (fileData.Length > 0 && fileData[0] == 0x42 && fileData[1] == 0x5A)
{
Console.WriteLine("Detected BZ2 compressed file.");
}
else
{
Console.WriteLine("Unknown file type.");
}
}
}
}