#! /opt/bin/dash # # os/prog/paging-multilevel-translate/post.sh # works best with paging-multilevel-translate.py modified to: # - print page numbers and PDBR in hex # - print memory dump column headings export PATH="/opt/bin:/bin:/usr/bin"; s="123456789" #echo "Content-type: text/plain\n"; in=$(cat); echo "in = \"$in\""; exit echo "Content-type: text/html\n\npaging-multilevel-translate" user=`echo "${REMOTE_USER}" | tr -dc '[:alnum:]' | tr '[:upper:]' '[:lower:]'` if [ -z "$user" ]; then echo "Bad user: ${REMOTE_USER} -> $user"; exit 1; fi if [ -n "$HTTP_HOST" ]; then cd /os/prog/paging-multilevel-translate || exit 1; fi # tomato = #FF6347 # lightgreen = #90EE90 # in=$(cat | egrep -v '#FF6347|#90EE90') useed=$(echo "$in" | awk '{ if( $2 == "useed") { gsub(/[^0-9]/,"",$3); print $3; exit; }}') #echo "
$in\n
" if [ -n "$useed" ]; then seed="$useed" msg="- seed = $seed" else x=$(perl -e "print unpack(\"C*\",$user);"); seed="${s}${x}" #echo "
s = $s, x = $x, seed = $seed
" msg="" fi echo "$user - paging-multilevel-translate results $msg

green = correct
    red = wrong

" #echo "

"
#python3 ./paging-multilevel-translate.py -s "$seed" -c | grep '^Virtual'
#echo "
" #exit # Virtual Address 2c03: # --> pde index:0xb [decimal 11] pde contents:0xc4 (valid 1, pfn 0x44 [decimal 68]) # --> pte index:0x0 [decimal 0] pte contents:0xd7 (valid 1, pfn 0x57 [decimal 87]) # --> Translates to Physical Address 0xae3 --> Value: 16 # Virtual Address 7fd7: # --> pde index:0x1f [decimal 31] pde contents:0x92 (valid 1, pfn 0x12 [decimal 18]) # --> pte index:0x1e [decimal 30] pte contents:0x7f (valid 0, pfn 0x7f [decimal 127]) # --> Fault (page table entry not valid) # Virtual Address 390f: # --> pde index:0xe [decimal 14] pde contents:0x7f (valid 0, pfn 0x7f [decimal 127]) # --> Fault (page directory entry not valid) out=$( (echo "$in"; python3 ./paging-multilevel-translate.py -s "$seed" -c) | awk 'function hex(h) { if( index(h,"0x") == 1) h=substr(h,3); # remove leading 0x while(length(h)>3 && index(h,"0") == 1) h=substr(h,2); # remove excess leading zeros while(length(h)<3) h = "0"h; return "0x"h; } # add leading zeros to make length 3 BEGIN { v=0; print "\ \ "; print "\ \ \ "; } { # each line of user input from paging-multilevel-translate-post looks like: U name value if( $1 != "") { if( $1 == "U") u[$2]=$3; # tv=1 for valid ti,tc, since valid ti could be 0 else if( $1 == "Virtual") { split($3,t,":"); va=t[1]; di=dc=ti=tc=pa=pv="0x000"; tv=0; } else if( $2 == "pde") { split($3,t,":"); di=hex(t[2]); split($7,t,":"); dc=hex(t[2]); } else if( $2 == "pte") { split($3,t,":"); ti=hex(t[2]); split($7,t,":"); tc=hex(t[2]); tv=1; } else if( $2 == "Translates") { pa=hex($6); pv=hex($9); } # check user answers if( $2 == "Translates" || $2 == "Fault") { print ""; x=u["d"v"di"]; if( x != "" && hex(x) == di) color="#90EE90"; else color="#FF6347"; print ""; x=u["d"v"dc"]; if( x != "" && hex(x) == dc) color="#90EE90"; else color="#FF6347"; print ""; x=u["t"v"ti"]; if( x != "" && hex(x) == ti) color="#90EE90"; else color="#FF6347"; print ""; x=u["t"v"tc"]; #-- bug if valid ti is 0: #-- if( (x != "" && hex(x) == tc) || (x == "" && ti == "0x000" && color == "#90EE90") ) if( (x != "" && hex(x) == tc) || (x == "" && tv == 0 && color == "#90EE90") ) color="#90EE90"; else color="#FF6347"; print ""; x=u["p"v"pa"]; if( x != "" && hex(x) == pa) color="#90EE90"; else color="#FF6347"; print ""; x=u["p"v"pv"]; if( (x != "" && hex(x) == pv) || (x == "" && pa == "0x000" && color == "#90EE90") ) color="#90EE90"; else color="#FF6347"; print ""; print ""; ++v; }}}' ) if [ -z "$useed" ]; then bad=$(echo "$out" | grep "#FF6347" | wc -l) good=$(echo "$out" | grep "#90EE90" | wc -l) log=$(echo "$in" | tr -dc '[:alnum:]') echo "$(date) $user good $good bad $bad in: $log" >> log fi echo "$out
 PDEPTE 
  #  VAindexcontentsindexcontentsPAvalue
"v"   "va"   "x"   "x"   "x"   "x"   "x"   "x"
"