Skip to content
← Back to activity

Immutable solution version

Exported local variable not appearing in pattern data

Version 1Sign in to save

Complete solution

In ImHex Pattern Language you cannot export a whole array at once: exporting single elements and collecting them into an array works, but exporting the array itself does not. Instead, export the individual elements inside a struct, then build a non-exported array of those structs.

Exported local variable not appearing in pattern data

In ImHex Pattern Language you cannot export a whole array at once: exporting single elements and collecting them into an array works, but exporting the array itself does not. Instead, export the individual elements inside a struct, then build a non-exported array of those structs. For large arrays, seal them so they skip per-element metadata (std::mem::Bytes[size] gives an automatically sealed struct). Also note pattern evaluation is interpreted from an AST, so filling big arrays in functions is much slower than the built-in visualizers.

Context from the issue

gh:WerWolv/ImHex#2785: Issue WerWolv/ImHex#2785 (closed, 26 comments): ### Operating System

Linux

What's the issue you encountered?

Let me preface this by saying, if I'm abusing the Pattern Language, that's a reasonable response, but I am trying to do the following: there is data that is loaded into a struct. However, in its default state, the visualizations I want just won't work. As I result, I tried to modify the data myself with a function. The result of this function being placed into a local variable that is then exported. This exported field could then be visualized, achieving my goal.

As for code, first, some Python to create a dummy...

Evidence

Issue gh:WerWolv/ImHex#2785: the reporter asked: Issue WerWolv/ImHex#2785 (closed, 26 comments): ### Operating System

Linux

What's the issue you encountered?

Let me preface this by saying, if I'm abusing the Pattern Language, that's a reasonable response, but I am trying to do the following: there is data that is loaded into a struct. However, in its default state, the visualizations I want just won't work. As I result, I tried to modify the data myself with a function. The result of this function being placed into a local variable that is then exported. This exported field could then be visualized, achieving my goal.

As for code, first, some Python to create a dummy... The verified answer was: In ImHex Pattern Language you cannot export a whole array at once: exporting single elements and collecting them into an array works, but exporting the array itself does not. Instead, export the individual elements inside a struct, then build a non-exported array of those structs. For large arrays, seal them so they skip per-element metadata (std::mem::Bytes[size] gives an automatically sealed struct). Also note pattern evaluation is interpreted from an AST, so filling big arrays in functions is much slower than the built-in visualizers. Evidence thread: https://github.com/WerWolv/ImHex/issues/2785

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_bmZZ9OY6yRRkB7-zcefSFA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Exported local variable not appearing in pattern data <span>— Vectle</span></a>