viv-utils

0.8.1 · active · verified Fri Apr 17

viv-utils (version 0.8.1) is a Python library providing utilities for binary analysis, specifically designed to complement vivisect. It offers helper functions and abstractions for common tasks like extracting information from vivisect workspaces, navigating control flow graphs, and working with function metadata. Its release cadence is somewhat infrequent, driven by the needs of its primary developers and the broader vivisect ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `viv-utils` with a `vivisect` workspace (using a minimal mock for runnable example) and iterate through functions, accessing their basic properties. In a real scenario, `vw` would be a fully loaded and analyzed `vivisect.VivWorkspace` object.

import viv_utils.api as viv_api
from unittest.mock import MagicMock

# --- Start Minimal Mock for Demonstrative vivisect Workspace ---
# In a real scenario, 'vw' would be an actual vivisect.VivWorkspace
# loaded with a binary and analyzed (e.g., vw.loadFromFile("path/to/binary"); vw.analyze()).

class MockVivWorkspace:
    def __init__(self):
        self.arch = "amd64" # Required by viv_utils
        self._functions = {
            0x1000: {"name": "entry_point", "blocks_count": 3},
            0x1050: {"name": "utility_func", "blocks_count": 2},
        }

    def getMetaInfo(self, key, default=None):
        # viv_utils queries meta info, e.g., 'Platform'
        return {"Platform": "windows"}.get(key, default)

    def getFunctions(self):
        return list(self._functions.keys())

    def getFunction(self, va):
        if va not in self._functions:
            return None
        # viv_utils expects specific attributes on the function object
        func_data = self._functions[va]
        mock_func = MagicMock()
        mock_func.va = va
        mock_func.name = func_data["name"]
        mock_func.basic_blocks = [MagicMock() for _ in range(func_data["blocks_count"])] # Simulate basic blocks
        mock_func.getBasicBlocks.return_value = {0x1000: (0x10, 5)} # dummy for internal access if needed
        return mock_func
    
    def getComments(self, va): return None # Often queried
    def getCodeBlocks(self): return [] # Often queried
    def getVivTaint(self): return MagicMock() # For emulator, though not used in this quickstart

vw = MockVivWorkspace()
# --- End Minimal Mock ---

# Wrap the mock vivisect workspace with viv-utils API
utils_workspace = viv_api.from_vivisect(vw)

print("Listing functions from the viv-utils wrapped workspace:")
for func in utils_workspace.get_functions():
    print(f"  Function VA: {hex(func.va)}, Name: '{func.name}', Basic Blocks: {len(func.basic_blocks)}")

# Example: Access a specific function by VA
target_va = 0x1050
target_func = utils_workspace.get_function(target_va)

if target_func:
    print(f"\nDetails for function '{target_func.name}' at {hex(target_func.va)}:")
    print(f"  Number of basic blocks: {len(target_func.basic_blocks)}")
else:
    print(f"\nFunction at {hex(target_va)} not found.")

view raw JSON →