Skip to content

Instantly share code, notes, and snippets.

View ivg's full-sized avatar

Ivan Gotovchits ivg

View GitHub Profile
@ivg
ivg / decode_it.ml
Created November 17, 2021 21:55
decoding LLVM IT instruction
let of_int_exn = function
| 0 -> `EQ
| 1 -> `NE
| 2 -> `CS
| 3 -> `CC
| 4 -> `MI
| 5 -> `PL
| 6 -> `VS
| 7 -> `VC
| 8 -> `HI
@ivg
ivg / extra-thumb2.lisp
Created September 13, 2021 21:27
the semantics of the stm thumb2 instruction
(declare (context (target arm)))
(in-package thumb)
(defun t2STMDB_UPD (dst base _pred _?
r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15)
(stmdb_upd dst base r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15))
(defun t2STMDB_UPD (dst base _pred _?
r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14)
@ivg
ivg / rewriter.ml
Created March 4, 2021 16:59
A simple binary rewriter using BAP
open Bap.Std
open Core_kernel
open Bap_main
module Unix = UnixLabels
type chunk = {
offset : int;
data : Bigstring.t
}
@ivg
ivg / lisp_demo.ml
Created January 28, 2021 21:17
implements a `lisp-demo` command in bap that translates lisp programs into BIL programs
open Core_kernel
open Bap.Std
open Bap_core_theory
open Bap_main
open Bap_primus.Std
open KB.Syntax
let show name =
Toplevel.exec @@ begin
@ivg
ivg / knowledge_explorer.ml
Created August 25, 2020 22:51
A simple example that shows how to explore the knowledge base.
open Core_kernel
open Bap_main
open Bap_knowledge
open Bap_core_theory
open Bap.Std
open KB.Syntax
let zero_collector = object
inherit [Tid.Set.t] Term.visitor
@ivg
ivg / bytoy.ml
Last active August 12, 2020 15:41
Lifting a toy bytecode using Core Theory
open Core_kernel
open Bap_core_theory
open Bap.Std
open KB.Syntax
include Self()
let package = "bytoy"
type name = string [@@deriving equal,sexp]
type oper = Reg of int | Imm of int [@@deriving equal,sexp]
@ivg
ivg / toy.ml
Created April 16, 2020 16:05
A lifter for the toy language
open Core_kernel
open Bap_core_theory
open Bap.Std
open KB.Syntax
include Self()
module Word = struct
include Bitvec_order
include Bitvec_sexp.Functions
end
@ivg
ivg / bap.deps
Last active July 11, 2019 14:15
bap deps (as of Jul 2019)
opam-version: "2.0"
compiler: [
"base-bigarray.base"
"base-threads.base"
"base-unix.base"
"ocaml-base-compiler.4.07.0"
]
roots: [
"bap-signatures.1.5.0"
"base.v0.11.1"
@ivg
ivg / ppx-tree.ml
Created May 8, 2019 13:21
A tree representation for ppx
open Core_kernel
module Ast = struct
type ident = string [@@deriving compare, hash, sexp]
type t =
| Var of ident
| Int of int
| Let of ident * t * t
| App of ident * t list
@ivg
ivg / combs.ml
Last active May 2, 2019 16:55
folding over all combinations
(* a simple iterator, using the for loop, note that it counts objects starting from 1. *)
let iter_combs n k f =
let rec gen v s j =
if j > k then f v
else for i = s to n do
gen (i::v) (i+1) (j+1)
done in
gen [] 1 1