Exemplo n.º 1
0
        /// <summary>
        /// Creates the .NET metadata chunks (constants, method bodies, .NET resources,
        /// the metadata, and Win32 resources)
        /// </summary>
        /// <param name="module"></param>
        protected void CreateMetaDataChunks(ModuleDef module)
        {
            constants    = new UniqueChunkList <ByteArrayChunk>();
            methodBodies = new MethodBodyChunks(TheOptions.ShareMethodBodies);
            netResources = new NetResources(DEFAULT_NETRESOURCES_ALIGNMENT);

            metaData          = MetaData.Create(module, constants, methodBodies, netResources, TheOptions.MetaDataOptions);
            metaData.Logger   = TheOptions.MetaDataLogger ?? this;
            metaData.Listener = this;

            // StrongNamePublicKey is used if the user wants to override the assembly's
            // public key or when enhanced strong naming the assembly.
            var pk = TheOptions.StrongNamePublicKey;

            if (pk != null)
            {
                metaData.AssemblyPublicKey = pk.CreatePublicKey();
            }
            else if (TheOptions.StrongNameKey != null)
            {
                metaData.AssemblyPublicKey = TheOptions.StrongNameKey.PublicKey;
            }

            var w32Resources = GetWin32Resources();

            if (w32Resources != null)
            {
                win32Resources = new Win32ResourcesChunk(w32Resources);
            }
        }
		/// <summary>
		/// Creates the .NET metadata chunks (constants, method bodies, .NET resources,
		/// the metadata, and Win32 resources)
		/// </summary>
		/// <param name="module"></param>
		protected void CreateMetaDataChunks(ModuleDef module) {
			constants = new UniqueChunkList<ByteArrayChunk>();
			methodBodies = new MethodBodyChunks(TheOptions.ShareMethodBodies);
			netResources = new NetResources(DEFAULT_NETRESOURCES_ALIGNMENT);

			metaData = MetaData.Create(module, constants, methodBodies, netResources, TheOptions.MetaDataOptions);
			metaData.Logger = TheOptions.MetaDataLogger ?? this;
			metaData.Listener = this;

			// StrongNamePublicKey is used if the user wants to override the assembly's
			// public key or when enhanced strong naming the assembly.
			var pk = TheOptions.StrongNamePublicKey;
			if (pk != null)
				metaData.AssemblyPublicKey = pk.CreatePublicKey();
			else if (TheOptions.StrongNameKey != null)
				metaData.AssemblyPublicKey = TheOptions.StrongNameKey.PublicKey;

			var w32Resources = GetWin32Resources();
			if (w32Resources != null)
				win32Resources = new Win32ResourcesChunk(w32Resources);
		}
Exemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="module">Module</param>
 /// <param name="constants">Constants list</param>
 /// <param name="methodBodies">Method bodies list</param>
 /// <param name="netResources">.NET resources list</param>
 /// <param name="options">Options</param>
 public NormalMetaData(ModuleDef module, UniqueChunkList <ByteArrayChunk> constants, MethodBodyChunks methodBodies, NetResources netResources, MetaDataOptions options)
     : base(module, constants, methodBodies, netResources, options)
 {
 }
Exemplo n.º 4
0
		void CreateSections(ModuleWriterBase writer) {
			var nameBuffer = new byte[8];
			nameBuffer[0] = (byte)(name1 >> 0);
			nameBuffer[1] = (byte)(name1 >> 8);
			nameBuffer[2] = (byte)(name1 >> 16);
			nameBuffer[3] = (byte)(name1 >> 24);
			nameBuffer[4] = (byte)(name2 >> 0);
			nameBuffer[5] = (byte)(name2 >> 8);
			nameBuffer[6] = (byte)(name2 >> 16);
			nameBuffer[7] = (byte)(name2 >> 24);
			var newSection = new PESection(Encoding.ASCII.GetString(nameBuffer), 0xE0000040);
			writer.Sections.Insert(0, newSection); // insert first to ensure proper RVA

			uint alignment;

			alignment = writer.TextSection.Remove(writer.MetaData).Value;
			writer.TextSection.Add(writer.MetaData, alignment);

			alignment = writer.TextSection.Remove(writer.NetResources).Value;
			writer.TextSection.Add(writer.NetResources, alignment);

			alignment = writer.TextSection.Remove(writer.Constants).Value;
			newSection.Add(writer.Constants, alignment);

			// move some PE parts to separate section to prevent it from being hashed
			var peSection = new PESection("", 0x60000020);
			bool moved = false;
			if (writer.StrongNameSignature != null) {
				alignment = writer.TextSection.Remove(writer.StrongNameSignature).Value;
				peSection.Add(writer.StrongNameSignature, alignment);
				moved = true;
			}
			var managedWriter = writer as ModuleWriter;
			if (managedWriter != null) {
				if (managedWriter.ImportAddressTable != null) {
					alignment = writer.TextSection.Remove(managedWriter.ImportAddressTable).Value;
					peSection.Add(managedWriter.ImportAddressTable, alignment);
					moved = true;
				}
				if (managedWriter.StartupStub != null) {
					alignment = writer.TextSection.Remove(managedWriter.StartupStub).Value;
					peSection.Add(managedWriter.StartupStub, alignment);
					moved = true;
				}
			}
			if (moved)
				writer.Sections.Add(peSection);

			// move encrypted methods
			var encryptedChunk = new MethodBodyChunks(writer.TheOptions.ShareMethodBodies);
			newSection.Add(encryptedChunk, 4);
			foreach (MethodDef method in methods) {
				if (!method.HasBody)
					continue;
				MethodBody body = writer.MetaData.GetMethodBody(method);
				bool ok = writer.MethodBodies.Remove(body);
				encryptedChunk.Add(body);
			}

			// padding to prevent bad size due to shift division
			newSection.Add(new ByteArrayChunk(new byte[4]), 4);
		}
Exemplo n.º 5
0
 public NormalMetaData(ModuleDef module, UniqueChunkList <ByteArrayChunk> constants, MethodBodyChunks methodBodies, NetResources netResources, MetaDataOptions options, DebugMetaDataKind debugKind, bool isStandaloneDebugMetadata)
     : base(module, constants, methodBodies, netResources, options, debugKind, isStandaloneDebugMetadata)
 {
 }
Exemplo n.º 6
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="module">Module</param>
		/// <param name="constants">Constants list</param>
		/// <param name="methodBodies">Method bodies list</param>
		/// <param name="netResources">.NET resources list</param>
		/// <param name="options">Options</param>
		public NormalMetaData(ModuleDef module, UniqueChunkList<ByteArrayChunk> constants, MethodBodyChunks methodBodies, NetResources netResources, MetaDataOptions options)
			: base(module, constants, methodBodies, netResources, options) {
		}