forked from swwwolf/wdbgark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objtype.cpp
99 lines (79 loc) · 3.45 KB
/
objtype.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* WinDBG Anti-RootKit extension
* Copyright © 2013-2014 Vyacheslav Rusakoff
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* This work is licensed under the terms of the GNU GPL, version 3. See
* the COPYING file in the top-level directory.
*/
#include <string>
#include <memory>
#include "wdbgark.hpp"
#include "analyze.hpp"
EXT_COMMAND(wa_objtype,
"Output kernel-mode object type(s)",
"{type;s;o;type,Object type name}") {
std::string type;
RequireKernelMode();
if ( !Init() )
throw ExtStatusException(S_OK, "global init failed");
if ( HasArg("type") ) // object type was provided
type.assign(GetArgStr("type"));
out << "Displaying \\ObjectTypes\\" << type << endlout;
unsigned __int64 object_types_directory_offset = m_obj_helper->FindObjectByName("ObjectTypes", 0);
if ( !object_types_directory_offset ) {
err << __FUNCTION__ << ": failed to get \"ObjectTypes\" directory" << endlerr;
return;
}
std::unique_ptr<WDbgArkAnalyze> display(new WDbgArkAnalyze(WDbgArkAnalyze::AnalyzeTypeDefault));
if ( !display->SetOwnerModule("nt") )
warn << __FUNCTION__ ": SetOwnerModule failed" << endlwarn;
display->PrintHeader();
try {
if ( type.empty() ) {
WalkDirectoryObject(object_types_directory_offset,
reinterpret_cast<void*>(display.get()),
DirectoryObjectTypeCallback);
} else {
ExtRemoteTyped object_type("nt!_OBJECT_TYPE",
m_obj_helper->FindObjectByName(type, object_types_directory_offset),
false,
NULL,
NULL);
if ( !SUCCEEDED(DirectoryObjectTypeCallback(this, object_type, reinterpret_cast<void*>(display.get()))) )
warn << __FUNCTION__ << ": DirectoryObjectTypeCallback failed" << endlwarn;
}
}
catch ( const ExtRemoteException &Ex ) {
err << __FUNCTION__ << ": " << Ex.GetMessage() << endlerr;
}
catch( const ExtInterruptException& ) {
throw;
}
display->PrintFooter();
}
HRESULT WDbgArk::DirectoryObjectTypeCallback(WDbgArk* wdbg_ark_class, const ExtRemoteTyped &object, void* context) {
WDbgArkAnalyze* display = reinterpret_cast<WDbgArkAnalyze*>(context);
try {
ExtRemoteTyped object_type("nt!_OBJECT_TYPE", object.m_Offset, false, NULL, NULL);
ExtRemoteTyped typeinfo = object_type.Field("TypeInfo");
display->AnalyzeObjectTypeInfo(typeinfo, object);
}
catch ( const ExtRemoteException &Ex ) {
std::stringstream tmperr;
tmperr << __FUNCTION__ << ": " << Ex.GetMessage() << endlerr;
return Ex.GetStatus();
}
return S_OK;
}