PDA

View Full Version : Change hardcoded serial


jackall
March 3rd, 2008, 03:55
i have an issue which is very simple to everyone else except to me as i seem to know very little about coding, assembly and reversing . Also this query could be similar to one often repeated so, please bear with me this monotony.

i have written a few lines of code in c++; it is compiled to a binary file. i reverse the binary in Olly and stepping into the main program loop (please correct me if iam using wrong terms) i was able to patch a jump to get 'good Boy' message. Now i want to locate the: 4321 in Olly and change it to 1234. i was not able to do this. i need help.

A friend in need…

#include<iostream>
using namespace std;
int main()
{
int nbr;
int a;
cout<<"Enter a 4-digit number:\n";
cin>>nbr;
cin.ignore();
if(nbr==4321)
{
cout<<"Good Boy";
}else

for(a=0;a<15;a++)
{
cout<<"Bad.....Boy\n\n\n";
}
cin.get();
return 0;
}

esther
March 3rd, 2008, 19:56
Remember,you just need to find the comparsion bettween 4321 and YOUR FAKE NUMBER change it to 1234 in HEX

jackall
March 3rd, 2008, 22:09
Thank you esther !
iam unable to or rather not knowing how to find the 4321 in Olly.

By stepping over (F8) and stepping in, i located the 'good Boy'. i tried to look at EAX hoping to find an entry equivalent to 4321b(i tried to look for this :10E1h ). But failed to find if any. Am i going in the right direction ?

i need guidance…..

Kayaker
March 4th, 2008, 01:17
Hi

Since you're declaring 'nbr' as a local variable, the instruction
if(nbr==4321)
should look something like

CMP DWORD PTR SS:[EBP-4],000010E1

followed by a JNZ

In any case, you should be able to right click in Olly, choose Search for/All Constants, and enter 000010E1 as the search value.

Just a point about your last post, 4321b is not the correct designation, it's a decimal(d) number not a binary(b).

jackall
March 4th, 2008, 07:47
Thank you Kayaker !
First ..You are right about 4321d . i made a mistake .

Regarding the other issue , following the suggestion by detten , i changed the data type to : string nbr ; nbr = "4321" and after compilation i could find 4321 in Olly and change it to another number.

Now you have come up with another suggestion . i need to read about 'local variable'. Then i will give it a go and see the result .

Regards....

personmans
March 4th, 2008, 13:34
Also if you did:
if(nbr=='0x4321')
the compare in olly would show up as 4321, because you're using the hex value of 4321 instead of dec, but you could no longer enter "4321" into the console to get the GoodBoy message. If you stick with strings, make sure both variables are strings, otherwise they won't compare correctly.

Using '4321':
'4321' as dec = 4321
'4321' as hex = 10E1

Using '0x4321', as I sugested is:
'0x4321' as dec = 17185 (You enter this to get it right)
'0x4321' as hex = 4321

using "4321":
"4321" as string = 31 30 45 31

Hope this helps.
~Personmans

jackall
March 5th, 2008, 01:44
Dear personmans...
it helps...
to learn that so many ways are available to solve the same issue ..in general...
and …
it helped me to think over Ascii Vs Decimal
Most of all...
it helps...
to know that so many people are willing to help others with their knowledge.

Thank you...

personmans
March 5th, 2008, 03:01
jackall, I think I speak for everyone when I say that we are just as glad to see new people pursuing the interest of reversing. Especially people with some patience and who are willing to do the research.

Take a look at this code:

Code:
#include<iostream>
using namespace std;

//This is used to convert the decimal input to the same number in hex.
/////START OF FUNCTION
int hex(int myDecimal) //<<"nbr" is input here and becomes the variable "myDecimal"
{
int myHex=0; // blank hex number for use soon.
while (myDecimal>0) // Runs through the if statement until we're finished.
{
if (myDecimal >=1000) //If the decimal # is more than 1000
{
myDecimal-=1000; //subtract 1000 from myDecimal (in decimal)
myHex+=0x1000; //add 1000 to myHex (in hex)
}
else if(myDecimal>=100) //same for 100
{
myDecimal-=100;
myHex+=0x100;
}
else if (myDecimal >=10) //same for 10
{
myDecimal-=10;
myHex+=0x10;
}
else if(myDecimal>0) //same for 1
{
myDecimal-=1;
myHex+=0x1;
}
}
return myHex; //This will send the final value of myHex back to the main program.
}
//////END OF FUNCTION

