All Projects → amoulu → Tinysmaliemulator

amoulu / Tinysmaliemulator

A very minimalist smali emulator that could be used to "decrypt" obfuscated strings

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Tinysmaliemulator

Andtroj
A tool for integrating the Metasploit payload with Android's healthy programs and bypassing antivirus
Stars: ✭ 43 (-36.76%)
Mutual labels:  obfuscation, smali
Obfuscapk
An automatic obfuscation tool for Android apps that works in a black-box fashion, supports advanced obfuscation features and has a modular architecture easily extensible with new techniques
Stars: ✭ 456 (+570.59%)
Mutual labels:  obfuscation, smali
Zxpoly
ZX-Poly platform info page and its emulator. It is a multi-CPU ZXSpectrum clone.
Stars: ✭ 60 (-11.76%)
Mutual labels:  emulator
Wechat
modified wechat
Stars: ✭ 66 (-2.94%)
Mutual labels:  smali
Clocal Gcp
🔭 Emulation engine for GCP
Stars: ✭ 63 (-7.35%)
Mutual labels:  emulator
Sega System For Fpga
FPGA Sega in Verilog, for Xilinx Virtex, circa 2002. Has an emulator thrown in, to simplify FPGA debugging.
Stars: ✭ 61 (-10.29%)
Mutual labels:  emulator
Skater .net Obfuscator
Skater .NET Obfuscator is an obfuscation tool for .NET code protection. It implements all known software protection techniques and obfuscation algorithms.
Stars: ✭ 64 (-5.88%)
Mutual labels:  obfuscation
Obfs4proxy Openvpn Linux
Obfuscating OpenVPN traffic using obfs4proxy - Linux platform
Stars: ✭ 57 (-16.18%)
Mutual labels:  obfuscation
Cryboy
A Game Boy (Color) emulator written in Crystal
Stars: ✭ 68 (+0%)
Mutual labels:  emulator
Xterm.dart
💻 xterm.dart is a fast and fully-featured terminal emulator for Flutter, with support for mobile and desktop platforms.
Stars: ✭ 63 (-7.35%)
Mutual labels:  emulator
Dsui
Datastore Emulator UI
Stars: ✭ 66 (-2.94%)
Mutual labels:  emulator
Play
Play! - PlayStation 2 Emulator
Stars: ✭ 1,117 (+1542.65%)
Mutual labels:  emulator
Obfuscation Stuff
Source Code Obfuscation And Binary Obfuscation, Multiple Languages And Multiple Platforms. Including 250+ Tools and 600+ Posts
Stars: ✭ 61 (-10.29%)
Mutual labels:  obfuscation
Chameleonmini
The ChameleonMini is a versatile contactless smartcard emulator compliant to NFC. The ChameleonMini was developed by https://kasper-oswald.de. The device is available at https://shop.kasper.it. For further information see the Getting Started Page https://rawgit.com/emsec/ChameleonMini/master/Doc/Doxygen/html/_page__getting_started.html or the Wiki tab above.
Stars: ✭ 1,133 (+1566.18%)
Mutual labels:  emulator
Simplesmali
通过精简Smali语法细节来增强反编译代码阅读性,自定义了一种简单语法
Stars: ✭ 61 (-10.29%)
Mutual labels:  smali
Bizhawk
BizHawk is a multi-system emulator written in C#. BizHawk provides nice features for casual gamers such as full screen, and joypad support in addition to full rerecording and debugging tools for all system cores.
Stars: ✭ 1,138 (+1573.53%)
Mutual labels:  emulator
Projectdmg
C# GameBoy Emulator
Stars: ✭ 57 (-16.18%)
Mutual labels:  emulator
Tapir
RGSS compatible runtime (namely: emulator for RPG Maker XP, VX, and VX Ace)
Stars: ✭ 60 (-11.76%)
Mutual labels:  emulator
Gritty
web terminal emulator
Stars: ✭ 63 (-7.35%)
Mutual labels:  emulator
Gcam
Stars: ✭ 68 (+0%)
Mutual labels:  smali

