Initial commit

This commit is contained in:
2026-09-19 16:13:20 +03:00 Unverified
commit d60d5b98d4
24 changed files with 1278 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Markup;
namespace IPClab3.Converters;
public class MemoryAddressConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is IntPtr ptr)
{
if (ptr == IntPtr.Zero)
return "0x0";
ulong numericAddress = (ulong)ptr;
// Format dynamically: 8 digits for 32-bit (x86), 16 digits for 64-bit (x64)
string hexFormat = IntPtr.Size == 4 ? "X8" : "X16";
return $"0x{numericAddress.ToString(hexFormat, CultureInfo.InvariantCulture)}";
}
return "0x0";
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
if (value is string addressStr)
{
if (string.IsNullOrWhiteSpace(addressStr))
return IntPtr.Zero;
string cleanInput = addressStr.Trim();
if (cleanInput.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
{
cleanInput = cleanInput.Substring(2);
}
if (!ulong.TryParse(cleanInput, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong numericAddress))
{
return IntPtr.Zero;
}
// Architecture safety overflow check
if (IntPtr.Size == 4 && numericAddress > uint.MaxValue)
{
return IntPtr.Zero;
}
return (IntPtr)numericAddress;
}
return IntPtr.Zero;
}
}