diff --git a/ape/ape.S b/ape/ape.S index f97383aca..79594ddd4 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -1036,7 +1036,7 @@ ape_pe: .ascin "PE",4 .quad ape_pe_base // ImageBase .long ape_pe_sectionalignment // SectionAlignment .long ape_pe_filealignment // FileAlignment - .short v_ntversion // MajorOperatingSystemVersion + .short 10 // MajorOperatingSystemVersion .short 0 // MinorOperatingSystemVersion .short 0 // MajorImageVersion .short 0 // MinorImageVersion diff --git a/ape/ape.lds b/ape/ape.lds index eaaf3ed59..81bd4ea6b 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -715,7 +715,6 @@ ape_idataz = LINK_WINDOWS ? RVA(ape_idata_iat) : 0; ape_idata_iatsize = LINK_WINDOWS ? ape_idata_iatend - ape_idata_iat : 0; ape_idata = LINK_WINDOWS ? RVA(ape_idata_idt) : 0; ape_idata_idtsize = LINK_WINDOWS ? ape_idata_idtend - ape_idata_idt : 0; -v_ntversion = LINK_WINDOWS ? 6 : 1; v_ntdllchar = LINK_WINDOWS ? 288 : 0; v_ntsubversion = LINK_WINDOWS ? 6 : 5; v_ntsubsystem = (LINK_WINDOWS diff --git a/libc/calls/reboot.c b/libc/calls/reboot.c index 062c5fb92..76ce77436 100644 --- a/libc/calls/reboot.c +++ b/libc/calls/reboot.c @@ -19,7 +19,6 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/framebuffervirtualscreeninfo.h" #include "libc/dce.h" -#include "libc/nt/enum/version.h" #include "libc/nt/system.h" #include "libc/runtime/runtime.h" #include "libc/sysv/errfuns.h" @@ -72,9 +71,7 @@ int reboot(int howto) { } else { howto |= kNtShutdownForceSelf; howto |= kNtShutdownForceOthers; - if (NtGetVersion() >= kNtVersionWindows8) { - howto |= kNtShutdownHybrid; - } + howto |= kNtShutdownHybrid; if (immediately) { ok = !!InitiateShutdown(0, 0, 0, howto | kNtShutdownGraceOverride, 0); } else { diff --git a/libc/calls/tcsetattr-nt.c b/libc/calls/tcsetattr-nt.c index 1eafdf66b..b0f49e803 100644 --- a/libc/calls/tcsetattr-nt.c +++ b/libc/calls/tcsetattr-nt.c @@ -25,7 +25,6 @@ #include "libc/intrin/nomultics.internal.h" #include "libc/nt/console.h" #include "libc/nt/enum/consolemodeflags.h" -#include "libc/nt/version.h" #include "libc/str/str.h" #include "libc/sysv/consts/baud.internal.h" #include "libc/sysv/consts/termios.h" @@ -96,9 +95,7 @@ textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) { if (!(tio->c_oflag & ONLCR)) { outmode |= kNtDisableNewlineAutoReturn; } - if (IsAtLeastWindows10()) { - outmode |= kNtEnableVirtualTerminalProcessing; - } + outmode |= kNtEnableVirtualTerminalProcessing; // tune the win32 configuration unassert(SetConsoleMode(hInput, inmode)); diff --git a/libc/calls/uname.c b/libc/calls/uname.c index 6c139776b..754142794 100644 --- a/libc/calls/uname.c +++ b/libc/calls/uname.c @@ -30,7 +30,6 @@ #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/nt/enum/computernameformat.h" -#include "libc/nt/struct/teb.h" #include "libc/nt/systeminfo.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" @@ -81,34 +80,13 @@ static textwindows void GetNtName(char *name, int kind) { } } -static inline textwindows int GetNtMajorVersion(void) { -#ifdef __x86_64__ - return NtGetPeb()->OSMajorVersion; -#else - return 0; -#endif -} - -static inline textwindows int GetNtMinorVersion(void) { -#ifdef __x86_64__ - return NtGetPeb()->OSMinorVersion; -#else - return 0; -#endif -} - -static inline textwindows int GetNtBuildNumber(void) { -#ifdef __x86_64__ - return NtGetPeb()->OSBuildNumber; -#else - return 0; -#endif -} - static textwindows void GetNtVersion(char *p) { - p = FormatUint32(p, GetNtMajorVersion()), *p++ = '.'; - p = FormatUint32(p, GetNtMinorVersion()), *p++ = '-'; - p = FormatUint32(p, GetNtBuildNumber()); + // We could ask GetVersionExW() for this information, but it'll simply + // report what we put in the MajorOperatingSystemVersion of the PE ape + // header fields. Windows doesn't want us detecting versions it seems. + // Chances are they bake all old versions of Windows into Windows, and + // run us on the intended one, like some kind of Docker container. Heh + strcpy(p, "10.0"); } static const char *Str(int rc, const char *s) { diff --git a/libc/intrin/asan.c b/libc/intrin/asan.c index c472997b9..57bca268b 100644 --- a/libc/intrin/asan.c +++ b/libc/intrin/asan.c @@ -39,7 +39,6 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/gc.internal.h" #include "libc/nexgen32e/stackframe.h" -#include "libc/nt/enum/version.h" #include "libc/runtime/memtrack.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" @@ -1500,10 +1499,6 @@ void __asan_init(int argc, char **argv, char **envp, unsigned long *auxv) { static bool once; if (!_cmpxchg(&once, false, true)) return; - if (IsWindows() && NtGetVersion() < kNtVersionWindows10) { - __write_str("error: asan binaries require windows10\r\n"); - _Exit(0); /* So `make MODE=dbg test` passes w/ Windows7 */ - } if (_weaken(hook_malloc) || _weaken(hook_calloc) || _weaken(hook_realloc) || _weaken(hook_realloc_in_place) || _weaken(hook_free) || _weaken(hook_malloc_usable_size)) { diff --git a/libc/intrin/isatleastwindows10.c b/libc/intrin/isatleastwindows10.c deleted file mode 100644 index 7ff304163..000000000 --- a/libc/intrin/isatleastwindows10.c +++ /dev/null @@ -1,27 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nt/version.h" - -bool32(IsAtLeastWindows10)(void) { -#ifdef __x86_64__ - return IsAtLeastWindows10(); -#else - return true; -#endif -} diff --git a/libc/intrin/isdebuggerpresent.c b/libc/intrin/isdebuggerpresent.c index 60fa89826..0e12034f3 100644 --- a/libc/intrin/isdebuggerpresent.c +++ b/libc/intrin/isdebuggerpresent.c @@ -24,7 +24,6 @@ #include "libc/intrin/promises.internal.h" #include "libc/log/libfatal.internal.h" #include "libc/log/log.h" -#include "libc/nt/struct/teb.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/at.h" #include "libc/sysv/consts/o.h" @@ -32,14 +31,6 @@ #define kBufSize 1024 #define kPid "TracerPid:\t" -static textwindows bool IsBeingDebugged(void) { -#ifdef __x86_64__ - return !!NtGetPeb()->BeingDebugged; -#else - return false; -#endif -} - /** * Determines if gdb, strace, windbg, etc. is controlling process. * @return non-zero if attached, otherwise 0 @@ -54,7 +45,7 @@ bool32 IsDebuggerPresent(bool32 force) { if (!force && environ && __getenv(environ, "HEISENDEBUG").s) return 0; if (IsWindows()) - return IsBeingDebugged(); + return false; // make virus scanners happy if (__isworker) return false; if (!PLEDGED(RPATH)) diff --git a/libc/intrin/nocolor.c b/libc/intrin/nocolor.c index efd2fa7f6..3c9df75eb 100644 --- a/libc/intrin/nocolor.c +++ b/libc/intrin/nocolor.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dce.h" #include "libc/log/internal.h" -#include "libc/nt/version.h" #include "libc/runtime/runtime.h" #define IsDumb(s) \ @@ -51,6 +50,5 @@ bool __nocolor; __attribute__((__constructor__(20))) optimizesize textstartup void __nocolor_init(int argc, char **argv, char **envp, intptr_t *auxv) { char *s; - __nocolor = (IsWindows() && !IsAtLeastWindows10()) || - ((s = getenv("TERM")) && IsDumb(s)); + __nocolor = IsWindows() || ((s = getenv("TERM")) && IsDumb(s)); } diff --git a/libc/intrin/ntgetversion.c b/libc/intrin/ntgetversion.c deleted file mode 100644 index 8afc3bddb..000000000 --- a/libc/intrin/ntgetversion.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2021 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nt/struct/teb.h" -#include "libc/runtime/runtime.h" -#ifdef __x86_64__ - -/** - * Returns New Technology version, e.g. - * - * This can only be called on Windows. - * - * @see IsAtLeastWindows10() - */ -textwindows int NtGetVersion(void) { - return (NtGetPeb()->OSMajorVersion & 0xff) << 8 | NtGetPeb()->OSMinorVersion; -} - -#endif /* __x86_64__ */ diff --git a/libc/isystem/winternl.h b/libc/isystem/winternl.h index d5d1b691b..6463ecba1 100644 --- a/libc/isystem/winternl.h +++ b/libc/isystem/winternl.h @@ -2,6 +2,4 @@ #define COSMOPOLITAN_LIBC_ISYSTEM_WINTERNL_H_ #include "libc/nt/ntdll.h" #include "libc/nt/struct/ldr.h" -#include "libc/nt/struct/peb.h" -#include "libc/nt/struct/teb.h" #endif /* COSMOPOLITAN_LIBC_ISYSTEM_WINTERNL_H_ */ diff --git a/libc/nt/enum/version.h b/libc/nt/enum/version.h deleted file mode 100644 index f7201d81e..000000000 --- a/libc/nt/enum/version.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_ -#define COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_ - -/** - * Known versions of the New Technology executive. - * @see IsAtLeastWindows10() - * @see NtGetVersion() - */ -#define kNtVersionWindows10 0x0a00 -#define kNtVersionWindows81 0x0603 -#define kNtVersionWindows8 0x0602 -#define kNtVersionWindows7 0x0601 -#define kNtVersionWindowsVista 0x0600 /* intended baseline */ -#define kNtVersionWindowsXp64 0x0502 /* end of the road */ -#define kNtVersionWindowsXp 0x0501 /* snowball's chance */ -#define kNtVersionWindows2000 0x0500 /* the golden age */ -#define kNtVersionFuture 0x0b00 - -#endif /* COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_ */ diff --git a/libc/nt/struct/osversioninfo.h b/libc/nt/struct/osversioninfo.h deleted file mode 100644 index 5268cecfd..000000000 --- a/libc/nt/struct/osversioninfo.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_ -#define COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_ -COSMOPOLITAN_C_START_ - -struct NtOsVersionInfo { - uint32_t dwOSVersionInfoSize; - uint32_t dwMajorVersion; - uint32_t dwMinorVersion; - uint32_t dwBuildNumber; - uint32_t dwPlatformId; - char16_t szCSDVersion[128]; - uint16_t wServicePackMajor; - uint16_t wServicePackMinor; - uint16_t wSuiteMask; - uint8_t wProductType; - uint8_t wReserved; -}; - -COSMOPOLITAN_C_END_ -#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_ */ diff --git a/libc/nt/struct/peb.h b/libc/nt/struct/peb.h deleted file mode 100644 index ba7623938..000000000 --- a/libc/nt/struct/peb.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_ -#define COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_ -#include "libc/nt/struct/ldr.h" -#include "libc/nt/struct/unicodestring.h" - -struct NtPeb { - union { - struct { - unsigned char InheritedAddressSpace; - unsigned char ReadImageFileExecOptions; - unsigned char BeingDebugged; - unsigned char __wut1; - }; - uint64_t __wut2; - }; - uint64_t Mutant; - uint64_t ImageBaseAddress; - struct NtLdr *Ldr; - uint64_t ProcessParameters; - uint64_t SubSystemData; - uint64_t ProcessHeap; - uint64_t FastPebLock; - uint64_t __wut3; - uint64_t __wut4; - uint64_t __wut5; - union { - uint64_t KernelCallbackTable; - uint64_t UserSharedInfoPtr; - }; - uint32_t SystemReserved; - uint32_t __wut6; - uint64_t __wut7; - uint64_t TlsExpansionCounter; - uint64_t TlsBitmap; - uint32_t TlsBitmapBits[2]; - uint64_t ReadOnlySharedMemoryBase; - uint64_t __wut8; - uint64_t ReadOnlyStaticServerData; - uint64_t AnsiCodePageData; - uint64_t OemCodePageData; - uint64_t UnicodeCaseTableData; - uint32_t NumberOfProcessors; -#ifdef __x86_64__ - uint32_t NtGlobalFlag; -#else - uint64_t NtGlobalFlag; -#endif - int64_t CriticalSectionTimeout; - uint64_t HeapSegmentReserve; - uint64_t HeapSegmentCommit; - uint64_t HeapDeCommitTotalFreeThreshold; - uint64_t HeapDeCommitFreeBlockThreshold; - uint32_t NumberOfHeaps; - uint32_t MaximumNumberOfHeaps; - uint64_t ProcessHeaps; - uint64_t GdiSharedHandleTable; - uint64_t ProcessStarterHelper; - uint64_t GdiDCAttributeList; - uint64_t LoaderLock; - union { - struct { - uint32_t OSMajorVersion; - uint32_t OSMinorVersion; - }; - uint64_t OSVersion; - }; - uint16_t OSBuildNumber; - uint16_t OSCSDVersion; - uint32_t OSPlatformId; - uint32_t ImageSubsystem; - uint32_t ImageSubsystemMajorVersion; - uint64_t ImageSubsystemMinorVersion; - union { - uint64_t ImageProcessAffinityMask; - uint64_t ActiveProcessAffinityMask; - }; - uint64_t GdiHandleBuffer[38 - __SIZEOF_POINTER__]; - uint64_t PostProcessInitRoutine; - uint64_t TlsExpansionBitmap; - uint32_t TlsExpansionBitmapBits[32]; - uint64_t SessionId; - uint64_t AppCompatFlags; - uint64_t AppCompatFlagsUser; - uint64_t pShimData; - uint64_t AppCompatInfo; - struct NtUnicodeString CSDVersion; - uint64_t ActivationContextData; - uint64_t ProcessAssemblyStorageMap; - uint64_t SystemDefaultActivationContextData; - uint64_t SystemAssemblyStorageMap; - uint64_t MinimumStackCommit; -}; - -#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_ */ diff --git a/libc/nt/struct/teb.h b/libc/nt/struct/teb.h deleted file mode 100644 index d7ee6f649..000000000 --- a/libc/nt/struct/teb.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_NT_TEB_H_ -#define COSMOPOLITAN_LIBC_NT_TEB_H_ -#include "libc/nt/struct/peb.h" -#ifdef __GNUC__ - -/* - * These macros address directly into NT's TEB a.k.a. TIB - * Any function that does this needs the `dontasan` keyword - */ -#define NtGetPeb() ((__seg_gs struct NtPeb *)0x60) -#define NtGetTeb() ((void *)*(__seg_gs uintptr_t *)0x30) -#define NtGetPid() (*(__seg_gs uint32_t *)0x40) -#define NtGetTid() (*(__seg_gs uint32_t *)0x48) -#define NtGetErr() (*(__seg_gs int *)0x68) -#define _NtGetSeh() ((void *)*(__seg_gs uintptr_t *)0x00) -#define _NtGetStackHigh() ((void *)*(__seg_gs uintptr_t *)0x08) -#define _NtGetStackLow() ((void *)*(__seg_gs uintptr_t *)0x10) -#define _NtGetSubsystemTib() ((void *)*(__seg_gs uintptr_t *)0x18) -#define _NtGetFib() ((void *)*(__seg_gs uintptr_t *)0x20) -#define _NtGetEnv() ((char16_t *)*(__seg_gs intptr_t *)0x38) -#define _NtGetRpc() ((void *)*(__seg_gs uintptr_t *)0x50) -#define _NtGetTls() ((void *)*(__seg_gs uintptr_t *)0x58) - -#endif /* __GNUC__ */ -#endif /* COSMOPOLITAN_LIBC_NT_TEB_H_ */ diff --git a/libc/nt/version.h b/libc/nt/version.h deleted file mode 100644 index 3d14e8f90..000000000 --- a/libc/nt/version.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_NT_VERSION_H_ -#define COSMOPOLITAN_LIBC_NT_VERSION_H_ -#include "libc/nt/struct/osversioninfo.h" -COSMOPOLITAN_C_START_ - -bool32 IsAtLeastWindows10(void) pureconst; -bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation); - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__) -#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10) -#define GetNtMajorVersion() \ - __extension__({ \ - uintptr_t __x; \ - __asm__("mov\t%%gs:96,%q0\r\n" \ - "mov\t280(%q0),%b0" \ - : "=q"(__x)); \ - (unsigned char)__x; \ - }) -#endif - -COSMOPOLITAN_C_END_ -#endif /* COSMOPOLITAN_LIBC_NT_VERSION_H_ */ diff --git a/libc/runtime/memtrack.internal.h b/libc/runtime/memtrack.internal.h index 6607a036a..120cf5939 100644 --- a/libc/runtime/memtrack.internal.h +++ b/libc/runtime/memtrack.internal.h @@ -3,7 +3,6 @@ #include "ape/sections.internal.h" #include "libc/dce.h" #include "libc/macros.internal.h" -#include "libc/nt/version.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/sysv/consts/ss.h" diff --git a/libc/runtime/runtime.h b/libc/runtime/runtime.h index 72a112936..c2dc963d3 100644 --- a/libc/runtime/runtime.h +++ b/libc/runtime/runtime.h @@ -120,7 +120,6 @@ void __jit_begin(void); void __jit_end(void); void __clear_cache(void *, void *); /* portability */ -int NtGetVersion(void) pureconst; bool32 IsGenuineBlink(void); bool32 IsCygwin(void); const char *GetCpuidOs(void); diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index d24bc90c0..cedab520e 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -34,7 +34,6 @@ #include "libc/nt/pedef.internal.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" -#include "libc/nt/struct/teb.h" #include "libc/nt/thunk/msabi.h" #include "libc/runtime/internal.h" #include "libc/runtime/memtrack.internal.h" @@ -159,9 +158,10 @@ static bool32 HasEnvironmentVariable(const char16_t *name) { static abi wontreturn void WinInit(const char16_t *cmdline) { __oldstack = (intptr_t)__builtin_frame_address(0); + __imp_SetConsoleOutputCP(kNtCpUtf8); + // make console into utf-8 ansi/xterm style tty - if (NtGetPeb()->OSMajorVersion >= 10 && - (intptr_t)v_ntsubsystem == kNtImageSubsystemWindowsCui) { + if ((intptr_t)v_ntsubsystem == kNtImageSubsystemWindowsCui) { __imp_SetConsoleCP(kNtCpUtf8); __imp_SetConsoleOutputCP(kNtCpUtf8); for (int i = 0; i <= 2; ++i) { diff --git a/libc/stdio/printargs.c b/libc/stdio/printargs.c index 34b2c362f..151136ac9 100644 --- a/libc/stdio/printargs.c +++ b/libc/stdio/printargs.c @@ -43,7 +43,6 @@ #include "libc/nt/startupinfo.h" #include "libc/nt/struct/ldrdatatableentry.h" #include "libc/nt/struct/startupinfo.h" -#include "libc/nt/struct/teb.h" #include "libc/runtime/clktck.h" #include "libc/runtime/internal.h" #include "libc/runtime/memtrack.internal.h" @@ -83,19 +82,6 @@ static const char *FindNameById(const struct IdName *names, unsigned long id) { return NULL; } -static void PrintDependencies(const char *prologue) { -#ifdef __x86_64__ - struct NtLinkedList *head = &NtGetPeb()->Ldr->InLoadOrderModuleList; - struct NtLinkedList *ldr = head->Next; - do { - const struct NtLdrDataTableEntry *dll = - (const struct NtLdrDataTableEntry *)ldr; - PRINT(" ☼ %.*!hs (%'zukb @ %p)", dll->FullDllName.Length, - dll->FullDllName.Data, dll->SizeOfImage / 1024, dll->DllBase); - } while ((ldr = ldr->Next) && ldr != head); -#endif -} - static void Print(const char *prologue) { } @@ -693,29 +679,6 @@ textstartup void __printargs(const char *prologue) { GetStdHandle(kNtStdErrorHandle)); if (GetConsoleMode(GetStdHandle(kNtStdErrorHandle), &cm)) PRINT(" %s", DescribeNtConsoleOutFlags(cm)); - -#ifdef __x86_64__ - PRINT(""); - PRINT("TEB"); - PRINT(" ☼ gs:0x%02x %s = %p", 0x00, "NtGetSeh()", _NtGetSeh()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x08, "NtGetStackHigh()", _NtGetStackHigh()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x10, "NtGetStackLow()", _NtGetStackLow()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x18, "_NtGetSubsystemTib()", - _NtGetSubsystemTib()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x20, "NtGetFib()", _NtGetFib()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x30, "NtGetTeb()", NtGetTeb()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x38, "NtGetEnv()", _NtGetEnv()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x40, "NtGetPid()", NtGetPid()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x48, "NtGetTid()", NtGetTid()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x50, "NtGetRpc()", _NtGetRpc()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x58, "NtGetTls()", _NtGetTls()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x60, "NtGetPeb()", NtGetPeb()); - PRINT(" ☼ gs:0x%02x %s = %p", 0x68, "NtGetErr()", NtGetErr()); -#endif - - PRINT(""); - PRINT("DEPENDENCIES"); - PrintDependencies(prologue); } PRINT(""); diff --git a/test/libc/runtime/grow_test.c b/test/libc/runtime/grow_test.c index 071fa2f89..9609b05de 100644 --- a/test/libc/runtime/grow_test.c +++ b/test/libc/runtime/grow_test.c @@ -21,7 +21,6 @@ #include "libc/macros.internal.h" #include "libc/mem/internal.h" #include "libc/mem/mem.h" -#include "libc/nt/enum/version.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/test/libc/sock/unix_test.c b/test/libc/sock/unix_test.c index e72a5baa6..f5847513b 100644 --- a/test/libc/sock/unix_test.c +++ b/test/libc/sock/unix_test.c @@ -23,7 +23,6 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/nexgen32e/vendor.internal.h" -#include "libc/nt/version.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" @@ -97,8 +96,6 @@ void StreamServer(atomic_bool *ready) { TEST(unix, stream) { int ws; - if (IsWindows() && !IsAtLeastWindows10()) - return; atomic_bool *ready = _mapshared(1); // TODO(jart): move this line down when kFdProcess is gone ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_STREAM, 0)); diff --git a/third_party/linenoise/linenoise.c b/third_party/linenoise/linenoise.c index b441b2af6..d402c6ae0 100644 --- a/third_party/linenoise/linenoise.c +++ b/third_party/linenoise/linenoise.c @@ -149,7 +149,6 @@ #include "libc/mem/alg.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/rdtsc.h" -#include "libc/nt/version.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" @@ -409,7 +408,7 @@ static int linenoiseIsUnsupportedTerm(void) { char *term; static char once, res; if (!once) { - if (IsWindows() && !IsAtLeastWindows10()) { + if (IsWindows()) { res = 1; } else if ((term = getenv("TERM"))) { for (i = 0; i < sizeof(kUnsupported) / sizeof(*kUnsupported); i++) { diff --git a/third_party/python/Modules/socketmodule.c b/third_party/python/Modules/socketmodule.c index b9605444f..a44040bbb 100644 --- a/third_party/python/Modules/socketmodule.c +++ b/third_party/python/Modules/socketmodule.c @@ -9,8 +9,6 @@ #include "libc/calls/weirdtypes.h" #include "libc/dce.h" #include "libc/errno.h" -#include "libc/nt/enum/version.h" -#include "libc/nt/version.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" @@ -7129,9 +7127,9 @@ PyInit__socket(void) if (TCP_USER_TIMEOUT) PyModule_AddIntMacro(m, TCP_USER_TIMEOUT); if (TCP_SAVE_SYN) PyModule_AddIntMacro(m, TCP_SAVE_SYN); if (TCP_SAVED_SYN) PyModule_AddIntMacro(m, TCP_SAVED_SYN); - if (TCP_KEEPCNT && (!IsWindows() || IsAtLeastWindows10())) + if (TCP_KEEPCNT) PyModule_AddIntMacro(m, TCP_KEEPCNT); - if (TCP_FASTOPEN && (!IsWindows() || IsAtLeastWindows10())) + if (TCP_FASTOPEN) PyModule_AddIntMacro(m, TCP_FASTOPEN); if (TCP_FASTOPEN_CONNECT) PyModule_AddIntMacro(m, TCP_FASTOPEN_CONNECT); diff --git a/third_party/python/Python/sysmodule.c b/third_party/python/Python/sysmodule.c index 8b0c6edc7..364b840d3 100644 --- a/third_party/python/Python/sysmodule.c +++ b/third_party/python/Python/sysmodule.c @@ -9,7 +9,6 @@ #include "libc/mem/gc.h" #include "libc/mem/mem.h" #include "libc/nt/dll.h" -#include "libc/nt/version.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/locale.h" @@ -1019,44 +1018,6 @@ static PyStructSequence_Desc windows_version_desc = { via indexing, the rest are name only */ }; -static PyObject * -sys_getwindowsversion(PyObject *self) -{ - int pos = 0; - PyObject *version; - struct NtOsVersionInfo ver; - - if (!IsWindows()) { - PyErr_SetString(PyExc_SystemError, "this is not windows"); - return 0; - } - - ver.dwOSVersionInfoSize = sizeof(ver); - if (!GetVersionEx(&ver)) - return PyErr_SetFromWindowsErr(0); - - version = PyStructSequence_New(&WindowsVersionType); - if (version == NULL) - return NULL; - - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMajorVersion)); - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMinorVersion)); - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwBuildNumber)); - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwPlatformId)); - PyStructSequence_SET_ITEM(version, pos++, PyUnicode_FromString(gc(utf16to8(ver.szCSDVersion,-1,0)))); - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMajor)); - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMinor)); - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask)); - PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType)); - - if (PyErr_Occurred()) { - Py_DECREF(version); - return NULL; - } - - return version; -} - #ifdef MS_WINDOWS #pragma warning(pop) @@ -1457,8 +1418,6 @@ static PyMethodDef sys_methods[] = { {"getsizeof", (PyCFunction)sys_getsizeof, METH_VARARGS | METH_KEYWORDS, getsizeof_doc}, {"_getframe", sys_getframe, METH_VARARGS, getframe_doc}, - {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, - getwindowsversion_doc}, #ifdef MS_WINDOWS {"_enablelegacywindowsfsencoding", (PyCFunction)sys_enablelegacywindowsfsencoding, METH_NOARGS, enablelegacywindowsfsencoding_doc }, diff --git a/tool/viz/printpeb.c b/tool/viz/printpeb.c deleted file mode 100644 index e311b4932..000000000 --- a/tool/viz/printpeb.c +++ /dev/null @@ -1,550 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/calls/internal.h" -#include "libc/dce.h" -#include "libc/intrin/safemacros.internal.h" -#include "libc/log/log.h" -#include "libc/nt/dll.h" -#include "libc/nt/enum/filetype.h" -#include "libc/nt/enum/startf.h" -#include "libc/nt/files.h" -#include "libc/nt/process.h" -#include "libc/nt/runtime.h" -#include "libc/nt/struct/ldr.h" -#include "libc/nt/struct/ldrdatatableentry.h" -#include "libc/nt/struct/linkedlist.h" -#include "libc/nt/struct/peb.h" -#include "libc/nt/struct/systeminfo.h" -#include "libc/nt/struct/teb.h" -#include "libc/nt/struct/unicodestring.h" -#include "libc/runtime/runtime.h" -#include "libc/stdio/stdio.h" -#include "libc/sysv/consts/madv.h" -#include "libc/sysv/consts/o.h" -#include "libc/time.h" -#include "tool/decode/lib/flagger.h" -#include "tool/decode/lib/idname.h" -#if defined(__x86_64__) && SupportsWindows() - -char *GetString(const struct NtUnicodeString *s) { - static char buf[1024]; - unsigned len = min(sizeof(buf) - 1, s->Length); - for (unsigned i = 0; i < len; ++i) { - buf[i] = (unsigned char)s->Data[i]; - } - buf[len] = '\0'; - return &buf[0]; -} - -int NextBestThing(void) { - int64_t fd = open("/proc/self/maps", O_RDONLY); - posix_fadvise(fd, 0, 0, MADV_SEQUENTIAL); - ssize_t wrote; - while ((wrote = copyfd(fd, 1, -1)) != -1) { - if (wrote == 0) - break; - } - close(fd); - return 0; -} - -const struct IdName kNtStartfFlagNames[] = { - {kNtStartfUseshowwindow, "kNtStartfUseshowwindow"}, - {kNtStartfUsesize, "kNtStartfUsesize"}, - {kNtStartfUseposition, "kNtStartfUseposition"}, - {kNtStartfUsecountchars, "kNtStartfUsecountchars"}, - {kNtStartfUsefillattribute, "kNtStartfUsefillattribute"}, - {kNtStartfRunfullscreen, "kNtStartfRunfullscreen"}, - {kNtStartfForceonfeedback, "kNtStartfForceonfeedback"}, - {kNtStartfForceofffeedback, "kNtStartfForceofffeedback"}, - {kNtStartfUsestdhandles, "kNtStartfUsestdhandles"}, - {kNtStartfUsehotkey, "kNtStartfUsehotkey"}, - {kNtStartfTitleislinkname, "kNtStartfTitleislinkname"}, - {kNtStartfTitleisappid, "kNtStartfTitleisappid"}, - {kNtStartfPreventpinning, "kNtStartfPreventpinning"}, - {kNtStartfUntrustedsource, "kNtStartfUntrustedsource"}, - {0, 0}, -}; - -dontasan void PrintStartupInfo(void) { -#if 0 - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § startup info │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); -#define X(D, F) \ - printf("%s.%-22s= " D "\n", "__nt_startupinfo", #F, __nt_startupinfo.F); - X("%u", cb); - X("%p", lpReserved); - X("%hs", lpDesktop); - X("%hs", lpTitle); - X("%u", dwX); - X("%u", dwY); - X("%u", dwXSize); - X("%u", dwYSize); - X("%u", dwXCountChars); - X("%u", dwYCountChars); - X("%u", dwFillAttribute); - printf("%s.%-22s: %s\n", "__nt_startupinfo", "dwFlags", - RecreateFlags(kNtStartfFlagNames, __nt_startupinfo.dwFlags)); - X("%hu", wShowWindow); - X("%hu", cbReserved2); - X("%s", lpReserved2); - X("%ld", hStdInput); - X("%ld", hStdOutput); - X("%ld", hStdError); -#undef X -#endif -} - -void PrintSystemInfo(void) { -#if 0 - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § system info │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); -#define X(D, F) \ - printf("%s.%-28s= " D "\n", "__nt_systeminfo", #F, __nt_systeminfo.F); - X("%08x", dwOemId); - X("%04hx", wProcessorArchitecture); - X("%d", dwPageSize); - X("%p", lpMinimumApplicationAddress); - X("%p", lpMaximumApplicationAddress); - X("%p", dwActiveProcessorMask); - X("%u", dwNumberOfProcessors); - X("%u", dwProcessorType); - X("%u", dwAllocationGranularity); - X("%hu", wProcessorLevel); - X("%hu", wProcessorRevision); -#undef X -#endif -} - -const char *ft2str(int ft) { - if (ft == kNtFileTypeUnknown) - return "kNtFileTypeUnknown"; - if (ft == kNtFileTypeDisk) - return "kNtFileTypeDisk"; - if (ft == kNtFileTypeChar) - return "kNtFileTypeChar"; - if (ft == kNtFileTypePipe) - return "kNtFileTypePipe"; - if (ft == kNtFileTypeRemote) - return "kNtFileTypeRemote"; - return "wut?"; -} - -void PrintStdioInfo(void) { - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § stdio info │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); - printf("%s: %ld (%s)\n", "g_fds.p[0].handle", g_fds.p[0].handle, - ft2str(GetFileType(g_fds.p[0].handle))); - printf("%s: %ld (%s)\n", "g_fds.p[1].handle", g_fds.p[1].handle, - ft2str(GetFileType(g_fds.p[1].handle))); - printf("%s: %ld (%s)\n", "g_fds.p[2].handle", g_fds.p[2].handle, - ft2str(GetFileType(g_fds.p[2].handle))); -} - -dontasan void PrintTeb(void) { - GetCurrentProcessId(); - SetLastError(0x1234); - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § teb? │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x00, "NtGetSeh()", _NtGetSeh()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x08, "NtGetStackHigh()", - _NtGetStackHigh()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x10, "NtGetStackLow()", - _NtGetStackLow()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x18, "_NtGetSubsystemTib()", - _NtGetSubsystemTib()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x20, "NtGetFib()", _NtGetFib()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x30, "NtGetTeb()", NtGetTeb()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x38, "NtGetEnv()", _NtGetEnv()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x40, "NtGetPid()", NtGetPid()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x48, "NtGetTid()", NtGetTid()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x50, "NtGetRpc()", _NtGetRpc()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x58, "NtGetTls()", _NtGetTls()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x60, "NtGetPeb()", NtGetPeb()); - printf("gs:0x%02x: %-39s = 0x%lx\n", 0x68, "NtGetErr()", NtGetErr()); -} - -void PrintPeb(void) { - __seg_gs struct NtPeb *peb = NtGetPeb(); - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § peb │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); - printf("0x%04x: %-40s = %u\n", offsetof(struct NtPeb, InheritedAddressSpace), - "InheritedAddressSpace", (unsigned)peb->InheritedAddressSpace); - printf("0x%04x: %-40s = %u\n", - offsetof(struct NtPeb, ReadImageFileExecOptions), - "ReadImageFileExecOptions", (unsigned)peb->ReadImageFileExecOptions); - printf("0x%04x: %-40s = %u\n", offsetof(struct NtPeb, BeingDebugged), - "BeingDebugged", (unsigned)peb->BeingDebugged); - printf("0x%04x: %-40s = %u\n", offsetof(struct NtPeb, __wut1), "__wut1", - (unsigned)peb->__wut1); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, Mutant), "Mutant", - peb->Mutant); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ImageBaseAddress), - "ImageBaseAddress", peb->ImageBaseAddress); - /* struct NtLdr *Ldr; */ - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessParameters), - "ProcessParameters", peb->ProcessParameters); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, SubSystemData), - "SubSystemData", peb->SubSystemData); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessHeap), - "ProcessHeap", peb->ProcessHeap); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, FastPebLock), - "FastPebLock", peb->FastPebLock); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut3), "__wut3", - peb->__wut3); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut4), "__wut4", - peb->__wut4); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut5), "__wut5", - peb->__wut5); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, KernelCallbackTable), - "KernelCallbackTable", peb->KernelCallbackTable); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, UserSharedInfoPtr), - "UserSharedInfoPtr", peb->UserSharedInfoPtr); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, SystemReserved), - "SystemReserved", peb->SystemReserved); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, __wut6), "__wut6", - peb->__wut6); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut7), "__wut7", - peb->__wut7); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, TlsExpansionCounter), - "TlsExpansionCounter", peb->TlsExpansionCounter); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, TlsBitmap), - "TlsBitmap", peb->TlsBitmap); - printf("0x%04x: %-40s = 0x%x 0x%x\n", offsetof(struct NtPeb, TlsBitmapBits), - "TlsBitmapBits", peb->TlsBitmapBits[0], peb->TlsBitmapBits[1]); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ReadOnlySharedMemoryBase), - "ReadOnlySharedMemoryBase", peb->ReadOnlySharedMemoryBase); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut8), "__wut8", - peb->__wut8); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ReadOnlyStaticServerData), - "ReadOnlyStaticServerData", peb->ReadOnlyStaticServerData); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AnsiCodePageData), - "AnsiCodePageData", peb->AnsiCodePageData); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, OemCodePageData), - "OemCodePageData", peb->OemCodePageData); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, UnicodeCaseTableData), "UnicodeCaseTableData", - peb->UnicodeCaseTableData); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, NumberOfProcessors), - "NumberOfProcessors", peb->NumberOfProcessors); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, NtGlobalFlag), - "NtGlobalFlag", peb->NtGlobalFlag); - printf("0x%04x: %-40s = %ld\n", - offsetof(struct NtPeb, CriticalSectionTimeout), - "CriticalSectionTimeout", peb->CriticalSectionTimeout); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, HeapSegmentReserve), - "HeapSegmentReserve", peb->HeapSegmentReserve); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, HeapSegmentCommit), - "HeapSegmentCommit", peb->HeapSegmentCommit); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, HeapDeCommitTotalFreeThreshold), - "HeapDeCommitTotalFreeThreshold", peb->HeapDeCommitTotalFreeThreshold); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, HeapDeCommitFreeBlockThreshold), - "HeapDeCommitFreeBlockThreshold", peb->HeapDeCommitFreeBlockThreshold); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, NumberOfHeaps), - "NumberOfHeaps", peb->NumberOfHeaps); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, MaximumNumberOfHeaps), - "MaximumNumberOfHeaps", peb->MaximumNumberOfHeaps); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessHeaps), - "ProcessHeaps", peb->ProcessHeaps); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, GdiSharedHandleTable), "GdiSharedHandleTable", - peb->GdiSharedHandleTable); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ProcessStarterHelper), "ProcessStarterHelper", - peb->ProcessStarterHelper); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, GdiDCAttributeList), - "GdiDCAttributeList", peb->GdiDCAttributeList); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, LoaderLock), - "LoaderLock", peb->LoaderLock); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, OSMajorVersion), - "OSMajorVersion", peb->OSMajorVersion); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, OSMinorVersion), - "OSMinorVersion", peb->OSMinorVersion); - printf("0x%04x: %-40s = %hu\n", offsetof(struct NtPeb, OSBuildNumber), - "OSBuildNumber", peb->OSBuildNumber); - printf("0x%04x: %-40s = %hu\n", offsetof(struct NtPeb, OSCSDVersion), - "OSCSDVersion", peb->OSCSDVersion); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, OSPlatformId), - "OSPlatformId", peb->OSPlatformId); - printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, ImageSubsystem), - "ImageSubsystem", peb->ImageSubsystem); - printf("0x%04x: %-40s = 0x%x\n", - offsetof(struct NtPeb, ImageSubsystemMajorVersion), - "ImageSubsystemMajorVersion", peb->ImageSubsystemMajorVersion); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ImageSubsystemMinorVersion), - "ImageSubsystemMinorVersion", peb->ImageSubsystemMinorVersion); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ImageProcessAffinityMask), - "ImageProcessAffinityMask", peb->ImageProcessAffinityMask); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ActiveProcessAffinityMask), - "ActiveProcessAffinityMask", peb->ActiveProcessAffinityMask); - /* "0x%lx", GdiHandleBuffer[38 - __SIZEOF_POINTER__]; */ - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, PostProcessInitRoutine), - "PostProcessInitRoutine", peb->PostProcessInitRoutine); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, TlsExpansionBitmap), - "TlsExpansionBitmap", peb->TlsExpansionBitmap); - /* "0x%x", TlsExpansionBitmapBits[32]; */ - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, SessionId), - "SessionId", peb->SessionId); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AppCompatFlags), - "AppCompatFlags", peb->AppCompatFlags); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AppCompatFlagsUser), - "AppCompatFlagsUser", peb->AppCompatFlagsUser); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, pShimData), - "pShimData", peb->pShimData); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AppCompatInfo), - "AppCompatInfo", peb->AppCompatInfo); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ActivationContextData), "ActivationContextData", - peb->ActivationContextData); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, ProcessAssemblyStorageMap), - "ProcessAssemblyStorageMap", peb->ProcessAssemblyStorageMap); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, SystemDefaultActivationContextData), - "SystemDefaultActivationContextData", - peb->SystemDefaultActivationContextData); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtPeb, SystemAssemblyStorageMap), - "SystemAssemblyStorageMap", peb->SystemAssemblyStorageMap); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, MinimumStackCommit), - "MinimumStackCommit", peb->MinimumStackCommit); -} - -void PrintPebLdr(void) { - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § peb » ldr │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, SizeOfThis), - "SizeOfThis", NtGetPeb()->Ldr->SizeOfThis); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, IsInitialized), - "IsInitialized", NtGetPeb()->Ldr->IsInitialized); - printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, SsHandle), - "SsHandle", NtGetPeb()->Ldr->SsHandle); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdr, InLoadOrderModuleList), "InLoadOrderModuleList", - NtGetPeb()->Ldr->InLoadOrderModuleList); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdr, InMemoryOrderModuleList), - "InMemoryOrderModuleList", NtGetPeb()->Ldr->InMemoryOrderModuleList); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdr, InInitOrderModuleList), "InInitOrderModuleList", - NtGetPeb()->Ldr->InInitOrderModuleList); -} - -void PrintModulesLoadOrder(void) { - { - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § modules » load order │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); - struct NtLinkedList *head = &NtGetPeb()->Ldr->InLoadOrderModuleList; - struct NtLinkedList *ldr = head->Next; - do { - const struct NtLdrDataTableEntry *dll = - (const struct NtLdrDataTableEntry *)ldr; - /* struct NtLinkedList InLoadOrderLinks; /\* msdn:reserved *\/ */ - /* struct NtLinkedList InMemoryOrderLinks; */ - /* struct NtLinkedList InInitOrderLinks; /\* msdn:reserved *\/ */ - printf("%p\n", ldr); - printf("%p vs. %p\n", dll, GetModuleHandleW(dll->FullDllName.Data)); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, DllBase), "DllBase", - dll->DllBase); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, EntryPoint), "EntryPoint", - dll->EntryPoint); - printf("0x%04x: %-40s = 0x%x\n", - offsetof(struct NtLdrDataTableEntry, SizeOfImage), "SizeOfImage", - dll->SizeOfImage); - printf("0x%04x: %-40s = \"%s\"\n", - offsetof(struct NtLdrDataTableEntry, FullDllName), "FullDllName", - GetString(&dll->FullDllName)); - printf("0x%04x: %-40s = \"%s\"\n", - offsetof(struct NtLdrDataTableEntry, BaseDllName), "BaseDllName", - GetString(&dll->BaseDllName)); - printf("0x%04x: %-40s = 0x%x\n", - offsetof(struct NtLdrDataTableEntry, Flags), "Flags", dll->Flags); - printf("0x%04x: %-40s = %hu\n", - offsetof(struct NtLdrDataTableEntry, Load_Count), "Load_Count", - dll->Load_Count); - printf("0x%04x: %-40s = %hu\n", - offsetof(struct NtLdrDataTableEntry, TlsIndex), "TlsIndex", - dll->TlsIndex); - /* union { */ - /* struct NtLinkedList HashLinks; */ - /* struct { */ - /* void *SectionPointer; */ - /* uint32_t CheckSum; */ - /* }; */ - /* }; */ - /* union { */ - /* void *LoadedImports; */ - /* uint32_t TimeDateStamp; */ - /* }; */ - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, EntryPointActivationContext), - "EntryPointActivationContext", dll->EntryPointActivationContext); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, PatchInformation), - "PatchInformation", dll->PatchInformation); - /* struct NtLinkedList ForwarderLinks; */ - /* struct NtLinkedList ServiceTagLinks; */ - /* struct NtLinkedList StaticLinks; */ - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, ContextInformation), - "ContextInformation", dll->ContextInformation); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, OriginalBase), "OriginalBase", - dll->OriginalBase); - printf("0x%04x: %-40s = %ld\n", - offsetof(struct NtLdrDataTableEntry, LoadTime), "LoadTime", - dll->LoadTime); - printf("\n"); - } while ((ldr = ldr->Next) && ldr != head); - } -} - -void PrintModulesMemoryOrder(void) { - { - printf("\n\ -╔──────────────────────────────────────────────────────────────────────────────╗\n\ -│ new technology § modules » memory order │\n\ -╚──────────────────────────────────────────────────────────────────────────────╝\n\ -\n"); - struct NtLinkedList *head = &NtGetPeb()->Ldr->InMemoryOrderModuleList; - struct NtLinkedList *ldr = head->Next; - do { - const struct NtLdrDataTableEntry *dll = - (const struct NtLdrDataTableEntry *)ldr; - /* struct NtLinkedList InLoadOrderLinks; /\* msdn:reserved *\/ */ - /* struct NtLinkedList InMemoryOrderLinks; */ - /* struct NtLinkedList InInitOrderLinks; /\* msdn:reserved *\/ */ - printf("%p\n", dll); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, DllBase), "DllBase", - dll->DllBase); - printf("0x%04x: %-40s = 0x%lx\n", - offsetof(struct NtLdrDataTableEntry, EntryPoint), "EntryPoint", - dll->EntryPoint); - printf("0x%04x: %-40s = 0x%x\n", - offsetof(struct NtLdrDataTableEntry, SizeOfImage), "SizeOfImage", - dll->SizeOfImage); - printf("0x%04x: %-40s = \"%s\"\n", - offsetof(struct NtLdrDataTableEntry, FullDllName), "FullDllName", - GetString(&dll->FullDllName)); - printf("0x%04x: %-40s = \"%s\"\n", - offsetof(struct NtLdrDataTableEntry, BaseDllName), "BaseDllName", - GetString(&dll->BaseDllName)); - printf("0x%04x: %-40s = 0x%x\n", - offsetof(struct NtLdrDataTableEntry, Flags), "Flags", dll->Flags); - printf("0x%04x: %-40s = %hu\n", - offsetof(struct NtLdrDataTableEntry, Load_Count), "Load_Count", - dll->Load_Count); - printf("0x%04x: %-40s = %hu\n", - offsetof(struct NtLdrDataTableEntry, TlsIndex), "TlsIndex", - dll->TlsIndex); - /* /\* union { *\/ */ - /* /\* struct NtLinkedList HashLinks; *\/ */ - /* /\* struct { *\/ */ - /* /\* void *SectionPointer; *\/ */ - /* /\* uint32_t CheckSum; *\/ */ - /* /\* }; *\/ */ - /* /\* }; *\/ */ - /* /\* union { *\/ */ - /* /\* void *LoadedImports; *\/ */ - /* /\* uint32_t TimeDateStamp; *\/ */ - /* /\* }; *\/ */ - /* printf("0x%04x: %-40s = 0x%lx\n", */ - /* offsetof(struct NtLdrDataTableEntry, - * EntryPointActivationContext), */ - /* "EntryPointActivationContext", - * dll->EntryPointActivationContext); */ - /* printf("0x%04x: %-40s = 0x%lx\n", */ - /* offsetof(struct NtLdrDataTableEntry, PatchInformation), */ - /* "PatchInformation", dll->PatchInformation); */ - /* /\* struct NtLinkedList ForwarderLinks; *\/ */ - /* /\* struct NtLinkedList ServiceTagLinks; *\/ */ - /* /\* struct NtLinkedList StaticLinks; *\/ */ - /* printf("0x%04x: %-40s = 0x%lx\n", */ - /* offsetof(struct NtLdrDataTableEntry, ContextInformation), */ - /* "ContextInformation", dll->ContextInformation); */ - /* printf("0x%04x: %-40s = 0x%lx\n", */ - /* offsetof(struct NtLdrDataTableEntry, OriginalBase), - * "OriginalBase", */ - /* dll->OriginalBase); */ - /* printf("0x%04x: %-40s = %ld\n", */ - /* offsetof(struct NtLdrDataTableEntry, LoadTime), "LoadTime", */ - /* dll->LoadTime); */ - printf("\n"); - } while ((ldr = ldr->Next) && ldr != head); - } -} - -int main(int argc, char *argv[]) { - if (IsLinux()) { - return NextBestThing(); - } - if (!IsWindows()) { - fprintf(stderr, "error: this tool is intended for windows\n"); - return 1; - } - PrintStartupInfo(); - PrintSystemInfo(); - PrintStdioInfo(); - PrintTeb(); - PrintPeb(); - PrintPebLdr(); - PrintModulesLoadOrder(); - PrintModulesMemoryOrder(); - return 0; -} - -#else -int main(int argc, char *argv[]) { - fprintf(stderr, "printpeb not supported on this cpu arch or build config\n"); - return 1; -} -#endif /* __x86_64__ && SupportsWindows() */