Skip to content

Instantly share code, notes, and snippets.

View cetfor's full-sized avatar

John Toterhi cetfor

View GitHub Profile
@cetfor
cetfor / cdecl.c
Last active November 8, 2021 12:27
Example source for my calling conventions article
// gcc -m32 -mpreferred-stack-boundary=2 cdecl.c -o cdecl
#include <stdio.h>
void printFavNums(int num1, int num2) {
printf("My favorite numbers are %d and %d!\n", num1, num2);
}
int main()
{
@cetfor
cetfor / keybase.md
Created July 9, 2018 15:32
keybase.md

Keybase proof

I hereby claim:

  • I am cetfor on github.
  • I am cetfor (https://keybase.io/cetfor) on keybase.
  • I have a public key ASBHlHOFYJOg5ZKnd_FHZsrevyhbS6mGSgcV24hW55cFDAo

To claim this, I am signing this object:

@cetfor
cetfor / emulate_pcode.py
Last active June 4, 2022 17:54
PCode Emulation with Python
from ghidra.app.emulator import EmulatorHelper
from ghidra.program.model.symbol import SymbolUtilities
# Tested with Ghidra v9.1 and v9.1.1, future releases are likely to simplify
# and/or expand the EmulatorHelper class in the API.
# == Helper functions ======================================================
def getAddress(offset):
return currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(offset)
@cetfor
cetfor / GetMLILSSA.py
Created February 8, 2020 16:59
How to get Binary Ninja's MLIL SSA
# Get MLIL SSA form
import binaryninja
target = "cwe369A_x64"
print("Analyzing file: {}".format(target))
bv = binaryninja.BinaryViewType.get_view_of_file(target)
bv.add_analysis_option('linearsweep')
@cetfor
cetfor / GetMLILOperands.py
Created February 8, 2020 18:53
Get MLIL SSA form and print operands
# Get MLIL SSA form and print operands
import binaryninja
target = "cwe369A_x64"
print("Analyzing file: {}".format(target))
bv = binaryninja.BinaryViewType.get_view_of_file(target)
bv.add_analysis_option('linearsweep')
# Get MLIL SSA form
import binaryninja
target = "cwe369A_x64"
target_operations = [
binaryninja.MediumLevelILOperation.MLIL_DIVS,
binaryninja.MediumLevelILOperation.MLIL_DIVS_DP,
binaryninja.MediumLevelILOperation.MLIL_DIVU,
@cetfor
cetfor / BuildAssignmentGraph.py
Created February 8, 2020 23:04
Build a NetworkX digraph of MLIL SSA assignments for data flow analysis
import binaryninja
import networkx as nx
target = "cwe369A_x64"
def build_symbol_graph(bv, func):
graph = nx.DiGraph()
for func in bv.functions:
for block in func.medium_level_il.ssa_form:
for instr in block:
import binaryninja
import networkx as nx
target = "cwe369A_x64"
target_operations = [
binaryninja.MediumLevelILOperation.MLIL_DIVS,
binaryninja.MediumLevelILOperation.MLIL_DIVS_DP,
binaryninja.MediumLevelILOperation.MLIL_DIVU,
binaryninja.MediumLevelILOperation.MLIL_DIVU_DP,
import binaryninja
import networkx as nx
target = "cwe369B_x64"
RETURN_MAP = {
'atoi': 0,
}
target_operations = [
import binaryninja
import networkx as nx
target = "cwe369B_ARM32"
RETURN_MAP = {
'atoi': 0,
}