TinySmaliEmulator

TL;DR

A very minimalist smali emulator that could be used to decrypt obfuscated strings.

This repo is composed of:

  • emulator.py, a basic smali emulator.
  • AndroguardEmulator.py, an example of how to use this emulator in androguard to deobfuscate whatsapp strings.
  • poc.dex, a class extracted from a whatsapp obfuscated version used by AndroguardEmulator.py to demo how it works.
  • DexguardEmulator.py, an example of how to use this emulator in JEB1 to deobfuscate strings protected by Dexguard 6.X.
  • jebAST.py, a basic JEB AST evaluator used by DexguardEmulator.py to try to discover the real values of parameters passed to the decryptString() functions.

Beware: this is really a dirty code, please keep in mind it was only a PoC.

Longer version

I wrote this initially to deal with Dexguard 6.x string obfuscation scheme.

When you have to deal with Dexguard 6.X, for each class with obfuscated strings, you have to find several elements:

  • a magic (a random int)
  • an "encrypted" array of bytes
  • a decryptString() method

For example:

dexguard_sample.png

In Dexguard 6.X, these different elements will have a different name in each protected class. Moreover, decryptString() for each class will have some variation in its implementation, you can't just reimplement it in python and use it for the entire APK. To solve this problem, I developped a basic smali emulator that will run decryptString() functions and return the deobfuscated strings.

But you also have to deal with the fact that Dexguard do now some calculation on the paramaters passed to decryptString(), you can't have directly the values as before.

For example, before you had things like:

decryptString(40,10,-2);
decryptString(1,-5,60);

Now you have things like:

decryptString(40, X.encBytes[12], (X.encBytes[9] & 8) + X.randomByte);
decryptString(0, (short)-X.encBytes[6], 10);
int v0 = 10; 
byte[] v1 = X.encBytes; 
v2 = v1[90]; 
decryptString(v2, v1[40] + v0, v1[2] >> X.randomByte);

To solve this problem I developped also a basic JEB AST evaluator to "calculate" the final values passed to decryptString() functions.

Finally I put these two modules in a JEB1 Plugin (DexguardEmulator.py). This plugin will identify for the current class (it can obviously be automated to all the classes in the APK) the important Dexguards elements (the magic, the encrypted array of byte and the decryptString() method), then for each call to decryptString() it will use the AST evaluator to get the true values passed as paramaters and finally it will run the smali emulator on decryptString() with the previously discovered parameters. And thanks to the powerfull JEB1 AST API, it replaces every call to decryptString() by the deobfuscated string.

An example of the result:

dexguard_result.png

Bonus

I also made a PoC to use the emulator in Androguard, it's implemented in AndroguardEmulator.py. This time, we will take whatsapp string obfuscation as a target.

I extracted a single obfuscated class from a Whatsapp APK file and put it in poc.dex to demo the Androguard emulation.

Basically, at runtime, the obfuscator will deobfuscate every strings used in the current class in a array of String and this is done in the <clinit> method of the class. If the original class has already some code in the <clinit> method, the obfuscator just prepend its deobfuscation code.

I will not explain the obfuscation here, you can have a look at poc.dex, it's really easy. You just have to know that the deobfuscation code finish with a sput-object smali instruction to place the deobfuscated array of String into a static array of String. Then, each time the application will need to use a deobfuscated string, it will reference an entry in the static array of String.

This time, in order to deobfuscate the strings, we just have to let the emulator execute the <clinit> method. To not have to deal with already existing complex code in <clinit> just after the debofuscation code, we can put a breakpoint in the emulator on the instruction sput-object, print the deobfuscated strings and stop the emulation.

Below is an example of output of the AndroguardEmulator.py script on poc.dex:

androguard_result.png

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