Esempio n. 1
0
uint32_t path_from_object_attributes(const OBJECT_ATTRIBUTES *obj,
    wchar_t *path, uint32_t buffer_length)
{
	uint32_t copylen;

    if (obj->ObjectName == NULL || obj->ObjectName->Buffer == NULL) {
		return path_from_handle(obj->RootDirectory, path, buffer_length);;
    }

    // ObjectName->Length is actually the size in bytes.
    uint32_t obj_length = obj->ObjectName->Length / sizeof(wchar_t);

	copylen = min(obj_length, buffer_length - 1);

    if(obj->RootDirectory == NULL) {
        memcpy(path, obj->ObjectName->Buffer, copylen * sizeof(wchar_t));
		path[copylen] = L'\0';
        return copylen;
    }

    uint32_t length = path_from_handle(obj->RootDirectory,
        path, buffer_length);

	
	path[length++] = L'\\';
	if (length >= (buffer_length - 1))
		copylen = 0;
	else
		copylen = buffer_length - 1 - length;
	copylen = min(copylen, obj_length);
	memcpy(&path[length], obj->ObjectName->Buffer, copylen * sizeof(wchar_t));
	path[length + copylen] = L'\0';
    return length + copylen;
}
Esempio n. 2
0
uint32_t path_from_object_attributes(const OBJECT_ATTRIBUTES *obj,
    wchar_t *path, uint32_t buffer_length)
{
    if(obj->ObjectName == NULL || obj->ObjectName->Buffer == NULL) {
        return 0;
    }

    // ObjectName->Length is actually the size in bytes.
    uint32_t obj_length = obj->ObjectName->Length / sizeof(wchar_t);

    if(obj->RootDirectory == NULL) {
        wcsncpy(path, obj->ObjectName->Buffer, buffer_length);
        return obj_length > buffer_length ? buffer_length : obj_length;
    }

    uint32_t length = path_from_handle(obj->RootDirectory,
        path, buffer_length);

    path[length++] = L'\\';
    wcsncpy(&path[length], obj->ObjectName->Buffer, buffer_length - length);

    length += obj_length;
    return length > buffer_length ? buffer_length : length;
}