-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKIntranetAuthSdk.cc
More file actions
230 lines (209 loc) · 6.48 KB
/
Copy pathKIntranetAuthSdk.cc
File metadata and controls
230 lines (209 loc) · 6.48 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <filesystem>
#include <fstream>
#include <iterator>
#include <string>
#include <vector>
#include <Windows.h>
#include "Logger.h"
#include "KIntranetAuthSdk.h"
#ifdef KINTRANETAUTHSDK_LEGACY_ABI
#include "KIntranetAuthorizeLegacy.h"
#else
#include "KIntranetAuthorize.h"
#endif
extern "C" IMAGE_DOS_HEADER __ImageBase;
namespace {
// KSnPrivilege list embedded in KIntranetAuthSdk 12.8.0.23123.
constexpr const char* kAllFeatures[] = {
"excel_split_merge",
"screen_recording",
"split_merge_tool",
"pdf_split",
"pdf_merge",
"doc_lose_weight",
"img_loss_compress",
"ocr",
"et_filter",
"data_comparison",
"gbbasicfunction",
"gbofficialfunction",
"gbofficialprintfunction",
"gjbbasicfunction",
"gjbofficialfunction",
"pdf2doc",
"pdf_2doc",
"pdf_2doc_local",
"pdf_2et_local",
"pdf_2ppt_local",
"pdf_split_local",
"pdf_merge_local",
"pdf_2cad_local",
"pdf_2cad",
"cad_2pdf_local",
"cad_2pdf",
"pdf_2txt_local",
"pdf_2txt",
"pdf_2img_pdf_local",
"pdf_2img_pdf",
"pdf_caj2pdf_local",
"pdf_caj2pdf",
"pic_2pdf_local",
"pic_2pdf",
"pdf_edit",
"pdf_text_edit",
"pdf_pic_edit",
"pdf_img_extract",
"pdf_compress",
"pdf_cover_pen",
"pdf_num_edit",
"pdf_page_edit",
"pdf_page_move",
"pdf_pagehf_edit",
"pdf_watermark_edit",
"pdf_batch_output",
"pdf_sign",
"pdf_page_extract",
"pdf_page_output",
"pdf_ocr",
"pdf_background",
"pdf_link",
"pdf_annex",
"pdf_page_copy",
"pdf_page_split",
"pdf_page_crop",
"pdf_table_extract",
"pdf_scan_edit",
"pdf_scan_optimize",
"pdf_batch_adddelwm",
"pdf_edit_path",
"pdf_videoedit",
"pdf_audioedit",
"pdf_videosave",
"pdf_audiosave",
"pdf_page_replace",
"pdf_page_size",
"pdf_password",
"pdf_2html",
"pdf_page_manage",
"pdf_2doc_bypage_local",
"pdf_2et_bypage_local",
"pdf_2ppt_bypage_local",
"pdf_annotate",
"pdf_annotation",
"pdf_output_annotate",
"pdf_watermark",
"pdf_txt_extract",
"pure_image_pdf",
"output_highlight",
"pdf_watermark_output",
"pdf_new",
"pdf_encryption",
"pdf_virtualprint",
"table_extract",
"pdf_invoiceprint",
"pdf_formedit",
"pdf_gencatalogue",
"pdf_genbookmark",
"pdf_delete_blankpage",
"pdf_identifyform",
"pdf_reverseorder",
"img_output",
"screenshot",
"advanced_print",
// "doc_check",
"mul_print",
"pdf_2doc_bypage",
"pdf_2et",
"pdf_2et_bypage",
"pdf_2ppt",
"pdf_2ppt_bypage",
"delete_blankpage",
"file_backup",
"background",
"pdf_stamp",
"pdf_cipher_apply",
"pdf_cipher_mark",
"doc_translate",
"pdf_splice_print",
};
std::filesystem::path privilegesFilePath() {
constexpr std::size_t kMaximumPathLength = 32768;
std::vector<wchar_t> modulePath(MAX_PATH);
DWORD length = 0;
for (;;) {
length = GetModuleFileNameW(reinterpret_cast<HMODULE>(&__ImageBase), modulePath.data(), static_cast<DWORD>(modulePath.size()));
if (length == 0) {
return {};
}
if (length < modulePath.size()) {
break;
}
if (modulePath.size() >= kMaximumPathLength) {
return {};
}
const std::size_t nextSize = modulePath.size() * 2;
modulePath.resize(nextSize < kMaximumPathLength ? nextSize : kMaximumPathLength);
}
const std::filesystem::path moduleFile(std::wstring(modulePath.data(), static_cast<std::size_t>(length)));
return moduleFile.parent_path() / L"KSNPrivileges.csv";
}
bool appendPrivilegesFromFile(QList<QString>& outList) {
const std::filesystem::path path = privilegesFilePath();
if (path.empty()) {
return false;
}
std::ifstream file(path, std::ios::in | std::ios::binary);
if (!file.is_open()) {
return false;
}
std::vector<std::string> features;
std::string line;
bool firstLine = true;
while (std::getline(file, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
if (firstLine && line.size() >= 3 &&
static_cast<unsigned char>(line[0]) == 0xEF &&
static_cast<unsigned char>(line[1]) == 0xBB &&
static_cast<unsigned char>(line[2]) == 0xBF) {
line.erase(0, 3);
}
firstLine = false;
const auto first = line.find_first_not_of(" \t\r");
if (first == std::string::npos) {
continue;
}
const auto last = line.find_last_not_of(" \t\r");
features.emplace_back(line.substr(first, last - first + 1));
}
if (file.bad()) {
return false;
}
for (const std::string& feature : features) {
outList.append(QString::fromUtf8(feature.data(), static_cast<int>(feature.size())));
}
Logger::instance().writer().stream() << "[AuthBypass] Loaded " << static_cast<int>(features.size()) << " privileges from " << QString::fromStdWString(path.wstring());
return true;
}
} // namespace
void GetSNPrivileges(QList<QString>& outList) {
Logger::instance().writer().stream() << "[AuthBypass] GetSNPrivileges() called";
if (appendPrivilegesFromFile(outList)) {
return;
}
outList.reserve(outList.size() + static_cast<int>(std::size(kAllFeatures)));
for (const char* feature : kAllFeatures) {
outList.append(QString::fromLatin1(feature));
}
}
void* _kintranetauthsdk_GetAuthObject() {
Logger::instance().writer().stream() << "[AuthBypass] GetAuthObject() called";
#ifdef KINTRANETAUTHSDK_LEGACY_ABI
static KIntranetAuthorizeLegacy instance;
return static_cast<IKIntranetAuthorizeLegacy*>(&instance);
#else
static KIntranetAuthorize instance;
return static_cast<IKIntranetAuthorize*>(&instance);
#endif
}