[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hev Value at Pointer

Posted on 2006-04-25
12
Medium Priority
?
253 Views
Last Modified: 2008-02-01
How do I do it?

This won't work:

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

MessageBox(NULL,buf,"Error",MB_OK);
0
Comment
Question by:edvinson
  • 6
  • 5
12 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 16540217
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
0
 
LVL 1

Author Comment

by:edvinson
ID: 16540343
Getting this error:

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


0
 
LVL 86

Expert Comment

by:jkr
ID: 16540402
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:edvinson
ID: 16540536
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;
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 16540577
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;
}
0
 
LVL 1

Author Comment

by:edvinson
ID: 16540836
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! :)

0
 
LVL 86

Expert Comment

by:jkr
ID: 16540855
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?
0
 
LVL 1

Author Comment

by:edvinson
ID: 16540874
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>
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 16540899
So you mean that it works for you? Well, that code does for me *g*
0
 
LVL 1

Author Comment

by:edvinson
ID: 16540913
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.
0
 
LVL 1

Author Comment

by:edvinson
ID: 16540920
points to jkr for the specifics stipulated.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16540933
>>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.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question