Skip to content

Commit

Permalink
Integrate Icicle into fuzzware
Browse files Browse the repository at this point in the history
  • Loading branch information
icicle-emu-dev committed Nov 10, 2022
1 parent 075dbb5 commit 05307bf
Show file tree
Hide file tree
Showing 41 changed files with 4,264 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "unicorn/fuzzware-unicorn"]
path = unicorn/fuzzware-unicorn
url = ../unicorn
url = https://github.com/fuzzware-fuzzer/unicorn
3 changes: 3 additions & 0 deletions harness/fuzzware_harness/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def main():
from fuzzware_harness import harness
harness.main()
17 changes: 13 additions & 4 deletions harness/fuzzware_harness/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import sys
import logging

from unicorn import (UC_ARCH_ARM, UC_MODE_MCLASS, UC_MODE_THUMB, Uc)
from icicle import Uc
from unicorn import (UC_ARCH_ARM, UC_MODE_MCLASS, UC_MODE_THUMB)
from unicorn.arm_const import UC_ARM_REG_PC, UC_ARM_REG_SP

from . import globs, interrupt_triggers, native, timer, user_hooks
Expand All @@ -18,6 +19,7 @@
parse_symbols, resolve_region_file_paths)

logger = logging.getLogger("emulator")
logging.basicConfig(level=logging.DEBUG)

def unicorn_trace_syms(uc, address, size=0, user_data=None):
if address in uc.syms_by_addr:
Expand Down Expand Up @@ -51,8 +53,11 @@ def configure_unicorn(args):
logger.error("Memory Configuration must be in config file")
sys.exit(1)

# Icicle doesn't currently handle shadow stacks for context switches
disable_shadow_stack = any('Soldering_Iron' in region['file'] for rname, region in config['memory_map'].items() if 'file' in region)

# Create the unicorn
uc = Uc(UC_ARCH_ARM, UC_MODE_THUMB | UC_MODE_MCLASS)
uc = Uc(UC_ARCH_ARM, UC_MODE_THUMB | UC_MODE_MCLASS, disable_shadow_stack)

uc.symbols, uc.syms_by_addr = parse_symbols(config)

Expand All @@ -61,6 +66,10 @@ def configure_unicorn(args):
entry_image_base = None
resolve_region_file_paths(args.config, config)

debug_info = config.get("debug_info")
if debug_info:
uc.set_debug_file(debug_info)

# Entry region recovery
file_backed_regions = {rname: region for rname, region in config['memory_map'].items() if 'file' in region}
num_entry_regions = [region.get('is_entry', False) is True for region in file_backed_regions.values()].count(True)
Expand Down Expand Up @@ -99,7 +108,7 @@ def configure_unicorn(args):
sys.exit(1)

start, size = parse_address_value(uc.symbols, region['base_addr']), region['size']
logger.debug(f"Mapping region {str(rname)} at {hex(size)}, perms: {int(prot)}")
logger.debug(f"Mapping region {str(rname)} at {hex(start)} (size: {hex(size)}), perms: {int(prot)}")

if size & (globs.PAGE_SIZE-1) != 0:
logger.warning(f"Size 0x{size:x} of region '{rname}' not page aligned. Aligning to next page boundary size.")
Expand Down Expand Up @@ -374,7 +383,7 @@ def main():
if any(debug_flags):
args.debug = True

globs.debug_enabled = args.debug
globs.debug_enabled = True

uc = configure_unicorn(args)
globs.uc = uc
Expand Down
2 changes: 1 addition & 1 deletion harness/fuzzware_harness/mmio_models/passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def register_passthrough_handlers(uc, addrs, pcs, vals):

ensure_rw_mapped(uc, address, address)

set_ignored_mmio_addresses(addrs, pcs)
set_ignored_mmio_addresses(uc, addrs, pcs)

