Files
kbe 6300bebe33 Fix API documentation and examples; add comprehensive documentation suite
- Example5: Fix format string bugs (alignment specifier placement, SafeMemoryHandle formatting)
- Example4: Fix DetourManager.Detour() → Create() in all doc strings
- Example3: Fix MemoryBase.CreateFunction() → InProcessInvoker.CreateFunction() in doc strings
- Examples 1-5: Correct all runtime errors and API mismatches vs actual WhiteMagic API
- README: Fix DetourManager.Detour() examples to use Create(); add missing code fence markers
- Add WhiteMagic.Examples project with 5 comprehensive example files (40+ sub-examples)
- Add docfx.json and toc.md for DocFX API reference generation
- Add 5 conceptual guides: architecture, memory-access, execution-models, hooking, troubleshooting
- Ensure zero errors, zero warnings across all projects (net8.0-windows)

Doc strings now teach correct APIs; runtime format bugs eliminated; build succeeds.
2026-07-22 22:26:07 +02:00

143 lines
6.4 KiB
C#

using System;
using System.Threading.Tasks;
namespace WhiteMagic.Examples;
/// <summary>
/// Main program for WhiteMagic examples
/// Demonstrates all major features of the library
/// </summary>
class Program
{
static async Task Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(@"
╔════════════════════════════════════════════════════════════════════════╗
║ ║
║ ████████╗██╗ ██╗██╗ ██████╗███████╗███████╗██╗ ██╗███████╗██╗ ║
║ ╚══██╔══╝██║ ██║██║██╔════╝██╔════╝██╔════╝██║ ██║██╔════╝██║ ║
║ ██║ ██║ ██║██║██║ ███████╗███████╗███████║█████╗ ██║ ║
║ ██║ ██║ ██║██║██║ ╚════██║╚════██║██╔══██║██╔══╝ ██║ ║
║ ██║ ╚██████╔╝██║╚██████╗███████║███████║██║ ██║███████╗███████╗║
║ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝╚══════╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝║
║ ║
║ Process Introspection Library for .NET ║
║ ║
╚════════════════════════════════════════════════════════════════════════╝
");
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(" Examples for Learning WhiteMagic API");
Console.WriteLine(" ─────────────────────────────────────");
Console.ResetColor();
while (true)
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Select an example to run:");
Console.ResetColor();
Console.WriteLine(" 1. Basic Memory Operations (Read/Write, Arrays, Strings, Structs)");
Console.WriteLine(" 2. Pattern Scanning (Find patterns in memory)");
Console.WriteLine(" 3. Execution Models (RemoteThread, MainThreadPump, InProcess)");
Console.WriteLine(" 4. Function Hooking (Detours, Patches)");
Console.WriteLine(" 5. High-Level API (RemotePointer, RemoteModule, RemoteWindow, etc.)");
Console.WriteLine(" 6. Run All Examples");
Console.WriteLine(" 0. Exit");
Console.WriteLine();
Console.Write("Enter your choice (0-6): ");
string? input = Console.ReadLine();
if (!int.TryParse(input, out int choice))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Invalid input. Please enter a number between 0 and 6.");
Console.ResetColor();
continue;
}
Console.WriteLine();
try
{
switch (choice)
{
case 1:
BasicMemoryOperations.RunAll();
break;
case 2:
PatternScanning.RunAll();
break;
case 3:
await ExecutionModels.RunAll();
break;
case 4:
FunctionHooking.RunAll();
break;
case 5:
HighLevelAPI.RunAll();
break;
case 6:
// Run all examples sequentially
BasicMemoryOperations.RunAll();
Console.WriteLine("\n" + new string('=', 70) + "\n");
await Task.Delay(500);
PatternScanning.RunAll();
Console.WriteLine("\n" + new string('=', 70) + "\n");
await Task.Delay(500);
await ExecutionModels.RunAll();
Console.WriteLine("\n" + new string('=', 70) + "\n");
await Task.Delay(500);
FunctionHooking.RunAll();
Console.WriteLine("\n" + new string('=', 70) + "\n");
await Task.Delay(500);
HighLevelAPI.RunAll();
break;
case 0:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Exiting WhiteMagic Examples. Thank you!");
Console.ResetColor();
return;
default:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Invalid choice. Please enter a number between 0 and 6.");
Console.ResetColor();
break;
}
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\n✗ Error running example: {ex.Message}");
Console.WriteLine($" Stack trace: {ex.StackTrace}");
Console.ResetColor();
}
if (choice != 0)
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Press any key to continue...");
Console.ResetColor();
Console.ReadKey();
Console.Clear();
}
}
}
}