diff options
| author | Peter LaFosse <peter@vector35.com> | 2017-03-05 13:12:01 -0500 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2017-03-05 13:12:01 -0500 |
| commit | cf5997848b8819725315bd2c8dd8a04c70da3b63 (patch) | |
| tree | 24d9360e3ccfaee361aca4d345072c142c386a41 /binaryview.cpp | |
| parent | a0132eed82d28d4408a2475847e1804a157b3dc1 (diff) | |
| parent | 27f1271083efb09efc6405f91be893ab38dad9a0 (diff) | |
Merginging with dev
Diffstat (limited to 'binaryview.cpp')
| -rw-r--r-- | binaryview.cpp | 135 |
1 files changed, 114 insertions, 21 deletions
diff --git a/binaryview.cpp b/binaryview.cpp index cc6667c5..8edbc2bf 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -129,6 +129,24 @@ void BinaryDataNotification::StringRemovedCallback(void* ctxt, BNBinaryView* obj } +void BinaryDataNotification::TypeDefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type) +{ + BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; + Ref<BinaryView> view = new BinaryView(BNNewViewReference(data)); + Ref<Type> typeObj = new Type(BNNewTypeReference(type)); + notify->OnTypeDefined(view, QualifiedName::FromAPIObject(name), typeObj); +} + + +void BinaryDataNotification::TypeUndefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type) +{ + BinaryDataNotification* notify = (BinaryDataNotification*)ctxt; + Ref<BinaryView> view = new BinaryView(BNNewViewReference(data)); + Ref<Type> typeObj = new Type(BNNewTypeReference(type)); + notify->OnTypeUndefined(view, QualifiedName::FromAPIObject(name), typeObj); +} + + BinaryDataNotification::BinaryDataNotification() { m_callbacks.context = this; @@ -143,6 +161,8 @@ BinaryDataNotification::BinaryDataNotification() m_callbacks.dataVariableUpdated = DataVariableUpdatedCallback; m_callbacks.stringFound = StringFoundCallback; m_callbacks.stringRemoved = StringRemovedCallback; + m_callbacks.typeDefined = TypeDefinedCallback; + m_callbacks.typeUndefined = TypeUndefinedCallback; } @@ -1366,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); @@ -1409,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); @@ -1423,9 +1447,9 @@ vector<LinearDisassemblyLine> BinaryView::GetNextLinearDisassemblyLines(LinearDi } -bool BinaryView::ParseTypeString(const string& text, NameAndType& result, string& errors) +bool BinaryView::ParseTypeString(const string& text, QualifiedNameAndType& result, string& errors) { - BNNameAndType nt; + BNQualifiedNameAndType nt; char* errorStr; if (!BNParseTypeString(m_object, text.c_str(), &nt, &errorStr)) @@ -1435,64 +1459,127 @@ bool BinaryView::ParseTypeString(const string& text, NameAndType& result, string return false; } - result.name = nt.name; - result.type = new Type(nt.type); + result.name = QualifiedName::FromAPIObject(&nt.name); + result.type = new Type(BNNewTypeReference(nt.type)); errors = ""; - BNFreeString(nt.name); + BNFreeQualifiedNameAndType(&nt); return true; } -map<string, Ref<Type>> BinaryView::GetTypes() +map<QualifiedName, Ref<Type>> BinaryView::GetTypes() { size_t count; - BNNameAndType* types = BNGetAnalysisTypeList(m_object, &count); + BNQualifiedNameAndType* types = BNGetAnalysisTypeList(m_object, &count); - map<string, Ref<Type>> result; + map<QualifiedName, Ref<Type>> result; for (size_t i = 0; i < count; i++) - result[types[i].name] = new Type(BNNewTypeReference(types[i].type)); + { + QualifiedName name = QualifiedName::FromAPIObject(&types[i].name); + result[name] = new Type(BNNewTypeReference(types[i].type)); + } BNFreeTypeList(types, count); return result; } -Ref<Type> BinaryView::GetTypeByName(const string& name) +Ref<Type> BinaryView::GetTypeByName(const QualifiedName& name) { - BNType* type = BNGetAnalysisTypeByName(m_object, name.c_str()); + BNQualifiedName nameObj = name.GetAPIObject(); + BNType* type = BNGetAnalysisTypeByName(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); + if (!type) return nullptr; return new Type(type); } -bool BinaryView::IsTypeAutoDefined(const std::string& name) +Ref<Type> BinaryView::GetTypeById(const string& id) +{ + BNType* type = BNGetAnalysisTypeById(m_object, id.c_str()); + if (!type) + return nullptr; + return new Type(type); +} + + +QualifiedName BinaryView::GetTypeNameById(const string& id) +{ + BNQualifiedName name = BNGetAnalysisTypeNameById(m_object, id.c_str()); + QualifiedName result = QualifiedName::FromAPIObject(&name); + BNFreeQualifiedName(&name); + return result; +} + + +string BinaryView::GetTypeId(const QualifiedName& name) +{ + BNQualifiedName nameObj = name.GetAPIObject(); + char* id = BNGetAnalysisTypeId(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); + string result = id; + BNFreeString(id); + return result; +} + + +bool BinaryView::IsTypeAutoDefined(const QualifiedName& name) +{ + BNQualifiedName nameObj = name.GetAPIObject(); + bool result = BNIsAnalysisTypeAutoDefined(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); + return result; +} + + +QualifiedName BinaryView::DefineType(const string& id, const QualifiedName& defaultName, Ref<Type> type) { - return BNIsAnalysisTypeAutoDefined(m_object, name.c_str()); + BNQualifiedName nameObj = defaultName.GetAPIObject(); + BNQualifiedName regName = BNDefineAnalysisType(m_object, id.c_str(), &nameObj, type->GetObject()); + QualifiedName::FreeAPIObject(&nameObj); + QualifiedName result = QualifiedName::FromAPIObject(®Name); + BNFreeQualifiedName(®Name); + return result; } -void BinaryView::DefineType(const std::string& name, Ref<Type> type) +void BinaryView::DefineUserType(const QualifiedName& name, Ref<Type> type) { - BNDefineAnalysisType(m_object, name.c_str(), type->GetObject()); + BNQualifiedName nameObj = name.GetAPIObject(); + BNDefineUserAnalysisType(m_object, &nameObj, type->GetObject()); + QualifiedName::FreeAPIObject(&nameObj); } -void BinaryView::DefineUserType(const std::string& name, Ref<Type> type) +void BinaryView::UndefineType(const string& id) { - BNDefineUserAnalysisType(m_object, name.c_str(), type->GetObject()); + BNUndefineAnalysisType(m_object, id.c_str()); } -void BinaryView::UndefineType(const std::string& name) +void BinaryView::UndefineUserType(const QualifiedName& name) { - BNUndefineAnalysisType(m_object, name.c_str()); + BNQualifiedName nameObj = name.GetAPIObject(); + BNUndefineUserAnalysisType(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); } -void BinaryView::UndefineUserType(const std::string& name) +void BinaryView::RenameType(const QualifiedName& oldName, const QualifiedName& newName) { - BNUndefineUserAnalysisType(m_object, name.c_str()); + BNQualifiedName oldNameObj = oldName.GetAPIObject(); + BNQualifiedName newNameObj = newName.GetAPIObject(); + BNRenameAnalysisType(m_object, &oldNameObj, &newNameObj); + QualifiedName::FreeAPIObject(&oldNameObj); + QualifiedName::FreeAPIObject(&newNameObj); +} + + +void BinaryView::RegisterPlatformTypes(Platform* platform) +{ + BNRegisterPlatformTypes(m_object, platform->GetObject()); } @@ -1604,6 +1691,12 @@ bool BinaryView::GetSegmentAt(uint64_t addr, Segment& result) } +bool BinaryView::GetAddressForDataOffset(uint64_t offset, uint64_t& addr) +{ + return BNGetAddressForDataOffset(m_object, offset, &addr); +} + + void BinaryView::AddAutoSection(const string& name, uint64_t start, uint64_t length, const string& type, uint64_t align, uint64_t entrySize, const string& linkedSection, const string& infoSection, uint64_t infoData) { |
