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

Crashing when used on a protected app/game #2

Open
anr2me opened this issue Jun 27, 2023 · 2 comments
Open

Crashing when used on a protected app/game #2

anr2me opened this issue Jun 27, 2023 · 2 comments

Comments

@anr2me
Copy link

anr2me commented Jun 27, 2023

const char* ImportDLLName = (const char*)BaseAddress + Descriptor->Name;

On a protected app/program some of the Descriptor contains invalid value resulting to a crash due to access violation, seems to start with a Descriptor that is filled with zeroes (0x00)

Adding these lines should be able to prevent the crash.

                const char* ImportDLLName = (const char*)BaseAddress + Descriptor->Name;
		// On a packed/protected program, some of the descriptors might contains an invalid data (feels like exceeding the actual number of import descriptors), zero-filled Descriptor seems to be used as terminator.
		if (!Descriptor->Name || !Descriptor->FirstThunk)
			break;
@pampersrocker
Copy link
Owner

Thanks, have you tested if the rest of the array is safe, or it just stops from the offending entry?
I am thinking of replacing the break; in your code with a continue to basically just skip the mangled entry.

@anr2me
Copy link
Author

anr2me commented Jun 27, 2023

The rest of the descriptors after the one filled with all zeroes seems to contains random junk which is an invalid memory address and resulting to access violation when used on strcmp

i've tried using continue and still crashing, i even tried to wrapped it with try..catch but nothing useful being printed after the terminating descriptor (the one filled with all zeroes).

Printed using:

WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), ImportDLLName, (DWORD)strlen(ImportDLLName), nullptr, nullptr);
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), "\n", 1, nullptr, nullptr);

The Result was :

...
WINTRUST.dll
WLDAP32.dll
WS2_32.dll <-- this is the last valid name right before the one filled with all zeroes
MZ� <-- this is the descriptor right after the one filled with all zeroes
MZ�

PS: Might be better to check the whole content of the Descriptor whether it's all zeroes or not as termination indicator, instead of partially by field, like:

                unsigned char* mm = (unsigned char*)Descriptor;
		if ((*mm == 0) && memcmp(mm, mm + 1, sizeof(IMAGE_IMPORT_DESCRIPTOR) - 1) == 0) 
			break;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants