/// <summary>Read a pointer value from the stream</summary> /// <param name="addressSize">Size of the pointer we're to read</param> /// <returns> /// A handle that encapsulates the pointer value and its size. After the value /// is read from the stream, <see cref="BaseAddress"/> is subtracted. /// </returns> /// <remarks> /// Be sure to set <see cref="BaseAddress"/> to the proper value so you get /// a correct relative-virtual-address. Otherwise, set <see cref="BaseAddress"/> /// to zero to get the pure pointer value. /// </remarks> public Values.PtrHandle ReadPointer(Shell.ProcessorSize addressSize) { var ptr = new Values.PtrHandle(addressSize); if (!ptr.Is64bit) { ptr.u32 = ReadUInt32(); if (ptr.u32 != 0) { ptr.u32 -= BaseAddress.u32; } } else { ptr.u64 = ReadUInt64(); if (ptr.u64 != 0) { ptr.u64 -= BaseAddress.u64; } } return(ptr); }
/// <summary>Construct an address with an explicit size, but no set value (default to NULL)</summary> /// <param name="addressSize">This pointer's Address size</param> public PtrHandle(Shell.ProcessorSize addressSize) { Handle = Info = u64 = 0; u32 = UserData = 0; Type = PtrHandleType.Absolute; Is64bit = addressSize == Shell.ProcessorSize.x64; }
/// <summary>Initialize the VAT with a specific handle size and initial table capacity</summary> /// <param name="vaSize">Handle size</param> /// <param name="translationCapacity">The initial table capacity</param> public void VirtualAddressTranslationInitialize(Shell.ProcessorSize vaSize, int translationCapacity = 0) { if (mVAT == null) { mVAT = new Memory.VirtualAddressTranslationStack(vaSize, translationCapacity); mVAT.PushNull(); // implicitly use null as our initial VA translator } }
/// <summary>Define a new <see cref="StringMemoryPool"/> configuration</summary> /// <param name="method">Text storage definition</param> /// <param name="implicitNull">Is a null string entry atomically added?</param> /// <param name="baseAddress">Base address for string references</param> /// <remarks><see cref="AddressSize"/> is determined from <see cref="baseAddress"/></remarks> public StringMemoryPoolSettings(StringStorage method, bool implicitNull, Values.PtrHandle baseAddress) { { Storage = method; AllowDuplicates = false; } mAddressSize = baseAddress.Is64bit ? Shell.ProcessorSize.x64 : Shell.ProcessorSize.x32; ImplicitNull = implicitNull; BaseAddress = baseAddress; }
/// <summary>Define a new <see cref="StringMemoryPool"/> configuration</summary> /// <param name="method">Text storage definition</param> /// <param name="implicitNull">Is a null string entry atomically added?</param> /// <param name="addressSize">Size of string address references</param> /// <remarks>Base address defaults to the null equivlent on <paramref name="addressSize"/> platforms</remarks> public StringMemoryPoolSettings(StringStorage method, bool implicitNull, Shell.ProcessorSize addressSize) { { Storage = method; AllowDuplicates = false; } mAddressSize = addressSize; ImplicitNull = implicitNull; BaseAddress = mAddressSize == Shell.ProcessorSize.x64 ? Values.PtrHandle.Null64 : Values.PtrHandle.Null32; }
/// <summary>Initialize the VAT with a specific handle size and initial table capacity</summary> /// <param name="vaSize">Handle size</param> /// <param name="translationCapacity">The initial table capacity</param> public void VirtualAddressTranslationInitialize(Shell.ProcessorSize vaSize, int translationCapacity = 0) { if (Reader != null) { Reader.VirtualAddressTranslationInitialize(vaSize, translationCapacity); } if (Writer != null) { Writer.VirtualAddressTranslationInitialize(vaSize, translationCapacity); } }
public EndianStream StreamPointer(ref Values.PtrHandle value, Shell.ProcessorSize addressSize) { if (IsReading) { value = Reader.ReadPointer(addressSize); } else if (IsWriting) { Writer.WritePointer(value); } return(this); }
/// <summary>Read a pointer value from the stream with no postprocessing to the result</summary> /// <param name="addressSize">Size of the pointer we're to read</param> /// <returns></returns> public Values.PtrHandle ReadRawPointer(Shell.ProcessorSize addressSize) { var ptr = new Values.PtrHandle(addressSize); if (!ptr.Is64bit) { ptr.u32 = ReadUInt32(); } else { ptr.u64 = ReadUInt64(); } return(ptr); }
public VirtualAddressTranslationStack(Shell.ProcessorSize ptrSize, int capacity) : base(capacity != 0 ? capacity : kDefaultCapacity) { Contract.Requires <ArgumentOutOfRangeException>( ptrSize == Shell.ProcessorSize.x32 || ptrSize == Shell.ProcessorSize.x64); switch (ptrSize) { case Shell.ProcessorSize.x32: mNull = Values.PtrHandle.Null32; break; case Shell.ProcessorSize.x64: mNull = Values.PtrHandle.Null64; break; } mCurrentPA = mNull; }
public ResourceTagHeader(Shell.ProcessorSize pointerSize = Shell.ProcessorSize.x32) { if (pointerSize == Shell.ProcessorSize.x32) { TagMachineNameOffset = Values.PtrHandle.InvalidHandle32; TagUserNameOffset = Values.PtrHandle.InvalidHandle32; CreatorToolCommandLine = Values.PtrHandle.InvalidHandle32; } else { TagMachineNameOffset = Values.PtrHandle.InvalidHandle64; TagUserNameOffset = Values.PtrHandle.InvalidHandle64; CreatorToolCommandLine = Values.PtrHandle.InvalidHandle64; } }
public void Read(KSoft.IO.EndianReader s) { var storage = new StringStorage(); storage.Read(s); Storage = storage; mAddressSize = (Shell.ProcessorSize)s.ReadByte(); ImplicitNull = s.ReadBoolean(); AllowDuplicates = s.ReadBoolean(); s.Seek(sizeof(byte)); var base_addr = new Values.PtrHandle(mAddressSize); base_addr.Read(s); BaseAddress.Read(s); }
/// <summary>Mark a position as a VA</summary> /// <param name="ptrSize">Size of the mark (all zeros) to write</param> /// <returns>Position of the stream before the 'mark' was written</returns> /// <remarks>Up to caller to write VA value later</remarks> public Values.PtrHandle MarkVirtualAddress(Shell.ProcessorSize ptrSize) { var va = PositionPtr; switch (ptrSize) { case Shell.ProcessorSize.x32: Write(uint.MinValue); break; case Shell.ProcessorSize.x64: Write(ulong.MinValue); break; default: throw new Debug.UnreachableException(ptrSize.ToString()); } return(va); }
public static int GetByteCount(Shell.ProcessorSize value) { Contract.Ensures(Contract.Result <int>() >= -1); switch (value) { case Shell.ProcessorSize.x32: return(sizeof(int)); case Shell.ProcessorSize.x64: return(sizeof(long)); default: return(-1); } }
public static int GetBitCount(Shell.ProcessorSize value) { Contract.Ensures(Contract.Result <int>() >= -1); switch (value) { case Shell.ProcessorSize.x32: return(Bits.kInt32BitCount); case Shell.ProcessorSize.x64: return(Bits.kInt64BitCount); default: return(-1); } }
public static void ConvertXmbToXml( string xmlFile, string xmbFile, Shell.EndianFormat endianFormat, Shell.ProcessorSize vaSize) { byte[] file_bytes = File.ReadAllBytes(xmbFile); using (var xmb_ms = new MemoryStream(file_bytes, false)) using (var xmb = new IO.EndianStream(xmb_ms, endianFormat, System.IO.FileAccess.Read)) using (var xml_ms = new MemoryStream(IntegerMath.kMega * 1)) { xmb.StreamMode = FileAccess.Read; ResourceUtils.XmbToXml(xmb, xml_ms, vaSize); using (var xml_fs = File.Create(xmlFile)) xml_ms.WriteTo(xml_fs); } }
/// <summary>Construct an address which is implicity casted based on the size</summary> /// <param name="addressSize">Real size of <paramref name="address"/></param> /// <param name="address">Starting address value</param> public PtrHandle(Shell.ProcessorSize addressSize, ulong address) : this(addressSize == Shell.ProcessorSize.x64, address) { }
private void TransformXmbToXml(byte[] eraFileEntryBuffer, string fullPath, Shell.EndianFormat byteOrder, Shell.ProcessorSize vaSize) { byte[] xmb_buffer; using (var xmb = new ECF.EcfFileXmb()) using (var ms = new System.IO.MemoryStream(eraFileEntryBuffer)) using (var es = new IO.EndianStream(ms, byteOrder, permissions: System.IO.FileAccess.Read)) { es.StreamMode = System.IO.FileAccess.Read; xmb.Serialize(es); xmb_buffer = xmb.FileData; } string xmb_path = fullPath; ResourceUtils.RemoveXmbExtension(ref xmb_path); var context = new Xmb.XmbFileContext() { PointerSize = vaSize, }; using (var ms = new System.IO.MemoryStream(xmb_buffer, false)) using (var s = new IO.EndianReader(ms, byteOrder)) { s.UserData = context; using (var xmbf = new Phoenix.Xmb.XmbFile()) { xmbf.Read(s); xmbf.ToXml(xmb_path); } } }
public VirtualAddressTranslationStack(Shell.ProcessorSize ptrSize) : this(ptrSize, kDefaultCapacity) { }
/// <summary>Get the current position as a <see cref="Data.PtrHandle"/></summary> /// <param name="ptrSize">Pointer size to use for the result handle</param> /// <returns></returns> public Values.PtrHandle GetPositionPtrWithExplicitWidth(Shell.ProcessorSize ptrSize) => new Values.PtrHandle(ptrSize, (ulong)BaseStream.Position);
public static void XmbToXml(IO.EndianStream xmbStream, System.IO.Stream outputStream, Shell.ProcessorSize vaSize) { byte[] xmbBytes; using (var xmb = new ECF.EcfFileXmb()) { xmb.Serialize(xmbStream); xmbBytes = xmb.FileData; } var context = new Xmb.XmbFileContext() { PointerSize = vaSize, }; using (var ms = new System.IO.MemoryStream(xmbBytes, false)) using (var s = new IO.EndianReader(ms, xmbStream.ByteOrder)) { s.UserData = context; using (var xmbf = new Phoenix.Xmb.XmbFile()) { xmbf.Read(s); xmbf.ToXml(outputStream); } } }
public static void XmbToXml(IO.EndianStream xmbStream, System.IO.Stream outputStream, Shell.ProcessorSize vaSize) { ECF.EcfFileXmb.XmbToXml(xmbStream, outputStream, vaSize); }