summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--architecture.cpp15
-rw-r--r--basicblock.cpp2
-rw-r--r--binaryninjaapi.h9
-rw-r--r--binaryninjacore.h43
-rw-r--r--binaryview.cpp4
-rw-r--r--function.cpp4
-rw-r--r--functiongraphblock.cpp2
-rw-r--r--lowlevelil.cpp8
-rw-r--r--type.cpp72
9 files changed, 139 insertions, 20 deletions
diff --git a/architecture.cpp b/architecture.cpp
index 3c7d9af8..e84b7f78 100644
--- a/architecture.cpp
+++ b/architecture.cpp
@@ -52,7 +52,14 @@ InstructionTextToken::InstructionTextToken(): type(TextToken), value(0)
InstructionTextToken::InstructionTextToken(BNInstructionTextTokenType t, const std::string& txt, uint64_t val,
- size_t s, size_t o) : type(t), text(txt), value(val), size(s), operand(o)
+ size_t s, size_t o) : type(t), text(txt), value(val), size(s), operand(o), context(NoTokenContext), address(0)
+{
+}
+
+
+InstructionTextToken::InstructionTextToken(BNInstructionTextTokenType t, BNInstructionTextTokenContext ctxt,
+ const string& txt, uint64_t a, uint64_t val, size_t s, size_t o):
+ type(t), text(txt), value(val), size(s), operand(o), context(ctxt), address(a)
{
}
@@ -153,6 +160,8 @@ bool Architecture::GetInstructionTextCallback(void* ctxt, const uint8_t* data, u
(*result)[i].value = tokens[i].value;
(*result)[i].size = tokens[i].size;
(*result)[i].operand = tokens[i].operand;
+ (*result)[i].context = tokens[i].context;
+ (*result)[i].address = tokens[i].address;
}
return true;
}
@@ -954,8 +963,8 @@ bool CoreArchitecture::GetInstructionText(const uint8_t* data, uint64_t addr, si
for (size_t i = 0; i < count; i++)
{
- result.push_back(InstructionTextToken(tokens[i].type, tokens[i].text, tokens[i].value,
- tokens[i].size, tokens[i].operand));
+ result.push_back(InstructionTextToken(tokens[i].type, tokens[i].context, tokens[i].text, tokens[i].address,
+ tokens[i].value, tokens[i].size, tokens[i].operand));
}
BNFreeInstructionText(tokens, count);
diff --git a/basicblock.cpp b/basicblock.cpp
index 93a279a1..4edcc568 100644
--- a/basicblock.cpp
+++ b/basicblock.cpp
@@ -164,6 +164,8 @@ vector<DisassemblyTextLine> BasicBlock::GetDisassemblyText(DisassemblySettings*
token.value = lines[i].tokens[j].value;
token.size = lines[i].tokens[j].size;
token.operand = lines[i].tokens[j].operand;
+ token.context = lines[i].tokens[j].context;
+ token.address = lines[i].tokens[j].address;
line.tokens.push_back(token);
}
result.push_back(line);
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 1d46bdc5..58f901ab 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -683,10 +683,15 @@ namespace BinaryNinja
std::string text;
uint64_t value;
size_t size, operand;
+ BNInstructionTextTokenContext context;
+ uint64_t address;
InstructionTextToken();
InstructionTextToken(BNInstructionTextTokenType type, const std::string& text, uint64_t value = 0,
size_t size = 0, size_t operand = BN_INVALID_OPERAND);
+ InstructionTextToken(BNInstructionTextTokenType type, BNInstructionTextTokenContext context,
+ const std::string& text, uint64_t address, uint64_t value = 0, size_t size = 0,
+ size_t operand = BN_INVALID_OPERAND);
};
struct DisassemblyTextLine
@@ -1538,6 +1543,10 @@ namespace BinaryNinja
std::string GetStringBeforeName() const;
std::string GetStringAfterName() const;
+ std::vector<InstructionTextToken> GetTokens() const;
+ std::vector<InstructionTextToken> GetTokensBeforeName() const;
+ std::vector<InstructionTextToken> GetTokensAfterName() const;
+
Ref<Type> Duplicate() const;
static Ref<Type> VoidType();
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 684fb534..b29a67a2 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -166,23 +166,17 @@ extern "C"
FloatingPointToken = 8,
AnnotationToken = 9,
CodeRelativeAddressToken = 10,
- StackVariableTypeToken = 11,
- DataVariableTypeToken = 12,
- FunctionReturnTypeToken = 13,
- FunctionAttributeToken = 14,
- ArgumentTypeToken = 15,
- ArgumentNameToken = 16,
- HexDumpByteValueToken = 17,
- HexDumpSkippedByteToken = 18,
- HexDumpInvalidByteToken = 19,
- HexDumpTextToken = 20,
- OpcodeToken = 21,
- StringToken = 22,
- CharacterConstantToken = 23,
- TypeDefinitionToken = 24,
- TypeDefinitionNameToken = 25,
- TypeDefinitionFieldToken = 26,
- TypeDefinitionFieldNameToken = 27,
+ ArgumentNameToken = 11,
+ HexDumpByteValueToken = 12,
+ HexDumpSkippedByteToken = 13,
+ HexDumpInvalidByteToken = 14,
+ HexDumpTextToken = 15,
+ OpcodeToken = 16,
+ StringToken = 17,
+ CharacterConstantToken = 18,
+ KeywordToken = 19,
+ TypeNameToken = 20,
+ FieldNameToken = 21,
// The following are output by the analysis system automatically, these should
// not be used directly by the architecture plugins
@@ -193,6 +187,15 @@ extern "C"
AddressDisplayToken = 68
};
+ enum BNInstructionTextTokenContext
+ {
+ NoTokenContext = 0,
+ StackVariableTokenContext = 1,
+ DataVariableTokenContext = 2,
+ FunctionReturnTokenContext = 3,
+ ArgumentTokenContext = 4
+ };
+
enum BNLinearDisassemblyLineType
{
BlankLineType,
@@ -714,6 +717,8 @@ extern "C"
char* text;
uint64_t value;
size_t size, operand;
+ BNInstructionTextTokenContext context;
+ uint64_t address;
};
struct BNInstructionTextLine
@@ -1969,6 +1974,10 @@ extern "C"
BINARYNINJACOREAPI char* BNGetTypeString(BNType* type);
BINARYNINJACOREAPI char* BNGetTypeStringBeforeName(BNType* type);
BINARYNINJACOREAPI char* BNGetTypeStringAfterName(BNType* type);
+ BINARYNINJACOREAPI BNInstructionTextToken* BNGetTypeTokens(BNType* type, size_t* count);
+ BINARYNINJACOREAPI BNInstructionTextToken* BNGetTypeTokensBeforeName(BNType* type, size_t* count);
+ BINARYNINJACOREAPI BNInstructionTextToken* BNGetTypeTokensAfterName(BNType* type, size_t* count);
+ BINARYNINJACOREAPI void BNFreeTokenList(BNInstructionTextToken* tokens, size_t count);
BINARYNINJACOREAPI BNType* BNCreateUnknownNamedType(BNUnknownType* ut);
BINARYNINJACOREAPI BNUnknownType* BNCreateUnknownType(void);
diff --git a/binaryview.cpp b/binaryview.cpp
index 16a270fc..154dfcf5 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1386,6 +1386,8 @@ vector<LinearDisassemblyLine> BinaryView::GetPreviousLinearDisassemblyLines(Line
token.value = lines[i].contents.tokens[j].value;
token.size = lines[i].contents.tokens[j].size;
token.operand = lines[i].contents.tokens[j].operand;
+ token.context = lines[i].contents.tokens[j].context;
+ token.address = lines[i].contents.tokens[j].address;
line.contents.tokens.push_back(token);
}
result.push_back(line);
@@ -1429,6 +1431,8 @@ vector<LinearDisassemblyLine> BinaryView::GetNextLinearDisassemblyLines(LinearDi
token.value = lines[i].contents.tokens[j].value;
token.size = lines[i].contents.tokens[j].size;
token.operand = lines[i].contents.tokens[j].operand;
+ token.context = lines[i].contents.tokens[j].context;
+ token.address = lines[i].contents.tokens[j].address;
line.contents.tokens.push_back(token);
}
result.push_back(line);
diff --git a/function.cpp b/function.cpp
index 109b6f49..b1d008ee 100644
--- a/function.cpp
+++ b/function.cpp
@@ -567,6 +567,10 @@ vector<vector<InstructionTextToken>> Function::GetBlockAnnotations(Architecture*
token.type = lines[i].tokens[j].type;
token.text = lines[i].tokens[j].text;
token.value = lines[i].tokens[j].value;
+ token.size = lines[i].tokens[j].size;
+ token.operand = lines[i].tokens[j].operand;
+ token.context = lines[i].tokens[j].context;
+ token.address = lines[i].tokens[j].address;
line.push_back(token);
}
result.push_back(line);
diff --git a/functiongraphblock.cpp b/functiongraphblock.cpp
index 47261453..db69c25a 100644
--- a/functiongraphblock.cpp
+++ b/functiongraphblock.cpp
@@ -101,6 +101,8 @@ const vector<DisassemblyTextLine>& FunctionGraphBlock::GetLines()
token.value = lines[i].tokens[j].value;
token.size = lines[i].tokens[j].size;
token.operand = lines[i].tokens[j].operand;
+ token.context = lines[i].tokens[j].context;
+ token.address = lines[i].tokens[j].address;
line.tokens.push_back(token);
}
result.push_back(line);
diff --git a/lowlevelil.cpp b/lowlevelil.cpp
index a312bbd6..bf3b980e 100644
--- a/lowlevelil.cpp
+++ b/lowlevelil.cpp
@@ -579,6 +579,10 @@ bool LowLevelILFunction::GetExprText(Architecture* arch, ExprId expr, vector<Ins
token.type = list[i].type;
token.text = list[i].text;
token.value = list[i].value;
+ token.size = list[i].size;
+ token.operand = list[i].operand;
+ token.context = list[i].context;
+ token.address = list[i].address;
tokens.push_back(token);
}
@@ -603,6 +607,10 @@ bool LowLevelILFunction::GetInstructionText(Function* func, Architecture* arch,
token.type = list[i].type;
token.text = list[i].text;
token.value = list[i].value;
+ token.size = list[i].size;
+ token.operand = list[i].operand;
+ token.context = list[i].context;
+ token.address = list[i].address;
tokens.push_back(token);
}
diff --git a/type.cpp b/type.cpp
index 7cc2757a..c8cfdc33 100644
--- a/type.cpp
+++ b/type.cpp
@@ -199,6 +199,78 @@ string Type::GetStringAfterName() const
}
+vector<InstructionTextToken> Type::GetTokens() const
+{
+ size_t count;
+ BNInstructionTextToken* tokens = BNGetTypeTokens(m_object, &count);
+
+ vector<InstructionTextToken> result;
+ for (size_t i = 0; i < count; i++)
+ {
+ InstructionTextToken token;
+ token.type = tokens[i].type;
+ token.text = tokens[i].text;
+ token.value = tokens[i].value;
+ token.size = tokens[i].size;
+ token.operand = tokens[i].operand;
+ token.context = tokens[i].context;
+ token.address = tokens[i].address;
+ result.push_back(token);
+ }
+
+ BNFreeTokenList(tokens, count);
+ return result;
+}
+
+
+vector<InstructionTextToken> Type::GetTokensBeforeName() const
+{
+ size_t count;
+ BNInstructionTextToken* tokens = BNGetTypeTokensBeforeName(m_object, &count);
+
+ vector<InstructionTextToken> result;
+ for (size_t i = 0; i < count; i++)
+ {
+ InstructionTextToken token;
+ token.type = tokens[i].type;
+ token.text = tokens[i].text;
+ token.value = tokens[i].value;
+ token.size = tokens[i].size;
+ token.operand = tokens[i].operand;
+ token.context = tokens[i].context;
+ token.address = tokens[i].address;
+ result.push_back(token);
+ }
+
+ BNFreeTokenList(tokens, count);
+ return result;
+}
+
+
+vector<InstructionTextToken> Type::GetTokensAfterName() const
+{
+ size_t count;
+ BNInstructionTextToken* tokens = BNGetTypeTokensAfterName(m_object, &count);
+
+ vector<InstructionTextToken> result;
+ for (size_t i = 0; i < count; i++)
+ {
+ InstructionTextToken token;
+ token.type = tokens[i].type;
+ token.text = tokens[i].text;
+ token.value = tokens[i].value;
+ token.size = tokens[i].size;
+ token.operand = tokens[i].operand;
+ token.context = tokens[i].context;
+ token.address = tokens[i].address;
+ result.push_back(token);
+ }
+
+ BNFreeTokenList(tokens, count);
+ return result;
+}
+
+
Ref<Type> Type::Duplicate() const
{
return new Type(BNDuplicateType(m_object));