using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PFCRip { public static class LittleEndianConverter { #region Public Methods public static string GetString(byte[] data, uint startIndex, uint length) { string ret = String.Empty; for (int i = 0; i < length; i++) ret += (char)data[startIndex + i]; return ret; } public static string GetSafeString(byte[] data) { return GetSafeString(data, 0, (uint)data.Length); } public static string GetSafeString(byte[] data, uint startIndex, uint length) { string start = GetString(data, startIndex, length); string ret = String.Empty; for (int i = 0; i < start.Length; i++) if (start[i] >= 0x20 && start[i] < 0xF0) ret += start[i]; return ret; } public static ushort ToUInt16(byte[] data) { return ToUInt16(data, 0); } public static ushort ToUInt16(byte[] data, uint startIndex) { ushort ret; ret = (ushort)(data[startIndex + 0] & 0x00FF); ret |= (ushort)((data[startIndex + 1] << 8) & 0xFF00); return ret; } public static uint ToUInt32(byte[] data) { return ToUInt32(data, 0); } public static uint ToUInt32(byte[] data, uint startIndex) { uint ret; ret = (uint)(data[startIndex + 0] & 0x000000FF); ret |= (uint)((data[startIndex + 1] << 8) & 0x0000FF00); ret |= (uint)((data[startIndex + 2] << 16) & 0x00FF0000); ret |= (uint)((data[startIndex + 3] << 24) & 0xFF000000); return ret; } #endregion } }