🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1397

Portability and re-defining datatypes

#1397
From: Mike Collins
Date: Thu, 13 Sep 2007 00:01
41 lines
2570 bytes
Hi all, in the middle of writting an article for the BCB Journal on Dll 
injeciton and API hooking and ran into a very strange problem.  Was 
wondering if anyone had any explaination of this.  Basically in my example, 
i was hooking a native api called NtCreateProcessEx.  The prototype for this 
(taken from Windows NT / 2000 Native API reference by Gary Nebbett - 
www.amazon.com/Windows-2000-Native-API-Reference/dp/1578701996 and the 
Undocumented NT Internals undocumented.ntinternals.net/) state that it is 
defined thus:

NTSTATUS NTAPI
  NtCreateProcessEx(
  PHANDLE ProcessHandle,
  ACCESS_MASK DesiredAccess,
  POBJECT_ATTRIBUTES ObjectAttributes,
  HANDLE InheritFromProcessHandle,
  BOOLEAN InheritHandles,
  HANDLE SectionHandle,
  HANDLE DebugPort,
  HANDLE ExceptionPort,
  DWORD dwSaferFlags
);


However, if i define it this way, the system fails to launch new processes 
(when hooked) reporting that the parameter are incorrect.  I found an delphi 
example where the author had define the prototype using a Cardinal for the 
PHANDLE and DWORD's for both the HANDLES and BOOLEAN values.  This 
implimentation seems to work when i copy it.  Having looked at the winnt.h 
the definition for a HANDLE changes depending upon the STRICT directive but 
is either a void or PVOID.

Can anyone explain this i.e. why the supposidly correct data types fail but 
re-defining them works?  Also, is it possible to redefine a HANDLE or 
override the orginal definition.  I have lots of example code where the 
prototypes are already define and it would be handy to simply redefine a 
HANDLE at the begining.

Many thank in advance,


Mike Collins
Technical Details
Message-ID: <46e86d1d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e50dbaba0bc077bb
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mike Collins" <its@TheBottomOfThePost>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Portability and re-defining datatypes
Date: Thu, 13 Sep 2007 00:01:15 -0000
Lines: 44
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.3959
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4073
NNTP-Posting-Host: 89.242.165.148
Message-ID: <46e86d1d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1189637405 89.242.165.148 (12 Sep 2007 15:50:05 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail