1
0
mirror of synced 2025-01-31 03:53:44 +01:00

impr: Allow full magic analysis, removed unidentified data from magic report

This commit is contained in:
WerWolv 2024-05-19 10:21:02 +02:00
parent 22f1713739
commit ec748f4a64
2 changed files with 41 additions and 10 deletions

View File

@ -105,8 +105,13 @@ namespace hex::magic {
ON_SCOPE_EXIT { magic_close(ctx); };
if (magic_load(ctx, magicFiles->c_str()) == 0) {
if (auto result = magic_buffer(ctx, data.data(), data.size()); result != nullptr)
return wolv::util::replaceStrings(result, "\\012-", "\n-");
if (auto description = magic_buffer(ctx, data.data(), data.size()); description != nullptr) {
auto result = wolv::util::replaceStrings(description, "\\012-", "\n-");
if (result.ends_with("- data"))
result = result.substr(0, result.size() - 6);
return result;
}
}
}
@ -130,8 +135,13 @@ namespace hex::magic {
ON_SCOPE_EXIT { magic_close(ctx); };
if (magic_load(ctx, magicFiles->c_str()) == 0) {
if (auto result = magic_buffer(ctx, data.data(), data.size()); result != nullptr)
return wolv::util::replaceStrings(result, "\\012-", "\n-");
if (auto mimeType = magic_buffer(ctx, data.data(), data.size()); mimeType != nullptr) {
auto result = wolv::util::replaceStrings(mimeType, "\\012-", "\n-");
if (result.ends_with("- application/octet-stream"))
result = result.substr(0, result.size() - 26);
return result;
}
}
}
@ -162,8 +172,13 @@ namespace hex::magic {
ON_SCOPE_EXIT { magic_close(ctx); };
if (magic_load(ctx, magicFiles->c_str()) == 0) {
if (auto result = magic_buffer(ctx, data.data(), data.size()); result != nullptr)
return wolv::util::replaceStrings(result, "\\012-", "\n-");
if (auto extension = magic_buffer(ctx, data.data(), data.size()); extension != nullptr) {
auto result = wolv::util::replaceStrings(extension, "\\012-", "\n-");
if (result.ends_with("- ???"))
result = result.substr(0, result.size() - 5);
return result;
}
}
}

View File

@ -7,8 +7,12 @@
#include <hex/api/task_manager.hpp>
#include <hex/ui/imgui_imhex_extensions.h>
#include <wolv/literals.hpp>
namespace hex::plugin::builtin {
using namespace wolv::literals;
class InformationProvider : public ContentRegistry::DataInformation::InformationSection {
public:
InformationProvider() : InformationSection("hex.builtin.information_section.provider_information") { }
@ -64,10 +68,22 @@ namespace hex::plugin::builtin {
task.update();
m_dataDescription = magic::getDescription(provider, region.getStartAddress());
m_dataMimeType = magic::getMIMEType(provider, region.getStartAddress());
m_dataAppleCreatorType = magic::getAppleCreatorType(provider, region.getStartAddress());
m_dataExtensions = magic::getExtensions(provider, region.getStartAddress());
try {
std::vector<u8> data(region.getSize());
provider->read(region.getStartAddress(), data.data(), data.size());
m_dataDescription = magic::getDescription(data);
m_dataMimeType = magic::getMIMEType(data);
m_dataAppleCreatorType = magic::getAppleCreatorType(data);
m_dataExtensions = magic::getExtensions(data);
} catch (const std::bad_alloc &) {
hex::log::error("Failed to allocate enough memory for full file magic analysis!");
// Retry analysis with only the first 100 KiB
if (region.getSize() != 100_kiB) {
process(task, provider, { region.getStartAddress(), 100_kiB });
}
}
}
void drawContent() override {