From 92ea310563466a077717d2ebf25d0b8b59fd2394 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sun, 2 Jul 2017 11:56:01 +0000 Subject: [PATCH] [SHIMDBG] Output both to the console and the debug output + fix a copypasta error. svn path=/trunk/; revision=75264 --- .../applications/devutils/shimdbg/shimdbg.c | 102 +++++++++++------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/rosapps/applications/devutils/shimdbg/shimdbg.c b/rosapps/applications/devutils/shimdbg/shimdbg.c index 43fe873610d..3bceef81d19 100644 --- a/rosapps/applications/devutils/shimdbg/shimdbg.c +++ b/rosapps/applications/devutils/shimdbg/shimdbg.c @@ -10,11 +10,31 @@ #include #include +void __stdcall OutputDebugStringA(PCSTR); + +void xprintf(const char *fmt, ...) +{ + va_list ap; + int length; + char *buf; + + va_start(ap, fmt); + length = _vscprintf(fmt, ap); + buf = malloc(length + 1); + vsprintf(buf, fmt, ap); + buf[length] = '\0'; + va_end(ap); + + fputs(buf, stdout); + OutputDebugStringA(buf); +} + + void CallApphelp(APPHELPCACHESERVICECLASS Service, PAPPHELP_CACHE_SERVICE_LOOKUP CacheEntry) { NTSTATUS Status = NtApphelpCacheControl(Service, CacheEntry); - printf("NtApphelpCacheControl returned 0x%x\n", (unsigned int)Status); + xprintf("NtApphelpCacheControl returned 0x%x\n", (unsigned int)Status); } HANDLE MapFile(char* filename, UNICODE_STRING* PathName, int MapIt) @@ -35,7 +55,7 @@ HANDLE MapFile(char* filename, UNICODE_STRING* PathName, int MapIt) FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE); if (!NT_SUCCESS(Status)) { - printf("Failed opening the file, using a NULL handle\n"); + xprintf("Failed opening the file, using a NULL handle\n"); FileHandle = NULL; } } @@ -50,7 +70,7 @@ void CallApphelpWithImage(char* filename, int MapIt, HANDLE FileHandle = MapFile(filename, &PathName, MapIt); - printf("Calling %s %s mapping\n", ServiceName, (MapIt ? "with" : "without")); + xprintf("Calling %s %s mapping\n", ServiceName, (MapIt ? "with" : "without")); RtlInitUnicodeString(&CacheEntry.ImageName, PathName.Buffer); CacheEntry.ImageHandle = FileHandle ? FileHandle : (HANDLE)-1; @@ -82,7 +102,7 @@ int HandleImageArg(int argc, char* argv[], int* pn, char MapItChar, (*pn) += 1; return 0; } - printf("Error: no image name specified\n"); + xprintf("Error: no image name specified\n"); return 1; } @@ -124,7 +144,7 @@ static BOOL InitApphelp() static ANSI_STRING SdbFreeFileAttributes = RTL_CONSTANT_STRING("SdbFreeFileAttributes"); if (!NT_SUCCESS(LdrLoadDll(NULL, NULL, &DllName, &hdll))) { - printf("Unable to load apphelp.dll\n"); + xprintf("Unable to load apphelp.dll\n"); return FALSE; } if (!NT_SUCCESS(LdrGetProcedureAddress(hdll, &SdbTagToString, 0, (PVOID)&pSdbTagToString)) || @@ -133,7 +153,7 @@ static BOOL InitApphelp() { LdrUnloadDll(hdll); hdll = NULL; - printf("Unable to resolve functions\n"); + xprintf("Unable to resolve functions\n"); return FALSE; } } @@ -158,7 +178,7 @@ int HandleDumpAttributes(int argc, char* argv[], int* pn, const char* opt) } else if (argn+1 >= argc) { - printf("Error: no image name specified\n"); + xprintf("Error: no image name specified\n"); return 1; } else @@ -171,7 +191,7 @@ int HandleDumpAttributes(int argc, char* argv[], int* pn, const char* opt) if (pSdbGetFileAttributes(FileName.Buffer, &attr, &num_attr)) { - printf("Dumping attributes for %s\n", arg); + xprintf("Dumping attributes for %s\n", arg); for (n = 0; n < num_attr; ++n) { TAG tagType; @@ -185,24 +205,24 @@ int HandleDumpAttributes(int argc, char* argv[], int* pn, const char* opt) switch (tagType) { case TAG_TYPE_DWORD: - printf("<%ls>0x%lx\n", tagName, attr[n].dwattr, tagName, attr[n].dwattr); + xprintf("<%ls>0x%lx\n", tagName, attr[n].dwattr, tagName); break; case TAG_TYPE_STRINGREF: - printf("<%ls>0x%ls\n", tagName, attr[n].lpattr, tagName); + xprintf("<%ls>%ls\n", tagName, attr[n].lpattr, tagName); break; case TAG_TYPE_QWORD: - printf("<%ls>0x%I64x\n", tagName, attr[n].qwattr, tagName, attr[n].qwattr); + xprintf("<%ls>0x%I64x\n", tagName, attr[n].qwattr, tagName); break; default: - printf("