Esempio n. 1
0
        public uint GetSymbolAddress(ELFDynamicSymbolTableSection.Symbol theSymbol, FOS_System.String theSymbolName)
        {
            uint address = 0;
            uint size    = 0;

            GetSymbolAddressAndSize(theSymbol, theSymbolName, ref address, ref size);
            return(address);
        }
Esempio n. 2
0
        public bool GetSymbolAddressAndSize(ELFDynamicSymbolTableSection.Symbol theSymbol, FOS_System.String theSymbolName, ref uint address, ref uint size)
        {
            //BasicConsole.WriteLine("Searching for symbol...");
            //BasicConsole.Write("     - Name : ");
            //BasicConsole.WriteLine(theSymbolName);

            //BasicConsole.WriteLine("     Searching executable's symbols...");
            for (int i = 0; i < theFile.Sections.Count; i++)
            {
                ELFSection aSection = (ELFSection)theFile.Sections[i];
                if (aSection is ELFSymbolTableSection)
                {
                    ELFSymbolTableSection symTabSection = (ELFSymbolTableSection)aSection;
                    ELFStringTableSection strTabSection = (ELFStringTableSection)theFile.Sections[symTabSection.StringsSectionIndex];

                    for (int j = 0; j < symTabSection.Symbols.Count; j++)
                    {
                        ELFSymbolTableSection.Symbol aSymbol = (ELFSymbolTableSection.Symbol)symTabSection.Symbols[j];

                        if (aSymbol.Type == theSymbol.Type &&
                            aSymbol.Binding == ELFSymbolTableSection.SymbolBinding.Global &&
                            aSymbol.SectionIndex > 0)
                        {
                            if (strTabSection.IsMatch(aSymbol.NameIdx, theSymbolName))
                            {
                                //BasicConsole.WriteLine("     Found symbol.");
                                //BasicConsole.Write("     aSymbol Address : ");
                                uint result = ((uint)aSymbol.Value - theFile.BaseAddress) + BaseAddress;
                                //BasicConsole.WriteLine(result);

                                address = result;
                                size    = aSymbol.Size;
                                return(true);
                            }
                        }
                    }
                }
            }
            for (int k = 0; k < SharedObjectDependencies.Count; k++)
            {
                //BasicConsole.WriteLine("     Searching shared object's symbols...");

                ELFSharedObject SO = (ELFSharedObject)SharedObjectDependencies[k];
                for (int i = 0; i < SO.TheFile.Sections.Count; i++)
                {
                    ELFSection aSection = (ELFSection)SO.TheFile.Sections[i];
                    if (aSection is ELFSymbolTableSection)
                    {
                        ELFSymbolTableSection symTabSection = (ELFSymbolTableSection)aSection;
                        ELFStringTableSection strTabSection = (ELFStringTableSection)SO.TheFile.Sections[symTabSection.StringsSectionIndex];
                        for (int j = 0; j < symTabSection.Symbols.Count; j++)
                        {
                            ELFSymbolTableSection.Symbol aSymbol = (ELFSymbolTableSection.Symbol)symTabSection.Symbols[j];
                            if (aSymbol.Type == theSymbol.Type &&
                                aSymbol.Binding == ELFSymbolTableSection.SymbolBinding.Global &&
                                aSymbol.SectionIndex > 0)
                            {
                                if (strTabSection.IsMatch(aSymbol.NameIdx, theSymbolName))
                                {
                                    //BasicConsole.WriteLine("     Found symbol.");
                                    //BasicConsole.Write("     aSymbol Address : ");
                                    uint result = ((uint)aSymbol.Value - SO.TheFile.BaseAddress) + SO.BaseAddress;
                                    //BasicConsole.WriteLine(result);

                                    address = result;
                                    size    = aSymbol.Size;
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }