Exemple #1
0
 /// <summary>
 /// Creates a new known relative pointer value.
 /// </summary>
 /// <param name="referencedMemory">The base memory pointer.</param>
 /// <param name="offset">The offset relative to the base po[inter.</param>
 /// <param name="is32Bit">Indicates the pointer is 32 or 64 bits wide.</param>
 public RelativePointerValue(IMemoryAccessValue referencedMemory, int offset, bool is32Bit)
 {
     Is32Bit          = is32Bit;
     ReferencedMemory = referencedMemory;
     CurrentOffset    = offset;
     IsKnown          = true;
 }
Exemple #2
0
 /// <summary>
 /// Creates a new string value.
 /// </summary>
 /// <param name="stringType">The string type signature.</param>
 /// <param name="contents">The raw contents of the string.</param>
 /// <exception cref="ArgumentException">
 /// Occurs when the memory block referenced by <paramref name="contents"/> is of an invalid size.
 /// </exception>
 public StringValue(TypeSignature stringType, IMemoryAccessValue contents)
 {
     Type      = stringType ?? throw new ArgumentNullException(nameof(stringType));
     _contents = contents ?? throw new ArgumentNullException(nameof(contents));
     if (contents.Size % sizeof(char) != 0)
     {
         throw new ArgumentException($"Length of raw string memory must be a multiple of two.");
     }
 }
 /// <summary>
 /// Reads a single .NET structure at the provided offset.
 /// </summary>
 /// <param name="self">The base pointer value to read from.</param>
 /// <param name="offset">The offset to start reading.</param>
 /// <param name="valueFactory">The memory allocator responsible for managing type layouts.</param>
 /// <param name="typeLayout">The type layout to read.</param>
 /// <returns>The read structure.</returns>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Occurs when the offset does not fall within the memory range.
 /// </exception>
 public static IConcreteValue ReadStruct(this IMemoryAccessValue self, int offset, IValueFactory valueFactory, TypeMemoryLayout typeLayout)
 {
     return(typeLayout.Type.ToTypeSignature().ElementType switch
     {
         ElementType.Boolean => self.ReadInteger8(offset),
         ElementType.Char => self.ReadInteger16(offset),
         ElementType.I1 => self.ReadInteger8(offset),
         ElementType.U1 => self.ReadInteger8(offset),
         ElementType.I2 => self.ReadInteger16(offset),
         ElementType.U2 => self.ReadInteger16(offset),
         ElementType.I4 => self.ReadInteger32(offset),
         ElementType.U4 => self.ReadInteger32(offset),
         ElementType.I8 => self.ReadInteger64(offset),
         ElementType.U8 => self.ReadInteger64(offset),
         ElementType.R4 => self.ReadFloat32(offset),
         ElementType.R8 => self.ReadFloat64(offset),
         ElementType.ValueType => self.ReadStructSlow(offset, valueFactory, typeLayout),
         ElementType.I => valueFactory.Is32Bit ? (IntegerValue)self.ReadInteger32(offset) : self.ReadInteger64(offset),
         ElementType.U => valueFactory.Is32Bit ? (IntegerValue)self.ReadInteger32(offset) : self.ReadInteger64(offset),
         ElementType.Enum => ReadEnumValue(self, offset, valueFactory, typeLayout),
         _ => new UnknownValue()
     });
Exemple #4
0
 /// <summary>
 /// Creates a new pointer to an offset within the memory.
 /// </summary>
 /// <param name="self">The memory to reference.</param>
 /// <param name="offset">The offset within the memory.</param>
 /// <param name="is32Bit">Indicates whether the pointer is 32 or 64 bits wide.</param>
 /// <returns>The constructed pointer.</returns>
 public static IPointerValue MakePointer(this IMemoryAccessValue self, int offset, bool is32Bit) =>
 new RelativePointerValue(self, offset, is32Bit);
Exemple #5
0
 /// <summary>
 /// Creates a new low level emulated object.
 /// </summary>
 /// <param name="valueFactory">The object responsible for memory management in the virtual machine.</param>
 /// <param name="valueType">The type of the object.</param>
 /// <param name="contents">The raw contents of the object.</param>
 public LleStructValue(IValueFactory valueFactory, TypeSignature valueType, IMemoryAccessValue contents)
 {
     Type         = valueType ?? throw new ArgumentNullException(nameof(valueType));
     ValueFactory = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory));
     Contents     = contents ?? throw new ArgumentNullException(nameof(contents));
 }
Exemple #6
0
 /// <summary>
 /// Creates a new pointer value.
 /// </summary>
 /// <param name="referencedMemory">The base pointer value.</param>
 /// <param name="offset">The offset relative to the base pointer.</param>
 /// <param name="is32Bit">Indicates the pointer is 32 or 64 bits wide.</param>
 public PointerValue(IMemoryAccessValue referencedMemory, int offset, bool is32Bit)
     : base(referencedMemory, offset, is32Bit)
 {
 }
 /// <summary>
 /// Creates a new known relative pointer value.
 /// </summary>
 /// <param name="referencedMemory">The base memory pointer.</param>
 /// <param name="is32Bit">Indicates the pointer is 32 or 64 bits wide.</param>
 public RelativePointerValue(IMemoryAccessValue referencedMemory, bool is32Bit)
     : this(referencedMemory, 0, is32Bit)
 {
 }
Exemple #8
0
 /// <summary>
 /// Creates a new structure value.
 /// </summary>
 /// <param name="valueFactory">The object responsible for memory management in the virtual machine.</param>
 /// <param name="valueType">The type of the object.</param>
 /// <param name="contents">The raw contents of the structure.</param>
 public StructValue(IValueFactory valueFactory, TypeSignature valueType, IMemoryAccessValue contents)
     : base(valueFactory, valueType, contents)
 {
 }