[Q] Edit java source from Apk and recompile it - General Topics

Goodmorning,
I use apktool to decompile the apk. I edit some file in res folder, now I want to edit some java source file from apk and recompile with apktool to run the "new" android application.
With Dex2jar & jd-gui i extract the java source code.
Now i want to edit and covert into .smali because Apktool can build the application with smali code.
I found a script that uses 2 file(dx.jar and backsmali.jar)
1- javac myClass.java //compile myClass.java in myClass.dex
2-java -jar tools/dx.jar --dex --output= myClass.dex myClass.class // convert myClass.class in myClass.dex
3-java -jar tools/baksmali.jar -o myClass.smali myClass.dex //convert myClass.dex in myClass.smali
Javac work great it produce the file myClass.class.
The step 2 and 3 makes me trouble,the prompt show me a message:
trouble processing:
bad class file magic (cafebabe) or version (0034.0000)
...while parsing BuildConfig.class
...while processing BuildConfig.class
1 warning
no classfiles specified
Can't find the file BuildConfig.dex
impossible find C:\Users\Lorenzo\Desktop\java2smali\BuildConfig.dex
impossible find the file .
Please someone can help me?
sorry for my english....

Related

need help compiling com.htc.resources.apk

hello
i did make the
java -jar apktool.jar if framework-res.apk
java -jar apktool.jar if com.htc.resources.apk
but when i compile the com.htc.resources.apk
i have a lot errors
error: Error: No resource found that matches the given name: attr 'android:layout_width'.
need some help here.
thanks
found the problem i was compiling with older aapt.exe version

[Tutorial] How to Deodex Lollipop System Files - One by One

