Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Bug in pattern leaves ImHex in corrupted state, program reload required, no pattern reload (with corrected pattern) can fix this. #1710

Closed
1 task
qknight opened this issue May 24, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@qknight
Copy link

qknight commented May 24, 2024

Operating System

Windows

What's the issue you encountered?

ImHex 1.24.3 Windows I edit this into imhex-pe.hexpat

imhex-pe.hexpat

	else if (std::string::starts_with(sectionTable[currentSectionIndex].name, ".idata")) {// Imports section
        ImportsSection importsSection;
+        for (u8 i = 0, i < 10, i = i + 1) { // sizeof(importsSection)
+            std::print("fooooooooooooo");
+        }
	}

Then I load the pattern using the main menu and I get this evaluation error:

error[P0003]: Unknown type
  --> <Source Code>:7:1709
7 | #include <std/mem.pat>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ^
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Type T has not been declared yet.

hint: If this type is being declared further down in the code, consider forward declaring it with 'using T;'.

This error doesn't make sense. However, more important, if I use an external editor to fix the issue back to the original code, ImHex won't recover from this error and I need to close ImHex.exe and reopen it.

There seems to be some stuck state.

How can the issue be reproduced?

Described in the issue. Basically add the lines and parse a exe.

ImHex Version

1.24.3

ImHex Build Type

  • Nightly or built from sources

Installation type

msi using chocolatey

Additional context?

No response

@qknight qknight added the bug Something isn't working label May 24, 2024
@jumanji144
Copy link
Collaborator

Can you try on the newest imhex version?

@qknight
Copy link
Author

qknight commented May 25, 2024

I've created this in ImHex v.1.33.2:

struct ImportsStructure {
	if (parent.importsDirectoryTable[std::core::array_index()].lookupTableRVA > 0) {
		ImportsLookup lookupTable[while(std::mem::read_unsigned($, wordsize()) != 0)] @ parent.importsDirectoryTable[std::core::array_index()].lookupTableRVA - relativeVirtualDifference();
	}
	if (parent.importsDirectoryTable[std::core::array_index()].addressTableRVA > 0) {
		ImportsAddress addressTable[while(std::mem::read_unsigned($, wordsize()) != 0)] @ parent.importsDirectoryTable[std::core::array_index()].addressTableRVA - relativeVirtualDifference();
	}
+       for (u8 i = 0, i < 10, i = i + 1) { // sizeof(importsSection)
+           std::print("fooooooooooooo");
+       }
	if (parent.importsDirectoryTable[std::core::array_index()].dllNameRVA > 0) {
		char dllName[] @ parent.importsDirectoryTable[std::core::array_index()].dllNameRVA - relativeVirtualDifference() [[format("formatNullTerminatedString")]];
	}
} [[inline]];

And it produced this error:

E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:8
E: 447 |        for (u8 i = 0, i < 10,
E:               ^^^
E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:12
E: 447 |        for (u8 i = 0, i < 10, i =
E:                   ^
E: error: Expected ';' at end of statement, got Separator (,).
E:   -->   in <Source Code>:447:20
E: 447 |        for (u8 i = 0, i < 10, i = i + 1)
E:                           ^
E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:21
E: 447 |       for (u8 i = 0, i < 10, i = i + 1) {
E:                           ^
E: error: Type i has not been declared yet.
E:   -->   in <Source Code>:447:23
E: 447 |     for (u8 i = 0, i < 10, i = i + 1) { 
E:                           ^

E: If this type is being declared further down in the code, consider forward declaring it with 'using i;'.
E: error: Expected ';' at end of statement, got Operator (<).
E:   -->   in <Source Code>:447:23
E: 447 |     for (u8 i = 0, i < 10, i = i + 1) { 
E:                           ^
E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:25
E: 447 |   for (u8 i = 0, i < 10, i = i + 1) { 
E:                           ^
E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:27
E: 447 |  for (u8 i = 0, i < 10, i = i + 1) { 
E:                            ^^
E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:29
E: 447 |  for (u8 i = 0, i < 10, i = i + 1) { 
E:                              ^
E: error: Expected ';' at end of statement, got Separator ()).
E:   -->   in <Source Code>:447:39
E: 447 |  0, i < 10, i = i + 1) { 
E:                            ^
E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:40
E: 447 |  0, i < 10, i = i + 1) { 
E:                             ^
E: error: Invalid struct member definition.
E:   -->   in <Source Code>:447:42
E: 447 |  i < 10, i = i + 1) { 
E:                            ^
E: error: Expected ';' at end of statement, got Keyword (if).
E:   -->   in <Source Code>:449:9
E: 449 |         }
E:               ^
I: Evaluation took 0.0303644s

From which ImHex recovers once the lines are removed and the pehex is reevaluated. Btw: I only installed this older version because I installed using choco. Thanks for your time!

@qknight qknight closed this as completed May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants