Skip to content
Snippets Groups Projects
Commit 067e0b6a authored by U-BASIS\cray's avatar U-BASIS\cray
Browse files

Updates

From standup it was decided that we should return data as it is found in the registry. This means that data will be null terminated only if it was null termianted in the registry.
parent 10231180
Branches
Tags
No related merge requests found
...@@ -85,9 +85,13 @@ namespace Rejistry { ...@@ -85,9 +85,13 @@ namespace Rejistry {
return getASCIIString(0, _byteBuffer->limit()); return getASCIIString(0, _byteBuffer->limit());
} }
/** /**
* Throws exception if offset or length is too large. * Reads data from the registry and returns the data as a string
*/ * as it is represented in the registry, including Null characters.
*
* @param offset: Offset where data begins
* @param length: Number of bytes to read
*/
std::string RegistryByteBuffer::getASCIIString(const uint32_t offset, const uint32_t length) const { std::string RegistryByteBuffer::getASCIIString(const uint32_t offset, const uint32_t length) const {
if (length == 0) { if (length == 0) {
return ""; return "";
...@@ -102,60 +106,52 @@ namespace Rejistry { ...@@ -102,60 +106,52 @@ namespace Rejistry {
return getUTF16String(0, _byteBuffer->limit()); return getUTF16String(0, _byteBuffer->limit());
} }
/**
* Reads data from the registry and returns a wstring of the data
* as it is represented in the registry, including Null characters.
*
* @param offset: Offset where data begins
* @param length: Number of bytes to read
*/
std::wstring RegistryByteBuffer::getUTF16String(const uint32_t offset, const uint32_t length) const { std::wstring RegistryByteBuffer::getUTF16String(const uint32_t offset, const uint32_t length) const {
if (length == 0) { if (length == 0) {
return L""; return L"";
} }
ByteBuffer::ByteArray &data = getData(offset, length);
// If the size of the array is not a multiple of 2 it is
// likely to not be UTF16 encoded. The most common case is that
// the string is simply missing a terminating null so we add it.
if (data.size() % 2 != 0) {
data.push_back('\0');
}
// Find UTF16 null terminator.
uint32_t nullPos = 0;
for (; nullPos < data.size(); nullPos += 2) {
if (data[nullPos] == '\0' && data[nullPos+1] == '\0') {
break;
}
}
// empty string
if (nullPos == 0) {
return L"";
}
// UFT16 NULL char not found so add it ByteBuffer::ByteArray &data = getData(offset, length);
// Non-ascii registry key names seem to not be NULL terminated // There are cases where an odd number of bytes are returned which
// which leads to conversion errors in from_bytes() (CT-2917) // leads to errors during conversion. See CT-2917 test12 for more details.
else if (nullPos == data.size()) { if (data.size() % 2 != 0) {
data.push_back('\0');
data.push_back('\0'); data.push_back('\0');
} }
std::wstring result; // Empty value data (single UTF16 null char)
if (data.size() == 2 && data[0] == '\0' && data[1] == '\0') {
return L"";
}
try { std::wstring result;
result = conv.from_bytes(reinterpret_cast<const char*>(&data[0]), reinterpret_cast<const char*>(&data[nullPos])); try {
} result = conv.from_bytes(reinterpret_cast<const char*>(&data[0]), reinterpret_cast<const char*>(&data[data.size()]));
catch (std::exception&) }
{ catch (std::exception&)
throw RegistryParseException("Error: Failed to convert string"); {
} throw RegistryParseException("Error: Failed to convert string");
}
return result; return result;
} }
ByteBuffer::ByteArray RegistryByteBuffer::getData() const { ByteBuffer::ByteArray RegistryByteBuffer::getData() const {
return getData(0, _byteBuffer->limit()); return getData(0, _byteBuffer->limit());
} }
/** /**
* Throws exception if offset and length are too large. * Reads data from the registry based off of the given offset and length of data to read.
*/ *
* @param offset: Offset where data begins
* @param length: Number of bytes to read
*/
ByteBuffer::ByteArray RegistryByteBuffer::getData(const uint32_t offset, const uint32_t length) const { ByteBuffer::ByteArray RegistryByteBuffer::getData(const uint32_t offset, const uint32_t length) const {
uint32_t savedPosition = _byteBuffer->position(); uint32_t savedPosition = _byteBuffer->position();
_byteBuffer->position(offset); _byteBuffer->position(offset);
...@@ -170,6 +166,12 @@ namespace Rejistry { ...@@ -170,6 +166,12 @@ namespace Rejistry {
return getStringList(0, _byteBuffer->limit()); return getStringList(0, _byteBuffer->limit());
} }
/**
* Reads data from the registry based off of the given offset and length of data to read.
*
* @param offset: Offset where data begins
* @param length: Number of bytes to read
*/
std::vector<std::wstring> RegistryByteBuffer::getStringList(const uint32_t offset, const uint32_t length) const { std::vector<std::wstring> RegistryByteBuffer::getStringList(const uint32_t offset, const uint32_t length) const {
std::vector<std::wstring> stringList; std::vector<std::wstring> stringList;
ByteBuffer::ByteArray data = getData(offset, length); ByteBuffer::ByteArray data = getData(offset, length);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment