Skip to content

Instantly share code, notes, and snippets.

@aevitas
Last active November 25, 2016 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aevitas/555b7e73f6c3b074f726511c665a5e47 to your computer and use it in GitHub Desktop.
Save aevitas/555b7e73f6c3b074f726511c665a5e47 to your computer and use it in GitHub Desktop.
Special type reads LocalProcessMemory
object ret = null;
var typeCode = Type.GetTypeCode(type);
// Special case simple value types:
// - Boolean
// - Byte, SByte
// - Char
// - Decimal
// - Int32, UInt32
// - Int64, UInt64
// - Int16, UInt16
// - IntPtr, UIntPtr
if (typeCode == TypeCode.Boolean)
ret = *(byte*)address != 0;
if (typeCode == TypeCode.Byte)
ret = *(byte*)address;
if (typeCode == TypeCode.SByte)
ret = *(sbyte*)address;
if (typeCode == TypeCode.Char)
ret = *(char*)address;
if (typeCode == TypeCode.Decimal)
ret = *(decimal*)address;
if (typeCode == TypeCode.Int32)
ret = *(int*)address;
if (typeCode == TypeCode.UInt32)
ret = *(uint*)address;
if (typeCode == TypeCode.Int64)
ret = *(long*)address;
if (typeCode == TypeCode.UInt64)
ret = *(ulong*)address;
if (typeCode == TypeCode.Int16)
ret = *(short*)address;
if (typeCode == TypeCode.UInt16)
ret = *(ushort*)address;
return (T)ret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment