mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 18:08:53 +00:00
c7355b19aa
Summary: Pull Request resolved: https://github.com/facebook/osquery/pull/5452 As suggested in another diff, this diff updates the language we use to describe the osquery licensing terms. We are changing all instances of //This source code is licensed as defined on the LICENSE file found in the root directory of this source tree.// to //This source code is licensed in accordance with the terms specified in the LICENSE file found in the root directory of this source tree.// We accomplish this with a codemod: $ codemod -md xplat/osquery/oss --extensions cpp,h,in,py,sh,mm,ps1 "(.\s+)This source code is licensed as defined on the LICENSE file found in the(.*)root directory of this source tree\." "\1This source code is licensed in accordance with the terms specified in\2the LICENSE file found in the root directory of this source tree." Reviewed By: fmanco Differential Revision: D14131290 fbshipit-source-id: 52c90da342263e2a80f5a678ecd760c19cf7513e
74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed in accordance with the terms specified in
|
|
* the LICENSE file found in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <string>
|
|
#include <cstddef>
|
|
|
|
#include <osquery/logger.h>
|
|
|
|
#include <osquery/utils/chars.h>
|
|
#include <osquery/utils/conversions/tryto.h>
|
|
|
|
namespace osquery {
|
|
|
|
bool isPrintable(const std::string& check) {
|
|
for (const unsigned char ch : check) {
|
|
if (ch >= 0x7F || ch <= 0x1F) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
size_t utf8StringSize(const std::string& str) {
|
|
size_t res = 0;
|
|
std::string::const_iterator it = str.begin();
|
|
for (; it != str.end(); incUtf8StringIterator(it, str.end())) {
|
|
res++;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
std::string unescapeUnicode(const std::string& escaped) {
|
|
if (escaped.size() < 6) {
|
|
return escaped;
|
|
}
|
|
|
|
std::string unescaped;
|
|
unescaped.reserve(escaped.size());
|
|
for (size_t i = 0; i < escaped.size(); ++i) {
|
|
if (i < escaped.size() - 5 && '\\' == escaped[i] && 'u' == escaped[i + 1]) {
|
|
// Assume 2-byte wide unicode.
|
|
auto const exp = tryTo<long>(escaped.substr(i + 2, 4), 16);
|
|
if (exp.isError()) {
|
|
LOG(WARNING) << "Unescaping a string with length: " << escaped.size()
|
|
<< " failed at: " << i;
|
|
return "";
|
|
}
|
|
long const value = exp.get();
|
|
if (value < 255) {
|
|
unescaped += static_cast<char>(value);
|
|
i += 5;
|
|
continue;
|
|
}
|
|
} else if (i < escaped.size() - 1 && '\\' == escaped[i] &&
|
|
'\\' == escaped[i + 1]) {
|
|
// In the case of \\users 'sers' is not a unicode character
|
|
// If we see \\ we should skip them and we do this by adding
|
|
// an extra jump forward.
|
|
unescaped += escaped[i];
|
|
++i;
|
|
}
|
|
unescaped += escaped[i];
|
|
}
|
|
return unescaped;
|
|
}
|
|
|
|
} // namespace osquery
|