Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[DEV][Work-In-Progress][C#] Direct Smali to Java converter

OP darkguy2008

Announcement from darkguy2008: Github: https://github.com/darkguy2008/smali2java - IRC: #smali2java in freenode.net !
31st December 2013, 01:46 PM   |  #1  
darkguy2008's Avatar
OP Senior Member
Flag Caracas
Thanks Meter: 229
 
645 posts
Join Date:Joined: Apr 2011
Donate to Me
More
DIRECT SMALI TO JAVA CONVERTER

(This is a work-in-progress. Hop in if you can help!)


Welcome guys!

This project is born because there isn't any reliable way to convert a bunch of smali files into something you can really import into eclipse and compile away. I've lost a few projects in a recent 1 TB HDD crash and man, it wasn't pretty to see I couldn't even get them back with JD-GUI or something. I've done the same with a few .NET projects of mine, so why can't I on Android? you can, but sometimes the tools (JD-GUI or JAD) go nuts and attempting to fix them just gives you a headache so...

Being a smali modder for quite some time, I managed to realize that the entire smali code, if analyzed correctly, it can be converted back to java. We mentally do it when we make smali mods, all I'm attempting to do is to automate the process and make it easier for everyone. Also, it would be really useful to be able to recompile a few Jars and APKs in order to fix device bugs (which is also another reason why I'm working on this).

Some of you would say there is already JD-GUI and JAD, but they're not a real true 1:1 conversion and also most of the times they're not compile-able. Also, There's JEB Android Decompiler but no way I'm gonna pay such a price for something I've been doing mentally and that I can automate with a script made in about a week or a few months. The tool could be great, but the price is too high and my own country's restrictions don't allow me to buy it even if I ever get the money.

The idea here, is to make an app that can translate Smali to Java, directly. Of course, it requires a bit of analysis. It needs to analyze the class directives, the methods and their prologue (parameters, declaration, etc), class annotations and method instructions. So far, I've managed to develop most of the analyzer with a few basic instructions set up for demo purposes.

Of course, I know it needs a bit more work: some variables/instructions don't appear, types are incomplete or missing, etc. But that's why I'm here: I can work on this alone, but, first, it wouldn't be fair. Also, I'm human and by default I have bugs, so I might skip something and make the code go bogus and stuff. And finally, I'd like to request the help of the community. I made this project to see if there's enough attention and contribution from the smart people here, and if there is, I'm gonna give it all to make this project do what it says, 100% error-free.

Note: IT NEEDS .NET FRAMEWORK 3.5. Yeah, and VS 2012. I assume you can make it work with VS2010 or I can make a version soon if there's enough interest, or heck, even Mono as long as it has Linq (I make heavy use of it). The idea is to make a good, open-source parser you can compile even on an arduino with Mono and it will work. But for now, this will have to do. It is my own code and I decided to share it to see if there's interest. If there's enough, I'll do everything I can to provide the tools needed for you guys to help me make this project a reality.

Also, it seems it works with SharpDevelop, so you can compile it under Linux too! :)

How to contribute:

Source code (active Github): https://github.com/darkguy2008/smali2java
IRC Channel: #smali2java in irc.freenode.net . You can also join us in development chit-chat through web IRC client here.

Fork away!

Well, hoping to attract the attention of you hackers 'round here :)
- DARKGuy

XDA:DevDB Information
Smali2Java, a Tool/Utility for the Android General

Contributors
darkguy2008

Version Information
Status: Testing

Created 2013-12-31
Last Updated 2014-01-04
Attached Thumbnails
Click image for larger version

Name:	ScreenShot022.jpg
Views:	2811
Size:	164.6 KB
ID:	2494080  
The Following 64 Users Say Thank You to darkguy2008 For This Useful Post: [ View ]
31st December 2013, 01:46 PM   |  #2  
darkguy2008's Avatar
OP Senior Member
Flag Caracas
Thanks Meter: 229
 
645 posts
Join Date:Joined: Apr 2011
Donate to Me
More
Reserved
The Following 3 Users Say Thank You to darkguy2008 For This Useful Post: [ View ]
1st January 2014, 03:34 AM   |  #3  
robcore's Avatar
Senior Member
Thanks Meter: 47
 
127 posts
Join Date:Joined: Jul 2012
Thanks for your effort. May I request a small readme or setup guide as I'm generally a Linux user trying this out on my Windows machine?

Sent from my SAMSUNG-SGH-I727 using Tapatalk
1st January 2014, 07:50 AM   |  #4  
Ricky Divjakovski's Avatar
Recognized Contributor
Flag Sydney
Thanks Meter: 5,372
 
