3 # ddsect - dissect (and reassemble) raw data dumps using a memory map file
5 # Copyright (C) 2012 Antonio Ospite <ospite@studenti.unina.it>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
32 cat $MAP_FILE | sed -e 's/#.*$//' -e '/^[[:space:]]*$/d' | tr -d ' ' |
35 RANGE=$(echo $line | cut -d ':' -f 1)
36 START_ADDRESS=$(( $(echo $RANGE | cut -d '-' -f 1) ))
37 END_ADDRESS=$(( $(echo $RANGE | cut -d '-' -f 2) ))
39 NAME=$(echo $line | cut -d ':' -f 2 | sed -e 's/^"//' -e 's/"$//')
41 SIZE=$(($END_ADDRESS - $START_ADDRESS))
43 SIZE_KiB=$(($SIZE / 1024))
45 echo "${NAME},${START_ADDRESS},${END_ADDRESS},${SIZE},${SIZE_KiB}"
54 echo "NAME START_ADDRESS END_ADDRESS SIZE SIZE_KiB"
65 parse_map_file $MAP_FILE |
66 while read NAME START_ADDRESS END_ADDRESS SIZE SIZE_KiB;
68 echo_exec dd ibs=1 skip=$START_ADDRESS count=$SIZE if="$IMAGE_FILE" of="${NAME}.bin"
79 parse_map_file $MAP_FILE |
80 while read NAME START_ADDRESS END_ADDRESS SIZE SIZE_KiB;
82 echo_exec dd obs=1 seek=$START_ADDRESS count=$SIZE conv=notrunc if="${NAME}.bin" of="$IMAGE_FILE"
89 usage: $(basename "$0") <OPTION> [ARGS]
91 Where OPTION and ARGS are:
93 info <MAP_FILE> show details of the map file
94 split <INPUT_IMAGE> <MAP_FILE> split sections as per MAP_FILE
95 join <MAP_FILE> <OUTPUT_IMAGE> join sections as per MAP_FILE
96 -h|--help|help show this help message
100 check_option_argument()
104 [ "x$ARGUMENT" != "x" ] || { echo "No $DESCRIPTION passed." 1>&2; usage; exit 1; }
107 check_input_file_argument()
110 FILE_DESCRIPTION="$2"
111 check_option_argument "$FILE" "$FILE_DESCRIPTION"
112 [ -r "$FILE" ] || { echo "Invalid $FILE_DESCRIPTION." 1>&2; exit 1; }
115 command -v dd >/dev/null 2>&1 || { echo "$(basename "$0"): command 'dd' is missing." 1>&2 ; exit 1; }
120 check_input_file_argument "$MAP_FILE" "map file"
122 command -v column >/dev/null 2>&1 || { echo "$(basename "$0"): command 'column' is missing." 1>&2 ; exit 1; }
124 print_map_info "$MAP_FILE"
129 check_input_file_argument "$INPUT_IMAGE" "input image"
132 check_input_file_argument "$MAP_FILE" "map file"
134 split_image "$INPUT_IMAGE" "$MAP_FILE"
139 check_input_file_argument "$MAP_FILE" "map file"
142 check_option_argument "$OUTPUT_IMAGE" "output image"
144 join_image "$MAP_FILE" "$OUTPUT_IMAGE"
153 echo "Missing or unknown option." 1>&2