forked from rlane/ubpf
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split file into directory and base name
Signed-off-by: Alan Jowett <[email protected]>
- Loading branch information
1 parent
0acdd2e
commit 8a24eb2
Showing
1 changed file
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Split the file name into path and base name | ||
path=$(dirname $1) | ||
base=$(basename $1) | ||
|
||
# Get the first 4 bytes from the file (which is the length of the program) | ||
input="$(xxd -p -l 4 $1)" | ||
input="$(xxd -p -l 4 $base)" | ||
# Convert from little endian | ||
input="${input:6:2}${input:4:2}${input:2:2}${input:0:2}" | ||
|
||
# Convert input from hex string to value | ||
length=$((16#$input)) | ||
|
||
# Extract the hash part from the file name | ||
hash=$(echo $1 | cut -d'-' -f2-) | ||
hash=$(echo $base | cut -d'-' -f2-) | ||
|
||
# Copy the program to a file named program-$hash | ||
echo "Extracting program-$hash..." | ||
dd if=$1 of=program-$hash bs=1 skip=4 count=$length 2> /dev/null | ||
dd if=$1 of=$path/program-$hash bs=1 skip=4 count=$length 2> /dev/null | ||
|
||
echo "Extracting memory-$hash..." | ||
# Copy the rest to a file named memory-$hash | ||
dd if=$1 of=memory-$hash bs=1 skip=$((4 + $length)) 2> /dev/null | ||
dd if=$1 of=$path/memory-$hash bs=1 skip=$((4 + $length)) 2> /dev/null | ||
|
||
echo "Disassembling program-$hash..." | ||
# Unassembly program using bin/ubpf-disassembler | ||
bin/ubpf-disassembler program-$hash > program-$hash.asm | ||
bin/ubpf-disassembler $path/program-$hash > $path/program-$hash.asm | ||
|
||
echo "Program size: $(stat -c %s program-$hash)" | ||
echo "Memory size: $(stat -c %s memory-$hash)" | ||
echo "Program size: $(stat -c %s $path/program-$hash)" | ||
echo "Memory size: $(stat -c %s $path/memory-$hash)" | ||
|
||
echo "Disassembled program:" | ||
cat program-$hash.asm | ||
cat $path/program-$hash.asm | ||
|
||
echo "Memory contents:" | ||
xxd memory-$hash | ||
xxd $path/memory-$hash |