This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Computes an expression using Primus. Showcases how to bootstrap the whole Primus machinery and how | |
to store and extract results of computations from the project data structure. | |
To compile, put this file in an empty folder and run the following commands: | |
$ bapbuild -pkg bap-primus peval.plugin | |
$ bapbundle instll peval.plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core_kernel | |
open Bap.Std | |
open Bap_primus.Std | |
open Bap_plugins.Std | |
open Monads.Std | |
open Format | |
let empty_project arch = | |
let nil = Memmap.empty in | |
Project.Input.create arch "/bin/true" ~code:nil ~data:nil |> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*** Turing Machines in Coq *) | |
(** Some preliminary types we'll use *) | |
CoInductive CoList (A: Type) := CONS (a:A) (t:CoList A) | NIL. | |
Arguments CONS [A] _ _. | |
Arguments NIL [A]. | |
CoInductive Delay A := HERE (a:A) | LATER (_:Delay A). | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(extend ddtbd) | |
;; debugging stuff | |
(option primus-propagate-taint-to-attributes) | |
(option print-bir-attr tainted-reg) | |
(option print-bir-attr tainted-ptr) | |
(option print-bir-attr tainted-regs) | |
(option print-bir-attr tainted-ptrs) | |
(option dump bir:out.bir) | |
(option primus-print-obs enter-term read) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core_kernel | |
open Bap.Std | |
open Bap_primus.Std | |
open Bap_taint.Std | |
open Format | |
include Self() | |
type state = { | |
path_taints : Taint.Object.Set.t | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core_kernel.Std | |
open Bap.Std | |
open Graphlib.Std | |
open Format | |
include Self() | |
module CG = Graphs.Callgraph | |
module CFG = Graphs.Tid | |
module DAG = Graphlib.Make(Tid)(Unit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core_kernel.Std | |
open Bap.Std | |
open Graphlib.Std | |
module G = Graphs.Cfg | |
let complexity graph = | |
let edges = Seq.length (G.edges graph) in | |
let nodes = Seq.length (G.nodes graph) in | |
let parts = Graphlib.strong_components (module G) graph |> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bap | |
import networkx as nx | |
def build_cfg(sub): | |
G = nx.DiGraph() | |
entry = sub.blks[0].id.number | |
G.add_node(entry) | |
for blk in sub.blks: | |
for jmp in blk.jmps: | |
if jmp.constr == 'Goto' and jmp.target.constr == 'Direct': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.provider "virtualbox" do |vb| | |
vb.memory = "4096" | |
end | |
config.vm.provision "shell", privileged: false, inline: <<-SHELL | |
sudo add-apt-repository --yes ppa:avsm/ppa | |
sudo apt-get update | |
sudo apt-get --yes install opam | |
opam init --auto-setup --comp=4.02.3 --yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core_kernel.Std | |
open Bap.Std | |
open Or_error.Monad_infix | |
module Insn = Disasm_expert.Basic.Insn | |
module Mips = struct | |
(** Defines the register map *) | |
module CPU = struct | |
let mem = Var.create "mem" @@ mem32_t `r8 |