Skip to content

Commit a774a25

Browse files
committed
Clean up code for CodeClimate
1 parent 57afb0f commit a774a25

13 files changed

+204
-138
lines changed

.codeclimate.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
engines:
3+
duplication:
4+
enabled: true
5+
config:
6+
languages:
7+
- ruby
8+
- javascript
9+
- python
10+
- php
11+
fixme:
12+
enabled: true
13+
rubocop:
14+
enabled: true
15+
checks:
16+
Metrics/LineLength:
17+
Enabled: false
18+
19+
Metrics/MethodLength:
20+
CountComments: false
21+
Max: 30
22+
23+
Style/IndentationWidth:
24+
Enabled: false
25+
26+
Style/LeadingCommentSpace:
27+
Enabled: false
28+
29+
Style/DoubleNegation:
30+
Enabled: false
31+
32+
Style/TrailingComma:
33+
Enabled: false
34+
35+
Documentation:
36+
Enabled: false
37+
ratings:
38+
paths:
39+
- "**.inc"
40+
- "**.js"
41+
- "**.jsx"
42+
- "**.module"
43+
- "**.php"
44+
- "**.py"
45+
- "**.rb"
46+
exclude_paths:
47+
- spec/

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ Style/TrailingComma:
1818
Enabled: false
1919

