<commit_before>#include <core/stdafx.h>
#include <core/mapi/cache/namedPropCache.h>
#include <core/mapi/cache/namedProps.h>
#include <core/interpret/guid.h>
#include <core/mapi/mapiMemory.h>
#include <core/mapi/mapiFunctions.h>
#include <core/utility/registry.h>
#include <core/utility/strings.h>
#include <core/utility/output.h>
#include <core/addin/mfcmapi.h>
#include <core/addin/addin.h>
#include <core/utility/error.h>

namespace cache
{
	namespace directMapi
	{
		_Check_return_ std::vector<std::shared_ptr<namedPropCacheEntry>>
		GetRange(_In_ LPMAPIPROP lpMAPIProp, ULONG start, ULONG end)
		{
			if (start > end) return {};
			// Allocate our tag array
			const auto count = end - start + 1;
			auto lpTag = mapi::allocate<LPSPropTagArray>(CbNewSPropTagArray(count));
			if (lpTag)
			{
				// Populate the array
				lpTag->cValues = count;
				for (ULONG tag = start, i = 0; tag <= end; tag++, i++)
				{
					mapi::setTag(lpTag, i) = PROP_TAG(PT_NULL, tag);
				}

				auto names = GetNamesFromIDs(lpMAPIProp, &lpTag, NULL);
				MAPIFreeBuffer(lpTag);
				return names;
			}

			return {};
		}

		_Check_return_ std::vector<std::shared_ptr<namedPropCacheEntry>> GetAllNamesFromIDs(_In_ LPMAPIPROP lpMAPIProp)
		{
			auto names = std::vector<std::shared_ptr<namedPropCacheEntry>>{};

			// We didn't get any names - try manual
			const auto ulLowerBound = __LOWERBOUND;
			const auto ulUpperBound = FindHighestNamedProp(lpMAPIProp);
			const auto batchSize = 200;

			output::DebugPrint(
				output::dbgLevel::NamedProp,
				L"GetAllNamesFromIDs: Walking through all IDs from 0x%X to 0x%X, looking for mappings to names\n",
				ulLowerBound,
				ulUpperBound);
			for (auto iTag = ulLowerBound; iTag <= ulUpperBound && iTag < __UPPERBOUND; iTag += batchSize - 1)
			{
				const auto range = GetRange(lpMAPIProp, iTag, min(iTag + batchSize - 1, ulUpperBound));
				for (const auto& name : range)
				{
					if (name->getMapiNameId()->lpguid != nullptr)
						if (name->getMapiNameId()->lpguid != nullptr)
						{
							names.push_back(name);
						}
				}
			}

			return names;
		}

		// Returns a vector of NamedPropCacheEntry for the input tags
		// Sourced directly from MAPI
		_Check_return_ std::vector<std::shared_ptr<namedPropCacheEntry>>
		GetNamesFromIDs(_In_ LPMAPIPROP lpMAPIProp, _In_ LPSPropTagArray* lppPropTags, ULONG ulFlags)
		{
			if (!lpMAPIProp) return {};
<commit_msg>remove extra code<commit_after>#include <core/stdafx.h>
#include <core/mapi/cache/namedPropCache.h>
#include <core/mapi/cache/namedProps.h>
#include <core/interpret/guid.h>
#include <core/mapi/mapiMemory.h>
#include <core/mapi/mapiFunctions.h>
#include <core/utility/registry.h>
#include <core/utility/strings.h>
#include <core/utility/output.h>
#include <core/addin/mfcmapi.h>
#include <core/addin/addin.h>
#include <core/utility/error.h>

namespace cache
{
	namespace directMapi
	{
		_Check_return_ std::vector<std::shared_ptr<namedPropCacheEntry>>
		GetRange(_In_ LPMAPIPROP lpMAPIProp, ULONG start, ULONG end)
		{
			if (start > end) return {};
			// Allocate our tag array
			const auto count = end - start + 1;
			auto lpTag = mapi::allocate<LPSPropTagArray>(CbNewSPropTagArray(count));
			if (lpTag)
			{
				// Populate the array
				lpTag->cValues = count;
				for (ULONG tag = start, i = 0; tag <= end; tag++, i++)
				{
					mapi::setTag(lpTag, i) = PROP_TAG(PT_NULL, tag);
				}

				auto names = GetNamesFromIDs(lpMAPIProp, &lpTag, NULL);
				MAPIFreeBuffer(lpTag);
				return names;
			}

			return {};
		}

		_Check_return_ std::vector<std::shared_ptr<namedPropCacheEntry>> GetAllNamesFromIDs(_In_ LPMAPIPROP lpMAPIProp)
		{
			auto names = std::vector<std::shared_ptr<namedPropCacheEntry>>{};

			// We didn't get any names - try manual
			const auto ulLowerBound = __LOWERBOUND;
			const auto ulUpperBound = FindHighestNamedProp(lpMAPIProp);
			const auto batchSize = 200;

			output::DebugPrint(
				output::dbgLevel::NamedProp,
				L"GetAllNamesFromIDs: Walking through all IDs from 0x%X to 0x%X, looking for mappings to names\n",
				ulLowerBound,
				ulUpperBound);
			for (auto iTag = ulLowerBound; iTag <= ulUpperBound && iTag < __UPPERBOUND; iTag += batchSize - 1)
			{
				const auto range = GetRange(lpMAPIProp, iTag, min(iTag + batchSize - 1, ulUpperBound));
				for (const auto& name : range)
				{
					if (name->getMapiNameId()->lpguid != nullptr)
					{
						names.push_back(name);
					}
				}
			}

			return names;
		}

		// Returns a vector of NamedPropCacheEntry for the input tags
		// Sourced directly from MAPI
		_Check_return_ std::vector<std::shared_ptr<namedPropCacheEntry>>
		GetNamesFromIDs(_In_ LPMAPIPROP lpMAPIProp, _In_ LPSPropTagArray* lppPropTags, ULONG ulFlags)
		{
			if (!lpMAPIProp) return {};

{'fraction_non_alphanumeric': 0.12507896399241947, 'fraction_numerical': 0.003790271636133923, 'mean_word_length': 3.90702479338843, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1864176', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1691, 'n_words': 377}