Hey guys,
I write this tutorial to help guys deodex individual apps and not all apps or not to do batch deodex.
There are few good tools to Batch Deodex Roms but I found one by one tutorial which was not properly framed...
Though the credits goes to the creator of the tool.
I dont take any credits for that tool and here I just write up a tutorail on how to do it.
Step by Step Tutorial:
- First of all download this zip file of the tools required for the process - Link
- Now, extract the files of the zip to any folder.
- Head over to the directory you extracted the tools. It will contain many files such as baksmali, smali, 7zip etc..
- Now press Shift+Right Click and select Open Command Window Here.
- Now just copy the apk and the .odex.art.xz and odex.xz files in that directory.
- Now in command prompt type the following commands.
Note: Replace * With the name of the apk. (If you dont get it see the Post #2 for eg)
Code:
7za x *.odex.xz
Code:
oat2dex.bat *.odex
Code:
oat2dex.bat *.odex temp.dex
Code:
java -jar baksmali-2.0.3.jar -a 21 -x temp.dex -o deodex
Code:
java -jar smali-2.0.3.jar -a 21 deodex -o classes.dex
Code:
7za u -tzip *.apk classes.dex
Now, the apk you initially coppied is now dexoded. Now you can use that apk the way you want
See post #2 for example
Reserved
Example:
Say I want to Deodex SystemUI for any lollipop rom.
Then, I would do the following
Code:
7za x SystemUI.odex.xz
Code:
oat2dex.bat SystemUI.odex
Code:
oat2dex.bat SystemUI.odex temp.dex
Code:
java -jar baksmali-2.0.3.jar -a 21 -x temp.dex -o deodex
Code:
java -jar smali-2.0.3.jar -a 21 deodex -o classes.dex
Code:
7za u -tzip SystemUI.apk classes.dex
The apk is now deodexed successfully. Enjoy!
hey mate, any chance you can upload a few small .apk files and matching .odex.xz files?
ive got a few test to run for a tool i made but cant because i dont have any android 5.0 devices

[GUIDE] How to build .apk file from command line

Author: Apriorit (Device Team)
If you don’t want to install a number of programs for building your Android project, this article is for you. You will need only JDK, the Android SDK platform tools and minimum Android platform for building the project using the batch file.
1. Introduction
In this article, I will describe how to use the Android tools for building the .apk file using the command line. As a result, you can use the batch file for building your Android application. I use Windows commands in this article. But you can use the same Android commands and tools and the same program if you are working on Linux OS. The example of the script for Linux OS is included in the sample project, attached to this article.
2. Preparation
You must install Java JDK and Android SDK on the system where you will build your Android application using the Windows command line. The private keystore also must be present.
2.1 Java JDK
You can use Java JDK from Eclipse or download it from this link: oracle(dot)com/technetwork/java/javase/downloads/index.html and then install it.
2.2 Android SDK
Android SDK and its HOWTO document are available here: developer.android.com/sdk/index.html[/url].
The Android SDK Platform-tools, SDK Platform Android 2.2, and API 8 are the minimum that is needed for the test project work.
2.3 Environment Variables
If you want to have a readable batch script and a program without very long file path definitions, you should use the environment variables. I recommend you to define the following ones:
• JAVABIN path to the Java JDK bin folder. For example: C:\Program Files\Java\jdk\bin. This folder must contain the javac.exe and jarsigner.exe files.
• ANDROID-SDK path to the Android SDK folder. For example: C:\Program Files\Andoroid\android-sdk-windows.
2.4 Private Key for Signing
You can read everything about signing, creating private key, and other operations here: developer.android(dot)com/guide/publishing/app-signing.html
In this article, I describe only one important command that will generate my-release-key.keystore:
Code:
%JAVABIN%\keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Specify your info and you will receive the my-release-key.keystore file. You must remember the password. You will need it later. Also, I recommend you to put the keystore file in the same folder as the project. In the example,It is in the keystore folder in the project directory.
2.5 Example Files Structure
You must remember that the dx Android tool requires the full path, which MUST not contain any spaces. So, check the fact, that your project path satisfies the requirement.
The file structure of the example project, which is built using the build.bat file, is the following:
Code:
SecureMessages/
assets/
keystore/
my-release-key.keystore
res/
drawable-hdpi/
icon.png
drawable-ldpi/
icon.png
drawable-mdpi/
icon.png
layout/
main.xml
values/
strings.xml
src/
org/
secure/
sms/
SecureMessagesActivity.java
StringCryptor.java
SmsReceiver.java
AndroidManifest.xml
build.bat // Windows build script
build.sh
// Linux build script
3. Command Sequence
The following commands are for the Windows OS, but you can find the script for the Linux OS project building in the attached sample.
First of all, we must save current path. Then we must change the CD variable to the path to the build.bat file:
Code:
SET PREV_PATH=%CD%
cd /d %0\..
Then, bin and gen old folders should be recreated:
rmdir "bin" /S /Q
rmdir "gen" /S /Q
mkdir "bin"
mkdir "gen"
I add some definitions. They make the batch file readable and easy to update. So, I recommend you the following definitions:
• minimum Android revision;
• the path to aapt Android tool and its arguments for adding files into the existing archive;
• the path to aapt Android tool and its arguments for packing and generating resources;
• the path to dx Android tool;
• the path to javac utility of JDK.
This list of independent definitions can be used for building the majority of Android projects (of course, with the changed Android revision value). For example:
Code:
SET ANDROID_REV=android-8
SET ANDROID_AAPT_ADD="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" add
SET ANDROID_AAPT_PACK="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" package -v -f -I "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar"
SET ANDROID_DX="%ANDROID-SDK%\platform-tools\dx.bat" --dex
SET JAVAC="%JAVABIN%\javac.exe" -classpath "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar"
Also I need the defined variables for my project:
• APP_NAME is the name of application that will be used for the output APK file.
• JAVAC_BUILD and JAVAC are the same commands, but there are path to the sources, generated R class, and output folder in JAVAC_BUILD.
These variables let us change the project name and paths to the sources easier.
Code:
SET APP_NAME=SecureSms
SET JAVAC_BUILD=%JAVAC% -sourcepath "src;gen" -d "bin"
And now, all preparations are finished and the application can be built. The R file will be generated using aapt tool. All resources will be packed into the resources.ap_ file:
Code:
call %ANDROID_AAPT_PACK% -M "AndroidManifest.xml" -A "assets" -S "res" -m -J "gen" -F "bin\resources.ap_"
Android manifest file, res and assets folder are the input data. Aapt will generate the R class and put it into the gen folder. Then, aapt will pack the resource files into the resourses.ap_ file.
Every folder that contains *.java file must be called with javac. In my example, there is only one folder with javac. So, I have only one command line for building sources:
Code:
call %JAVAC_BUILD% src\org\secure\sms\*.java
As you remember, the JAVAC_BUILD command has already contained the arguments that specify the bin folder. The bin folder is an output folder for the compiled sources.
At this moment, the sources have been compiled successfully and they can be packed in the special dex file:
Code:
call %ANDROID_DX% --output="%CD%\bin\classes.dex" %CD%\bin
For the application signing, the resources file must be copied to another file, which will be used for the signing:
Code:
copy "%CD%\bin\resources.ap_" "%CD%\bin\%APP_NAME%.ap_"
The classes.dex file must be added to the new file that has an ap_ extension
Code:
call %ANDROID_AAPT_ADD% "%CD%\bin\%APP_NAME%.ap_" "%CD%\bin\classes.dex"
Now, the ap_ file is a correct apk file. But it is not signed yet and it cannot be installed to the Android device.
The creation of the signed Android application from the *.ap_ file is the following (Output file name must differ from the input file name – in this case the file extension is changed to the *.apk):
Code:
call "%JAVABIN%\jarsigner" -keystore "%CD%\keystore\my-release-key.keystore" -storepass "password" -keypass "password" -signedjar "%CD%\bin\%APP_NAME%.apk" "%CD%\bin\%APP_NAME%.ap_" "alias_name"
And delete temp ap_ file:
Code:
del "bin\%APP_NAME%.ap_"
Finally, let’s return to the start folder and clear local variables:
Code:
:EXIT
cd "%PREV_PATH%"
ENDLOCAL
exit /b %ERRORLEVEL%
To test the example, you must:
• unpack it
• do the steps 2.1-2.5 from the Preparations paragraph
• run the build.bat file
You can download the sample project source at the article official page apriorit(dot)com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line
Please guide me building with Android support libraries and jack without gradle or ant.
Thanks.

Smali/Baksmali

Hey guys I'm wondering if someone could help me setup smali/baksmali on linux.
I downloaded the jar. Put the jar, the odex file, and the folder containing my framework files inside the same folder opened a command window inside that folder.
But when I try to call baksmali with
java -jar baksmali-2.2b4.jar -x LGEIME.odex -d ddt -o outclass
I get an error saying -x is an unknown command.
Thanks for any help anyone can provide.
Figured out the new smali/baksmali has new commands. Haben't had to deodex anything, but have smalied a dex file.

Cheat, Hack, disassemble, "NR Shooter" apk

Hi there,
I'm looking for possibility too cheat in "NR Shooter™_v2.7.4_apkpure.com.apk" bubble shooter game.
Is there a way to get the source code from an apk game?
I already have tried it with "APK EASY Tool" latest jar 2.3.4 get a massage "decompile failed please check the log try clear framework if you got..blablabla"
Here my log:
Decompiling APK file... (CMD mode: Normal)
/c "java -Xmx1024m -jar "C:\Program Files\APK Easy Tool\Apktool\apktool_2.3.4.jar" d -f -o "C:\Users\SUSER\Documents\APK Easy Tool\1-Decompiled APKs\NR Shooter™_v2.7.4_apkpure.com" "C:\Users\SUSER\Desktop\Wo\NR Shooter™_v2.7.4_apkpure.com.apk""
Exception in thread "main" brut.androlib.AndrolibException: Multiple resources: spec=0x7f070003 string/APKTOOL_DUMMYVAL_0x7f070003, config=-sr
at brut.androlib.res.data.ResType.addResource(ResType.java:66)
at brut.androlib.res.data.ResType.addResource(ResType.java:55)
at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:315)
at brut.androlib.res.decoder.ARSCDecoder.readTableType(ARSCDecoder.java:260)
at brut.androlib.res.decoder.ARSCDecoder.readTableTypeSpec(ARSCDecoder.java:175)
at brut.androlib.res.decoder.ARSCDecoder.readTablePackage(ARSCDecoder.java:131)
at brut.androlib.res.decoder.ARSCDecoder.readTableHeader(ARSCDecoder.java:82)
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:48)
at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:741)
at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:67)
at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:59)
at brut.androlib.Androlib.getResTable(Androlib.java:68)
at brut.androlib.ApkDecoder.setTargetSdkVersion(ApkDecoder.java:228)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:118)
at brut.apktool.Main.cmdDecode(Main.java:164)
at brut.apktool.Main.main(Main.java:73)
------------------------------------------
The goal is for example stop shootercounter, or get joker bubble for every shot.
Any help out there?

Categories

Resources