2020
Documentation:
21-
Enabled: false
21+
Enabled: false

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Caleb Fenton
3+
Copyright (c) 2016 Caleb Fenton
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Oracle
2+
23
A pattern based Dalvik deobfuscator which uses limited execution to improve semantic analysis. Also, the inspiration for another Android deobfuscator: [Simplify](https://github.com/CalebFenton/simplify).
34

45
[![Gem Version](https://badge.fury.io/rb/dex-oracle.svg)](https://badge.fury.io/rb/dex-oracle)
@@ -11,38 +12,59 @@ A pattern based Dalvik deobfuscator which uses limited execution to improve sema
1112
**After**
1213
![after](http://i.imgur.com/aFFd9eM.png)
1314

15+
_sha1: a68d5d2da7550d35f7dbefc21b7deebe3f4005f3_
16+
17+
_md5: 2dd2eeeda08ac8c15be8a9f2d01adbe8_
18+
1419
## Installation
1520

1621
### Step 1. Install Smali / Baksmali
17-
I'm sure since you're an elite Android reverser you already have smali and baksmali on your path.
22+
23+
Since you're an elite Android reverser, I'm sure you already have Smali and Baksmali on your path. If for some strange reason it's not already installed, this should get you started, but please examine it carefully before running:
24+
25+
```bash
26+
mkdir ~/bin || cd ~/bin
27+
curl --location -O https://bitbucket.org/JesusFreke/smali/downloads/smali-2.1.2.jar && mv smali-*.jar smali.jar
28+
curl --location -O https://bitbucket.org/JesusFreke/smali/downloads/baksmali-2.1.2.jar && mv baksmali-*.jar baksmali.jar
29+
curl --location -O https://bitbucket.org/JesusFreke/smali/downloads/smali
30+
curl --location -O https://bitbucket.org/JesusFreke/smali/downloads/baksmali
31+
chmod +x ./smali ./baksmali
32+
export PATH=$PATH:$PWD
33+
```
1834

1935
### Step 2. Install Android SDK / ADB
36+
2037
Make sure `adb` is on your path.
2138

2239
### Step 3. Install the Gem
23-
```
40+
41+
```bash
2442
gem install dex-oracle
2543
```
2644

2745
Or, if you prefer to build from source:
28-
```
46+
47+
```bash
2948
git clone https://github.com/CalebFenton/dex-oracle.git
3049
cd dex-oracle
3150
gem install bundler
3251
bundle install
3352
```
3453

3554
### Step 4. Connect a Device or Emulator
55+
3656
_You must have either an emulator running or a device plugged in for Oracle to work._
3757

3858
Oracle needs to execute methods on an live Android system. This can either be on a device or an emulator (preferred). If it's a device, _make sure you don't mind running potentially hostile code on it_.
3959

4060
If you'd like to use an emulator, and already have the Android SDK installed, you can create and start emulator images with:
41-
```
61+
62+
```bash
4263
android avd
4364
```
4465

4566
## Usage
67+
4668
```
4769
Usage: dex-oracle [opts] <APK / DEX / Smali Directory>
4870
-h, --help Display this screen
@@ -60,18 +82,20 @@ Usage: dex-oracle [opts] <APK / DEX / Smali Directory>
6082

6183
For example, to only deobfuscate methods in a class called `Lcom/android/system/admin/CCOIoll;` inside of an APK called `obad.apk`:
6284

63-
```
85+
```bash
6486
dex-oracle -i com/android/system/admin/CCOIoll obad.apk
6587
```
6688

6789
## How it Works
90+
6891
Oracle takes Android apps (APK), Dalvik executables (DEX), and Smali files as inputs. First, if the input is an APK or DEX, it is disassembled into Smali files. Then, the Smali files are passed to various plugins which perform analysis and modifications. Plugins search for patterns which can be transformed into something easier to read. In order to understand what the code is doing, some Dalvik methods are actually executed with and the output is collected. This way, some method calls can be replaced with constants. After that, all of the Smali files are updated. Finally, if the input was an APK or a DEX file, the modified Smali files are recompiled and an updated APK or DEX is created.
6992

70-
Method execution is performed by the [Driver](driver/src/main/java/org/cf/oracle/Driver.java). The input APK, DEX, or Smali is combined with the Driver into a single DEX using dexmerge and pushed onto a device or emulator. Oracle then sends method execution information to Driver whenever a plugin requests it. Driver uses Java reflection to execute methods within its own DEX with the arguments provided by Oracle and returns any output or exceptions. This is especially useful for many string decryption methods, which usually take an encrypted string or some One limitation is that execution is limited to static methods.
93+
Method execution is performed by the [Driver](driver/src/main/java/org/cf/oracle/Driver.java). The input APK, DEX, or Smali is combined with the Driver into a single DEX using dexmerge and is pushed onto a device or emulator. Plugins can then use Driver which uses Java reflection to execute methods from the input DEX. The return values can be used to improve semantic analysis beyond mere pattern recognition. This is especially useful for many string decryption methods, which usually take an encrypted string or some byte array. One limitation is that execution is limited to static methods.
7194

7295
## Hacking
7396

7497
### Creating Your Own Plugin
98+
7599
There are three [plugins](lib/dex-oracle/plugins) which come with Oracle:
76100

77101
1. [Undexguard](lib/dex-oracle/plugins/undexguard.rb) - removes certain types of Dexguard obfuscations
@@ -95,6 +119,7 @@ The included plugins should be a good guide for understanding steps #3 and #4. D
95119
Of course, you're always welcome to share whatever obfuscation you come across and someone may eventually get to it.
96120

97121
### Updating Driver
122+
98123
First, ensure `dx` is on your path. This is part of the Android SDK, but it's probably not on your path unless you're hardcore.
99124

100125
The [driver](driver) folder is a Java project managed by Gradle. Import it into Eclipse, IntelliJ, etc. and make any changes you like. To finish updating the driver, run `./update_driver`. This will rebuild the driver and convert the output JAR into a DEX.

bin/dex-oracle

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ optparse = OptionParser.new do |opts|
2929
options[:device_id] = id
3030
end
3131

32-
opts.on('-t', '--timeout N',
32+
opts.on('-t', '--timeout N', Integer,
3333
"ADB command execution timeout in seconds, default=\"#{options[:timeout]}\"") do |id|
3434
options[:timeout] = id
3535
end

dex-oracle.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ EOF
2222
[:development, 'rspec-mocks', '~> 3.4', '>= 3.4.0'],
2323
]
2424

25-
exclude_files = Dir['driver/build/**/*'] + Dir['driver/bin/**/*'] + Dir['sandbox/**/*'] + ['driver/build', 'driver/bin', 'sandbox']
25+
exclude_files = Dir['driver/build/**/*'] + Dir['driver/bin/**/*'] + Dir['sandbox/**/*'] + %w(driver/build driver/bin sandbox)
2626
s.files = Dir['**/*'] - exclude_files
2727
s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
2828
s.executables = Dir['bin/*'].map { |f| File.basename(f) }

0 commit comments

Comments
 (0)