(C++) Jump With Same Target by Unprotect

Created the Tuesday 06 December 2022. Updated 1 month, 3 weeks ago.

Description:

This allows the code to demonstrate the intended behavior of the original instructions, which is to always call the my_function function, regardless of the value of the eax register. This technique can make it difficult for a disassembler to accurately reconstruct the original instructions of the program, as the disassembler will not be able to determine the intended behavior of the program without actually executing it.

Code

            #include <stdio.h>

void my_function() {
    printf("Hello, world!\n");
}

int main() {
    int eax = 0x12345678;

    // Original instructions
    if (eax == 0) {
        my_function();
    }
    if (eax != 0) {
        my_function();
    }

    // Obfuscated instructions using back-to-back conditional jumps
    if (eax == 0) {
        my_function();
    }
    my_function();

    return 0;
}