Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
 public ManifestResourceRow(uint offset, ManifestResourceAttributes attributes, uint name, MetadataToken implementation) : this()
 {
     Offset         = offset;
     Attributes     = attributes;
     Name           = name;
     Implementation = implementation;
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
		private void LoadData(CLIFile pFile)
		{
			Offset = pFile.ReadUInt32();
			Flags = (ManifestResourceAttributes)pFile.ReadUInt32();
			Name = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit));
			Implementation.LoadData(pFile);
		}
Exemplo n.º 5
0
 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>();
 }
Exemplo n.º 6
0
 /// <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;
 }
Exemplo n.º 7
0
 /// <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;
 }
Exemplo n.º 8
0
 public LinkedResource(string name, ManifestResourceAttributes flags, string resourceFileName, byte[] hash)
     : base(name, flags)
 {
     this.resourceFileName = name;
     this.hash = hash;
     this.hashSource = LinkedResourceHashSource.Explicit;
 }
Exemplo n.º 9
0
 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>();
 }
Exemplo n.º 10
0
 /// <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;
 }
Exemplo n.º 11
0
        /// <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;
        }
Exemplo n.º 12
0
 /// <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;
 }
Exemplo n.º 13
0
 /// <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;
 }
Exemplo n.º 14
0
 /// <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;
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
 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>();
 }
Exemplo n.º 17
0
 /// <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;
 }
Exemplo n.º 18
0
 /// <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");
     }
 }
Exemplo n.º 19
0
        /// <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;
        }
Exemplo n.º 20
0
 /// <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;
 }
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 22
0
        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();
		}
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Modify <see cref="attributes"/> property: <see cref="attributes"/> =
        /// (<see cref="attributes"/> &amp; <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)
                );
        }
Exemplo n.º 27
0
        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());
        }
Exemplo n.º 28
0
		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();
			}
		}
Exemplo n.º 29
0
        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;
		}
Exemplo n.º 31
0
		/// <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) {
		}
Exemplo n.º 32
0
 public AssemblyLinkedResource(string name, ManifestResourceAttributes flags,
                               AssemblyNameReference asmRef) : base(name, flags)
 {
     m_asmRef = asmRef;
 }
 public LinkedResource(string name, ManifestResourceAttributes flags)
     : base(name, flags)
 {
 }
Exemplo n.º 34
0
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, Stream stream) :
     base(name, attributes)
 {
     this.stream = stream;
 }
Exemplo n.º 35
0
		internal Resource (string name, ManifestResourceAttributes attributes)
		{
			this.name = name;
			this.attributes = (uint) attributes;
		}
Exemplo n.º 36
0
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, byte [] data)
     : base(name, attributes)
 {
     this.data = data;
 }
Exemplo n.º 37
0
		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);
		}
Exemplo n.º 38
0
		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) {
		}
Exemplo n.º 41
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;
 }
Exemplo n.º 42
0
 internal EmbeddedResource(uint offset, ManifestResourceAttributes attributes, string name)
 {
     this.Offset = offset;
     this.Attributes = attributes;
     this.Name = name;
 }
Exemplo n.º 43
0
		public LinkedResource (string name, ManifestResourceAttributes flags)
			: base (name, flags)
		{
		}
Exemplo n.º 44
0
 internal EmbeddedResource(string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader)
     : base(name, attributes)
 {
     this.offset = offset;
     this.reader = reader;
 }
Exemplo n.º 45
0
		public LinkedResource (string name, ManifestResourceAttributes flags, string file)
			: base (name, flags)
		{
			this.file = file;
		}
Exemplo n.º 46
0
		/// <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;
		}
Exemplo n.º 47
0
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, Stream stream)
     : base(name, attributes)
 {
     this.stream = stream;
 }
Exemplo n.º 48
0
		/// <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;
 }
Exemplo n.º 50
0
		/// <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;
		}
Exemplo n.º 51
0
 internal Resource(string name, ManifestResourceAttributes attributes)
 {
     this.name       = name;
     this.attributes = (uint)attributes;
 }
 public AssemblyLinkedResource(string name, ManifestResourceAttributes flags,
     AssemblyNameReference asmRef)
     : base(name, flags)
 {
     m_asmRef = asmRef;
 }
Exemplo n.º 53
0
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, byte [] data) :
     base(name, attributes)
 {
     this.data = data;
 }
Exemplo n.º 54
0
 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
     });
 }
Exemplo n.º 55
0
 internal EmbeddedResource(string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader)
     : base(name, attributes)
 {
     this.offset = offset;
     this.reader = reader;
 }
Exemplo n.º 56
0
 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);
        }
Exemplo n.º 60
0
		/// <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;
		}