mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
includes/type: Added LEB128 type (#40)
* Implement VarInt type * VarInts are little endian, make result u128 * Rename VarInt to LEB128 * It didn't remove the varint file
This commit is contained in:
33
includes/type/leb128.pat
Normal file
33
includes/type/leb128.pat
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <std/io.pat>
|
||||
#include <std/mem.pat>
|
||||
|
||||
namespace type {
|
||||
|
||||
struct LEB128 {
|
||||
u8 array[while($ == addressof(this) || std::mem::read_unsigned($-1, 1) & 0x80 != 0)] [[hidden]];
|
||||
} [[format("type::impl::format_leb128"), transform("type::impl::transform_leb128")]];
|
||||
|
||||
namespace impl {
|
||||
|
||||
fn transform_leb128_array(auto array) {
|
||||
u128 res = array[0] & 0x7f;
|
||||
for(u8 i = 1, array[i-1] & 0x80 != 0, i+=1) {
|
||||
res |= u64(array[i] & 0x7f) << 7 * i;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
fn format_leb128(auto leb128) {
|
||||
u128 res = type::impl::transform_leb128_array(leb128.array);
|
||||
return std::format("{} ({:#x})", res, res);
|
||||
};
|
||||
|
||||
fn transform_leb128(auto leb128) {
|
||||
return type::impl::transform_leb128_array(leb128.array);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user