Article View: borland.public.cppbuilder.nativeapi
Article #1512PHANDLE, HANDLE comparisions and vectors
From: Mike Collins
Date: Mon, 23 Jul 2007 23:08
Date: Mon, 23 Jul 2007 23:08
77 lines
3527 bytes
3527 bytes
Hi all got a bit of a vague question regarding PHANDLE's and HANDLES. I'm
doing some work with dll injection and api hooking on a native level.
I'm hooking one function, NtCreateSection and i need to store one of the
values returned from this function, in a vector, for future checking. The
value is defined / returned as a PHANDLE.
I've declared a vectore of HANDLE's and assign the PHANDLE thus:
std::vector<HANDLE>vecFileWatch;
NTSTATUS NTAPI NtCreateSectionCallback(PHANDLE SectionHandle, ACCESS_MASK
DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes,
PLARGE_INTEGER
SectionSize, ULONG Protect, ULONG Attributes, HANDLE FileHandle)
{
NTSTATUS iStatus;
iStatus = NtCreateSectionNxt(SectionHandle, DesiredAccess,
ObjectAttributes, SectionSize, Protect, Attributes, FileHandle);
if (NT_SUCCESS(iStatus))
vecFileWatch.push_back(SectionHandle); //Always seems to assign 1 into
the vector...
return iStatus;
}
- i'm not sure how to assign or cast this though because i always end up
with the value 1 in the vector.
Later on, i need to scan this vector and compare the stored value against an
actual HANDLE, which is performed from another native api hook,
NtCreateProcessEx:
NTSTATUS NTAPI NtCreateProcessExCallback(PHANDLE ProcessHandle, ACCESS_MASK
DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, HANDLE ParentProcess,
BOOLEAN InheritObjectTable, HANDLE SectionHandle, HANDLE DebugPort, HANDLE
ExceptionPort, DWORD dwSaferFlags)
{
NTSTATUS iStatus;
iStatus = NtCreateProcessExNxt(ProcessHandle, DesiredAccess,
ObjectAttributes, ParentProcess, InheritObjectTable, SectionHandle,
DebugPort,
ExceptionPort,
dwSaferFlags);
if (NT_SUCCESS(iStatus))
{
if (!vecFileWatch.empty())
{
// Vector index position...
int iRtn = -1;
unsigned int i = 0;
// while loop used to ensure that we can exit as soon as a value is
found.
while ((i < vecFileWatch.size())&&(iRtn < 0))
{
// Comparison of HANDLES always fails even though they appear to
be 1!
if (vecFileWatch[i] == SectionHandle)
iRtn = i;
else
++i;
}
if (iRtn > -1)
TFileMonitor *FileMon = new TFileMonitor(false, ProcessHandle);
}
}
return iStatus;
}
can anyone give me some pointers on how to assign / cast between the PHANDLE
and HANDLE and how to perform the necessary comparison?
Many thanks in advance,
Mike C
Technical Details
Message-ID:
<46a52487$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,30800f5259a52803,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Mike Collins" <its@TheBottomOfThePost> Newsgroups: borland.public.cppbuilder.nativeapi Subject: PHANDLE, HANDLE comparisions and vectors Date: Mon, 23 Jul 2007 23:08:47 -0000 Lines: 79 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.3959 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4073 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 89.240.141.150 Message-ID: <46a52487$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1185227911 89.240.141.150 (23 Jul 2007 14:58:31 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail