/* (C) 2003 XDA Developers * Author: Willem Jan Hengeveld * Web: http://www.xda-developers.com/ * * $Header$ */ #include #include #include //----------------------------- void vtdebug(WCHAR *msg, va_list ap) { WCHAR *tbuf = (WCHAR*)malloc(16384*sizeof(WCHAR)); _vsnwprintf(tbuf, 16384, msg, ap); fputws(tbuf, stdout); free(tbuf); } void vdebug(char *msg, va_list ap) { char *buf = (char*)malloc(16384); _vsnprintf(buf, 16384, msg, ap); WCHAR *tbuf = (WCHAR*)malloc(16384*sizeof(WCHAR)); _snwprintf(tbuf, 16384, L"%hs", buf); fputws(tbuf, stdout); free(buf); free(tbuf); } void tdebug(WCHAR *msg, ...) { va_list ap; va_start(ap, msg); vtdebug(msg, ap); va_end(ap); } void debug(char *msg, ...) { va_list ap; va_start(ap, msg); vdebug(msg, ap); va_end(ap); } void verror(DWORD dwErrorCode, char *msg, va_list ap) { debug("ERROR: "); vdebug(msg, ap); TCHAR *msgbuf; int rc= FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwErrorCode, 0, (LPTSTR)&msgbuf, 0, NULL); if (rc) debug(" - %hs\n", msgbuf); else debug(" - UNKNOWNERROR: 0x%08lx\n", dwErrorCode); LocalFree(msgbuf); } void error(DWORD dwErrorCode, char *msg, ...) { va_list ap; va_start(ap, msg); verror(dwErrorCode, msg, ap); va_end(ap); } void error(char *msg, ...) { va_list ap; va_start(ap, msg); verror(GetLastError(), msg, ap); va_end(ap); } void ceerror(char *msg, ...) { va_list ap; va_start(ap, msg); verror(CeRapiGetError() || CeGetLastError(), msg, ap); va_end(ap); } int g_nDumpUnitSize=1; int g_nMaxWordsPerLine=-1; void hexdumpbytes(BYTE *buf, int nLength) { while(nLength--) printf(" %02x", *buf++); } void hexdumpwords(WORD *buf, int nLength) { while(nLength--) printf(" %04x", *buf++); } void hexdumpdwords(DWORD *buf, int nLength) { while(nLength--) printf(" %08x", *buf++); } void dumpascii(BYTE *buf, int nLength) { while(nLength--) { BYTE c= *buf++; putchar((c>=' ' && c<='~')?c:'.'); } } void writespaces(int n) { while(n--) putchar(' '); } void hexdump(DWORD dwOffset, BYTE *buf, int nLength, int nDumpUnitSize, int nMaxUnitsPerLine) { while(nLength) { // is rounding correct here? int nLineLength= min(nLength/nDumpUnitSize, nMaxUnitsPerLine); printf("%08lx: ", dwOffset); switch(nDumpUnitSize) { case 1: hexdumpbytes(buf, nLineLength); break; case 2: hexdumpwords((WORD*)buf, nLineLength); break; case 4: hexdumpdwords((DWORD*)buf, nLineLength); break; } if (nLineLength