int main()
{
int nbr;
int a;
cout<<"Enter a 4-digit number:\n";
cin>>nbr; //Takes the input in decimal
cin.ignore();
if((hex(nbr))==0x4321) //the "hex(nbr)" part sends the variable "hex" to the function above.
{
cout<<"Good Boy";
}else

for(a=0;a<15;a++)
{
cout<<"Bad.....Boy\n\n\n";
}
cin.get();
return 0;
}

jackall
March 5th, 2008, 08:40
The code you presented must be simple (as it is meant for people like me newbie’s);
yet it 'looks’ a little above my present level of grasping ability.
Sorry i couldn’t respond to it much more creatively than this at the moment....Sure.. i will catch up with it soon.

Meanwhile a little explanation in addition to the code would be helpful and would be much appreciated.
i am sure there are many others who would benefit from similar contributions.

Regards...

personmans
March 5th, 2008, 20:25
Basically it's a cheap trick to switch the number from hex to dec, so your code would be comparing "4321" in hex, to "4321" in hex. (Can you tell I don't like strings?) I could have made the loop more efficient and encompassed all values up to 4294967295d (FFFFFFFFh), but I wrote it this way to make it easier to understand.

I have updated the code with some comments (They are everything with a // in front). Hope it helps, if not let me know and I will try harder.

jackall
March 6th, 2008, 08:22
Thanks for the update and comments.
iam trying to understand the code ; i need further reading for this .
meanwhile ...with regards
..

jackall
March 7th, 2008, 01:24
Personmans!
You have spared your time and effort to give further clarity to the code. I read the additional notes you made... and yes i almost got the idea. Meanwhile i have made a paper copy of the same if i need to refer it later on.

i wish you had made this explanatory notes made available to all. There may be many who need it.
Your effort will always be remembered...
Thank you.
Thank you ..

jackall
March 7th, 2008, 03:28
.............................................................................................
Here is the slightly simplified code of the last query.


#include <iostream>
using namespace std;

int main () {
string nbr="4321";

cout<<"Enter a 4-digit number:\n";
cin>>nbr;
cin.ignore();

if (nbr=="4321"{
cout<<"....GoodBoy";
}else
cout<<"....BadBoy";
cin.get();

return 0;
}

...........................................................................................

These lines below create a Message Box:


#include<windows.h>
using namespace std;

int WINAPI WinMain(
HINSTANCE HIntance,
HINSTANCE HPrevInstance,
LPSTR lpCmdLine,
int CmdShow )
{
MessageBox(
NULL,
"...Good Boy",
"learning..",
MB_OK
);
return 0;
}
.................................................................................................... ....


Now how do i combine these two functions ??.
intention is to get the Good/Bad message on a Message box instead of on the console window.


Thank you...

JMI
March 7th, 2008, 18:54
jakall:

Please STOP using "RIGHT JUSTIFIED Text" in your Posts. Use "LEFT JUSTIFIED Text" so I can stop having to edit all your general Text content.

Regards,

jackall
March 8th, 2008, 03:56
My apologies...
This will not occur ever again..
regards..

personmans
March 10th, 2008, 16:32
I think you're looking for something like this:

Code:

#include <iostream>
#include<windows.h>
using namespace std;

int main () {

int nbr=4321;
cout<<"Enter a 4-digit number:\n";
cin>>nbr;
cin.ignore();

if (nbr==4321){
MessageBox(NULL,"...Good Boy","learning..",MB_OK);
}else
cout<<"....BadBoy";
cin.get();

return 0;
}


There is a book online called "Thinking in C++" That I think you ought to read.

It is free and well written. It also includes a lot of example code.

~Personmans

jackall
March 13th, 2008, 02:16
Well! It was very simple enough...
Why didn’t i think of it by myself.. Probably iam not thinking in CCC .

i will read the book "Thinking in C++" .
Thanks for the suggestion..

i hope you are not pushing me aside to a corner with a suggestion ' Read before cry help ' .
if you can tolerate me for a while, here is another ......simple ..doubt..as usual..

From the above code you , i get MessageBox alright . But is there any way to suppress the simultaneouse appearance of shell window or atleast to get the MessageBox to the foreground ??
regards..

Kayaker
March 13th, 2008, 03:34
Quote:
[Originally Posted by jackall;73330] is there any way to suppress the simultaneouse appearance of shell window or atleast to get the MessageBox to the foreground ??


There may be a way to suppress it, but I wouldn't worry about it. That would be non-standard behaviour you're trying to create.

Very soon you're going to want to get into GUI coding where the input would be through a text box instead of the command line, so it's a moot point. There are more productive reversing (and programming) experiences than modifying shell behaviour

Hmm, just noticed you mentioned the MsgBox not appearing in the foreground, maybe that's a different issue.

btw, I noticed you were specifically using LEFT html tags to left justify your posts, since your earlier ones were all centered. You shouldn't have to do that, just type as normal without any justification and your posts should appear properly.

jackall
March 13th, 2008, 09:51
Kayaker ..
' just noticed you mentioned the MsgBox not appearing in the foreground, maybe that's a different issue.'
May be ...
but for me...lesser mortals like me..
..i wish Hamlet is not alive to hear this ..
to the Foreground or not to the foreground, that is THE issue;
So..
please let me know if there is a simple solution to this seemingly
simple issue..
regards..

blabberer
March 13th, 2008, 13:16
ah like kayaker said modifying shell behaviour is best left unattended
shell has got its own brain and it normaly doesnt like billgates's creations
at the most you can make it flicker

with some of the following kludges

like FindWindow() SetForeGroundWindow() on your messagebox

or ShowWindow(GetConsoleHwnd(),SW_HIDE); on your console shell

or maybe CloseWindow() Altogether and then spawning the msgbox()

or to the least you can try to coexist but get your msgbox to foreground using

Code:

if (nbr==4321){
MessageBox(NULL,"...Good Boy","learning..",MB_OK|MB_TOPMOST|MB_SETFOREGROUND );


windows will try to set your messagebox Topmost in Z scale

jackall
March 14th, 2008, 10:17
Blabberer !
i knew it.... the solution must be very simple ...i knew it all the way back from high school days...
just a glance at the answer sheet of the student beside ...the answer always seemed very simple...to Ctr+C...
That was way back...

I have great appreciation and admiration for all the brainy people around...tirelessly helping the inexperienced ones..
Who sometimes comes with very very elementary queries... like …
is it possible to place the above mentioned MessageBox at a specific location on the screen!!

A minor clarification ' set your messagebox Topmost in Z scale ' or is it not Z direction !!

regards…

personmans
March 15th, 2008, 21:31
Quote:
[Originally Posted by jackall;73330]
i hope you are not pushing me aside to a corner with a suggestion ' Read before cry help ' .

jackall, I'm not trying to put you into that group. It just seems that you could use a nice solid foundation for C++ coding, and that book is free/readily available for reference.

On the other hand, this is a reversing board, so the C++ coding part of it doesn't really fit in with the 'normal' discussion topics.

~Personmans

jackall
March 15th, 2008, 22:46
personmans !

i have the book ' Thinking in C++ ' got downloaded. i flicked through a few pages; i feel it is worth buying.
iam buying it if a locally printed one is available.

i value your suggestions; they are always welcome and they would very much be appreciated.
regards...

jackall
March 17th, 2008, 04:14
Well!
This far it reached in two weeks of my placing the post on this forum.
By now, i feel much more confident of my understanding of related concepts though it may not be apparent.
Here is the initial code with minor changes:

#include <iostream>
#include<windows.h>
using namespace std;
int main ()
{
string nme;
cout<<"Enter a name: \n";
cin>>nme;
cin.ignore ();

if (nme=="danisha"
{
MessageBox (NULL,"...Good Morning","greetings", MB_OK|MB_TOPMOST);
} else
cout<<nme<<"! you need to enter: danisha";
cin.get ();

return 0;
}

i like to get a MessageBox to replace the COUT after the ELSE ; a massageBox that can display: <<nme<<
How do one use the variable ' nme ‘??
To get it displayed on the MessageBox...

regards...

Admiral
March 17th, 2008, 09:01
Jackall, we're not going to teach you C++. But for the sake of throwing a man a fish...

You'll find things easier to understand if you indent your code correctly. After doing so, it should be clear that you need to expand the syntax of your else clause:

Code:
#include <iostream>
#include<Windows.h>

using namespace std;

int main () {
string nme;
cout << "Enter a name: \n";
cin >> nme;
cin.ignore();

if (nme == "danisha" {
MessageBox (NULL, "...Good Morning", "greetings", MB_OK |MB_TOPMOST);
} else {
// Do whatever you need to do here
}

cin.get();
// This get is a hack. It keeps the console application from terminating
// before you've seen all the input. Don't confuse it with the actual
// program's logic. A slightly nicer hack would be system("pause";

return 0;
// This return is unnecessary as the C++ spec dictates that main
// returns zero by default. But we'll leave it in here as this is the
// exception to a far more general rule.
}

jackall
March 18th, 2008, 04:07
Admiral...

Please do enhance the awareness of C++ if you can spare little time and lot of patience .it will be really helpful for many more like me.

Thank you...