Skip to content

Commit 2a91e60

Browse files
committed
Make Warp function type optional in the C++ bindings
1 parent fb719eb commit 2a91e60

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

plugins/warp/api/warp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,16 @@ FunctionGUID Function::GetGUID() const
6868
BinaryNinja::Ref<BinaryNinja::Symbol> Function::GetSymbol(const BinaryNinja::Function &function) const
6969
{
7070
BNSymbol *symbol = BNWARPFunctionGetSymbol(m_object, function.m_object);
71+
if (!symbol)
72+
return nullptr;
7173
return new BinaryNinja::Symbol(symbol);
7274
}
7375

7476
BinaryNinja::Ref<BinaryNinja::Type> Function::GetType(const BinaryNinja::Function &function) const
7577
{
7678
BNType *type = BNWARPFunctionGetType(m_object, function.m_object);
79+
if (!type)
80+
return nullptr;
7781
return new BinaryNinja::Type(type);
7882
}
7983

plugins/warp/ui/shared/function.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,32 @@ WarpFunctionItem::WarpFunctionItem(Warp::Ref<Warp::Function> function,
1818
BinaryNinja::Ref<BinaryNinja::Symbol> symbol = m_function->GetSymbol(*analysisFunction);
1919
std::string symbolName = symbol->GetShortName();
2020
setText(QString::fromStdString(symbolName));
21-
22-
// TODO: This needs to be better. Type can be nullptr.
23-
BinaryNinja::Ref<BinaryNinja::Type> type = m_function->GetType(*analysisFunction);
24-
BinaryNinja::Ref<BinaryNinja::Platform> platform = analysisFunction->GetPlatform();
25-
std::vector<BinaryNinja::InstructionTextToken> beforeTokens = type->GetTokensBeforeName(platform);
26-
std::vector<BinaryNinja::InstructionTextToken> afterTokens = type->GetTokensAfterName(platform);
2721
BinaryNinja::InstructionTextToken nameToken = {255, TextToken, symbolName};
2822

2923
// Serialize the tokens to make it accessible via QModelIndex.
3024
// We will take these tokens and then user them in our custom item delegate.
3125
TokenData tokenData = {};
32-
for (const auto &token: beforeTokens)
33-
tokenData.tokens.emplace_back(token);
34-
tokenData.tokens.emplace_back(255, TextToken, " ");
35-
tokenData.tokens.emplace_back(nameToken);
36-
for (const auto &token: afterTokens)
37-
tokenData.tokens.emplace_back(token);
26+
27+
// TODO: Make this not look like garbage
28+
BinaryNinja::Ref<BinaryNinja::Type> type = m_function->GetType(*analysisFunction);
29+
if (type)
30+
{
31+
BinaryNinja::Ref<BinaryNinja::Platform> platform = analysisFunction->GetPlatform();
32+
std::vector<BinaryNinja::InstructionTextToken> beforeTokens = type->GetTokensBeforeName(platform);
33+
std::vector<BinaryNinja::InstructionTextToken> afterTokens = type->GetTokensAfterName(platform);
34+
35+
for (const auto &token: beforeTokens)
36+
tokenData.tokens.emplace_back(token);
37+
tokenData.tokens.emplace_back(255, TextToken, " ");
38+
tokenData.tokens.emplace_back(nameToken);
39+
for (const auto &token: afterTokens)
40+
tokenData.tokens.emplace_back(token);
41+
}
42+
else
43+
{
44+
tokenData.tokens.emplace_back(nameToken);
45+
}
46+
3847
setData(QVariant::fromValue(tokenData), Qt::UserRole);
3948
}
4049

0 commit comments

Comments
 (0)