Example #1
0
        public Bfd(OperatingSystemBackend os, TargetMemoryInfo info, string filename,
                   TargetAddress base_address, bool is_loaded)
        {
            this.os           = os;
            this.info         = info;
            this.filename     = filename;
            this.base_address = base_address;
            this.is_loaded    = is_loaded;

            this.symfile = new BfdSymbolFile(this);

            bfd = bfd_glue_openr(filename, null);
            if (bfd == IntPtr.Zero)
            {
                throw new SymbolTableException("Can't read symbol file: {0}", filename);
            }

            if (bfd_glue_check_format_archive(bfd))
            {
                IntPtr archive = bfd;
                bfd = IntPtr.Zero;

                while (true)
                {
                    bfd = bfd_glue_openr_next_archived_file(archive, bfd);
                    if (bfd == IntPtr.Zero)
                    {
                        throw new SymbolTableException("Can't read symbol file: {0}", filename);
                    }

                    if (bfd_glue_check_format_object(bfd))
                    {
                        /*
                         * At this point, just check for mach-o-le (OS X X86 binary).
                         * When we want to support other architctures in fat binarys,
                         * we need to somehow get the correct target string for the
                         * process, and chech against that.
                         */
                        if (bfd_glue_get_target_name(bfd) == "mach-o-le")
                        {
                            break;
                        }
                    }
                }
            }

            if (bfd_glue_check_format_object(bfd))
            {
                is_coredump = false;
            }
            else if (bfd_glue_check_format_core(bfd))
            {
                is_coredump = true;
            }
            else
            {
                throw new SymbolTableException("Not an object file: {0}", filename);
            }

            target = bfd_glue_get_target_name(bfd);
            if ((target == "elf32-i386") || (target == "elf64-x86-64"))
            {
                if (!is_coredump)
                {
                    Section text = GetSectionByName(".text", false);
                    Section bss  = GetSectionByName(".bss", false);

                    if ((text != null) && (bss != null))
                    {
                        if (!base_address.IsNull)
                        {
                            start_address = new TargetAddress(
                                info.AddressDomain,
                                base_address.Address + text.vma);
                        }
                        else
                        {
                            start_address = new TargetAddress(
                                info.AddressDomain, text.vma);
                        }

                        if (!base_address.IsNull)
                        {
                            end_address = new TargetAddress(
                                info.AddressDomain,
                                base_address.Address + bss.vma + bss.size);
                        }
                        else
                        {
                            end_address = new TargetAddress(
                                info.AddressDomain, bss.vma + bss.size);
                        }
                    }
                }

                read_bfd_symbols();

                if (DwarfReader.IsSupported(this))
                {
                    has_debugging_info = true;
                }

                Section plt_section = GetSectionByName(".plt", false);
                Section got_section = GetSectionByName(".got", false);
                if ((plt_section != null) && (got_section != null))
                {
                    plt_start = new TargetAddress(
                        info.AddressDomain,
                        base_address.Address + plt_section.vma);
                    plt_end = plt_start + plt_section.size;

                    got_start = new TargetAddress(
                        info.AddressDomain,
                        base_address.Address + got_section.vma);
                    has_got = true;
                }
            }
            else if (target == "mach-o-le")
            {
                if (!is_coredump)
                {
                    read_sections();
                    long start = 0xffffffff;
                    long end   = 0;
                    foreach (Section section in sections)
                    {
                        long relocated = base_address.Address + section.vma;

                        if (relocated < start)
                        {
                            start = relocated;
                        }
                        if (relocated + section.size > end)
                        {
                            end = relocated + section.size;
                        }
                    }

                    start_address = new TargetAddress(info.AddressDomain, start);
                    end_address   = new TargetAddress(info.AddressDomain, end);
                }

                read_bfd_symbols();

                if (DwarfReader.IsSupported(this))
                {
                    has_debugging_info = true;
                }

                has_got = false;
            }
            else
            {
                throw new SymbolTableException(
                          "Symbol file {0} has unknown target architecture {1}",
                          filename, target);
            }

            long entry_point_addr = bfd_glue_get_start_address(bfd);

            entry_point = entry_point_addr != 0 ? new TargetAddress(info.AddressDomain, entry_point_addr) : TargetAddress.Null;

            module = os.Process.Session.GetModule(filename);
            if (module == null)
            {
                module = os.Process.Session.CreateModule(filename, symfile);
                OnModuleChanged();
            }
            else
            {
                module.LoadModule(symfile);
            }

            os.Process.SymbolTableManager.AddSymbolFile(symfile);
        }
