summaryrefslogtreecommitdiff
path: root/plugins/efi_resolver/include/Utils.h
blob: 981908b285073b71a3f93060e81f50aa3891aff5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once

#include "binaryninjaapi.h"

using namespace BinaryNinja;

static inline std::string GetOriginalTypeName(Ref<Type> type)
{
	std::string result;
	if (type->IsPointer())
	{
		if (type->GetChildType().GetValue()->IsNamedTypeRefer())
		{
			return type->GetChildType().GetValue()->GetNamedTypeReference()->GetName().GetString();
		}
		return type->GetTypeName().GetString();
	}
	if (type->IsNamedTypeRefer())
		return type->GetNamedTypeReference()->GetName().GetString();

	return type->GetTypeName().GetString();
}

static inline std::string GetVarNameForTypeStr(const std::string typeStr)
{
	std::istringstream iss(typeStr);
	std::string word;
	std::string result;

	while (std::getline(iss, word, '_'))
	{
		if (!word.empty())
		{
			word[0] = std::toupper(word[0]);
			std::transform(word.begin() + 1, word.end(), word.begin() + 1, ::tolower);
			result += word;
		}
	}
	return result;
}