Skip to content

Commit

Permalink
Fix #144
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Oct 10, 2018
1 parent 021da9d commit bc31934
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
17 changes: 13 additions & 4 deletions UEFIExtract/ffsdumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ USTATUS FfsDumper::dump(const UModelIndex & root, const UString & path, const Du
return U_DIR_ALREADY_EXIST;

USTATUS result = recursiveDump(root, path, dumpMode, sectionType, guid);
if (result)
if (result) {
return result;
else if (!dumped)
} else if (!dumped) {
removeDirectory(path);
return U_ITEM_NOT_FOUND;
}

return U_SUCCESS;
}

Expand Down Expand Up @@ -61,6 +64,8 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
return U_FILE_OPEN;
const UByteArray &data = model->header(index);
file.write(data.constData(), data.size());

dumped = true;
}
}

Expand All @@ -77,6 +82,8 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
return U_FILE_OPEN;
const UByteArray &data = model->body(index);
file.write(data.constData(), data.size());

dumped = true;
}
}

Expand All @@ -99,6 +106,8 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
file.write(headerData.constData(), headerData.size());
file.write(bodyData.constData(), bodyData.size());
file.write(tailData.constData(), tailData.size());

dumped = true;
}
}

Expand All @@ -121,9 +130,9 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
if (!file)
return U_FILE_OPEN;
file << info.toLocal8Bit();
}

dumped = true;
dumped = true;
}
}

USTATUS result;
Expand Down
6 changes: 3 additions & 3 deletions common/ffsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,7 +2516,7 @@ USTATUS FfsParser::parseGuidedSectionBody(const UModelIndex & index)
if (model->hasEmptyParsingData(index) == false) {
UByteArray data = model->parsingData(index);
const GUIDED_SECTION_PARSING_DATA* pdata = (const GUIDED_SECTION_PARSING_DATA*)data.constData();
guid = pdata->guid;
guid = readMisaligned(pdata).guid;
}

// Check if section requires processing
Expand Down Expand Up @@ -3008,8 +3008,8 @@ USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index)
if (model->hasEmptyParsingData(index) == false) {
UByteArray data = model->parsingData(index);
const TE_IMAGE_SECTION_PARSING_DATA* pdata = (const TE_IMAGE_SECTION_PARSING_DATA*)data.constData();
originalImageBase = pdata->imageBase;
adjustedImageBase = pdata->adjustedImageBase;
originalImageBase = readMisaligned(pdata).imageBase;
adjustedImageBase = readMisaligned(pdata).adjustedImageBase;
}

if (imageBase != 0) {
Expand Down
8 changes: 8 additions & 0 deletions common/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ static inline bool changeDirectory(const UString & dir) {
return (_chdir(dir.toLocal8Bit()) == 0);
}

static inline void removeDirectory(const UString & dir) {
_rmdir(dir.toLocal8Bit());
}

static inline UString getAbsPath(const UString & path) {
char abs[1024] = {};
if (_fullpath(abs, path.toLocal8Bit(), sizeof(abs)))
Expand All @@ -54,6 +58,10 @@ static inline bool makeDirectory(const UString & dir) {
return (mkdir(dir.toLocal8Bit(), ACCESSPERMS) == 0);
}

static inline void removeDirectory(const UString & dir) {
rmdir(dir.toLocal8Bit());
}

static inline bool changeDirectory(const UString & dir) {
return (chdir(dir.toLocal8Bit()) == 0);
}
Expand Down

0 comments on commit bc31934

Please sign in to comment.