Hev Value at Pointer

How do I do it?

This won't work:

char buf[255];
wsprintf(buf,"HEX VALUE  == %x",*p);

MessageBox(NULL,buf,"Error",MB_OK);
LVL 1
edvinsonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AxterCommented:
You're using wsprintf with a ANSI buffer.
If p is a pointer, try the following instead:
sprintf(buf,"HEX VALUE  == %x", p); //Don't dereference p
edvinsonAuthor Commented:
Getting this error:

Error      1      error C2664: 'wsprintfW' : cannot convert parameter 1 from 'char [255]' to 'LPWSTR'


jkrCommented:
It seems that you have "UNICODE" defined somewhere in your code which uses the wide character version. Just use the exact line Axter has posted

sprintf(buf,"HEX VALUE  == %x", p); //Don't dereference p

or

wsprintfA(buf,"HEX VALUE  == %x", p); //Don't dereference p

explicitly.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

edvinsonAuthor Commented:
IMO, I don't think I am using UNICODE anywhere.

My project settings:

Character set:         Not Set


Here is my entire function: (JKR you should know this by heart by now) :)

bool CheckNag()

{
     char * p;  
     p = (char *)  &Nag;
     p += fudge;  

      // Messagebox the value
      // Print first hex values

      char buf[255];
        sprintf(buf,"HEX VALUE  == %x", p); //Don't dereference p
        MessageBox(NULL,buf,"Error",MB_OK);
      
        if( *p != 0xFF )
            return false;

        return true;
}
jkrCommented:
Aaah, I see, you want to see the hex value that 'p' points to as in your other Q - try

bool CheckNag()

{
     char * p;  
     p = (char *)  &Nag;
     p += fudge;  

     // Messagebox the value
     // Print first hex values

     char buf[255];
     char c = *((char*) p);
     int val = (int) c;
        wsprintfA(buf,"HEX VALUE  == 0x%2.2x", val)
        MessageBox(NULL,buf,"Error",MB_OK);
     
        if( *p != 0xFF )
            return false;

        return true;
}
edvinsonAuthor Commented:
cool, thanks jkr.

I am being returned this in the message box:

0xffffffff

so what's the problem now?

Are my variable types off?

I am checking the value 0xFF against 0xffffffff

What needs to be done? Ugh... I am so close I can feel it! :)

jkrCommented:
How are you using that? As I told you, that doesn't make sense for inline functions.

BTW - the format string is "0x%2.2x", isn't it?
edvinsonAuthor Commented:
Ok, lol, here is the whole ball of wax:

#include <windows.h>


void Nag()
{  

      MessageBox(NULL, TEXT("Please Pay!"), TEXT("Note"), MB_OK);

}

#define fudge  14;


bool CheckNag()

{
     char * p;  
     p = (char *)  &Nag;
     p += fudge;  

     // Messagebox the value
     // Print first hex values

     char buf[255];
     char c = *((char*) p);
     int val = (int) c;
        wsprintfA(buf,"HEX VALUE  == 0x%2.2x", val);
        MessageBox(NULL,buf,"Error",MB_OK);
     
        if( *p != 0xFF )
            return false;

        return true;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{

     if(CheckNag()){

      // Program runs normal. The messagebox is in tact
        MessageBox(NULL, TEXT("NO PATCH"), TEXT("Not tampered with."), MB_OK);

    } else {

     // You should be ashamed of yourself! Patching this little program!

     MessageBox(NULL, TEXT("PATCH DETECTED!"), TEXT("Program has been tampered with"), MB_OK);

   }

    return 0;
}



You know what I am trying to do by now!  This is almost all your code   :)    :)    :)

I just want to see if the call is being patched. For some reason, I am being returned a wrong result, so I am trying to MessageBox the Hev value at the location to see what exactly is being returned.

<crowd chants> JRK </crowd>
jkrCommented:
So you mean that it works for you? Well, that code does for me *g*

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
edvinsonAuthor Commented:
Are you referring to the "specifics" of this question?

If so, yes. Points awarded.


But not my problem.  I am being returned wrong results. The program is telling me it's patched, when in fact it is not.


jkr, I will give you 500 points all day long.... not concerned with points. I just want to learn, and get this working.

Do I need to begin another question? If so, how do I get a hold of you to let you know the link?

Regards,

Ed Vinson's employee, John.
edvinsonAuthor Commented:
points to jkr for the specifics stipulated.
jkrCommented:
>>jkr, I will give you 500 points all day long.... not concerned with points. I just want to learn, and get
>>this working.

That's not the point - if I have a solution for you, I'll be happy to contribute it.

>>Do I need to begin another question? If so, how do I get a hold of you to let you know the link?

If you have a new Q, just ask it. If I see that one right in time, I'll be happy to chime in, but please don't post Qs exclusively for me unless absolutely neccesary, there are a lot of great guys around here to help you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.