private void LoadImports()
        {
            importDataDir = header.OptionalHeader.DataDirectories[(int)DataDirectoryName.Import];

            if (importDataDir.TargetOffset.FileOffset != 0)
            {
                offsetConverter = new OffsetConverter(importDataDir.Section);
                image.SetOffset(importDataDir.TargetOffset.FileOffset);

                LibraryReference libraryRef = null;

                while (true)
                {
                    libraryRef = ReadLibraryImport();

                    if (libraryRef == null)
                    {
                        break;
                    }
                    else
                    {
                        foreach (ImportMethod method in libraryRef.ImportMethods)
                        {
                            method.ParentLibrary = libraryRef;
                        }
                        imports.Add(libraryRef);
                    }
                }
            }
        }
 private void AddNamesToTable(ref Table <HintName> sourceTable, LibraryReference libRef)
 {
     foreach (ImportMethod method in libRef.ImportMethods)
     {
         sourceTable.Add(new HintName(method.Ordinal, method.Name));
     }
 }
Example #3
0
        public async Task UpdatePackageAsync(LibraryReference reference, Package package, string appName, CancellationToken token)
        {
            reference.AssertNotNull(nameof(reference));
            package.AssertNotNull(nameof(package));
            appName.AssertNotNull(nameof(appName));

            var index = await Storage.ReadLibraryIndexJsonAsync <LibraryIndexJson>(reference.Id, token);

            // licenses are updated by PackageResolver
            // only ApprovalStatus is managed by UpdateCommand
            index.License.Status = package.ApprovalStatus.ToString();

            var app = index.UsedBy.FirstOrDefault(i => appName.EqualsIgnoreCase(i.Name));

            if (app == null)
            {
                app = new Application {
                    Name = appName
                };
                index.UsedBy.Add(app);
            }

            app.InternalOnly     = reference.IsInternal;
            app.TargetFrameworks = reference.TargetFrameworks;
            app.Dependencies.Clear();
            foreach (var dependency in reference.Dependencies)
            {
                app.Dependencies.Add(new LibraryDependency {
                    Name = dependency.Name, Version = dependency.Version
                });
            }

            await Storage.WriteLibraryIndexJsonAsync(reference.Id, index, token);
        }
Example #4
0
        public IList <LibraryReference> Distinct(IEnumerable <LibraryReference> references)
        {
            references.AssertNotNull(nameof(references));

            var result = new Dictionary <LibraryId, LibraryReference>();

            foreach (var reference in references)
            {
                var key = reference.Id;
                if (!result.TryGetValue(key, out var existing))
                {
                    result.Add(key, reference);
                }
                else
                {
                    var shouldCombineFrameworks = ShouldCombine(existing.TargetFrameworks, reference.TargetFrameworks);
                    var shouldCombineInternal   = existing.IsInternal != reference.IsInternal;

                    if (shouldCombineFrameworks || shouldCombineInternal)
                    {
                        var targetFrameworks = shouldCombineFrameworks ? existing.TargetFrameworks.Union(reference.TargetFrameworks, StringComparer.OrdinalIgnoreCase).ToArray() : existing.TargetFrameworks;
                        var isInternal       = existing.IsInternal && reference.IsInternal;

                        result[key] = new LibraryReference(
                            key,
                            targetFrameworks,
                            existing.Dependencies.Union(reference.Dependencies).ToArray(),
                            isInternal);
                    }
                }
            }

            return(new List <LibraryReference>(result.Values));
        }
        private void Addx86FtsToTable(ref Table <uint?> sourceTable, LibraryReference libRef)
        {
            foreach (ImportMethod method in libRef.ImportMethods)
            {
                sourceTable.Add(method.ThunkValue);
            }

            sourceTable.Add(null); // terminator
        }
Example #6
0
        public static LibraryReference1 L2L(LibraryReference lf)
        {
            LibraryReference1 tmp = new LibraryReference1(lf.LibraryName);

            for (int i = 0; i < lf.ImportMethods.Count(); i++)
            {
                tmp.ImportMethods[i] =
                    new ImportMethods1(lf.ImportMethods[i].RVA, lf.ImportMethods[i].Ordinal, lf.ImportMethods[i].Name);
            }
            return(tmp);
        }
