hex-patch 1.13.0

HexPatch is a binary patcher and editor with terminal user interface (TUI), it's capable of disassembling instructions and assembling patches. It supports a variety of architectures and file formats. Also, it can edit remote files via SSH.
Documentation
use std::error::Error;

use crate::headers::encoder::Encoder;
use crate::headers::Header;
use rbpf::assembler;

pub fn assemble(
    asm: &str,
    starting_virtual_address: u64,
    header: &Header,
) -> Result<Vec<u8>, Box<dyn Error>> {
    let encoder = header
        .get_encoder()
        .map_err(|e| t!("errors.create_encoder", e = e))?;

    let out: Vec<u8> = match encoder {
        Encoder::Keystone(keystone) => {
            keystone
                .asm(asm.to_string(), starting_virtual_address)
                .map_err(|e| t!("errors.assemble", e = e))?
                .bytes
        }
        Encoder::EBPF => assembler::assemble(asm).map_err(|e| t!("errors.assemble", e = e))?,
    };

    Ok(out)
}