-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryScanner.cs
More file actions
58 lines (55 loc) · 1.87 KB
/
BinaryScanner.cs
File metadata and controls
58 lines (55 loc) · 1.87 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
using System;
using System.IO;
using System.Linq;
namespace ProcessorEmulator.Tools
{
public static class BinaryScanner
{
public static void ScanTypicalBinaryDirs(string rootDir)
{
var dirs = new[] {"bin", "sbin", Path.Combine("usr", "bin"), Path.Combine("usr", "sbin")};
foreach (var dir in dirs)
{
string fullPath = Path.Combine(rootDir, dir);
if (Directory.Exists(fullPath))
ScanDirectory(fullPath);
}
}
public static void ScanDirectory(string directory)
{
var detector = new ArchitectureDetector();
var files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories);
foreach (var file in files)
{
try
{
byte[] data = File.ReadAllBytes(file);
string arch = ArchitectureDetector.Detect(data);
if (arch != "Unknown")
{
Console.WriteLine($"{file}: {arch}");
var disasm = Disassembler.Disassemble(data, arch);
foreach (var line in disasm.Take(5)) // Preview first 5 lines
Console.WriteLine(" " + line);
}
}
catch { /* Ignore unreadable files */ }
}
}
}
internal static class BinaryDisassembler
{
public static string[] Disassemble(byte[] data, string arch)
{
// Stub implementation: return dummy lines for now
return new[]
{
$"Disassembly preview for arch: {arch}",
"0x0000: NOP",
"0x0001: MOV R1, R2",
"0x0002: ADD R3, R4",
"0x0003: JMP 0x0000"
};
}
}
}