Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,770,879 Members 43,477 Now Online
XDA Developers Android and Mobile Development Forum
Announcement from darkguy2008: Github: https://github.com/darkguy2008/smali2java - IRC: #smali2java in freenode.net !

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

Tip us?
 
darkguy2008
Old
#1  
darkguy2008's Avatar
Senior Member - OP
Thanks Meter 223
Posts: 645
Join Date: Apr 2011
Location: Caracas

 
DONATE TO ME
Default [DEV][Work-In-Progress][C#] Direct Smali to Java converter

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:	2154
Size:	164.6 KB
ID:	2494080  
The Following 60 Users Say Thank You to darkguy2008 For This Useful Post: [ Click to Expand ]
 
darkguy2008
Old
#2  
darkguy2008's Avatar
Senior Member - OP
Thanks Meter 223
Posts: 645
Join Date: Apr 2011
Location: Caracas

 
DONATE TO ME
Default Reserved

The Following 3 Users Say Thank You to darkguy2008 For This Useful Post: [ Click to Expand ]
 
robcore
Old
#3  
robcore's Avatar
Senior Member
Thanks Meter 47
Posts: 127
Join Date: 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
 
Ricky Divjakovski
Old
#4  
Ricky Divjakovski's Avatar
Recognized Contributor
Thanks Meter 5254
Posts: 3,591
Join Date: Feb 2013
Location: Sydney

 
DONATE TO ME
This is great, really interested in this, and is the project open source?
Like my blog on facebook, add me to your circles, follow me on twitter or donate to me with paypal
 
darkguy2008
Old
#5  
darkguy2008's Avatar
Senior Member - OP
Thanks Meter 223
Posts: 645
Join Date: Apr 2011
Location: Caracas

 
DONATE TO ME
Quote:
Originally Posted by robcore View Post
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 View Post
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!
Current devices:
ZTE Grand X V970M ["Mimosa X"]
B&N Nook Simple Touch

Previous devices:
HTC Magic 32A (stolen) - FroyoDragon ROM developer
Motorola Defy+ MB525 (sold)
The Following 2 Users Say Thank You to darkguy2008 For This Useful Post: [ Click to Expand ]
 
Ricky Divjakovski
Old
#6  
Ricky Divjakovski's Avatar
Recognized Contributor
Thanks Meter 5254
Posts: 3,591
Join Date: Feb 2013
Location: Sydney

 
DONATE TO ME
Quote:
Originally Posted by darkguy2008 View Post

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!
Like my blog on facebook, add me to your circles, follow me on twitter or donate to me with paypal
 
robcore
Old
#7  
robcore's Avatar
Senior Member
Thanks Meter 47
Posts: 127
Join Date: Jul 2012
Thanks so much, trying it now!

Sent from my SAMSUNG-SGH-I727 using Tapatalk
 
darkguy2008
Old
(Last edited by darkguy2008; 2nd January 2014 at 06:35 PM.)
#8  
darkguy2008's Avatar
Senior Member - OP
Thanks Meter 223
Posts: 645
Join Date: Apr 2011
Location: Caracas

 
DONATE TO ME
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!
Current devices:
ZTE Grand X V970M ["Mimosa X"]
B&N Nook Simple Touch

Previous devices:
HTC Magic 32A (stolen) - FroyoDragon ROM developer
Motorola Defy+ MB525 (sold)
 
Ricky Divjakovski
Old
#9  
Ricky Divjakovski's Avatar
Recognized Contributor
Thanks Meter 5254
Posts: 3,591
Join Date: Feb 2013
Location: Sydney

 
DONATE TO ME
Quote:
Originally Posted by darkguy2008 View Post
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?
Like my blog on facebook, add me to your circles, follow me on twitter or donate to me with paypal
 
darkguy2008
Old
#10  
darkguy2008's Avatar
Senior Member - OP
Thanks Meter 223
Posts: 645
Join Date: Apr 2011
Location: Caracas

 
DONATE TO ME
Quote:
Originally Posted by ricky310711 View Post
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
Current devices:
ZTE Grand X V970M ["Mimosa X"]
B&N Nook Simple Touch

Previous devices:
HTC Magic 32A (stolen) - FroyoDragon ROM developer
Motorola Defy+ MB525 (sold)

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

Advanced Search
Display Modes