def parse_passthrough_handlers(symbols, declarations):
addrs = []
Expand Down
167 changes: 97 additions & 70 deletions harness/fuzzware_harness/native.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions harness/fuzzware_harness/native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ OWN_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
UC_DIRNAME := fuzzware-unicorn

LIBDIR = $(OWN_DIR)/../../../unicorn/$(UC_DIRNAME)/
INC=-I$(OWN_DIR)/../../../unicorn/$(UC_DIRNAME)/include
# INC=-I$(OWN_DIR)/../../../unicorn/$(UC_DIRNAME)/include
INC=
BIN_EXT = .so

CC = clang
CFLAGS += -fpic -Wall -Werror $(INC) -g -O3
LDFLAGS += -shared -L$(LIBDIR) -lunicorn
LDFLAGS += -shared

.PHONY: all clean

Expand Down
165 changes: 165 additions & 0 deletions harness/fuzzware_harness/native/arm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* Unicorn Engine */
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2015-2017 */
/* This file is released under LGPL2.
See COPYING.LGPL2 in root directory for more details
*/

#ifndef UNICORN_ARM_H
#define UNICORN_ARM_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _MSC_VER
#pragma warning(disable:4201)
#endif

//> ARM registers
typedef enum uc_arm_reg {
UC_ARM_REG_INVALID = 0,
UC_ARM_REG_APSR,
UC_ARM_REG_APSR_NZCV,
UC_ARM_REG_CPSR,
UC_ARM_REG_FPEXC,
UC_ARM_REG_FPINST,
UC_ARM_REG_FPSCR,
UC_ARM_REG_FPSCR_NZCV,
UC_ARM_REG_FPSID,
UC_ARM_REG_ITSTATE,
UC_ARM_REG_LR,
UC_ARM_REG_PC,
UC_ARM_REG_SP,
UC_ARM_REG_SPSR,
UC_ARM_REG_D0,
UC_ARM_REG_D1,
UC_ARM_REG_D2,
UC_ARM_REG_D3,
UC_ARM_REG_D4,
UC_ARM_REG_D5,
UC_ARM_REG_D6,
UC_ARM_REG_D7,
UC_ARM_REG_D8,
UC_ARM_REG_D9,
UC_ARM_REG_D10,
UC_ARM_REG_D11,
UC_ARM_REG_D12,
UC_ARM_REG_D13,
UC_ARM_REG_D14,
UC_ARM_REG_D15,
UC_ARM_REG_D16,
UC_ARM_REG_D17,
UC_ARM_REG_D18,
UC_ARM_REG_D19,
UC_ARM_REG_D20,
UC_ARM_REG_D21,
UC_ARM_REG_D22,
UC_ARM_REG_D23,
UC_ARM_REG_D24,
UC_ARM_REG_D25,
UC_ARM_REG_D26,
UC_ARM_REG_D27,
UC_ARM_REG_D28,
UC_ARM_REG_D29,
UC_ARM_REG_D30,
U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UC_ARM_REG_MSP,
UC_ARM_REG_PSP,
UC_ARM_REG_CONTROL,

// Fuzzware registers
UC_ARM_REG_XPSR,
UC_ARM_REG_OTHER_SP,
UC_ARM_REG_CURR_SP_MODE_IS_PSP,
UC_ARM_REG_SPSEL,
UC_ARM_REG_BASEPRI,
UC_ARM_REG_PRIMASK,
UC_ARM_REG_ENDING, // <-- mark the end of the list or registers

//> alias registers
UC_ARM_REG_R13 = UC_ARM_REG_SP,
UC_ARM_REG_R14 = UC_ARM_REG_LR,
UC_ARM_REG_R15 = UC_ARM_REG_PC,

UC_ARM_REG_SB = UC_ARM_REG_R9,
UC_ARM_REG_SL = UC_ARM_REG_R10,
UC_ARM_REG_FP = UC_ARM_REG_R11,
UC_ARM_REG_IP = UC_ARM_REG_R12,
} uc_arm_reg;

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 05307bf

Please sign in to comment.