diff --git a/libexeinfo/BigEndianMarshal.cs b/libexeinfo/BigEndianMarshal.cs index b60aca9..6c87dc8 100644 --- a/libexeinfo/BigEndianMarshal.cs +++ b/libexeinfo/BigEndianMarshal.cs @@ -48,6 +48,20 @@ namespace libexeinfo return SwapStructureMembersEndian(str); } + /// + /// Marshals a little endian structure from a byte array. + /// + /// The structure. + /// Byte array. + /// Structure type. + public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct + { + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + T str = (T)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); + return str; + } + /// /// Swaps endian of structure members that correspond to numerical types. /// Does not traverse nested structures.