modification support & other

+ Replace and rebuild functions
+ NVRAM volumes rebuild support (without changing the size of volume)
+ 'TXT' and 'Microcode' parsing tabs
+ 'Inspect with IDA' function
This commit is contained in:
Dmitry Frolov 2018-08-23 08:43:46 +03:00
parent b064495db8
commit 856ea2a3aa
18 changed files with 2439 additions and 301 deletions

View file

@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "ffsops.h"
#include "ffs.h"
#include "utility.h"
#include "nvramparser.h"
USTATUS FfsOperations::extract(const UModelIndex & index, UString & name, UByteArray & extracted, const UINT8 mode)
{
@ -59,22 +60,114 @@ USTATUS FfsOperations::extract(const UModelIndex & index, UString & name, UByteA
return U_SUCCESS;
}
USTATUS FfsOperations::replace(const UModelIndex & index, const UString & data, const UINT8 mode)
USTATUS FfsOperations::replace(const UModelIndex & index, UByteArray & data, const UINT8 mode)
{
U_UNUSED_PARAMETER(data);
// Sanity check
if (!index.isValid())
if (!index.isValid() || !index.parent().isValid())
return U_INVALID_PARAMETER;
if (mode == REPLACE_MODE_AS_IS) {
return U_NOT_IMPLEMENTED;
USTATUS result;
UByteArray empty = "";
FfsParser parser(model);
UINT32 localOffset = model->offset(index) + model->header(index).size();
UModelIndex index_out;
if(mode == REPLACE_MODE_BODY)
data = model->header(index) + data;
if (model->type(index) == Types::Region) {
UINT8 type = model->subtype(index);
switch (type) {
case Subtypes::BiosRegion:
result = parser.parseBiosRegion(data, localOffset, index, index_out, CREATE_MODE_AFTER);
break;
case Subtypes::MeRegion:
result = parser.parseMeRegion(data, localOffset, index, index_out, CREATE_MODE_AFTER);
break;
case Subtypes::GbeRegion:
result = parser.parseGbeRegion(data, localOffset, index, index_out, CREATE_MODE_AFTER);
break;
case Subtypes::PdrRegion:
result = parser.parsePdrRegion(data, localOffset, index, index_out, CREATE_MODE_AFTER);
break;
default:
return U_NOT_IMPLEMENTED;
}
if (result && result != U_VOLUMES_NOT_FOUND && result != U_INVALID_VOLUME)
return result;
}
else if (mode == REPLACE_MODE_BODY) {
return U_NOT_IMPLEMENTED;
else if (model->type(index) == Types::Padding) {
// Get info
QString name = usprintf("Padding");
QString info = usprintf("Full size: %Xh (%u)", data.size(), data.size());
// Add tree item
//!TODO UModelIndex fileIndex = model->addItem(Types::Padding, getPaddingType(body), COMPRESSION_ALGORITHM_NONE, name, "", info, UByteArray(), body, index, mode);
}
return U_UNKNOWN_REPLACE_MODE;
else if (model->type(index) == Types::Volume) {
result = parser.parseVolumeHeader(data, localOffset, index, index_out, CREATE_MODE_AFTER);
if (result)
return result;
result = parser.parseVolumeBody(index_out);
if (result)
return result;
}
else if (model->type(index) == Types::File) {
result = parser.parseFileHeader(data, localOffset, index, index_out, CREATE_MODE_AFTER);
if (result && result != U_VOLUMES_NOT_FOUND && result != U_INVALID_VOLUME)
return result;
result = parser.parseFileBody(index_out);
if (result && result != U_VOLUMES_NOT_FOUND && result != U_INVALID_VOLUME)
return result;
}
else if (model->type(index) == Types::Section) {
result = parser.parseSectionHeader(data, localOffset, index, index_out, true, CREATE_MODE_AFTER);
if (result && result != U_VOLUMES_NOT_FOUND && result != U_INVALID_VOLUME)
return result;
result = parser.parseSectionBody(index_out);
if(result && result != U_VOLUMES_NOT_FOUND && result != U_INVALID_VOLUME)
return result;
}
else if(model->type(index) == Types::EvsaStore || model->type(index) == Types::CmdbStore ||
model->type(index) == Types::FdcStore || model->type(index) == Types::FlashMapStore ||
model->type(index) == Types::FsysStore || model->type(index) == Types::FtwStore ||
model->type(index) == Types::Vss2Store || model->type(index) == Types::VssStore) {
if(data.size() != model->header(index).size() + model->body(index).size())
return U_INVALID_STORE_SIZE;
NvramParser nvramParser(model, &parser);
result = nvramParser.parseStoreHeader(data, localOffset, index, index_out, CREATE_MODE_AFTER);
if (result && result != U_VOLUMES_NOT_FOUND && result != U_INVALID_VOLUME)
return result;
UINT8 type = model->type(index);
switch (type) {
case Types::FdcStore: nvramParser.parseFdcStoreBody(index_out); break;
case Types::VssStore: nvramParser.parseVssStoreBody(index_out, 0); break;
case Types::Vss2Store: nvramParser.parseVssStoreBody(index_out, 4); break;
case Types::FsysStore: nvramParser.parseFsysStoreBody(index_out); break;
case Types::EvsaStore: nvramParser.parseEvsaStoreBody(index_out); break;
case Types::FlashMapStore: nvramParser.parseFlashMapBody(index_out); break;
}
}
else
return U_NOT_IMPLEMENTED;
// Set remove action to replaced item
model->setAction(index, Actions::Remove);
model->setAction(index_out, Actions::Replace);
// Rebuild parent, if it has no action now
UModelIndex parent = index.parent();
if (parent.isValid() && model->type(parent) != Types::Root
&& model->action(parent) == Actions::NoAction)
rebuild(parent);
return U_SUCCESS;
}
USTATUS FfsOperations::remove(const UModelIndex & index)