home *** CD-ROM | disk | FTP | other *** search
- /*
- THHOOK.C -- Exploring KERNEL's DS
-
- From Chapter 5 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC THHOOK HANDLES (for Borland C++ v3.00)
- WINIOMS THHOOK HANDLES (for Microsoft C/SDK)
-
- Changed slightly from code printed in book: as text notes,
- SelTableLen and SelTableStart are not in same location in 3.0.
- As a last-minute change, we just stopped printing these fields!
- For more information on SelTableLen and SelTableStart, see the
- sample code in the Selector Table entry in Chapter 5.
- */
-
- #include <windows.h>
- #include <stdlib.h>
- #include <dos.h>
- #include "winio.h"
- #include "handles.h"
-
- typedef struct {
- WORD hGlobalHeap; // 0
- WORD pGlobalHeap; // 2
- WORD hExeHead; // 4
- WORD hExeSweep; // 6
- WORD TopPDB; // 8
- WORD HeadPDB; // 0a
- WORD TopSizePDB; // 0c
- WORD HeadTDB; // 0e
- WORD CurTDB; // 10
- WORD LoadTDB; // 12
- WORD LockTDB; // 14
- } THHOOK;
-
- main()
- {
- THHOOK far *lpTHH;
- WORD wVers;
-
- winio_about("THHOOK"
- "\nExploring KERNEL's DS"
- "\n\nFrom Chapter 5 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- wVers = GetVersion();
- if (wVers == 0x0003)
- {
- WORD wKernel, wKernelDgroup;
- wKernel = GetModuleHandle("KERNEL");
- printf("KERNEL = %04x\n", wKernel);
- if (! (wKernelDgroup = GetModuleDgroup(wKernel)))
- fail("Can't get KERNEL DGROUP");
- lpTHH = MK_FP(wKernelDgroup, 0x10);
- }
- else // 3.1+
- {
- lpTHH = GetProcAddress(GetModuleHandle("KERNEL"), "THHOOK");
- if (! lpTHH)
- fail("Can't locate THHOOK");
- }
-
- printf("hGlobalHeap = %04xh\n", lpTHH->hGlobalHeap);
- printf("pGlobalHeap = %04xh\n", lpTHH->pGlobalHeap);
- printf("hExeHead = %04xh\n", lpTHH->hExeHead);
- printf("hExeSweep = %04xh\n", lpTHH->hExeSweep);
- printf("TopPDB = %04xh\n", lpTHH->TopPDB);
- printf("HeadPDB = %04xh\n", lpTHH->HeadPDB);
- printf("TopSizePDB = %04xh\n", lpTHH->TopSizePDB);
- printf("HeadTDB = %04xh\n", lpTHH->HeadTDB);
- printf("CurTDB = %04xh\n", lpTHH->CurTDB);
- printf("LoadTDB = %04xh\n", lpTHH->LoadTDB);
- printf("LockTDB = %04xh\n", lpTHH->LockTDB);
-
- return 0;
- }
-