コード例 #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;
 }
コード例 #2
0
 public ManifestResourceRow(uint offset, ManifestResourceAttributes attributes, uint name, MetadataToken implementation) : this()
 {
     Offset         = offset;
     Attributes     = attributes;
     Name           = name;
     Implementation = implementation;
 }
コード例 #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);
        }
コード例 #4
0
		private void LoadData(CLIFile pFile)
		{
			Offset = pFile.ReadUInt32();
			Flags = (ManifestResourceAttributes)pFile.ReadUInt32();
			Name = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit));
			Implementation.LoadData(pFile);
		}
コード例 #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>();
 }
コード例 #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;
 }
コード例 #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;
 }
コード例 #8
0
ファイル: LinkedResource.cs プロジェクト: poizan42/cecil
 public LinkedResource(string name, ManifestResourceAttributes flags, string resourceFileName, byte[] hash)
     : base(name, flags)
 {
     this.resourceFileName = name;
     this.hash = hash;
     this.hashSource = LinkedResourceHashSource.Explicit;
 }
コード例 #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>();
 }
コード例 #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;
 }
コード例 #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;
        }
コード例 #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;
 }
コード例 #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;
 }
コード例 #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;
 }
コード例 #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;
 }
コード例 #16
0
ファイル: ManifestResource.cs プロジェクト: micax/AsmResolver
 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>();
 }
コード例 #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;
 }
コード例 #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");
     }
 }
コード例 #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;
        }
コード例 #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;
 }
コード例 #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));
        }
コード例 #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);
        }
コード例 #23
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();
		}
コード例 #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);
        }
コード例 #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
        }
コード例 #26
0
        /// <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)
                );
        }
コード例 #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());
        }
コード例 #28
0
ファイル: ResourceOptions.cs プロジェクト: arkanoid1/dnSpy
		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();
			}
		}
コード例 #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();
            }
        }
コード例 #30
0
		public AssemblyLinkedResource (string name, ManifestResourceAttributes flags, AssemblyNameReference reference)
			: base (name, flags)
		{
			this.reference = reference;
		}
コード例 #31
0
ファイル: Resource.cs プロジェクト: EmilZhou/dnlib
		/// <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) {
		}
コード例 #32
0
 public AssemblyLinkedResource(string name, ManifestResourceAttributes flags,
                               AssemblyNameReference asmRef) : base(name, flags)
 {
     m_asmRef = asmRef;
 }
コード例 #33
0
 public LinkedResource(string name, ManifestResourceAttributes flags)
     : base(name, flags)
 {
 }
コード例 #34
0
ファイル: EmbeddedResource.cs プロジェクト: isoundy000/ETGame
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, Stream stream) :
     base(name, attributes)
 {
     this.stream = stream;
 }
コード例 #35
0
ファイル: Resource.cs プロジェクト: 0xb1dd1e/cecil
		internal Resource (string name, ManifestResourceAttributes attributes)
		{
			this.name = name;
			this.attributes = (uint) attributes;
		}
コード例 #36
0
ファイル: EmbeddedResource.cs プロジェクト: jbevain/cecil
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, byte [] data)
     : base(name, attributes)
 {
     this.data = data;
 }
コード例 #37
0
ファイル: StructureWriter.cs プロジェクト: nobled/mono
		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);
		}
コード例 #38
0
ファイル: MDAPI.cs プロジェクト: arkanoid1/dnSpy
		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;
		}
コード例 #39
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.flags = flags;
			this.offset = offset;
		}
コード例 #40
0
		/// <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) {
		}
コード例 #41
0
ファイル: ManifestResource.cs プロジェクト: Rex-Hays/GNIDA
 public ManifestResource(string name, ManifestResourceAttributes attributes, MetaDataMember implementation, uint offset)
     : base(new MetaDataRow(offset, (uint)attributes, 0U, 0U))
 {
     this._name = name;
     this._implementation = implementation;
 }
コード例 #42
0
ファイル: EmbeddedResource.cs プロジェクト: CAPCHIK/roslyn
 internal EmbeddedResource(uint offset, ManifestResourceAttributes attributes, string name)
 {
     this.Offset = offset;
     this.Attributes = attributes;
     this.Name = name;
 }
コード例 #43
0
		public LinkedResource (string name, ManifestResourceAttributes flags)
			: base (name, flags)
		{
		}
コード例 #44
0
ファイル: EmbeddedResource.cs プロジェクト: jbevain/cecil
 internal EmbeddedResource(string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader)
     : base(name, attributes)
 {
     this.offset = offset;
     this.reader = reader;
 }
コード例 #45
0
		public LinkedResource (string name, ManifestResourceAttributes flags, string file)
			: base (name, flags)
		{
			this.file = file;
		}
コード例 #46
0
ファイル: Resource.cs プロジェクト: EmilZhou/dnlib
		/// <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;
		}
コード例 #47
0
ファイル: EmbeddedResource.cs プロジェクト: jbevain/cecil
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, Stream stream)
     : base(name, attributes)
 {
     this.stream = stream;
 }
コード例 #48
0
ファイル: Resource.cs プロジェクト: EmilZhou/dnlib
		/// <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;
		}
コード例 #49
0
 internal Resource(string name, ManifestResourceAttributes flags)
 {
     m_name  = name;
     m_flags = flags;
 }
コード例 #50
0
ファイル: Resource.cs プロジェクト: EmilZhou/dnlib
		/// <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;
		}
コード例 #51
0
 internal Resource(string name, ManifestResourceAttributes attributes)
 {
     this.name       = name;
     this.attributes = (uint)attributes;
 }
コード例 #52
0
 public AssemblyLinkedResource(string name, ManifestResourceAttributes flags,
     AssemblyNameReference asmRef)
     : base(name, flags)
 {
     m_asmRef = asmRef;
 }
コード例 #53
0
ファイル: EmbeddedResource.cs プロジェクト: isoundy000/ETGame
 public EmbeddedResource(string name, ManifestResourceAttributes attributes, byte [] data) :
     base(name, attributes)
 {
     this.data = data;
 }
コード例 #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
     });
 }
コード例 #55
0
ファイル: EmbeddedResource.cs プロジェクト: isoundy000/ETGame
 internal EmbeddedResource(string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader)
     : base(name, attributes)
 {
     this.offset = offset;
     this.reader = reader;
 }
コード例 #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;
 }
コード例 #57
0
 public LinkedResource(string name, ManifestResourceAttributes flags, string file)
     : base(name, flags)
 {
     this.file = file;
 }
コード例 #58
0
		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);
        }
コード例 #60
0
ファイル: Resource.cs プロジェクト: EmilZhou/dnlib
		/// <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;
		}