mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 18:08:53 +00:00
41283223af
For the second time in a couple of weeks, I've rewritten the xattr table into a new extended_attributes table. If we find an attribute that we don't have a parser for, we will check if it contains non printable characters. If it does, we'll base64 it. If it doesn't, we will just output the unencoded string.
82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
/*
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
|
|
#include <sstream>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
#include <boost/archive/iterators/transform_width.hpp>
|
|
#include <boost/archive/iterators/binary_from_base64.hpp>
|
|
#include <boost/archive/iterators/base64_from_binary.hpp>
|
|
|
|
#include <boost/archive/iterators/transform_width.hpp>
|
|
|
|
#include "osquery/core/conversions.h"
|
|
|
|
namespace bai = boost::archive::iterators;
|
|
|
|
namespace osquery {
|
|
|
|
typedef bai::binary_from_base64<const char*> base64_str;
|
|
typedef bai::transform_width<base64_str, 8, 6> base64_dec;
|
|
typedef bai::transform_width<std::string::const_iterator, 6, 8> base64_enc;
|
|
typedef bai::base64_from_binary<base64_enc> it_base64;
|
|
|
|
std::string base64Decode(const std::string& encoded) {
|
|
std::string is;
|
|
std::stringstream os;
|
|
|
|
is = encoded;
|
|
boost::replace_all(is, "\r\n", "");
|
|
boost::replace_all(is, "\n", "");
|
|
uint32_t size = is.size();
|
|
|
|
// Remove the padding characters
|
|
if (size && is[size - 1] == '=') {
|
|
--size;
|
|
if (size && is[size - 1] == '=') {
|
|
--size;
|
|
}
|
|
}
|
|
|
|
if (size == 0) {
|
|
return "";
|
|
}
|
|
|
|
std::copy(base64_dec(is.data()),
|
|
base64_dec(is.data() + size),
|
|
std::ostream_iterator<char>(os));
|
|
|
|
return os.str();
|
|
}
|
|
|
|
std::string base64Encode(const std::string& unencoded) {
|
|
std::stringstream os;
|
|
|
|
if (unencoded.size() == 0) {
|
|
return std::string();
|
|
}
|
|
|
|
unsigned int writePaddChars = (3-unencoded.length()%3)%3;
|
|
std::string base64(it_base64(unencoded.begin()), it_base64(unencoded.end()));
|
|
base64.append(writePaddChars,'=');
|
|
os << base64;
|
|
return os.str();
|
|
}
|
|
|
|
bool isPrintable(const std::string& check) {
|
|
for (const unsigned char ch : check) {
|
|
if (ch >= 0x7F || ch <= 0x1F) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|