/*++ Copyright (c) 1990 Microsoft Corporation Module Name: ntsdexts.c Abstract: This function contains miscellaneous VDMEXTS functions Author: Bob Day (bobday) 29-Feb-1992 Grabbed standard header Revision History: Neil Sandlin (NeilSa) 15-Jan-1996 Merged with vdmexts --*/ #include #pragma hdrstop #include VOID DumpMemory( UINT UnitSize, BOOL bAscii ) { VDMCONTEXT ThreadContext; int mode; int j, lines = 8, linelength; WORD selector; ULONG offset, endoffset, units; ULONG base; char ch; if (!UnitSize) { return; } mode = GetContext( &ThreadContext ); if (!GetNextToken()) { PRINTF("Please specify an address\n"); return; } if (!ParseIntelAddress(&mode, &selector, &offset)) { return; } if (GetNextToken()) { if ((*lpArgumentString == 'l') || (*lpArgumentString == 'L')) { lpArgumentString++; } units = EvaluateToken(); lines = (units*UnitSize+15)/16; } else { units = (lines*16)/UnitSize; } endoffset = offset+units*UnitSize; base = GetInfoFromSelector(selector, mode, NULL) + GetIntelBase(); while (lines--) { if (offset & 0xFFFF0000) { PRINTF("%04x:%08lx ", selector, offset); } else { PRINTF("%04x:%04x ", selector, LOWORD(offset)); } linelength = endoffset - offset; if (linelength > 16) { linelength = 16; } switch(UnitSize) { case 1: for (j=0; j= si.Limit) cb -= offset+cb-si.Limit; if (!READMEM((LPVOID)(Base+offset), rgbInstruction, cb)) { PRINTF("%04x:%08x: \n", selector, offset); return; } cb = unassemble_one(rgbInstruction, si.bBig, selector, offset, rgchOutput, rgchExtra, &ThreadContext, mode); if (offset > 0xffff) { PRINTF("%04x:%08x ", selector, offset); } else { PRINTF("%04x:%04x ", selector, offset); } for (j=0; j 8) { szModuleArg[8] = 0; } } } PRINTF("Sel Base Limit Type Seg Module\n"); PRINTF("==== ======== ======== ==== ==== ========\n"); se = (SEGENTRY *) EXPRESSION("WOW_BIG_BDE_HACK"); cnt = 0; while ( cnt != MAXSEGENTRY ) { if ( selector == 0 || se[cnt].selector == selector || bModuleNameGiven) { switch (se[cnt].type) { case SEGTYPE_PROT: { HEAPENTRY he = {0}; he.Selector = se[cnt].selector; if (FindHeapEntry(&he, FHE_FIND_SEL_ONLY, FHE_FIND_QUIET)) { break; } } GetInfoFromSelector(se[cnt].selector, PROT_MODE, &si); ParseModuleName(filename, se[cnt].path_name); if (!bModuleNameGiven || !_stricmp(filename, szModuleArg)) { PRINTF("%04X %08lX %08lX", se[cnt].selector, si.Base, si.Limit); PRINTF(" %s", si.bCode ? "code" : "data"); PRINTF(" %04X %s\n", se[cnt].segment+1, filename ); } break; case SEGTYPE_V86: ParseModuleName(filename, se[cnt].path_name); if (!bModuleNameGiven || !_stricmp(filename, szModuleArg)) { PRINTF("%04X %08lX %08lX %s %04X %s\n", se[cnt].selector, se[cnt].selector << 4, se[cnt].ImgLen, "v86 ", se[cnt].segment+1, filename ); } break; } } cnt++; } he.CurrentEntry = 0; // reset scan if (bModuleNameGiven) { strcpy(he.ModuleArg, szModuleArg); } else { he.Selector = selector; } while (FindHeapEntry(&he, bModuleNameGiven ? FHE_FIND_MOD_ONLY : FHE_FIND_SEL_ONLY, FHE_FIND_QUIET)) { if (he.SegmentNumber != -1) { GetInfoFromSelector((WORD)(he.gnode.pga_handle | 1), PROT_MODE, &si); PRINTF("%04X %08lX %08lX", he.gnode.pga_handle | 1, he.gnode.pga_address, he.gnode.pga_size - 1); PRINTF(" %s", si.bCode ? "Code" : "Data"); PRINTF(" %04X %s\n", he.SegmentNumber+1, he.OwnerName); } } } VOID dg( CMD_ARGLIST ) { ULONG selector; ULONG Base; SELECTORINFO si; int count = 16; CMD_INIT(); if (!GetNextToken()) { PRINTF("Please enter a selector\n"); return; } selector = EvaluateToken(); if (GetNextToken()) { if (tolower(*lpArgumentString) == 'l') { lpArgumentString++; } count = (WORD) EvaluateToken(); } while (count--) { Base = GetInfoFromSelector( (WORD) selector, PROT_MODE, &si ); PRINTF("%04X => Base: %08lX", selector, Base); #ifndef i386 PRINTF(" (%08X)", Base+GetIntelBase()); #endif PRINTF(" Limit: %08lX %s %s %s %s\n", si.Limit, si.bPresent ? " P" : "NP", si.bSystem ? "System" : si.bCode ? "Code " : "Data ", si.bSystem ? "" : si.bWrite ? "W" : "R", si.bSystem ? "" : si.bAccessed ? "A" : "" ); selector+=8; if (selector>0xffff) { break; } } } VOID PrintOneFaultVector( int vector, ULONG pHandler ) { VDM_FAULTHANDLER handler; char sym_text[255]; ULONG dist; PRINTF("%02X: ", vector); if (!READMEM((LPVOID)pHandler, &handler, sizeof(VDM_FAULTHANDLER))) { PRINTF("\n"); return; } PRINTF("%04LX:%08lX ", handler.CsSelector, handler.Eip); if (FindSymbol(handler.CsSelector, handler.Eip, sym_text, &dist, BEFORE, PROT_MODE )) { if ( dist == 0 ) { PRINTF("%s", sym_text ); } else { PRINTF("%s+0x%lx", sym_text, dist ); } } PRINTF("\n"); } VOID df( CMD_ARGLIST ) { int vector = -1; LPVOID pHandlers; #ifdef i386 THREAD_BASIC_INFORMATION ThreadBasicInfo; NTSTATUS Status; TEB teb; #endif CMD_INIT(); if (GetNextToken()) { vector = EvaluateToken(); if ((vector < 0) || (vector > 0x1f)) { PRINTF("Invalid fault vector\n"); return; } } #ifdef i386 Status = NtQueryInformationThread( hCurrentThread, ThreadBasicInformation, &ThreadBasicInfo, sizeof(ThreadBasicInfo), NULL ); if (!NT_SUCCESS(Status)) { PRINTF("NtQueryInfomationThread failed\n"); return; } if (!READMEM((LPVOID)(ThreadBasicInfo.TebBaseAddress), &teb, sizeof(TEB))) { PRINTF("\n"); return; } pHandlers = (LPVOID) ((PVDM_TIB)teb.Vdm)->VdmFaultHandlers; #else pHandlers = (LPVOID) EXPRESSION("ntvdm!dpmifaulthandlers"); if (!pHandlers) { PRINTF("Could get symbol ntvdm!dpmifaulthandlers\n"); return; } #endif // i386 if (vector >= 0) { PrintOneFaultVector(vector, (ULONG)pHandlers + vector*sizeof(VDM_FAULTHANDLER)); } else for (vector = 0; vector < 0x20; vector++) { PrintOneFaultVector(vector, (ULONG)pHandlers + vector*sizeof(VDM_FAULTHANDLER)); } } VOID PrintOneInterruptVector( int vector, ULONG pHandler ) { VDM_INTERRUPTHANDLER handler; char sym_text[255]; ULONG dist; PRINTF("%02X: ", vector); if (!READMEM((LPVOID)pHandler, &handler, sizeof(VDM_INTERRUPTHANDLER))) { PRINTF("\n"); return; } PRINTF("%04LX:%08lX ", handler.CsSelector, handler.Eip); if (FindSymbol(handler.CsSelector, handler.Eip, sym_text, &dist, BEFORE, PROT_MODE )) { if ( dist == 0 ) { PRINTF("%s", sym_text ); } else { PRINTF("%s+0x%lx", sym_text, dist ); } } PRINTF("\n"); } VOID di( CMD_ARGLIST ) { int vector = -1; LPVOID pHandlers; #ifdef i386 THREAD_BASIC_INFORMATION ThreadBasicInfo; NTSTATUS Status; TEB teb; #endif CMD_INIT(); if (GetNextToken()) { vector = EvaluateToken(); if ((vector < 0) || (vector > 0xff)) { PRINTF("Invalid interrupt vector\n"); return; } } #ifdef i386 Status = NtQueryInformationThread( hCurrentThread, ThreadBasicInformation, &ThreadBasicInfo, sizeof(ThreadBasicInfo), NULL ); if (!NT_SUCCESS(Status)) { PRINTF("NtQueryInfomationThread failed\n"); return; } if (!READMEM((LPVOID)(ThreadBasicInfo.TebBaseAddress), &teb, sizeof(TEB))) { PRINTF("\n"); return; } pHandlers = (LPVOID) ((PVDM_TIB)teb.Vdm)->VdmInterruptHandlers; #else pHandlers = (LPVOID) EXPRESSION("ntvdm!dpmiinterrupthandlers"); if (!pHandlers) { PRINTF("Could get symbol ntvdm!dpmiinterrupthandlers\n"); return; } #endif // i386 if (vector >= 0) { PrintOneInterruptVector(vector, (ULONG)pHandlers + vector*sizeof(VDM_INTERRUPTHANDLER)); } else for (vector = 0; vector < 0x100; vector++) { PrintOneInterruptVector(vector, (ULONG)pHandlers + vector*sizeof(VDM_INTERRUPTHANDLER)); } }