/* Sysinf.cc Copyright Dave Korn 2007 This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. Sysinf.cc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Sysinf.cc; see the file COPYING. If not see . To compile this utility under Cygwin, simply enter g++ sysinf.cc -o sysinf -lntdll at the commandline. You invoke it with a single command-line argument, which is the integer value of the system information class (as defined by the NT native API and the SYSTEM_INFORMATION_CLASS enumeration) for which you wish to view the data returned by NtQuerySystemInformation. To build a simplified version that only dumps the system information class 5 and 11 data and ignores command-line arguments, add the compiler flag "-DAUTOMATIC" to the above command-line. */ #include #include #include #include #include #define RVS "\e[7m" #define NORM "\e[0m" void dump_sysinf (int infonum) { unsigned long size = 29360; //29232; //29168; //0x1000; unsigned long outsize; unsigned char *buffer = (unsigned char *) malloc (size); while (NtQuerySystemInformation ((SYSTEM_INFORMATION_CLASS)(infonum & 0xff), buffer, size, &outsize) == STATUS_INFO_LENGTH_MISMATCH) { size *= 2; free (buffer); buffer = (unsigned char *) malloc (size); } /* Now dump it out. */ unsigned int i, j; fprintf (stdout, "System Information #%d: Size %d (0x%08x) Base $%08x\n", infonum, outsize, outsize, (unsigned int)buffer); for (i = 0; i < outsize; i += 16) { fprintf (stdout, " %04x: ", i); for (j = 0; j < 16; j++) { if ((i + j) >= outsize) fprintf (stdout, ".. "); else fprintf (stdout, "%02x ", buffer[i + j]); } fprintf (stdout, " "); for (j = 0; j < 16; j++) { unsigned char outch; if ((i + j) >= outsize) break; outch = buffer[i + j]; if (outch < 0x20) fprintf (stdout, RVS "%c" NORM, outch + 0x40); else if (outch < 0x7f) fprintf (stdout, "%c", outch); else if (outch == 0x7f) fprintf (stdout, "~"); else if (outch < 0xa0) fprintf (stdout, RVS "%c" NORM, outch + 0xC0); else fprintf (stdout, "%c", outch); } fprintf (stdout, "\n"); } } int main (int argc, const char **argv) { #ifdef AUTOMATIC dump_sysinf (5); fprintf (stdout, "\n\n"); dump_sysinf (11); #else /* !AUTOMATIC */ if (argc != 2) { fprintf (stderr, "Usage: sysinf "); return -1; } char *endptr; unsigned long infonum = strtoul (argv[1], &endptr, 0); if ((infonum > 256) || *endptr) { fprintf (stderr, "Invalid info number %d ('%s')\n", infonum, argv[1]); return -1; } dump_sysinf (infonum); #endif /* ?AUTOMATIC */ return 0; }