Skip to content

Commit cf59978

Browse files
committed
Merginging with dev
2 parents a0132ee + 27f1271 commit cf59978

39 files changed

+2450
-489
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ api-docs/build/*
2020
.env
2121
api-docs/source/binaryninja.*
2222
*.pyc
23+
api-docs/source/python.rst
24+
api-docs/source/index.rst

api-docs/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SPHINXOPTS =
66
SPHINXBUILD = sphinx-build
77
PAPER =
88
BUILDDIR = build
9+
SOURCEDIR = source
910

1011
# Internal variables.
1112
PAPEROPT_a4 = -D latex_paper_size=a4
@@ -47,6 +48,8 @@ help:
4748
.PHONY: clean
4849
clean:
4950
rm -rf $(BUILDDIR)/*
51+
rm $(SOURCEDIR)/binaryninja.*.rst
52+
rm $(SOURCEDIR)/python.rst
5053

5154
.PHONY: html
5255
html:

api-docs/source/conf.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
def modulelist(modulename):
3333
modules = inspect.getmembers(modulename, inspect.ismodule)
34-
return filter(lambda x: x[0] not in ("abc", "ctypes", "core", "struct", "sys", "_binaryninjacore", "traceback", "code", "enum", "json", "threading"), modules)
34+
return filter(lambda x: x[0] not in ("abc", "ctypes", "core", "struct", "sys", "_binaryninjacore", "traceback", "code", "enum", "json", "threading", "startup", "associateddatastore"), modules)
3535

3636

3737
def classlist(module):
@@ -43,7 +43,7 @@ def classlist(module):
4343

4444

4545
def generaterst():
46-
pythonrst = open("python.rst", "w")
46+
pythonrst = open("index.rst", "w")
4747
pythonrst.write('''Binary Ninja Python API Documentation
4848
=====================================
4949
@@ -53,7 +53,7 @@ def generaterst():
5353
''')
5454

5555
for modulename, module in modulelist(binaryninja):
56-
filename = 'binaryninja.{module}.rst'.format(module=modulename)
56+
filename = 'binaryninja.{module}-module.rst'.format(module=modulename)
5757
pythonrst.write(' {module} <{filename}>\n'.format(module=modulename, filename=filename))
5858
modulefile = open(filename, "w")
5959
modulefile.write('''{module} module
@@ -69,6 +69,11 @@ def generaterst():
6969

7070
modulefile.write('''\n.. toctree::
7171
:maxdepth: 2\n''')
72+
73+
modulefile.write('''\n\n.. automodule:: binaryninja.{module}
74+
:members:
75+
:undoc-members:
76+
:show-inheritance:'''.format(module=modulename))
7277
modulefile.close()
7378

7479
pythonrst.write('''.. automodule:: binaryninja
@@ -125,7 +130,7 @@ def generaterst():
125130
# source_encoding = 'utf-8-sig'
126131

127132
# The master toctree document.
128-
master_doc = 'python'
133+
master_doc = 'index'
129134

130135
# General information about the project.
131136
project = u'Binary Ninja API'
File renamed without changes.

api-docs/source/python.rst

Lines changed: 0 additions & 73 deletions
This file was deleted.

architecture.cpp

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ InstructionTextToken::InstructionTextToken(): type(TextToken), value(0)
5252

5353

5454
InstructionTextToken::InstructionTextToken(BNInstructionTextTokenType t, const std::string& txt, uint64_t val,
55-
size_t s, size_t o) : type(t), text(txt), value(val), size(s), operand(o)
55+
size_t s, size_t o) : type(t), text(txt), value(val), size(s), operand(o), context(NoTokenContext), address(0)
56+
{
57+
}
58+
59+
60+
InstructionTextToken::InstructionTextToken(BNInstructionTextTokenType t, BNInstructionTextTokenContext ctxt,
61+
const string& txt, uint64_t a, uint64_t val, size_t s, size_t o):
62+
type(t), text(txt), value(val), size(s), operand(o), context(ctxt), address(a)
5663
{
5764
}
5865

@@ -153,6 +160,8 @@ bool Architecture::GetInstructionTextCallback(void* ctxt, const uint8_t* data, u
153160
(*result)[i].value = tokens[i].value;
154161
(*result)[i].size = tokens[i].size;
155162
(*result)[i].operand = tokens[i].operand;
163+
(*result)[i].context = tokens[i].context;
164+
(*result)[i].address = tokens[i].address;
156165
}
157166
return true;
158167
}
@@ -737,9 +746,9 @@ void Architecture::SetBinaryViewTypeConstant(const string& type, const string& n
737746

738747

739748
bool Architecture::ParseTypesFromSource(const string& source, const string& fileName,
740-
map<string, Ref<Type>>& types, map<string, Ref<Type>>& variables,
741-
map<string, Ref<Type>>& functions, string& errors,
742-
const vector<string>& includeDirs)
749+
map<QualifiedName, Ref<Type>>& types, map<QualifiedName, Ref<Type>>& variables,
750+
map<QualifiedName, Ref<Type>>& functions, string& errors, const vector<string>& includeDirs,
751+
const string& autoTypeSource)
743752
{
744753
BNTypeParserResult result;
745754
char* errorStr;
@@ -753,26 +762,35 @@ bool Architecture::ParseTypesFromSource(const string& source, const string& file
753762
functions.clear();
754763

755764
bool ok = BNParseTypesFromSource(m_object, source.c_str(), fileName.c_str(), &result,
756-
&errorStr, includeDirList, includeDirs.size());
765+
&errorStr, includeDirList, includeDirs.size(), autoTypeSource.c_str());
757766
errors = errorStr;
758767
BNFreeString(errorStr);
759768
if (!ok)
760769
return false;
761770

762771
for (size_t i = 0; i < result.typeCount; i++)
763-
types[result.types[i].name] = new Type(BNNewTypeReference(result.types[i].type));
772+
{
773+
QualifiedName name = QualifiedName::FromAPIObject(&result.types[i].name);
774+
types[name] = new Type(BNNewTypeReference(result.types[i].type));
775+
}
764776
for (size_t i = 0; i < result.variableCount; i++)
765-
types[result.variables[i].name] = new Type(BNNewTypeReference(result.variables[i].type));
777+
{
778+
QualifiedName name = QualifiedName::FromAPIObject(&result.variables[i].name);
779+
types[name] = new Type(BNNewTypeReference(result.variables[i].type));
780+
}
766781
for (size_t i = 0; i < result.functionCount; i++)
767-
types[result.functions[i].name] = new Type(BNNewTypeReference(result.functions[i].type));
782+
{
783+
QualifiedName name = QualifiedName::FromAPIObject(&result.functions[i].name);
784+
types[name] = new Type(BNNewTypeReference(result.functions[i].type));
785+
}
768786
BNFreeTypeParserResult(&result);
769787
return true;
770788
}
771789

772790

773-
bool Architecture::ParseTypesFromSourceFile(const string& fileName, map<string, Ref<Type>>& types,
774-
map<string, Ref<Type>>& variables, map<string, Ref<Type>>& functions,
775-
string& errors, const vector<string>& includeDirs)
791+
bool Architecture::ParseTypesFromSourceFile(const string& fileName, map<QualifiedName, Ref<Type>>& types,
792+
map<QualifiedName, Ref<Type>>& variables, map<QualifiedName, Ref<Type>>& functions,
793+
string& errors, const vector<string>& includeDirs, const string& autoTypeSource)
776794
{
777795
BNTypeParserResult result;
778796
char* errorStr;
@@ -786,18 +804,27 @@ bool Architecture::ParseTypesFromSourceFile(const string& fileName, map<string,
786804
functions.clear();
787805

788806
bool ok = BNParseTypesFromSourceFile(m_object, fileName.c_str(), &result, &errorStr,
789-
includeDirList, includeDirs.size());
807+
includeDirList, includeDirs.size(), autoTypeSource.c_str());
790808
errors = errorStr;
791809
BNFreeString(errorStr);
792810
if (!ok)
793811
return false;
794812

795813
for (size_t i = 0; i < result.typeCount; i++)
796-
types[result.types[i].name] = new Type(BNNewTypeReference(result.types[i].type));
814+
{
815+
QualifiedName name = QualifiedName::FromAPIObject(&result.types[i].name);
816+
types[name] = new Type(BNNewTypeReference(result.types[i].type));
817+
}
797818
for (size_t i = 0; i < result.variableCount; i++)
798-
variables[result.variables[i].name] = new Type(BNNewTypeReference(result.variables[i].type));
819+
{
820+
QualifiedName name = QualifiedName::FromAPIObject(&result.variables[i].name);
821+
variables[name] = new Type(BNNewTypeReference(result.variables[i].type));
822+
}
799823
for (size_t i = 0; i < result.functionCount; i++)
800-
functions[result.functions[i].name] = new Type(BNNewTypeReference(result.functions[i].type));
824+
{
825+
QualifiedName name = QualifiedName::FromAPIObject(&result.functions[i].name);
826+
functions[name] = new Type(BNNewTypeReference(result.functions[i].type));
827+
}
801828
BNFreeTypeParserResult(&result);
802829
return true;
803830
}
@@ -954,8 +981,8 @@ bool CoreArchitecture::GetInstructionText(const uint8_t* data, uint64_t addr, si
954981

955982
for (size_t i = 0; i < count; i++)
956983
{
957-
result.push_back(InstructionTextToken(tokens[i].type, tokens[i].text, tokens[i].value,
958-
tokens[i].size, tokens[i].operand));
984+
result.push_back(InstructionTextToken(tokens[i].type, tokens[i].context, tokens[i].text, tokens[i].address,
985+
tokens[i].value, tokens[i].size, tokens[i].operand));
959986
}
960987

961988
BNFreeInstructionText(tokens, count);

0 commit comments

Comments
 (0)