GithubHelp home page GithubHelp logo

jinterpose's Introduction

JInterpose

LD_PRELOAD, but for Java applications.

This is a proof-of-concept - there is a lot to do to be actually useful.

This leverages the Java Agent feature to instrument the application, and ASM to edit the code at runtime.

The configuration is in protobuf Text Format. The format is defined in com/pimzero/jinterpose/Proto.proto.

While the user needs to keep in mind low-level Java details in mind while writing the configuration, this project aims to describe the instrumentations/transformations in the configuration file in a "declarative" manner.

Dependencies:

The build system is GNU Makefile, as I am not used to standard Java ecosystem tools. This has the following drawbacks:

  • Dependencies versions need to be updated manually in the Makefile
  • Dependencies between files need to be explicitly defined manually

Example

The initial goal of this project was to have a "pretty" dark-mode in bindiff (although not needed anymore now that bindiff is opensource ๐Ÿ˜Š). While the -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel goes a long way, there are still a few gaps. See for instance the "Workspace" tab.

$ java -Dawt.useSystemAAFontSettings=on \
       -Dswing.aatext=true \
       -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel \
       -jar /opt/bindiff/bin/bindiff.jar

The Workspace tab has white text on a white background

With the help of a debugger, we can find that when creating a new tab, the color is hardcoded to the WORKSPACE_TAB_COLOR field. With JInterpose, we can interpose to use another field instead, such as java/awt/Color.BLACK.

$ cat example.textproto
action {
	when {
		and {
			expr {
				match {
					classname: "com/google/security/zynamics/bindiff/gui/tabpanels/TabPanelManager"
				}
			}
			expr {
				match {
					methodname: "addTab"
				}
			}
		}
	}
	do {
		field_interposition {
			src_owner: "com/google/security/zynamics/bindiff/gui/tabpanels/TabPanelManager"
			src_name: "WORKSPACE_TAB_COLOR"
			dst_owner: "java/awt/Color"
			dst_name: "BLACK"
		}
	}
}
$ # This is the same command as earlier, but with -javaagent:out/agent.jar=example.textproto to use the agent with the config
$ java -javaagent:out/agent.jar=example.textproto \
       -Dawt.useSystemAAFontSettings=on \
       -Dswing.aatext=true \
       -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel \
       -jar /opt/bindiff/bin/bindiff.jar

The Workspace tab has white text on a white background

This works by applying all the transformations defined in the do section for all the methods matched by the when clause of the config.

For a list of supported actions, see com/pimzero/jinterpose/Proto.proto

jinterpose's People

Contributors

pimzero avatar

Stargazers

 avatar

Watchers

 avatar  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.