Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enables ARM Thumb support #1122

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a115deb
adds radare2 symbolizer
Phosphorus15 Jun 5, 2020
fcdf8ee
Fixes errors within oasis file
Phosphorus15 Jun 5, 2020
0a3f07c
fixes silly mistakes
Phosphorus15 Jun 6, 2020
b8e8ce1
use 'isj' to dump symbols
Phosphorus15 Jun 10, 2020
2c6dfd3
thumb lifter draft
Phosphorus15 Jun 12, 2020
13ae335
fix typo
Phosphorus15 Jun 12, 2020
80f8dc8
chop 'sym.imp' prefix
Phosphorus15 Jun 14, 2020
c03508a
extends register set
Phosphorus15 Jun 14, 2020
3bb5fab
complete & extract move-like instructions
Phosphorus15 Jun 14, 2020
246dcae
single memory l/s instructions
Phosphorus15 Jun 15, 2020
d64507f
multiple l/s instructions
Phosphorus15 Jun 15, 2020
00b2fcd
complete all bitwise move-like instructions
Phosphorus15 Jun 15, 2020
7aa7b65
finished instructions def
Phosphorus15 Jun 15, 2020
434c772
code style clean-up
Phosphorus15 Jun 17, 2020
c5a6c1b
refactor for new radare2-ocaml interface
Phosphorus15 Jun 21, 2020
612f15a
lift symbol extracting to allow partial failure
Phosphorus15 Jun 21, 2020
111df62
clean-up refactor & indentation fix
Phosphorus15 Jun 24, 2020
1325ade
polymorphic variant & pipe operator fix
Phosphorus15 Jun 25, 2020
f27131b
apply ocp-indent
Phosphorus15 Jul 3, 2020
e99afb9
thumb plugin refinement
Phosphorus15 Jul 14, 2020
640c80a
.merlin file update
Phosphorus15 Jul 14, 2020
6f66029
ocp-indent rerun
Phosphorus15 Jul 14, 2020
8e019a0
address assigned to LR should be subtracted
Phosphorus15 Jul 14, 2020
a8cd86b
register KB semantics promise
Phosphorus15 Jul 14, 2020
b48931b
now its up and working
Phosphorus15 Jul 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/arm_thumb/.merlin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
REC

B ./_build
146 changes: 146 additions & 0 deletions plugins/arm_thumb/dsl_common.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
open Bap_core_theory
open Base
open KB.Syntax
(** This is mean to design a dsl for ARM lifter *)

(** General cpu defs. *)
module type CPU = sig
type value
type bit_val
type reg_type
type operand
val value: value Theory.Bitv.t Theory.Value.sort
val bit_val: bit_val Theory.Bitv.t Theory.Value.sort
val load_reg: reg_type -> value Theory.Bitv.t Theory.Var.t
val assert_var: operand -> value Theory.Bitv.t Theory.Var.t
val assert_val: operand -> value Theory.Bitv.t Theory.pure
end

(** General fpu defs *)
module type FPU = sig
type operand
type value
val value : value Theory.Float.t Theory.Value.sort
val assert_var: operand -> value Theory.Float.t Theory.Var.t
val assert_val: operand -> value Theory.Float.t Theory.pure
end

module type ValueHolder = sig
type value
val value: value Theory.Bitv.t Theory.Value.sort
end

module DSL(Core: Theory.Core)(CPU: CPU)(V: ValueHolder) = struct
open Core

let expand (dsl : 'a Theory.eff list) =
let bot = perform Theory.Effect.Sort.bot in
List.fold dsl ~init:bot
~f:(fun acc current -> seq acc current)

(** alternative of expand to enable short syntax *)
let ( !% ) = expand

let assert_var = CPU.assert_var

let (!$$) = assert_var

let assert_val = CPU.assert_val

let (!$) = assert_val

let value_size = Theory.Bitv.size CPU.value

let word_as_bitv w = (int CPU.value (Bap.Std.Word.to_bitvec w))

let bool_as_bitv b = ite b (int CPU.value Bitvec.one) (int CPU.value Bitvec.zero)

let bool_as_bit b = ite b (int CPU.bit_val Bitvec.one) (int CPU.bit_val Bitvec.zero)

let imm (x : int) = word_as_bitv (Bap.Std.Word.of_int value_size x)

let (!!) = imm

let ( := ) = set
let set_if cond dest src = dest := ite cond src (var dest)
let when_else_ (cond : bool) then_ else_ =
if cond then then_ |> expand else else_ |> expand
let when_ (cond : bool) eff =
let bot = perform Theory.Effect.Sort.bot in
when_else_ cond eff [bot]
let unless_ (cond : bool) eff = when_ (phys_equal cond false) eff
let if_else_ (cond : Theory.bool) then_ else_ =
branch cond (then_ |> expand) (else_ |> expand)
let if_ (cond : Theory.bool) then_ =
let bot = perform Theory.Effect.Sort.bot in
if_else_ cond then_ [bot]

(** this is a static effect list generator (from core theory perspective) *)
let rec while_ (cond : 'a -> bool * 'a) (init : 'a) (perf : 'a -> 'b Theory.eff) =
match cond init with
| true, next -> [perf init] @ while_ cond next perf
| false, _ -> [perform Theory.Effect.Sort.bot]

let foreach_ (list : 'a list) (perf : 'a -> int -> 'b Theory.eff) =
List.foldi list ~init:(perform Theory.Effect.Sort.bot)
~f:(fun it eff item -> seq eff (perf item it))

let ( < ) = slt
let ( > ) = sgt
let ( <= ) = sle
let ( >= ) = sge
let ( <+ ) = ult
let ( >+ ) = ugt
let ( <=+ ) = ule
let ( >=+ ) = uge
let ( = ) = eq
let ( <> ) = neq
let ( << ) = lshift
let ( >> ) = rshift
let ( asr ) = arshift
let ( lor ) = logor
let ( land ) = logand
let ( lxor ) = logxor
let ( lnot ) = not

let nth_bit n e = cast CPU.bit_val b0 (shiftr b0 e n) |> msb

module Bool = struct
let ( lor ) = or_
let ( land ) = and_
let ( lnot ) = inv
let ( lxor ) x y = (lnot x land y) lor (x land lnot y)
let ( = ) = (lxor)
let ( <> ) x y = lnot (x = y)
end

module Arith = struct
let distribute op x y = op (cast V.value b0 x) (cast V.value b0 y)
let ( + ) x y = distribute add x y
let ( - ) x y = distribute sub x y
let ( * ) x y = distribute mul x y
(* multiplication with signed cast *)
let ( -* ) x y = mul (signed V.value x) (signed V.value y)
let ( / ) x y = distribute div x y
let ( % ) x y = distribute modulo x y
end

include Arith

let extend v = cast CPU.value b0 v
let extend_to s v = cast s b0 v
let extend_signed v = signed CPU.value v
let extend_to_signed s v = signed s v
let scoped_var = Theory.Var.scoped

end

module DSLFP(Core : Theory.Core)(FPU: FPU) = struct
let assert_var = FPU.assert_var

let (!$$.) = assert_var

let assert_val = FPU.assert_val

let (!$.) = assert_val
end
Loading