Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>If it's a shared library</p> <p><strong>You're hosed, unfortunately; it's not possible to know where the libraries were placed in memory by the dynamic linker after-the-fact</strong>.</p> </blockquote> <p>Well, there is still a possibility to retrieve the information, not from the binary, but from the object. But you need the base address of the object. And this information still is within the coredump, in the link_map structure.</p> <p>So first you want to import the struct link_map into GDB. So lets compile a program with it with debug symbol and add it to the GDB.</p> <p><strong>link.c</strong></p> <pre><code>#include &lt;link.h&gt; toto(){struct link_map * s = 0x400;} </code></pre> <p>get_baseaddr_from_coredump.sh</p> <pre><code>#!/bin/bash BINARY=$(which myapplication) IsBinPIE () { readelf -h $1|grep 'Type' |grep "EXEC"&gt;/dev/null || return 0 return 1 } Hex2Decimal () { export number="`echo "$1" | sed -e 's:^0[xX]::' | tr '[a-f]' '[A-F]'`" export number=`echo "ibase=16; $number" | bc` } GetBinaryLength () { if [ $# != 1 ]; then echo "Error, no argument provided" fi IsBinPIE $1 || (echo "ET_EXEC file, need a base_address"; exit 0) export totalsize=0 # Get PT_LOAD's size segment out of Program Header Table (ELF format) export sizes="$(readelf -l $1 |grep LOAD |awk '{print $6}'|tr '\n' ' ')" for size in $sizes do Hex2Decimal "$size"; export totalsize=$(expr $number + $totalsize); export totalsize=$(expr $number + $totalsize) done return $totalsize } if [ $# = 1 ]; then echo "Using binary $1" IsBinPIE $1 &amp;&amp; (echo "NOT ET_EXEC, need a base_address..."; exit 0) BINARY=$1 fi gcc -g3 -fPIC -shared link.c -o link.so GOTADDR=$(readelf -S $BINARY|grep -E '\.got.plt[ \t]'|awk '{print $4}') echo "First do the following command :" echo file $BINARY echo add-symbol-file ./link.so 0x0 read echo "Now copy/paste the following into your gdb session with attached coredump" cat &lt;&lt;EOF set \$linkmapaddr = *(0x$GOTADDR + 4) set \$mylinkmap = (struct link_map *) \$linkmapaddr while (\$mylinkmap != 0) if (\$mylinkmap-&gt;l_addr) printf "add-symbol-file .%s %#.08x\n", \$mylinkmap-&gt;l_name, \$mylinkmap-&gt;l_addr end set \$mylinkmap = \$mylinkmap-&gt;l_next end </code></pre> <p>it will print you the whole link_map content, within a set of GDB command.</p> <p>It itself it might seems unnesseray but with the base_addr of the shared object we are about, you might get some more information out of an address by debuging directly the involved shared object in another GDB instance. Keep the first gdb to have an idee of the symbol.</p> <p>NOTE : the script is rather incomplete i suspect you may <strong>add</strong> to the second parameter of add-symbol-file printed the sum with this value :</p> <pre><code>readelf -S $SO_PATH|grep -E '\.text[ \t]'|awk '{print $5}' </code></pre> <p>where $SO_PATH is the <em>first</em> argument of the add-symbol-file</p> <p>Hope it helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload