[SCRIPT/HOW-TO] Sign files with a right-click (Ubuntu) - myTouch 3G, Magic Android Development

1. Download testsign.jar
2. Create the following script in your Nautilus script directory and name it sign :
Code:
#!/bin/sh
# Update the Loc var to where YOU stored the testsign.jar file !
Loc=/home/ra/android-sdk-linux_x86-1.5_r2/tools/SignApp/
for arg
do
java -classpath "$Loc"testsign.jar testsign "$arg" signed-"$arg"
gdialog --title "signapk" --msgbox "signed-"$arg" created" 200 200
done
3. Right-click the file you want to sign, navigate to script and select sign ^^
Important :
The Nautilus script directory is probably ~.gnome2/nautilus-scripts (Prior to Nautilus release 1.0.5, the scripts directory was ~/Nautilus/scripts).
Make sure that you chmod u+x both script and testsign.jar !
Don't forget to update the Loc var in the script !

Great! This was really handy

Thanks Amon_RA

thx, nice solution.

Thanks for this Amon_RA, if it's not already in the Wiki can we add it there please otherwise this post will get lost

Hi Amon_Ra, is there a way to do this on windows???

Yes
WWW.modmygphone.com/forums/archive/index.php/t-10591.html

Related

[SCRIPT/HOW-TO] Sign files with a right-click (Ubuntu)

1. Download testsign.jar
2. Create the following script in your Nautilus script directory and name it sign :
Code:
#!/bin/sh
# Update the Loc var to where YOU stored the testsign.jar file !
Loc=/home/ra/android-sdk-linux_x86-1.5_r2/tools/SignApp/
for arg
do
java -classpath "$Loc"testsign.jar testsign "$arg" "$arg"-signed
gdialog --title "signapk" --msgbox ""$arg"-signed created" 200 200
done
3. Right-click the file you want to sign, navigate to script and select sign ^^
Important :
The Nautilus script directory is probably ~.gnome2/nautilus-scripts (Prior to Nautilus release 1.0.5, the scripts directory was ~/Nautilus/scripts).
Make sure that you chmod u+x both script and testsign.jar !
Don't forget to update the Loc var in the script !
Amon_RA said:
1. Download testsign.jar
2. Create the following script in your Nautilus script directory and name it sign :
Code:
#!/bin/sh
# Update the Loc var to where YOU stored the testsign.jar file !
Loc=/home/ra/android-sdk-linux_x86-1.5_r2/tools/SignApp/
for arg
do
java -classpath "$Loc"testsign.jar testsign "$arg" "$arg"-signed.zip
gdialog --title "signapk" --msgbox ""$arg"-signed.zip created" 200 200
done
3. Right-click the file you want to sign, navigate to script and select sign ^^
Important :
The Nautilus script directory is probably ~.gnome2/nautilus-scripts (Prior to Nautilus release 1.0.5, the scripts directory was ~/Nautilus/scripts).
Make sure that you chmod u+x both script and testsign.jar !
Don't forget to update the Loc var in the script !
Click to expand...
Click to collapse
Nice, I miss this feature coming from Windows didn't know how to do it haha Thanks
Amon_RA said:
1. Download testsign.jar
2. Create the following script in your Nautilus script directory and name it sign :
Code:
#!/bin/sh
# Update the Loc var to where YOU stored the testsign.jar file !
Loc=/home/ra/android-sdk-linux_x86-1.5_r2/tools/SignApp/
for arg
do
java -classpath "$Loc"testsign.jar testsign "$arg" "$arg"-signed.zip
gdialog --title "signapk" --msgbox ""$arg"-signed.zip created" 200 200
done
3. Right-click the file you want to sign, navigate to script and select sign ^^
Important :
The Nautilus script directory is probably ~.gnome2/nautilus-scripts (Prior to Nautilus release 1.0.5, the scripts directory was ~/Nautilus/scripts).
Make sure that you chmod u+x both script and testsign.jar !
Don't forget to update the Loc var in the script !
Click to expand...
Click to collapse
thanks just finished setting it up
Updated the script so it's just adding signed in front of the file.
Great!
Added a link to the top of my how-to.
"-signed.zip" be added to the end. I get this after the script is executed with the script:
signed-/home/stephane/Desktop/udpate.zip created
Click to expand...
Click to collapse
thanks, my debian box is happy
okay, renaming the archive and removing the zip extension and using the original script seems to work.
I thought I had set this all up correctly, but when I right click on a zip and choose "Sign" I get a popup about encryption keys :-S
No encryption keys were found with which to perform the operation you requested. The program Passwords and Encryption Keys will now be started so that you may either create a key or import one.
Click to expand...
Click to collapse
I'm really not sure what I did wrong.
I pasted testsing.jar in /home/adrian/android
then made the script - sudo gedit /home/adrian/.gnome2/nautilus-scripts/sign
Code:
#!/bin/sh
# Update the Loc var to where YOU stored the testsign.jar file !
Loc=/home/adrian/android/
for arg
do
java -classpath "$Loc"testsign.jar testsign "$arg" signed-"$arg"
gdialog --title "signapk" --msgbox "signed-"$arg" created" 200 200
done
and finally chmodded the jar and script
Code:
cd /home/adrian/android/
chmod u+x testsign.jar
cd /home/adrian/.gnome2/nautilus-scripts/
chmod u+x sign
Any help is appreciated, I feel like such a n00b right now :-/
Bump
I assume I'm doing something wrong, as I've tried the same thing on my netbook and the exact same thing happens.
AdrianK said:
I thought I had set this all up correctly, but when I right click on a zip and choose "Sign" I get a popup about encryption keys :-S
I'm really not sure what I did wrong.
I pasted testsing.jar in /home/adrian/android
then made the script - sudo gedit /home/adrian/.gnome2/nautilus-scripts/sign
Code:
#!/bin/sh
# Update the Loc var to where YOU stored the testsign.jar file !
Loc=/home/adrian/android/
for arg
do
java -classpath "$Loc"testsign.jar testsign "$arg" signed-"$arg"
gdialog --title "signapk" --msgbox "signed-"$arg" created" 200 200
done
and finally chmodded the jar and script
Code:
cd /home/adrian/android/
chmod u+x testsign.jar
cd /home/adrian/.gnome2/nautilus-scripts/
chmod u+x sign
Any help is appreciated, I feel like such a n00b right now :-/
Click to expand...
Click to collapse
It looks like you're selecting the Sign option that does gpg/pgp signing. There should be a "Scripts" submenu when you right click and then your script name should be listed under that.
alcahuete said:
It looks like you're selecting the Sign option that does gpg/pgp signing. There should be a "Scripts" submenu when you right click and then your script name should be listed under that.
Click to expand...
Click to collapse
I feel like such a n00b, I just saw saw sign and assumed it was the correct option ;-) Where do the signed files actaully end up? They don't appear in the original directory :-S
okay, renaming the archive and removing the zip extension and using the original script seems to work.
Click to expand...
Click to collapse
This doesn't change anything for me :-S
Does this also work for Apk's?
I'm having the same problem as Adrian.
I followed the directions to the letter and I get the scripts submenu with the sign option.
after I select "sign" I get the "signapk" message that says "signed! /home/greg/desktop/hero.zip created. OK
But when I check my archive there is nothing in the META-INF file (except the com directory).
PS. I'm a Linux noob too.
alritewhadeva said:
Nice, I miss this feature coming from Windows didn't know how to do it haha Thanks
Click to expand...
Click to collapse
You could actually do something like this in Windows; you could write a batch (cmd) file and modify the registry for shell open commands. It might take a little more effort and use components of Windows most users wouldn't touch with a 10 foot pole, but it works pretty well. I "wrote" a pdf creation system based on ghostscript and used a similar technique.
Changed the first post a bit, check if it's working now for you.
Amon_RA said:
Changed the first post a bit, check if it's working now for you.
Click to expand...
Click to collapse
I somehow managed to get it to work by creating a folder called "signing" in my androidsdk directory. For some reason it won't work from the Desktop.
Amon_RA said:
1. Download testsign.jar
2. Create the following script in your Nautilus script directory and name it sign :
Code:
#!/bin/sh
# Update the Loc var to where YOU stored the testsign.jar file !
Loc=/home/ra/android-sdk-linux_x86-1.5_r2/tools/SignApp/
for arg
do
java -classpath "$Loc"testsign.jar testsign "$arg" "$arg"-signed
gdialog --title "signapk" --msgbox ""$arg"-signed created" 200 200
done
3. Right-click the file you want to sign, navigate to script and select sign ^^
Important :
The Nautilus script directory is probably ~.gnome2/nautilus-scripts (Prior to Nautilus release 1.0.5, the scripts directory was ~/Nautilus/scripts).
Make sure that you chmod u+x both script and testsign.jar !
Don't forget to update the Loc var in the script !
Click to expand...
Click to collapse
Thank you so much for this! I wasn't sure how to do it, couldn't find an answer, then you pop up! Thank you for your hard work.
Much obliged, RA.
~~~~~~~~~~
Great work! It works on Gentoo/Sabayon with nautilus installed under e17.

32b dream->sapphire script (updated 20th august, new feature!)

So, as the title says a simple bash script to convert a dream rom to a sapphire rom.
To make this work you need unpack / repack boot img utilities from here:
http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack,_Edit,_and_Re-Pack_Boot_Images
testsign.jar from here:
http://forum.xda-developers.com/showpost.php?p=4008431&postcount=15
mkbootimg from here:
http://forum.xda-developers.com/showpost.php?p=3387504&postcount=26
since I'm a nice guy I've included these in the attached zip file.
extract the attached zip file into a folder (warning: make sure there's no spaces in the folder name!!) then run:
Code:
./convert.sh your_dream_rom.zip
this will:
extract the boot.img from the zip
unpack the boot image
rename init.trout.rc to init.sapphire.rc
repack the boot image
put the boot image back into a copy of the dream rom zip
NEW!! in v3: add anything in the 'addin' folder into the zip (see below)
resign the new zip
you'll be left with your_dream_rom-sapphire.zip which should (hopefully) work on the sapphire.
v3: new addin folder. Anything in this folder will be added to the resulting zip, overwriting if needed. So if you want to replace (for example) /system/etc/AudioPara4.csv just put the file in /addin/system/etc and it will automagically be merged in.
Deicist said:
So, as the title says a simple bash script to convert a dream rom to a sapphire rom.
To make this work you need unpack / repack boot img utilities from here:
http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack,_Edit,_and_Re-Pack_Boot_Images
testsign.jar from here:
http://forum.xda-developers.com/showpost.php?p=4008431&postcount=15
since I'm a nice guy I've included these in the attached zip file.
You'll also need to compile the mkbootimg executable that (I think!) comes with the android source.
extract the attached zip file inot a folder then run:
Code:
./convert.sh your_dream_rom.zip
this will:
extract the boot.img from the zip
unpack the boot image
rename init.trout.rc to init.sapphire.rc
repack the boot image
put the boot image back into a copy of the dream rom zip
resign the new zip
you'll be left with your_dream_rom-sapphire.zip which should (hopefully) work on the sapphire.
attached is a zip file containing everything you need except mkbootimg, since that needs to be compiled for your system.
Please note, I don't have a compiled copy of mkbootimg for my system, so I haven't been able to try the full process... but extracting and repacking the zip works, signing seems to work... and it's a pretty simple script so I can't see why it wouldn't work.
Enjoy!
Click to expand...
Click to collapse
Thanks! Do I need a boot.img and wlan.ko for pvt32A if I want it to work?
it won't work for 32a, but I'm sure you can mod the script to add in a new boot.img and radio thingy.
updated initial post with new attachment:
added mkbootimg to zip file
changed script slightly.
in case anyone was wondering, I tried this script on Drizzy's "superlight hero" rom from the dream forum and it worked perfectly.
[email protected]:~$ /home/ubuntu/Desktop/a/convert.sh Personal.zip
unzip: cannot find or open ./Personal.zip, ./Personal.zip.zip or ./Personal.zip.ZIP.
/home/ubuntu/Desktop/a/convert.sh: 3: ./unpack-bootimg.pl: not found
rm: Entfernen von „boot.img“ nicht möglich: No such file or directory
mv: Aufruf von stat für „./boot.img-ramdisk/init.trout.rc“ nicht möglich: No such file or directory
/home/ubuntu/Desktop/a/convert.sh: 6: ./repack-bootimg.pl: not found
cp: Aufruf von stat für „./Personal.zip“ nicht möglich: No such file or directory
zip warning: name not matched: boot.img
zip error: Nothing to do! (update.zip)
/home/ubuntu/Desktop/a/convert.sh: 9: java: not found
rm: Entfernen von „./boot.img-ramdisk“ nicht möglich: No such file or directory
rm: Entfernen von „boot.img-kernel.gz“ nicht möglich: No such file or directory
rm: Entfernen von „boot.img-ramdisk.cpio.gz“ nicht möglich: No such file or directory
rm: Entfernen von „update.zip“ nicht möglich: No such file or directory
Click to expand...
Click to collapse
What do i wrong ... ?
No idea, according to the error message it says it can't find 'Personal.zip'... is that file present in the same directory as 'convert.sh' ?
yes it is ...
can anyone convert this boot.img ... so that i can use on 32b?
you need to actually change directory to the directory containing the utility to run it.
try:
cd /home/ubuntu/Desktop/a/
./convert.sh Personal.zip
is ist possible that it doesn't work because i'm using the live cd now?
now it says
Archive: ./Personal.zip
inflating: ./boot.img
kernel written to ./boot.img-kernel.gz
ramdisk written to ./boot.img-ramdisk.cpio.gz
472 blocks
extracted ramdisk contents to directory ./boot.img-ramdisk/
472 blocks
sh: mkbootimg: not found
repacked boot image written at ./boot.img-ramdisk-repack.img
zip error: Nothing to do! (update.zip)
Click to expand...
Click to collapse
but mkbootimg is in this directory
This is what I end up getting. I ended up using a precompiled binary of mkbootimg for OSX since it didn't work on my Linux box.
./convert.sh NewVision_2.8.zip
Archive: ./NewVision_2.8.zip
inflating: ./boot.img
kernel written to ./boot.img-kernel.gz
ramdisk written to ./boot.img-ramdisk.cpio.gz
extracted ramdisk contents to directory ./boot.img-ramdisk/
usage: cpio -o [-aABcLvVzZ] [-C bytes] [-H format] [-O archive]
[-F archive] < name-list [> archive]
cpio -i [-bBcdfmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]
[-I archive] [-F archive] [pattern...] [< archive]
cpio -p [-adlLmuvV] destination-directory < name-list
repacked boot image written at ./boot.img-ramdisk-repack.img
updating: boot.img (deflated 1%)
Exception in thread "main" java.lang.UnsupportedClassVersionError: testsign (Unsupported major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Hello,
MarcoNieddu said:
extracted ramdisk contents to directory ./boot.img-ramdisk/
472 blocks
sh: mkbootimg: not found
Click to expand...
Click to collapse
You have to modify the script repack-bootimg.pl at line 19 :
replace : system ("mkbootimg ...
by : system ("./mkbootimg ...
Note the ./ before mkbootimg
Scargoll.
Got everything working.
1. Add ./ to the repack script before mkbootimg
2. make sure you have a 32bit OS, as the binary provided was compiled for it. I made an Intrepid machine on my VM server.
3. Use the latest version of Java. Even Karmic Koala Ubuntu doesn't have it. The class file in the jar was compiled with a very recent version of Java, so you'll error out since the jre version isn't equal to or above whats needed. You can simply do "export JAVAHOME=pathtojava" if you don't want to keep that version permanently.
4. Have fun!
Bugfixes:
removes boot.img when script is done
added ./ before mkbootimg (sorry!)
the provided mkbootimg *should* work on a 64bit machine, it does on my 64 bit arch linux box...as with all things linux though, YMMV.
I ve tried to convert a dream rom but it didn't work, does this method can be applied from a windows command shell ?
EDIT: can I take a dream rom, flash it, and push a boot.img from a hero 32B rom ?
EDIT2: Ok now that I have read the name of the topic I understand it wont work in windows. So here's my new question...
Is there a way to adapt this script (or to create something similar) so it works with windows ?
updated with 'addin' feature
ElChouch said:
Is there a way to adapt this script (or to create something similar) so it works with windows ?
Click to expand...
Click to collapse
A windows version would be great!
Nice work Deicist. Thanks for sharing.
some facts:
- i'm running Windows 7 RC (64-bit)
- i installed Cygwin and executed it as administrator
- i browse out to the correct folder where the rom zip file is located
i get the following errors. any suggestions?:
$ ./convert.sh modaco_hero.zip
unzipping...
./convert.sh: line 3: unzip: command not found
unpacking boot image
./convert.sh: ./unpack-bootimg.pl: /usr/bin/perl: bad interpreter: Permission de
nied
moving trout to sapphire
mv: cannot stat `./boot.img-ramdisk/init.trout.rc': No such file or directory
repacking boot image
./convert.sh: ./repack-bootimg.pl: /usr/bin/perl: bad interpreter: Permission de
nied
re-zipping
./convert.sh: line 12: zip: command not found
rm: cannot remove `boot.img': No such file or directory
Addin files found....
./convert.sh: line 18: zip: command not found
Re-signing zip (this may take a while)
tidying up
rm: cannot remove `./boot.img-ramdisk': No such file or directory
rm: cannot remove `boot.img-kernel.gz': No such file or directory
rm: cannot remove `boot.img-ramdisk.cpio.gz': No such file or directory
all done
Make it work on Fedora
Was having problems with this script working at the java part on a FC10 box.
Was able to get it to work by installing java-1.6.0-openjdk:
Code:
$ yum install java-1.6.0-openjdk
just posting that here in case anyone who needs it stumbles by.
Thanks for your great script Deicist
I'm getting this error. What am I doing wrong?
Exception in thread "main" java.lang.NoClassDefFoundError: testsign
at java.lang.Class.initializeClass(libgcj.so.90)
Caused by: java.lang.ClassNotFoundException: sun.security.x509.AlgorithmId not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:testsign.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.90)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.Class.initializeClass(libgcj.so.90)

[Q] Help using Android command line dev tools

I'm trying to deconstruct the Android app development process by creating and installing a sample app entirely from the command line (without even using Ant). I've composed a script which seems to work until the very last command, at which point I get the message
134 KB/s (10496 bytes in 0.076s)
pkg: /data/local/tmp/MyActivity-debug.apk
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
Please don't be put off by the fact that my script is a Windows .bat script. I'm just calling code from the SDK's tools and platform-tools directories. Anyway, here's the script. If find what I'm missing that's giving me the NO_CERTIFICATES error, please reply...
call "c:\program files (x86)\Android\android-sdk\tools\android" create project --target 10 --name MyAndroidProject --path c:\MyProjects\MyAndroidProject --activity MyActivity --package com.allmycode.samples
cd \MyProjects\MyAndroidProject
mkdir C:\MyProjects\MyAndroidProject\res
mkdir C:\MyProjects\MyAndroidProject\libs
mkdir C:\MyProjects\MyAndroidProject\bin
mkdir C:\MyProjects\MyAndroidProject\gen
mkdir C:\MyProjects\MyAndroidProject\bin\classes
"C:\Program Files (x86)\Android\android-sdk\platform-tools\aapt.exe" package -f -m -M C:\MyProjects\MyAndroidProject\AndroidManifest.xml -S C:\MyProjects\MyAndroidProject\res -I "C:\Program Files (x86)\Android\android-sdk\platforms\android-9\android.jar" -J C:\MyProjects\MyAndroidProject\gen
"c:\program files\java\jdk1.7.0\bin\javac" -d C:\MyProjects\MyAndroidProject\bin\classes -classpath C:\MyProjects\MyAndroidProject\bin\classes;C:\MyProjects\MyAndroidProject;c:\ant\lib\ant-launcher.jar;"C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip";C:\ant\lib\ant-antlr.jar;C:\ant\lib\ant-apache-bcel.jar;C:\ant\lib\ant-apache-bsf.jar;C:\ant\lib\ant-apache-log4j.jar;C:\ant\lib\ant-apache-oro.jar;C:\ant\lib\ant-apache-regexp.jar;C:\ant\lib\ant-apache-resolver.jar;C:\ant\lib\ant-apache-xalan2.jar;C:\ant\lib\ant-commons-logging.jar;C:\ant\lib\ant-commons-net.jar;C:\ant\lib\ant-jai.jar;C:\ant\lib\ant-javamail.jar;C:\ant\lib\ant-jdepend.jar;C:\ant\lib\ant-jmf.jar;C:\ant\lib\ant-jsch.jar;C:\ant\lib\ant-junit.jar;C:\ant\lib\ant-junit4.jar;C:\ant\lib\ant-netrexx.jar;C:\ant\lib\ant-swing.jar;C:\ant\lib\ant-testutil.jar;C:\ant\lib\ant.jar;"C:\Program Files\Java\jdk1.7.0\lib\tools.jar" -sourcepath C:\MyProjects\MyAndroidProject\src;C:\MyProjects\MyAndroidProject\gen -target 1.5 -bootclasspath "C:\Program Files (x86)\Android\android-sdk\platforms\android-9\android.jar" -encoding UTF-8 -g -source 1.5 c:\MyProjects\MyAndroidProject\src\com\allmycode\samples\*.java
call "C:\Program Files (x86)\Android\android-sdk\platform-tools\dx.bat" --dex --output=C:\MyProjects\MyAndroidProject\bin\classes.dex C:\MyProjects\MyAndroidProject\bin\classes
"C:\Program Files (x86)\Android\android-sdk\platform-tools\aapt.exe" package -f --debug-mode -M C:\MyProjects\MyAndroidProject\AndroidManifest.xml -S C:\MyProjects\MyAndroidProject\res -I "C:\Program Files (x86)\Android\android-sdk\platforms\android-9\android.jar" -F C:\MyProjects\MyAndroidProject\bin\MyActivity-debug-unaligned.apk
"C:\Program Files (x86)\Android\android-sdk\tools\zipalign.exe" -f 4 C:\MyProjects\MyAndroidProject\bin\MyActivity-debug-unaligned.apk C:\MyProjects\MyAndroidProject\bin\MyActivity-debug.apk
start "Launch an emulator" "C:\Program Files (x86)\Android\android-sdk/tools/emulator.exe" -avd Gingerbread
timeout /T 60
"C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" install -r C:\MyProjects\MyAndroidProject\bin\MyActivity-debug.apk
You need to sign your apk
Hey, I believe all you need to do is sign your .apk with a certificate.
Here is a link about creating a certificate if you dont already have one. I tried to include a link but it wont let me. (sorry im a new user)
Once you have acquired a certificate, you can then use the JDK utitility called jarsigner. The terminal command should be something like this...
jarsigner -verbose -keystore my-release-key.keystore final.apk alias_name
Click to expand...
Click to collapse
Hope this helps ya out.

[APP][DEV][GUIDE] Using the Android Java Internal/Hidden API classes

Using Java Reflection with Eclipse ADT to Access Internal/Hidden API classes.
Purpose
We present a way to access all the Internal and Hidden Java packages/classes
in the AOS. To do this we need to both repackage the Android.jar and hack the
Eclipse ADT plugin, to allow using these internal packages.
Posting
==================================================
Do NOT post general questions/requests on how to
do this or that, they will not be answered here.
DO post if you have additional tricks, hacks or
information that can help/benefit this tutorial.
==================================================
Background
There are two reasons one cannot use internal packages. One reason is that, if
you're using Eclipse as your development platform, those packages are
internally blocked in the Eclipse ADT plugin. Second reason is that the normal
development android.jar runtime does not contain those *.class files that
belong to the internal packages.
"There is no easy way to use com.android.internal package (internal API) or
anything marked with @hide attribute (hidden API) without using reflection.
That’s because android.jar file does not contain classes from internal and
hidden API and because of this nobody can reference those classes in compile
time."
Thus we need to first restore the "original" android.jar which will allow us
to use internal and hidden APIs. But the runtime equivalent of Android SDK’s
android.jar file is framework.jar. This file is located in the
/system/framework/ directory of your device. We will extract and use this for
our pleasure.
The general procedure:
A) Grab the "full" framwork.jar from your device
B) extract the class files
C) add them to "full" android.jar ??
D) Hack the Eclipse ADT plugin jar.
Finally, NOTHING would have been possible without the excellent step-by-step
instructions on the devmaze-blog by senior Android developer Ievgenii Nazaruk
(aka. "inazaruk"). THANK YOU Ievgenii!​References
http://stackoverflow.com/questions/...d-sdk-with-hidden-and-internal-apis-available
http://stackoverflow.com/questions/...-state-permission-for-apps-ran-on-gingerbread
http://code.google.com/p/smali/wiki/DeodexInstructions
http://code.google.com/p/adt-addons/
​
The General Procedure
NOTE: All this was performed on Windows Vista with Cygwin.(1) Grab BOOTCLASSPATH from init.rc
Find the line in your init.rc file that reads something like:
Code:
[SIZE=2]export BOOTCLASSPATH /system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar[/SIZE]
Extract and reformat the path to:
Code:
[SIZE=2]core.jar:bouncycastle.jar:ext.jar:framework.jar:android.policy.jar:services.jar:core-junit.jar[/SIZE]
(2) Grab the "framework" from your device
Create a working directory somewhere, let's call it "_framework":
Code:
[SIZE=2]mkdir ./_framework[/SIZE]
[SIZE=2]cd _framework[/SIZE]
Grab all the framework files from your device:
Code:
[SIZE=2]adb pull /system/framework .[/SIZE]
Rename directory if needed.
NOTE-1: From now on I'll assume you know where you are!
NOTE-2: Most GB 2.3.4+ devices uses .odex'ed files,
with name pairs like: <package>.jar and <package>.odex.
These need to be converted.
(3) Use baksmali with (1)
You can also use baksmali with the switch: -d <framwork-dir>.
The general command is something like below, but in windows there may be "wrappers"
that allow you to just type "baksmali" without the "java -jar" prefix and without
the ".jar" post fix. Anyway here is the command I used:
Code:
[SIZE=2]java -Xmx1024m -jar ./../../baksmali.jar -a 10 -c :core.jar:bouncycastle.jar:ext.jar:framework.jar:android.policy.jar:services.jar:core-junit.jar -x framework.odex[/SIZE]
==> This results in all files put in the "out" sub-directory.
This directory contain 3 sub-directories (for GB 2.3.4):
Code:
[I]android [/I](Hidden APIs)
[I]com [/I](Internal APIs)
[I]javax [/I](Hidden APIs)
NOTE: If you are using Google's own API's, you will probably also need to add
those packages to the path above. (Eg. Email.jar, etc etc ?)
(4) Then use smali to create a dex file from "out" directory
Code:
java -jar smali.jar out
==> creates out.dex from "out" directory.
(5) Run dex2jar on out.dex
Code:
[SIZE=2]./dex2jar.bat out.dex[/SIZE]
==> creates out_dex2jar.jar
(This .jar contain close to 4900 files at 12 MB!)
(6) Rename "out_dex2jar.jar" to "framework-classes.zip"
Code:
[SIZE=2]mv out_dex2jar.jar framework-classes.zip
unzip framework-classes.zip[/SIZE]
(7) Find and copy your Android SDK's android.jar file
Go to: /path/to/android-sdk-windows/platforms/android-X/android.jar
where X is the API level of interest. This obviously have to match the
API level of the files you extracted from your device in: /system/framework .
This .jar file contain more than 5300 files when expanded, but missing all
the internal packages. Our job is to add them back in.
Let's first make a copy that we can use to expand and add files from (6):
Code:
cp android.jar custom-android.zip
unzip custom-android.zip
(8) Add all *.class files from (6) in to (7)
Copy and replace all existing *.class files from framework-classes.zip into
custom-android.zip:
Code:
[SIZE=2]cp -R /path/to/framework-classes/* /path/to/custom-android/.[/SIZE]
The root content of that directory should then look something like this:
Code:
[SIZE=2]android[/SIZE]
[SIZE=2]assets[/SIZE]
[SIZE=2]com[/SIZE]
[SIZE=2]dalvik[/SIZE]
[SIZE=2]java[/SIZE]
[SIZE=2]javax[/SIZE]
[SIZE=2]junit[/SIZE]
[SIZE=2]META-INF[/SIZE]
[SIZE=2]org[/SIZE]
[SIZE=2]res[/SIZE]
[SIZE=2]AndroidManifest.xml[/SIZE]
[SIZE=2]resources.arsc[/SIZE]
(9) Rename directory and create your new "classy-android.jar"
We rename it so not confuse with the original:
Code:
mv custom-android classy-android
zip classy-android
mv classy-android.zip classy-android.jar
IMPORTANT:
Make absolutely sure that the folder structure of your zip archive
is exactly the same as what you intended. To check, unzip the file
and see if it is what you (and eventually Eclipse) would expect.
(For example, if you use 7zip to zip a directory file called "test",
into "test.zip", you may end-up extracting it to ./test/test/... )
(10) Enabling & Restricting Access to classy-android.jar
Instead of just replacing the android.jar with classy-android.jar, we choose
to create a customized Android platform. This way you can enable the Internal
and Hidden API's for those projects requiring them, while other standard
projects doesn't have access to those.
(a) Go to: /path/to/android-sdk-windows/platforms/
and copy the relevant directory (for example):
Code:
cp -R android-10 android-10-internals
(b) Replace android.jar with your classy-android.jar:
Code:
cp classy-android.jar android.jar
("cp" overwrites!)
(c) Edit the build.prop file:
Edit/replace the following lines:
Code:
[SIZE=2]ro.build.version.sdk=10 ==> ro.build.version.sdk=[COLOR=Black][B]-10[/B][/COLOR][/SIZE]
[SIZE=2]ro.build.version.release=2.3.3 ==> ro.build.version.release=2.3.internal[/SIZE]
(11) Customizing the Eclipse ADT
In order to be able to use com.android.internal packages in the Eclipse ADT,
you have to disable the internal protection mechanism of the plugin, that
prevent you to use these libraries. You can see this by right-clicking on your
project package and navigate to:
Code:
[SIZE=2]==> Properties ==> Java Build Path ==> Libraries (tab) [/SIZE]
[SIZE=2]--> Android 2.x.x --> android.jar [/SIZE]
[SIZE=2]--> "Access rules: 1 rule defined": [B][COLOR=Red](X)[/COLOR][/B] [B]Forbidden: com/android/internal/**[/B][/SIZE]
This can not be removed (bug?), even though the interface allows changing, it
never persists after closing the Properties window. So we have to hack it!
The way to do it, is to hexedit the correct java class file and change the
name from "internal" to "internax". First let's find the correct file. The
plugin file is located in the ./eclipse/plugins/ directory, and its name is
something like:
Code:
com.android.ide.eclipse.adt_18.0.0.v201203301601-306762.jar
(a) make a backup copy of this (with the exact name preserved) in another directory.
(b) make a another copy of this in another directory.
(c) unzip (b) in that directory
Code:
[SIZE=2]cp com.android.ide.eclipse.adt_18.0.0.v201203301601-306762.jar hacked_adt.zip[/SIZE]
[SIZE=2]unzip hacked_adt.zip[/SIZE]
[SIZE=2]cd hacked_adt[/SIZE]
This is a huge directory system, so forget poking around in it,
just go to the correct sub-directory:
Code:
[SIZE=2]cd ./com/android/ide/eclipse/adt/internal/project/[/SIZE]
Then find the correct file and the approximate string location within that file:
Code:
[SIZE=2]strings.exe -f -4 -t x ./*.class |grep "android\/internal"[/SIZE]
It happens to be in "AndroidClasspathContainerInitializer.class". Now, use a
hexeditor to find and change the string "com/android/internal/**"
to "com/android/internax/**". That will do it!
Now zip-up your hacked jar directory and copy it over the old one.
(Remember that "cp" overwrites without warning!)
Code:
[SIZE=2]zip hacked_adt[/SIZE]
[SIZE=2]cp hacked_adt.zip /path/to/eclipse/plugins/com.android.ide.eclipse.adt_18.0.0.v201203301601-306762.jar[/SIZE]
You Are Done!
Enjoy your newly hacked Eclipse! ​Errors
If you get any errors;
1. make sure you have zipped up everything properly as warned before.
2. make sure you have included Google API packages in your BOOTCLASSPATH in step (3).
3. Try to "clean-up" the Java by: "Right-Click" ==> Source ==> "Clean Up...".
4. Google them
5. Ignore them
6. Give up. Not! But I can't help you!
If it still doesn't work, try to download inazaruk's pre-compiled set of internal android.jar's from here.
(For android 7,8,10,15.)
​
WIP! <here be dragons2>
For a project using internal package imports, see my thread:
"[TOOL][APP][WIP] Native AT Command Injector"
<here be more dragons>
Following the instructions in posts 1-2 above, may not always work. It is not known to me at this time, why it shouldn't. One theory is that it can have something to do with how Eclipse and Android.jar is packaging their files and the resulting sizes.
This was mentioned in this Stackoverflow post:
"Jar files: why does extracting then compression a jar file create a file of a different size to the original?"
Then reading the man pages for "jar" we can inform ourselves with:
Code:
[SIZE=2] c Creates a new archive file named jarfile (if f is specified) or to
standard output (if f and jarfile are omitted). Add to it the
files and directories specified by inputfiles.
u Updates an existing file jarfile (when f is specified) by adding
to it files and directories specified by inputfiles.
x Extracts files and directories from jarfile (if f is specified) or
standard input (if f and jarfile are omitted). If inputfiles is
specified, only those specified files and directories are
extracted. Otherwise, all files and directories are extracted.
t Lists the table of contents from jarfile (if f is specified) or
standard input (if f and jarfile are omitted). If inputfiles is
specified, only those specified files and directories are listed.
Otherwise, all files and directories are listed.
i Generate index information for the specified jarfile and its
dependent jar files.
[/SIZE]
More info is provided here:
The JAR Overview @
http://java.sun.com/javase/6/docs/technotes/guides/jar/jarGuide.html
The JAR File Specification @
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html
The JARIndex Spec @
http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html
JAR Tutorial @
http://java.sun.com/docs/books/tutorial/jar/
pack200 Reference Page @
http://java.sun.com/javase/6/docs/technotes/tools/share/pack200.html
Another theory is that it may have something to do with what seem to be, that Google have revoked the the use of MODIFY_PHONE_STATE since Android 2.3, and that this influences the Eclipse behavior, when using and modifying older android.jar's. This was mentioned here and here.
Any help would be very much appreciated!
< bump >
Hi, thanks for the info, I made it using linux and worked really nice, these were the lines that I used, hope be useful.
This is my Android folder at home
Code:
Android/
├── eclipse
├── ndk
├── platforms-internals
├── sdk
└── tools
Start an avd running the desired API to modify in this case API-17
Code:
$ emulator -avd avd_api_17 -no-window &
Get the framework
Code:
$ cd ~/Android/
$ mkdir _framework
$ cd _framework
$ adb -s emulator-5554 pull /system/framework .
Grab BOOTCLASSPATH
Code:
$ adb -s emulator-5554 shell cat init.rc | grep BOOTCLASSPATH > bootclasspath
I didn't have the tools used in this tutorial, so I included the steps for getting them
Decompile with baskmali
Code:
$ cd ~/Android/tools
$ wget https://smali.googlecode.com/files/baksmali-1.4.2.jar
$ cd ~/Android/_framework
$ java -Xmx1024m -jar ../tools/baksmali-1.4.2.jar -a 17 -c core.jar:core-junit.jar:bouncycastle.jar:ext.jar:framework.jar:telephony-common.jar:mms-common.jar:android.policy.jar:services.jar:apache-xml.jar -x framework.odex
The parameter -a for baksmali refers to the API we are working with.
Generate out.dex with smali
Code:
$ cd ~/Android/tools
$ wget https://smali.googlecode.com/files/smali-1.4.2.jar
$ cd ~/Android/_framework
$ java -jar ../tools/smali-1.4.2.jar out
Get internal and hidden classes using dex2jar
Code:
$ cd ~/Android
$ wget https://dex2jar.googlecode.com/files/dex2jar-0.0.9.15.zip
$ unzip dex2jar-0.0.9.15.zip
$ rm dex2jar-0.0.9.15.zip
$ cd _framework/
$ ../tools/dex2jar-0.0.9.15/d2j-dex2jar.sh out.dex
$ unzip out-dex2jar.jar -d framework-classes
Add these classes to plataform's default android.jar
Code:
$ cd ~/Android
$ unzip sdk/platforms/android-17/android.jar -d custom-android
$ cp -r _framework/framework-classes/* custom-android/
$ rm -r _framework
$ cd custom-android
$ zip -r ../custom-android.jar *
$ cd ..
$ rm -r custom-android
Create new extended platform
Code:
$ cd ~/Android
$ cp -r sdk/platforms/android-17 platforms-internals/android-17-internals
$ mv custom-android.jar platforms-internals/android-17-internals/android.jar
$ vi platforms-internals/android-17-internals/build.prop
ro.build.version.release=4.2.2
ro.build.version.release=4.2.2.internal
$ ln -s ~/Android/platforms-internals/android-17-internals ~/Android/sdk/platforms/android-17-internals
I use a symlink for keep it a little organized
Hack ADT
Code:
$ cd ~/Android
$ unzip eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar -d hacked_adt
Go to right folder
Code:
$ cd hacked_adt/com/android/ide/eclipse/adt/internal/project/
Find file where is our desired string
Code:
$ strings -f -a -t x * | grep "android\/internal"
Edit with an hex editor
Code:
$ bless AndroidClasspathContainerInitializer.class &
Here we change the l for the x.
Replace original file making a backup
Code:
$ cd ~/Android
$ cp eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar.original
$ cd hacked_adt/
$ zip -r ../eclipse/plugins/com.android.ide.eclipse.adt_22.0.4.v201307151829--741630.jar *
$ cd ..
$ rm -r hacked_adt
This worked for me... thanks E:V:A
I got just one error related to a dropbox class, but i think this is not important... hope that
lenieto3 said:
...Start an avd running the desired API to modify in this case API-17... This worked for me... I got just one error related to a dropbox class, but i think this is not important...
Click to expand...
Click to collapse
Thanks and sorry for late reply. I'm very happy to hear these instructions still works with API-17! Could you also upload your hacked JAR somewhere so that people can save some time when experimenting?
I was just here to check-in and try to bump this thread to see if it is still useful to anyone.
E:V:A said:
Thanks and sorry for late reply. I'm very happy to hear these instructions still works with API-17! Could you also upload your hacked JAR somewhere so that people can save some time when experimenting?
I was just here to check-in and try to bump this thread to see if it is still useful to anyone.
Click to expand...
Click to collapse
ive got access to ActivityManager's hidden methods.
I want to use the removeTask method, but it keeps saying that I dont have the REMOVE_TASKS permissions even though I added it to the manifest (and turned off lint).
Permission Denial: removeTask() from pid=9963, uid=10179 requires android.permission.REMOVE_TASKS
Does someone know if there are any automated tools to do/performs steps 1-9?
I'd like to see a tool to automatically pull (from phone), extract and create a compatible android.jar.
@Mohammad_Adib: Sorry, this is the wrong thread for those type of questions.
see this link stackoverflow.com|questions|30656933|android-system-framework-jar-files

[TOOL][ARM]sdat2img for Android!

sdat2img for Android!
Most of us, have no pc for converting system.new.dat to system.img...
So, this is why i create this tool!​
Code:
[B]Post 1[/B] → Introduction, installation, downloads
[B]Post 2[/B] → Changelog
[B]Post 3[/B] → How to use
sdat2img is a tool, that write on python language, to convert system.new.dat into system.img
This tool was only work on Windows and Linux
So i adapt it into android that can be runned in the Terminal​
Requirements:
Custom Recovery
Around 30-50MB of free system
a Terminal
Installation:
Download the zip
Install via custom recovery
Reboot!
Uninstalling:
I should have the uninstaller, but it is gone somewere in my PC. So maybe later gonna add this.
Download links:
AndroidFileHost
Credits:
@xpirt for sdat2img.py
@7175 for python for android
XDA:DevDB Information
sdat2img for Android, Tool/Utility for the Android General
Contributors
RendyAK
Version Information
Status: Beta
Current Beta Version: 0.2
Created 2016-08-27
Last Updated 2016-08-27
Changelog:
0.2 BETA
Code:
[Fixed] Convert error
Old Changelog
Code:
[B]0.1 BETA[/B]
- Intial Release
How to use!
Well, this is pretty simple, haha.
Just like the @xpirt sdat2img.
Code:
Usage: sdat2img <system_transfer_list> <system_new_file> <system_img>
And wait for the process finish.
WARNING!
I SUGGEST YOU TO "cd" TO THE DIRECTORY OF system.new.dat FIRST!
How to extract the system.img?
Just simply enter this command
Dont forget to "cd" to the directory of system.img
Code:
mkdir system
mount -t ext4 -o loop system.img system
cp -rf system system2
And the output is on system2 folder.
Dont forget to press enter each command you type!
Reserved for some case.
Update!
0.2 BETA
Code:
[Fixed] Convert error
Incredible! Thank you so much for this, can't wait to try it out! :good:
RendyAK said:
Changelog:
0.2 BETA
Click to expand...
Click to collapse
After unpacking the file sdat2img-android-arm-0.2.zip, catalog python3.4.2 occupies 42.6 MB of valuable space on the system partition.
Could you just leave these components python that are needed?
Thanks.
ze7zez said:
After unpacking the file sdat2img-android-arm-0.2.zip, catalog python3.4.2 occupies 42.6 MB of valuable space on the system partition.
Could you just leave these components python that are needed?
Thanks.
Click to expand...
Click to collapse
I didnt know whats the python main file.
But it think for best result its need all of the python files.
On Android! Just what I was searching for. Thank you @RendyAK. This is awesome stuff.
hi @RendyAK
I have a cm12 system.new.dat. What will your program do to this
I floop the pig
Everything had worked fine till i tried to convert a dat file of over 4gb. It says
[email protected]:/ $ su
[email protected]:/ # cd /storage/sdcard1
system.transfer.list system.new.dat system.img <
Traceback (most recent call last):
File "/system/python3.4.2/sdat2img.py", line 99, in <module>
main(sys.argv)
File "/system/python3.4.2/sdat2img.py", line 78, in main
init_output_file_size(output_img, commands)
File "/system/python3.4.2/sdat2img.py", line 73, in init_output_file_size
output_file_obj.flush()
OSError: [Errno 27] File too large
1|[email protected]:/storage/sdcard1 #
adithbalan said:
Everything had worked fine till i tried to convert a dat file of over 4gb. It says
0_a1[email protected]:/ $ su
[email protected]:/ # cd /storage/sdcard1
system.transfer.list system.new.dat system.img <
Traceback (most recent call last):
File "/system/python3.4.2/sdat2img.py", line 99, in <module>
main(sys.argv)
File "/system/python3.4.2/sdat2img.py", line 78, in main
init_output_file_size(output_img, commands)
File "/system/python3.4.2/sdat2img.py", line 73, in init_output_file_size
output_file_obj.flush()
OSError: [Errno 27] File too large
1|[email protected]:/storage/sdcard1 #
Click to expand...
Click to collapse
Please make sure you have 4-8GB free on your sdcard.
PiggyFlooper said:
hi @RendyAK
I have a cm12 system.new.dat. What will your program do to this
I floop the pig
Click to expand...
Click to collapse
It just do the same with the xpirt's sdat2img.
Go to xpirt thread for more info
@RendyAK, can you give me a link to the python for android
When i write this command
mount -t ext4 -o loop system.img system
Then it shows device or resource busy
@RendyAK
Hi is there a way to uninstall this zip ?
Help me !
RendyAK said:
Well, this is pretty simple, haha.
Just like the @xpirt sdat2img.
Code:
Usage: sdat2img <system_transfer_list> <system_new_file> <system_img>
And wait for the process finish.
WARNING!
I SUGGEST YOU TO "cd" TO THE DIRECTORY OF system.new.dat FIRST!
How to extract the system.img?
Just simply enter this command
Dont forget to "cd" to the directory of system.img
Code:
mkdir system
mount -t ext4 -o loop system.img system
cp -rf system system2
And the output is on system2 folder.
Dont forget to press enter each command you type!
Click to expand...
Click to collapse
After I type and enter " Usage: sdat2img...." , terminal display this "
/system/bin/sh: syntax error: '< ' unexpected
"
Lordlight said:
After I type and enter " Usage: sdat2img...." , terminal display this "
/system/bin/sh: syntax error: '< ' unexpected
"
Click to expand...
Click to collapse
Don't type it literally. You supposed to replace stuff in brackets with your filenames. "Usage:" should be there too.
Thanks a lot !
Not_Sure said:
Don't type it literally. You supposed to replace stuff in brackets with your filenames. "Usage:" should be there too.
Click to expand...
Click to collapse
Could you please give me an example ?
It is better.
Binary sdat2img, no python

Categories

Resources