-
Notifications
You must be signed in to change notification settings - Fork 1
/
srec2bin.sh
executable file
·53 lines (41 loc) · 1.13 KB
/
srec2bin.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#
# a script to convert a binary codeplug to an srecord codeplug which is able to be loaded in CPS
# Copyright Bryan Fields 2020
# Licensed under the GPLv2
# This is a PoC. Please don't use this.
#
#
usage()
{
echo "used to convert a CPS srec file to binary for ayalisis"
echo "Usage: srec2bin.sh input.bin output.srec"
}
while [ "$1" != "" ]; do
case $1 in
-i | --in ) shift
inputfilename=$1
;;
-o | --out) shift
outputfilename=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
# remove the header of 0x322 bytes
dd if=$inputfilename of=tmp-stage-1.srec bs=1 skip=802
#conver to binary
srec_cat -Output -Binary tmp-stage-1.srec >tmp-stage-2.bin
# Then the first 0x5 bytes must be removed from the binary file.
# 0x0000 will be the segment starting at 0x280 in a normal code plug.
dd if=tmp-stage-2.bin of=tmp-stage-3.bin bs=1 skip=5
# add 0x27F bytes to the file
printf '\x02\x80' >$outputfilename
dd if=/dev/zero bs=1 count=638 >> $outputfilename
dd if=tmp-stage-3.bin >> $outputfilename
#rm tmp-stage-2.bin tmp-stage-3.bin tmp-stage-1.srec