Skip to content

Adding minor fix for when DEBUG_COMMENTS is enabled.#146

Open
jershmagersh wants to merge 1 commit into
kevoreilly:capemonfrom
Invoke-RE:capemon
Open

Adding minor fix for when DEBUG_COMMENTS is enabled.#146
jershmagersh wants to merge 1 commit into
kevoreilly:capemonfrom
Invoke-RE:capemon

Conversation

@jershmagersh

@jershmagersh jershmagersh commented Jul 16, 2026

Copy link
Copy Markdown

This fixes a case where instruction is uninitialized when DEBUG_COMMENTS is enabled and the build target is not _WIN64:

        // Bug: our distorm fails to dissassemble rdtscp on x86
        //if (ide(&instruction, (void*)ExceptionInfo->ContextRecord->Eip) && !stricmp("rdtscp", instruction.mnemonic.p)) {
        if (!memcmp((PUCHAR)ExceptionInfo->ContextRecord->Eip, "\x0f\x01\xf9", 3)) {
            if (g_config.nop_rdtscp)
            {
                DWORD OldProtect;
                VirtualProtect((PVOID)ExceptionInfo->ContextRecord->Eip, 3, PAGE_EXECUTE_READWRITE, &OldProtect);
                memcpy((PVOID)ExceptionInfo->ContextRecord->Eip, "\x90\x90\x90", 3);
                VirtualProtect((PVOID)ExceptionInfo->ContextRecord->Eip, 3, OldProtect, &OldProtect); 
            }
            else
            {
                DWORD64 Timestamp = __rdtsc();
                ExceptionInfo->ContextRecord->Eax = (DWORD)Timestamp;
                ExceptionInfo->ContextRecord->Edx = Timestamp >> 32;
                ExceptionInfo->ContextRecord->Eip += lde((void*)ExceptionInfo->ContextRecord->Eip);
            }

Moving the _DecodedInst instruction declaration before the #ifdef _WIN64 fixes this case.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies CAPE/Debugger.c to declare the instruction variable unconditionally. The review feedback correctly points out that this change will cause an unused variable warning or compilation error on x86 builds where _WIN64 is not defined, and suggests conditionally declaring the variable only when needed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread CAPE/Debugger.c
Comment on lines 784 to +785
_DecodedInst instruction;
#ifdef _WIN64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Declaring instruction unconditionally will lead to an unused variable warning (or error if warnings are treated as errors) on x86 builds when DEBUG_COMMENTS is disabled, because instruction is only used when _WIN64 is defined or when DEBUG_COMMENTS is enabled. Conditionally declaring it only when needed avoids this issue.

	#if defined(_WIN64) || defined(DEBUG_COMMENTS)
		_DecodedInst instruction;
	#endif
	#ifdef _WIN64

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

Successfully merging this pull request may close these issues.

1 participant