/// <summary> /// Get WideByte null terminated String /// </summary> /// <param name="Pointer">Pointer to the string</param> /// <param name="Decode">if False, return the hex of the string</param> /// <returns></returns> internal static string GetStringW(IntPtr Pointer, bool Decode = true, bool ForceUnicode = false) { int len = 0; while (Marshal.ReadInt16(Pointer, len) != 0) { len += 2; } byte[] buffer = new byte[len]; Marshal.Copy(Pointer, buffer, 0, buffer.Length); if ((LogInput || LogAll) && !DumpStrOnly) { Log("Input: {0}", true, ParseBytes(buffer)); } if (Decode) { return(ForceUnicode ? Encoding.Unicode.GetString(buffer) : ReadEncoding.GetString(buffer)); } else { return(ParseBytes(buffer)); } }
/// <summary> /// Get a null terminated String /// </summary> /// <param name="Pointer">Pointer to the string</param> /// <param name="Decode">if False, return the hex of the string</param> /// <returns></returns> internal static string GetStringA(IntPtr Pointer, bool Decode = true, int?CP = null, int?Len = null) { int len = 0; if (Len == null) { while (Marshal.ReadByte(Pointer, len) != 0) { ++len; } } else { len = Len.Value; } byte[] buffer = new byte[len]; Marshal.Copy(Pointer, buffer, 0, buffer.Length); if ((LogInput || LogAll) && !DumpStrOnly) { Log("Input: {0}", true, ParseBytes(buffer)); } if (Unicode && CP == null) { return(Encoding.Default.GetString(buffer)); } else { if (CP != null) { Encoding Enco; switch (CP) { case 0: case 3: case 2: case 1: Enco = Encoding.Default; break; default: Enco = (from x in Encoding.GetEncodings() where x.CodePage == CP select x.GetEncoding()).FirstOrDefault() ?? WriteEncoding; break; } return(Enco.GetString(buffer)); } else if (Decode) { return(ReadEncoding.GetString(buffer)); } else { return(ParseBytes(buffer)); } } }