private string GetAsciiString(DacGetByteArrayWithArg func, ulong addr) { int hr = func(Self, addr, 0, null, out int needed); if (hr != S_OK) { return(null); } if (needed == 0) { return(""); } byte[] buffer = AcquireBuffer(needed); hr = func(Self, addr, needed, buffer, out needed); if (hr != S_OK) { ReleaseBuffer(buffer); return(null); } int len = Array.IndexOf(buffer, (byte)0); if (len >= 0) { needed = len; } string result = Encoding.ASCII.GetString(buffer, 0, needed); ReleaseBuffer(buffer); return(result); }
private string?GetAsciiString(DacGetByteArrayWithArg func, ulong addr) { int hr = func(Self, addr, 0, null, out int needed); if (hr != S_OK) { return(null); } if (needed == 0) { return(string.Empty); } byte[] buffer = ArrayPool <byte> .Shared.Rent(needed); try { hr = func(Self, addr, needed, buffer, out needed); if (hr != S_OK) { return(null); } int len = Array.IndexOf(buffer, (byte)0); if (len >= 0) { needed = len; } string result = Encoding.ASCII.GetString(buffer, 0, needed); return(result); } finally { ArrayPool <byte> .Shared.Return(buffer); } }