All Projects → TheRomanXpl0it → ghidra-emu-fun

TheRomanXpl0it / ghidra-emu-fun

Licence: Apache-2.0 license
Ghidra Emulates Functions

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to ghidra-emu-fun

GhidraEmu
Native Pcode emulator
Stars: ✭ 25 (-30.56%)
Mutual labels:  emulation, ghidra, ghidra-plugin
ghidra2dwarf
🐉 Export ghidra decompiled code to dwarf sections inside ELF binary
Stars: ✭ 135 (+275%)
Mutual labels:  ghidra, ghidra-plugin
ghidra-findcrypt
Ghidra analysis plugin to locate cryptographic constants
Stars: ✭ 138 (+283.33%)
Mutual labels:  ghidra, ghidra-plugin
Ghidra-SegaSaturn-Processor
A Ghidra processor module for the Sega Saturn (SuperH SH-2)
Stars: ✭ 43 (+19.44%)
Mutual labels:  ghidra
Smart-Traffic-Signals-in-India-using-Deep-Reinforcement-Learning-and-Advanced-Computer-Vision
We have used Deep Reinforcement Learning and Advanced Computer Vision techniques to for the creation of Smart Traffic Signals for Indian Roads. We have created the scripts for using SUMO as our environment for deploying all our RL models.
Stars: ✭ 131 (+263.89%)
Mutual labels:  emulation
dynarmic
An ARM dynamic recompiler.
Stars: ✭ 675 (+1775%)
Mutual labels:  emulation
CeDImu
Experimental Philips CD-I emulator written in C++
Stars: ✭ 41 (+13.89%)
Mutual labels:  emulation
desmume
DeSmuME is a Nintendo DS emulator
Stars: ✭ 1,609 (+4369.44%)
Mutual labels:  emulation
SkyEmu
Game Boy, Game Boy Color, and Game Boy Advanced Emulator
Stars: ✭ 59 (+63.89%)
Mutual labels:  emulation
ida2ghidra-kb
IDA Pro to Ghidra Key Bindings to feel like if you were in IDA Pro when navigating
Stars: ✭ 74 (+105.56%)
Mutual labels:  ghidra
mupen64plus-libretro-nx
Improved mupen64plus libretro core reimplementation
Stars: ✭ 139 (+286.11%)
Mutual labels:  emulation
kaiju
CERT Kaiju is a binary analysis framework extension for the Ghidra software reverse engineering suite. This repository is the primary, canonical repository for this project -- file bug reports and wishes here!
Stars: ✭ 150 (+316.67%)
Mutual labels:  ghidra
venix
No description or website provided.
Stars: ✭ 22 (-38.89%)
Mutual labels:  emulation
vscode-cc65-debugger
VSCode extension for CC65 debugging with VICE or Mesen
Stars: ✭ 26 (-27.78%)
Mutual labels:  emulation
pretendo
A multiplatform NES emulator
Stars: ✭ 36 (+0%)
Mutual labels:  emulation
Ghidra
As it is obvious from the name this is version of NSA Ghidra which actually could be built from sources
Stars: ✭ 24 (-33.33%)
Mutual labels:  ghidra
ghidra scripts
Ghidra scripts for malware analysis
Stars: ✭ 53 (+47.22%)
Mutual labels:  ghidra
dskalyzer
DSKalyzer Apple II disk image management tool
Stars: ✭ 23 (-36.11%)
Mutual labels:  emulation
yupi
🎲 open source gaming emulator for flash based games
Stars: ✭ 28 (-22.22%)
Mutual labels:  emulation
worldwide
A toy GameBoy Color emulator written in golang.
Stars: ✭ 563 (+1463.89%)
Mutual labels:  emulation

ghidra-emu-fun

Ghidra Emulates Functions

The love child of Ghidra and an Emu

This repo hosts a Ghidra script that offers a frontend for Ghidra P-code emulator.

The mission of this project is making the emulation of a function as fun as possible.

Quick Start

Download Ghidra 9.1.2

To install this script, clone the repository and add the src directory to the Script Manager.

Open a binary in Ghidra and run emulate_function.py from the script manager.

You should see a new window with a button and a text field. Usually we dock the "console" window right above the emulator plugin window so we can get an experience closer to normal debuggers.

Roadmap

There will probably be a new release after CSAW ESC 2020 (late November) with some of the items below

So here are the next things that we are going to work on:

  • Better documentation and tutorials
  • Richer library of implemented hooks
  • Maybe syscall modelling (but don't count of that)
  • Better handling of symbols and types (especially with regards to hooks)
  • Implement default behaviour for pcode user ops
    • Add instruction hooks

Technical Curiosities

Hooks

So Sleigh allows great flexibility when defining the P-code translation of an instruction, as such there can be code fragments that Ghidra cannot emulate correctly.

We added function hooking to allow the emulation of dynamically linked binaries and bypassing of functions with unsupported P-code instructions.

There is a bit of magic to make writing hooks a fun experience. Take for example the puts implementation in lib/libc6.py:

@hooks.args
def puts(p):
    s = []
    i = 0
    while p[i] != '\x00' and i < 1000:
        s.append(p[i])
        i += 1
    logger.info('puts: {}'.format(repr(''.join(s))))
    return 1

To make the same implementation of the hook work across different architectures we look at the storage location of the parameters as detected by the decompiler. So as long as the function signature is correct, things "should just work". For example, we used the hooks at CSAW ESC on ARM32 binaries and on GameBoy Z80 16-bit architecture for the presentation at DEF CON Group Rome.

If you compare writing a hook like this with other emulation frameworks, you should see that there are some merits in leveraging a mature reverse engineering platform.

The hooks.args function decorator wraps the python implementation of puts and tries to automatically read the parameters from the emulator state.

There are some interesting ideas that we need to complete: at the moment the DataType extracted from Ghidra's analysis (or from manual annotation on Ghidra) are only used to compute the size of the DataType or to distinguish between values and pointers.

Currently values will be converted to byte strings and pointers will be converted into NativePointers which serve to mediate memory read and writes to the emulator.

Since the signature of puts is int puts(char *p) when the emulation hits the hook, the plugin will wrap the relevant portion of memory into a NativePointer (e.g. on Linux x86-64, p will be a NativePointer with base address equal to rdi, but on ARM32 the base address will be r0).

For a dynamically linked binary, the plugin will try automatically to match any import against the functions that have been implemented in lib.

Contributors

This repository was created from a flattened version of the original repository that we used for CSAW ESC, so the activity shown on GitHub may not reflect the actual contributions made by our team members.

I would like to thank matteojug for large refactories of the code base, for polishing the ui a bit and for bending jython to register a Ghidra Plugin without using Java.

I also want to thank pietroborrello, CristianRichie and B4dSheeP for testing the emulator.

Finally I would like to thank andreafioraldi for the precious feedback.

Also for submitting pull requests:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].