-
Hello everyone, I'm new to ImHex and PatternLanguage. Recently tried implementing RPM package format (http://ftp.rpm.org/max-rpm/s1-rpm-file-format-rpm-file-format.html#FTN.AEN14176) but I was unable to express some of RPM struct patterns. Consider this working and completely correct example:
TL;DR: we have array of (type, offset, amount). Next for each array element we go to It works fine, but the trick is that there always
It is not working and highlighting everything wrong. I honestly don't even know if it is possible to express this idea now. It is like using enums, but values are different types and you can't just slap a union and call it a day |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
i think you are making it more complicated than it needs be:
The following resulting code produces the same patterns as the first example posted: #pragma example 04 01 00 02 05 02 01 07 0A 01 06 0B 01 61 61 00 00 00 00 00 00 00 00 00 73 74 72 00 00 00 00 00
import std.core;
enum IndexType : u8 {
_null = 0,
_char = 1,
_int8 = 2,
_int16 = 3,
_int32 = 4,
_int64 = 5,
_string = 6,
_bin = 7,
};
struct Index {
IndexType type;
u8 offset;
u8 count;
};
struct String {
char s[];
};
struct StoreEntry {
auto i = std::core::array_index();
const u8 c = parent.index[i].count;
match (parent.index[i].type) {
(IndexType::_char): char data[c];
(IndexType::_int8): s8 data[c];
(IndexType::_int16): s16 data[c];
(IndexType::_int32): s32 data[c];
(IndexType::_int64): s64 data[c];
(IndexType::_string): String data;
(IndexType::_bin): u8 data[c];
}
};
struct Test {
u8 n;
Index index[n];
StoreEntry e[n];
};
Test t @ 0x00; |
Beta Was this translation helpful? Give feedback.
All store is data contiguous and in this example it is in order, but it can also be unordered. For example
But I was able to achieve that introducing
parent.offset
into your solution, big thanks!Only updated parts: