コード例 #1
0
        public static ModuleInventory FromFiles(IEnumerable <string> pathsToLibraryFiles, ErrorHandling errors)
        {
            ModuleInventory inventory = null;

            foreach (string path in pathsToLibraryFiles)
            {
                if (inventory == null)
                {
                    inventory = new ModuleInventory();
                }
                using (FileStream stm = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    FromStreamInto(stm, inventory, errors, path);
                }
            }
            return(inventory);
        }
コード例 #2
0
        public static ModuleInventory FromStream(Stream stm, ErrorHandling errors, string fileName = null)
        {
            ModuleInventory inventory = new ModuleInventory();

            return(FromStreamInto(stm, inventory, errors, fileName));
        }
コード例 #3
0
        static ModuleInventory FromStreamInto(Stream stm, ModuleInventory inventory,
                                              ErrorHandling errors, string fileName = null)
        {
            Ex.ThrowOnNull(errors, "errors");
            Ex.ThrowOnNull(stm, "stm");
            OffsetStream      osstm   = null;
            List <NListEntry> entries = null;

            try {
                List <MachOFile> macho = MachO.Read(stm, null).ToList();
                MachOFile        file  = macho [0];

                List <SymTabLoadCommand> symbols = file.load_commands.OfType <SymTabLoadCommand> ().ToList();
                NListEntryType           nlet    = symbols [0].nlist [0].EntryType;
                entries = symbols [0].nlist.
                          Where((nle, i) => nle.IsPublic && nle.EntryType == NListEntryType.InSection).ToList();
                inventory.Architecture = file.Architecture;
                osstm = new OffsetStream(stm, file.StartOffset);
            } catch (Exception e) {
                errors.Add(ErrorHelper.CreateError(ReflectorError.kCantHappenBase + 58, e, "Unable to retrieve functions from {0}: {1}",
                                                   fileName ?? "stream", e.Message));
                return(inventory);
            }

            bool isOldVersion = IsOldVersion(entries);

            foreach (var entry in entries)
            {
                if (!entry.IsSwiftEntryPoint())
                {
                    continue;
                }
                TLDefinition def = null;
                try {
                    def = Decomposer.Decompose(entry.str, isOldVersion, Offset(entry));
                } catch (RuntimeException e) {
                    var except = new RuntimeException(e.Code, false, e, $"error decomposing {entry.str}: {e.Message}, skipping");
                    errors.Add(except);
                }
                catch (Exception e) {
                    var except = new RuntimeException(ReflectorError.kDecomposeBase + 0, false, e, $"unexpected error handling {entry.str}: {e.Message}, skipping.");
                    errors.Add(except);
                }
                if (def != null)
                {
                    // this skips over privatized names
                    var tlf = def as TLFunction;
                    if (tlf != null && tlf.Name != null && tlf.Name.Name.Contains("..."))
                    {
                        continue;
                    }
                    try {
                        inventory.Add(def, osstm);
                    } catch (RuntimeException e) {
                        e = new RuntimeException(e.Code, e.Error, $"error dispensing top level definition of type {def.GetType ().Name} decomposed from {entry.str}: {e.Message}");
                        errors.Add(e);
                    }
                }
                else
                {
                    var ex = ErrorHelper.CreateWarning(ReflectorError.kInventoryBase + 18, $"entry {entry.str} uses an unsupported swift feature, skipping.");
                    errors.Add(ex);
                }
            }

            return(inventory);
        }