View Single Post
Old 12-20-2012, 01:25 AM   #1
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
Checking for required libs. Exporting Binaries "easily"

Have you ever wished you could just export a binary and it's supporting libs. Or at the very least some likely candidate supporting libs.

well I did (and so did Brian...)

For the 2 3 4 Touch and Paperwhite (INSIDE A DEBIAN)
(or even on your desktop via a qemu-arm-static chroot)

Code:
#!/bin/bash
FAILS=""
MAINEXPORTDIR="/export"
TESTUSRLIB="/kindle/usr/lib/"
TESTLIB="/kindle/lib/"

# fail on missing victim
if [ -z ${@} ]
then
  echo "hmm I need a victim... usage: filechecker <binary_file>"
exit 1
fi
# fail on missing victim
if [ ! -e ${@} ]
then
  echo "hmm I cannot find: ${@} - you sure? check the file exists."
exit 1
fi

BINARY=$(basename ${@})
EXPORTDIR="${MAINEXPORTDIR}""/""${BINARY}"
mkdir -p $EXPORTDIR/bin
mkdir -p $EXPORTDIR/lib
mkdir -p $EXPORTDIR/kindle-lib
cd $EXPORTDIR

# copy the binary we are interested in
cp -f ${@} "${EXPORTDIR}/bin/${BINARY}"
echo "copying ${@} to ${EXPORTDIR}/bin/${BINARY}"

echo "finding all dependencies and copying them to $EXPORTDIR/lib"
echo "this will take a couple seconds, please wait..."
ldd ${@} | awk ' /=> \// {print $3}' | xargs -I '{}' cp -v '{}' $EXPORTDIR/lib > /dev/null


echo "Done. Now going to see if any of these libraries are already on the Kindle Touch (5.3.7)..."
find $EXPORTDIR/lib -type f | while read filename
  filename=$( basename $filename 2>/dev/null) 
do
echo
echo "checking $EXPORTDIR/lib/$filename.."
  if [ -f "$TESTUSRLIB""$filename" ]; then

    if cmp --quiet $TESTUSRLIB$filename $EXPORTDIR/lib/$filename ; then

     echo "$EXPORTDIR/lib/$filename is the same as my Kindle version - deleting!"
      rm $EXPORTDIR/lib/$filename

	fi
  fi


  if [ -f "$TESTLIB""$filename" ]; then

    if cmp --quiet $TESTLIB$filename $EXPORTDIR/lib/$filename ; then

	  echo "$EXPORTDIR/lib/$filename is the same as my Kindle version - deleting"
      rm $EXPORTDIR/lib/$filename
    fi

  fi
done

#no need to have this at all ??
if [ -f $EXPORTDIR/lib/libc.so.6 ]; then
  echo
  echo "*** removing unneeded libc.so.6.." 
  rm $EXPORTDIR/lib/libc.so.6
fi

#remove empty lib dir
if [[ "$(ls -1 $EXPORTDIR/lib | wc -l)" == "0" ]] ; then
  rmdir $EXPORTDIR/lib
else
  echo
  echo "$EXPORTDIR/lib has: `ls -1 $EXPORTDIR/lib | wc -l` files:"
  ls -1 $EXPORTDIR/lib
  echo
fi

touch $EXPORTDIR/README
echo "Directories created in $EXPORTDIR. kindle-lib has newer versions of Kindle libraries." | tee $EXPORTDIR/README
echo "These are normally not needed. Run the program like this:" | tee $EXPORTDIR/README
echo "cd $EXPORTDIR/bin; LD_LIBRARY_PATH=../lib:\$LD_LIBRARY_PATH ./$BINARY" | tee $EXPORTDIR/README
[root@kindle 600x800]# filechecker /mnt/us/bin/nano
Quote:
copying /mnt/us/bin/nano to /mnt/us/export/nano/bin/nano
Searching 937 user libs, 85 libs, 17 extended dirs

libncurses.so.5
kindle supported at /usr/lib/libncurses.so.5
/usr/lib support detected

libc.so.6
kindle supported at /lib/libc.so.6
/lib support detected

Export complete at /mnt/us/export/nano ensure you run nano like: LD_LIBRARY_PATH=../lib ./nano
If you don't know what this is for you don't need it.

Everyone likes a good bash improvement thread. feel free to pick holes.

THIS VERSION WAS PROVIDED BY BRIAN

IT EXPECTS TO LIVE INSIDE A DEBIAN

With the kindle libs bind mounted like:
mount --bind /usr/lib /mnt/us/debian/kindle/usr/lib
mount --bind /lib /mnt/us/debian/kindle/lib
Attached Thumbnails
Click image for larger version

Name:	Selection_074.png
Views:	582
Size:	7.4 KB
ID:	97961  

Last edited by twobob; 10-29-2013 at 07:20 PM. Reason: # now improved to catch sub-dependencies
twobob is offline   Reply With Quote