mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-28 07:47:02 -05:00
patterns/fdt: Fix flattened device tree parsing (#140)
* Fix flattened device tree parsing Fix parsing to support multiple FDTs in a file and non-zero base addresses. * Fix string parsing Parent offset wasn't being taken into account when looking for prop names.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <std/sys.pat>
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
#include <type/magic.pat>
|
||||
#include <type/size.pat>
|
||||
@@ -26,7 +27,7 @@ struct AlignTo<auto Alignment> {
|
||||
struct FDTReserveEntry {
|
||||
u64 address;
|
||||
type::Size<u64> size;
|
||||
|
||||
|
||||
if (address == 0x00 && size == 0x00)
|
||||
break;
|
||||
};
|
||||
@@ -51,7 +52,7 @@ struct FDTStructureBlock {
|
||||
u32 nameoff;
|
||||
char value[len];
|
||||
AlignTo<4>;
|
||||
char name[] @ parent.header.off_dt_strings + nameoff;
|
||||
char name[] @ address(parent) + parent.header.off_dt_strings + nameoff;
|
||||
} else if (token == FDTToken::FDT_NOP || token == FDTToken::FDT_END_NODE) {
|
||||
// Nothing to do
|
||||
} else {
|
||||
@@ -62,9 +63,9 @@ struct FDTStructureBlock {
|
||||
struct FDT {
|
||||
FDTHeader header;
|
||||
std::assert(header.version == 17, "Unsupported format version");
|
||||
|
||||
FDTStructureBlock structureBlocks[while(true)] @ header.off_dt_struct;
|
||||
FDTReserveEntry reserveEntries[while(true)] @ header.off_mem_rsvmap;
|
||||
|
||||
FDTStructureBlock structureBlocks[while(true)] @ addressof(this) + header.off_dt_struct;
|
||||
FDTReserveEntry reserveEntries[while(true)] @ addressof(this) + header.off_mem_rsvmap;
|
||||
};
|
||||
|
||||
FDT fdt @ 0x00;
|
||||
std::mem::MagicSearch<"\xD0\x0D\xFE\xED", FDT> fdt @ std::mem::base_address();
|
||||
|
||||
Reference in New Issue
Block a user