pmt: reformat code
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -14,49 +14,65 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <PartitionManager/PartitionManager.hpp>
|
||||
#include "functions.hpp"
|
||||
#include <PartitionManager/PartitionManager.hpp>
|
||||
|
||||
#define TFUN "typeFunction"
|
||||
|
||||
namespace PartitionManager {
|
||||
bool typeFunction::init(CLI::App &_app) {
|
||||
LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl;
|
||||
cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)");
|
||||
cmd->add_option("content(s)", contents, "Content(s)")->required()->delimiter(',');
|
||||
cmd->add_option("-b,--buffer-size", bufferSize, "Buffer size for max seek depth");
|
||||
cmd->add_flag("--only-check-android-magics", onlyCheckAndroidMagics, "Only check Android magic values.");
|
||||
cmd->add_flag("--only-check-filesystem-magics", onlyCheckFileSystemMagics, "Only check filesystem magic values.");
|
||||
return true;
|
||||
}
|
||||
bool typeFunction::init(CLI::App &_app) {
|
||||
LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl;
|
||||
cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)");
|
||||
cmd->add_option("content(s)", contents, "Content(s)")
|
||||
->required()
|
||||
->delimiter(',');
|
||||
cmd->add_option("-b,--buffer-size", bufferSize,
|
||||
"Buffer size for max seek depth");
|
||||
cmd->add_flag("--only-check-android-magics", onlyCheckAndroidMagics,
|
||||
"Only check Android magic values.");
|
||||
cmd->add_flag("--only-check-filesystem-magics", onlyCheckFileSystemMagics,
|
||||
"Only check filesystem magic values.");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool typeFunction::run() {
|
||||
std::unordered_map<uint64_t, std::string> magics;
|
||||
if (onlyCheckAndroidMagics) magics.merge(PartitionMap::Extras::AndroidMagicMap);
|
||||
else if (onlyCheckFileSystemMagics) magics.merge(PartitionMap::Extras::FileSystemMagicMap);
|
||||
else magics.merge(PartitionMap::Extras::MagicMap);
|
||||
bool typeFunction::run() {
|
||||
std::unordered_map<uint64_t, std::string> magics;
|
||||
if (onlyCheckAndroidMagics)
|
||||
magics.merge(PartitionMap::Extras::AndroidMagicMap);
|
||||
else if (onlyCheckFileSystemMagics)
|
||||
magics.merge(PartitionMap::Extras::FileSystemMagicMap);
|
||||
else magics.merge(PartitionMap::Extras::MagicMap);
|
||||
|
||||
for (const auto& content : contents) {
|
||||
if (!Variables->PartMap->hasPartition(content) && !Helper::fileIsExists(content))
|
||||
throw Error("Couldn't find partition or image file: %s\n", content.data());
|
||||
for (const auto &content : contents) {
|
||||
if (!Variables->PartMap->hasPartition(content) &&
|
||||
!Helper::fileIsExists(content))
|
||||
throw Error("Couldn't find partition or image file: %s\n",
|
||||
content.data());
|
||||
|
||||
bool found = false;
|
||||
for (const auto& [magic, name] : magics) {
|
||||
if (PartitionMap::Extras::hasMagic(magic, bufferSize, Helper::fileIsExists(content) ? content : Variables->PartMap->getRealPathOf(content))) {
|
||||
println("%s contains %s magic (%s)", content.data(), name.data(), PartitionMap::Extras::formatMagic(magic).data());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool found = false;
|
||||
for (const auto &[magic, name] : magics) {
|
||||
if (PartitionMap::Extras::hasMagic(
|
||||
magic, bufferSize,
|
||||
Helper::fileIsExists(content)
|
||||
? content
|
||||
: Variables->PartMap->getRealPathOf(content))) {
|
||||
println("%s contains %s magic (%s)", content.data(), name.data(),
|
||||
PartitionMap::Extras::formatMagic(magic).data());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) throw Error("Couldn't determine type of %s%s\n", content.data(), content == "userdata" ? " (encrypted file system?)" : "");
|
||||
}
|
||||
if (!found)
|
||||
throw Error("Couldn't determine type of %s%s\n", content.data(),
|
||||
content == "userdata" ? " (encrypted file system?)" : "");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool typeFunction::isUsed() const { return cmd->parsed(); }
|
||||
bool typeFunction::isUsed() const { return cmd->parsed(); }
|
||||
|
||||
const char* typeFunction::name() const { return TFUN; }
|
||||
const char *typeFunction::name() const { return TFUN; }
|
||||
|
||||
} // namespace PartitionManager
|
||||
|
||||
Reference in New Issue
Block a user