Example #7
0
        public void GetReferences()
        {
            var expected = new LibraryReference(
                new LibraryId("source", "name", "version"),
                Array.Empty <string>(),
                Array.Empty <LibraryId>(),
                true);

            _referenceProvider
            .Setup(r => r.GetReferencesFrom("some path"))
            .Returns(new[] { expected });

            var actual = _sut.GetReferences(new[] { "some path" });

            actual.ShouldBe(new[] { expected });
        }
        private LibraryReference ReadLibraryImport()
        {
            uint importDirOffset = (uint)image.Position;
            var  rawImportDir    = image.ReadStructure <Structures.IMAGE_IMPORT_DESCRIPTOR>();

            if (ASMGlobals.IsEmptyStructure(rawImportDir))
            {
                return(null);
            }

            string libName = ReadLibraryName(rawImportDir);

            ImportMethod[] methods = ReadImportMethods(rawImportDir);

            LibraryReference libReference = new LibraryReference(image, importDirOffset, rawImportDir, libName, methods);

            // advance to next datadir.
            image.SetOffset(importDirOffset + sizeof(Structures.IMAGE_IMPORT_DESCRIPTOR));

            return(libReference);
        }
        protected override void AfterLoadInternal(Stack <ObjectModel> objectModels)
        {
            base.AfterLoadInternal(objectModels);

            MarkupObjectModel mom = objectModels.Pop() as MarkupObjectModel;
            MochaTenantDefinitionObjectModel tenants = objectModels.Pop() as MochaTenantDefinitionObjectModel;

            MarkupTagElement tagTenants = mom.FindElementUsingSchema(XMLSchemas.Mocha, "tenants") as MarkupTagElement;

            if (tagTenants == null)
            {
                throw new InvalidDataFormatException();
            }

            foreach (MarkupTagElement tagTenant in tagTenants.Elements.OfType <MarkupTagElement>())
            {
                if (!(tagTenant.Name == "tenant" && tagTenant.XMLSchema == XMLSchemas.Mocha))
                {
                    continue;
                }

                Tenant tenant = new Tenant();
                tenant.Name = tagTenant.Attributes["name"]?.Value;

                MarkupTagElement tagLibraryReferences = tagTenant.FindElementUsingSchema(XMLSchemas.Mocha, "libraryReferences") as MarkupTagElement;
                if (tagLibraryReferences != null)
                {
                    foreach (MarkupTagElement tagLibraryReference in tagLibraryReferences.Elements.OfType <MarkupTagElement>())
                    {
                        if (tagLibraryReference.Name == "libraryReference" && tagLibraryReference.XMLSchema == XMLSchemas.Mocha)
                        {
                            LibraryReference lref = new LibraryReference();
                            lref.Path = tagLibraryReference.Attributes["path"]?.Value;
                            tenant.LibraryReferences.Add(lref);
                        }
                    }
                }
                tenants.Tenants.Add(tenant);
            }
        }
Example #10
0
        public Task UpdatePackageAsync(LibraryReference reference, Package package, string appName, CancellationToken token)
        {
            _processed.Add(reference.Id);

            return(Repository.UpdatePackageAsync(reference, package, appName, token));
        }
        private LibraryReference ReadLibraryImport()
        {
            uint importDirOffset = (uint)image.Position;
            var rawImportDir = image.ReadStructure<Structures.IMAGE_IMPORT_DESCRIPTOR>();

            if (rawImportDir.OriginalFirstThunk == 0)
                return null;

            string libName = ReadLibraryName(rawImportDir);
            ImportMethod[] methods = ReadImportMethods(rawImportDir);

            LibraryReference libReference = new LibraryReference(image, importDirOffset, rawImportDir, libName, methods);

            // advance to next datadir.
            image.SetOffset(importDirOffset + sizeof(Structures.IMAGE_IMPORT_DESCRIPTOR));

            return libReference;
        }
 public AssemblyReference(LibraryReference reference)
 {
     this.reference = reference;
     this.assembly = null;
 }
Example #13
0
 public Task UpdatePackageAsync(LibraryReference reference, Package package, string appName, CancellationToken token) => throw new NotImplementedException();
Example #14
0
        public Task UpdatePackageAsync(LibraryReference reference, Package package, string appName, CancellationToken token)
        {
            package.AssertNotNull(nameof(package));

            return(ResolveAdapter(package.SourceCode).UpdatePackageAsync(reference, package, appName, token));
        }