diff options
| author | Zichuan Li <34680029+river-li@users.noreply.github.com> | 2024-08-15 11:53:05 -0400 |
|---|---|---|
| committer | Brandon Miller <brandon@vector35.com> | 2025-05-08 07:23:08 -0400 |
| commit | 7f08117cfeb48a8f48d08e14cb498ee028efcef2 (patch) | |
| tree | 345eab220c00cfa098e94fa261dce092fc8d5182 /platform/efi/efi_resolver/src/GuidRenderer.cpp | |
| parent | 64de95854f9ad4da90b9cf2ee69a80f5dddd7a18 (diff) | |
Move EFI Resolver to API
Support all existing features in EFI Resolver,
1. Doesn't support running on existing BNDBs (though we tried to support
this in python plugins, it doesn't work well)
2. Perform analysis on MLIL rather than HLIL, previous pattern matching
on HLIL constains many false negatives
Diffstat (limited to 'platform/efi/efi_resolver/src/GuidRenderer.cpp')
| -rw-r--r-- | platform/efi/efi_resolver/src/GuidRenderer.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/platform/efi/efi_resolver/src/GuidRenderer.cpp b/platform/efi/efi_resolver/src/GuidRenderer.cpp new file mode 100644 index 00000000..ef148094 --- /dev/null +++ b/platform/efi/efi_resolver/src/GuidRenderer.cpp @@ -0,0 +1,56 @@ +#include "GuidRenderer.h" + +bool isType(const vector<pair<Type*, size_t>>& context, const string& name) +{ + if (context.empty()) + return false; + + auto [deepestType, size] = context.back(); + if (!deepestType->IsNamedTypeRefer()) + return false; + + return deepestType->GetTypeName().GetString() == name; +} + +bool EfiGuidRenderer::IsValidForData(BinaryView* bv, uint64_t address, Type* type, + vector<pair<Type*, size_t>>& context) +{ + return isType(context, "EFI_GUID"); +} + +static string formatGuid(uint32_t data1, uint16_t data2, uint16_t data3, uint64_t data4) +{ + std::ostringstream oss; + oss << std::hex << std::uppercase << std::setfill('0') + << std::setw(8) << data1 << "-" + << std::setw(4) << data2 << "-" + << std::setw(4) << data3 << "-" + << std::setw(16) << data4; + return oss.str(); +} + +vector<DisassemblyTextLine> EfiGuidRenderer::GetLinesForData( + BinaryView* bv, uint64_t address, Type*, const vector<InstructionTextToken>& prefix, + size_t, vector<pair<Type*, size_t>>& context) +{ + BinaryReader reader(bv); + reader.Seek(address); + auto data1 = reader.Read32(); + auto data2 = reader.Read16(); + auto data3 = reader.Read16(); + auto data4 = reader.ReadBE64(); + string guidStr = formatGuid(data1, data2, data3, data4); + + DisassemblyTextLine line; + line.addr = address; + line.tokens = prefix; + line.tokens.emplace_back(TextToken, "[EFI_GUID(\""); + line.tokens.emplace_back(StringToken, guidStr); + line.tokens.emplace_back(TextToken, "\")]"); + return { line }; +} + +void EfiGuidRenderer::Register() +{ + DataRendererContainer::RegisterTypeSpecificDataRenderer(new EfiGuidRenderer()); +} |
