Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions dumpIfs.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@ PRGNAME=$0

DIRNAME=$(dirname $0)

DUMPIFS=$DIRNAME/dumpifs
DUMPIFS=$(realpath $DIRNAME/dumpifs)

prnUsageAndQuit()
{
echo "Usage: $PRGNAME <ifs image> <destination directory>"
exit
echo "Usage: $PRGNAME <ifs image> <destination directory>"
exit
}

if [ "x$1" = "x" ];then
prnUsageAndQuit
prnUsageAndQuit
fi

if [ "x$2" = "x" ];then
prnUsageAndQuit
prnUsageAndQuit
fi

dirs=$($DUMPIFS $1 | grep -v ^[a-zA-Z]|grep -v '\-\-\-\-'|awk '{print($3)}'|sort -u |xargs -n 1 dirname |sort -u)
IFS_FILE=$(realpath $1)

dirs=$($DUMPIFS ${IFS_FILE} | grep -v ^[a-zA-Z]|grep -v '\-\-\-\-'|awk '{print($3)}'|sort -u |xargs -n 1 dirname |sort -u)
for d in $dirs;do
theDir=$2/$d
echo mkdir -p $theDir
mkdir -p $theDir
theDir=$2/$d
echo mkdir -p $theDir
mkdir -p $theDir
done

echo "Enter dir $2"
cd $2

for x in $($DUMPIFS ../$1 | grep -v ^[a-zA-Z]| awk '{print($3)}'|sort -u |xargs -n 1 basename)
do
$DUMPIFS -x ../$1 $x
for x in $($DUMPIFS "${IFS_FILE}" | grep -v ^[a-zA-Z]| awk '{print($3)}'|sort -u |xargs -n 1 basename)
do
$DUMPIFS -x "${IFS_FILE}" $x
done
cd ..

Binary file modified dumpifs
100644 → 100755
Binary file not shown.
18 changes: 13 additions & 5 deletions dumpifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,6 @@ int mkdir_p(const char *path)
}

void extract_file(FILE *fp, int ipos, struct image_file *ent) {
char *name;
FILE *dst;
struct utimbuf buff;
struct extract_file *ef;
Expand All @@ -1003,7 +1002,14 @@ void extract_file(FILE *fp, int ipos, struct image_file *ent) {
return;
}

name = (flags & FLAG_BASENAME) ? basename(ent->path) : ent->path;
// Both dirname() and basename() may modify the contents of path, so we'll use copies
const size_t len = strlen(ent->path);
char ent_path_copy[len];
strncpy(ent_path_copy, ent->path, len);

char* name = (flags & FLAG_BASENAME) ? basename(ent_path_copy) : ent->path;
// Reset in case it was altered by basename()
strncpy(ent_path_copy, ent->path, len);

if ( extract_files != NULL ) {
for ( ef = extract_files; ef != NULL; ef = ef->next ) {
Expand All @@ -1018,12 +1024,14 @@ void extract_file(FILE *fp, int ipos, struct image_file *ent) {
processing_done = 1;
}
}
/*
if(mkdir_p(dirname(ent->path))) {

if(mkdir_p(dirname(ent_path_copy))) {
printf("unable to mkdir -p for %s\n", name);
return;
}
*/
// Reset because it was probably altered by dirname()
strncpy(ent_path_copy, ent->path, len);

if(!(dst = fopen(name, "wb"))) {
error(0, "Unable to open %s: %s\n", name, strerror(errno));
}
Expand Down