/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="implementation">Implementation</param> /// <param name="flags">Flags</param> /// <param name="offset">Offset</param> public ManifestResourceUser(UTF8String name, IImplementation implementation, ManifestResourceAttributes flags, uint offset) { this.name = name; this.implementation = implementation; this.attributes = (int)flags; this.offset = offset; }
public ManifestResourceRow(uint offset, ManifestResourceAttributes attributes, uint name, MetadataToken implementation) : this() { Offset = offset; Attributes = attributes; Name = name; Implementation = implementation; }
public void PersistentAttributes() { const ManifestResourceAttributes newAttributes = ManifestResourceAttributes.Private; var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true); var header = assembly.NetDirectory.MetadataHeader; var image = header.LockMetadata(); var resource = CreateDummyResource(); resource.Attributes = newAttributes; image.Assembly.Resources.Add(resource); var mapping = header.UnlockMetadata(); var resourceRow = header.GetStream <TableStream>() .GetTable <ManifestResourceTable>()[(int)(mapping[resource].Rid - 1)]; Assert.Equal(newAttributes, resourceRow.Column2); image = header.LockMetadata(); resource = (ManifestResource)image.ResolveMember(mapping[resource]); Assert.Equal(newAttributes, resource.Attributes); }
private void LoadData(CLIFile pFile) { Offset = pFile.ReadUInt32(); Flags = (ManifestResourceAttributes)pFile.ReadUInt32(); Name = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit)); Implementation.LoadData(pFile); }
public void Read(ClrModuleReader reader) { this.Offset = reader.Binary.ReadUInt32(); this.Flags = (ManifestResourceAttributes)reader.Binary.ReadUInt32(); this.Name = reader.ReadString(); this.Implementation = reader.ReadCodedIndex<Implementation>(); }
/// <summary> /// Creates a new row for the manifest resource metadata table. /// </summary> /// <param name="offset">The byte offset within the referenced file at which the resource record begins. </param> /// <param name="attributes">The attributes associated with this resource.</param> /// <param name="name">The index into the #Strings heap referencing the name of the resource.</param> /// <param name="implementation">The Implementation index (an index into either the File, AssemblyRef or /// ExportedType table) indicating the file that contains the resource data. </param> public ManifestResourceRow(uint offset, ManifestResourceAttributes attributes, uint name, uint implementation) { Offset = offset; Attributes = attributes; Name = name; Implementation = implementation; }
/// <summary> /// Creates a new embedded manifest resource. /// </summary> /// <param name="name">The name of the repository.</param> /// <param name="attributes">The attributes of the resource.</param> /// <param name="data">The embedded resource data.</param> public ManifestResource(string name, ManifestResourceAttributes attributes, ISegment data) : this(new MetadataToken(TableIndex.ManifestResource, 0)) { Name = name; Attributes = attributes; EmbeddedDataSegment = data; }
public LinkedResource(string name, ManifestResourceAttributes flags, string resourceFileName, byte[] hash) : base(name, flags) { this.resourceFileName = name; this.hash = hash; this.hashSource = LinkedResourceHashSource.Explicit; }
public void Read(ClrModuleReader reader) { this.Offset = reader.Binary.ReadUInt32(); this.Flags = (ManifestResourceAttributes)reader.Binary.ReadUInt32(); this.Name = reader.ReadString(); this.Implementation = reader.ReadCodedIndex <Implementation>(); }
/// <summary> /// Initializes a new instance of the <see cref="ManifestResourceRow" /> struct. /// </summary> /// <param name="offset">The offset.</param> /// <param name="flags">The flags.</param> /// <param name="nameString">Index of the name string.</param> /// <param name="implementation">The implementation.</param> public ManifestResourceRow(uint offset, ManifestResourceAttributes flags, HeapIndexToken nameString, Token implementation) { Offset = offset; Flags = flags; NameString = nameString; Implementation = implementation; }
/// <summary> /// Creates a new external manifest resource. /// </summary> /// <param name="name">The name of the resource</param> /// <param name="attributes">The attributes of the resource.</param> /// <param name="implementation">The location of the resource data.</param> /// <param name="offset">The offset within the file referenced by <paramref name="implementation"/> where the data starts.</param> public ManifestResource(string name, ManifestResourceAttributes attributes, IImplementation implementation, uint offset) : this(new MetadataToken(TableIndex.ManifestResource, 0)) { Name = name; Attributes = attributes; Implementation = implementation; Offset = offset; }
/// <summary> /// Initializes a new instance of the <see cref="ManifestResourceRow"/> struct. /// </summary> /// <param name="offset">The offset.</param> /// <param name="flags">The flags.</param> /// <param name="nameStringIndex">Index of the name string.</param> /// <param name="implementationTableIdx">The implementation table idx.</param> public ManifestResourceRow(uint offset, ManifestResourceAttributes flags, TokenTypes nameStringIndex, TokenTypes implementationTableIdx) { _offset = offset; _flags = flags; _nameStringIdx = nameStringIndex; _implementationTableIdx = implementationTableIdx; }
/// <summary> /// Initializes a new instance of the <see cref="ManifestResourceRow"/> struct. /// </summary> /// <param name="offset">The offset.</param> /// <param name="flags">The flags.</param> /// <param name="nameStringIndex">Index of the name string.</param> /// <param name="implementation">The implementation table idx.</param> public ManifestResourceRow(uint offset, ManifestResourceAttributes flags, HeapIndexToken nameStringIndex, Token implementation) { _offset = offset; _flags = flags; _nameStringIdx = nameStringIndex; _implementation = implementation; }
internal ResourceElementSetTreeNode(ModuleDef module, string name, ManifestResourceAttributes flags) : base(new EmbeddedResource(name, new byte[0], flags)) { this.module = module; RegenerateEmbeddedResource(module); this.resourceElementSet = dnlib.DotNet.Resources.ResourceReader.Read(module, ((EmbeddedResource)r).Data); this.LazyLoading = true; }
public ManifestResource(string name, ManifestResourceAttributes attributes, byte[] data) : base(null, new MetadataToken(MetadataTokenType.ManifestResource), new MetadataRow <uint, uint, uint, uint>()) { Attributes = attributes; _name = new LazyValue <string>(name); _data = new LazyValue <byte[]>(data); _implementation = new LazyValue <IImplementation>(); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of resource</param> /// <param name="asmRef">Assembly reference</param> /// <param name="flags">Resource flags</param> public AssemblyLinkedResource(UTF8String name, AssemblyRef asmRef, ManifestResourceAttributes flags) : base(name, flags) { if (asmRef == null) { throw new ArgumentNullException("asmRef"); } }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of resource</param> /// <param name="dataStream">Resource data</param> /// <param name="flags">Resource flags</param> public EmbeddedResource(UTF8String name, IImageStream dataStream, ManifestResourceAttributes flags) : base(name, flags) { if (dataStream == null) { throw new ArgumentNullException("dataStream"); } this.dataStream = dataStream; }
public static void ReplaceResource(this AssemblyDefinition @this, string resName, byte[] newData) { Resource resourceToReplace = @this.MainModule.Resources.Single(r => r.Name.Equals(resName, StringComparison.OrdinalIgnoreCase)); ManifestResourceAttributes attribs = resourceToReplace.Attributes; int index = @this.MainModule.Resources.IndexOf(resourceToReplace); @this.MainModule.Resources.RemoveAt(index); @this.MainModule.Resources.Insert(index, new EmbeddedResource(resName, attribs, newData)); }
public ManifestResourceRow CreateManifestResourceRow(uint _offset, ManifestResourceAttributes _flags, uint _name, MetadataToken _implementation) { ManifestResourceRow row = new ManifestResourceRow(); row.Offset = _offset; row.Flags = _flags; row.Name = _name; row.Implementation = _implementation; return(row); }
internal static string ToString(ManifestResourceAttributes flags) { var sb = new StringBuilder(); switch ((flags & ManifestResourceAttributes.VisibilityMask)) { case ManifestResourceAttributes.Public: sb.Append("Public"); break; case ManifestResourceAttributes.Private: sb.Append("Private"); break; default: sb.Append("Visibility_UNKNOWN"); break; } return sb.ToString(); }
void AddManifestResource(uint offset, string name, ManifestResourceAttributes flags, MetadataToken impl) { ManifestResourceTable mrTable = m_tableWriter.GetManifestResourceTable(); ManifestResourceRow mrRow = m_rowWriter.CreateManifestResourceRow( offset, flags, m_mdWriter.AddString(name), impl); mrTable.Rows.Add(mrRow); }
/// <summary> /// Modify <see cref="attributes"/> property: <see cref="attributes"/> = /// (<see cref="attributes"/> & <paramref name="andMask"/>) | <paramref name="orMask"/>. /// </summary> /// <param name="andMask">Value to <c>AND</c></param> /// <param name="orMask">Value to OR</param> private void ModifyAttributes(ManifestResourceAttributes andMask, ManifestResourceAttributes orMask) { #if THREAD_SAFE int origVal, newVal; do { origVal = attributes; newVal = (origVal & (int)andMask) | (int)orMask; } while (Interlocked.CompareExchange(ref attributes, newVal, origVal) != origVal); #else attributes = (attributes & (int)andMask) | (int)orMask; #endif }
/// <summary> /// Initialises a new instance of the ManifestResourceMetadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of this current row</param> public ManifestResourceMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfImplementationIndex = resolver.GetSizeOfIndex(CodedIndexes.Implementation); byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); _offset = BitConverter.ToUInt32(contents, offset.Shift(4)); _flags = (ManifestResourceAttributes)BitConverter.ToUInt32(contents, offset.Shift(4)); _name = new StringIndex(contents, sizeOfStringIndex, offset); _implementation = resolver.Resolve( CodedIndexes.Implementation, FieldReader.ToUInt32(contents, offset.Shift(sizeOfImplementationIndex), sizeOfImplementationIndex) ); }
internal static string ToString(ManifestResourceAttributes flags) { var sb = new StringBuilder(); switch ((flags & ManifestResourceAttributes.VisibilityMask)) { case ManifestResourceAttributes.Public: sb.Append("Public"); break; case ManifestResourceAttributes.Private: sb.Append("Private"); break; default: sb.Append("Visibility_UNKNOWN"); break; } return(sb.ToString()); }
public ResourceOptions(Resource resource) { this.ResourceType = resource.ResourceType; this.Name = resource.Name ?? UTF8String.Empty; this.Attributes = resource.Attributes; switch (resource.ResourceType) { case ResourceType.Embedded: break; case ResourceType.AssemblyLinked: this.Assembly = ((AssemblyLinkedResource)resource).Assembly; break; case ResourceType.Linked: this.File = ((LinkedResource)resource).File; break; default: throw new InvalidOperationException(); } }
public ResourceOptions(Resource resource) { ResourceType = resource.ResourceType; Name = resource.Name ?? UTF8String.Empty; Attributes = resource.Attributes; switch (resource.ResourceType) { case ResourceType.Embedded: break; case ResourceType.AssemblyLinked: Assembly = ((AssemblyLinkedResource)resource).Assembly; break; case ResourceType.Linked: File = ((LinkedResource)resource).File; break; default: throw new InvalidOperationException(); } }
public AssemblyLinkedResource (string name, ManifestResourceAttributes flags, AssemblyNameReference reference) : base (name, flags) { this.reference = reference; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of resource</param> /// <param name="data">Resource data</param> /// <param name="flags">Resource flags</param> public EmbeddedResource(UTF8String name, byte[] data, ManifestResourceAttributes flags) : this(name, new MemoryImageStream(0, data, 0, data.Length), flags) { }
public AssemblyLinkedResource(string name, ManifestResourceAttributes flags, AssemblyNameReference asmRef) : base(name, flags) { m_asmRef = asmRef; }
public LinkedResource(string name, ManifestResourceAttributes flags) : base(name, flags) { }
public EmbeddedResource(string name, ManifestResourceAttributes attributes, Stream stream) : base(name, attributes) { this.stream = stream; }
internal Resource (string name, ManifestResourceAttributes attributes) { this.name = name; this.attributes = (uint) attributes; }
public EmbeddedResource(string name, ManifestResourceAttributes attributes, byte [] data) : base(name, attributes) { this.data = data; }
void AddManifestResource (uint offset, string name, ManifestResourceAttributes flags, MetadataToken impl) { ManifestResourceTable mrTable = m_tableWriter.GetManifestResourceTable (); ManifestResourceRow mrRow = m_rowWriter.CreateManifestResourceRow ( offset, flags, m_mdWriter.AddString (name), impl); mrTable.Rows.Add (mrRow); }
public unsafe static bool GetManifestResourceProps(IMetaDataAssemblyImport mdai, uint token, out uint offset, out uint implementation, out ManifestResourceAttributes attrs) { offset = 0; implementation = 0; attrs = 0; if (mdai == null) return false; uint tkImplementation, dwOffset, dwResourceFlags; int hr = mdai.GetManifestResourceProps(token, IntPtr.Zero, 0, IntPtr.Zero, new IntPtr(&tkImplementation), new IntPtr(&dwOffset), new IntPtr(&dwResourceFlags)); if (hr != 0) return false; implementation = tkImplementation; offset = dwOffset; attrs = (ManifestResourceAttributes)dwResourceFlags; return true; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="implementation">Implementation</param> /// <param name="flags">Flags</param> /// <param name="offset">Offset</param> public ManifestResourceUser(UTF8String name, IImplementation implementation, ManifestResourceAttributes flags, uint offset) { this.name = name; this.implementation = implementation; this.flags = flags; this.offset = offset; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="implementation">Implementation</param> /// <param name="flags">Flags</param> public ManifestResourceUser(UTF8String name, IImplementation implementation, ManifestResourceAttributes flags) : this(name, implementation, flags, 0) { }
public ManifestResource(string name, ManifestResourceAttributes attributes, MetaDataMember implementation, uint offset) : base(new MetaDataRow(offset, (uint)attributes, 0U, 0U)) { this._name = name; this._implementation = implementation; }
internal EmbeddedResource(uint offset, ManifestResourceAttributes attributes, string name) { this.Offset = offset; this.Attributes = attributes; this.Name = name; }
public LinkedResource (string name, ManifestResourceAttributes flags) : base (name, flags) { }
internal EmbeddedResource(string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader) : base(name, attributes) { this.offset = offset; this.reader = reader; }
public LinkedResource (string name, ManifestResourceAttributes flags, string file) : base (name, flags) { this.file = file; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of resource</param> /// <param name="asmRef">Assembly reference</param> /// <param name="flags">Resource flags</param> public AssemblyLinkedResource(UTF8String name, AssemblyRef asmRef, ManifestResourceAttributes flags) : base(name, flags) { if (asmRef == null) throw new ArgumentNullException("asmRef"); this.asmRef = asmRef; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of resource</param> /// <param name="file">The file</param> /// <param name="flags">Resource flags</param> public LinkedResource(UTF8String name, FileDef file, ManifestResourceAttributes flags) : base(name, flags) { this.file = file; }
internal Resource(string name, ManifestResourceAttributes flags) { m_name = name; m_flags = flags; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of resource</param> /// <param name="dataStream">Resource data</param> /// <param name="flags">Resource flags</param> public EmbeddedResource(UTF8String name, IImageStream dataStream, ManifestResourceAttributes flags) : base(name, flags) { if (dataStream == null) throw new ArgumentNullException("dataStream"); this.dataStream = dataStream; }
internal Resource(string name, ManifestResourceAttributes attributes) { this.name = name; this.attributes = (uint)attributes; }
public void AddManifestResource( ManifestResourceAttributes attributes, StringHandle name, EntityHandle implementation, long offset) { _manifestResourceTable.Add(new ManifestResourceRow { Flags = (uint)attributes, Name = name, Implementation = implementation.IsNil ? 0 : (uint)CodedIndex.ToImplementation(implementation), Offset = (uint)offset }); }
public ManifestResourceRow CreateManifestResourceRow(uint _offset, ManifestResourceAttributes _flags, uint _name, MetadataToken _implementation) { ManifestResourceRow row = new ManifestResourceRow (); row.Offset = _offset; row.Flags = _flags; row.Name = _name; row.Implementation = _implementation; return row; }
public LinkedResource(string name, ManifestResourceAttributes flags, string file) : base(name, flags) { this.file = file; }
public EmbeddedResource (string name, ManifestResourceAttributes flags, byte [] data) : base (name, flags) { m_data = data; }
/**<summary>Repacks the localization files into terraria.</summary>*/ public static bool Repack() { // Backup the file first if (!File.Exists(BackupPath)) { File.Copy(ExePath, BackupPath, false); } var resolver = new EmbeddedAssemblyResolver(); var readerParameters = new ReaderParameters { AssemblyResolver = resolver, ReadingMode = ReadingMode.Deferred, //ReadSymbols = false, ReadWrite = true, // New in updated Mono.Cecil version }; var writerParameters = new WriterParameters { //WriteSymbols = false, }; bool filesFound = false; // New usage of stream (combined with newer version of Mono.Cecil), // allows us to do everything in one open-close), no more waiting till a file is "no longer in use" using (Stream stream = File.Open(ExePath, FileMode.Open, FileAccess.ReadWrite)) { var AsmDefinition = AssemblyDefinition.ReadAssembly(stream, readerParameters); var ModDefinition = AsmDefinition.MainModule; List <EmbeddedResource> dllResources = new List <EmbeddedResource>(); for (int i = 0; i < ModDefinition.Resources.Count; i++) { EmbeddedResource er = ModDefinition.Resources[i] as EmbeddedResource; if (er == null) { continue; } //TODO: In the future these could be loosened to include non-json files, etc. // Step 1: Ignore extension requirements // Step 2: Only check for "Terraria.Localization." prefix, the "Content." // part seems too specific. Naturally this must also be accounted // for elsewhere in this program's code. if (er.Name.StartsWith("Terraria.Localization.Content.") && er.Name.EndsWith(".json")) { string path = Path.Combine(InputDirectory, er.Name); if (File.Exists(path)) { // Replace the resource with the new user-supplied one ManifestResourceAttributes attributes = er.Attributes; ModDefinition.Resources.RemoveAt(i); er = new EmbeddedResource(er.Name, er.Attributes, File.ReadAllBytes(path)); ModDefinition.Resources.Insert(i, er); filesFound = true; } } // NOTE: as of Terraria 1.4, all dlls are prefixed with "Terraria.Libraries." // and end with ".dll", Terraria resolves these at runtime by checking if the // resource name ends with the assembly reference name. // I don't recall if Terraria prefixed these dll names in 1.3.5 or earlier, // so we'll assume all dlls are potential candidates. //else if (er.Name.StartsWith("Terraria.Libraries") && er.Name.EndsWith(".dll")) { else if (er.Name.EndsWith(".dll")) { dllResources.Add(er); } } if (filesFound) { for (int i = 0; i < dllResources.Count; i++) { resolver.AddPreloadedResource(dllResources[i].Name, dllResources[i].GetResourceData()); } // Do not include the filename? We're writing to the same place, so // this may help tell Mono.Cecil to avoid any unnecessary rewrites that // may require assembly reference resolution. // In anycase we, still preload embedded references as a safety. AsmDefinition.Write(writerParameters); //AsmDefinition.Write(ExePath, writerParameters); // Wait for the exe to be closed by AsmDefinition.Write() //Thread.Sleep(400); // Mono.Cecil.ImageWriter will only add LargeAddressAware characteristic for 64-bit assemblies. // Terraria lists itself as a 32-bit assembly AND as large-address aware. This is different // from the alternative "32-bit preferred" setting. As a result we lose this vital flag. //https://github.com/jbevain/cecil/blob/f6a871b023fe10015be0e97955143aedc1232110/Mono.Cecil.PE/ImageWriter.cs#L199-L203 // We're now passing the same still-open stream that was just written to so that we can make our // changes without waiting for the file to no longer "be in use"... potentially being scanned by antivirus? who knows. IL.MakeLargeAddressAware(stream); } } return(filesFound); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="flags">flags</param> protected Resource(UTF8String name, ManifestResourceAttributes flags) { this.name = name; this.flags = flags; }