A script to download libs (#10)

* fix dir problem. add id.url

* add id.url

* add download script

* add the usage of download
This commit is contained in:
Matrix
2018-11-09 14:06:41 +01:00
committed by Niklas Baumstark
parent bc38a6215a
commit 6989f92c4c
9 changed files with 74 additions and 1 deletions
+11
View File
@@ -40,3 +40,14 @@ Check whether a library is already in the database.
$ ./identify /usr/lib/libc.so.6
id local-f706181f06104ef6c7008c066290ea47aa4a82c5
Download the whole libs corresponding to a libc ID.
$ ./download libc6_2.23-0ubuntu10_amd64
Getting libc6_2.23-0ubuntu10_amd64
-> Location: http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6_2.23-0ubuntu10_amd64.deb
-> Downloading package
-> Extracting package
-> Package saved to libs/libc6_2.23-0ubuntu10_amd64
$ ls libs/libc6_2.23-0ubuntu10_amd64
ld-2.23.so ... libc.so.6 ... libpthread.so.0 ...
+1
View File
@@ -1,4 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")"
if [[ $# != 1 ]]; then
echo >&2 "Usage: $0 libc_filename"
exit 2
+3 -1
View File
@@ -39,6 +39,7 @@ process_libc() {
local libc=$1
local id=$2
local info=$3
local url=$4
echo " -> Writing libc to db/${id}.so"
cp $libc db/${id}.so
echo " -> Writing symbols to db/${id}.symbols"
@@ -46,6 +47,7 @@ process_libc() {
> db/${id}.symbols
echo " -> Writing version info"
echo "$info" > db/${id}.info
echo "$url" > db/${id}.url
}
check_id() {
@@ -78,7 +80,7 @@ get_ubuntu() {
suffix=
cnt=1
for libc in $(find $tmp -name libc.so.6 || die "Cannot locate libc.so.6"); do
process_libc $libc $id$suffix $info
process_libc $libc $id$suffix $info $url
cnt=$((cnt+1))
suffix=_$cnt
done
Executable
+53
View File
@@ -0,0 +1,53 @@
#!/bin/bash
cd "$(dirname "$0")"
die() {
echo >&2 $1
exit 1
}
function usage() {
echo >&2 "Usage: $0 id [id ...]"
exit 2
}
function download_single() {
local id=$1
echo "Getting $id"
if [ -d libs/$id ]; then
echo " --> Downloaded before. Remove it to download again."
return
fi
local url=`cat db/$1.url 2>/dev/null|| die "-> Invalid id"`
echo " -> Location: $url"
local tmp=`mktemp -d || mktemp -d -t "libc-database" || die "Cannot get temp dir"`
echo " -> Downloading package"
wget $url 2>/dev/null -O $tmp/pkg.deb || die "Failed to download package from $url"
echo " -> Extracting package"
pushd $tmp 1>/dev/null
ar x pkg.deb || die "ar failed"
tar xf data.tar.* || die "tar failed"
popd 1>/dev/null
mkdir libs/$id
cp $tmp/lib/*/* libs/$id 2>/dev/null || cp $tmp/lib32/* libs/$id 2>/dev/null \
|| die "Failed to save. Check it manually $tmp"
echo " -> Package saved to libs/$id"
rm -rf $tmp
}
function download() {
[[ $# < 1 ]] && usage
id=$1; shift
if [[ $# == 0 ]]; then
download_single $id
else
comm -12 \
<(download_single $id) \
<(download "$@")
fi
}
download "$@"
+1
View File
@@ -1,4 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")"
if [[ $# < 1 ]]; then
echo >&2 "Usage: $0 id [name1 [name2 ...]]"
exit 2
+1
View File
@@ -1,4 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")"
function usage() {
echo >&2 "Usage: $0 name address [name address ...]"
exit 2
+1
View File
@@ -1,4 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")"
. common/libc.sh
get_current_ubuntu trusty i386 libc6
+1
View File
@@ -1,4 +1,5 @@
#!/bin/bash
cd "$(dirname "$0")"
if [[ $# != 1 ]]; then
echo >&2 "Usage: $0 path/to/libc.so"
exit 2
+2
View File
@@ -0,0 +1,2 @@
*
!/.gitignore