The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RedXVII on August 30, 2006, 09:16:10 PM

Title: Is it a pointer?
Post by: RedXVII on August 30, 2006, 09:16:10 PM
To put it blunt:

Is it possible to detect if a DWORD passed into my function is a pointer or not?

RedXVII  :U
Title: Re: Is it a pointer?
Post by: mnemonic on August 30, 2006, 09:24:49 PM
To put it straight: Nope, not reliable.

You could install a SEH and try to access the location pointed to by the value and if you can not (exception is thrown), you know it is a value and not a pointer.
But if you can access it, you can not say for sure that it is a pointer because it could be as well a DWORD-value that randomly has the same value as a memory location accessible by your program.

I think you get the idea.

EDIT: Corrected spelling error.
Title: Re: Is it a pointer?
Post by: asmfan on August 30, 2006, 09:26:39 PM
Use API funcs IsBad*Ptr or SEH as mnemonic suggested
Title: Re: Is it a pointer?
Post by: drizz on August 30, 2006, 09:30:14 PM
Use some of these windows api-s

IsBadCodePtr
IsBadHugeReadPtr
IsBadHugeWritePtr
IsBadReadPtr
IsBadStringPtr
IsBadWritePtr

GetSystemInfo
    lpMinimumApplicationAddress < YOUR POINTER < lpMaximumApplicationAddress

EDIT: asmfan was faster :)
Title: Re: Is it a pointer?
Post by: zooba on August 31, 2006, 11:39:25 PM
It's no more possible to tell than it is to tell whether a DWORD is signed or unsigned (note that signed is different to negative). This is why strong typing was introduced, to make it easier to know what a variable is.

Personally I prefer a good naming convention to C's policy of one-typedef-per-variable (there's about 160-170 variables equivalent to a DWORD in windows.inc). The only way to know for sure that a value is a pointer is to set it to the address of something. Otherwise, you're only guessing.

Cheers,

Zooba :U
Title: Re: Is it a pointer?
Post by: P1 on September 01, 2006, 01:51:39 PM
Quote from: RedXVII on August 30, 2006, 09:16:10 PMIs it possible to detect if a DWORD passed into my function is a pointer or not?
I believe you meant valid or not?

But seeing you did not tell us what your expecting as data, it's kind of hard for us to tell you if it's valid or not, or if code is available to do so.

Regards,  P1  :8)
Title: Re: Is it a pointer?
Post by: sinsi on September 01, 2006, 02:31:06 PM
QuoteIs it possible to detect if a DWORD passed into my function is a pointer or not?
Who cares? :bg
If it is your function, you should know, and if it's prototyped with the full "FileName:PTR BYTE" (for example)
then others should know that it's supposed to be a pointer and can suffer the consequences of error 0c0000005h.
Title: Re: Is it a pointer?
Post by: RedXVII on September 10, 2006, 05:41:11 PM
What api can i use to find out what the max/min address of the different sections used and the stack?

Thanks so far  :U
Title: Re: Is it a pointer?
Post by: P1 on September 10, 2006, 06:15:17 PM
Maybe you can share what you are trying to do? 

Because maybe we can share a better technique, if we knew what your trying to do.

Regards,  P1  :8)
Title: Re: Is it a pointer?
Post by: RedXVII on September 11, 2006, 12:07:04 AM
Find out where the pointer is pointing to and in what section of the code (which library/program, .data, .code, stack etc) if you get the max min of them then its a simple comparison until you find it, hence why i asked.