Skip to content

Instantly share code, notes, and snippets.

View pgoodman's full-sized avatar
🦥

Peter Goodman pgoodman

🦥
View GitHub Profile
@pgoodman
pgoodman / out.txt
Last active October 6, 2020 03:26
Pretty print tables.
+- Grammar ---------------+ +-----------------------------------------------------+
| | | Production | Nullable | FIRST | FOLLOW |
| S -> S S | |-------------------------+----------+-------+--------|
| S -> if E then S else S | | S' -> S $ | False | exit | |
| S -> if E then S | | | | if | |
| S -> exit when E | |-------------------------+----------+-------+--------|
+-------------------------+ | S -> S S | False | exit | $ |
| S -> if E then S else S | | if | exit |
| S -> if E then S | | | if |
| S -> exit when E | | | else |
// Copyright 2020 Peter Goodman, all rights reserved.
#include <cassert>
#include <cstdint>
#include <cstddef>
#include <iostream>
#include <type_traits>
#include <vector>
template<typename IntegralType_, unsigned kNumBits_, unsigned kShift_>
@pgoodman
pgoodman / asan.md
Created July 3, 2020 03:59
Address Sanitizer

On macOS

export CFLAGS="-fsanitize=address -ffunction-sections -fdata-sections -Wl,-dead_strip -Wl,-undefined,dynamic_lookup -Wno-unused-command-line-argument"
export CXXFLAGS="-fsanitize=address -ffunction-sections -fdata-sections -Wl,-dead_strip -Wl,-undefined,dynamic_lookup -Wno-unused-command-line-argument"

On Linux

export CFLAGS="-fsanitize=address -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--allow-multiple-definition"
export CXXFLAGS="-fsanitize=address -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--allow-multiple-definition"
@pgoodman
pgoodman / Terminal
Created March 3, 2020 21:24
Example on how to use Anvill
/path/to/remill-build/tools/anvill/anvill-decompile-json-9.0 --spec /tmp/slice.json --ir_out /dev/stderr
@pgoodman
pgoodman / compile.sh
Created November 5, 2019 18:16
Using ANVILL with AArch64
clang --target=armv8-pc-linux-gnu -m64 -c /tmp/test.c -o /tmp/test.o
@pgoodman
pgoodman / BUILD_REMILL.md
Last active June 30, 2020 14:22
Instructions for building Remill and its dependencies from scratch

Instructions for a full build of Remill and its depedencies.

Clone cxx-common

cd ~/src
git clone git@github.com:trailofbits/cxx-common.git

Repository path

@pgoodman
pgoodman / lifted.bc
Created October 23, 2019 16:35
anvill-decompile-7.0 --spec /tmp/slice.json --ir_out /dev/stdout
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu-elf"
%struct.Memory = type opaque
%struct.State = type { %struct.ArchState, [32 x %union.VectorReg], %struct.ArithFlags, %union.anon, %struct.Segments, %struct.AddressSpace, %struct.GPR, %struct.X87Stack, %struct.MMX, %struct.FPUStatusFlags, %union.anon, %union.FPU, %struct.SegmentCaches }
%struct.ArchState = type { i32, i32, %union.anon }
%union.VectorReg = type { %union.vec512_t }
%union.vec512_t = type { %struct.uint64v8_t }
%struct.uint64v8_t = type { [8 x i64] }
%struct.ArithFlags = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8 }
@pgoodman
pgoodman / code.S
Last active October 10, 2019 19:24
remill-lift-7.0 --ir_out /dev/stdout --bytes 89F80FB74C241881F9008000000F95C1D3E0C3 --slice_inputs RSP,EDI --slice_outputs EAX
0: 89 f8 mov eax,edi
2: 0f b7 4c 24 18 movzx ecx,WORD PTR [rsp+0x18]
7: 81 f9 00 80 00 00 cmp ecx,0x8000
d: 0f 95 c1 setne cl
10: d3 e0 shl eax,cl
12: c3 ret
static bool TryExtractCMEQ_ASIMDMISC_Z(InstData &inst, uint32_t bits) {
// bits
// & 10111111001111111111110000000000
// --------------------------------
// 00001110001000001001100000000000
if ((bits & 0xbf3ffc00U) != 0xe209800U) {
return false;
}
union {
uint32_t flat;
@pgoodman
pgoodman / transformations.py
Created October 3, 2018 16:49
Transform new LLVM IR into old LLVM IR
import logging
import os
import re
from subprocess import call
import sys
def _convert_data(data):
'''
'data' is a string of the 'disassembled' bitcode (could be
read in from file/stdin)