Example #2
0
        public Bfd(OperatingSystemBackend os, TargetMemoryInfo info, string filename,
			    TargetAddress base_address, bool is_loaded)
        {
            this.os = os;
            this.info = info;
            this.filename = filename;
            this.base_address = base_address;
            this.is_loaded = is_loaded;

            this.symfile = new BfdSymbolFile (this);

            bfd = bfd_glue_openr (filename, null);
            if (bfd == IntPtr.Zero)
                throw new SymbolTableException ("Can't read symbol file: {0}", filename);

            if (bfd_glue_check_format_archive (bfd))
            {
                IntPtr archive = bfd;
                bfd = IntPtr.Zero;

                while (true) {
                    bfd = bfd_glue_openr_next_archived_file (archive, bfd);
                    if(bfd == IntPtr.Zero)
                        throw new SymbolTableException ("Can't read symbol file: {0}", filename);

                    if (bfd_glue_check_format_object(bfd))
                    {
                        /*
                         * At this point, just check for mach-o-le (OS X X86 binary).
                         * When we want to support other architctures in fat binarys,
                         * we need to somehow get the correct target string for the
                         * process, and chech against that.
                         */
                        if (bfd_glue_get_target_name(bfd) == "mach-o-le")
                            break;
                    }
                }
            }

            if (bfd_glue_check_format_object (bfd))
                is_coredump = false;
            else if (bfd_glue_check_format_core (bfd))
                is_coredump = true;
            else
                throw new SymbolTableException ("Not an object file: {0}", filename);

            target = bfd_glue_get_target_name (bfd);
            if ((target == "elf32-i386") || (target == "elf64-x86-64")) {
                if (!is_coredump) {
                    Section text = GetSectionByName (".text", false);
                    Section bss = GetSectionByName (".bss", false);

                    if ((text != null) && (bss != null)) {
                        if (!base_address.IsNull)
                            start_address = new TargetAddress (
                                info.AddressDomain,
                                base_address.Address + text.vma);
                        else
                            start_address = new TargetAddress (
                                info.AddressDomain, text.vma);

                        if (!base_address.IsNull)
                            end_address = new TargetAddress (
                                info.AddressDomain,
                                base_address.Address + bss.vma + bss.size);
                        else
                            end_address = new TargetAddress (
                                info.AddressDomain, bss.vma + bss.size);
                    }
                }

                read_bfd_symbols ();

                if (DwarfReader.IsSupported (this))
                    has_debugging_info = true;

                Section plt_section = GetSectionByName (".plt", false);
                Section got_section = GetSectionByName (".got", false);
                if ((plt_section != null) && (got_section != null)) {
                    plt_start = new TargetAddress (
                        info.AddressDomain,
                        base_address.Address + plt_section.vma);
                    plt_end = plt_start + plt_section.size;

                    got_start = new TargetAddress (
                        info.AddressDomain,
                        base_address.Address + got_section.vma);
                    has_got = true;
                }
            } else if (target == "mach-o-le") {
                if (!is_coredump) {
                    read_sections ();
                    long start = 0xffffffff;
                    long end = 0;
                    foreach (Section section in sections) {
                        long relocated = base_address.Address + section.vma;

                        if (relocated < start)
                            start = relocated;
                        if (relocated + section.size > end)
                            end = relocated + section.size;
                    }

                    start_address = new TargetAddress (info.AddressDomain, start);
                    end_address = new TargetAddress (info.AddressDomain, end);
                }

                read_bfd_symbols ();

                if (DwarfReader.IsSupported (this))
                    has_debugging_info = true;

                has_got = false;
            } else
                throw new SymbolTableException (
                    "Symbol file {0} has unknown target architecture {1}",
                    filename, target);

            long entry_point_addr = bfd_glue_get_start_address (bfd);
            entry_point = entry_point_addr != 0 ? new TargetAddress (info.AddressDomain, entry_point_addr) : TargetAddress.Null;

            module = os.Process.Session.GetModule (filename);
            if (module == null) {
                module = os.Process.Session.CreateModule (filename, symfile);
                OnModuleChanged ();
            } else {
                module.LoadModule (symfile);
            }

            os.Process.SymbolTableManager.AddSymbolFile (symfile);
        }