diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2023-08-29 23:31:56 -0400 |
|---|---|---|
| committer | Jordan Wiens <jordan@psifertex.com> | 2023-08-29 23:31:56 -0400 |
| commit | 9202af38c7d0d894038be4192e0a90294a7c07aa (patch) | |
| tree | abfda454f9312e813dc5a7bd83c4badf3f8145c6 /docs/dev/concepts.md | |
| parent | 1875328326356054538694240064822492534697 (diff) | |
UI plugin dev and more licensing documentation
Diffstat (limited to 'docs/dev/concepts.md')
| -rw-r--r-- | docs/dev/concepts.md | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/docs/dev/concepts.md b/docs/dev/concepts.md index 5f839799..f962ba0d 100644 --- a/docs/dev/concepts.md +++ b/docs/dev/concepts.md @@ -20,4 +20,44 @@ It is easy to confuse ExpressionIndex and InstructionIndex properties in the API There are several ways to create UI elements in Binary Ninja. The first is to use the simplified [interaction](https://api.binary.ninja/binaryninja.interaction-module.html) API which lets you make simple UI elements for use in GUI plugins in Binary Ninja. As an added bonus, they all have fallbacks that will work in headless console-based applications as well. Plugins that use these API include the [angr](https://github.com/Vector35/binaryninja-api/blob/dev/python/examples/angr_plugin.py) and [nampa](https://github.com/kenoph/nampa) plugins. -The second and more powerful (but more complicated) mechanism is to leverage the _binaryninjaui_ module. Additional documentation is forthcoming, but there are several examples ([1](https://github.com/Vector35/kaitai), [2](https://github.com/Vector35/snippets), [3](https://github.com/Vector35/binaryninja-api/tree/dev/python/examples/triage)), and most of the APIs are backed by the [documented C++ headers](https://api.binary.ninja/cpp). Additionally, the generated _binaryninjaui_ module is shipped with each build of binaryninja and the usual python `dir()` instructions are helpful for exploring its capabilities.
\ No newline at end of file +The second and more powerful (but more complicated) mechanism is to leverage the _binaryninjaui_ module. Additional documentation is forthcoming, but there are several examples ([1](https://github.com/Vector35/kaitai), [2](https://github.com/Vector35/snippets), [3](https://github.com/Vector35/binaryninja-api/tree/dev/python/examples/triage)), and most of the APIs are backed by the [documented C++ headers](https://api.binary.ninja/cpp). Additionally, the generated _binaryninjaui_ module is shipped with each build of binaryninja and the usual python `dir()` instructions are helpful for exploring its capabilities. + +## Function Starts, Sizes, and Ending + +### How big is a Function? + +One of the common questions asked of a binary analysis platform is "how big is a function?". This is a deceptively simple question without a simple answer. There are rather several equally valid definitions you could give for what is the size of a function: + + - the total sum of all basic blocks? + - the highest virtual address in the function minus the lowest virtual address? + - the address of return instruction subtracted from the entry point + +Except that last one is a trick of course. Because not only can functions have multiple return instructions, but they may have multiple entry points (as is often the case with error handling). + +Basic blocks have, by definition, a start, and an end. Basic Blocks can therefore have consistent sizes that all binary analysis tools would agree upon (though more formal analysis might stop basic blocks on call instructions while for convenience sake, most reverse engineering tools do not). + +Summing up the basic blocks of a function is one way to produce a consistent size for a function, but how do you handle bytes that overlap standard function definitions, for example, via a tail call? Or via a mis-aligned jump where a byte is in two basic blocks? Different tools may resolve those ambiguous situations in different ways, so again, it is difficult to compare the "size" of any one binary analysis tool to another. + + In Binary Ninja, there is no explicit `.size` property of functions. Rather, you can choose to calculate it one of two ways: + +``` +function_size = current_function.total_bytes +# or +function_size = current_function.highest_address - current_function.lowest_address +``` + +Total bytes is similar to the first proposed definition above. It merely sums up the lengths of each basic block in the function. Because Binary Ninja allows bytes to exist in multiple blocks, this can cause bytes to be "double" counted, but this definition is consistent within BN itself, if not always with other tools in some edge cases. + +### When does a Function stop? + +One reason that having an "end" might be useful in a function (as opposed to the `.highest_address` in Binary Ninja), would be to make it a property that controls the analysis for a function. Unlike some other systems where it's possible to define the start and end of a function, in Binary Ninja, you merely define the start and allow analysis to occur naturally. The end results when all basic blocks terminate either in: + + - an invalid instruction + - a return instruction + - a call to a function marked as `__noreturn__` + - a branch to a block already in the function + - any other instruction such as an interrupt that by its definition stops analysis + +So how do you tell Binary Ninja how big a function is? The answer is you don't directly, but you can instead direct its analysis. For example, if a function is improperly not marked as a noreturn function, edit the function properties via the right-click menu and set the property and all calls to it will end analysis at that point in any callees. + +Likewise, you can do things like change memory permissions, patch in invalid instructions, [change an indirect branch's targets](https://github.com/Vector35/binaryninja-api/blob/dev/python/examples/jump_table.py), or use [UIDF](https://binary.ninja/2020/09/10/user-informed-dataflow.html) to influence analysis such that it ends where desired.
\ No newline at end of file |
