mirror of
https://github.com/andreacristaldi/DefenderRuleParser
synced 2026-06-16 13:55:00 +00:00
108 lines
3.0 KiB
C#
108 lines
3.0 KiB
C#
// DefenderRuleParser
|
|
// Author: Andrea Cristaldi 2025 - https://github.com/andreacristaldi/DefenderRuleParser
|
|
// This project is licensed under the Apache 2.0 License.
|
|
using System;
|
|
using System.Text;
|
|
|
|
namespace DefenderRuleParser2
|
|
{
|
|
|
|
public static class Logger
|
|
{
|
|
|
|
public static bool Quiet { get; set; }
|
|
|
|
|
|
public static bool DebugEnabled { get; set; }
|
|
|
|
public static string OutputFolder { get; set; }
|
|
|
|
public static void Info(string msg)
|
|
{
|
|
if (Quiet) return;
|
|
Console.WriteLine(msg);
|
|
}
|
|
|
|
public static void Warn(string msg)
|
|
{
|
|
if (Quiet) return;
|
|
Console.WriteLine(msg);
|
|
}
|
|
|
|
public static void Error(string msg)
|
|
{
|
|
if (Quiet) return;
|
|
Console.WriteLine(msg);
|
|
}
|
|
|
|
public static void Verbose(string msg)
|
|
{
|
|
if (Quiet || !DebugEnabled) return;
|
|
Console.WriteLine(msg);
|
|
}
|
|
|
|
public static void HexDump(string title, byte[] data, long offset)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine($"{title}");
|
|
for (int i = 0; i < data.Length; i += 16)
|
|
{
|
|
StringBuilder hex = new StringBuilder();
|
|
StringBuilder ascii = new StringBuilder();
|
|
|
|
for (int j = 0; j < 16; j++)
|
|
{
|
|
if (i + j < data.Length)
|
|
{
|
|
byte b = data[i + j];
|
|
hex.AppendFormat("{0:X2} ", b);
|
|
ascii.Append((b >= 32 && b <= 126) ? (char)b : '.');
|
|
}
|
|
else
|
|
{
|
|
hex.Append(" ");
|
|
ascii.Append(" ");
|
|
}
|
|
}
|
|
|
|
Console.WriteLine($"{offset + i:X8} {hex} {ascii}");
|
|
|
|
}
|
|
Console.WriteLine();
|
|
}
|
|
|
|
|
|
public static void HexDumpVerbose(string title, byte[] data, long offset)
|
|
{
|
|
if (Quiet || !DebugEnabled) return;
|
|
Console.WriteLine();
|
|
Console.WriteLine($"{title}");
|
|
for (int i = 0; i < data.Length; i += 16)
|
|
{
|
|
StringBuilder hex = new StringBuilder();
|
|
StringBuilder ascii = new StringBuilder();
|
|
|
|
for (int j = 0; j < 16; j++)
|
|
{
|
|
if (i + j < data.Length)
|
|
{
|
|
byte b = data[i + j];
|
|
hex.AppendFormat("{0:X2} ", b);
|
|
ascii.Append((b >= 32 && b <= 126) ? (char)b : '.');
|
|
}
|
|
else
|
|
{
|
|
hex.Append(" ");
|
|
ascii.Append(" ");
|
|
}
|
|
}
|
|
|
|
Console.WriteLine($"{offset + i:X8} {hex} {ascii}");
|
|
|
|
}
|
|
Console.WriteLine();
|
|
}
|
|
|
|
}
|
|
}
|