Assembly - Debugging self made program.

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Icyvel

Newbie
Full Member
Aug 6, 2013
17
198
0
Hi there, I'm trying to debug and analyze a little program i made for assembly learning purposes.


Here's the source code:

C++:
#include <iostream>

int SimpleMathFunction1(int in_a, int in_b);
int x = 0;
int a = 0;
int b = 5;


using namespace std;


int main()
{
	int input, pauseprogram;
	int nestedx, nesteda, nestedb;

	cout << "Hello World" << endl << endl;
	cout << "SimpleMathFunction1 is located at address: " << &SimpleMathFunction1 << endl << endl;
	cout << "My x is located at address: " << &x << endl;
	cout << "My a is located at address: " << &a << endl;
	cout << "My b is located at address: " << &b << endl;


	
	do
	{

		cout << "Loop start ->" << endl << endl;

		cout << "Input: ";

		cin >> input;
		cout << endl;

		//SimpleMathFunction1(input, 5);

		nestedx = SimpleMathFunction1(input, 5);

		cout << input << " + " << b << " is " << nestedx << endl;
		


	} while (1);

	

	return 0;

}


int SimpleMathFunction1(int in_a, int in_b)
{
	x = in_a + b;

	return x;
}
Please do note the code is kind of gibberish and garbage, but for learning purposes i wanted to keep my SimpleMathFunction1 very clean and small in size.
What I'm interrested in doing as of right now is inserting a break point at the start of my function but for some reason the program control doesn't get passed to the debugger.

I've tried both hardware breakpoints and software breakpoints.

picture of asm1.png

Here is a picture of the ASM code in OllyDbg.

While the breakpoint is there, the function continues to run without "breaking" on the breakpoint. Any idea´s?


PS. The program is a console application compiled with Visual Studio 2013.

Kind Regards.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,118
78,998
2,392
What if you put the breakpoint on the next instruction?
 

Syntax Error

Coder
Silenced
Meme Tier VIP
Nov 6, 2014
239
2,928
6
You can do a string search for "loop start->" and put a breakpoint on the call to SimpleMathFunction and step into it.
 

Icyvel

Newbie
Full Member
Aug 6, 2013
17
198
0
What if you put the breakpoint on the next instruction?
Same thing.

You can do a string search for "loop start->" and put a breakpoint on the call to SimpleMathFunction and step into it.
This looks really weird i can't even find a call to the function. Looked at Call-Tree and looking at references. Mhmm

Weird thing is i tried compiling the program using the "debug" feature of VS2013 instead of "Release", it alters the code abit and makes it look more messy.
But it makes me able to breakpoint.

I know it works "in theory", but now I'm curious what is causing this problem. Mhmm..
 

Syntax Error

Coder
Silenced
Meme Tier VIP
Nov 6, 2014
239
2,928
6
Weird thing is i tried compiling the program using the "debug" feature of VS2013 instead of "Release", it alters the code abit and makes it look more messy.
But it makes me able to breakpoint.

I know it works "in theory", but now I'm curious what is causing this problem. Mhmm..
My guess is that the compiler is optimizing your code and inlining the function.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,118
78,998
2,392
You put a breakpoint on an instruction, if that instruction gets executed it will stop execution of the code. That is what a breakpoint does.

So there are 2 logical conclusions:
1)the instruction never gets executed
2)the debugger is glitched or you're not attaching to the process

Fix #1:
Break on process startup. Step through the code from the beginning until the end of the program. If the instruction never gets executed you know your function got inlined.
If the instruction does get executed then proceed to Fix #2.

Fix #2:
Try the cheat engine debugger, reinstall olly.

Hope this helps, please respond with your progress
 

Icyvel

Newbie
Full Member
Aug 6, 2013
17
198
0
You can do
__declspec(noinline) int SimpleMathFunction1
and check again
Thank you tried compiling as Release with this, and it stopped on my breakpoint. :D

You put a breakpoint on an instruction, if that instruction gets executed it will stop execution of the code. That is what a breakpoint does.

So there are 2 logical conclusions:
1)the instruction never gets executed
2)the debugger is glitched or you're not attaching to the process

Fix #1:
Break on process startup. Step through the code from the beginning until the end of the program. If the instruction never gets executed you know your function got inlined.
If the instruction does get executed then proceed to Fix #2.

Fix #2:
Try the cheat engine debugger, reinstall olly.

Hope this helps, please respond with your progress
Yeah, the funny thing is i actually used Cheat Engine before to try and Debug as well. But then switched over to OllyDbg.
I guess both have their ups / downs. I still use Cheat Engine to find most of my addresses manually.

So what i think happened is compiling as Release the compiler inlined the function. And probably made another copy of it somewhere else.
Thus my "&SimpleMathFunction1" provides a wrong address i guess.

Mhmm interresting stuff, thanks all 3 though!

PS. Multi quoting is anoyying! :O
 

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51
Multi quoting is anoyying!
you can quote one and then press the add quote to it on the bottom right


Glad your issue is fixed aswell but give credit to Syntax Error ;)
 

SunBeam

Full Member
Nobleman
Jun 7, 2018
63
1,273
2
Quick necro - - just as a tip, always start from WinMain/main and trace your code. You wouldn't have had to do all the running around this way :p
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods