* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: fb0efdab52e7e204b38d795d316d0e1bab642b34
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 03:14:09 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=fb0efdab
scripts/revdep-paxmark: deprecated
---
scripts/revdep-paxmark | 639 ------------------------------------------------
1 files changed, 0 insertions(+), 639 deletions(-)
diff --git a/scripts/revdep-paxmark b/scripts/revdep-paxmark
deleted file mode 100755
index fd07c3c..0000000
--- a/scripts/revdep-paxmark
+++ /dev/null
@@ -1,639 +0,0 @@
-#!/bin/bash
-# Copyright 1999-2011 Gentoo Foundation
-
-#
-# This utility will look for any binaries which do not have
-# the same pax markings as the corresponding libraries which
-# they link against.
-#
-# This code is mostly derived from revdep-rebuild.
-#
-
-# Readonly variables:
-declare -r APP_NAME="${0##*/}" # The name of this application
-declare -r VERSION="0.1.0.0"
-declare -r OIFS="$IFS" # Save the IFS
-declare -r ENV_FILE=0_env.rr # Contains environment variables
-declare -r FILES_FILE=1_files.rr # Contains a list of files to search
-declare -r LDPATH_FILE=2_ldpath.rr # Contains the LDPATH
-declare -r BROKEN_FILE=3_broken.rr # Contains the list of broken files
-declare -r ERRORS_FILE=3_errors.rr # Contains the ldd error output
-declare -ra FILES=(
- "$ENV_FILE"
- "$FILES_FILE"
- "$LDPATH_FILE"
- "$BROKEN_FILE"
- "$ERRORS_FILE"
-)
-
-# "Boolean" variables: Considered "true" if it has any value at all
-# "True" indicates we should...
-declare FULL_LD_PATH # ...search across the COMPLETE_LD_LIBRARY_PATH
-declare ORDER_PKGS # ...sort the atoms in deep dependency order
-declare RM_OLD_TEMPFILES # ...remove tempfiles from prior runs
-declare SEARCH_BROKEN # ...search for broken libraries and binaries
-
-# Globals that impact portage directly:
-declare EMERGE_DEFAULT_OPTS # String of options portage assumes to be set
-declare PORTAGE_NICENESS # Renice to this value
-declare PORTAGE_ROOT # The root path for portage
-
-# Customizable incremental variables:
-# These variables can be prepended to either by setting the variable in
-# your environment prior to execution, or by placing an entry in
-# /etc/make.conf.
-#
-# An entry of "-*" means to clear the variable from that point forward.
-# Example: env SEARCH_DIRS="/usr/bin -*" revdep-rebuild will set SEARCH_DIRS
-# to contain only /usr/bin
-declare LD_LIBRARY_MASK # Mask of specially evaluated libraries
-declare SEARCH_DIRS # List of dirs to search for executables and libraries
-declare SEARCH_DIRS_MASK # List of dirs not to search
-
-# Other globals:
-declare OLDPROG # Previous pass through the progress meter
-declare EXACT_PKG # Versionated atom to emerge
-declare HEAD_TEXT # Feedback string about the search
-declare OK_TEXT # Feedback about a search which found no errors
-declare REBUILD_LIST # Array of atoms to emerge
-declare SONAME # Soname/soname path pattern given on commandline
-declare SONAME_SEARCH # Value of SONAME modified to match ldd's output
-declare WORKING_TEXT # Feedback about the search
-declare WORKING_DIR # Working directory where cache files are kept
-
-main() {
- portage_settings
- get_opts "$@"
- setup_search_paths_and_masks
- get_search_env
- get_files
- get_ldpath
- main_checks
- cleanup
-}
-##
-# GNU find has -executable, but if our users' finds do not have that flag
-# we emulate it with this function. Also emulates -writable and -readable.
-# Usage: find PATH ARGS -- use find like normal, except use -executable instead
-# of various versions of -perm /+ blah blah and hacks
-find() {
- hash find || { die 1 'find not found!'; }
- # We can be pretty sure find itself should be executable.
- local testsubject="$(type -P find)"
- if [[ $(command find "$testsubject" -executable 2> /dev/null) ]]; then
- unset -f find # We can just use the command find
- elif [[ $(command find "$testsubject" -perm /u+x 2> /dev/null) ]]; then
- find() {
- a=(${@//-executable/-perm \/u+x})
- a=(${a[@]//-writable/-perm \/u+w})
- a=(${a[@]//-readable/-perm \/r+w})
- command find "${a[@]}"
- }
- elif [[ $(command find "$testsubject" -perm +u+x 2> /dev/null) ]]; then
- find() {
- a=(${@//-executable/-perm +u+x})
- a=(${a[@]//-writable/-perm +u+w})
- a=(${a[@]//-readable/-perm +r+w})
- command find "${a[@]}"
- }
- else # Last resort
- find() {
- a=(${@//-executable/-exec test -x '{}' \; -print})
- a=(${a[@]//-writable/-exec test -w '{}' \; -print})
- a=(${a[@]//-readable/-exec test -r '{}' \; -print})
- command find "${a[@]}"
- }
- fi
- find "$@"
-}
-
-print_usage() {
-cat << EOF
-${APP_NAME}: (${VERSION})
-
-Copyright (C) 2003-2010 Gentoo Foundation, Inc.
-This is free software; see the source for copying conditions.
-
-Usage: $APP_NAME [OPTIONS] [--]
-
-Broken reverse dependency rebuilder.
-
- -C, --nocolor Turn off colored output
- -d, --debug Print way too much information (uses bash's set -xv)
- -h, --help Print this usage
- -i, --ignore Ignore temporary files from previous runs
- -k, --keep-temp Do not delete temporary files on exit
- -L, --library NAME Emerge existing packages that use the library with NAME
- --library=NAME NAME can be a full path to the library or a basic
- regular expression (man grep)
- -l, --no-ld-path Do not set LD_LIBRARY_PATH
- -P, --no-progress Turn off the progress meter
- -q, --quiet Be less verbose (also passed to emerge command)
- -v, --verbose Be more verbose (also passed to emerge command)
-
-Calls emerge, options after -- are ignored by $APP_NAME
-and passed directly to emerge.
-
-Report bugs to <http://bugs.gentoo.org>
-
-EOF
-}
-##
-# Usage: progress i n
-# i: current item
-# n: total number of items to process
-progress() {
- if [[ -t 1 ]]; then
- progress() {
- local curProg=$(( $1 * 100 / $2 ))
- (( curProg == OLDPROG )) && return # no change, output nothing
- OLDPROG="$curProg" # must be a global variable
- (( $1 == $2 )) && local lb=$'\n'
- echo -ne '\r \r'"[ $curProg% ] $lb"
- }
- progress $@
- else # STDOUT is not a tty. Disable progress meter.
- progress() { :; }
- fi
-}
-##
-# Replace whitespace with linebreaks, normalize repeated '/' chars, and sort -u
-# (If any libs have whitespace in their filenames, someone needs punishment.)
-clean_var() {
- gawk 'BEGIN {RS="[[:space:]]"}
- /-\*/ {exit}
- /[^[:space:]]/ {gsub(/\/\/+/, "/"); print}' | sort -u
-}
-##
-# Exit and optionally output to sterr
-die() {
- local status=$1
- shift
-
- type eerror &> /dev/null
-
- if [[ $? -eq 0 ]];
- then
- eerror "$@"
- else
- echo " * ${@}" >> /dev/stderr
- fi
- exit $status
-}
-##
-# What to do when dynamic linking is consistent
-clean_exit() {
- echo
- einfo "$OK_TEXT... All done. "
- exit 0
-}
-##
-# Get the name of the package that owns a file or list of files given as args.
-# NOTE: depends on app-misc/realpath!
-get_file_owner() {
- local IFS=$'\n'
-
- rpath=$(realpath "${*}" 2>/dev/null)
- # To ensure we always have something in rpath...
- [[ -z $rpath ]] && rpath=${*}
-
- # Workaround for bug 280341
- mlib=$(echo ${*}|sed 's:/lib/:/lib64/:')
- [[ "${*}" == "${mlib}" ]] && mlib=$(echo ${*}|sed 's:/lib64/:/lib/:')
-
- # Add a space to the end of each object name to prevent false
- # matches, for example /usr/bin/dia matching /usr/bin/dialog (bug #196460).
- # The same for "${rpath} ".
- # Don't match an entry with a '-' at the start of the package name. This
- # prevents us from matching invalid -MERGING entries. (bug #338031)
- find -L /var/db/pkg -type f -name CONTENTS -print0 |
- xargs -0 grep -m 1 -Fl -e "${*} " -e "${rpath} " -e "${mlib} " |
- sed 's:/var/db/pkg/\(.*\)/\([^-].*\)/CONTENTS:\1/\2:'
-}
-##
-# Die if an argument is missing.
-die_if_missing_arg() {
- [[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1"
-}
-##
-# Die because an option is not recognized.
-die_invalid_option() {
- # Can't use eerror and einfo because this gets called before function.sh
- # is sourced
- echo
- echo "Encountered unrecognized option $1." >&2
- echo
- echo "$APP_NAME no longer automatically passes unrecognized options to portage."
- echo "Separate emerge-only options from revdep-rebuild options with the -- flag."
- echo
- echo "For example, $APP_NAME -v -- --ask"
- echo
- echo "See the man page or $APP_NAME -h for more detail."
- echo
- exit 1
-}
-##
-# Get whole-word commandline options preceded by two dashes.
-get_longopts() {
- case $1 in
- --debug) set -xv;;
- --help) print_usage
- exit 0;;
- --ignore) RM_OLD_TEMPFILES=1;;
- --library=*) SONAME="${1#*=}"
- unset SEARCH_BROKEN;;
- --library) die_if_missing_arg $1 $2
- shift
- SONAME="$1"
- unset SEARCH_BROKEN;;
- --no-ld-path) unset FULL_LD_PATH;;
- --no-progress) progress() { :; };;
- *) die_invalid_option $1;;
- esac
-}
-
-##
-# Get single-letter commandline options preceded by a single dash.
-get_shortopts() {
- local OPT OPTSTRING OPTARG OPTIND
- while getopts ":CdehikL:loPpqu:vX" OPT; do
- case "$OPT" in
- d) set -xv;;
- h) print_usage
- exit 0;;
- i) RM_OLD_TEMPFILES=1;;
- L) SONAME="${OPTARG#*=}"
- unset SEARCH_BROKEN;;
- l) unset FULL_LD_PATH;;
- P) progress() { :; };;
- *) die_invalid_option "-$OPTARG";;
- esac
- done
-}
-##
-# Get command-line options.
-get_opts() {
- local avoid_utils
- local -a args
- echo_v() { ewarn "$@"; }
- unset RM_OLD_TEMPFILES
- ORDER_PKGS=1
- SONAME="not found"
- SEARCH_BROKEN=1
- FULL_LD_PATH=1
- while [[ $1 ]]; do
- case $1 in
- -*) while true; do
- args+=("$1")
- shift
- [[ ${1:--} = -* ]] && break
- done
- if [[ ${args[0]} = --* ]]; then
- get_longopts "${args[@]}"
- else
- get_shortopts "${args[@]}"
- fi;;
- *) die_invalid_option "$1";;
- esac
- unset args
- done
-
- . /etc/init.d/functions.sh
-}
-##
-# Clean up temporary files and exit
-cleanup_and_die() {
- rm -f "$@"
- die 1 " ...terminated. Removing incomplete $@."
-}
-##
-# Clean trap
-clean_trap() {
- trap "cleanup_and_die $*" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
- rm -f "$@"
-}
-
-get_search_env() {
- local new_env
- WORKING_DIR="$(mktemp -d -t revdep-paxmark.XXXXXXXXXX)"
- cd ${WORKING_DIR}
-
- # From here on all work is done inside the temporary directory
-
- rm -f "${FILES[@]}"
-
- if [[ $SEARCH_BROKEN ]]; then
- SONAME_SEARCH="$SONAME"
- HEAD_TEXT="broken by a package update"
- OK_TEXT="Dynamic linking on your system is consistent"
- WORKING_TEXT="consistency"
- else
- # first case is needed to test against /path/to/foo.so
- if [[ $SONAME = /* ]]; then
- # Set to "<space>$SONAME<space>"
- SONAME_SEARCH=" $SONAME "
- # Escape the "/" characters
- SONAME_SEARCH="${SONAME_SEARCH//\//\\/}"
- else
- # Set to "<tab>$SONAME<space>"
- SONAME_SEARCH=$'\t'"$SONAME "
- fi
- HEAD_TEXT="using $SONAME"
- OK_TEXT="There are no dynamic links to $SONAME"
- unset WORKING_TEXT
- fi
-
- new_env=$(
- cat <<- EOF
- SEARCH_DIRS="$SEARCH_DIRS"
- SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK"
- LD_LIBRARY_MASK="$LD_LIBRARY_MASK"
- PORTAGE_ROOT="$PORTAGE_ROOT"
- ORDER_PKGS="$ORDER_PKGS"
- FULL_LD_PATH="$FULL_LD_PATH"
- EOF
- )
-
-
- echo "$new_env" > "$ENV_FILE"
-
- echo
- einfo "Checking reverse dependencies"
- einfo "Packages containing binaries and libraries $HEAD_TEXT"
- einfo "will be emerged."
-}
-
-get_files() {
- einfo "Collecting system binaries and libraries"
-
- clean_trap "$FILES_FILE"
-
- if [[ $SEARCH_DIRS_MASK ]]; then
- findMask=($SEARCH_DIRS_MASK)
- findMask="${findMask[@]/#/-o -path }"
- findMask="( ${findMask#-o } ) -prune -o"
- fi
- # TODO: Check this -- afaict SEARCH_DIRS isn't an array, so this should just be $SEARCH_DIRS?
- find ${SEARCH_DIRS[@]} $findMask -type f \( -perm -u+x -o -perm -g+x -o -perm -o+x -o \
- -name '*.so' -o -name '*.so.*' -o -name '*.la' \) -print 2> /dev/null |
- sort -u > "$FILES_FILE" ||
- die $? "find failed to list binary files (This is a bug.)"
- einfo "Generated new $FILES_FILE"
-}
-
-parse_ld_so_conf() {
- # FIXME: not safe for paths with spaces
- local include
- for path in $(sed '/^#/d;s/#.*$//' < /etc/ld.so.conf); do
- if [[ $include = true ]]; then
- for include_path in $(sed '/^#/d;s/#.*$//' /etc/${path} 2>/dev/null); do
- echo $include_path
- done
- include=""
- continue
- fi
- if [[ $path != include ]]; then
- echo $path
- else
- include="true"
- continue
- fi
- done
-}
-
-get_ldpath() {
- local COMPLETE_LD_LIBRARY_PATH
- [[ $SEARCH_BROKEN && $FULL_LD_PATH ]] || return
- einfo 'Collecting complete LD_LIBRARY_PATH'
-
- clean_trap "$LDPATH_FILE"
- # Ensure that the "trusted" lib directories are at the start of the path
- COMPLETE_LD_LIBRARY_PATH=(
- /lib*
- /usr/lib*
- $(parse_ld_so_conf)
- $(sed 's:/[^/]*$::' < "$FILES_FILE" | sort -ru)
- )
- IFS=':'
- COMPLETE_LD_LIBRARY_PATH="${COMPLETE_LD_LIBRARY_PATH[*]}"
- IFS="$OIFS"
- echo "$COMPLETE_LD_LIBRARY_PATH" > "$LDPATH_FILE"
- einfo "Generated new $LDPATH_FILE"
-}
-
-main_checks() {
- local target_file
- local -a files
- local i=0
- local ldd_output
- local ldd_status
- local numFiles
- local COMPLETE_LD_LIBRARY_PATH
-
- if [[ $SEARCH_BROKEN && $FULL_LD_PATH ]]; then
- [[ -r "$LDPATH_FILE" && -s "$LDPATH_FILE" ]] ||
- die 1 "Unable to find $LDPATH_FILE"
- COMPLETE_LD_LIBRARY_PATH=$(<"$LDPATH_FILE")
- fi
-
- einfo "Checking dynamic linking $WORKING_TEXT"
-
- clean_trap "$BROKEN_FILE" "$ERRORS_FILE"
- files=($(<"$FILES_FILE"))
- numFiles="${#files[@]}"
- for target_file in "${files[@]}"; do
- if [[ $target_file != *.la ]]; then
- # Note: double checking seems to be faster than single with complete path
- # (special add ons are rare).
- ldd_output=$(ldd "$target_file" 2>> "$ERRORS_FILE" | sort -u)
- ldd_status=$? # TODO: Check this for problems with sort
- # HACK: if LD_LIBRARY_MASK is null or undefined grep -vF doesn't work
- if grep -vF "${LD_LIBRARY_MASK:=$'\a'}" <<< "$ldd_output" |
- grep -q -E "$SONAME_SEARCH"; then
- if [[ $SEARCH_BROKEN && $FULL_LD_PATH ]]; then
- if LD_LIBRARY_PATH="$COMPLETE_LD_LIBRARY_PATH" ldd "$target_file" 2>/dev/null |
- grep -vF "$LD_LIBRARY_MASK" | grep -q -E "$SONAME_SEARCH"; then
- # FIXME: I hate duplicating code
- # Only build missing direct dependencies
- MISSING_LIBS=$(
- expr='s/[[:space:]]*\([^[:space:]]*\) => not found/\1/p'
- sed -n "$expr" <<< "$ldd_output"
- )
- REQUIRED_LIBS=$(
- expr='s/^[[:space:]]*NEEDED[[:space:]]*\([^[:space:]]*\).*/\1/p';
- objdump -x "$target_file" | grep NEEDED | sed "$expr" | sort -u
- )
- MISSING_LIBS=$(grep -F "$REQUIRED_LIBS" <<< "$MISSING_LIBS")
- if [[ $MISSING_LIBS ]]; then
- echo "obj $target_file" >> "$BROKEN_FILE"
- echo_v " broken $target_file (requires $MISSING_LIBS)"
- fi
- fi
- else
- # FIXME: I hate duplicating code
- # Only rebuild for direct dependencies
- MISSING_LIBS=$(
- expr="s/^[[:space:]]*\([^[:space:]]*\).*$/\1/p"
- sort -u <<< "$ldd_output" | grep -E "$SONAME" | sed -n "$expr"
- )
- REQUIRED_LIBS=$(
- expr='s/^[[:space:]]*NEEDED[[:space:]]*\([^[:space:]]*\).*/\1/p';
- objdump -x "$target_file" | grep NEEDED | sed "$expr" | sort -u
- )
- MISSING_LIBS=$(grep -F "$REQUIRED_LIBS" <<< "$MISSING_LIBS")
- if [[ $MISSING_LIBS ]]; then
- echo "obj $target_file" >> "$BROKEN_FILE"
- if [[ $SEARCH_BROKEN ]]; then
- echo_v " broken $target_file (requires $MISSING_LIBS)"
- else
- echo_v " found $target_file"
- fi
- fi
- fi
- fi
- elif [[ $SEARCH_BROKEN ]]; then
- # Look for broken .la files
- la_SEARCH_DIRS="$SEARCH_DIRS"
- la_search_dir=""
- la_broken=""
- la_lib=""
- for depend in $(
- gawk -F"[=']" '/^dependency_libs/{
- print $3
- }' "$target_file"
- ); do
- if [[ $depend = /* && ! -e $depend ]]; then
- echo "obj $target_file" >> "$BROKEN_FILE"
- echo_v " broken $target_file (requires $depend)"
- elif [[ $depend = -[LR]/* ]]; then
- if ! [[ $'\n'${la_SEARCH_DIRS}$'\n' == *$'\n'${depend#-?}$'\n'* ]]; then
- la_SEARCH_DIRS+=$'\n'"${depend#-?}"
- fi
- elif [[ $depend = "-l"* ]]; then
- la_lib="lib${depend#-l}"
- la_broken="yes"
- IFS=$'\n'
- for la_search_dir in $la_SEARCH_DIRS; do
- if [[ -e ${la_search_dir}/${la_lib}.so || -e ${la_search_dir}/${la_lib}.a ]]; then
- la_broken="no"
- fi
- done
- IFS="$OIFS"
- if [[ $la_broken = yes ]]; then
- echo "obj $target_file" >> "$BROKEN_FILE"
- echo_v " broken $target_file (requires $depend)"
- fi
- fi
- done
- unset la_SEARCH_DIRS la_search_dir la_broken la_lib
- fi
- progress $((++i)) $numFiles
- done
-
- if [[ $SEARCH_BROKEN && -f $ERRORS_FILE ]]; then
- # Look for missing version
- while read target_file; do
- echo "obj $target_file" >> "$BROKEN_FILE"
- echo_v " broken $target_file (no version information available)"
- done < <(
- # Regexify LD_LIBRARY_MASK. Exclude it from the search.
- LD_LIBRARY_MASK="${LD_LIBRARY_MASK//$'\n'/|}"
- gawk -v ldmask="(${LD_LIBRARY_MASK//./\\\.})" '
- /no version information available/ && $0 !~ ldmask {
- gsub(/[()]/, "", $NF)
- if (seen[$NF]++) next
- print $NF
- }' "$ERRORS_FILE"
- )
- fi
-
- [[ -r "$BROKEN_FILE" && -s "$BROKEN_FILE" ]] || clean_exit
- sort -u "$BROKEN_FILE" -o "$BROKEN_FILE"
-
- einfo "Generated new $BROKEN_FILE"
-}
-
-
-# Get multiple portage variables at once to speedup revdep-rebuild.
-portage_settings() {
- local ORIG_SEARCH_DIRS="$SEARCH_DIRS"
- local ORIG_SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK"
- local ORIG_LD_LIBRARY_MASK="$LD_LIBRARY_MASK"
- unset SEARCH_DIRS
- unset SEARCH_DIRS_MASK
- unset LD_LIBRARY_MASK
-
- eval $(portageq envvar -v PORTAGE_ROOT PORTAGE_NICENESS EMERGE_DEFAULT_OPTS SEARCH_DIRS SEARCH_DIRS_MASK LD_LIBRARY_MASK)
-
- SEARCH_DIRS="$ORIG_SEARCH_DIRS $SEARCH_DIRS"
- SEARCH_DIRS_MASK="$ORIG_SEARCH_DIRS_MASK $SEARCH_DIRS_MASK"
- LD_LIBRARY_MASK="$ORIG_LD_LIBRARY_MASK $LD_LIBRARY_MASK"
-}
-
-##
-# Setup the paths to search (and filter the ones to avoid)
-setup_search_paths_and_masks() {
- local configfile sdir mdir skip_me filter_SEARCH_DIRS
-
- einfo "Configuring search environment for $APP_NAME"
-
- # Update the incremental variables using /etc/profile.env, /etc/ld.so.conf,
- # portage, and the environment
-
- # Read the incremental variables from environment and portage
- # Until such time as portage supports these variables as incrementals
- # The value will be what is in /etc/make.conf
-# SEARCH_DIRS+=" "$(unset SEARCH_DIRS; portageq envvar SEARCH_DIRS)
-# SEARCH_DIRS_MASK+=" "$(unset SEARCH_DIRS_MASK; portageq envvar SEARCH_DIRS_MASK)
-# LD_LIBRARY_MASK+=" "$(unset LD_LIBRARY_MASK; portageq envvar LD_LIBRARY_MASK)
-
- # Add the defaults
- if [[ -d /etc/revdep-rebuild ]]; then
- for configfile in /etc/revdep-rebuild/*; do
- SEARCH_DIRS+=" "$(. $configfile; echo $SEARCH_DIRS)
- SEARCH_DIRS_MASK+=" "$(. $configfile; echo $SEARCH_DIRS_MASK)
- LD_LIBRARY_MASK+=" "$(. $configfile; echo $LD_LIBRARY_MASK)
- done
- else
- SEARCH_DIRS+=" /bin /sbin /usr/bin /usr/sbin /lib* /usr/lib*"
- SEARCH_DIRS_MASK+=" /opt/OpenOffice /usr/lib/openoffice"
- LD_LIBRARY_MASK+=" libodbcinst.so libodbc.so libjava.so libjvm.so"
- fi
-
- # Get the ROOTPATH and PATH from /etc/profile.env
- if [[ -r "/etc/profile.env" && -s "/etc/profile.env" ]]; then
- SEARCH_DIRS+=" "$(. /etc/profile.env; /usr/bin/tr ':' ' ' <<< "$ROOTPATH $PATH")
- fi
-
- # Get the directories from /etc/ld.so.conf
- if [[ -r /etc/ld.so.conf && -s /etc/ld.so.conf ]]; then
- SEARCH_DIRS+=" "$(parse_ld_so_conf)
- fi
-
- # Set the final variables
- SEARCH_DIRS=$(clean_var <<< "$SEARCH_DIRS")
- SEARCH_DIRS_MASK=$(clean_var <<< "$SEARCH_DIRS_MASK")
- LD_LIBRARY_MASK=$(clean_var <<< "$LD_LIBRARY_MASK")
- # Filter masked paths from SEARCH_DIRS
- for sdir in ${SEARCH_DIRS} ; do
- skip_me=
- for mdir in ${SEARCH_DIRS_MASK}; do
- [[ ${sdir} == ${mdir}/* ]] && skip_me=1 && break
- done
- [[ -n ${skip_me} ]] || filter_SEARCH_DIRS+=" ${sdir}"
- done
- SEARCH_DIRS=$(clean_var <<< "${filter_SEARCH_DIRS}")
- [[ $SEARCH_DIRS ]] || die 1 "No search defined -- this is a bug."
-}
-##
-# Finish up
-cleanup() {
- trap_cmd() {
- eerror "terminated. Please remove the temporary files manually:"
- eerror "rm ${WORKING_DIR}/*.rr"
- exit 1
- }
- trap trap_cmd SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
-}
-
-main "$@"
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 52380bd399798c63b9a4093072987bc64d417940
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 03:13:28 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=52380bd3
scripts/paxmodule.c: stub python binding for paxctl
---
scripts/paxmodule.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
scripts/revdep-pax | 3 +++
scripts/setup.py | 19 +++++++++++++++++++
3 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
new file mode 100644
index 0000000..03ba794
--- /dev/null
+++ b/scripts/paxmodule.c
@@ -0,0 +1,47 @@
+#include <Python.h>
+
+static PyObject * pax_getflags(PyObject *, PyObject *);
+
+static PyMethodDef PaxMethods[] = {
+ {"getflags", pax_getflags, METH_VARARGS, "Get the pax flags."},
+ {NULL, NULL, 0, NULL}
+};
+
+static PyObject *PaxError;
+
+PyMODINIT_FUNC
+initpax(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule("pax", PaxMethods);
+ if (m == NULL)
+ return;
+
+ PaxError = PyErr_NewException("pax.error", NULL, NULL);
+ Py_INCREF(PaxError);
+ PyModule_AddObject(m, "error", PaxError);
+}
+
+
+static PyObject *
+pax_getflags(PyObject *self, PyObject *args)
+{
+ const char *value;
+ int sts;
+
+ if (!PyArg_ParseTuple(args, "s", &value))
+ return NULL;
+
+ printf("%s\n", value);
+
+ sts = 1;
+
+ if (sts < 0)
+ {
+ PyErr_SetString(PaxError, "pax_getflags failed");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", sts);
+}
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 75e833a..ac21bae 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -4,6 +4,8 @@ from os import listdir
#from os import path
import re
+import pax
+
var_db_pkg = '/var/db/pkg'
binaries = {}
@@ -21,6 +23,7 @@ for cat in listdir(var_db_pkg):
binary = linking[0]
print binary
library_list = re.split(',', linking[1])
+ print "\t%s" % library_list
binaries[binary] = library_list
except:
break
diff --git a/scripts/setup.py b/scripts/setup.py
new file mode 100755
index 0000000..317efbd
--- /dev/null
+++ b/scripts/setup.py
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+from distutils.core import setup, Extension
+
+module1 = Extension(
+ name='pax',
+ sources = ['paxmodule.c']
+)
+
+setup(
+ name = 'PaxPython',
+ version = '1.0',
+ author = 'Anthony G. Basile',
+ author_email = 'blueness@gentoo.org',
+ url = 'http://dev.gentoo.org/~blueness/elfix',
+ description = 'This is bindings between paxctl and python',
+ license = 'GPL-2',
+ ext_modules = [module1]
+)
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 9c56db5076568f722b8745808e3970f4573520a2
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 04:19:08 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=9c56db50
scripts/paxmodule.c: return pax flags as string
---
scripts/paxmodule.c | 46 ++++++++++++++++++++++++----------------------
1 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 1b3e1eb..927bb50 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -54,17 +54,16 @@ pax_getflags(PyObject *self, PyObject *args)
int fd, sts;
Elf *elf;
+ char pax_buf[BUF_SIZE];
+
GElf_Ehdr ehdr;
- char ei_buf[BUF_SIZE];
uint16_t ei_flags;
GElf_Phdr phdr;
- char pt_buf[BUF_SIZE];
char found_pt_pax;
size_t i, phnum;
- memset(ei_buf, 0, BUF_SIZE);
- memset(pt_buf, 0, BUF_SIZE);
+ memset(pax_buf, 0, BUF_SIZE);
if (!PyArg_ParseTuple(args, "s", &f_name))
{
@@ -86,12 +85,15 @@ pax_getflags(PyObject *self, PyObject *args)
if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
{
+ close(fd);
PyErr_SetString(PaxError, "pax_getflags: elf_begin() failed");
return NULL;
}
if(elf_kind(elf) != ELF_K_ELF)
{
+ elf_end(elf);
+ close(fd);
PyErr_SetString(PaxError, "pax_getflags: elf_kind() failed: this is not an elf file.");
return NULL;
}
@@ -103,6 +105,8 @@ pax_getflags(PyObject *self, PyObject *args)
{
if(gelf_getphdr(elf, i, &phdr) != &phdr)
{
+ elf_end(elf);
+ close(fd);
PyErr_SetString(PaxError, "pax_getflags: gelf_getphdr() failed");
return NULL;
}
@@ -111,50 +115,48 @@ pax_getflags(PyObject *self, PyObject *args)
{
found_pt_pax = 1;
- pt_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
+ pax_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
phdr.p_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
- pt_buf[1] = phdr.p_flags & PF_SEGMEXEC ? 'S' :
+ pax_buf[1] = phdr.p_flags & PF_SEGMEXEC ? 'S' :
phdr.p_flags & PF_NOSEGMEXEC ? 's' : '-';
- pt_buf[2] = phdr.p_flags & PF_MPROTECT ? 'M' :
+ pax_buf[2] = phdr.p_flags & PF_MPROTECT ? 'M' :
phdr.p_flags & PF_NOMPROTECT ? 'm' : '-';
- pt_buf[3] = phdr.p_flags & PF_EMUTRAMP ? 'E' :
+ pax_buf[3] = phdr.p_flags & PF_EMUTRAMP ? 'E' :
phdr.p_flags & PF_NOEMUTRAMP ? 'e' : '-';
- pt_buf[4] = phdr.p_flags & PF_RANDMMAP ? 'R' :
+ pax_buf[4] = phdr.p_flags & PF_RANDMMAP ? 'R' :
phdr.p_flags & PF_NORANDMMAP ? 'r' : '-';
- pt_buf[5] = phdr.p_flags & PF_RANDEXEC ? 'X' :
+ pax_buf[5] = phdr.p_flags & PF_RANDEXEC ? 'X' :
phdr.p_flags & PF_NORANDEXEC ? 'x' : '-';
}
}
- if(found_pt_pax)
- printf("PT_PAX: %s\n", pt_buf);
- else
+ if(!found_pt_pax)
{
if(gelf_getehdr(elf, &ehdr) != &ehdr)
{
+ elf_end(elf);
+ close(fd);
PyErr_SetString(PaxError, "pax_getflags: gelf_getehdr() failed");
return NULL;
}
ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
- ei_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
- ei_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
- ei_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
- ei_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
- ei_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
- ei_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
-
- printf("EI_PAX: %s\n", ei_buf);
+ pax_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
+ pax_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
+ pax_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
+ pax_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
+ pax_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
+ pax_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
}
elf_end(elf);
close(fd);
- return Py_BuildValue("i", sts);
+ return Py_BuildValue("s", pax_buf);
}
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: caa17d7d9e10e0ef49b3df0d0bf1ceb007dd64d5
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 04:07:33 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=caa17d7d
scripts/paxmodule.c: add code to read pax flags
---
scripts/paxmodule.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++---
scripts/setup.py | 3 +-
2 files changed, 122 insertions(+), 8 deletions(-)
diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 03ba794..1b3e1eb 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -1,5 +1,28 @@
#include <Python.h>
+#include <stdio.h> //remove when you remove printf
+#include <string.h>
+
+#include <gelf.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+
+#define HF_PAX_PAGEEXEC 1
+#define HF_PAX_EMUTRAMP 2
+#define HF_PAX_MPROTECT 4
+#define HF_PAX_RANDMMAP 8
+#define HF_PAX_RANDEXEC 16
+#define HF_PAX_SEGMEXEC 32
+
+#define EI_PAX 14 // Index to read the PaX flags into ELF header e_ident[] array
+
+#define BUF_SIZE 7 //Buffer for holding human readable flags
+
+
static PyObject * pax_getflags(PyObject *, PyObject *);
static PyMethodDef PaxMethods[] = {
@@ -27,21 +50,111 @@ initpax(void)
static PyObject *
pax_getflags(PyObject *self, PyObject *args)
{
- const char *value;
- int sts;
+ const char *f_name;
+ int fd, sts;
+ Elf *elf;
+
+ GElf_Ehdr ehdr;
+ char ei_buf[BUF_SIZE];
+ uint16_t ei_flags;
+
+ GElf_Phdr phdr;
+ char pt_buf[BUF_SIZE];
+ char found_pt_pax;
+ size_t i, phnum;
+
+ memset(ei_buf, 0, BUF_SIZE);
+ memset(pt_buf, 0, BUF_SIZE);
- if (!PyArg_ParseTuple(args, "s", &value))
+ if (!PyArg_ParseTuple(args, "s", &f_name))
+ {
+ PyErr_SetString(PaxError, "pax_getflags: PyArg_ParseTuple failed");
return NULL;
+ }
- printf("%s\n", value);
+ if(elf_version(EV_CURRENT) == EV_NONE)
+ {
+ PyErr_SetString(PaxError, "pax_getflags: library out of date");
+ return NULL;
+ }
- sts = 1;
+ if((fd = open(f_name, O_RDONLY)) < 0)
+ {
+ PyErr_SetString(PaxError, "pax_getflags: open() failed");
+ return NULL;
+ }
- if (sts < 0)
+ if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
{
- PyErr_SetString(PaxError, "pax_getflags failed");
+ PyErr_SetString(PaxError, "pax_getflags: elf_begin() failed");
return NULL;
}
+ if(elf_kind(elf) != ELF_K_ELF)
+ {
+ PyErr_SetString(PaxError, "pax_getflags: elf_kind() failed: this is not an elf file.");
+ return NULL;
+ }
+
+
+ found_pt_pax = 0;
+ elf_getphdrnum(elf, &phnum);
+ for(i=0; i<phnum; ++i)
+ {
+ if(gelf_getphdr(elf, i, &phdr) != &phdr)
+ {
+ PyErr_SetString(PaxError, "pax_getflags: gelf_getphdr() failed");
+ return NULL;
+ }
+
+ if(phdr.p_type == PT_PAX_FLAGS)
+ {
+ found_pt_pax = 1;
+
+ pt_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
+ phdr.p_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
+
+ pt_buf[1] = phdr.p_flags & PF_SEGMEXEC ? 'S' :
+ phdr.p_flags & PF_NOSEGMEXEC ? 's' : '-';
+
+ pt_buf[2] = phdr.p_flags & PF_MPROTECT ? 'M' :
+ phdr.p_flags & PF_NOMPROTECT ? 'm' : '-';
+
+ pt_buf[3] = phdr.p_flags & PF_EMUTRAMP ? 'E' :
+ phdr.p_flags & PF_NOEMUTRAMP ? 'e' : '-';
+
+ pt_buf[4] = phdr.p_flags & PF_RANDMMAP ? 'R' :
+ phdr.p_flags & PF_NORANDMMAP ? 'r' : '-';
+
+ pt_buf[5] = phdr.p_flags & PF_RANDEXEC ? 'X' :
+ phdr.p_flags & PF_NORANDEXEC ? 'x' : '-';
+ }
+ }
+
+ if(found_pt_pax)
+ printf("PT_PAX: %s\n", pt_buf);
+ else
+ {
+ if(gelf_getehdr(elf, &ehdr) != &ehdr)
+ {
+ PyErr_SetString(PaxError, "pax_getflags: gelf_getehdr() failed");
+ return NULL;
+ }
+
+ ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+
+ ei_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
+ ei_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
+ ei_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
+ ei_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
+ ei_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
+ ei_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
+
+ printf("EI_PAX: %s\n", ei_buf);
+ }
+
+ elf_end(elf);
+ close(fd);
+
return Py_BuildValue("i", sts);
}
diff --git a/scripts/setup.py b/scripts/setup.py
index 317efbd..77854f1 100755
--- a/scripts/setup.py
+++ b/scripts/setup.py
@@ -4,7 +4,8 @@ from distutils.core import setup, Extension
module1 = Extension(
name='pax',
- sources = ['paxmodule.c']
+ sources = ['paxmodule.c'],
+ libraries = ['elf'],
)
setup(
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 2895c2b55d7ceb4e9ab6d202c786d8bfbf5b6c90
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 02:20:09 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=2895c2b5
scripts/revdep-pax: python rewrite of revdep-paxmark
---
scripts/revdep-pax | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
new file mode 100755
index 0000000..75e833a
--- /dev/null
+++ b/scripts/revdep-pax
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+from os import listdir
+#from os import path
+import re
+
+var_db_pkg = '/var/db/pkg'
+
+binaries = {}
+for cat in listdir(var_db_pkg):
+ catdir = '%s/%s' % (var_db_pkg, cat)
+ for pkg in listdir(catdir):
+ pkgdir = '%s/%s' % (catdir, pkg)
+ need = '%s/%s' % (pkgdir, 'NEEDED')
+ try:
+ g = open(need, 'r')
+ needs = g.readlines()
+ for line in needs:
+ line = line.strip()
+ linking = re.split('\s', line)
+ binary = linking[0]
+ print binary
+ library_list = re.split(',', linking[1])
+ binaries[binary] = library_list
+ except:
+ break
+
+""" Print out mapping: binary -> library, library, library ...
+for binary in binaries:
+ print binary
+ for library in binaries[binary]:
+ print "\t", library
+"""
+
+libraries = {}
+for binary in binaries:
+ for library in binaries[binary]:
+ libraries[library] = []
+
+for binary in binaries:
+ for library in binaries[binary]:
+ libraries[library].append(binary)
+
+""" Print out mapping: library -> binary, binary, binary ...
+for library in libraries:
+ print library
+ for binary in libraries[library]:
+ print "\t", binary
+ #if not path.exists(binary):
+ # print "%s doesn't exist!" % binary
+"""
+
+
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 1c3eb9ed50bc21b46ac4eb75a96a565163bc5b43
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 19:46:25 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=1c3eb9ed
scripts/revdep-pax: organize into functions
---
scripts/revdep-pax | 89 ++++++++++++++++++++++++++++------------------------
1 files changed, 48 insertions(+), 41 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index ac21bae..df78e35 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -1,56 +1,63 @@
#!/usr/bin/env python
from os import listdir
-#from os import path
+#from os import listdir, path
import re
import pax
-var_db_pkg = '/var/db/pkg'
-
-binaries = {}
-for cat in listdir(var_db_pkg):
- catdir = '%s/%s' % (var_db_pkg, cat)
- for pkg in listdir(catdir):
- pkgdir = '%s/%s' % (catdir, pkg)
- need = '%s/%s' % (pkgdir, 'NEEDED')
- try:
- g = open(need, 'r')
- needs = g.readlines()
- for line in needs:
- line = line.strip()
- linking = re.split('\s', line)
- binary = linking[0]
- print binary
- library_list = re.split(',', linking[1])
- print "\t%s" % library_list
- binaries[binary] = library_list
- except:
- break
-""" Print out mapping: binary -> library, library, library ...
-for binary in binaries:
- print binary
- for library in binaries[binary]:
- print "\t", library
-"""
+def forward_linkings():
+ var_db_pkg = '/var/db/pkg'
+ elf_objects = {}
+ for cat in listdir(var_db_pkg):
+ catdir = '%s/%s' % (var_db_pkg, cat)
+ for pkg in listdir(catdir):
+ pkgdir = '%s/%s' % (catdir, pkg)
+ need = '%s/%s' % (pkgdir, 'NEEDED')
+ try:
+ g = open(need, 'r')
+ needs = g.readlines()
+ for line in needs:
+ line = line.strip()
+ linking = re.split('\s', line)
+ elf = linking[0]
+ elf_deps = re.split(',', linking[1])
+ elf_objects[elf] = elf_deps
+ except:
+ break
+
+ return elf_objects
+
+
+def reverse_linkings( binaries ):
+ libraries = {}
+ for binary in binaries:
+ for library in binaries[binary]:
+ libraries[library] = []
+
+ for binary in binaries:
+ for library in binaries[binary]:
+ libraries[library].append(binary)
-libraries = {}
-for binary in binaries:
- for library in binaries[binary]:
- libraries[library] = []
+ return libraries
-for binary in binaries:
- for library in binaries[binary]:
- libraries[library].append(binary)
+
+elf_objects = forward_linkings()
+elf_deps = reverse_linkings( elf_objects )
+
+""" Print out mapping: binary -> library, library, library ...
+for elf in elf_objects:
+ print elf
+ for elf_deps in elf_objects[elf]:
+ print "\t", elf_deps
+"""
""" Print out mapping: library -> binary, binary, binary ...
-for library in libraries:
- print library
- for binary in libraries[library]:
- print "\t", binary
+for elf in elf_deps:
+ print elf
+ for elf_object in elf_deps[elf]:
+ print "\t", elf_object
#if not path.exists(binary):
# print "%s doesn't exist!" % binary
"""
-
-
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 4c3d4391e72ef87793564a31cec20a32c7ce9b2f
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 23:39:08 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=4c3d4391
scripts/revdep-pax: add soname to real file mappings
---
scripts/revdep-pax | 32 +++++++++++++++++++++++++++-----
1 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 697a41d..4873518 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -1,18 +1,17 @@
#!/usr/bin/env python
-from os import listdir
-#from os import listdir, path
+import os
+import subprocess
import re
-
import pax
def get_forward_linkings():
var_db_pkg = '/var/db/pkg'
forward_linkings = {}
- for cat in listdir(var_db_pkg):
+ for cat in os.listdir(var_db_pkg):
catdir = '%s/%s' % (var_db_pkg, cat)
- for pkg in listdir(catdir):
+ for pkg in os.listdir(catdir):
pkgdir = '%s/%s' % (catdir, pkg)
need = '%s/%s' % (pkgdir, 'NEEDED')
try:
@@ -43,8 +42,26 @@ def invert_linkings( forward_linkings ):
return reverse_linkings
+def get_soname2file_mappings():
+ ldconfig_output = subprocess.check_output(["/sbin/ldconfig", "-p"])
+ ldconfig_lines = ldconfig_output.split('\n')
+ ldconfig_lines.pop(0) #first line is a header
+ ldconfig_lines.pop() #last line empty because of previous split
+ mappings = {}
+ for m in range(0,len(ldconfig_lines)):
+ ldconfig_lines[m] = ldconfig_lines[m].strip()
+ mapp = re.split('=>', ldconfig_lines[m] )
+ soname = re.sub('\(.*$', '', mapp[0]).strip()
+ abi = re.search('\(.+\)', mapp[0]).group(0)
+ abi = abi.strip().strip('(').strip(')').strip()
+ filename = mapp[1].strip()
+ filename = os.path.realpath(filename)
+ mappings[soname] = [ filename, pax.getflags(filename), abi ]
+ return mappings
+
forward_linkings = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
+soname2file_mappings = get_soname2file_mappings()
""" Print out mapping: binary -> library, library, library ... """
@@ -52,6 +69,7 @@ for elf in forward_linkings:
print elf
for elf_dep in forward_linkings[elf]:
print "\t", elf_dep
+ #print "\t\t", soname2file_mappings[elf_dep]
raw_input()
@@ -62,3 +80,7 @@ for elf_dep in reverse_linkings:
print "\t", elf
#if not path.exists(elf):
# print "%s doesn't exist!" % elf
+raw_input()
+
+for s in soname2file_mappings:
+ print s, soname2file_mappings[s]
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: a8b83eba788dc6512aaf103ad271d6990dd21359
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 7 01:56:14 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=a8b83eba
scripts/revdep-pax: use ldd to get mappings rather than NEEDS
---
scripts/revdep-pax | 39 +++++++++++++++++++++++++++++++++++----
1 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 4873518..1a5a2bb 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -5,6 +5,25 @@ import subprocess
import re
import pax
+def get_ldd_linkings(elf):
+ try:
+ ldd_output = subprocess.check_output(["/usr/bin/ldd", elf])
+ except:
+ return []
+ ldd_lines = ldd_output.split('\n')
+ linkings = []
+ for m in range(0,len(ldd_lines)):
+ if not re.search('=>', ldd_lines[m]):
+ continue
+ ldd_lines[m] = ldd_lines[m].strip()
+ mapp = re.split('=>', ldd_lines[m] )
+ soname = mapp[0].strip()
+ filename = re.sub('\(.*$', '', mapp[1]).strip()
+ if filename == '':
+ continue
+ filename = os.path.realpath(filename)
+ linkings.append(soname)
+ return linkings
def get_forward_linkings():
var_db_pkg = '/var/db/pkg'
@@ -21,7 +40,8 @@ def get_forward_linkings():
line = line.strip()
link = re.split('\s', line)
elf = link[0]
- linkings = re.split(',', link[1])
+ linkings = get_ldd_linkings(elf)
+ #linkings = re.split(',', link[1]) #this uses NEEDS to determine linkage
forward_linkings[elf] = linkings
except:
break
@@ -46,7 +66,7 @@ def get_soname2file_mappings():
ldconfig_output = subprocess.check_output(["/sbin/ldconfig", "-p"])
ldconfig_lines = ldconfig_output.split('\n')
ldconfig_lines.pop(0) #first line is a header
- ldconfig_lines.pop() #last line empty because of previous split
+ ldconfig_lines.pop() #last line empty because of previous split
mappings = {}
for m in range(0,len(ldconfig_lines)):
ldconfig_lines[m] = ldconfig_lines[m].strip()
@@ -65,15 +85,25 @@ soname2file_mappings = get_soname2file_mappings()
""" Print out mapping: binary -> library, library, library ... """
+unmapped = []
for elf in forward_linkings:
print elf
for elf_dep in forward_linkings[elf]:
print "\t", elf_dep
- #print "\t\t", soname2file_mappings[elf_dep]
+ #try:
+ # print "\t\t", soname2file_mappings[elf_dep]
+ #except:
+ # unmapped.append(elf_dep)
+ # print "%s doesn't have a mapping" % elf_dep
raw_input()
-""" Print out mapping: library -> binary, binary, binary ... """
+print unmapped
+
+raw_input()
+
+
+""" Print out mapping: library -> binary, binary, binary ...
for elf_dep in reverse_linkings:
print elf_dep
for elf in reverse_linkings[elf_dep]:
@@ -84,3 +114,4 @@ raw_input()
for s in soname2file_mappings:
print s, soname2file_mappings[s]
+"""
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 2abc34b0c8c5774351d492c572db652acf2313bd
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 6 20:14:11 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=2abc34b0
scripts/revdep-pax: improved variable names
---
scripts/revdep-pax | 63 ++++++++++++++++++++++++++-------------------------
1 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index df78e35..697a41d 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -7,9 +7,9 @@ import re
import pax
-def forward_linkings():
+def get_forward_linkings():
var_db_pkg = '/var/db/pkg'
- elf_objects = {}
+ forward_linkings = {}
for cat in listdir(var_db_pkg):
catdir = '%s/%s' % (var_db_pkg, cat)
for pkg in listdir(catdir):
@@ -20,44 +20,45 @@ def forward_linkings():
needs = g.readlines()
for line in needs:
line = line.strip()
- linking = re.split('\s', line)
- elf = linking[0]
- elf_deps = re.split(',', linking[1])
- elf_objects[elf] = elf_deps
+ link = re.split('\s', line)
+ elf = link[0]
+ linkings = re.split(',', link[1])
+ forward_linkings[elf] = linkings
except:
break
- return elf_objects
+ return forward_linkings
-def reverse_linkings( binaries ):
- libraries = {}
- for binary in binaries:
- for library in binaries[binary]:
- libraries[library] = []
+def invert_linkings( forward_linkings ):
+ reverse_linkings = {}
+ for elf in forward_linkings:
+ for elf_dep in forward_linkings[elf]:
+ reverse_linkings[elf_dep] = []
- for binary in binaries:
- for library in binaries[binary]:
- libraries[library].append(binary)
+ for elf in forward_linkings:
+ for elf_dep in forward_linkings[elf]:
+ reverse_linkings[elf_dep].append(elf)
- return libraries
+ return reverse_linkings
-elf_objects = forward_linkings()
-elf_deps = reverse_linkings( elf_objects )
+forward_linkings = get_forward_linkings()
+reverse_linkings = invert_linkings( forward_linkings )
-""" Print out mapping: binary -> library, library, library ...
-for elf in elf_objects:
- print elf
- for elf_deps in elf_objects[elf]:
- print "\t", elf_deps
-"""
-""" Print out mapping: library -> binary, binary, binary ...
-for elf in elf_deps:
+""" Print out mapping: binary -> library, library, library ... """
+for elf in forward_linkings:
print elf
- for elf_object in elf_deps[elf]:
- print "\t", elf_object
- #if not path.exists(binary):
- # print "%s doesn't exist!" % binary
-"""
+ for elf_dep in forward_linkings[elf]:
+ print "\t", elf_dep
+
+raw_input()
+
+""" Print out mapping: library -> binary, binary, binary ... """
+for elf_dep in reverse_linkings:
+ print elf_dep
+ for elf in reverse_linkings[elf_dep]:
+ print "\t", elf
+ #if not path.exists(elf):
+ # print "%s doesn't exist!" % elf
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 2108c02cba18bace8f65c768f0d7f3213e56b409
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 7 19:58:34 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=2108c02c
scripts/revdep-pax: use ldd instead of ldconfig to get so2filename mappings
---
scripts/revdep-pax | 130 +++++++++++++++++++++++++++++++--------------------
1 files changed, 79 insertions(+), 51 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 1a5a2bb..48b11d4 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -7,27 +7,34 @@ import pax
def get_ldd_linkings(elf):
try:
- ldd_output = subprocess.check_output(["/usr/bin/ldd", elf])
+ #When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
+ ldd_output = subprocess.check_output(['/usr/bin/ldd', elf], stderr=subprocess.PIPE)
except:
return []
ldd_lines = ldd_output.split('\n')
linkings = []
+ mappings = []
for m in range(0,len(ldd_lines)):
if not re.search('=>', ldd_lines[m]):
continue
ldd_lines[m] = ldd_lines[m].strip()
mapp = re.split('=>', ldd_lines[m] )
soname = mapp[0].strip()
+ soname = os.path.basename(soname) # This is for ./libSDL-1.2.so.0
filename = re.sub('\(.*$', '', mapp[1]).strip()
if filename == '':
continue
- filename = os.path.realpath(filename)
+ filename = os.path.realpath(filename)
linkings.append(soname)
- return linkings
+ mappings.append([soname,filename])
+ return ( linkings, mappings )
+
def get_forward_linkings():
+ """ I'm still not sure we wan to use /var/db/pkg vs some path of binaries """
var_db_pkg = '/var/db/pkg'
forward_linkings = {}
+ so2filename_mappings = {}
for cat in os.listdir(var_db_pkg):
catdir = '%s/%s' % (var_db_pkg, cat)
for pkg in os.listdir(catdir):
@@ -40,13 +47,14 @@ def get_forward_linkings():
line = line.strip()
link = re.split('\s', line)
elf = link[0]
- linkings = get_ldd_linkings(elf)
- #linkings = re.split(',', link[1]) #this uses NEEDS to determine linkage
+ ( linkings, mappings ) = get_ldd_linkings(elf)
forward_linkings[elf] = linkings
+ for m in mappings:
+ so2filename_mappings[m[0]] = m[1]
except:
break
- return forward_linkings
+ return ( forward_linkings, so2filename_mappings )
def invert_linkings( forward_linkings ):
@@ -62,56 +70,76 @@ def invert_linkings( forward_linkings ):
return reverse_linkings
-def get_soname2file_mappings():
- ldconfig_output = subprocess.check_output(["/sbin/ldconfig", "-p"])
- ldconfig_lines = ldconfig_output.split('\n')
- ldconfig_lines.pop(0) #first line is a header
- ldconfig_lines.pop() #last line empty because of previous split
- mappings = {}
- for m in range(0,len(ldconfig_lines)):
- ldconfig_lines[m] = ldconfig_lines[m].strip()
- mapp = re.split('=>', ldconfig_lines[m] )
- soname = re.sub('\(.*$', '', mapp[0]).strip()
- abi = re.search('\(.+\)', mapp[0]).group(0)
- abi = abi.strip().strip('(').strip(')').strip()
- filename = mapp[1].strip()
- filename = os.path.realpath(filename)
- mappings[soname] = [ filename, pax.getflags(filename), abi ]
- return mappings
-
-forward_linkings = get_forward_linkings()
-reverse_linkings = invert_linkings( forward_linkings )
-soname2file_mappings = get_soname2file_mappings()
+def print_forward_linkings( forward_linkings ):
+ missing_elfs = []
+ missing_links = []
+ for elf in forward_linkings:
+ try:
+ print elf, '(', pax.getflags(elf), ')'
+ except:
+ missing_elfs.append(elf)
+ continue
+ for elf_dep in forward_linkings[elf]:
+ try:
+ filename = so2filename_mappings[elf_dep]
+ flags = pax.getflags(filename)
+ print '\t', elf_dep, '\t', filename, '(', flags, ')'
+ except:
+ missing_links.append(elf_dep)
+
+
+ missing_elfs = set(missing_elfs)
+ print '\n\n'
+ print '**** Missing elfs ****'
+ for m in missing_elfs:
+ print m
+
+ missing_links = set(missing_links)
+ print '\n\n'
+ print '**** Missing forward linkings ****'
+ for m in missing_links:
+ print m
+
+ print '\n\n'
+
+
+def print_reverse_linkings( reverse_linkings ):
+ missing_elfs = []
+ missing_links = []
+ for elf in reverse_linkings:
+ try:
+ filename = so2filename_mappings[elf]
+ flags = pax.getflags(filename)
+ print elf, '\t', filename, '(', flags, ')'
+ except:
+ missing_elfs.append(elf)
+ for elf_dep in reverse_linkings[elf]:
+ try:
+ flags = pax.getflags(elf_dep)
+ print '\t', elf_dep, '(', flags, ')'
+ except:
+ missing_links.append(elf_dep)
+ missing_elfs = set(missing_elfs)
+ print '\n\n'
+ print '**** Missing elfs ****'
+ for m in missing_elfs:
+ print m
-""" Print out mapping: binary -> library, library, library ... """
-unmapped = []
-for elf in forward_linkings:
- print elf
- for elf_dep in forward_linkings[elf]:
- print "\t", elf_dep
- #try:
- # print "\t\t", soname2file_mappings[elf_dep]
- #except:
- # unmapped.append(elf_dep)
- # print "%s doesn't have a mapping" % elf_dep
+ missing_links = set(missing_links)
+ print '\n\n'
+ print '**** Missing reverse linkings ****'
+ for m in missing_links:
+ print m
-raw_input()
+ print '\n\n'
-print unmapped
-raw_input()
+( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+reverse_linkings = invert_linkings( forward_linkings )
+
+print_forward_linkings( forward_linkings )
+#print_reverse_linkings( reverse_linkings )
-""" Print out mapping: library -> binary, binary, binary ...
-for elf_dep in reverse_linkings:
- print elf_dep
- for elf in reverse_linkings[elf_dep]:
- print "\t", elf
- #if not path.exists(elf):
- # print "%s doesn't exist!" % elf
-raw_input()
-for s in soname2file_mappings:
- print s, soname2file_mappings[s]
-"""
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 1e697a073206588f60492585463333f6d3039f02
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 8 02:01:44 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=1e697a07
scripts/revdep-pax: completed four command line options
-f all forward linkings from binary to their libraries
-r all reverse linkings from libraries to binaries that consume them
-b binary - forward mapping for given binary
-s soname - reverse mapping for given library identified by soname
---
scripts/revdep-pax | 40 ++++++++++++++++++++++++++--------------
1 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 98a2985..e91a964 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -143,7 +143,7 @@ def usage():
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], 'hfrb:l:')
+ opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:')
except getopt.GetoptError, err:
print str(err) # will print something like 'option -a not recognized'
usage()
@@ -156,7 +156,7 @@ def main():
do_forward = False
do_reverse = False
binary = None
- library = None
+ soname = None
for o, a in opts:
@@ -169,8 +169,8 @@ def main():
do_reverse = True
elif o == '-b':
binary = a
- elif o == '-l':
- library = a
+ elif o == '-s':
+ soname = a
else:
print 'Option included in getopt but not handled here!'
usage()
@@ -188,20 +188,32 @@ def main():
if binary != None:
( forward_linkings, so2filename_mappings ) = get_forward_linkings()
linkings = forward_linkings[binary]
- print linkings
- """
- try:
- filename = so2filename_mappings[binary]
- flags = pax.getflags(filename)
- print binary, '\t', filename, '(', flags, ')'
- except:
- print "%s doesn't link to anything that I know of" % binary
- """
+ flags = pax.getflags(binary)
+ print binary, '(', flags, ')'
+ for soname in linkings:
+ try:
+ filename = so2filename_mappings[soname]
+ flags = pax.getflags(filename)
+ print '\t', soname, '\t', filename, '(', flags, ')'
+ except:
+ print "file for soname %s not found" % soname
- if library !=None:
+ if soname !=None:
( forward_linkings, so2filename_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
+ linkings = reverse_linkings[soname]
+ library = so2filename_mappings[soname]
+
+ flags = pax.getflags(library)
+ print soname, '\t', library, '(', flags, ')'
+ for binary in linkings:
+ try:
+ flags = pax.getflags(binary)
+ print '\t', binary, '(', flags, ')'
+ except:
+ print "cannot obtain pax flags for %s" % binary
+
if __name__ == '__main__':
main()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 44f64229fd2997488871601913b5d25c66106109
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 7 22:14:35 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=44f64229
scripts/revdep-pax: added main() and command line opts
---
scripts/revdep-pax | 60 +++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 48b11d4..6a28a72 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+import sys
+import getopt
import os
import subprocess
import re
@@ -31,7 +33,7 @@ def get_ldd_linkings(elf):
def get_forward_linkings():
- """ I'm still not sure we wan to use /var/db/pkg vs some path of binaries """
+ # I'm still not sure we wan to use /var/db/pkg vs some path of binaries
var_db_pkg = '/var/db/pkg'
forward_linkings = {}
so2filename_mappings = {}
@@ -70,7 +72,7 @@ def invert_linkings( forward_linkings ):
return reverse_linkings
-def print_forward_linkings( forward_linkings ):
+def print_forward_linkings( forward_linkings, so2filename_mappings ):
missing_elfs = []
missing_links = []
for elf in forward_linkings:
@@ -87,7 +89,6 @@ def print_forward_linkings( forward_linkings ):
except:
missing_links.append(elf_dep)
-
missing_elfs = set(missing_elfs)
print '\n\n'
print '**** Missing elfs ****'
@@ -135,11 +136,54 @@ def print_reverse_linkings( reverse_linkings ):
print '\n\n'
-( forward_linkings, so2filename_mappings ) = get_forward_linkings()
-reverse_linkings = invert_linkings( forward_linkings )
-
-print_forward_linkings( forward_linkings )
-#print_reverse_linkings( reverse_linkings )
+def usage():
+ print 'TODO'
+def main():
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'hfrb:l:')
+ except getopt.GetoptError, err:
+ print str(err) # will print something like 'option -a not recognized'
+ usage()
+ sys.exit(1)
+
+ if len(opts) == 0:
+ usage()
+ sys.exit(1)
+
+ binary = None
+ library = None
+
+ do_forward = False
+ do_reverse = False
+
+ for o, a in opts:
+ if o == '-h':
+ usage()
+ sys.exit(1)
+ elif o == '-f':
+ do_forward = True
+ elif o == '-r':
+ do_reverse = True
+ elif o == '-b':
+ binary = a
+ elif o == '-l':
+ library = a
+ else:
+ print 'Option included in getopt but not handled here!'
+ usage()
+ sys.exit(1)
+
+ if do_forward:
+ ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ print_forward_linkings( forward_linkings, so2filename_mappings )
+
+ if do_reverse:
+ ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ reverse_linkings = invert_linkings( forward_linkings )
+ print_reverse_linkings( reverse_linkings )
+
+if __name__ == '__main__':
+ main()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 31cb534074005884933d27b20e8ef054dd663f62
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 8 00:45:06 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=31cb5340
scripts/revdep-pax: fixed two bugs
1) We need to continue to the next pkg not break out of the loop
when /var/db/pkg/cat/pkg/NEEDED is missing
2) print_forward_linkings needs so2filename_mappings to do its job
---
scripts/revdep-pax | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 6a28a72..98a2985 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -12,6 +12,7 @@ def get_ldd_linkings(elf):
#When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
ldd_output = subprocess.check_output(['/usr/bin/ldd', elf], stderr=subprocess.PIPE)
except:
+ # We should record these elfs which are probably static
return []
ldd_lines = ldd_output.split('\n')
linkings = []
@@ -54,7 +55,7 @@ def get_forward_linkings():
for m in mappings:
so2filename_mappings[m[0]] = m[1]
except:
- break
+ continue
return ( forward_linkings, so2filename_mappings )
@@ -104,7 +105,7 @@ def print_forward_linkings( forward_linkings, so2filename_mappings ):
print '\n\n'
-def print_reverse_linkings( reverse_linkings ):
+def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
missing_elfs = []
missing_links = []
for elf in reverse_linkings:
@@ -152,11 +153,11 @@ def main():
usage()
sys.exit(1)
+ do_forward = False
+ do_reverse = False
binary = None
library = None
- do_forward = False
- do_reverse = False
for o, a in opts:
if o == '-h':
@@ -182,7 +183,25 @@ def main():
if do_reverse:
( forward_linkings, so2filename_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
- print_reverse_linkings( reverse_linkings )
+ print_reverse_linkings( reverse_linkings, so2filename_mappings )
+
+ if binary != None:
+ ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ linkings = forward_linkings[binary]
+ print linkings
+
+ """
+ try:
+ filename = so2filename_mappings[binary]
+ flags = pax.getflags(filename)
+ print binary, '\t', filename, '(', flags, ')'
+ except:
+ print "%s doesn't link to anything that I know of" % binary
+ """
+
+ if library !=None:
+ ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ reverse_linkings = invert_linkings( forward_linkings )
if __name__ == '__main__':
main()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-08 18:54 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-08 18:54 UTC (permalink / raw
To: gentoo-commits
commit: 6fcb3d8aa826f50211958970872f76fbfc3d3dfc
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 8 18:35:30 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Oct 8 18:53:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=6fcb3d8a
scripts/Makefile.am: fix to work with make dist
---
scripts/Makefile.am | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 9faaeac..089cc3c 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -1 +1 @@
-sbin_SCRIPTS = revdep-pax
+dist_sbin_SCRIPTS = revdep-pax
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-12 10:47 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-12 10:47 UTC (permalink / raw
To: gentoo-commits
commit: abfd9450aec668669ef6ece6f65baa7f7a1d4be7
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 17:29:17 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Oct 12 10:47:05 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=abfd9450
scripts/revdep-pax: move option actions to functions
---
scripts/revdep-pax | 111 +++++++++++++++++++++++++++++++++-------------------
1 files changed, 71 insertions(+), 40 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index e91a964..26334c7 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -16,7 +16,7 @@ def get_ldd_linkings(elf):
return []
ldd_lines = ldd_output.split('\n')
linkings = []
- mappings = []
+ mappings = {}
for m in range(0,len(ldd_lines)):
if not re.search('=>', ldd_lines[m]):
continue
@@ -29,7 +29,7 @@ def get_ldd_linkings(elf):
continue
filename = os.path.realpath(filename)
linkings.append(soname)
- mappings.append([soname,filename])
+ mappings[soname] = filename
return ( linkings, mappings )
@@ -52,8 +52,7 @@ def get_forward_linkings():
elf = link[0]
( linkings, mappings ) = get_ldd_linkings(elf)
forward_linkings[elf] = linkings
- for m in mappings:
- so2filename_mappings[m[0]] = m[1]
+ so2filename_mappings.update(mappings)
except:
continue
@@ -140,10 +139,62 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
def usage():
print 'TODO'
+def run_forward():
+ ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ print_forward_linkings( forward_linkings, so2filename_mappings )
+
+
+def run_reverse():
+ ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ reverse_linkings = invert_linkings( forward_linkings )
+ print_reverse_linkings( reverse_linkings, so2filename_mappings )
+
+
+def run_binary(binary, verbose):
+ ( linkings, mappings ) = get_ldd_linkings(binary)
+
+ binary_flags = pax.getflags(binary)
+ print binary, '(', binary_flags, ')'
+
+ count = 0
+ for soname in linkings:
+ try:
+ filename = mappings[soname]
+ soname_flags = pax.getflags(filename)
+ if verbose:
+ print '\t', soname, '\t', filename, '(', soname_flags, ')'
+ else:
+ if binary_flags != soname_flags:
+ print '\t', soname, '\t',filename, '(', soname_flags, ')'
+ count = count + 1
+ except:
+ print "file for soname %s not found" % soname
+
+ if count == 0:
+ print '\nNo mismatches'
+
+
+def run_soname(soname, verbose):
+ ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ reverse_linkings = invert_linkings( forward_linkings )
+ linkings = reverse_linkings[soname]
+ library = so2filename_mappings[soname]
+
+ flags = pax.getflags(library)
+ if verbose:
+ print soname, '\t', library, '(', flags, ')'
+ for binary in linkings:
+ try:
+ flags = pax.getflags(binary)
+ if verbose:
+ print '\t', binary, '(', flags, ')'
+ except:
+ print "cannot obtain pax flags for %s" % binary
+
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:')
+ opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:v')
except getopt.GetoptError, err:
print str(err) # will print something like 'option -a not recognized'
usage()
@@ -153,16 +204,18 @@ def main():
usage()
sys.exit(1)
+ do_usage = False
do_forward = False
do_reverse = False
+
binary = None
soname = None
+ verbose = False
for o, a in opts:
if o == '-h':
- usage()
- sys.exit(1)
+ do_usage = True
elif o == '-f':
do_forward = True
elif o == '-r':
@@ -171,50 +224,28 @@ def main():
binary = a
elif o == '-s':
soname = a
+ elif o == '-v':
+ verbose = True
else:
print 'Option included in getopt but not handled here!'
- usage()
+ print 'Please file a bug'
sys.exit(1)
+
+ if do_usage:
+ run_usage()
+
if do_forward:
- ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
- print_forward_linkings( forward_linkings, so2filename_mappings )
+ run_forward()
if do_reverse:
- ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
- reverse_linkings = invert_linkings( forward_linkings )
- print_reverse_linkings( reverse_linkings, so2filename_mappings )
+ run_reverse()
if binary != None:
- ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
- linkings = forward_linkings[binary]
-
- flags = pax.getflags(binary)
- print binary, '(', flags, ')'
- for soname in linkings:
- try:
- filename = so2filename_mappings[soname]
- flags = pax.getflags(filename)
- print '\t', soname, '\t', filename, '(', flags, ')'
- except:
- print "file for soname %s not found" % soname
+ run_binary(binary, verbose)
if soname !=None:
- ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
- reverse_linkings = invert_linkings( forward_linkings )
- linkings = reverse_linkings[soname]
- library = so2filename_mappings[soname]
-
- flags = pax.getflags(library)
- print soname, '\t', library, '(', flags, ')'
- for binary in linkings:
- try:
- flags = pax.getflags(binary)
- print '\t', binary, '(', flags, ')'
- except:
- print "cannot obtain pax flags for %s" % binary
-
+ run_soname(soname)
if __name__ == '__main__':
main()
-
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-12 10:47 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-12 10:47 UTC (permalink / raw
To: gentoo-commits
commit: 5af2834148d2d074a79c5fc390cbfd85bf9e16c5
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 17:30:06 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Oct 12 10:47:47 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=5af28341
scripts/revdep-pax: add help
---
scripts/revdep-pax | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 26334c7..bdf6004 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -137,7 +137,18 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
def usage():
- print 'TODO'
+ print 'Package Name : elfix\n'
+ print 'Bug Reports : http://bugs.gentoo.org/'
+ print 'Program Name : revdep-pax\n'
+ print 'Description : Get or set pax flags on an ELF object\n\n'
+ print 'Usage : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h\n\n'
+ print 'Options : -f print out all the forward mappings for all system binaries\n'
+ print ' : -r print out all the reverse mappints for all system sonames\n'
+ print ' : -b BINARY print all the forward mappings only for BINARY\n'
+ print ' : -s SONAME print all the reverse mappings only for SONAME\n'
+ print ' : -v verbose, otherwise just print mismatched pax flags \n'
+ print ' : -h print out this help\n\n'
+
def run_forward():
( forward_linkings, so2filename_mappings ) = get_forward_linkings()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-12 10:48 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-12 10:48 UTC (permalink / raw
To: gentoo-commits
commit: f318ed774bf2a200211043181a8ab42986aec31d
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 23:21:09 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Oct 12 10:48:27 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=f318ed77
scripts/revdep-pax: add verbosity to output
---
scripts/revdep-pax | 189 +++++++++++++++++++++++++++++++---------------------
1 files changed, 114 insertions(+), 75 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index bdf6004..4e35f1e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -7,12 +7,12 @@ import subprocess
import re
import pax
-def get_ldd_linkings(elf):
+def get_ldd_linkings(binary):
try:
#When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
- ldd_output = subprocess.check_output(['/usr/bin/ldd', elf], stderr=subprocess.PIPE)
+ ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
except:
- # We should record these elfs which are probably static
+ # We should record these binaries which are probably statically linked
return []
ldd_lines = ldd_output.split('\n')
linkings = []
@@ -24,12 +24,12 @@ def get_ldd_linkings(elf):
mapp = re.split('=>', ldd_lines[m] )
soname = mapp[0].strip()
soname = os.path.basename(soname) # This is for ./libSDL-1.2.so.0
- filename = re.sub('\(.*$', '', mapp[1]).strip()
- if filename == '':
+ library = re.sub('\(.*$', '', mapp[1]).strip()
+ if library == '':
continue
- filename = os.path.realpath(filename)
+ library = os.path.realpath(library)
linkings.append(soname)
- mappings[soname] = filename
+ mappings[soname] = library
return ( linkings, mappings )
@@ -49,9 +49,9 @@ def get_forward_linkings():
for line in needs:
line = line.strip()
link = re.split('\s', line)
- elf = link[0]
- ( linkings, mappings ) = get_ldd_linkings(elf)
- forward_linkings[elf] = linkings
+ binary = link[0]
+ ( linkings, mappings ) = get_ldd_linkings(binary)
+ forward_linkings[binary] = linkings
so2filename_mappings.update(mappings)
except:
continue
@@ -61,38 +61,52 @@ def get_forward_linkings():
def invert_linkings( forward_linkings ):
reverse_linkings = {}
- for elf in forward_linkings:
- for elf_dep in forward_linkings[elf]:
- reverse_linkings[elf_dep] = []
+ for binary in forward_linkings:
+ for library in forward_linkings[binary]:
+ reverse_linkings[library] = []
- for elf in forward_linkings:
- for elf_dep in forward_linkings[elf]:
- reverse_linkings[elf_dep].append(elf)
+ for binary in forward_linkings:
+ for library in forward_linkings[binary]:
+ reverse_linkings[library].append(binary)
return reverse_linkings
-def print_forward_linkings( forward_linkings, so2filename_mappings ):
- missing_elfs = []
+def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
+ missing_binaries = []
missing_links = []
- for elf in forward_linkings:
+ for binary in forward_linkings:
+
try:
- print elf, '(', pax.getflags(elf), ')'
+ binary_flags = pax.getflags(binary)
+ s = "%s ( %s )" % ( binary, binary_flags )
except:
- missing_elfs.append(elf)
+ missing_binaries.append(binary)
continue
- for elf_dep in forward_linkings[elf]:
+
+ count = 0
+ for soname in forward_linkings[binary]:
try:
- filename = so2filename_mappings[elf_dep]
- flags = pax.getflags(filename)
- print '\t', elf_dep, '\t', filename, '(', flags, ')'
+ library = so2filename_mappings[soname]
+ library_flags = pax.getflags(library)
+ s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
+ if binary_flags != library_flags:
+ count = count + 1
except:
- missing_links.append(elf_dep)
+ missing_links.append(soname)
+
+ if verbose:
+ print s
+ if count == 0:
+ print 'No mismatches'
+ else:
+ if count != 0:
+ print s
- missing_elfs = set(missing_elfs)
+ missing_binaries = set(missing_binaries)
print '\n\n'
- print '**** Missing elfs ****'
- for m in missing_elfs:
+ print '**** Missing binaries ****'
+ for m in missing_binaries:
print m
missing_links = set(missing_links)
@@ -104,27 +118,42 @@ def print_forward_linkings( forward_linkings, so2filename_mappings ):
print '\n\n'
-def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
- missing_elfs = []
+def print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose ):
+ missing_sonames = []
missing_links = []
- for elf in reverse_linkings:
+
+ for soname in reverse_linkings:
+
try:
- filename = so2filename_mappings[elf]
- flags = pax.getflags(filename)
- print elf, '\t', filename, '(', flags, ')'
+ library = so2filename_mappings[soname]
+ library_flags = pax.getflags(library)
+ s = "%s\t%s ( %s )" % ( soname, library, library_flags )
except:
- missing_elfs.append(elf)
- for elf_dep in reverse_linkings[elf]:
+ missing_libraries.append(soname)
+ continue
+
+ count = 0
+ for binary in reverse_linkings[soname]:
try:
- flags = pax.getflags(elf_dep)
- print '\t', elf_dep, '(', flags, ')'
+ binary_flags = pax.getflags(binary)
+ s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
+ if library_flags != binary_flags:
+ count = count + 1
except:
- missing_links.append(elf_dep)
+ missing_links.append(binary)
- missing_elfs = set(missing_elfs)
+ if verbose:
+ print s
+ if count == 0:
+ print 'No mismatches'
+ else:
+ if count != 0:
+ print s
+
+ missing_sonames = set(missing_sonames)
print '\n\n'
- print '**** Missing elfs ****'
- for m in missing_elfs:
+ print '**** Missing sonames ****'
+ for m in missing_sonames:
print m
missing_links = set(missing_links)
@@ -136,29 +165,32 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings ):
print '\n\n'
-def usage():
- print 'Package Name : elfix\n'
+def run_usage():
+ print 'Package Name : elfix'
print 'Bug Reports : http://bugs.gentoo.org/'
- print 'Program Name : revdep-pax\n'
- print 'Description : Get or set pax flags on an ELF object\n\n'
- print 'Usage : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h\n\n'
- print 'Options : -f print out all the forward mappings for all system binaries\n'
- print ' : -r print out all the reverse mappints for all system sonames\n'
- print ' : -b BINARY print all the forward mappings only for BINARY\n'
- print ' : -s SONAME print all the reverse mappings only for SONAME\n'
- print ' : -v verbose, otherwise just print mismatched pax flags \n'
- print ' : -h print out this help\n\n'
-
-
-def run_forward():
+ print 'Program Name : revdep-pax'
+ print 'Description : Get or set pax flags on an ELF object'
+ print
+ print 'Usage : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h'
+ print
+ print 'Options : -f print out all the forward mappings for all system binaries'
+ print ' : -r print out all the reverse mappints for all system sonames'
+ print ' : -b BINARY print all the forward mappings only for BINARY'
+ print ' : -s SONAME print all the reverse mappings only for SONAME'
+ print ' : -v verbose, otherwise just print mismatched pax flags'
+ print ' : -h print out this help'
+ print
+
+
+def run_forward(verbose):
( forward_linkings, so2filename_mappings ) = get_forward_linkings()
- print_forward_linkings( forward_linkings, so2filename_mappings )
+ print_forward_linkings( forward_linkings, so2filename_mappings, verbose)
-def run_reverse():
+def run_reverse(verbose):
( forward_linkings, so2filename_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
- print_reverse_linkings( reverse_linkings, so2filename_mappings )
+ print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose )
def run_binary(binary, verbose):
@@ -170,19 +202,20 @@ def run_binary(binary, verbose):
count = 0
for soname in linkings:
try:
- filename = mappings[soname]
- soname_flags = pax.getflags(filename)
+ library = mappings[soname]
+ library_flags = pax.getflags(library)
if verbose:
- print '\t', soname, '\t', filename, '(', soname_flags, ')'
+ print '\t', soname, '\t', library, '(', library_flags, ')'
else:
- if binary_flags != soname_flags:
- print '\t', soname, '\t',filename, '(', soname_flags, ')'
+ if binary_flags != library_flags:
+ print '\t', soname, '\t', library, '(', library_flags, ')'
count = count + 1
except:
print "file for soname %s not found" % soname
if count == 0:
- print '\nNo mismatches'
+ print
+ print 'No mismatches'
def run_soname(soname, verbose):
@@ -191,17 +224,24 @@ def run_soname(soname, verbose):
linkings = reverse_linkings[soname]
library = so2filename_mappings[soname]
- flags = pax.getflags(library)
- if verbose:
- print soname, '\t', library, '(', flags, ')'
+ library_flags = pax.getflags(library)
+ print soname, '\t', library, '(', library_flags, ')'
+
+ count = 0
for binary in linkings:
try:
- flags = pax.getflags(binary)
+ binary_flags = pax.getflags(binary)
if verbose:
- print '\t', binary, '(', flags, ')'
+ print '\t', binary, '(', binary_flags, ')'
+ else:
+ if library_flags != binary_flags:
+ print '\t', binary, '(', binary_flags, ')'
+ count = count + 1
except:
print "cannot obtain pax flags for %s" % binary
+ if count == 0:
+ print '\nNo mismatches'
def main():
try:
@@ -242,21 +282,20 @@ def main():
print 'Please file a bug'
sys.exit(1)
-
if do_usage:
run_usage()
if do_forward:
- run_forward()
+ run_forward(verbose)
if do_reverse:
- run_reverse()
+ run_reverse(verbose)
if binary != None:
run_binary(binary, verbose)
if soname !=None:
- run_soname(soname)
+ run_soname(soname, verbose)
if __name__ == '__main__':
main()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-12 10:48 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-12 10:48 UTC (permalink / raw
To: gentoo-commits
commit: 235a6390f12379b058b0eb0d59f03f0861bc536e
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 10 23:42:31 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Oct 12 10:48:46 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=235a6390
scripts/revdep-pax: code and variable name cleanup
---
scripts/revdep-pax | 67 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 42 insertions(+), 25 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 4e35f1e..75ec724 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -8,13 +8,16 @@ import re
import pax
def get_ldd_linkings(binary):
+
try:
- #When subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
+ #TODO: when subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
except:
- # We should record these binaries which are probably statically linked
+ #TODO: we should record these binaries which are probably statically linked
return []
+
ldd_lines = ldd_output.split('\n')
+
linkings = []
mappings = {}
for m in range(0,len(ldd_lines)):
@@ -30,14 +33,16 @@ def get_ldd_linkings(binary):
library = os.path.realpath(library)
linkings.append(soname)
mappings[soname] = library
+
return ( linkings, mappings )
def get_forward_linkings():
- # I'm still not sure we wan to use /var/db/pkg vs some path of binaries
+ #TODO: I'm still not sure we wan to use /var/db/pkg vs some path of binaries
var_db_pkg = '/var/db/pkg'
+
forward_linkings = {}
- so2filename_mappings = {}
+ so2library_mappings = {}
for cat in os.listdir(var_db_pkg):
catdir = '%s/%s' % (var_db_pkg, cat)
for pkg in os.listdir(catdir):
@@ -52,11 +57,11 @@ def get_forward_linkings():
binary = link[0]
( linkings, mappings ) = get_ldd_linkings(binary)
forward_linkings[binary] = linkings
- so2filename_mappings.update(mappings)
+ so2library_mappings.update(mappings)
except:
continue
- return ( forward_linkings, so2filename_mappings )
+ return ( forward_linkings, so2library_mappings )
def invert_linkings( forward_linkings ):
@@ -72,7 +77,7 @@ def invert_linkings( forward_linkings ):
return reverse_linkings
-def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
+def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
missing_binaries = []
missing_links = []
for binary in forward_linkings:
@@ -87,7 +92,7 @@ def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
count = 0
for soname in forward_linkings[binary]:
try:
- library = so2filename_mappings[soname]
+ library = so2library_mappings[soname]
library_flags = pax.getflags(library)
s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
if binary_flags != library_flags:
@@ -103,33 +108,38 @@ def print_forward_linkings( forward_linkings, so2filename_mappings, verbose ):
if count != 0:
print s
+ print
+
missing_binaries = set(missing_binaries)
- print '\n\n'
+ print
+ print
print '**** Missing binaries ****'
for m in missing_binaries:
print m
missing_links = set(missing_links)
- print '\n\n'
+ print
+ print
print '**** Missing forward linkings ****'
for m in missing_links:
print m
- print '\n\n'
+ print
+ print
-def print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose ):
+def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
missing_sonames = []
missing_links = []
for soname in reverse_linkings:
try:
- library = so2filename_mappings[soname]
+ library = so2library_mappings[soname]
library_flags = pax.getflags(library)
s = "%s\t%s ( %s )" % ( soname, library, library_flags )
except:
- missing_libraries.append(soname)
+ missing_sonames.append(soname)
continue
count = 0
@@ -150,19 +160,23 @@ def print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose ):
if count != 0:
print s
+ print
+
missing_sonames = set(missing_sonames)
- print '\n\n'
+ print
+ print
print '**** Missing sonames ****'
for m in missing_sonames:
print m
missing_links = set(missing_links)
- print '\n\n'
+ print
+ print
print '**** Missing reverse linkings ****'
for m in missing_links:
print m
-
- print '\n\n'
+ print
+ print
def run_usage():
@@ -183,14 +197,14 @@ def run_usage():
def run_forward(verbose):
- ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
- print_forward_linkings( forward_linkings, so2filename_mappings, verbose)
+ ( forward_linkings, so2library_mappings ) = get_forward_linkings()
+ print_forward_linkings( forward_linkings, so2library_mappings, verbose)
def run_reverse(verbose):
- ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ ( forward_linkings, so2library_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
- print_reverse_linkings( reverse_linkings, so2filename_mappings, verbose )
+ print_reverse_linkings( reverse_linkings, so2library_mappings, verbose )
def run_binary(binary, verbose):
@@ -219,10 +233,10 @@ def run_binary(binary, verbose):
def run_soname(soname, verbose):
- ( forward_linkings, so2filename_mappings ) = get_forward_linkings()
+ ( forward_linkings, so2library_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
linkings = reverse_linkings[soname]
- library = so2filename_mappings[soname]
+ library = so2library_mappings[soname]
library_flags = pax.getflags(library)
print soname, '\t', library, '(', library_flags, ')'
@@ -241,7 +255,8 @@ def run_soname(soname, verbose):
print "cannot obtain pax flags for %s" % binary
if count == 0:
- print '\nNo mismatches'
+ print
+ print 'No mismatches'
def main():
try:
@@ -282,6 +297,8 @@ def main():
print 'Please file a bug'
sys.exit(1)
+ #TODO: Add code to only allow one of -h, -f -r -b -s
+
if do_usage:
run_usage()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-12 10:49 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-12 10:49 UTC (permalink / raw
To: gentoo-commits
commit: 8a5871718ac79cadb836253e052aceb44206e128
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 11 00:50:28 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed Oct 12 10:49:06 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=8a587171
scripts/revdep-pax: restrict non-verbose to only mismatches
---
scripts/revdep-pax | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 75ec724..576025e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -84,7 +84,8 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
try:
binary_flags = pax.getflags(binary)
- s = "%s ( %s )" % ( binary, binary_flags )
+ sv = "%s ( %s )" % ( binary, binary_flags )
+ s = sv
except:
missing_binaries.append(binary)
continue
@@ -94,14 +95,15 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
try:
library = so2library_mappings[soname]
library_flags = pax.getflags(library)
- s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
+ sv = "%s\n\t%s\t%s ( %s )" % ( sv, soname, library, library_flags )
if binary_flags != library_flags:
+ s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
count = count + 1
except:
missing_links.append(soname)
if verbose:
- print s
+ print sv
if count == 0:
print 'No mismatches'
else:
@@ -137,7 +139,8 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
try:
library = so2library_mappings[soname]
library_flags = pax.getflags(library)
- s = "%s\t%s ( %s )" % ( soname, library, library_flags )
+ sv = "%s\t%s ( %s )" % ( soname, library, library_flags )
+ s = sv
except:
missing_sonames.append(soname)
continue
@@ -146,14 +149,15 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
for binary in reverse_linkings[soname]:
try:
binary_flags = pax.getflags(binary)
- s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
+ sv = "%s\n\t%s ( %s )" % ( sv, binary, binary_flags )
if library_flags != binary_flags:
+ s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
count = count + 1
except:
missing_links.append(binary)
if verbose:
- print s
+ print sv
if count == 0:
print 'No mismatches'
else:
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: de6e5f3c7ab6f46549ec5c3561e1317e6183f291
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 13 02:27:41 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:03:23 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=de6e5f3c
scripts/revdep-pax: improve format of output
---
scripts/revdep-pax | 30 ++++++++++++++++++++++++++----
1 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index f06bf3d..dd359db 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -105,7 +105,13 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
if verbose:
print sv
if count == 0:
- print 'No mismatches'
+ print
+ print '\tNo mismatches'
+ print
+ else:
+ print
+ print '\tMismatches'
+ print
else:
if count != 0:
print s
@@ -159,7 +165,13 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
if verbose:
print sv
if count == 0:
- print 'No mismatches'
+ print
+ print '\tNo mismatches'
+ print
+ else:
+ print
+ print '\tMismatches'
+ print
else:
if count != 0:
print s
@@ -233,7 +245,12 @@ def run_binary(binary, verbose):
if count == 0:
print
- print 'No mismatches'
+ print '\tNo mismatches'
+ print
+ else:
+ print
+ print '\tMismatches'
+ print
def run_soname(soname, verbose):
@@ -260,7 +277,12 @@ def run_soname(soname, verbose):
if count == 0:
print
- print 'No mismatches'
+ print '\tNo mismatches'
+ print
+ else:
+ print
+ print '\tMismatches'
+ print
def main():
try:
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: c1675070da9c5fa47361e7cc314a6d484584d6e7
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 16 18:03:58 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:03:46 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=c1675070
scripts/paxmodule.c: add pax_setflags
---
scripts/paxmodule.c | 253 +++++++++++++++++++++++++++++++++++++++++++++++++++
scripts/revdep-pax | 4 +
2 files changed, 257 insertions(+), 0 deletions(-)
diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 927bb50..eac774a 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -24,9 +24,11 @@
static PyObject * pax_getflags(PyObject *, PyObject *);
+static PyObject * pax_setflags(PyObject *, PyObject *);
static PyMethodDef PaxMethods[] = {
{"getflags", pax_getflags, METH_VARARGS, "Get the pax flags."},
+ {"setflags", pax_setflags, METH_VARARGS, "Set the pax flags."},
{NULL, NULL, 0, NULL}
};
@@ -160,3 +162,254 @@ pax_getflags(PyObject *self, PyObject *args)
return Py_BuildValue("s", pax_buf);
}
+
+
+static PyObject *
+pax_setflags(PyObject *self, PyObject *args)
+{
+ const char *f_name;
+ int pax_flags;
+ int fd, sts;
+
+ Elf *elf;
+ GElf_Ehdr ehdr;
+ uint16_t ei_flags;
+
+ GElf_Phdr phdr;
+ size_t i, phnum;
+
+ if (!PyArg_ParseTuple(args, "si", &f_name, &pax_flags))
+ {
+ PyErr_SetString(PaxError, "pax_setflags: PyArg_ParseTuple failed");
+ return NULL;
+ }
+
+ if(elf_version(EV_CURRENT) == EV_NONE)
+ {
+ PyErr_SetString(PaxError, "pax_setflags: library out of date");
+ return NULL;
+ }
+
+ if((fd = open(f_name, O_RDONLY)) < 0)
+ {
+ PyErr_SetString(PaxError, "pax_setflags: open() failed");
+ return NULL;
+ }
+
+ if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
+ {
+ close(fd);
+ PyErr_SetString(PaxError, "pax_setflags: elf_begin() failed");
+ return NULL;
+ }
+
+ if(elf_kind(elf) != ELF_K_ELF)
+ {
+ elf_end(elf);
+ close(fd);
+ PyErr_SetString(PaxError, "pax_setflags: elf_kind() failed: this is not an elf file.");
+ return NULL;
+ }
+
+
+
+ if(gelf_getehdr(elf, &ehdr) != &ehdr)
+ {
+ elf_end(elf);
+ close(fd);
+ PyErr_SetString(PaxError, "pax_setflags: gelf_getehdr() failed");
+ return NULL;
+ }
+
+ ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+
+ //PAGEEXEC
+ if(pax_flags & PF_PAGEEXEC)
+ ei_flags &= ~HF_PAX_PAGEEXEC;
+ if(pax_flags & PF_NOPAGEEXEC)
+ ei_flags |= HF_PAX_PAGEEXEC;
+ if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
+ ei_flags &= ~HF_PAX_PAGEEXEC;
+
+ //SEGMEXEC
+ if(pax_flags & PF_SEGMEXEC)
+ ei_flags &= ~HF_PAX_SEGMEXEC;
+ if(pax_flags & PF_NOSEGMEXEC)
+ ei_flags |= HF_PAX_SEGMEXEC;
+ if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
+ ei_flags &= ~HF_PAX_SEGMEXEC;
+
+ //MPROTECT
+ if(pax_flags & PF_MPROTECT)
+ ei_flags &= ~HF_PAX_MPROTECT;
+ if(pax_flags & PF_NOMPROTECT)
+ ei_flags |= HF_PAX_MPROTECT;
+ if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
+ ei_flags &= ~HF_PAX_MPROTECT;
+
+ //EMUTRAMP
+ if(pax_flags & PF_EMUTRAMP)
+ ei_flags |= HF_PAX_EMUTRAMP;
+ if(pax_flags & PF_NOEMUTRAMP)
+ ei_flags &= ~HF_PAX_EMUTRAMP;
+ if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
+ ei_flags &= ~HF_PAX_EMUTRAMP;
+
+ //RANDMMAP
+ if(pax_flags & PF_RANDMMAP)
+ ei_flags &= ~HF_PAX_RANDMMAP;
+ if(pax_flags & PF_NORANDMMAP)
+ ei_flags |= HF_PAX_RANDMMAP;
+ if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
+ ei_flags &= ~HF_PAX_RANDMMAP;
+
+ //RANDEXEC
+ if(pax_flags & PF_RANDEXEC)
+ ei_flags |= HF_PAX_RANDEXEC;
+ if(pax_flags & PF_NORANDEXEC)
+ ei_flags &= ~HF_PAX_RANDEXEC;
+ if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
+ ei_flags |= HF_PAX_RANDEXEC;
+
+
+ ehdr.e_ident[EI_PAX] = (uint8_t)ei_flags ;
+ ehdr.e_ident[EI_PAX + 1] = (uint8_t)(ei_flags >> 8) ;
+
+ if(!gelf_update_ehdr(elf, &ehdr))
+ {
+ elf_end(elf);
+ close(fd);
+ PyErr_SetString(PaxError, "pax_setflags: gelf_update_ehdr() failed");
+ return NULL;
+ }
+
+ elf_getphdrnum(elf, &phnum);
+ for(i=0; i<phnum; ++i)
+ {
+ if(gelf_getphdr(elf, i, &phdr) != &phdr)
+ {
+ elf_end(elf);
+ close(fd);
+ PyErr_SetString(PaxError, "pax_setflags: gelf_getphdr() failed");
+ return NULL;
+ }
+
+ if(phdr.p_type == PT_PAX_FLAGS)
+ {
+ //PAGEEXEC
+ if(pax_flags & PF_PAGEEXEC)
+ {
+ phdr.p_flags |= PF_PAGEEXEC;
+ phdr.p_flags &= ~PF_NOPAGEEXEC;
+ }
+ if(pax_flags & PF_NOPAGEEXEC)
+ {
+ phdr.p_flags &= ~PF_PAGEEXEC;
+ phdr.p_flags |= PF_NOPAGEEXEC;
+ }
+ if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
+ {
+ phdr.p_flags &= ~PF_PAGEEXEC;
+ phdr.p_flags &= ~PF_NOPAGEEXEC;
+ }
+
+ //SEGMEXEC
+ if(pax_flags & PF_SEGMEXEC)
+ {
+ phdr.p_flags |= PF_SEGMEXEC;
+ phdr.p_flags &= ~PF_NOSEGMEXEC;
+ }
+ if(pax_flags & PF_NOSEGMEXEC)
+ {
+ phdr.p_flags &= ~PF_SEGMEXEC;
+ phdr.p_flags |= PF_NOSEGMEXEC;
+ }
+ if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
+ {
+ phdr.p_flags &= ~PF_SEGMEXEC;
+ phdr.p_flags &= ~PF_NOSEGMEXEC;
+ }
+
+ //MPROTECT
+ if(pax_flags & PF_MPROTECT)
+ {
+ phdr.p_flags |= PF_MPROTECT;
+ phdr.p_flags &= ~PF_NOMPROTECT;
+ }
+ if(pax_flags & PF_NOMPROTECT)
+ {
+ phdr.p_flags &= ~PF_MPROTECT;
+ phdr.p_flags |= PF_NOMPROTECT;
+ }
+ if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
+ {
+ phdr.p_flags &= ~PF_MPROTECT;
+ phdr.p_flags &= ~PF_NOMPROTECT;
+ }
+
+ //EMUTRAMP
+ if(pax_flags & PF_EMUTRAMP)
+ {
+ phdr.p_flags |= PF_EMUTRAMP;
+ phdr.p_flags &= ~PF_NOEMUTRAMP;
+ }
+ if(pax_flags & PF_NOEMUTRAMP)
+ {
+ phdr.p_flags &= ~PF_EMUTRAMP;
+ phdr.p_flags |= PF_NOEMUTRAMP;
+ }
+ if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
+ {
+ phdr.p_flags &= ~PF_EMUTRAMP;
+ phdr.p_flags &= ~PF_NOEMUTRAMP;
+ }
+
+ //RANDMMAP
+ if(pax_flags & PF_RANDMMAP)
+ {
+ phdr.p_flags |= PF_RANDMMAP;
+ phdr.p_flags &= ~PF_NORANDMMAP;
+ }
+ if(pax_flags & PF_NORANDMMAP)
+ {
+ phdr.p_flags &= ~PF_RANDMMAP;
+ phdr.p_flags |= PF_NORANDMMAP;
+ }
+ if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
+ {
+ phdr.p_flags &= ~PF_RANDMMAP;
+ phdr.p_flags &= ~PF_NORANDMMAP;
+ }
+
+ //RANDEXEC
+ if(pax_flags & PF_RANDEXEC)
+ {
+ phdr.p_flags |= PF_RANDEXEC;
+ phdr.p_flags &= ~PF_NORANDEXEC;
+ }
+ if(pax_flags & PF_NORANDEXEC)
+ {
+ phdr.p_flags &= ~PF_RANDEXEC;
+ phdr.p_flags |= PF_NORANDEXEC;
+ }
+ if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
+ {
+ phdr.p_flags &= ~PF_RANDEXEC;
+ phdr.p_flags &= ~PF_NORANDEXEC;
+ }
+
+ if(!gelf_update_phdr(elf, i, &phdr))
+ {
+ elf_end(elf);
+ close(fd);
+ PyErr_SetString(PaxError, "pax_setflags: gelf_update_phdr() failed");
+ return NULL;
+ }
+ }
+ }
+
+ elf_end(elf);
+ close(fd);
+
+ return Py_BuildValue("");
+}
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 0fcb8e6..e43db27 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -104,6 +104,7 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
if verbose:
print sv
+ print
if count == 0:
print
print '\tNo mismatches'
@@ -164,6 +165,7 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
if verbose:
print sv
+ print
if count == 0:
print
print '\tNo mismatches'
@@ -230,6 +232,7 @@ def run_binary(binary, verbose):
binary_flags = pax.getflags(binary)
print binary, '(', binary_flags, ')'
+ print
count = 0
for soname in linkings:
@@ -277,6 +280,7 @@ def run_soname(name, verbose, use_soname):
library_flags = pax.getflags(library)
print soname, '\t', library, '(', library_flags, ')'
+ print
count = 0
for binary in linkings:
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: cada51e03eb9d72c9f0ef5a426d221060b984903
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 16 18:25:54 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:03:55 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=cada51e0
scripts/revdep-pax: make only one of -f -r -b -s -l allowed
---
scripts/revdep-pax | 42 +++++++++++++++++++++---------------------
1 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index e43db27..326007e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -203,14 +203,12 @@ def run_usage():
print 'Program Name : revdep-pax'
print 'Description : Get or set pax flags on an ELF object'
print
- print 'Usage : revdep-pax [-fv] | [-rv] | -v [-b BINARY] | -v [-s SONAME] | -h'
- print
- print 'Options : -f print out all the forward mappings for all system binaries'
- print ' : -r print out all the reverse mappints for all system sonames'
- print ' : -b BINARY print all the forward mappings only for BINARY'
- print ' : -s SONAME print all the reverse mappings only for SONAME'
- print ' : -v verbose, otherwise just print mismatched pax flags'
- print ' : -h print out this help'
+ print 'Usage : revdep-pax -f [-v] print out all forward mappings for all system binaries'
+ print ' : revdep-pax -r [-v] print out all reverse mappints for all system sonames'
+ print ' : revdep-pax -b BINARY [-v] print all forward mappings only for BINARY'
+ print ' : revdep-pax -s SONAME [-v] print all reverse mappings only for SONAME'
+ print ' : revdep-pax [-h] print out this help'
+ print ' : -v verbose, otherwise just print mismatched flags'
print
@@ -327,19 +325,27 @@ def main():
verbose = False
+ opt_count = 0
+
for o, a in opts:
if o == '-h':
do_usage = True
+ opt_count += 1
elif o == '-f':
do_forward = True
+ opt_count += 1
elif o == '-r':
do_reverse = True
+ opt_count += 1
elif o == '-b':
binary = a
+ opt_count += 1
elif o == '-s':
soname = a
+ opt_count += 1
elif o == '-l':
library = a
+ opt_count += 1
elif o == '-v':
verbose = True
else:
@@ -347,24 +353,18 @@ def main():
print 'Please file a bug'
sys.exit(1)
- #TODO: Add code to only allow one of -h, -f -r -b -s
-
- if do_usage:
+ # Only allow one of -h, -f -r -b -s
+ if opt_count > 1 or do_usage:
run_usage()
-
- if do_forward:
+ elif do_forward:
run_forward(verbose)
-
- if do_reverse:
+ elif do_reverse:
run_reverse(verbose)
-
- if binary != None:
+ elif binary != None:
run_binary(binary, verbose)
-
- if soname != None:
+ elif soname != None:
run_soname(soname, verbose, True)
-
- if library != None:
+ elif library != None:
library = os.path.realpath(library)
run_soname(library, verbose, False)
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: fa17b2980b8c20d095c357f122315d6df24c764d
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 13 04:36:09 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:03:36 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=fa17b298
scripts/revdep-pax: add search by full library path
---
scripts/revdep-pax | 32 ++++++++++++++++++++++++++++----
1 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index dd359db..0fcb8e6 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -215,12 +215,14 @@ def run_usage():
def run_forward(verbose):
( forward_linkings, so2library_mappings ) = get_forward_linkings()
print_forward_linkings( forward_linkings, so2library_mappings, verbose)
+ print
def run_reverse(verbose):
( forward_linkings, so2library_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
print_reverse_linkings( reverse_linkings, so2library_mappings, verbose )
+ print
def run_binary(binary, verbose):
@@ -253,9 +255,23 @@ def run_binary(binary, verbose):
print
-def run_soname(soname, verbose):
+def invert_so2library_mappings( so2library_mappings ):
+ library2soname_mappings = {}
+ for soname, library in so2library_mappings.iteritems():
+ library2soname_mappings[library] = soname
+ return library2soname_mappings
+
+
+def run_soname(name, verbose, use_soname):
( forward_linkings, so2library_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
+
+ if use_soname:
+ soname = name
+ else:
+ library2soname_mappings = invert_so2library_mappings(so2library_mappings)
+ soname = library2soname_mappings[name]
+
linkings = reverse_linkings[soname]
library = so2library_mappings[soname]
@@ -284,9 +300,10 @@ def run_soname(soname, verbose):
print '\tMismatches'
print
+
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:v')
+ opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:v')
except getopt.GetoptError, err:
print str(err) # will print something like 'option -a not recognized'
run_usage()
@@ -302,6 +319,7 @@ def main():
binary = None
soname = None
+ library = None
verbose = False
@@ -316,6 +334,8 @@ def main():
binary = a
elif o == '-s':
soname = a
+ elif o == '-l':
+ library = a
elif o == '-v':
verbose = True
else:
@@ -337,8 +357,12 @@ def main():
if binary != None:
run_binary(binary, verbose)
- if soname !=None:
- run_soname(soname, verbose)
+ if soname != None:
+ run_soname(soname, verbose, True)
+
+ if library != None:
+ library = os.path.realpath(library)
+ run_soname(library, verbose, False)
if __name__ == '__main__':
main()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: 621eac4f956d7487559a7f7f460ac87f457f495f
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 19:28:22 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:04:11 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=621eac4f
scripts/{paxmodule.c,revdep-pax}: add code to set pax flags
---
scripts/paxmodule.c | 183 +++++++++++----------------------------------------
scripts/revdep-pax | 100 +++++++++++++++++-----------
2 files changed, 101 insertions(+), 182 deletions(-)
diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index eac774a..32c8768 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -1,6 +1,5 @@
#include <Python.h>
-#include <stdio.h> //remove when you remove printf
#include <string.h>
#include <gelf.h>
@@ -53,14 +52,13 @@ static PyObject *
pax_getflags(PyObject *self, PyObject *args)
{
const char *f_name;
- int fd, sts;
+ int fd;
Elf *elf;
char pax_buf[BUF_SIZE];
+ uint16_t pax_flags;
GElf_Ehdr ehdr;
- uint16_t ei_flags;
-
GElf_Phdr phdr;
char found_pt_pax;
size_t i, phnum;
@@ -102,6 +100,8 @@ pax_getflags(PyObject *self, PyObject *args)
found_pt_pax = 0;
+ pax_flags = 0;
+
elf_getphdrnum(elf, &phnum);
for(i=0; i<phnum; ++i)
{
@@ -116,24 +116,25 @@ pax_getflags(PyObject *self, PyObject *args)
if(phdr.p_type == PT_PAX_FLAGS)
{
found_pt_pax = 1;
+ pax_flags = phdr.p_flags;
- pax_buf[0] = phdr.p_flags & PF_PAGEEXEC ? 'P' :
- phdr.p_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
+ pax_buf[0] = pax_flags & PF_PAGEEXEC ? 'P' :
+ pax_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
- pax_buf[1] = phdr.p_flags & PF_SEGMEXEC ? 'S' :
- phdr.p_flags & PF_NOSEGMEXEC ? 's' : '-';
+ pax_buf[1] = pax_flags & PF_SEGMEXEC ? 'S' :
+ pax_flags & PF_NOSEGMEXEC ? 's' : '-';
- pax_buf[2] = phdr.p_flags & PF_MPROTECT ? 'M' :
- phdr.p_flags & PF_NOMPROTECT ? 'm' : '-';
+ pax_buf[2] = pax_flags & PF_MPROTECT ? 'M' :
+ pax_flags & PF_NOMPROTECT ? 'm' : '-';
- pax_buf[3] = phdr.p_flags & PF_EMUTRAMP ? 'E' :
- phdr.p_flags & PF_NOEMUTRAMP ? 'e' : '-';
+ pax_buf[3] = pax_flags & PF_EMUTRAMP ? 'E' :
+ pax_flags & PF_NOEMUTRAMP ? 'e' : '-';
- pax_buf[4] = phdr.p_flags & PF_RANDMMAP ? 'R' :
- phdr.p_flags & PF_NORANDMMAP ? 'r' : '-';
+ pax_buf[4] = pax_flags & PF_RANDMMAP ? 'R' :
+ pax_flags & PF_NORANDMMAP ? 'r' : '-';
- pax_buf[5] = phdr.p_flags & PF_RANDEXEC ? 'X' :
- phdr.p_flags & PF_NORANDEXEC ? 'x' : '-';
+ pax_buf[5] = pax_flags & PF_RANDEXEC ? 'X' :
+ pax_flags & PF_NORANDEXEC ? 'x' : '-';
}
}
@@ -147,20 +148,20 @@ pax_getflags(PyObject *self, PyObject *args)
return NULL;
}
- ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+ pax_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
- pax_buf[0] = ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
- pax_buf[1] = ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
- pax_buf[2] = ei_flags & HF_PAX_MPROTECT ? 'm' : 'M';
- pax_buf[3] = ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
- pax_buf[4] = ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
- pax_buf[5] = ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
+ pax_buf[0] = pax_flags & HF_PAX_PAGEEXEC ? 'p' : 'P';
+ pax_buf[1] = pax_flags & HF_PAX_SEGMEXEC ? 's' : 'S';
+ pax_buf[2] = pax_flags & HF_PAX_MPROTECT ? 'm' : 'M';
+ pax_buf[3] = pax_flags & HF_PAX_EMUTRAMP ? 'E' : 'e';
+ pax_buf[4] = pax_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
+ pax_buf[5] = pax_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
}
elf_end(elf);
close(fd);
- return Py_BuildValue("s", pax_buf);
+ return Py_BuildValue("si", pax_buf, pax_flags);
}
@@ -168,10 +169,11 @@ static PyObject *
pax_setflags(PyObject *self, PyObject *args)
{
const char *f_name;
- int pax_flags;
- int fd, sts;
+ uint16_t pax_flags;
+ int fd;
Elf *elf;
+
GElf_Ehdr ehdr;
uint16_t ei_flags;
@@ -190,13 +192,13 @@ pax_setflags(PyObject *self, PyObject *args)
return NULL;
}
- if((fd = open(f_name, O_RDONLY)) < 0)
+ if((fd = open(f_name, O_RDWR)) < 0)
{
PyErr_SetString(PaxError, "pax_setflags: open() failed");
return NULL;
}
- if((elf = elf_begin(fd, ELF_C_READ_MMAP, NULL)) == NULL)
+ if((elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL)) == NULL)
{
close(fd);
PyErr_SetString(PaxError, "pax_setflags: elf_begin() failed");
@@ -211,8 +213,6 @@ pax_setflags(PyObject *self, PyObject *args)
return NULL;
}
-
-
if(gelf_getehdr(elf, &ehdr) != &ehdr)
{
elf_end(elf);
@@ -223,54 +223,48 @@ pax_setflags(PyObject *self, PyObject *args)
ei_flags = ehdr.e_ident[EI_PAX] + (ehdr.e_ident[EI_PAX + 1] << 8);
+ ei_flags &= ~HF_PAX_PAGEEXEC;
+ ei_flags &= ~HF_PAX_SEGMEXEC;
+ ei_flags &= ~HF_PAX_MPROTECT;
+ ei_flags |= HF_PAX_EMUTRAMP;
+ ei_flags &= ~HF_PAX_RANDMMAP;
+ ei_flags |= HF_PAX_RANDEXEC;
+
//PAGEEXEC
if(pax_flags & PF_PAGEEXEC)
ei_flags &= ~HF_PAX_PAGEEXEC;
if(pax_flags & PF_NOPAGEEXEC)
ei_flags |= HF_PAX_PAGEEXEC;
- if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
- ei_flags &= ~HF_PAX_PAGEEXEC;
//SEGMEXEC
if(pax_flags & PF_SEGMEXEC)
ei_flags &= ~HF_PAX_SEGMEXEC;
if(pax_flags & PF_NOSEGMEXEC)
ei_flags |= HF_PAX_SEGMEXEC;
- if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
- ei_flags &= ~HF_PAX_SEGMEXEC;
//MPROTECT
if(pax_flags & PF_MPROTECT)
ei_flags &= ~HF_PAX_MPROTECT;
if(pax_flags & PF_NOMPROTECT)
ei_flags |= HF_PAX_MPROTECT;
- if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
- ei_flags &= ~HF_PAX_MPROTECT;
//EMUTRAMP
if(pax_flags & PF_EMUTRAMP)
ei_flags |= HF_PAX_EMUTRAMP;
if(pax_flags & PF_NOEMUTRAMP)
ei_flags &= ~HF_PAX_EMUTRAMP;
- if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
- ei_flags &= ~HF_PAX_EMUTRAMP;
//RANDMMAP
if(pax_flags & PF_RANDMMAP)
ei_flags &= ~HF_PAX_RANDMMAP;
if(pax_flags & PF_NORANDMMAP)
ei_flags |= HF_PAX_RANDMMAP;
- if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
- ei_flags &= ~HF_PAX_RANDMMAP;
//RANDEXEC
if(pax_flags & PF_RANDEXEC)
ei_flags |= HF_PAX_RANDEXEC;
if(pax_flags & PF_NORANDEXEC)
ei_flags &= ~HF_PAX_RANDEXEC;
- if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
- ei_flags |= HF_PAX_RANDEXEC;
-
ehdr.e_ident[EI_PAX] = (uint8_t)ei_flags ;
ehdr.e_ident[EI_PAX + 1] = (uint8_t)(ei_flags >> 8) ;
@@ -283,6 +277,7 @@ pax_setflags(PyObject *self, PyObject *args)
return NULL;
}
+
elf_getphdrnum(elf, &phnum);
for(i=0; i<phnum; ++i)
{
@@ -296,107 +291,7 @@ pax_setflags(PyObject *self, PyObject *args)
if(phdr.p_type == PT_PAX_FLAGS)
{
- //PAGEEXEC
- if(pax_flags & PF_PAGEEXEC)
- {
- phdr.p_flags |= PF_PAGEEXEC;
- phdr.p_flags &= ~PF_NOPAGEEXEC;
- }
- if(pax_flags & PF_NOPAGEEXEC)
- {
- phdr.p_flags &= ~PF_PAGEEXEC;
- phdr.p_flags |= PF_NOPAGEEXEC;
- }
- if((pax_flags & PF_PAGEEXEC) && (pax_flags & PF_NOPAGEEXEC))
- {
- phdr.p_flags &= ~PF_PAGEEXEC;
- phdr.p_flags &= ~PF_NOPAGEEXEC;
- }
-
- //SEGMEXEC
- if(pax_flags & PF_SEGMEXEC)
- {
- phdr.p_flags |= PF_SEGMEXEC;
- phdr.p_flags &= ~PF_NOSEGMEXEC;
- }
- if(pax_flags & PF_NOSEGMEXEC)
- {
- phdr.p_flags &= ~PF_SEGMEXEC;
- phdr.p_flags |= PF_NOSEGMEXEC;
- }
- if((pax_flags & PF_SEGMEXEC) && (pax_flags & PF_NOSEGMEXEC))
- {
- phdr.p_flags &= ~PF_SEGMEXEC;
- phdr.p_flags &= ~PF_NOSEGMEXEC;
- }
-
- //MPROTECT
- if(pax_flags & PF_MPROTECT)
- {
- phdr.p_flags |= PF_MPROTECT;
- phdr.p_flags &= ~PF_NOMPROTECT;
- }
- if(pax_flags & PF_NOMPROTECT)
- {
- phdr.p_flags &= ~PF_MPROTECT;
- phdr.p_flags |= PF_NOMPROTECT;
- }
- if((pax_flags & PF_MPROTECT) && (pax_flags & PF_NOMPROTECT))
- {
- phdr.p_flags &= ~PF_MPROTECT;
- phdr.p_flags &= ~PF_NOMPROTECT;
- }
-
- //EMUTRAMP
- if(pax_flags & PF_EMUTRAMP)
- {
- phdr.p_flags |= PF_EMUTRAMP;
- phdr.p_flags &= ~PF_NOEMUTRAMP;
- }
- if(pax_flags & PF_NOEMUTRAMP)
- {
- phdr.p_flags &= ~PF_EMUTRAMP;
- phdr.p_flags |= PF_NOEMUTRAMP;
- }
- if((pax_flags & PF_EMUTRAMP) && (pax_flags & PF_NOEMUTRAMP))
- {
- phdr.p_flags &= ~PF_EMUTRAMP;
- phdr.p_flags &= ~PF_NOEMUTRAMP;
- }
-
- //RANDMMAP
- if(pax_flags & PF_RANDMMAP)
- {
- phdr.p_flags |= PF_RANDMMAP;
- phdr.p_flags &= ~PF_NORANDMMAP;
- }
- if(pax_flags & PF_NORANDMMAP)
- {
- phdr.p_flags &= ~PF_RANDMMAP;
- phdr.p_flags |= PF_NORANDMMAP;
- }
- if((pax_flags & PF_RANDMMAP) && (pax_flags & PF_NORANDMMAP))
- {
- phdr.p_flags &= ~PF_RANDMMAP;
- phdr.p_flags &= ~PF_NORANDMMAP;
- }
-
- //RANDEXEC
- if(pax_flags & PF_RANDEXEC)
- {
- phdr.p_flags |= PF_RANDEXEC;
- phdr.p_flags &= ~PF_NORANDEXEC;
- }
- if(pax_flags & PF_NORANDEXEC)
- {
- phdr.p_flags &= ~PF_RANDEXEC;
- phdr.p_flags |= PF_NORANDEXEC;
- }
- if((pax_flags & PF_RANDEXEC) && (pax_flags & PF_NORANDEXEC))
- {
- phdr.p_flags &= ~PF_RANDEXEC;
- phdr.p_flags &= ~PF_NORANDEXEC;
- }
+ phdr.p_flags = pax_flags;
if(!gelf_update_phdr(elf, i, &phdr))
{
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 326007e..7a8da3e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -8,7 +8,6 @@ import re
import pax
def get_ldd_linkings(binary):
-
try:
#TODO: when subprocess.DEVNULL makes it to python, change this: http://bugs.python.org/issue5870
ldd_output = subprocess.check_output(['/usr/bin/ldd', binary], stderr=subprocess.PIPE)
@@ -83,8 +82,8 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
for binary in forward_linkings:
try:
- binary_flags = pax.getflags(binary)
- sv = "%s ( %s )" % ( binary, binary_flags )
+ ( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+ sv = '%s ( %s )' % ( binary, binary_flags )
s = sv
except:
missing_binaries.append(binary)
@@ -94,10 +93,10 @@ def print_forward_linkings( forward_linkings, so2library_mappings, verbose ):
for soname in forward_linkings[binary]:
try:
library = so2library_mappings[soname]
- library_flags = pax.getflags(library)
- sv = "%s\n\t%s\t%s ( %s )" % ( sv, soname, library, library_flags )
+ ( library_flags, library_pax_flags ) = pax.getflags(library)
+ sv = '%s\n\t%s\t%s ( %s )' % ( sv, soname, library, library_flags )
if binary_flags != library_flags:
- s = "%s\n\t%s\t%s ( %s )" % ( s, soname, library, library_flags )
+ s = '%s\n\t%s\t%s ( %s )' % ( s, soname, library, library_flags )
count = count + 1
except:
missing_links.append(soname)
@@ -145,8 +144,8 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
try:
library = so2library_mappings[soname]
- library_flags = pax.getflags(library)
- sv = "%s\t%s ( %s )" % ( soname, library, library_flags )
+ ( library_flags, library_pax_flags ) = pax.getflags(library)
+ sv = '%s\t%s ( %s )' % ( soname, library, library_flags )
s = sv
except:
missing_sonames.append(soname)
@@ -155,10 +154,10 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose ):
count = 0
for binary in reverse_linkings[soname]:
try:
- binary_flags = pax.getflags(binary)
- sv = "%s\n\t%s ( %s )" % ( sv, binary, binary_flags )
+ ( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+ sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_flags )
if library_flags != binary_flags:
- s = "%s\n\t%s ( %s )" % ( s, binary, binary_flags )
+ s = '%s\n\t%s ( %s )' % ( s, binary, binary_flags )
count = count + 1
except:
missing_links.append(binary)
@@ -203,12 +202,13 @@ def run_usage():
print 'Program Name : revdep-pax'
print 'Description : Get or set pax flags on an ELF object'
print
- print 'Usage : revdep-pax -f [-v] print out all forward mappings for all system binaries'
- print ' : revdep-pax -r [-v] print out all reverse mappints for all system sonames'
- print ' : revdep-pax -b BINARY [-v] print all forward mappings only for BINARY'
- print ' : revdep-pax -s SONAME [-v] print all reverse mappings only for SONAME'
- print ' : revdep-pax [-h] print out this help'
- print ' : -v verbose, otherwise just print mismatched flags'
+ print 'Usage : revdep-pax -f [-mv] print out all forward mappings for all system binaries'
+ print ' : revdep-pax -r [-mv] print out all reverse mappints for all system sonames'
+ print ' : revdep-pax -b BINARY [-mv] print all forward mappings only for BINARY'
+ print ' : revdep-pax -s SONAME [-mv] print all reverse mappings only for SONAME'
+ print ' : revdep-pax [-h] print out this help'
+ print ' : -v verbose, otherwise just print mismatched flags'
+ print ' : -m prompt to mark the found objects'
print
@@ -225,28 +225,28 @@ def run_reverse(verbose):
print
-def run_binary(binary, verbose):
+def run_binary(binary, verbose, mark):
( linkings, mappings ) = get_ldd_linkings(binary)
-
- binary_flags = pax.getflags(binary)
- print binary, '(', binary_flags, ')'
+ ( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+ print '%s (%s)' % ( binary, binary_flags )
print
- count = 0
+ mismatched_libraries = []
+
for soname in linkings:
try:
library = mappings[soname]
- library_flags = pax.getflags(library)
+ ( library_flags, library_pax_flags ) = pax.getflags(library)
if verbose:
- print '\t', soname, '\t', library, '(', library_flags, ')'
- else:
- if binary_flags != library_flags:
- print '\t', soname, '\t', library, '(', library_flags, ')'
- count = count + 1
+ print '\t%s\t%s ( %s )' % ( soname, library, library_flags )
+ if binary_flags != library_flags:
+ mismatched_libraries.append(library)
+ if not verbose:
+ print '\t%s\t%s ( %s )' % ( soname, library, library_flags )
except:
- print "file for soname %s not found" % soname
+ print 'file for soname %s not found' % soname
- if count == 0:
+ if len(mismatched_libraries) == 0:
print
print '\tNo mismatches'
print
@@ -254,6 +254,27 @@ def run_binary(binary, verbose):
print
print '\tMismatches'
print
+ if mark:
+ print '\tWill mark libraries with %s' % binary_flags
+ print
+ for library in mismatched_libraries:
+ do_marking = False
+ while True:
+ ans = raw_input('\tSet flags for %s (y/n): ' % library)
+ if ans == 'y':
+ do_marking = True
+ break
+ elif ans == 'n':
+ do_marking = False
+ break
+ else:
+ print '\t\tPlease enter y or n'
+
+ if do_marking:
+ pax.setflags(library, binary_pax_flags)
+ ( library_flags, library_pax_flags ) = pax.getflags(library)
+ print '\t%s ( %s )' % ( library, library_flags )
+ print
def invert_so2library_mappings( so2library_mappings ):
@@ -263,7 +284,7 @@ def invert_so2library_mappings( so2library_mappings ):
return library2soname_mappings
-def run_soname(name, verbose, use_soname):
+def run_soname(name, verbose, use_soname, mark):
( forward_linkings, so2library_mappings ) = get_forward_linkings()
reverse_linkings = invert_linkings( forward_linkings )
@@ -276,14 +297,14 @@ def run_soname(name, verbose, use_soname):
linkings = reverse_linkings[soname]
library = so2library_mappings[soname]
- library_flags = pax.getflags(library)
+ ( library_flags, library_pax_flags ) = pax.getflags(library)
print soname, '\t', library, '(', library_flags, ')'
print
count = 0
for binary in linkings:
try:
- binary_flags = pax.getflags(binary)
+ ( binary_flags, binary_pax_flags ) = pax.getflags(binary)
if verbose:
print '\t', binary, '(', binary_flags, ')'
else:
@@ -291,7 +312,7 @@ def run_soname(name, verbose, use_soname):
print '\t', binary, '(', binary_flags, ')'
count = count + 1
except:
- print "cannot obtain pax flags for %s" % binary
+ print 'cannot obtain pax flags for %s' % binary
if count == 0:
print
@@ -305,7 +326,7 @@ def run_soname(name, verbose, use_soname):
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:v')
+ opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:l:vm')
except getopt.GetoptError, err:
print str(err) # will print something like 'option -a not recognized'
run_usage()
@@ -324,6 +345,7 @@ def main():
library = None
verbose = False
+ mark = False
opt_count = 0
@@ -348,6 +370,8 @@ def main():
opt_count += 1
elif o == '-v':
verbose = True
+ elif o == '-m':
+ mark = True
else:
print 'Option included in getopt but not handled here!'
print 'Please file a bug'
@@ -361,12 +385,12 @@ def main():
elif do_reverse:
run_reverse(verbose)
elif binary != None:
- run_binary(binary, verbose)
+ run_binary(binary, verbose, mark)
elif soname != None:
- run_soname(soname, verbose, True)
+ run_soname(soname, verbose, True, mark)
elif library != None:
library = os.path.realpath(library)
- run_soname(library, verbose, False)
+ run_soname(library, verbose, False, mark)
if __name__ == '__main__':
main()
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: e0dc791e4349b94c4faa0be1d287025d34db7f10
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 13 00:36:29 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:03:14 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=e0dc791e
scripts/revdep-pax: fix call to run_usage() on command line errors
---
scripts/revdep-pax | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 576025e..f06bf3d 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -267,11 +267,11 @@ def main():
opts, args = getopt.getopt(sys.argv[1:], 'hfrb:s:v')
except getopt.GetoptError, err:
print str(err) # will print something like 'option -a not recognized'
- usage()
+ run_usage()
sys.exit(1)
if len(opts) == 0:
- usage()
+ run_usage()
sys.exit(1)
do_usage = False
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: 0f3d0e4f2c73eac2be69adf7c7e07edfcb673c72
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 20:15:42 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:04:23 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=0f3d0e4f
scripts/revdep-pax: extend setting flags to reverse mappings
---
scripts/revdep-pax | 34 +++++++++++++++++++++++++++-------
1 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index 7a8da3e..a5636bd 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -301,20 +301,20 @@ def run_soname(name, verbose, use_soname, mark):
print soname, '\t', library, '(', library_flags, ')'
print
- count = 0
+ mismatched_binaries = []
for binary in linkings:
try:
( binary_flags, binary_pax_flags ) = pax.getflags(binary)
if verbose:
- print '\t', binary, '(', binary_flags, ')'
- else:
- if library_flags != binary_flags:
- print '\t', binary, '(', binary_flags, ')'
- count = count + 1
+ print '\t%s ( %s )' % ( binary, binary_flags )
+ if library_flags != binary_flags:
+ mismatched_binaries.append(binary)
+ if not verbose:
+ print '\t%s ( %s )' % ( binary, binary_flags )
except:
print 'cannot obtain pax flags for %s' % binary
- if count == 0:
+ if len(mismatched_binaries) == 0
print
print '\tNo mismatches'
print
@@ -322,6 +322,26 @@ def run_soname(name, verbose, use_soname, mark):
print
print '\tMismatches'
print
+ if mark:
+ print '\tWill mark binaries with %s' % library_flags
+ print
+ for binary in mismatched_binaries:
+ do_marking = False
+ while True:
+ ans = raw_input('\tSet flags for %s (y/n): ' % binary)
+ if ans == 'y':
+ do_marking = True
+ break
+ elif ans == 'n':
+ do_marking = False
+ break
+ else:
+ print '\t\tPlease enter y or n'
+ if do_marking:
+ pax.setflags(binary, library_pax_flags)
+ ( binary_flags, binary_pax_flags ) = pax.getflags(binary)
+ print '\t%s ( %s )' % ( binary, binary_flags )
+ print
def main():
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/
@ 2011-10-17 21:09 Anthony G. Basile
0 siblings, 0 replies; 27+ messages in thread
From: Anthony G. Basile @ 2011-10-17 21:09 UTC (permalink / raw
To: gentoo-commits
commit: 32854a4f874b573339ed1fd43399b1cdc8171464
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 20:55:00 2011 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 21:04:43 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=32854a4f
scripts/{paxmodule.c,revdep-pax}: removed EI_PAX markings, bug #387459
---
scripts/paxmodule.c | 18 +++++++++++++++++-
scripts/revdep-pax | 2 +-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c
index 32c8768..45e9f26 100644
--- a/scripts/paxmodule.c
+++ b/scripts/paxmodule.c
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <unistd.h>
+/* Gentoo bug #387459
#define HF_PAX_PAGEEXEC 1
#define HF_PAX_EMUTRAMP 2
@@ -18,6 +19,7 @@
#define HF_PAX_SEGMEXEC 32
#define EI_PAX 14 // Index to read the PaX flags into ELF header e_ident[] array
+*/
#define BUF_SIZE 7 //Buffer for holding human readable flags
@@ -58,7 +60,9 @@ pax_getflags(PyObject *self, PyObject *args)
char pax_buf[BUF_SIZE];
uint16_t pax_flags;
- GElf_Ehdr ehdr;
+ /* Gentoo bug #387459
+ GElf_Ehdr ehdr;
+ */
GElf_Phdr phdr;
char found_pt_pax;
size_t i, phnum;
@@ -140,6 +144,12 @@ pax_getflags(PyObject *self, PyObject *args)
if(!found_pt_pax)
{
+ //Set to the strictest possible
+ }
+
+ /* Gentoo bug #387459
+ if(!found_pt_pax)
+ {
if(gelf_getehdr(elf, &ehdr) != &ehdr)
{
elf_end(elf);
@@ -157,6 +167,7 @@ pax_getflags(PyObject *self, PyObject *args)
pax_buf[4] = pax_flags & HF_PAX_RANDMMAP ? 'r' : 'R';
pax_buf[5] = pax_flags & HF_PAX_RANDEXEC ? 'X' : 'x';
}
+ */
elf_end(elf);
close(fd);
@@ -174,8 +185,10 @@ pax_setflags(PyObject *self, PyObject *args)
Elf *elf;
+ /* Gentoo bug #387459
GElf_Ehdr ehdr;
uint16_t ei_flags;
+ */
GElf_Phdr phdr;
size_t i, phnum;
@@ -213,6 +226,8 @@ pax_setflags(PyObject *self, PyObject *args)
return NULL;
}
+ /* Gentoo bug #387459
+
if(gelf_getehdr(elf, &ehdr) != &ehdr)
{
elf_end(elf);
@@ -276,6 +291,7 @@ pax_setflags(PyObject *self, PyObject *args)
PyErr_SetString(PaxError, "pax_setflags: gelf_update_ehdr() failed");
return NULL;
}
+ */
elf_getphdrnum(elf, &phnum);
diff --git a/scripts/revdep-pax b/scripts/revdep-pax
index a5636bd..59b8b4e 100755
--- a/scripts/revdep-pax
+++ b/scripts/revdep-pax
@@ -314,7 +314,7 @@ def run_soname(name, verbose, use_soname, mark):
except:
print 'cannot obtain pax flags for %s' % binary
- if len(mismatched_binaries) == 0
+ if len(mismatched_binaries) == 0:
print
print '\tNo mismatches'
print
^ permalink raw reply related [flat|nested] 27+ messages in thread
end of thread, other threads:[~2011-10-17 21:10 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-17 21:09 [gentoo-commits] proj/elfix:elfix-0.2.x commit in: scripts/ Anthony G. Basile
-- strict thread matches above, loose matches on Subject: below --
2011-10-17 21:09 Anthony G. Basile
2011-10-17 21:09 Anthony G. Basile
2011-10-17 21:09 Anthony G. Basile
2011-10-17 21:09 Anthony G. Basile
2011-10-17 21:09 Anthony G. Basile
2011-10-17 21:09 Anthony G. Basile
2011-10-17 21:09 Anthony G. Basile
2011-10-12 10:49 Anthony G. Basile
2011-10-12 10:48 Anthony G. Basile
2011-10-12 10:48 Anthony G. Basile
2011-10-12 10:47 Anthony G. Basile
2011-10-12 10:47 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
2011-10-08 18:54 Anthony G. Basile
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox