Skip to content

Instantly share code, notes, and snippets.

View pgoodman's full-sized avatar
🦥

Peter Goodman pgoodman

🦥
View GitHub Profile
@pgoodman
pgoodman / .gdbinit
Created July 30, 2014 13:21
Trace logger in Granary+
# Print $arg1 instructions starting at address $arg0.
define pi
set $__rip = $arg0
set $__ni = $arg1
python None ; \
rip = str(gdb.parse_and_eval("$__rip")).lower() ; \
ni = str(gdb.parse_and_eval("$__ni")).lower() ; \
gdb.execute( \
"x/%si %s\n" % (ni, rip), \
from_tty=True, to_string=False) ;
/* Copyright 2014 Peter Goodman, all rights reserved. */
#include <granary/granary.h>
using namespace granary;
// TODO(pag): Generic allocators (similar to with meta-data) but for allowing
// multiple tools to register descriptor info.
// TODO(pag): Eventually handle user space syscalls to avoid EFAULTs.
// TODO(pag): Eventually handle user space signals.
/* Copyright 2014 Peter Goodman, all rights reserved. */
#include <granary/granary.h>
using namespace granary;
// Simple tool decoding all blocks in a function.
class WholeFunctionDecoder : public InstrumentationTool {
public:
virtual ~WholeFunctionDecoder(void) = default;
@pgoodman
pgoodman / Use
Created August 14, 2014 18:02
GDB commands for printing Granary's internal `arch::Instruction` structures as x86-like instructions.
(gdb) print-arch-instr &($12->instruction)
MOV_MEMv_GPRv [SLOT:0], R15
(gdb)
// This source code comes from:
// http://stackoverflow.com/questions/8941711/is-is-possible-to-set-a-gdb-watchpoint-programatically
// with additional tricks from:
// https://code.google.com/p/google-breakpad/source/browse/trunk/src/client/linux/handler/exception_handler.cc?r=1361
#include <errno.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
;;;; Recursive Descent Parser Generator
;;;; Copyright 2008 Peter Goodman, all rights reserved
(defun concatenate* (type &rest lst)
"Concatenate all cars within a tree."
(setf lst (remove nil lst))
(if (null lst)
"" ; nothing to concatenate, return
(let ((a (car lst)) (d (cdr lst)))
(defun-parser :html-attr
(no-capture (repeat 0 nil " "))
(and (concat (repeat 0 nil (range #\a #\z))
(and ":" (repeat 0 nil (concat (range #\a #\z)))))
(no-capture #\= #\")
(find-next #\")
(no-capture #\")))
(defun-parser :html-attrs
(repeat 0 nil :html-attr))
(print (parse ':html "prefix text<div class=\"post\"><a name=\"comment-{$comment.comment_ID}\" id=\"comment-{$comment.comment_ID}\"></a>{$comment.content}<ul class=\"categories\">by <cond:if var=\"comment.comment_author_url\" neq=\"\"><a href=\"{$comment.comment_author_url}\" title=\"{$comment.comment_author}\">{$comment.comment_author}</a><cond:else />{$comment.comment_author}</cond:if> on {$comment.date} </ul></div>postfix text"))
;; what's generated:
("prefix text" (:HTML-TAG "" (:HTML-TAG-NAME "div") (:HTML-ATTRS (:HTML-ATTR "class" "post")) "") "" (:HTML-TAG "" (:HTML-TAG-NAME "a") (:HTML-ATTRS (:HTML-ATTR "name" "comment-{$comment.comment_ID}") (:HTML-ATTR "id" "comment-{$comment.comment_ID}")) "") "" (:HTML-TAG "/" (:HTML-TAG-NAME "a") (:HTML-ATTRS) "") "{$comment.content}" (:HTML-TAG "" (:HTML-TAG-NAME "ul") (:HTML-ATTRS (:HTML-ATTR "class" "categories")) "") "by " (:HTML-TAG "" (:HTML-TAG-NAME "cond:if") (:HTML-ATTRS (:HTML-ATTR "var" "comment.comment_author_url") (:HTML-ATTR "neq" "")) "") ""
(defun-parser :html-attr
(no-capture (repeat 0 nil " "))
(and (concat (repeat 0 nil (range #\a #\z))
(and ":" (repeat 0 nil (concat (range #\a #\z)))))
(no-capture #\= #\")
(find-next #\")
(no-capture #\")))
(defun-parser :html-attrs
(repeat 0 nil :html-attr))
("prefix text"
(:HTML-TAG
""
(:HTML-TAG-NAME "div")
(:HTML-ATTRS
(:HTML-ATTR "class" "post"))
"")
""
(:HTML-TAG
""