Coder Social home page Coder Social logo

spanalysis's Introduction

SPAnal

This repository contains a suite of scripts useful for analyzing iOS armv7 binaries in Radare2. It is titles SPAnal because the original target binary for these scripts was Spotify.

Motivation

My usual disassembler of choice is IDA but the free version does not support armv7. Ghidra's decompiler takes until the heat death of the universe to decompile a binary on the order of 10's of MB. Therefore, I use Radare2. However, Radare2's auto-analysis also takes ages and gigabytes of memory on such a large binary. The goal of these scripts is to basically perform the analysis Radare2 would normally do on selected classes or methods so that it doesn't take so long.

Scripts

get_classlist.py

This script walks the __objc_classlist section of the Mach-O file and builds a JSON object of the classes defined in the binary. The JSON object is formatted as such:

{
	<class name>: {
		"methods": {
			<selector name>: <implementation pointer>,
			...
		},
		"ivars": {
			<instance variable name>: <instance variable type>,
			...
		}
	},
	...
}

This script performs basically the same function as the classdump tool but formats the output as a JSON file. The name of the output file is specified as the first commandline argument.

process_class.py

This script uses the JSON classes object generated by get_classlist.py to process every method of a certain class using the process_method.py script. The class name is specified as the first commandline argument.

process_method.py

Tells Radare2 to analyze the given method and then resolves the selectors used and receivers of objc_msgSend calls from within the function. The method name is specified as the first commandline argument and is formatted as ..

resolve_selectors.py

Tells Radare2 to analyze the function at the given address and then resolves the selectors used from within the function. This is done by iterating through each disassembled instruction and building up a table mapping registers to selectors. This can be performed because on armv7 (at least on all of the binaries I have analyzed), selector addresses are loaded into registers like so:

movw <reg a>, low 2 bytes of address
movt <reg a>, high 2 bytes of address
add <reg a>, pc
ldr <reg b>, [<reg a>]

Then the table can be updated when is moved into r1, the sel param for objc_msgSend.

resolve_receivers.py

Using the class information from get_classlist.py and the selector information from resolve_selectors.py, this script tries to infer the type of receiver in each call to objc_msgSend. This is performed by building up a table mapping the instantiated types in scope to the selector that created them. Since instance variables are actually accessed through selectors (such as <ivar> and set<ivar>:), when we see a selector that is also the name of an instance variable for the current class, we know that the type of the ivar is in scope.

We can then look to see if subsequent selectors are in fact selectors of an instantiated ivar type and update our table if it is.

spanalysis's People

Contributors

saml98 avatar

Watchers

James Cloos 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.