3,629 posts
Join Date:Joined: Feb 2013
Donate to Me
More
This is great, really interested in this, and is the project open source?
1st January 2014, 08:05 AM   |  #5  
darkguy2008's Avatar
OP Senior Member
Flag Caracas
Thanks Meter: 229
 
645 posts
Join Date:Joined: Apr 2011
Donate to Me
More
Quote:
Originally Posted by robcore

Thanks for your effort. May I request a small readme or setup guide as I'm generally a Linux user trying this out on my Windows machine?

Sent from my SAMSUNG-SGH-I727 using Tapatalk

Hello!

Oh, sure, here's a small resume but if you need more help don't hesitate to ask

First you need to install Visual Studio 2010 or Visual Studio 2012, I don't know if the express editions work, but they should. Then, if you use VS2010, you need to install the 4.5 .NET Targeting Pack for VS2010 which you can find on the MS website. If you install VS2012, it comes with it preinstalled.

Then, I assume you can double-click the .csproj (project file) and it'll open inside a blank solution that will ask you to save before you can compile it (press F5 to build & run). Also, make sure to edit Program.cs and modify it where it says to edit and put the absolute path of a smali file of your choice (for example, C:\users\you\desktop\someclass.smali). There's no need to put double-backslashes due to the "@" before the string literal.

Also, I think it could also work with .NET 3.5 or 4.0, but I didn't test it as I was hesitant to make something that I could publish on here. Over the next few days I'll keep working on it and keep you guys updated

Quote:
Originally Posted by ricky310711

This is great, really interested in this, and is the project open source?

Thanks for your interest! I'm glad and yes! you can download the whole source code and binary from the Download section here in the black top bar over the first post. That's the idea open-source and easy to understand!
The Following 2 Users Say Thank You to darkguy2008 For This Useful Post: [ View ]
1st January 2014, 08:34 AM   |  #6  
Ricky Divjakovski's Avatar
Recognized Contributor
Flag Sydney
Thanks Meter: 5,372
 
3,629 posts
Join Date:Joined: Feb 2013
Donate to Me
More
Quote:
Originally Posted by darkguy2008


Thanks for your interest! I'm glad and yes! you can download the whole source code and binary from the Download section here in the black top bar over the first post. That's the idea open-source and easy to understand!

Thanks will definately check it out when I get home!
1st January 2014, 01:17 PM   |  #7  
robcore's Avatar
Senior Member
Thanks Meter: 47
 
127 posts
Join Date:Joined: Jul 2012
Thanks so much, trying it now!

Sent from my SAMSUNG-SGH-I727 using Tapatalk
2nd January 2014, 04:48 PM   |  #8  
darkguy2008's Avatar
OP Senior Member
Flag Caracas
Thanks Meter: 229
 
645 posts
Join Date:Joined: Apr 2011
Donate to Me
More
Alright, I finally learned how to use GitHub (it wasn't that hard... yet, lol), so here's a link for you all to try (it's in the main post, too): https://github.com/darkguy2008/smali2java

Also, I modified the code a bit... removed the whole switch/case stuff for each instruction and changed it to functions. Also, SmaliVM is now the main class where the translation to Java happens. I've also made a "buffer system" because, in smali, you need to process a lot of lines to create one Java line, so every smali line adds up stuff to the buffer (if needed) and it "flushes" on each .line directive. So far, so good.

Fork away and I'm eager to see your pull requests!
Last edited by darkguy2008; 2nd January 2014 at 07:35 PM.
2nd January 2014, 07:27 PM   |  #9  
Ricky Divjakovski's Avatar
Recognized Contributor
Flag Sydney
Thanks Meter: 5,372
 
3,629 posts
Join Date:Joined: Feb 2013
Donate to Me
More
Quote:
Originally Posted by darkguy2008

Alright, I finally learned how to use GitHub (it wasn't that hard... yet, lol), so here's a link for you all to try (it's in the main post, too): https://github.com/darkguy2008/smali2java

Also, I modified the code a bit... removed the whole switch/case stuff for each instruction and changed it to functions. Also, SmaliVM is now the main class where the translation to Java happens. I've also made a "buffer system" because, in smali, you need to process a lot of lines to create one Java line, so every smali line adds up stuff to the buffer (if needed) and it "flushes" on each .line directive. So far, so good.

Fork away and I'm eager to see your pull requests!

404 not found?
2nd January 2014, 07:36 PM   |  #10  
darkguy2008's Avatar
OP Senior Member
Flag Caracas
Thanks Meter: 229
 
645 posts
Join Date:Joined: Apr 2011
Donate to Me
More
Quote:
Originally Posted by ricky310711

404 not found?

Whoops, sorry, fixed! stupid reply box, it ate the "va" in my "java" lol.

It's also corrected in the main post :P

Post Reply Subscribe to Thread

Tags
converter, deodex, direct, java, smali
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes