Reverse Analysis on Windows - A First Look

Dig deep into advanced debugging with Visual Studio and x64dbg: breaking and modifying game rules on Windows, and mastering single-step analysis and instruction edits for optimized code execution.

Reverse Analysis on Windows - A First Look
Jose Elgueta, a graphic designer, is deeply devoted to the arts of painting, illustration, and muralism. Continuously striving to hone his graphic and artistic expressions, he possesses a profound fascination with Latin-American shamanic themes. Through his journey, he has crafted a unique visual language, unveiling a world of forms and colors yet to be discovered by others.

Environment Information

System information: Windows
Tools involved: Visual studio , x64dbg
Note: This is a translation of the article previously written into English version, if you can not see the message I improve the translation
Test code.
C:

#include <stdio.h>
int main()
{
    int a;
    printf("Please input a number:\n");
    int x = scanf_s("%d", &a);               
    printf("%d\n", x);
     if (a % 5 == 0 && a % 7 == 0 && a >1 && a <200)                        
            printf("yes\n");                                
    else
            printf("no\n");                                    
    return 0;
}

Game rules


Enter a value so that its terminal returns the following information.

1
yes

Note: Normal input of 140 will satisfy the requirement

Break the rules

Enter something that does not match the condition to satisfy the requirement

1665830990224.png


Example idea:
After the program runs, a string will be entered

1665831003888.png


After that, the user starts to input, and then returns some content after judging.
The normal flow of the output string code will be before the judgment code, and most likely in a region, you can test to locate the judgment code region according to this string.

Verification:
The following settings will break at the Entry Breakpoint

1665831047573.png


Click the Run button to let the program continue to run

1665831060173.png


At this point, return to the x64dbg interface and search for the string information loaded by the program

1665831075275.png


Result:

1665831086467.png


Double-click the left mouse button to enter. At this time, see some judgment process.

1665831094196.png


Mouse wheel slide up to see the entry point of this function area (sub)
There are multiple int3 on sub, determine this is the address of the call

1665831104534.png


Next breakpoint

1665831118962.png


Reload the program

1665831126584.png



Run to the place where the breakpoint is placed

1665831135368.png


Breakpoints under Call and Judgment instructions are used for analysis

1665831144974.png


lea instruction: take offset address 7FF7D3DA2260 and send to register RCX

1665830928742.png


1665830922072.png


Run it in a single step and see that the terminal outputs the following string after this call

1665830905413.png


After this call, the terminal can enter the value

1665830894328.png


After confirming

1665830882167.png


Call register information

1665830870871.png


Return 1 after Call

1665830857696.png


Rerun, enter the value that does not meet the condition and compare

Call register information

1665830833292.png


Return 0 after Call

1665830807946.png


Difference
RAX is different
Rerun and enter the value that does not meet the condition and change the rax information to 1
Select RAX or the corresponding value and right click

1665830793996.png


Modify

1665830786135.png


Call runs and sees that 1 has been returned and a rule has been broken

1665830757668.png


Continue to run and see the following judgments

1665830742963.png


Judgment: according to the displayed instruction execution flow judgment, if the two jne instructions do not jump and jbe jump can return yes
Right click to edit the instruction so that it does not work

1665830731365.png


1665830719822.png


Modify the instructions

1665830712817.png




1665830704813.png


After modifying

1665830695757.png


Run to verify

1665830680976.png


This article, this is the end, have the fate to meet again.

Test code modified at: https://blog.csdn.net/qq_42200183/article/details/81431747