index : builder | |
Archlinux32 build system | gitolite user |
summaryrefslogtreecommitdiff |
-rwxr-xr-x | bin/check-opcodes | 18 | ||||
-rwxr-xr-x | bin/opcode | 49 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/opcode_list (renamed from conf/Opcode_list) | 0 |
diff --git a/bin/check-opcodes b/bin/check-opcodes index fd740b1..c7ab4a9 100755 --- a/bin/check-opcodes +++ b/bin/check-opcodes @@ -1,5 +1,8 @@ #!/bin/sh +# shellcheck disable=SC2086 + +# shellcheck source=conf/default.conf . "${0%/*}/../conf/default.conf" usage( ) { @@ -21,7 +24,7 @@ VERBOSE=0 EXIT_CODE=0 log( ) { if test $VERBOSE = 1; then - echo $* + echo "$@" fi } @@ -31,7 +34,7 @@ err( ) { } tmp_dir=$(mktemp -d "${work_dir}/tmp.check-opcodes.XXXXXX") -trap "rm -rf --one-file-system '${tmp_dir:?}'" EXIT +trap 'rm -rf --one-file-system "${tmp_dir:?}"' EXIT ARCH=i686 @@ -97,14 +100,15 @@ esac log "Checking for architecture: $ARCH ($OPCODE_ARGS)" bsdtar --no-fflags -x -C $tmp_dir -f $PACKAGE -for absfile in `find $tmp_dir -name '*.so*' -type f`; do - file=`basename $absfile` +# shellcheck disable=SC2044 +for absfile in $(find $tmp_dir -name '*.so*' -type f); do + file=$(basename $absfile) log "Checking shared library: $file" readelf -a $absfile > $tmp_dir/$file.elf objdump -f $absfile > $tmp_dir/$file.objdump file $absfile > $tmp_dir/$file.file - arch=`grep ^architecture $tmp_dir/$file.objdump | sed 's/^architecture: //g' | cut -f 1 -d ,` + arch=$(grep ^architecture $tmp_dir/$file.objdump | sed 's/^architecture: //g' | cut -f 1 -d ,) case $arch in i386:x86-64) arch='x86_64' @@ -118,7 +122,7 @@ for absfile in `find $tmp_dir -name '*.so*' -type f`; do esac log " Objdump architecture: $arch" - archelf=`grep '^ \+Class' $tmp_dir/$file.elf | cut -f 2 -d : | tr -d ' '` + archelf=$(grep '^ \+Class' $tmp_dir/$file.elf | cut -f 2 -d : | tr -d ' ') case $archelf in ELF64) archelf='x86_64' @@ -142,7 +146,7 @@ for absfile in `find $tmp_dir -name '*.so*' -type f`; do fi objdump -M intel -d $absfile > $tmp_dir/$file.asm - bad_opcodes=`cat $tmp_dir/$file.asm | ${base_dir}/bin/opcode $OPCODE_ARGS -m 1 | wc -l` + bad_opcodes=$(${base_dir}/bin/opcode $OPCODE_ARGS -m 1 < $tmp_dir/$file.asm | wc -l) if test $bad_opcodes != 0; then case $ARCH in i486) @@ -24,6 +24,9 @@ # with Opcode_WILLAMETTE_Base # * Remove all line in Opcode_ARM_THUMB # return values + +# shellcheck disable=SC2001,SC2034,SC2086 + EXIT_FOUND=0 EXIT_NOT_FOUND=1 EXIT_USAGE=2 @@ -42,7 +45,8 @@ Line_Numbers=false Leading_Context=0 Trailing_Context=0 -source "${0%/*}/../conf/Opcode_list" # include opcodes from a separate file +# shellcheck source=lib/opcode_list +source "${0%/*}/../lib/opcode_list" # include opcodes from a separate file # GAS-specific opcodes (unofficial names) belonging to the x64 instruction set. # They are generated by GNU tools (e.g. GDB, objdump) and specify a variant of ordinal opcodes like NOP and MOV. @@ -162,7 +166,7 @@ usage() { echo "The script uses Intel opcode syntax. When used in conjunction with objdump, \`-M intel' must be set in order to prevent opcode translation using AT&T syntax." echo echo "BE AWARE THAT THE LIST OF KNOWN INSTRUCTIONS OR INSTRUCTIONS SUPPORTED BY PARTICULAR ARCHITECTURES (ESPECIALLY AMD'S) IS ONLY TENTATIVE AND MAY CONTAIN MISTAKES!" - kill -TRAP $TOP_PID + kill -TRAP "$TOP_PID" } list_contains() { # Returns 0 if $2 is in array $1, 1 otherwise. @@ -175,25 +179,25 @@ list_contains() { # Returns 0 if $2 is in array $1, 1 otherwise. build_instruction_set() { # $1 = enum { Arch, InstSet }, $2 = architecture or instruction set as obtained using -L or -l, $3 = "architecture"/"instruction set" to be used in error message local e - list_contains "`eval echo \\\$${1}List`" "$2" || (echo "$2 is not a valid $3."; usage) # Test if the architecture/instruction set is valid. - if [ -n "`eval echo \\\$${1}_${2}`" ]; then # Add the instruction set(s) if any. - for e in `eval echo \\\$${1}_${2}`; do # Skip duplicates. + list_contains "$(eval echo \\\$${1}List)" "$2" || (echo "$2 is not a valid $3."; usage) # Test if the architecture/instruction set is valid. + if [ -n "$(eval echo \\\$${1}_${2})" ]; then # Add the instruction set(s) if any. + for e in $(eval echo \\\$${1}_${2}); do # Skip duplicates. list_contains "$InstSet_Base" $e || InstSet_Base="$e $InstSet_Base" done fi if [ $Recursive = true ]; then - for a in `eval echo \\\$${1}Dep_$2`; do + for a in $(eval echo \\\$${1}Dep_$2); do build_instruction_set $1 $a "$3" done fi - InstSet_Base="`echo $InstSet_Base | sed 's/$ *//'`" # Remove trailing space. + InstSet_Base=$(echo $InstSet_Base | sed 's/$ *//') # Remove trailing space. } -trap "exit $EXIT_USAGE" TRAP # Allow usage() function to abort script execution. +trap 'exit $EXIT_USAGE' TRAP # Allow usage() function to abort script execution. export TOP_PID=$$ # PID of executing process. # Parse command line arguments. -while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do +while getopts ":ra:s:LliIcf:d:D:CvVm:nB:A:h" o; do case $o in r) Recursive=true ;; a) build_instruction_set Arch "$OPTARG" "architecture" ;; @@ -205,19 +209,19 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do echo $InstSet_Base exit $EXIT_USAGE else - echo -e "No instruction set or architecture set.\n" + echo -e "No instruction set or architecture set.\\n" usage fi ;; I) if [ -n "$InstSet_Base" ]; then for s in $InstSet_Base; do - echo -ne "\e[31;1m$s:\e[0m " + echo -ne "\\e[31;1m$s:\\e[0m " eval echo "\$Opcode_$s" done exit $EXIT_USAGE else - echo -e "No instruction set or architecture set.\n" + echo -e "No instruction set or architecture set.\\n" usage fi ;; @@ -226,12 +230,12 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do # Unlike architectures, instruction sets are disjoint. Found=false for s in $InstSetList; do - for b in `eval echo \\\$InstSet_$s`; do + for b in $(eval echo \\\$InstSet_$s); do Found_In_Base=false - for i in `eval echo \\\$Opcode_$b`; do + for i in $(eval echo \\\$Opcode_$b); do if [[ "$i" =~ ^$OPTARG$ ]]; then - $Found_In_Base || echo -ne "Instruction set \e[33;1m$s\e[0m (base instruction set \e[32;1m$b\e[0m):" - echo -ne " \e[31;1m$i\e[0m" + $Found_In_Base || echo -ne "Instruction set \\e[33;1m$s\\e[0m (base instruction set \\e[32;1m$b\\e[0m):" + echo -ne " \\e[31;1m$i\\e[0m" Found_In_Base=true Found=true fi @@ -240,7 +244,7 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do done done if [ $Found = false ]; then - echo -e "Operation code \e[31;1m$OPTARG\e[0m has not been found in the database of known instructions." \ + echo -e "Operation code \\e[31;1m$OPTARG\\e[0m has not been found in the database of known instructions." \ "Perhaps it is translated using other than Intel syntax. If obtained from objdump, check if the \`-M intel' flag is set." \ "Be aware that the search is case sensitive by default (you may use the -C flag, otherwise only lower case opcodes are accepted)." exit $EXIT_NOT_FOUND @@ -259,13 +263,13 @@ while getopts ":ra:s:LliIcf:Fd:D:CvVm:nB:A:h" o; do A) Trailing_Context=$OPTARG ;; h) usage ;; \?) - echo -e "Unknown option: -$OPTARG\n" + echo -e "Unknown option: -$OPTARG\\n" usage ;; esac done shift $((OPTIND-1)) -[ -n "$1" ] && echo -e "Unknown command line parameter: $1\n" && usage +[ -n "$1" ] && echo -e "Unknown command line parameter: $1\\n" && usage [ -z "$InstSet_Base" ] && usage # Create list of grep parameters. @@ -279,12 +283,13 @@ Grep_Params="--color=auto -B $Leading_Context -A $Trailing_Context" # Build regular expression for use in grep. RegEx="" for s in $InstSet_Base; do - eval RegEx=\"$RegEx \$Opcode_$s\" + eval 'RegEx="$RegEx $Opcode_'"$s"'"' done # Add leading and trailing opcode separators to prevent false positives. -RegEx="$Leading_Separator`echo $RegEx | sed "s/ /$(echo "$Trailing_Separator"|sed 's/[\/&]/\\\&/g')|$(echo "$Leading_Separator"|sed 's/[\/&]/\\\&/g')/g"`$Trailing_Separator" +RegEx="$Leading_Separator$(echo $RegEx | sed "s/ /$(echo "$Trailing_Separator"|sed 's/[\/&]/\\\&/g')|$(echo "$Leading_Separator"|sed 's/[\/&]/\\\&/g')/g")$Trailing_Separator" -[ $Verbose = true -a $Count_Matching = false ] && RegEx="$RegEx|\$" +[ $Verbose = true ] && [ $Count_Matching = false ] && RegEx="$RegEx|\$" +# shellcheck disable=SC2086 # The actual search. grep $Grep_Params -E "$RegEx" && exit $EXIT_FOUND || exit $EXIT_NOT_FOUND diff --git a/conf/Opcode_list b/lib/opcode_list index 213321f..213321f 100644..100755 --- a/conf/Opcode_list +++ b/lib/opcode_list |