diff --git a/trunk/ProcessHacker.Common/Utils.cs b/trunk/ProcessHacker.Common/Utils.cs
index bcee92a3f..fef9b19b6 100644
--- a/trunk/ProcessHacker.Common/Utils.cs
+++ b/trunk/ProcessHacker.Common/Utils.cs
@@ -36,6 +36,11 @@ namespace ProcessHacker.Common
///
public static class Utils
{
+ public enum Endianness
+ {
+ Little, Big
+ }
+
#region Constants
public static string[] SizeUnitNames = { "B", "kB", "MB", "GB", "TB", "PB", "EB" };
@@ -117,6 +122,19 @@ namespace ProcessHacker.Common
return na;
}
+ ///
+ /// Determines whether the specified value is contained
+ /// within an array.
+ ///
+ /// The type of the array.
+ /// The array to search.
+ /// The value to search for.
+ /// True if the array contains the value, otherwise false.
+ public static bool Contains(this T[] array, T value)
+ {
+ return Array.IndexOf(array, value) != -1;
+ }
+
///
/// Counts the number of bits in the specified number.
///
@@ -252,7 +270,7 @@ namespace ProcessHacker.Common
/// The first array.
/// The second array.
/// Whether the two arrays are considered to be equal.
- public static bool Equals(T[] array, T[] other)
+ public static bool Equals(this T[] array, T[] other)
{
return Equals(array, other, 0);
}
@@ -265,7 +283,7 @@ namespace ProcessHacker.Common
/// The second array.
/// The index from which to begin comparing.
/// Whether the two arrays are considered to be equal.
- public static bool Equals(T[] array, T[] other, int startIndex)
+ public static bool Equals(this T[] array, T[] other, int startIndex)
{
return Equals(array, other, startIndex, array.Length);
}
@@ -279,7 +297,7 @@ namespace ProcessHacker.Common
/// The index from which to begin comparing.
/// The number of elements to compare.
/// Whether the two arrays are considered to be equal.
- public static bool Equals(T[] array, T[] other, int startIndex, int length)
+ public static bool Equals(this T[] array, T[] other, int startIndex, int length)
{
for (int i = startIndex; i < startIndex + length; i++)
if (!array[i].Equals(other[i]))
@@ -293,7 +311,7 @@ namespace ProcessHacker.Common
///
/// The string to escape.
/// The escaped string.
- public static string EscapeString(string str)
+ public static string Escape(this string str)
{
str = str.Replace("\\", "\\\\");
str = str.Replace("\"", "\\\"");
@@ -394,6 +412,26 @@ namespace ProcessHacker.Common
return "0x" + address.ToString("x");
}
+ public static string FormatFlags(Type e, long value)
+ {
+ string r = "";
+
+ for (int i = 0; i < 32; i++)
+ {
+ long fv = 1 << i;
+
+ if ((value & fv) == fv)
+ {
+ r += Enum.GetName(e, fv) + ", ";
+ }
+ }
+
+ if (r.EndsWith(", "))
+ r = r.Remove(r.Length - 2, 2);
+
+ return r;
+ }
+
///
/// Formats a object into a string representation.
///
@@ -596,6 +634,80 @@ namespace ProcessHacker.Common
time.Milliseconds);
}
+ public static byte[] GetBytes(this int n, Endianness type)
+ {
+ byte[] data = new byte[4];
+
+ if (type == Endianness.Little)
+ {
+ data[0] = (byte)(n & 0xff);
+ data[1] = (byte)((n >> 8) & 0xff);
+ data[2] = (byte)((n >> 16) & 0xff);
+ data[3] = (byte)((n >> 24) & 0xff);
+ }
+ else if (type == Endianness.Big)
+ {
+ data[0] = (byte)((n >> 24) & 0xff);
+ data[1] = (byte)((n >> 16) & 0xff);
+ data[2] = (byte)((n >> 8) & 0xff);
+ data[3] = (byte)(n & 0xff);
+ }
+ else
+ {
+ throw new ArgumentException();
+ }
+
+ return data;
+ }
+
+ public static byte[] GetBytes(this uint n, Endianness type)
+ {
+ byte[] data = new byte[4];
+
+ if (type == Endianness.Little)
+ {
+ data[0] = (byte)(n & 0xff);
+ data[1] = (byte)((n >> 8) & 0xff);
+ data[2] = (byte)((n >> 16) & 0xff);
+ data[3] = (byte)((n >> 24) & 0xff);
+ }
+ else if (type == Endianness.Big)
+ {
+ data[0] = (byte)((n >> 24) & 0xff);
+ data[1] = (byte)((n >> 16) & 0xff);
+ data[2] = (byte)((n >> 8) & 0xff);
+ data[3] = (byte)(n & 0xff);
+ }
+ else
+ {
+ throw new ArgumentException();
+ }
+
+ return data;
+ }
+
+ public static byte[] GetBytes(this ushort n, Endianness type)
+ {
+ byte[] data = new byte[2];
+
+ if (type == Endianness.Little)
+ {
+ data[0] = (byte)(n & 0xff);
+ data[1] = (byte)((n >> 8) & 0xff);
+ }
+ else if (type == Endianness.Big)
+ {
+ data[0] = (byte)((n >> 8) & 0xff);
+ data[1] = (byte)(n & 0xff);
+ }
+ else
+ {
+ throw new ArgumentException();
+ }
+
+ return data;
+ }
+
///
/// Converts a 64-bit Windows time value to a DateTime object.
///
@@ -629,7 +741,7 @@ namespace ProcessHacker.Common
return new Rectangle(int.Parse(split[0]), int.Parse(split[1]),
int.Parse(split[2]), int.Parse(split[3]));
}
-
+
///
/// Returns a object of the specified thread ID.
///
@@ -710,6 +822,16 @@ namespace ProcessHacker.Common
return ProcessPriorityClass.Idle;
}
+ public static int ReadInt32(Stream s, Endianness type)
+ {
+ byte[] buffer = new byte[4];
+
+ if (s.Read(buffer, 0, 4) == 0)
+ throw new EndOfStreamException();
+
+ return ToInt32(buffer, type);
+ }
+
///
/// Reads a null-terminated string from a stream.
///
@@ -732,6 +854,26 @@ namespace ProcessHacker.Common
return str.ToString();
}
+ public static string ReadString(Stream s, int length)
+ {
+ byte[] buffer = new byte[length];
+
+ if (s.Read(buffer, 0, length) == 0)
+ throw new EndOfStreamException();
+
+ return System.Text.ASCIIEncoding.ASCII.GetString(buffer);
+ }
+
+ public static uint ReadUInt32(Stream s, Endianness type)
+ {
+ byte[] buffer = new byte[4];
+
+ if (s.Read(buffer, 0, 4) == 0)
+ throw new EndOfStreamException();
+
+ return ToUInt32(buffer, type);
+ }
+
///
/// Reads a null-terminated Unicode string from a stream.
///
@@ -792,6 +934,68 @@ namespace ProcessHacker.Common
return str.ToString();
}
+ ///
+ /// Swaps the order of the bytes.
+ ///
+ /// The number to change.
+ /// A number.
+ public static int Reverse(this int v)
+ {
+ byte b1 = (byte)v;
+ byte b2 = (byte)(v >> 8);
+ byte b3 = (byte)(v >> 16);
+ byte b4 = (byte)(v >> 24);
+
+ return b4 | (b3 << 8) | (b2 << 16) | (b1 << 24);
+ }
+
+ ///
+ /// Swaps the order of the bytes.
+ ///
+ /// The number to change.
+ /// A number.
+ public static uint Reverse(this uint v)
+ {
+ uint b0 = v & 0xff;
+ uint b1 = (v >> 8) & 0xff;
+ uint b2 = (v >> 16) & 0xff;
+ uint b3 = (v >> 24) & 0xff;
+
+ b0 <<= 24;
+ b1 <<= 16;
+ b2 <<= 8;
+
+ return b0 | b1 | b2 | b3;
+ }
+
+ ///
+ /// Swaps the order of the bytes.
+ ///
+ /// The number to change.
+ /// A number.
+ public static ushort Reverse(this ushort v)
+ {
+ byte b1 = (byte)v;
+ byte b2 = (byte)(v >> 8);
+
+ return (ushort)(b2 | (b1 << 8));
+ }
+
+ ///
+ /// Reverses an array.
+ ///
+ /// The array to reverse.
+ /// A new array.
+ public static T[] Reverse(this T[] data)
+ {
+ T[] newData = new T[data.Length];
+
+ for (int i = 0; i < data.Length; i++)
+ newData[i] = data[data.Length - i - 1];
+
+ return newData;
+ }
+
///
/// Selects all of the specified items.
///
@@ -819,7 +1023,7 @@ namespace ProcessHacker.Common
/// The control.
/// The type of the control.
/// The new setting.
- public static void SetDoubleBuffered(Control c, Type t, bool value)
+ public static void SetDoubleBuffered(this Control c, Type t, bool value)
{
PropertyInfo property = t.GetProperty("DoubleBuffered",
BindingFlags.NonPublic | BindingFlags.Instance);
@@ -834,7 +1038,7 @@ namespace ProcessHacker.Common
/// The new value.
public static void SetDoubleBuffered(this Control c, bool value)
{
- SetDoubleBuffered(c, c.GetType(), value);
+ c.SetDoubleBuffered(c.GetType(), value);
}
///
@@ -867,47 +1071,95 @@ namespace ProcessHacker.Common
return nameList;
}
- ///
- /// Swaps the order of the bytes.
- ///
- /// The number to change.
- /// A number.
- public static int SwapBytes(this int v)
+ public static int ToInt32(this byte[] data, Endianness type)
{
- byte b1 = (byte)v;
- byte b2 = (byte)(v >> 8);
- byte b3 = (byte)(v >> 16);
- byte b4 = (byte)(v >> 24);
-
- return b4 | (b3 << 8) | (b2 << 16) | (b1 << 24);
+ if (type == Endianness.Little)
+ {
+ return (data[0]) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+ }
+ else if (type == Endianness.Big)
+ {
+ return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | (data[3]);
+ }
+ else
+ {
+ throw new ArgumentException();
+ }
}
- ///
- /// Swaps the order of the bytes.
- ///
- /// The number to change.
- /// A number.
- public static uint SwapBytes(this uint v)
+ public static long ToInt64(this byte[] data, Endianness type)
{
- byte b1 = (byte)v;
- byte b2 = (byte)(v >> 8);
- byte b3 = (byte)(v >> 16);
- byte b4 = (byte)(v >> 24);
-
- return (uint)(b4 | (b3 << 8) | (b2 << 16) | (b1 << 24));
+ if (type == Endianness.Little)
+ {
+ return (data[0]) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24) |
+ (data[4] << 32) | (data[5] << 40) | (data[6] << 48) | (data[7] << 56);
+ }
+ else if (type == Endianness.Big)
+ {
+ return (data[0] << 56) | (data[1] << 48) | (data[2] << 40) | (data[3] << 32) |
+ (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | (data[7]);
+ }
+ else
+ {
+ throw new ArgumentException();
+ }
}
- ///
- /// Swaps the order of the bytes.
- ///
- /// The number to change.
- /// A number.
- public static ushort SwapBytes(this ushort v)
+ public static IntPtr ToIntPtr(this byte[] data)
{
- byte b1 = (byte)v;
- byte b2 = (byte)(v >> 8);
+ if (IntPtr.Size != data.Length)
+ throw new ArgumentException("data");
- return (ushort)(b2 | (b1 << 8));
+ if (IntPtr.Size == sizeof(int))
+ return new IntPtr(data.ToInt32(Endianness.Little));
+ else if (IntPtr.Size == sizeof(long))
+ return new IntPtr(data.ToInt64(Endianness.Little));
+ else
+ throw new ArgumentException("data");
+ }
+
+ public static ushort ToUInt16(this byte[] data, Endianness type)
+ {
+ return ToUInt16(data, 0, type);
+ }
+
+ public static ushort ToUInt16(this byte[] data, int offset, Endianness type)
+ {
+ if (type == Endianness.Little)
+ {
+ return (ushort)(data[offset] | (data[offset + 1] << 8));
+ }
+ else if (type == Endianness.Big)
+ {
+ return (ushort)((data[offset] << 8) | data[offset + 1]);
+ }
+ else
+ {
+ throw new ArgumentException();
+ }
+ }
+
+ public static uint ToUInt32(this byte[] data, Endianness type)
+ {
+ return ToUInt32(data, 0, type);
+ }
+
+ public static uint ToUInt32(this byte[] data, int offset, Endianness type)
+ {
+ if (type == Endianness.Little)
+ {
+ return (uint)(data[offset]) | (uint)(data[offset + 1] << 8) |
+ (uint)(data[offset + 2] << 16) | (uint)(data[offset + 3] << 24);
+ }
+ else if (type == Endianness.Big)
+ {
+ return (uint)(data[offset] << 24) | (uint)(data[offset + 1] << 16) |
+ (uint)(data[offset + 2] << 8) | (uint)(data[offset + 3]);
+ }
+ else
+ {
+ throw new ArgumentException();
+ }
}
public static int WindowsToNativeBasePriority(System.Diagnostics.ProcessPriorityClass priority)
@@ -930,270 +1182,5 @@ namespace ProcessHacker.Common
return 8;
}
}
-
- #region Stuff from PNG.Net
-
- public enum Endianness
- {
- Little, Big
- }
-
- public static bool ArrayContains(T[] array, T element)
- {
- foreach (T e in array)
- if (e.Equals(element))
- return true;
-
- return false;
- }
-
- public static bool BytesEqual(byte[] b1, byte[] b2)
- {
- for (int i = 0; i < b1.Length; i++)
- if (b1[i] != b2[i])
- return false;
-
- return true;
- }
-
- public static int BytesToInt(byte[] data, Endianness type)
- {
- if (type == Endianness.Little)
- {
- return (data[0]) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
- }
- else if (type == Endianness.Big)
- {
- return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | (data[3]);
- }
- else
- {
- throw new ArgumentException();
- }
- }
-
- public static long BytesToLong(byte[] data, Endianness type)
- {
- if (type == Endianness.Little)
- {
- return (data[0]) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24) |
- (data[4] << 32) | (data[5] << 40) | (data[6] << 48) | (data[7] << 56);
- }
- else if (type == Endianness.Big)
- {
- return (data[0] << 56) | (data[1] << 48) | (data[2] << 40) | (data[3] << 32) |
- (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | (data[7]);
- }
- else
- {
- throw new ArgumentException();
- }
- }
-
- public static uint BytesToUInt(byte[] data, Endianness type)
- {
- return BytesToUInt(data, 0, type);
- }
-
- public static uint BytesToUInt(byte[] data, int offset, Endianness type)
- {
- if (type == Endianness.Little)
- {
- return (uint)(data[offset]) | (uint)(data[offset + 1] << 8) |
- (uint)(data[offset + 2] << 16) | (uint)(data[offset + 3] << 24);
- }
- else if (type == Endianness.Big)
- {
- return (uint)(data[offset] << 24) | (uint)(data[offset + 1] << 16) |
- (uint)(data[offset + 2] << 8) | (uint)(data[offset + 3]);
- }
- else
- {
- throw new ArgumentException();
- }
- }
-
- public static ushort BytesToUShort(byte[] data, Endianness type)
- {
- return BytesToUShort(data, 0, type);
- }
-
- public static ushort BytesToUShort(byte[] data, int offset, Endianness type)
- {
- if (type == Endianness.Little)
- {
- return (ushort)(data[offset] | (data[offset + 1] << 8));
- }
- else if (type == Endianness.Big)
- {
- return (ushort)((data[offset] << 8) | data[offset + 1]);
- }
- else
- {
- throw new ArgumentException();
- }
- }
-
- public static string FlagsToString(Type e, long value)
- {
- string r = "";
-
- for (int i = 0; i < 32; i++)
- {
- long fv = 1 << i;
-
- if ((value & fv) == fv)
- {
- r += Enum.GetName(e, fv) + ", ";
- }
- }
-
- if (r.EndsWith(", "))
- r = r.Remove(r.Length - 2, 2);
-
- return r;
- }
-
- public static int IntCeilDiv(int a, int b)
- {
- return (int)Math.Ceiling(((double)a / b));
- }
-
- public static byte[] IntToBytes(int n, Endianness type)
- {
- byte[] data = new byte[4];
-
- if (type == Endianness.Little)
- {
- data[0] = (byte)(n & 0xff);
- data[1] = (byte)((n >> 8) & 0xff);
- data[2] = (byte)((n >> 16) & 0xff);
- data[3] = (byte)((n >> 24) & 0xff);
- }
- else if (type == Endianness.Big)
- {
- data[0] = (byte)((n >> 24) & 0xff);
- data[1] = (byte)((n >> 16) & 0xff);
- data[2] = (byte)((n >> 8) & 0xff);
- data[3] = (byte)(n & 0xff);
- }
- else
- {
- throw new ArgumentException();
- }
-
- return data;
- }
-
- public static byte[] ReverseBytes(byte[] data)
- {
- byte[] newdata = new byte[data.Length];
-
- for (int i = 0; i < data.Length; i++)
- newdata[i] = data[data.Length - i - 1];
-
- return newdata;
- }
-
- public static uint ReverseEndian(uint n)
- {
- uint b0 = n & 0xff;
- uint b1 = (n >> 8) & 0xff;
- uint b2 = (n >> 16) & 0xff;
- uint b3 = (n >> 24) & 0xff;
-
- b0 <<= 24;
- b1 <<= 16;
- b2 <<= 8;
-
- return b0 | b1 | b2 | b3;
- }
-
- public static int ReadInt(Stream s, Endianness type)
- {
- byte[] buffer = new byte[4];
-
- if (s.Read(buffer, 0, 4) == 0)
- throw new EndOfStreamException();
-
- return BytesToInt(buffer, type);
- }
-
- public static string ReadString(Stream s, int length)
- {
- byte[] buffer = new byte[length];
-
- if (s.Read(buffer, 0, length) == 0)
- throw new EndOfStreamException();
-
- return System.Text.ASCIIEncoding.ASCII.GetString(buffer);
- }
-
- public static uint ReadUInt(Stream s, Endianness type)
- {
- byte[] buffer = new byte[4];
-
- if (s.Read(buffer, 0, 4) == 0)
- throw new EndOfStreamException();
-
- return BytesToUInt(buffer, type);
- }
-
- public static uint RoundUpAddress(uint address, uint align)
- {
- uint t = (uint)Math.Ceiling((double)address / align);
-
- return t * align;
- }
-
- public static byte[] UIntToBytes(uint n, Endianness type)
- {
- byte[] data = new byte[4];
-
- if (type == Endianness.Little)
- {
- data[0] = (byte)(n & 0xff);
- data[1] = (byte)((n >> 8) & 0xff);
- data[2] = (byte)((n >> 16) & 0xff);
- data[3] = (byte)((n >> 24) & 0xff);
- }
- else if (type == Endianness.Big)
- {
- data[0] = (byte)((n >> 24) & 0xff);
- data[1] = (byte)((n >> 16) & 0xff);
- data[2] = (byte)((n >> 8) & 0xff);
- data[3] = (byte)(n & 0xff);
- }
- else
- {
- throw new ArgumentException();
- }
-
- return data;
- }
-
- public static byte[] UShortToBytes(ushort n, Endianness type)
- {
- byte[] data = new byte[2];
-
- if (type == Endianness.Little)
- {
- data[0] = (byte)(n & 0xff);
- data[1] = (byte)((n >> 8) & 0xff);
- }
- else if (type == Endianness.Big)
- {
- data[0] = (byte)((n >> 8) & 0xff);
- data[1] = (byte)(n & 0xff);
- }
- else
- {
- throw new ArgumentException();
- }
-
- return data;
- }
-
- #endregion
}
}
diff --git a/trunk/ProcessHacker.Native/Windows.cs b/trunk/ProcessHacker.Native/Windows.cs
index fa6c46e3c..4606ba5a6 100644
--- a/trunk/ProcessHacker.Native/Windows.cs
+++ b/trunk/ProcessHacker.Native/Windows.cs
@@ -337,8 +337,8 @@ namespace ProcessHacker.Native
retDict[struc.OwningProcessId].Add(new NetworkConnection()
{
Protocol = NetworkProtocol.Tcp,
- Local = new IPEndPoint(struc.LocalAddress, ((ushort)struc.LocalPort).SwapBytes()),
- Remote = new IPEndPoint(struc.RemoteAddress, ((ushort)struc.RemotePort).SwapBytes()),
+ Local = new IPEndPoint(struc.LocalAddress, ((ushort)struc.LocalPort).Reverse()),
+ Remote = new IPEndPoint(struc.RemoteAddress, ((ushort)struc.RemotePort).Reverse()),
State = struc.State,
Pid = struc.OwningProcessId
});
@@ -365,7 +365,7 @@ namespace ProcessHacker.Native
new NetworkConnection()
{
Protocol = NetworkProtocol.Udp,
- Local = new IPEndPoint(struc.LocalAddress, ((ushort)struc.LocalPort).SwapBytes()),
+ Local = new IPEndPoint(struc.LocalAddress, ((ushort)struc.LocalPort).Reverse()),
Pid = struc.OwningProcessId
});
}
@@ -793,9 +793,9 @@ namespace ProcessHacker.Native
{
State = MibTcpState.DeleteTcb,
LocalAddress = (uint)this.Local.Address.Address,
- LocalPort = ((ushort)this.Local.Port).SwapBytes(),
+ LocalPort = ((ushort)this.Local.Port).Reverse(),
RemoteAddress = this.Remote != null ? (uint)this.Remote.Address.Address : 0,
- RemotePort = this.Remote != null ? ((ushort)this.Remote.Port).SwapBytes() : 0
+ RemotePort = this.Remote != null ? ((ushort)this.Remote.Port).Reverse() : 0
};
int result = Win32.SetTcpEntry(ref row);
diff --git a/trunk/ProcessHacker/Forms/PEWindow.cs b/trunk/ProcessHacker/Forms/PEWindow.cs
index 4d3de52ef..acff1d138 100644
--- a/trunk/ProcessHacker/Forms/PEWindow.cs
+++ b/trunk/ProcessHacker/Forms/PEWindow.cs
@@ -149,7 +149,7 @@ namespace ProcessHacker
listCOFFHeader.Items.Add(new ListViewItem(new string[] { "Size of Optional Header",
_peFile.COFFHeader.SizeOfOptionalHeader.ToString() }));
listCOFFHeader.Items.Add(new ListViewItem(new string[] { "Characteristics",
- Utils.FlagsToString(typeof(ImageCharacteristics), (long)_peFile.COFFHeader.Characteristics) }));
+ Utils.FormatFlags(typeof(ImageCharacteristics), (long)_peFile.COFFHeader.Characteristics) }));
#endregion
@@ -201,7 +201,7 @@ namespace ProcessHacker
listCOFFOptionalHeader.Items.Add(new ListViewItem(new string[] { "Subsystem",
_peFile.COFFOptionalHeader.Subsystem.ToString() }));
listCOFFOptionalHeader.Items.Add(new ListViewItem(new string[] { "DLL Characteristics",
- Utils.FlagsToString(typeof(DllCharacteristics), (long)_peFile.COFFOptionalHeader.DllCharacteristics) }));
+ Utils.FormatFlags(typeof(DllCharacteristics), (long)_peFile.COFFOptionalHeader.DllCharacteristics) }));
listCOFFOptionalHeader.Items.Add(new ListViewItem(new string[] { "Size of Stack Reserve",
"0x" + _peFile.COFFOptionalHeader.SizeOfStackReserve.ToString("x") }));
listCOFFOptionalHeader.Items.Add(new ListViewItem(new string[] { "Size of Stack Commit",
@@ -251,7 +251,7 @@ namespace ProcessHacker
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "0x" + sh.VirtualSize.ToString("x")));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "0x" + sh.PointerToRawData.ToString("x")));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item,
- Utils.FlagsToString(typeof(SectionFlags), (long)sh.Characteristics)));
+ Utils.FormatFlags(typeof(SectionFlags), (long)sh.Characteristics)));
listSections.Items.Add(item);
}
diff --git a/trunk/ProcessHacker/PE/PEFile.cs b/trunk/ProcessHacker/PE/PEFile.cs
index 58d566fa5..5936acae5 100644
--- a/trunk/ProcessHacker/PE/PEFile.cs
+++ b/trunk/ProcessHacker/PE/PEFile.cs
@@ -80,7 +80,7 @@ namespace ProcessHacker.PE
byte[] peSig = br.ReadBytes(4);
- if (!Utils.BytesEqual(peSig, PEFile.PESignature))
+ if (!Utils.Equals(peSig, PEFile.PESignature))
throw new PEException("Invalid PE signature.");
// read COFF header
diff --git a/trunk/ProcessHacker/Structs/StructDef.cs b/trunk/ProcessHacker/Structs/StructDef.cs
index 5c9e29340..617a79593 100644
--- a/trunk/ProcessHacker/Structs/StructDef.cs
+++ b/trunk/ProcessHacker/Structs/StructDef.cs
@@ -137,7 +137,7 @@ namespace ProcessHacker.Structs
switch (field.Type)
{
case FieldType.Bool32:
- value.Value = Utils.BytesToInt(IOProvider.ReadBytes(offset, 4),
+ value.Value = Utils.ToInt32(IOProvider.ReadBytes(offset, 4),
Utils.Endianness.Little) != 0;
readSize = 4;
break;
@@ -155,7 +155,7 @@ namespace ProcessHacker.Structs
break;
case FieldType.Double:
{
- long data = Utils.BytesToLong(
+ long data = Utils.ToInt64(
IOProvider.ReadBytes(offset, 8), Utils.Endianness.Little);
value.Value = *(double*)&data;
@@ -163,18 +163,17 @@ namespace ProcessHacker.Structs
}
break;
case FieldType.Int16:
- value.Value = (short)Utils.BytesToUShort(
+ value.Value = (short)Utils.ToUInt16(
IOProvider.ReadBytes(offset, 2), Utils.Endianness.Little);
readSize = 2;
break;
- case FieldType.PVoid:
case FieldType.Int32:
- value.Value = Utils.BytesToInt(
+ value.Value = Utils.ToInt32(
IOProvider.ReadBytes(offset, 4), Utils.Endianness.Little);
readSize = 4;
break;
case FieldType.Int64:
- value.Value = Utils.BytesToLong(
+ value.Value = Utils.ToInt64(
IOProvider.ReadBytes(offset, 8), Utils.Endianness.Little);
readSize = 8;
break;
@@ -182,9 +181,13 @@ namespace ProcessHacker.Structs
value.Value = (sbyte)IOProvider.ReadBytes(offset, 1)[0];
readSize = 1;
break;
+ case FieldType.PVoid:
+ value.Value = IOProvider.ReadBytes(offset, IntPtr.Size).ToIntPtr();
+ readSize = IntPtr.Size;
+ break;
case FieldType.Single:
{
- int data = Utils.BytesToInt(
+ int data = Utils.ToInt32(
IOProvider.ReadBytes(offset, 4), Utils.Endianness.Little);
value.Value = *(float*)&data;
@@ -268,17 +271,17 @@ namespace ProcessHacker.Structs
break;
case FieldType.UInt16:
- value.Value = Utils.BytesToUShort(
+ value.Value = Utils.ToUInt16(
IOProvider.ReadBytes(offset, 2), Utils.Endianness.Little);
readSize = 2;
break;
case FieldType.UInt32:
- value.Value = Utils.BytesToUInt(
+ value.Value = Utils.ToUInt32(
IOProvider.ReadBytes(offset, 4), Utils.Endianness.Little);
readSize = 4;
break;
case FieldType.UInt64:
- value.Value = (ulong)Utils.BytesToLong(
+ value.Value = (ulong)Utils.ToInt64(
IOProvider.ReadBytes(offset, 8), Utils.Endianness.Little);
readSize = 8;
break;
@@ -308,7 +311,7 @@ namespace ProcessHacker.Structs
// resolve pointer
if (field.IsPointer)
{
- int pointingTo = Utils.BytesToInt(IOProvider.ReadBytes(Offset.Increment(localOffset), 4), Utils.Endianness.Little);
+ int pointingTo = Utils.ToInt32(IOProvider.ReadBytes(Offset.Increment(localOffset), 4), Utils.Endianness.Little);
localOffset += 4;