Reverse Engineering a Samsung Scanner Button, page 8
Pages: 1 2 3 4 5 6 7 8
Step 8: Write the code, part2
Now that we have written the C code and compiled our binary, here is the shell script.
#!/bin/bash
SCANROOT="/data/network/scans"
LOGFILE="/var/log/scanlog"
N=0
# paper sizes
# us letter 216 x 279 mm (8.5 x 11 inches)
# us legal 216 x 356 mm (8.5 x 14 inches )
# us ledger 279 x 432 mm (11 x 17 inches )
# infinite loop, repeating every 1 seconds **********************************************
while :
do
# run the command that will query the scanner button
/usr/local/bin/sbuttond
STATUS=$? # this is whatever the c code returns when you run sbuttond
case "$STATUS" in
0) #echo "Idle - itteration $N"
;;
1) echo "Scan now - itteration $N"
DATE=`date +%Y-%m-%d`
TIME=`date +%H%M%S`
DESTDIR=$SCANROOT/$DATE
FILENAME=$TIME.tiff
TEMP="/temp"
FIX=0
CONVERT=0
# create the directory if it doesn't exist
if [ ! -d "$DESTDIR" ]; then
mkdir -p $DESTDIR
fi
# scan the image and store it in the temp directory (we are using us letter ( 216 x 279mm ))
/usr/bin/scanimage -l 0 -t 0 -x 215 -y 280 --resolution=300 --format=tiff > $TEMP/$FILENAME
# fix brightness/contrast?
if [ $FIX = 1 ]; then
# fix the brightness and contrast settings for the Samsung SCX-4305w
/usr/local/bin/convert -brightness-contrast -2,+22 $TEMP/$FILENAME $TEMP/$TIME.new.tiff
rm -f $TEMP/$FILENAME
mv $TEMP/$TIME.new.tiff $TEMP/$FILENAME
fi
# convert to .jpg?
if [ $CONVERT = 1 ]; then
/usr/local/bin/convert -resize 2550x3304 -quality 100% $TEMP/$FILENAME $TEMP/$TIME.jpg
rm -f $TEMP/$FILENAME
FILENAME=$TIME.jpg
fi
mv $TEMP/$FILENAME $DESTDIR
echo "File $DESTDIR/$FILENAME was created." >> $LOGFILE
;;
2) echo "Error code 2: could not initialize libusb object!!!" >> $LOGFILE
;;
3) echo "Error code 3: could not get device list!!!" >> $LOGFILE
;;
# 4 - this is the message you get when the unit is off
4) echo "Error code 4: could not open device!!!" >> $LOGFILE
;;
5) echo "Error code 5: could not detach kernel driver!!!" >> $LOGFILE
;;
6) echo "Error code 6: could not claim interface!!!" >> $LOGFILE
;;
7) echo "Error code 7: could not query the endpoint!!!" >> $LOGFILE
;;
esac
N=`expr $N + 1`
sleep 3
done
We are done! With this script running, it will know when the scan button is pressed and then it will take action by scanning and storing the file in the specified directory.
Happy reversing.