Log in

View Full Version : remove bug problem


cse_india
December 22nd, 2006, 06:47
first and foremost my sincere apologies to all the great reversers here if my problem is very stupid.its just i was confused where to post my problem,as this is not an unpacking problem nor i am a newbie anymore.




this is no unpacking or rce help related to cracking,but rather removing a bug from an mfc project in vc++.

the problem is that when i run the application i get an error message:
sam.exe has encountered a problem and we needs to close.

when i debug using vc++ i get an error:
the instruction at "0x5f43351b" referenced memory at"0x00000000".the memory could not be"read".
click ok to terminate the program.



the problem to me most probably is due to an unresolved pointer.i decided to open the .exe in olly but olly seems to crash everytime. i opened the .exe in ImpRec with something in mind to look at the imports.but i cannot understand the problem.
can some one have a look at the source code and see whats wrong. again i suspect the problem is something related to pointers( perhaps i have not used the "delete" keyword to deallocate memory.


also can anybody run the application by reverse code engineering.i have attached it.


here is the code( vc++ ).it is a mfc program to create a simple window.( i'm a beginner in vc++ )
#include<afxwin.h>

class myframe: public CFrameWnd
{
public:
myframe()
{
Create(0,"hello mfc",WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX);
}
};

class myapp: public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
p->ShowWindow(3);
m_pMainWnd=p;

return 1;
}
};

myapp;

ZaiRoN
December 22nd, 2006, 09:42
Hint:
Quote:
MyApp;

You forgot something

cse_india
December 22nd, 2006, 10:43
i banged my head; but unfortunately i didnt get anything
can i get another hint:
what is the difference between myapp and MyApp;i could not get it.

blabberer
December 22nd, 2006, 11:58
i just glanced at it in ollydbg it seems its erring inside some mfc42d.dll
ms doesnt have the pdbs for this in symbol server so i cant say for sure
what the mfc42#1105 function is looking for

it loads comdlg and returns back the comctl base
and in your code its trying to write into peheader of comctl.dll
here

00401325 |. 8848 14 MOV BYTE PTR DS:[EAX+14], CL

EAX 5D090000 OFFSET COMCTL32.#240

CL=00
DS:[5D090014]=00

obviously it will fail one cant write arbitrarily to different module without using
vprotect etc

i dont have mfc installed so cant check out compiling or changing this but i found some article in google which resembles your code

take a look and see if both of your code and this code matches
i see some differnces between the code in articl and yours
the failure is in the part of your initinstance call you probably left out the parenthesis myframe() so the pointer is getting a different value

http://www.codersource.net/mfc_tutorial_Part1.html

i was really wondering if the code thats shown is the way to code mfc no error checking nothing just plain go ahead
and it seems someone seems to have commented upon the style

read this too

http://www.codeproject.com/cpp/Beginner_MFC_Tutorial.asp?df=100&forumid=35188&select=760173#xx760173xx

ZaiRoN
December 22nd, 2006, 14:29
Quote:
can i get another hint:
What does the line "MyApp;" represent for you? Does it need something else?

naides
December 22nd, 2006, 16:51
Quote:
[Originally Posted by cse_india;63303]
#include<afxwin.h>

class myframe: public CFrameWnd
{
public:
myframe()
{
Create(0,"hello mfc",WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX);
}
};

class myapp: public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
p->ShowWindow(3);
m_pMainWnd=p;

return 1;
}
};

myapp;


1. I do not know if you can omit this in VC++ but it is a good practice to write

main{
my statements here
};

2. myapp is a class, not an object. Don't you need to create an instance of that class?

myapp * myAppInstance = new myapp;

3. Finally,

You need to call the myapp public method that paints your window:

myAppInstance -> InitInstance();

Unless the InitInstance() method is the default constructor (Which is not, based on the code you provided). If it were, the constructor would get called when you create the instance of myapp.

LLXX
December 22nd, 2006, 18:31
lol, where's ur main() ?

Edit: one more thing, MFC is ugly - just load your example into IDA and take a look at the whole conglomeration of obtuse code it puts in your executable

ZaiRoN
December 23rd, 2006, 09:54
Preamble: I'm not good in mfc. I only know few things and I'm not pretty sure about that

Quote:
lol, where's ur main() ?
He doesn't need a main because everything starts from:
Code:
myapp put_a_word_you_like_here;
If he'll modify the instruction above he (should) solve his problem.

Quote:
Don't you need to create an instance of that class?
No.

Quote:
You need to call the myapp public method that paints your window:
myAppInstance -> InitInstance();
No, InitInstance is called by the mfc system, exactly by WinMain. "p->ShowWindow(3);" displays the window.

Ciao!
ZaiRoN (Proud to come from good old Ansi C school :devil

nikolatesla20
December 23rd, 2006, 21:36
My god, I can't believe this actually compiled, forgetting to declare a variable of the application class. Of course that is why it crashed then, but I can't believe the compiler let it through!

-nt20

ZaiRoN
December 24th, 2006, 05:36
The code is syntactically correct. The same thing happens when you try to compile "int;", the compiler recognise the warning but it doesn't generate an error. What I don't understand is why it doesn't generate a warning with "myapp;" instruction...

cse_india
December 25th, 2006, 10:04
oh shit!

sorry guys for troubling u over such a stupid question.i have acted like a complete asshole!

yes i needed
myapp name_of_my_object_of_class_myapp

thanks ZaiRoN