Sponsored Content
Top Forums UNIX for Advanced & Expert Users A hexdumper using echo only... Post 302932607 by wisecracker on Thursday 22nd of January 2015 06:19:24 PM
Old 01-22-2015
Right guys...

This is the finished hex dumper for my new Android phone and it is running just great.
Believe it or not it is marginally quicker than the OSX version... <shock>
Code:
#!/system/bin/sh
# [./]hex </full/path/to/filename> ['delimiter_character']<CR>
if [ "$1" == "" ]
then
	echo "Usage: [./]hex </full/path/to/filename> ['delimiter_character']<CR>"
	exit 1
fi
. /storage/sdcard0/Home/bin/ENVARC
ifs_str="$IFS"
IFS=""
if [ ! -f $TMPDIR/00.HEX ]
then
	for high_nibble in 0 1 2 3 4 5 6 7 8 9 A B C D E F
	do
		for low_nibble in 0 1 2 3 4 5 6 7 8 9 A B C D E F
		do
			echo -e -n "\x$high_nibble$low_nibble" > $TMPDIR/$high_nibble$low_nibble'.HEX'
		done
	done
fi
listing=$(ls $TMPDIR/*.HEX)
count=0
char=""
hexval="$TMPDIR/00.HEX"
subscript=0
chr=""
while read -s -d '' -r -n 1 char
do
	subscript=0
	count=0
	while [ $count -le 255 ]
	do
		hexval="${listing:$subscript:${#hexval}}"
		chr=$(cat $hexval)
		if [ "$char" == "$chr" ]
		then
			if [ "$chr" == "" ]
			then
				echo -n "00$2"
				break
			fi
			if [ "$chr" != "" ]
			then
				echo -n "${hexval:$((${#hexval}-6)):2}$2"
				break
			fi
		fi
		subscript=$((subscript+${#hexval}+1))
		count=$((count+1))
		if [ $count -eq 256 ]
		then
			echo -n "0A$2"
		fi
	done
done < $1
IFS="$ifs_str"
exit 0

The absolute address(es) I had to create manually...
ENVARC is this file too...
Note that TMPDIR does not exist in Android so why not use it... ;o)
Code:
#!/system/bin/sh
# ENVARC
PATH=$PATH:/storage/sdcard0/Home/bin
TMPDIR=/storage/sdcard0/Home/tmp

Also tr and dos2unix do not exist either so this is another tool for the phone generated from minimal Android tools...
This is a dos2unix work-alike...
Code:
#!/system/bin/sh
# [./]d2u <infile> [outfile]<CR>
. /storage/sdcard0/Home/bin/ENVARC
ifs_str="$IFS"
IFS=""
newfile=""
substring=0
outfile=$2
if [ "$1" == "" ]
then
	echo "Usage: [./]d2u <infile> [outfile]..."
	exit 1
fi
if [ "$2" == "" ]
then
	outfile=$1
fi
read -s -d '' -r oldfile < $1
while [ $substring -lt ${#oldfile} ]
do
	if [ "${oldfile:$substring:1}" == $'\r' ]
	then
		substring=$((substring+1))
	else
		newfile=$newfile${oldfile:$substring:1} 
		substring=$((substring+1))
	fi
done
IFS="$ifs_str"
echo -n "$newfile" > $outfile
echo "File, $1, now converted to UNIX format..."
exit 0

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

echo with \n

Hi, When I do /usr/ucb/echo "message \n" in bone shell program , \n never works as new line feeder. It just showed it as part of my message. Is there something wrong with my system? Thanks! (3 Replies)
Discussion started by: whatisthis
3 Replies

2. UNIX for Advanced & Expert Users

What does echo ^[[r do?

I tried echo ^[[r and it takes the cursor to first line in the telnet window... and echo ^[[32m changes font color to green .... Also echo ^[[00ff takes cursor to first command line in the current window (Note : ^ is entered as Ctrl + V and first [ as Escape character) Wud like to know how... (1 Reply)
Discussion started by: hamsasal
1 Replies

3. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

4. Shell Programming and Scripting

Using Echo

Hi All, Need help in resoving the issue . Can anyone let me know how to get fix length using unix shellscript. For Ex: echo "NUMBER OF RECORDS "${NO_OF_ROWS}"\nFILE CREATION DATE&TIME "${PROD_DT}" output should be : NUMBER OF RECORDS 2546 CREATIN DATE&TIME 2009-12-01 Each... (14 Replies)
Discussion started by: Samtel
14 Replies

5. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

6. Shell Programming and Scripting

Help with echo

Hi Guys, I need to print a value in the same line , But when we use the echo instead the loops (while), the value goes to the next line.. Can you help me in this.. Thanks For your help in advance. (6 Replies)
Discussion started by: mac4rfree
6 Replies

7. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

8. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

9. UNIX for Dummies Questions & Answers

Difference between echo `ls -l` and echo "`ls -l`" ?

Hi guys, Been messing around with shell programming for a couple of days and I found something that was pretty odd in the behavior of the echo command. Below is an example-: When I type the following in my /home directory from my lxterminal in Debian-: echo "`ls -l`" I get the... (2 Replies)
Discussion started by: sreyan32
2 Replies

10. Programming

Python hexdumper with a difference.

Hi guys... I haven't done any real Python code since I started messing with Shell Scripting in January 2012 when I started AudioScope. Well I fished a little project out of my ANCIENT AMIGA files which created a raw hexdump of any binary file within reason for a stock A1200(HD). Well... (0 Replies)
Discussion started by: wisecracker
0 Replies
aha(1)								 Ansi HTML Adapter							    aha(1)

NAME
aha - Ansi HTML Adapter SYNOPSIS
aha [options] [-f datei] DESCRIPTION
aha takes SGR-colored Input and prints W3C conform HTML-Code. aha reads the Input from a file or stdin and writes HTML-Code to stdout. OPTIONS
--help , -h , -? A help like this --black , -b Black Background and white "standard color" --pink , -p Pink Background --iso X , -i X Uses ISO 8859-X instead of utf-8. X must be 1..16 --title X , -t X Gives the html output the title --line-fix , -l Uses a fix for inputs using control sequences to change the cursor position like htop. It's a hot fix, it may not work with any pro- gram like htop. (See EXAMPLE) EXAMPLE
aha --help | aha --black --title "the awesome aha help"> aha-help.htm Creates an HTML file with the help of aha with black background colordiff oldfile.c newfile.c | aha > colordiff.htm Creates an HTML file with a colorful diff-output of two files "oldfile.c" and "newfile.c" with white background ls --color=always | aha --pink > ls.htm Creates an HTML file with a colorful ls-output with pink background. echo a | htop | aha --black --line-fix > htop.htm Creates an HTML file with the output of htop. You have to use --line-fix due the other new-line-commands htop uses. AUTHOR
Copyleft Alexander Matthes aka Ziz 2011 zizsdl@googlemail.com SEE ALSO
http://ziz.delphigl.com/tool_aha.php August 31, 2011 aha(1)
All times are GMT -4. The time now is 03:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy