Skip to content

Commit 8acfb02

Browse files
committed
misc: formated code and fixed several small issues
1. Fix code related to SMI handlers 2. also parse handlers registered by SxDispatch and parse them together 3. Set Progress Text properly
1 parent e6dc40a commit 8acfb02

13 files changed

+1567
-1428
lines changed

platform/efi/efi_resolver/include/DxeResolver.h

+16-15
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
#include "Resolver.h"
44

5-
class DxeResolver : Resolver {
6-
bool resolveBootServices();
7-
bool resolveRuntimeServices();
5+
class DxeResolver : Resolver
6+
{
7+
bool resolveBootServices();
8+
bool resolveRuntimeServices();
89

9-
bool resolveSmmTables(string serviceName, string tableName);
10-
bool resolveSmmServices();
11-
bool resolveSmiHandlers();
10+
bool resolveSmmTables(string serviceName, string tableName);
11+
bool resolveSmmServices();
12+
bool resolveSmiHandlers();
1213

1314
public:
14-
/*!
15-
resolve BootServices and RuntimeServices, define protocol types that loaded by BootServices
16-
*/
17-
bool resolveDxe();
15+
/*!
16+
resolve BootServices and RuntimeServices, define protocol types that loaded by BootServices
17+
*/
18+
bool resolveDxe();
1819

19-
/*!
20-
Define MMST/SMMST and resolve SMM related protocols
21-
*/
22-
bool resolveSmm();
20+
/*!
21+
Define MMST/SMMST and resolve SMM related protocols
22+
*/
23+
bool resolveSmm();
2324

24-
DxeResolver(Ref<BinaryView> view, Ref<BackgroundTask> task);
25+
DxeResolver(Ref<BinaryView> view, Ref<BackgroundTask> task);
2526
};

platform/efi/efi_resolver/include/GuidRenderer.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
using namespace BinaryNinja;
77
using namespace std;
88

9-
class EfiGuidRenderer : public BinaryNinja::DataRenderer {
10-
EfiGuidRenderer() = default;
9+
class EfiGuidRenderer : public BinaryNinja::DataRenderer
10+
{
11+
EfiGuidRenderer() = default;
1112

1213
public:
13-
bool IsValidForData(BinaryView*, uint64_t address, Type*,
14-
vector<pair<Type*, size_t>>&) override;
14+
bool IsValidForData(BinaryView*, uint64_t address, Type*, vector<pair<Type*, size_t>>&) override;
1515

16-
vector<DisassemblyTextLine> GetLinesForData(
17-
BinaryView*, uint64_t address, Type*, const vector<InstructionTextToken>& prefix,
18-
size_t width, vector<pair<Type*, size_t>>&) override;
16+
vector<DisassemblyTextLine> GetLinesForData(BinaryView*, uint64_t address, Type*,
17+
const vector<InstructionTextToken>& prefix, size_t width, vector<pair<Type*, size_t>>&) override;
1918

20-
static void Register();
19+
static void Register();
2120
};

platform/efi/efi_resolver/include/ModuleType.h

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44

55
using namespace BinaryNinja;
66

7-
enum EFIModuleType {
8-
UNKNOWN,
9-
PEI,
10-
DXE,
7+
enum EFIModuleType
8+
{
9+
UNKNOWN,
10+
PEI,
11+
DXE,
1112
};
1213

1314
static inline EFIModuleType identifyModuleType(BinaryView* bv)
1415
{
15-
std::string viewType = bv->GetCurrentView();
16-
if (viewType == "Linear:PE")
17-
return DXE;
18-
else if (viewType == "Linear:TE")
19-
return PEI;
20-
else
21-
return UNKNOWN;
16+
std::string viewType = bv->GetCurrentView();
17+
if (viewType == "Linear:PE")
18+
return DXE;
19+
else if (viewType == "Linear:TE")
20+
return PEI;
21+
else
22+
return UNKNOWN;
2223
}

platform/efi/efi_resolver/include/PeiResolver.h

+14-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
#include "Resolver.h"
44

5-
class PeiResolver : Resolver {
6-
bool resolvePeiIdt();
7-
bool resolvePeiMrc();
8-
bool resolvePeiMrs();
9-
bool resolvePlatformPointers();
10-
bool resolvePeiDescriptors();
11-
bool resolvePeiServices();
5+
class PeiResolver : Resolver
6+
{
7+
bool resolvePeiIdt();
8+
bool resolvePeiMrc();
9+
bool resolvePeiMrs();
10+
bool resolvePlatformPointers();
11+
bool resolvePeiDescriptors();
12+
bool resolvePeiServices();
1213

1314
public:
14-
/*!
15-
resolve Pei related types and PPIs, this function will also resolve processor-specific pointers
16-
and tried to define the EFI_PEI_DESCRIPTORS
17-
*/
18-
bool resolvePei();
19-
PeiResolver(Ref<BinaryView> view, Ref<BackgroundTask> task);
15+
/*!
16+
resolve Pei related types and PPIs, this function will also resolve processor-specific pointers
17+
and tried to define the EFI_PEI_DESCRIPTORS
18+
*/
19+
bool resolvePei();
20+
PeiResolver(Ref<BinaryView> view, Ref<BackgroundTask> task);
2021
};

platform/efi/efi_resolver/include/Resolver.h

+46-47
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,60 @@ using namespace std;
1616

1717
typedef array<uint8_t, 16> EFI_GUID;
1818

19-
class Resolver {
19+
class Resolver
20+
{
2021
protected:
21-
Ref<BinaryView> m_view;
22-
Ref<BackgroundTask> m_task;
23-
size_t m_width;
24-
map<EFI_GUID, pair<string, string>> m_protocol;
25-
map<EFI_GUID, string> m_user_guids;
22+
Ref<BinaryView> m_view;
23+
Ref<BackgroundTask> m_task;
24+
size_t m_width;
25+
map<EFI_GUID, pair<string, string>> m_protocol;
26+
map<EFI_GUID, string> m_user_guids;
2627

27-
vector<pair<uint64_t, string>> m_service_usages;
28-
vector<pair<uint64_t, string>> m_protocol_usages;
29-
vector<pair<uint64_t, EFI_GUID>> m_guid_usages;
30-
vector<pair<uint64_t, string>> m_variable_usages;
28+
vector<pair<uint64_t, string>> m_service_usages;
29+
vector<pair<uint64_t, string>> m_protocol_usages;
30+
vector<pair<uint64_t, EFI_GUID>> m_guid_usages;
31+
vector<pair<uint64_t, string>> m_variable_usages;
3132

32-
bool parseUserGuidIfExists(const string& filePath);
33-
bool parseProtocolMapping(const string& filePath);
33+
bool parseUserGuidIfExists(const string& filePath);
34+
bool parseProtocolMapping(const string& filePath);
3435

35-
/*!
36-
For backward compatibility, if a user saved a bndb with older version Binary Ninja
37-
this function will try to retrieve types from Platform Types if it doesn't find one
38-
in BinaryView
39-
*/
40-
Ref<Type> GetTypeFromViewAndPlatform(string type_name);
41-
void initProtocolMapping();
36+
/*!
37+
For backward compatibility, if a user saved a bndb with older version Binary Ninja
38+
this function will try to retrieve types from Platform Types if it doesn't find one
39+
in BinaryView
40+
*/
41+
Ref<Type> GetTypeFromViewAndPlatform(string type_name);
42+
void initProtocolMapping();
4243

4344
public:
44-
bool setModuleEntry(EFIModuleType fileType);
45-
bool resolveGuidInterface(Ref<Function> func, uint64_t addr, int guid_pos, int interface_pos);
46-
Resolver(Ref<BinaryView> view, Ref<BackgroundTask> task);
45+
bool setModuleEntry(EFIModuleType fileType);
46+
bool resolveGuidInterface(Ref<Function> func, uint64_t addr, int guid_pos, int interface_pos);
47+
Resolver(Ref<BinaryView> view, Ref<BackgroundTask> task);
4748

48-
pair<string, string> lookupGuid(EFI_GUID guidBytes);
49-
pair<string, string> defineAndLookupGuid(uint64_t addr);
49+
pair<string, string> lookupGuid(EFI_GUID guidBytes);
50+
pair<string, string> defineAndLookupGuid(uint64_t addr);
5051

51-
string nonConflictingName(const string& basename);
52-
static string nonConflictingLocalName(Ref<Function> func, const string& basename);
52+
string nonConflictingName(const string& basename);
53+
static string nonConflictingLocalName(Ref<Function> func, const string& basename);
5354

54-
/*!
55-
Define the structure used at the callsite with type `typeName`, propagate it to the data section. If it's a structure type, define it fields
56-
according to the `followFields` parameter. The input `addr` should be a call instruction
57-
\param func the function that contains the callsite (it's parent function)
58-
\param addr address of the callsite
59-
\param typeName the type that need to define
60-
\param paramIdx the parameter index that want to define
61-
\param followFields whether to define the structure's fields if they are pointers
62-
\return False if failed
55+
/*!
56+
Define the structure used at the callsite with type `typeName`, propagate it to the data section. If it's a
57+
structure type, define it fields according to the `followFields` parameter. The input `addr` should be a call
58+
instruction \param func the function that contains the callsite (it's parent function) \param addr address of the
59+
callsite \param typeName the type that need to define \param paramIdx the parameter index that want to define \param
60+
followFields whether to define the structure's fields if they are pointers \return False if failed
6361
64-
\b Example:
65-
\code{.cpp}
66-
refs = bv->GetCodeReferencesForType(QualifiedName("EFI_GET_VARIABLE"));
67-
for (auto ref : refs)
68-
{
69-
// ... some checking, need to make sure is a call instruction
70-
bool ok = defineTypeAtCallsite(ref.func, ref.addr, "EFI_GUID", 2, false);
71-
}
72-
\endcode
73-
*/
74-
bool defineTypeAtCallsite(Ref<Function> func, uint64_t addr, string typeName, int paramIdx, bool followFields = false);
75-
vector<HighLevelILInstruction> HighLevelILExprsAt(Ref<Function> func, Ref<Architecture> arch, uint64_t addr);
62+
\b Example:
63+
\code{.cpp}
64+
refs = bv->GetCodeReferencesForType(QualifiedName("EFI_GET_VARIABLE"));
65+
for (auto ref : refs)
66+
{
67+
// ... some checking, need to make sure is a call instruction
68+
bool ok = defineTypeAtCallsite(ref.func, ref.addr, "EFI_GUID", 2, false);
69+
}
70+
\endcode
71+
*/
72+
bool defineTypeAtCallsite(
73+
Ref<Function> func, uint64_t addr, string typeName, int paramIdx, bool followFields = false);
74+
vector<HighLevelILInstruction> HighLevelILExprsAt(Ref<Function> func, Ref<Architecture> arch, uint64_t addr);
7675
};

platform/efi/efi_resolver/include/TypePropagation.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
using namespace BinaryNinja;
77

8-
class TypePropagation {
9-
Ref<BinaryView> m_view;
10-
std::deque<uint64_t> m_queue;
11-
Ref<Platform> m_platform;
8+
class TypePropagation
9+
{
10+
Ref<BinaryView> m_view;
11+
std::deque<uint64_t> m_queue;
12+
Ref<Platform> m_platform;
1213

1314
public:
14-
TypePropagation(BinaryView* view);
15-
bool propagateFuncParamTypes(Function* func);
16-
bool propagateFuncParamTypes(Function* func, SSAVariable ssa_var);
15+
TypePropagation(BinaryView* view);
16+
bool propagateFuncParamTypes(Function* func);
17+
bool propagateFuncParamTypes(Function* func, SSAVariable ssa_var);
1718
};

platform/efi/efi_resolver/include/Utils.h

+25-21
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@ using namespace BinaryNinja;
66

77
static inline std::string GetOriginalTypeName(Ref<Type> type)
88
{
9-
std::string result;
10-
if (type->IsPointer()) {
11-
if (type->GetChildType().GetValue()->IsNamedTypeRefer()) {
12-
return type->GetChildType().GetValue()->GetNamedTypeReference()->GetName().GetString();
13-
}
14-
return type->GetTypeName().GetString();
15-
}
16-
if (type->IsNamedTypeRefer())
17-
return type->GetNamedTypeReference()->GetName().GetString();
9+
std::string result;
10+
if (type->IsPointer())
11+
{
12+
if (type->GetChildType().GetValue()->IsNamedTypeRefer())
13+
{
14+
return type->GetChildType().GetValue()->GetNamedTypeReference()->GetName().GetString();
15+
}
16+
return type->GetTypeName().GetString();
17+
}
18+
if (type->IsNamedTypeRefer())
19+
return type->GetNamedTypeReference()->GetName().GetString();
1820

19-
return type->GetTypeName().GetString();
21+
return type->GetTypeName().GetString();
2022
}
2123

2224
static inline std::string GetVarNameForTypeStr(const std::string typeStr)
2325
{
24-
std::istringstream iss(typeStr);
25-
std::string word;
26-
std::string result;
26+
std::istringstream iss(typeStr);
27+
std::string word;
28+
std::string result;
2729

28-
while (std::getline(iss, word, '_')) {
29-
if (!word.empty()) {
30-
word[0] = std::toupper(word[0]);
31-
std::transform(word.begin() + 1, word.end(), word.begin() + 1, ::tolower);
32-
result += word;
33-
}
34-
}
35-
return result;
30+
while (std::getline(iss, word, '_'))
31+
{
32+
if (!word.empty())
33+
{
34+
word[0] = std::toupper(word[0]);
35+
std::transform(word.begin() + 1, word.end(), word.begin() + 1, ::tolower);
36+
result += word;
37+
}
38+
}
39+
return result;
3640
}

0 commit comments

Comments
 (0)