Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Bazhan committed Jun 27, 2015
1 parent 0dd340b commit a5ac67d
Showing 1 changed file with 65 additions and 69 deletions.
134 changes: 65 additions & 69 deletions KD/st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Return Value:
--*/

{
HRESULT Result;
HRESULT Status = S_OK;
ULONG ProcessorType;
ULONG PlatformId;
ULONG Major;
Expand All @@ -51,109 +51,105 @@ Return Value:

UNREFERENCED_PARAMETER(args);

if ((Result = QueryInterfaces(DebugClient)) != S_OK) {
__try {

ReleaseInterfaces();
return Result;
}
if ((Status = QueryInterfaces(DebugClient)) != S_OK) {

if ((Result = DebugControl->GetActualProcessorType(&ProcessorType)) != S_OK) {
__leave;
}

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't get the processor type.\n");
ReleaseInterfaces();
return Result;
}
if ((Status = DebugControl->GetActualProcessorType(&ProcessorType)) != S_OK) {

if ((Result = DebugControl->GetSystemVersion(&PlatformId, &Major, &Minor, NULL, NULL, NULL, &ServicePackNumber, NULL, NULL, NULL)) != S_OK) {
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't get the processor type.\n");
__leave;
}

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't get system version.\n");
ReleaseInterfaces();
return Result;
}
if ((Status = DebugControl->GetSystemVersion(&PlatformId, &Major, &Minor, NULL, NULL, NULL, &ServicePackNumber, NULL, NULL, NULL)) != S_OK) {

if ((Result = DebugSymbols->GetOffsetByName("nt!KeServiceDescriptorTable", &KeServiceDescriptorTable)) != S_OK) {
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't get system version.\n");
__leave;
}

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read nt!KeServiceDescriptorTable.\n");
ReleaseInterfaces();
return Result;
}
if ((Status = DebugSymbols->GetOffsetByName("nt!KeServiceDescriptorTable", &KeServiceDescriptorTable)) != S_OK) {

if ((Result = DebugSymbols->GetOffsetByName("nt!KiServiceLimit", &KiServiceLimit)) != S_OK) {
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read nt!KeServiceDescriptorTable.\n");
__leave;
}

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read nt!KiServiceLimit.\n");
ReleaseInterfaces();
return Result;
}
if ((Status = DebugSymbols->GetOffsetByName("nt!KiServiceLimit", &KiServiceLimit)) != S_OK) {

if ((Result = DebugDataSpaces->ReadPointersVirtual(1, KeServiceDescriptorTable, &ServiceTableBase)) != S_OK) {
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read nt!KiServiceLimit.\n");
__leave;
}

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read service table base.\n");
ReleaseInterfaces();
return Result;
}
if ((Status = DebugDataSpaces->ReadPointersVirtual(1, KeServiceDescriptorTable, &ServiceTableBase)) != S_OK) {

if ((Result = DebugDataSpaces->ReadVirtual(KiServiceLimit, &Limit, sizeof(ULONG), &BytesRead)) != S_OK) {
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read service table base.\n");
__leave;
}

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read service table limit.\n");
ReleaseInterfaces();
return Result;
}
if ((Status = DebugDataSpaces->ReadVirtual(KiServiceLimit, &Limit, sizeof(ULONG), &BytesRead)) != S_OK) {

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read service table limit.\n");
__leave;
}

Address = ServiceTableBase;
Address = ServiceTableBase;

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "\n");
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "\n");

if (IMAGE_FILE_MACHINE_I386 == ProcessorType) {
if (IMAGE_FILE_MACHINE_I386 == ProcessorType) {

for (i = 0; i < Limit; i++, Address += sizeof(ULONG)) {
for (i = 0; i < Limit; i++, Address += sizeof(ULONG)) {

ServiceName[0] = '\0';
ServiceName[0] = '\0';

if ((Result = DebugDataSpaces->ReadPointersVirtual(1, Address, &ServiceAddress)) != S_OK) {
if ((Status = DebugDataSpaces->ReadPointersVirtual(1, Address, &ServiceAddress)) != S_OK) {

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read memory.\n");
ReleaseInterfaces();
return Result;
}
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read memory.\n");
__leave;
}

DebugSymbols->GetNameByOffset(ServiceAddress, (PSTR)ServiceName, _countof(ServiceName), &BytesRead, NULL);
DebugSymbols->GetNameByOffset(ServiceAddress, (PSTR)ServiceName, _countof(ServiceName), &BytesRead, NULL);

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "%03lx:\t%p\t%s\n", i, ServiceAddress, ServiceName);
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "%03lx:\t%p\t%s\n", i, ServiceAddress, ServiceName);
}
}
}
else if (IMAGE_FILE_MACHINE_AMD64 == ProcessorType) {
else if (IMAGE_FILE_MACHINE_AMD64 == ProcessorType) {

for (i = 0; i < Limit; i++, Address += sizeof(ULONG)) {
for (i = 0; i < Limit; i++, Address += sizeof(ULONG)) {

ServiceName[0] = '\0';
ServiceName[0] = '\0';

if ((Result = DebugDataSpaces->ReadVirtual(Address, &Offset, sizeof(Offset), &BytesRead)) != S_OK) {
if ((Status = DebugDataSpaces->ReadVirtual(Address, &Offset, sizeof(Offset), &BytesRead)) != S_OK) {

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read memory.\n");
ReleaseInterfaces();
return Result;
}
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "Couldn't read memory.\n");
__leave;
}

if (Minor < 6000) {
if (Minor < 6000) {

Offset &= ~0xF;
}
else {
Offset &= ~0xF;
}
else {

Offset >>= 4;
}
Offset >>= 4;
}

ServiceAddress = ServiceTableBase + Offset;
ServiceAddress = ServiceTableBase + Offset;

DebugSymbols->GetNameByOffset(ServiceAddress, (PSTR)ServiceName, _countof(ServiceName), &BytesRead, NULL);
DebugSymbols->GetNameByOffset(ServiceAddress, (PSTR)ServiceName, _countof(ServiceName), &BytesRead, NULL);

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "%03lx:\t%p\t%s\n", i, ServiceAddress, ServiceName);
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "%03lx:\t%p\t%s\n", i, ServiceAddress, ServiceName);
}
}
}

DebugControl->Output(DEBUG_OUTPUT_NORMAL, "\n");
DebugControl->Output(DEBUG_OUTPUT_NORMAL, "\n");
}
__finally {

ReleaseInterfaces();
ReleaseInterfaces();
}

return S_OK;
return Status;
}

0 comments on commit a5ac67d

Please sign in to comment.