Beispiel #1
0
        private void AddNativeImage(string entryName, Stream content, PeHeader header)
        {
            if (!header.Is32BitHeader)
            {
                throw new PackException("Native images must be compiled for x86");
            }

            var description = new NativeImageDescription
            {
                EntryName = entryName,
                ImageName = Path.GetFileNameWithoutExtension(entryName)
            };

            _index.NativeImages.Add(description);

            AddFileRaw(entryName, content);
        }
Beispiel #2
0
        /// <summary>
        ///     Adds a .NET assembly to the plugin archive.
        /// </summary>
        /// <param name="entryName">The relative name of the resulting file in the archive</param>
        /// <param name="content"></param>
        /// <param name="header"></param>
        private Assembly AddAssembly(string entryName, Stream content, PeHeader header)
        {
            if (!header.Is32BitHeader)
            {
                throw new PackException("Assemblies must be compiled for x86 or AnyCPU");
            }

            byte[] rawAssembly;
            var    assembly        = LoadAssemblyFrom(content, out rawAssembly);
            var    targetFramework = assembly.GetCustomAttribute <TargetFrameworkAttribute>();
            var    version         = ParseVersion(targetFramework);

            // This attribute has been added with .NET 4.0. Tailviewer should obviously
            // support adding assemblies which target older .NET frameworks where this attribute
            // is obviously missing and therefore we will tolerate assemblies without it.
            if (version != null)
            {
                if (version > new Version(4, 5, 2))
                {
                    throw new PackException("Assemblies may only target frameworks of up to .NET 4.5.2");
                }
            }

            var assemblyDescription = AssemblyDescription.FromAssembly(assembly);

            assemblyDescription.EntryName = entryName;
            AddFile(entryName, rawAssembly);
            _index.Assemblies.Add(assemblyDescription);

            foreach (var dependency in assemblyDescription.Dependencies)
            {
                var assemblyName = new AssemblyName(dependency.FullName);
                if (ShouldAddDependency(assemblyName))
                {
                    var fileName = Path.Combine(_currentDirectory, string.Format("{0}.exe", assemblyName.Name));
                    if (!File.Exists(fileName))
                    {
                        fileName = Path.Combine(_currentDirectory, string.Format("{0}.dll", assemblyName.Name));
                    }
                    var dependencyEntryName = Path.GetFileName(fileName);
                    AddAssembly(dependencyEntryName, fileName);
                }
            }

            return(assembly);
        }
        public static IMAGE_IMPORT_DESCRIPTOR[] GetImportDescriptors(this PeHeader hdr, IntPtr baseAddress)
        {
            var importTable = hdr.OptionalHeader32.ImportTable;
            var addr        = (int)importTable.VirtualAddress;
            var list        = new List <IMAGE_IMPORT_DESCRIPTOR>();

            while (true)
            {
                var importDesc = Marshal.PtrToStructure <IMAGE_IMPORT_DESCRIPTOR>(baseAddress + addr);
                if (importDesc == IMAGE_IMPORT_DESCRIPTOR.Empty)
                {
                    break;
                }
                list.Add(importDesc);
                addr += 20;
            }

            return(list.ToArray());
        }
 private unsafe static PeHeader GetPEHeader()
 {
     return(PeHeader.ReadFrom(new UnmanagedMemoryStream((byte *)ModuleHandle, 4194304)));
 }