21 lines
741 B
C#
21 lines
741 B
C#
// dotnet run scripts/Analyze.cs -- <file.asm> <pattern>
|
|||
|
|
using System.Text;
|
||
|
|
using System.Text.RegularExpressions;
|
||
|
|
|
||
|
|
string path = args[0];
|
||
|
|
string pattern = args[1];
|
||
|
|
|
||
|
|
byte[] data = File.ReadAllBytes(path);
|
||
|
|
string testo = Encoding.Latin1.GetString(data);
|
||
|
|
|
||
|
|
foreach (Match m in Regex.Matches(testo, pattern))
|
||
|
|
{
|
||
|
|
int s = Math.Max(0, m.Index - 24);
|
||
|
|
int e = Math.Min(testo.Length, m.Index + m.Length + 24);
|
||
|
|
string ctx = testo.Substring(s, e - s).Replace("\r", "\\r").Replace("\n", "\\n");
|
||
|
|
string hexCtx = string.Join(" ", data.Skip(s).Take(e - s).Select(b => b.ToString("x2")));
|
||
|
|
Console.WriteLine($"offset={m.Index:x} val={m.Value}");
|
||
|
|
Console.WriteLine($" txt: {ctx}");
|
||
|
|
Console.WriteLine($" hex: {hexCtx}");
|
||
|
|
}
|
||
|
|
return 0;
|