Giter Club home page Giter Club logo

ghidra-jni's Introduction

ghidra-jni

All in-one jni.h compiled for Ghidra.

How to load in Ghidra?

Go to File -> Parse C Source

Create a new Parse Configuration Profile with the following Parse Options

-D_X86_
-D__STDC__
-D_GNU_SOURCE
-D__WORDSIZE=64
-Dva_list=void *
-D__DO_NOT_DEFINE_COMPILE
-D_Complex
-D_WCHAR_T
-D__NO_STRING_INLINES
-D__signed__
-D__extension__=""
-D_Bool="bool"
-D__GLIBC_HAVE_LONG_LONG=1
-D__need_sigset_t
-Daligned_u64=uint64_t
-Daligned_u64=uint64_t

Under source files to parse, add jni-ghidra.h to the list. Remove any other existing file (if any).

How was this generated ?

The default jni.h from Java fails to parse correctly in Ghidra. As a result, I have taken a precompiled jni.h intended for IDA Pro from here and pre-processed it (gcc -E/cpp). The pre-processed file contain several lines begining with # which correspond to source files. These lines must be removed or else Ghidra will fail to parse.

As a result of pre-processing this does not contain C++ definitions for the various JNI types. If you want C++ type definitions as well use the one intended for IDA Pro.

Useful Info

Adding a function data type using the API

A function data type can also be added using the Ghidra Python API. An example is shown below

from ghidra.app.util.cparser.C.CParserUtils import parseSignature
from ghidra.program.model.data import DataTypeConflictHandler 

fn_sign = 'void function1(int p1, int p2)'
fn_defn = parseSignature(None, currentProgram, fn_sign)
dtm = currentProgram.getDataTypeManager()
dtm.addDataType(fn_defn, DataTypeConflictHandler.DEFAULT_HANDLER)

Creating structures programmatically

From my answer on RE.SE

from ghidra.program.model.data import DataTypeConflictHandler
from ghidra.app.util.cparser.C import CParser

mystruct_txt = """
struct mystruct{
    uint32_t field1; 
    uint32_t field2;
};"""

# Get Data Type Manager
data_type_manager = currentProgram.getDataTypeManager()

# Create CParser
parser = CParser(data_type_manager)

# Parse structure
parsed_datatype = parser.parse(mystruct_txt)

# Add parsed type to data type manager
data_type_manager.addDataType(parsed_datatype, DataTypeConflictHandler.DEFAULT_HANDLER)

ghidra-jni's People

Contributors

extremecoders-re avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.