Exemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public ImportEntry(FilePath calledFromFile, FileHint providerFileHint, string symbol,
                    string shortFunctionName)
 {
     CalledFromFile    = calledFromFile;
     ProviderFileHint  = providerFileHint;
     Symbol            = symbol;
     ShortFunctionName = shortFunctionName;
 }
Exemplo n.º 2
0
        public List <ImportEntry> EntriesForProvider(FileHint providerHint)
        {
            var entries = new List <ImportEntry>();

            if (!_providerIndex.TryFind(providerHint, out var ids))
            {
                return(entries);
            }
            foreach (int id in ids)
            {
                entries.Add(_entries[id]);
            }
            return(entries);
        }
Exemplo n.º 3
0
        public int Add(FileHint fileHint)
        {
            var field = _fileHintMatch.ExtractField(fileHint);

            if (_fileHintMatch.Contains(field))
            {
                return(_fileHintMatch.FirstOrDefault(field));
            }
            int newHintId = _fileHints.Count;

            _fileHints.Add(fileHint);
            _fileHintMatch.Add(fileHint, newHintId);
            return(newHintId);
        }
        public static List <ImportEntry> GetImports(FilePath targetFile)
        {
            var invoker = new DumpBinInvoker();

            invoker.Arguments.Add("/IMPORTS");
            invoker.Arguments.Add(targetFile.FullName);
            invoker.Run();
            char[]   splitChars     = new char[] { ' ', '\t' };
            int      lineCount      = invoker.Outputs.Count;
            bool     hasStarted     = false;
            var      imports        = new List <ImportEntry>();
            FileHint calleeFileHint = null;

            for (int lineIndex = 0; lineIndex < lineCount; ++lineIndex)
            {
                string line = invoker.Outputs[lineIndex];
                if (!hasStarted)
                {
                    if (line.Trim().Equals("Section contains the following imports:", StringComparison.InvariantCulture))
                    {
                        hasStarted = true;
                    }
                    continue;
                }
                else
                {
                    if (line.Trim().Equals("Summary", StringComparison.InvariantCulture))
                    {
                        break;
                    }
                }
                string[] parts = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 0)
                {
                    continue;
                }
                if (parts.Length == 1)
                {
                    calleeFileHint = new FileHint(parts[0]);
                    continue;
                }
                else if (parts.Length == 2)
                {
                    if (!IsHexString(parts[0]))
                    {
                        throw new Exception("Expects imported function to start with hexadecimal value. Text: \n" + line + "\n");
                    }
                    if (calleeFileHint == null)
                    {
                        throw new Exception("Invalid execution flow: missing file name");
                    }
                    string strValue  = parts[0];
                    string remainder = line.Substring(line.IndexOf(strValue) + strValue.Length).Trim();
                    imports.Add(new ImportEntry(targetFile, calleeFileHint, remainder, remainder));
                }
                else if (parts.Length > 2)
                {
                    if (!IsHexString(parts[0]))
                    {
                        throw new Exception("Expects additional information to start with hexadecimal value. Text: \n" + line + "\n");
                    }
#if false
                    // additional information skipped
                    string strValue  = parts[0];
                    string remainder = line.Substring(line.IndexOf(strValue) + strValue.Length).Trim();
                    currentInfo.AdditionalInfos.Add(remainder, strValue);
#endif
                }
            }
            return(imports);
        }