summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/dev/bnil-hlil.md1
-rw-r--r--docs/dev/bnil-llil.md8
-rw-r--r--docs/dev/outlining.md7
-rwxr-xr-xscripts/check_markdown_list.py233
4 files changed, 246 insertions, 3 deletions
diff --git a/docs/dev/bnil-hlil.md b/docs/dev/bnil-hlil.md
index b66081dc..db8377fc 100644
--- a/docs/dev/bnil-hlil.md
+++ b/docs/dev/bnil-hlil.md
@@ -49,7 +49,6 @@ There are a number of properties that can be queried on the [`HighLevelILInstruc
* `HLIL_IF` - Branch to the `true`/`false` HLIL instruction identifier depending on the result of the `condition` expression
* `HLIL_GOTO` - Branch to the `dest` expression id
* `HLIL_TAILCALL` - This instruction calls the expression `dest` using `params` as input and `output` for return values
-not exist
* `HLIL_SYSCALL` - Make a system/service call with parameters `params` and output `output`
* `HLIL_WHILE` -
* `HLIL_DO_WHILE` -
diff --git a/docs/dev/bnil-llil.md b/docs/dev/bnil-llil.md
index 2eafe5cb..2ac1e77f 100644
--- a/docs/dev/bnil-llil.md
+++ b/docs/dev/bnil-llil.md
@@ -15,8 +15,7 @@ Since doing is the easiest way to learn let's start with a simple example binary
![Low Level IL Option >](../img/llil-option.png)
- Download [chal1](../files/chal1) and open it with Binary Ninja
- - Next, bring up the `Low Level IL` view by clicking in the view drop down at the top of the pane
- (or alternatively, use the `i` key to cycle view levels)
+ - Next, bring up the `Low Level IL` view by clicking in the view drop down at the top of the pane (or alternatively, use the `i` key to cycle view levels)
- Navigate to main (`g`, then "main", or double-click it in the function list)
- Finally, bring up the python console using: `~`
@@ -97,30 +96,35 @@ For the above instruction, we have a few operations we can perform:
>>> instr.function
<binaryninja.lowlevelil.LowLevelILFunction object at 0x111c79810>
```
+
* **instr_index** - returns the LLIL index
```
>>> instr.instr_index
2
```
+
* **operands** - returns a list of all operands.
```
>>> instr.operands
['rsp', <il: rsp - 0x110>]
```
+
* **operation** - returns the enumeration value of the current operation
```
>>> instr.operation
<LowLevelILOperation.LLIL_SET_REG: 1>
```
+
* **src** - returns the source operand
```
>>> instr.src
<il: rsp - 0x110>
```
+
* **dest** - returns the destination operand
```
diff --git a/docs/dev/outlining.md b/docs/dev/outlining.md
index fa826b2f..78d2bbe0 100644
--- a/docs/dev/outlining.md
+++ b/docs/dev/outlining.md
@@ -109,6 +109,7 @@ The outliner then recognizes the intrinsic name and transforms it into the appro
#### Recognized Intrinsic Names
**Memory Copy Intrinsics**:
+
- `__memcpy` → `memcpy`, `strcpy`, or `strncpy` (based on data classification)
- `__memcpy_u8` → `memcpy` (byte-wise, count unchanged)
- `__memcpy_u16` → `memcpy` (16-bit elements, count × 2)
@@ -116,6 +117,7 @@ The outliner then recognizes the intrinsic name and transforms it into the appro
- `__memcpy_u64` → `memcpy` (64-bit elements, count × 8)
**Memory Fill Intrinsics**:
+
- `__memfill` → `memset`
- `__memfill_u8` → `memset` (byte-wise, count unchanged)
- `__memfill_u16` → `memset` (16-bit elements, count × 2)
@@ -235,11 +237,13 @@ Outlining is valuable across many analysis domains including reverse engineering
### Common Issues
**Patterns not being outlined**:
+
- Check if `analysis.outlining.builtins` is enabled
- Verify type information supports the expected operation
- Ensure patterns meet minimum size thresholds (see below)
**Incorrect function selection**:
+
- Provide more precise type information
- Check data stream classification
- Verify pattern clarity and confidence
@@ -249,17 +253,20 @@ Outlining is valuable across many analysis domains including reverse engineering
Binary Ninja applies size-based filtering to avoid outlining trivial operations. Understanding these thresholds can help explain why certain patterns aren't outlined:
**Without Type Information** (no user-provided types with full confidence):
+
- General memory operations: Must be >16 bytes
- String operations: Must be ≥4 bytes
- ASCII patterns: Must be ≥4 bytes
- Fill patterns (memset): Must be ≥16 bytes
**With Type Information** (user-provided types with full confidence):
+
- Size thresholds are relaxed
- Type compatibility checks take priority
- Operations matching type boundaries are more likely to be outlined
**String-Specific Requirements**:
+
- String must have at least 4 printable characters before null terminator
- Very short strings (1-3 bytes) are often demoted to general memory operations
diff --git a/scripts/check_markdown_list.py b/scripts/check_markdown_list.py
new file mode 100755
index 00000000..2b64b308
--- /dev/null
+++ b/scripts/check_markdown_list.py
@@ -0,0 +1,233 @@
+#!/usr/bin/env python3
+"""
+Check markdown files for missing blank lines before list items.
+
+This script identifies places where text is immediately followed by a list item
+without a blank line, which can cause rendering issues in markdown parsers.
+"""
+
+import argparse
+import os
+import re
+import sys
+from pathlib import Path
+
+
+def get_indentation(line):
+ """Get the number of leading spaces/tabs in a line."""
+ return len(line) - len(line.lstrip())
+
+
+def is_list_item(line):
+ """Check if a line is a list item (ordered, unordered, or nested)."""
+ stripped = line.lstrip()
+ # Unordered list: starts with -, *, or +
+ if re.match(r'^[-*+]\s', stripped):
+ return True
+ # Ordered list: starts with number followed by . or )
+ if re.match(r'^\d+[.)]\s', stripped):
+ return True
+ return False
+
+
+def is_blank(line):
+ """Check if a line is blank or whitespace only."""
+ return line.strip() == ''
+
+
+def is_code_fence(line):
+ """Check if a line is a code fence."""
+ stripped = line.strip()
+ return stripped.startswith('```') or stripped.startswith('~~~')
+
+
+def is_within_list_context(lines, current_idx):
+ """
+ Check if we're currently within a list context by looking backwards.
+ Returns True if there's a recent list item without intervening blank lines.
+ """
+ # Look back up to 10 lines for a list item
+ for i in range(current_idx - 1, max(current_idx - 10, -1), -1):
+ line = lines[i]
+
+ if is_blank(line):
+ # Hit a blank line, no longer in list context
+ return False
+
+ if is_list_item(line):
+ # Found a list item, we're in list context
+ return True
+
+ return False
+
+
+def needs_blank_line_before_list(lines, current_idx):
+ """
+ Determine if a blank line is needed before the current line.
+
+ Returns True if:
+ - Current line is a list item
+ - Previous line is NOT blank
+ - Previous line is NOT a code fence
+ - We're NOT already within a list context
+ - Previous line is NOT a list item
+ - Current line is NOT more indented (nested list)
+ """
+ if current_idx == 0:
+ return False
+
+ curr_line = lines[current_idx]
+ prev_line = lines[current_idx - 1]
+
+ if not is_list_item(curr_line):
+ return False
+
+ if is_blank(prev_line):
+ return False
+
+ # If previous line is a code fence, no blank line needed
+ if is_code_fence(prev_line):
+ return False
+
+ # If previous line is also a list item, no blank line needed
+ if is_list_item(prev_line):
+ return False
+
+ # Check if we're within a list context (continuing list)
+ if is_within_list_context(lines, current_idx):
+ return False
+
+ # Get indentation levels
+ prev_indent = get_indentation(prev_line)
+ curr_indent = get_indentation(curr_line)
+
+ # If current line is more indented than previous, it's likely a nested list
+ # Allow some flexibility (at least 2 spaces more for nesting)
+ if curr_indent > prev_indent + 1:
+ return False
+
+ # If previous line ends with certain patterns, it might be okay
+ prev_stripped = prev_line.strip()
+
+ # Skip if previous line looks like a heading
+ if prev_stripped.startswith('#'):
+ return False
+
+ # Skip if previous line is HTML/markdown directive
+ if prev_stripped.startswith('<') or prev_stripped.startswith('>'):
+ return False
+
+ # Otherwise, we likely need a blank line
+ return True
+
+
+def check_file(filepath):
+ """Check a single markdown file for formatting issues."""
+ issues = []
+
+ with open(filepath, 'r', encoding='utf-8') as f:
+ lines = f.readlines()
+
+ in_code_block = False
+
+ for i, line in enumerate(lines):
+ # Track code blocks to skip them
+ if is_code_fence(line):
+ in_code_block = not in_code_block
+ continue
+
+ if in_code_block:
+ continue
+
+ # Check if we need a blank line before this line
+ if needs_blank_line_before_list(lines, i):
+ issues.append({
+ 'line_num': i + 1,
+ 'line': line.rstrip(),
+ 'prev_line': lines[i - 1].rstrip()
+ })
+
+ return issues
+
+
+def main():
+ """Main entry point."""
+ parser = argparse.ArgumentParser(
+ description='Check markdown files for missing blank lines before list items.'
+ )
+ parser.add_argument(
+ 'paths',
+ nargs='*',
+ help='Files or directories to check (default: docs/ directory)'
+ )
+ parser.add_argument(
+ '-v', '--verbose',
+ action='store_true',
+ help='Show all files being checked, not just files with issues'
+ )
+
+ args = parser.parse_args()
+
+ if args.paths:
+ # Check if argument is a directory or file(s)
+ files_to_check = []
+ for path_str in args.paths:
+ arg_path = Path(path_str)
+ if arg_path.is_dir():
+ # Recursively find all .md files in directory
+ files_to_check.extend(arg_path.rglob('*.md'))
+ elif arg_path.is_file():
+ # Add specific file
+ files_to_check.append(arg_path)
+ else:
+ print(f"Warning: {path_str} is not a valid file or directory")
+ else:
+ # Check all markdown files in docs/
+ docs_dir = Path(__file__).parent.parent / 'docs'
+ if not docs_dir.exists():
+ print(f"Error: docs directory not found at {docs_dir}")
+ return 1
+
+ files_to_check = list(docs_dir.rglob('*.md'))
+
+ total_issues = 0
+ files_with_issues = []
+
+ for filepath in files_to_check:
+ filepath = Path(filepath)
+ if not filepath.exists():
+ print(f"Warning: {filepath} does not exist")
+ continue
+
+ if args.verbose:
+ print(f"Checking {filepath}...", end='', flush=True)
+
+ issues = check_file(filepath)
+
+ if issues:
+ if args.verbose:
+ print(f" {len(issues)} issue(s) found")
+ else:
+ print(f"{filepath}: {len(issues)} issue(s) found")
+
+ files_with_issues.append(filepath)
+ total_issues += len(issues)
+ for issue in issues:
+ print(f" Line {issue['line_num']}: Missing blank line before list item")
+ print(f" Previous: {issue['prev_line']}")
+ print(f" Current: {issue['line']}")
+ else:
+ if args.verbose:
+ print(" OK")
+
+ if total_issues > 0:
+ print(f"\nFound {total_issues} issue(s) in {len(files_with_issues)} file(s)")
+ return 1
+ else:
+ if args.verbose:
+ print("No issues found!")
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())