Skip to content

Commit b6d0ef9

Browse files
committed
make type library questions headers
1 parent c54d583 commit b6d0ef9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/dev/typelibraries.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ typelib.write_to_file('test.so.1.bntl')
123123

124124
## Other Type Library Questions
125125

126-
_What's a named type vs. just a type?_
126+
### What's a named type vs. just a type?
127127

128128
Some variable definitions have type information, but don't produce a type name useful for future definitions, examples:
129129

@@ -158,17 +158,17 @@ typedef int (MyFunc)(int ac, char **av); // type int ()(int, char **), name:MyFu
158158

159159
```
160160

161-
_How does Binary Ninja decide when to use a typelibrary (.bntl) file?_
161+
### How does Binary Ninja decide when to use a typelibrary (.bntl) file?
162162

163163
Type Libraries are loaded when the corresponding library is imported by a BinaryView. (i.e. if an exe imports `ntdll.dll`, binja will look in the bv's platform for type libraries named ntdll.bntl and load the first one it finds)
164164

165-
_What's the difference between a named type and a named object?_
165+
### What's the difference between a named type and a named object?
166166

167167
A named type is a type with a name that can identify it. For example, `color` is the name of type `enum {RED=0, ORANGE=1, YELLOW=2, ...}`.
168168

169169
A named object is the name of an external/imported symbol for which the type library has type information. For example, `MessageBoxA` is the name of a function whose type is `int ()(HWND, LPCSTR, LPCSTR, UINT)`.
170170

171-
_How do I find what type of type a type object is? How many are there?_
171+
### How do I find what type of type a type object is? How many are there?
172172

173173
I've seen "types of types", "sorts of types", "kinds of types", "classes of types" used to differentiate the varieties of possible types, and there are probably more. Binary Ninja uses "class", example:
174174

@@ -183,26 +183,26 @@ Compare this to LLDB, which also uses the term "class", and currently has 19 of
183183

184184
Compare this to GDB, which uses the term "type code" and has 25 of them.
185185

186-
_Where are function parameter names stored?_
186+
### Where are function parameter names stored?
187187

188188
While technically not part of the type, having names of function parameters is very useful and can thus be optionally stored in a type.
189189

190190
Function types (types with `.type_class == FunctionTypeClass`) have a `.parameters` attribute, a list of [`FunctionParameter`](https://api.binary.ninja/binaryninja.types-module.html#binaryninja.types.FunctionParameter) objects. When those objects have `.name==''` you get the bare bones function types like `int ()(int, char **)`. When those objects have their `.name` populated you get the more meaningful `int ()(int argc, char **argv)`.
191191

192-
_How do I manually load a type library?_
192+
### How do I manually load a type library?
193193

194194
```
195195
>>> bv.add_type_library(TypeLibrary.load_from_file('test.bntl'))
196196
```
197197

198-
_How can I manually load a type object?_
198+
### How can I manually load a type object?
199199

200200
```
201201
>>> bv.import_library_object('_MySuperComputation')
202202
<type: int32_t (int32_t, int32_t, char*)>
203203
```
204204

205-
_Why doesn't the types view show the types imported from type libraries?_
205+
### Why doesn't the types view show the types imported from type libraries?
206206

207207
Because the type libraries added to a binary view only makes their type information _available_ for use. The types view will show a type from a type library only after it is used (on demand).
208208

@@ -215,7 +215,7 @@ Try this experiment:
215215
- set the type of some data to `struct Rectangle` (using `y` in linear view or via any other method described above)
216216
- `bv.types` is extended, and the types view shows `struct Rectangle` in the auto types
217217

218-
_What's a named type reference?_
218+
### What's a named type reference?
219219

220220
Named Type References are a way to refer to a type by name without having its declaration immediately available.
221221

@@ -254,7 +254,7 @@ This makes sense! Now go to types view and `define struct Point { int x; int y;
254254

255255
You should repeat the experiment using `struct Rectangle` and see that you're allowed to create variables with type containing _pointers_ to unresolved type references.
256256

257-
_How are types represented?_
257+
### How are types represented?
258258

259259
By a hierarchy of objects from [api/python/types.py](https://github.com/Vector35/binaryninja-api/blob/dev/python/types.py) referencing one another. The "glue" object is [`binaryninja.types.Type`](https://api.binary.ninja/binaryninja.types-module.html#binaryninja.types.Type) and depending on the complexity of the type it represents (stored in its `.type_class` attribute), it could have an attribute with more information. For instance, if the `binaryninja.types.Type` has `.type_class == FunctionTypeClass` then its `.parameters` attribute is a list of [`binaryninja.types.FunctionParameter`](https://api.binary.ninja/binaryninja.types-module.html#binaryninja.types.FunctionParameter). See [typelib_dump.py](https://github.com/Vector35/binaryninja-api/blob/dev/python/examples/typelib_dump.py) for how this can work.
260260

@@ -277,7 +277,7 @@ Type class=Structure
277277

278278
Here is the representation of `type int ()(int, int)` named `MyFunctionType` from [typelib_create.py](https://github.com/Vector35/binaryninja-api/blob/dev/python/examples/typelib_create.py):
279279

280-
_When do named objects get used?_
280+
### When do named objects get used?
281281

282282
When a binary is loaded and its external symbols is processed, the symbol names are searched against the named objects from type libraries. If there is a match, it obeys the type from the type library. Upon success, you'll see a message like:
283283

0 commit comments

Comments
 (0)