News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Is it a pointer?

Started by RedXVII, August 30, 2006, 09:16:10 PM

Previous topic - Next topic

RedXVII

To put it blunt:

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

RedXVII  :U

mnemonic

#1
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.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

asmfan

Use API funcs IsBad*Ptr or SEH as mnemonic suggested
Russia is a weird place

drizz

Use some of these windows api-s

IsBadCodePtr
IsBadHugeReadPtr
IsBadHugeWritePtr
IsBadReadPtr
IsBadStringPtr
IsBadWritePtr

GetSystemInfo
    lpMinimumApplicationAddress < YOUR POINTER < lpMaximumApplicationAddress

EDIT: asmfan was faster :)
The truth cannot be learned ... it can only be recognized.

zooba

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

P1

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)

sinsi

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.
Light travels faster than sound, that's why some people seem bright until you hear them.

RedXVII

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

P1

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)

RedXVII

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.