How to cook android - Touch Pro, Fuze Android Development

I tried to do this too yesterday, but this spend a lot of time.
for who want to try, here go a link with the basic for make a build.
http://forum.xda-developers.com/showthread.php?t=610303
i searched a most detailed post, but i dont found.
can anyone make an better tutorial?
the only thing that is useful is "how to extract and how to repack the squashfs"
but is useful, is old, i know, but is the only
here is the full post
By jamezelle
[TUT]-PORTING-Android To The VOGUE
after many requests here is the guide
most of this is spread around the vogue
forum here and there, i just wanted to bring it all together
goal-seeing lately we have lost some good developers, this is a shot at getting more involvement in vogue/android development
I.SETTING UP YOUR SYSTEM
1. GETTING LINUX you will need to have Linux installed on your computer(dual-boot, vm, whatever). i recommend Ubuntu karmic (9.10) because its pretty new-user friendly. It can be found at http://www.ubuntu.com/
for you windows lovers here is a guide to setting up a ubuntu VM(virtual machine (if you really didnt know ))
2. THINGS/TOOLS YOU WILL NEED
Download these:
original 8/8/09 ion 1.5 build HERE(we are gonna use the bin-files and the apns-conf.xml, and a few apps) http://sourceforge.net/projects/androidhtc/files/2009-11-16/system-2009-08-08.img/download
the latest rootfs.img (find it)
these android tools (included are genext2fs (android version), split_bootimg.pl, and extract_ramdisk.sh)
after downloading, extract the zip to a folder. open a terminal and cd to the dir of the tools. click applications>accesories>terminal and type:
Code:
cd ~/whatever/
sudo rm -rf /bin/genext2fs
#dont type whats after the pound signs
#type in your password
#if you havent set up a su password yet type:
sudo passwd
#then make one, next
sudo cp -r ./whatever/genext2fs /bin/
squashfs-tools (if you have ubuntu 9.10-karmic first you will have to uninstall squashfs-tools 4.0(4.0 WILL NOT NOT NOT NOT NOT WORK) that is installed during the installation of linux ): go to system>administration>synaptic package manager. type squashfs-tools in the quick search, then right click and click mark for complete removal. then hit apply. then download and install this here http://http://ftp.us.debian.org/debian/pool/main/s/squashfs/squashfs-tools_3.3-7_i386.deb
i also strongly recommend downloading the sdk-tools v1.1(adb is almost essential when porting, for debugging purposes) enatefox has it posted on his media fire. (search for it)
3. ORGANIZATION
now that we have what we need. lets get organized.
a.mount points
we are going to use mount points while porting.
terminal:
Code:
sudo mkdir /mnt/rootfs
sudo mkdir /mnt/system
#i also have one for mounting data files
mkdir /mnt/data
b. directories
terminal:
Code:
mkdir ~/Desktop/android
mkdir ~/Desktop/android/ion
mkdir ~/Desktop/android/donut
#you get the point...
now put the ion 8/8/09 build in the ~/Desktop/android/ion folder and rename it system.sqsh then
terminal:
Code:
cd ~/Desktop/android/ion
unsquashfs ./system.sqsh
you should now have a folder called squashfs-root in the ion directory. it contains all the guts from the ion build. feel free to look around in that folder as you should get familiar with the folders and things in there
II PORTING
1. PORTING A HERO ROM(this was in zens how-to-make-a-hero-rom.txt im just adding on to it)
a. Download a rom from the dream/sapphire development forums.
b. Extract what you downloaded to ~/Desktop/android/hero. It is usually an update.zip.
c. Open the extracted folder. Inside you should see a data directory and a system directory.
d. Open the data directory and look for an app or app_s folder.
e. Open those folders and copy the apks to the system/app/ folder. Leave out what you don't need. feel free to add any custom apps. as long as they are from the same sdk number. ie 1.5, 1.6, 2.0.1, 2.1 most are pretty cross-compatible though.
f. Delete system/xbin from the rom your porting and replace it with the one from Ion.
g. Copy ~/Desktop/android/ion/squashfs-root/etc/apns-conf.xml from Ion to ~/Desktop/android/hero/system/etc/
h. Mount the latest rootfs.img
terminal:
Code:
sudo mount ~/whereever/rootfs.img -o loop /mnt/rootfs
i. Copy libaudio.so libaudioflinger.so libcameraservice.so libgps.so from /lib in the mounted rootfs over to system/lib in the rom you are porting*(donut and eclair really dont need this step because those files are in most of the latest rootfs.img's but be sure to check)
j. Edit the system/build.prop or even use the Ion build.prop.*(for donut/eclair you may want to edit the lcd density to 120 or 110 in the build.prop for qvga and 160 for 320x480)
k. Create a blank file in system/ called hero.build*(for eclair/donut create donut.build or eclair.build or eclairhero.build.....etc)
*l. for hero any systems too big to run on nand, here is a script to make a data file. put this in the ~/Desktop/android/hero directory. cut the app folder from ~/Desktop/android/hero/system and paste it to ~/Desktop/android/hero , and rename it too app_s . next run the mkdataimg.sh it should ask for you password in a terminal. type it in and then it should mount the data.img to data-mnt folder in ~/Desktop/android/hero . keep that terminal open copy the app_s folder in to data-mnt. then type y in the terminal to unmount the data.img. next:
terminal:
Code:
cd ~/Desktop/android/hero
ln -s /data/app_s ./system/app
that should make a broken symlink in system
2. Mount it and squash it
ok now that we are done porting lets put it together
terminal:
Code:
cd ~/Desktop/android/hero
genext2fs -d ./system -b 180000 -a system.ext2
sudo mount -o loop ./system.ext2 /mnt/system
sudo mksquashfs /mnt/system system.sqsh
sudo chown $USER ./system.sqsh
#and if you want
rm -rf ./system.ext2

After i will post my genext2fs

Htanks for the guide, i will try

ftp://ftp.us.debian.org/debian/pool/main/s/squashfs
The link for some reason wasn't working, so I decided to repost it seeing as how the http:// extension breaks it? Hm. Well, that's just linking to the directory tree incase if you're a 64-Bit Linux user like me .
Also, I think the instructions should be altered a bit as it doesn't seem to tell how to use squashfs tools. (I personally don't use genext2fs, but I know XDAndroid is compatible)
Here's the syntax:
Code:
mksquashfs <directory containing your Android root> <squash file destination> <other parameters>
Live example of such a usage would be:
Code:
mksquashfs ./ /home/John/desktop/system.sqsh
To extract an existing squashfs:
Code:
unsquashfs <squashfile> <extraction destination>
Note: Even squashfs-tools 4.0 seems to work just fine with extracting older versions.
There's a HOWTO document which goes more in-depth than my general overview of creating a basic system.sqsh. I only listed the key things that you would need to know.
http://tldp.org/HOWTO/SquashFS-HOWTO/mksqoverview.html
Essentially, it's almost no different than building any other Android ROM. Stinebd actually has a kitchen made for the XDAndroid package.
http://southcape.org/category/android/ <-- His blog
http://xdandroid.com/wiki/Main_Page <-- Official Wiki
There are other parameters which are optional, just type "man mksquashfs" to pull up the help man docs. Oh, and you should probably put it in bold that the version of squash-tools matters so people see that better. There's a reason for why the newer ones break compatibility with the older versions.

Related

rom cooking - unyaffs

I'm not daily Linux user but I'm usually savvy enough to figure things out; however unyaffs is giving me quite some trouble.
I have downloaded unyaffs from Lox's Rom cooking thread and placed it in the /bin/ folder but when I type /bin/unyaffs system.img I get "cannot get execute binary file". Help please?
did you chmod +x it?
kendong2 said:
did you chmod +x it?
Click to expand...
Click to collapse
No, didn't know I needed to. So now I have am getting "syntax error: ")" unexpected.
I am brand new to Rom cooking; sorry if this seems simple or stupid.
It needs to be in your computer's /bin/, not your phone's. Actually, it can be anywhere as long as it's on your $PATH. It's usually suggested that you create a /bin/ directory at your home folder (~) and then run all your personal binaries from there, then you can include that /bin/ in your .bashrc so that it gets loaded on every new terminal.
Open up a terminal window and do either
Code:
~$ gedit ~/.bashrc
or
Code:
~$ nano ~/.bashrc
depending on which editor you're comfortable with. Add the following to the end of your .bashrc
Code:
PATH=$PATH:/path-to-home/bin/
export PATH
where path-to-home is, ofcourse, the path to your home folder (usually /home/username), you can't use the ~ wildcard in the .bashrc script.
After you have your ~/bin set up, restart the terminal then move the unyaffs binary to ~/bin/ and then chmod a+x it, that way you can run the tool from any location.
To run the tool, just pass an image file as a parameter, note that the contents will be output to the directory where the image file is stored, so say I have a hero system file on my Desktop:
Code:
~$ cd ~/Desktop
~/Desktop$ mkdir HeroSystem
~/Desktop$ mv system.img HeroSystem
~/Desktop$ cd HeroSystem
~/Desktop/HeroSystem$ unyaffs system.img
end of file.
~/Desktop/Herosystem$_
The contents, along with the system.img will be in ~/Desktop/HeroSystem
Okay so added the following to bottom of my bashrc:
PATH=$PATH:/home/tito/bin/
export PATH
New terminal:
Code:
cd ~/bin
chmod a+x unyaffs
cd ~/Desktop/HeroSystem
unyaffs system.img
bash /home/tito/bin/unyaffs: cannot execute binary file
Followed all directions but still getting this error.
Found this site: hotrobots.blogspot.com/2009/07/useful-tool-unyaffs.html
Managed to unyaff my system.img; thanks for the help.
Hi, I am getting the "cannot execute binary file" error aswell..
I copied unyaffs in /bin and it is executable for everyone.
Yet and still it won't work. Any ideas?
Or do I really have to put unyaffs in a seperate bin folder and then edit bashrc?
Oh, and I'm running Mac OS X, if that's of any importance.. Bash is bash I think, or are there any differences I'm not aware of?
royalmitkaese said:
Hi, I am getting the "cannot execute binary file" error aswell..
I copied unyaffs in /bin and it is executable for everyone.
Yet and still it won't work. Any ideas?
Or do I really have to put unyaffs in a seperate bin folder and then edit bashrc?
Oh, and I'm running Mac OS X, if that's of any importance.. Bash is bash I think, or are there any differences I'm not aware of?
Click to expand...
Click to collapse
in this case you need the binary for osx, but the rest of the instructions should apply AFAIK (i have never used macos myself).
Thanks, but where can I get a binary for OSX?
The code.google.com page only offers one version of the binary..
royalmitkaese said:
Thanks, but where can I get a binary for OSX?
The code.google.com page only offers one version of the binary..
Click to expand...
Click to collapse
it is probably easier to compile it yourself...
download xcode from apple developer site for free
download source unyaffs from google site
and run gcc -o unyaffs unyaffs.c.
thats it ur done
Thanks for everyone's help. Almost done with my rom.
royalmitkaese said:
Thanks, but where can I get a binary for OSX?
The code.google.com page only offers one version of the binary..
Click to expand...
Click to collapse
I've attached version i compiled for OSX 10.6
jabbslad said:
I've attached version i compiled for OSX 10.6
Click to expand...
Click to collapse
sorry for reviving a dead thread but i was getting the "cannot execute binary file" so i used your attached compiled unyaffs and now i'm getting "Bad CPU type in executable"
I'm not registered on apple as a developer and can't download xcode :/
i'm getting "Bad CPU type in executable"
Click to expand...
Click to collapse
Are you running a 32 or 64 bit kernel on osx. You need a compile binary that is correct for your cpu. Let me know I will attach the right one in a reply. Check under apple menu >> about this mac >> more info >> software >> 64 bit kernel and extensions, yes or no.
anika200 said:
Are you running a 32 or 64 bit kernel on osx. You need a compile binary that is correct for your cpu. Let me know I will attach the right one in a reply. Check under apple menu >> about this mac >> more info >> software >> 64 bit kernel and extensions, yes or no.
Click to expand...
Click to collapse
@anika200 I'm also getting "Bad CPU type in executable". Mine is a 32bit one...
64-bit Kernel and Extensions: No
Could you please build one for 32bit kernel?
I got a hold of xcode (i love torrents ) and compiled it myself.
Heres the attached compiled OSX 32 bit unyaffs
Extract it and place it wherever you want, and to use it in another directory make sure you append it to your .bash_profile
Hey alright. You got it done before I could even check the thread again. I figured it was a 64 bit. Now we have both on here, nice.
Anyone familiar with doing this on windows?
I tried a couple of binaries, but i get errors.
Microsoft Windows XP [Version 5.1.2600]
C:\g2orgsys>unyaffs systemg2.img
28852 [main] unyaffs 3212 _cygtls::handle_exceptions: Exception: STATUS_ACCESS
_VIOLATION
30677 [main] unyaffs 3212 open_stackdumpfile: Dumping stack trace to unyaffs.e
xe.stackdump
348883 [main] unyaffs 3212 _cygtls::handle_exceptions: Exception: STATUS_ACCESS
_VIOLATION
375003 [main] unyaffs 3212 _cygtls::handle_exceptions: Error while dumping stat
e (probably corrupted stack)
Perhaps windows just sucks with this. I've never really used bash, but I got some LiveCDs around. :/
I use the attached file, works fine on windows. I think you need cygwin installed but not sure.

Ubuntu/Debian install for Slide

Ok so the ubuntu install now works on slide credit goes to eratosthene he updated all the files to make it work all other credit goes to the dev’s listed on the links provided. FYI this was tested on eugenes latest froyo rom.
1. Go to http://nexusonehacks.net/nexus-one-hacks/how-to-install-ubuntu-on-your-nexus-oneandroid/ download the ubuntu.zip file .
2. Unzip to a location on your pc to a folder named ubuntu.
3. Download the ubuntu-slide-v2 from here.
4. Unzip the ubuntu-slide-v2 to the same folder you used in step 2.
5. Create a ubuntu folder on the root of your sdcard .
6. Connect your Slide to the pc verify debugging enabled and storage disabled.
7. Adb push the files in the ubuntu folder to the /sdcard/ubuntu.
8. Then adb shell.
9. cd /sdcard then sh ubuntu.sh
Note: At this point, the scripts are now located in /data/local/bin and the mount point is /data/local/mnt
10. sh /data/local/bin/bootubuntu
11. you should now see [email protected]:/#
Note : install completed only do the following if you want to access ubuntu from android vnc app.
12. apt-get update
13. apt-get install tightvncserver
14. export USER=root
15. vncserver -geometry 480x320
16. • Run the android-vnc-viewer app and specify localhost port 5901 .
UPDATE: This is not working on CM 6 , I'm not sure why please help if you know .
That would be sooooo coool
Sent From My HTC Espresso Running Froyo Thanks to eugene373
Tried it but the install fails , may be the script or may be rights to edit the files im not that good with linux yet so im not sure .
Ok thanks, any help would be apriciated . If we can get a procedure that works ill write up a step by step for everyone and maybe make a video how to also.
Just guessing but it's probably because we don't have rw access to /system.
Until we get an unlocked bootloader it ain't happenin...
I could be completely way off though
I think you are right , if i rember most the errors where do to access issue's with files in the system folder. If it is the bootloader what would need to be done to " unlock " it ?
bled82 said:
I think you are right , if i rember most the errors where do to access issue's with files in the system folder. If it is the bootloader what would need to be done to " unlock " it ?
Click to expand...
Click to collapse
An OTA update would unlock it.
So once we get the froyo ota we should be able to follow the same process as the nexus one then ?
i would say "unlikely," i dont see how an ota would unlock the bootloader in any fashion. but i guess he might have been referencing the possibility of someone using the new ota to create an unlocked bootloader. the whole "how could the bootloader be unlocked," question bothers me, i never seem to get a straight answer
aceraider4 said:
i would say "unlikely," i dont see how an ota would unlock the bootloader in any fashion. but i guess he might have been referencing the possibility of someone using the new ota to create an unlocked bootloader. the whole "how could the bootloader be unlocked," question bothers me, i never seem to get a straight answer
Click to expand...
Click to collapse
Once there is an official OTA devs will be able to extract the keys needed to properly sign files I believe.
I thought the engineering build had an unlocked boot loader on it and once we flashed it that was that ?
Here's an updated zip for you guys. The process is generally the same as on the above-linked nexus one version, I just changed the scripts to move a few files to different places. You'll need to download ubuntu.zip from that post as well. Summary:
unzip ubuntu.zip somewhere
unzip ubuntu-slide.zip in the same place, replace all the files
make a directory called 'ubuntu' on your sdcard
adb push all the files in the zip to that directory
adb shell
cd /sdcard/ubuntu
sh ubuntu.sh
At this point, the scripts are now located in /data/local/bin and the mount point is /data/local/mnt
sh /data/local/bin/bootubuntu
You're now chrooted into the ubuntu install. Have fun.
Thanks going to try it now !!!
Does not work get attached error.
bled82 said:
Does not work get attached error.
Click to expand...
Click to collapse
I haven't tried this but based on your error, try this from the shell:
mkdir /data/local/bin
then run the ubuntu.sh again
falken98 said:
I haven't tried this but based on your error, try this from the shell:
mkdir /data/local/bin
then run the ubuntu.sh again
Click to expand...
Click to collapse
I did cd /data/local then ls and bin is listed , ran mkdir /data/local/bin failed file exists . i cant cd /data/local/bin get error cant cd to /data/local/bin
bled82 said:
I did cd /data/local then ls and bin is listed , ran mkdir /data/local/bin failed file exists . i cant cd /data/local/bin get error cant cd to /data/local/bin
Click to expand...
Click to collapse
This is some other script messed up when bin wasn't there and ended up creating a file called bin instead of it being a directory.
rm /data/local/bin
mkdir /data/local/bin
falken98 said:
This is some other script messed up when bin wasn't there and ended up creating a file called bin instead of it being a directory.
rm /data/local/bin
mkdir /data/local/bin
Click to expand...
Click to collapse
Ok getting closer , Thank you very much . Now when i ran sh .data/local/bin/bootubuntu i get error attached .
bled82 said:
Ok getting closer , Thank you very much . Now when i ran sh .data/local/bin/bootubuntu i get error attached .
Click to expand...
Click to collapse
What rom are you using? It looks like you don't have the ext3 module built into your kernel. I set my scripts up to use ext3 (more reliable, I really don't care that it eats into the life of my sd card), but many roms only have ext2. You might try uncommenting the first line of bootubuntu, and changing the ext3 to ext2 on line 10.
eratosthene said:
What rom are you using? It looks like you don't have the ext3 module built into your kernel. I set my scripts up to use ext3 (more reliable, I really don't care that it eats into the life of my sd card), but many roms only have ext2. You might try uncommenting the first line of bootubuntu, and changing the ext3 to ext2 on line 10.
Click to expand...
Click to collapse
I am running froyo using Kanged CM6 newbuild.zip from eugene373 , http://forum.xda-developers.com/showthread.php?t=721515 .

[GUIDE] Beginner guide how to make your ROM *.img from Linux OS !!!

First you must to install yaffs!!!
Download attached archive and unpack it to /usr/sbin/ folder with your File Manager or Terminal window. I preffered File Manager, it is simpliest way.
After copyed mkfs.yaffs2 and unyaffs, you must to change permissions on these two files.
Open Terminal if you don`t previously opened and write...
[email protected]_name:~$ sudo nautilus
Nautilus is File Explorer on Ubuntu Linux. On other Linux distribution you may have other File Explorer. Anyway... open it with sudo command.
Enter your root password and navigate to /usr/sbin folder.
Find these two files mkfs.yaffs2 and unyaffs.
Right click mouse on it then click to see "Properties".
In properties tab you will see "Permissions" tab.
Click on it and set "read and write" option for all users and group in this tab then close window and Terminal.
You can change permission in the Terminal window with this command if you want...
[email protected]_name:~$ sudo chmod 667 /usr/sbin/mkfs.yaffs2
[email protected]_name:~$ sudo chmod 667 /usr/sbin/unyaffs
This is it for install mkfs.yaffs2 and unyaffs.
After that, create new folders on your desktop named as "newrom".
Copy system.img from ROM instalation folder to newrom folder and run unyaffs.
Open terminal and type... Only type BOLD text.
[email protected]_name:~$ cd /home/your_name/Desktop/newrom
[email protected]_name:~/Desktop/newrom$ unyaffs /home/your_name/Desktop/newrom/system.img
Wait unyaffs to uncompress all files and folders from system.img
When unyaffs has been completed uncompress procedure, you will see something like that...
end of image
[email protected]_name:~/Desktop/newrom$
Close terminal window if you want to close.
Open folder newrom and delete system.img file. Folder "newrom" contains everything from your system.img file. You may to change, delete or something else to create your new Android build. Yes you may to be ROM cookers.
After your intervention on files and many other stuff in your "new rom", you will be prepare to create your new "system.img" file.
This process must to be in other folder with diference name. Not to be in same folder where is your previous uncopressed folders and files. In my case this folder is "newrom".
Folder for new "system.img is my Desktop.
Ok, let see what we must to do... In case when you previous closed Terminal window, you must be placed on Desktop uses CD command in Terminal.
[email protected]_name:~$ cd Desktop
You must see this...
[email protected]_name:~/Desktop$
Enter this...
[email protected]_name:~/Desktop$ mkfs.yaffs2 newrom/ system.img
And you must see this...
mkfs.yaffs2: Android YAFFS2 Tool,Build by PowerGUI
at http://www.openhandsetalliance.org.cn
Building...
Build Ok.
[email protected]_name:~/Desktop$
After that you will see new system.img on your Desktop.
For boot.img file, procedure is same except name of *.img file.
That`s it. I hope that is help.
Thanks to everyone who helped me to write this guide.
Enjoy.
FileFixer.
so much thanks. i'll have a try~
Ignore this
I have extracted the files in to the directories as suggested but when I run the command to extract the system.img I get access is denied. I have tried this as my standard user account and logged on as root any ideas?
Edit: modified the permissions on the two files I dumped in to sbin and resolved the issue!
Yes... If you don`t permission you can login as root and change rigts on this two files.
In my case i just copy these two files in /usr/sbin folder and everything work fine.
This is, maybe i think,for per user mod.
I would be to edit thread for this problem...
Works very well very nice thread man. I was able to fully extract the img file from a gingerbread build and play arround with it and rebuild it cheers!
Pictures or video's?
You will be free to create them. I have no much time for this. if you try my procedure step by step, you can learn something...
@FileFixer
Maybe you could also post a way for us to edit the initrd.gz files in the rom builds, so we can make some changes that are necessary for SD builds to work with MAGLDR "AD SD" option ourselves?
Thanks, Santroph.
Unpack initrd.gz on your desktop and open cpio archive. Inside is a few scripts and few elf files.
I am not developer but i will trying to learn more about this.
Pretty useful tutorial i will try that soon.
FileFixer said:
Unpack initrd.gz on your desktop and open cpio archive. Inside is a few scripts and few elf files.
I am not developer but i will trying to learn more about this.
Click to expand...
Click to collapse
Cool guide did you have any help you would like to credit
No, i don`t have any help about this. I just playing with some files.
FileFixer said:
No, i don`t have any help about this. I just playing with some files.
Click to expand...
Click to collapse
KillaHurtz said:
Cool guide did you have any help you would like to credit
Click to expand...
Click to collapse
hehe
(10 chars)
When I use the command unyaffs /home/your_name/Desktop/newrom/system.img I get an error open image file failed.
Why is this not working for me?
...
Never mind, it worked!
Very useful topic!
Yo MUST be placed in to your "newrom" folder before start unyaffs command.
[email protected]_name:~$ cd /home/your_name/Desktop/newrom
then type this...
[email protected]_name:~/Desktop/newrom$ unyaffs /home/your_name/Desktop/newrom/system.img
Only type BOLD text.
Never mind, it worked for you!
After repack - no root
I did unpack and repack system.img according this guide (without any changes - only for testing). After flash the ROM works fine, but is not rooted. Original ROM is rooted.
Why? I didn't make any changes in unpacked system.img.
Can anyone help me with this, please?
Thanks.
I think that you must set permissions to all before pack img file.
santroph said:
@FileFixer
Maybe you could also post a way for us to edit the initrd.gz files in the rom builds, so we can make some changes that are necessary for SD builds to work with MAGLDR "AD SD" option ourselves?
Thanks, Santroph.
Click to expand...
Click to collapse
Hi,
Here's a quick howto
* mkdir initrd-temp
* cp initrd.gz initrd-temp
* cd initrd-temp
* gunzip initrd.gz -c | cpio --extract --make-directories
* rm initrd.gz
* Make your changes
* find .|cpio -H newc -o|gzip -9 -c - > ../initrd.gz
I hope that helps
Hey,
thanks for this useful thread!
I have problems in this whole process of booting a custom rom ( in my case Miui) in the Emulator . I have compiled the whole rom on a Linux VM with your Guide and pushed it in a Windows system into android-9/images/system.img but it won't boot I don't know what I am doing wrong. My system.img is 2 GB big I think this is not normal. if i am replacing the system.img with the original out of the emulator, it is booting. I just want to boot the Miui rom to port some features to Cyanogenmod... Thanks in advance. I have a HTC Legend btw .

(Guide) How to logcat, ADB, shell, etc

ADB:-
Android Debug Bridge
Very useful program made itself by Google for Programmers and developers. Its based on command line and basically communicates with your Android to respond to certain commands. There is vast amount of knowledge about adb but its most useful commands limit to getting:-
Logcat:-
A real time log of what is happening in background of our devices. It is really useful for developers to see which component has malfunctioned and helps to narrow down their search for what failed and what needs to be fixed. Several times users are asked to give logcats of their devices which are giving errors. We will go in detail that how to get logcats in every and easiest way possible.
App Installation and Management:-
adb proves really handy if you want to install apks directly from your PC or want to batch install or delete them.
Shell Execution:-
You must have heard of Terminal Emulator. It is an app for android to execute shell commands(linux commands) which are basically present as applets in /system/bin, /system/sbin or /system/xbin(in our case) folders. A very imporant applet called busybox is installed there mainly used for execution of basic commands during root browsing or ROM installation. Many times updater script of ROMs use busybox commands to install it. Well, these commands can be initiated from your device too but they can be initiated from adb also making it easy for programmers.
Pushing and Pulling:-
Most used commands of adb. adb makes it a piece of cake for new device developers to get an ideo of structure and basic knowledge of devices by pulling command. We can pull out i.e copy any files or folders from our devices to our PC, even the root directories without rooting the devices. It help rooters and ROM chefs of new devices to get an idea and implement their mods on them. Pushing is also very useful command. It copies your files and folders from PC to your device. Very useful in pushing some /system apps and other things
Remounting and setting permissions
Basic commands:-
Of-course basic commands such as reooting and rebooting in recovery ode and download mode are supported.
Others:-
There are several other features of adb such as fastboot, aapt, etc
Setting up ADB
Pre Requirements:-
A little amount of brain
PC(This is a windows guide, if asked I will add linux and mac guide later)
Java Runtime environment or Java Developing kit
Your Device Drivers
An Android Device
Assuming you all these ready and working properly, we continue
If you are having trouble completing Pre-Requisites, there are several guides featuring them too
Start
1. First Download Android SDK. Roughly about 70 MB
2. There may be any compressed zip file or exe file
If zip file, then extract it to C:\android-sdk
If exe file then double click on it and install it in C:\ Drive(or any other drive you want)
3. Now to get adb and other tools, you need to download 'Platform Tools'
To download them, go to the android-sdk folder and double click on SDK Manager
It will ask you which package to download? However, it is your choice which package to Download, but here, we will only talk about platform
Tools. So, simply tick on Platform Tools and click on install. Once you have done it. Go to the platform-tools folder in the directory where you installed android-sdk. You will find several files there like adb, fastboot, aapt, etc
4. Now, you can backup the whole folder of android-sdk to any external storage that will make you not download package
again if you want to. You can have it placed in any computer and run it as it does not require registry to work
5. Now, you are just one step away from using adb. Next step is SKIPPING SETTING ENVIRONMENT VARIABLE
Many guides on internet say that it is to be done for making it easy for users and if you have some basic knowledge of Command Prompt,
you will know that to execute any application with command prompt, you first need to change the directory to the one where application is
placed. And to skip changing the directories every time you open CMD, you need to put that application is environment variable. Howeve, we will not do so.
6. Type cmd in the search bar. Copy cmd.exe from there. Go to the directory where you have installed android-sdk. Go to platform-tools folder. Paste cmd there, right click on it and in the settings, select Run as Administrator.
7. You are done. Now what to do in it?
ADB Commands
Type adb in command prompt. And several commands will show up on your screen. It is very difficult to analyse these all commands, so we will only talk about most used and important commands
Connect your device via USB cable
And open the CMD in platform-tools folder(Make a shortcut of it on desktop). And type the suitable commands
Code:
adb devices
Will show the list of devices attached to the PC andtheir serial numbers. If this shows up correctly on your PC, then it means that everything is fine for continuing.
Logcat
Code:
adb logcat
It will display the real time log of your device
Best time to do it is when your device boots up
Now, many users ask me how to copy the logcat and upload it from CMD
There are several methods:-
1. Right click on the Title Bar of Command Prompt. Hover the cursor over edit and select mark. Select all the things you want to copy and then click enter. All the things will be copied to clipboard.
2. This is the correct way of getting logcat saved.
Code:
adb logcat > logcat.txt
This command will create a logcat.txt document in platform-tools folder with the complete logcat of the device. Ofcourse you can type any name instead of logcat.txt
3. I prefer taking logcat this way as it neatly compiles logs of different time
Code:
adb logcat -v long > logcat.txt
This is a very nice way to get logcat.
Installing Apps
Code:
adb install %PATH OF APK%
This will install an app on your Android
For example, if my app AreeB.apk is in G:\ drive (G:\AreeB.apk)
Then I will type
Code:
adb install G:\AreeB.apk
Be sure your apk is not in a folder that has space in its name, else the command will break at space bar.
For eg:-
G:\Program Files\AreeB.apk
Mounting
However, I never found any problem in tweaking with system files with adb, but some users said that they couldn't do it, so the problem was that their system partition was mounted as Read Only(R/O)
So, it is necessary now to tell how to mount system partition as Read Write(R/W)
Code:
adb remount
It is easiest way to do so, if it does not work then
There is another method that we will discuss in ADB Shell commands section
Pushing and Pulling
For pushing,
Type
Code:
adb push %PATH TO BE PUSHED% %PATH WHERE TO BE PUSHED%
Suppose I have an app named SystemUI.apk(PATH = G:\SystemUI.apk) which I want to push in /system/app/ on my android(or in other words, install an app as a system app). Then I would type
Code:
adb push G:\SystemUI.apk /system/app/
More examples
G:\Dance.txt file to be pushed in Dance folder in sdcard
Code:
adb push G:\Dance.txt /sdcard/Dance/
OR
Code:
adb push G:\Dance.txt /mnt/sdcard/Dance/
G:\Movies folder to be transferred in SDCARD in Videos Folder
Code:
adb push G:\Movies /sdcard/Videos/
G:\system\framework\framework-res.apk to be pushed in /system/framework/
Code:
adb push G:\system\framework\framework-res.apk /system/framework/
For pulling,
push command replaces with pull and paths are swapped
Code:
adb pull %PATH TO BE PULLED FROM% %PATH TO PLACE PULLED FILE%
Example,
All system apps are to be pulled to G:\ROM\system\app
Code:
adb pull /system/app G:\ROM\system\app\
build.prop to be extracted to desktop
Code:
adb pull /system/build.prop C:\Users\Areeb\Desktop\
However, if a folder is in platform-tools folder, you don't need to type full path
Suppose if I type
Code:
adb pull /system/ system
Then a folder named system will be created inside platform-tools with all the files in system in it
If a file is in platform-tools folder, then also no need to type full path
For example,
There is an app name DeskClock.apk in this folder then, to push it to /system/app, type
Code:
adb push DeskClock.apk /system/app/
ADB Shell Commands
This mode of adb allows you to execute linux shell commands from your PC
These commands can aldo be executed through the mobile using Terminal Emulator
To initiate shell mode
Type
Code:
adb shell
You will get an prompt like this
sh-3.2#
Now you are in shell mode
adb commands won't work here and a new set of commands will work here. But we will only go in a little detail here.
Assuming you are in adb shell mode, I will only type commands that will work on shell. Note:- These commands won't work if you type them alone on cmd. But, these command will directly work on your mobile's Terminal Emulator
As these commands can also work on mobile, I am going to tell you a way of taking logcat on mobile
Type
Code:
logcat
You will see log of your device
To save this
Type
Code:
logcat > /sdcard/log.txt
A file named log.txt will be generated in sdcard
Uninstalling Applications
Code:
cd /data/app
This will change the directory to /data/app
Code:
ls
This will show the list of files in there
Suppose, there is an app named com.opera.browser (Opera Mobile) you want to uninstall it
Type
Code:
rm -r com.opera.browser
This will uninstall the app
Mounting Command:-
Code:
mount -o rw,remount system /system/
Miscellanous commands:-
su: Initiates root request
du: Shows files, folders and size
date: Shows todays date
surfaceflinger: Shows your bootanimation (Tested on GB)
grep: Used to search through text files
chmod: Sets permission to files
sh: Initiates shell mode
echo: Displays the text you wrote with the command. Analogous to PRINT command on QBasic
Forgot next ones, will write later
Credits
Google: For Android and several searchings
Samsung: For Galaxy Ace s5830I
Broadcom: For their Open Sourceness
XDA Forums : For the precious knowledge
My Uncle: For gifting me this Phone
My Teachers: For teaching me English(I would not be here without them)
You: For future Thanks
Till now, thats it, will add some more things later
If any problem, I will add it too
Suggestion? They are welcome
Nice thread , every thing is very clearly stated.
Thx, Nice guide.
I suggest to change the 'remount' command in:
mount -o remount,rw /system
As the effect is the same and it works universally (at least, should)
Sent from my GT-5660 using xda app-developers app
ItachiSama said:
I suggest to change the 'remount' command in:
mount -o remount,rw /system
As the effect is the same and it works universally (at least, should)
Sent from my GT-5660 using xda app-developers app
Click to expand...
Click to collapse
I use the command you mentioned every time. Thanks for reminding. I can't remember why I wrote that command there!

SOLVED! Python on the command line (scripts on post #17)

Hello everyone,
If your just reading this, skip to page 2 to save me some embarassment... Been a learning curve.
Go here .... http://forum.xda-developers.com/showpost.php?p=47607547&postcount=17
First post here and well I hope it's in the right place. I am definitely a novice programmer, am a little comfortable writing small python scripts which leads to this...
I got my phone rooted, I have sl4a ( It Nice! I like it. You like dogs?), and I just got my CM 10 source on Ubuntu 10 like Google recommends. I got adb working and Terminal IDE so I originally wanted to get python to be able to be called by the bash shell it provides ( I think its bash). I sorta got it working for a single session but what a drag, and I would get an error along the lines that the title suggests, so I,m not happy about that.
I also managed to get a copy of python from com.googlecode.pythonforandroid into /system/bin/ and now when I type "python" into an ADB shell I get the python interpreter!!! Whoo hooo, but I still got that same error. A "import sys", "import ephem", and maybe a few more workes but still something is wrong it said something thiss stuff here..
"""[email protected]:/data/data # python
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback
Python 2.6.2 (r262:71600, Mar 20 2011, 16:54:21)
[GCC 4.4.3] on linux-armv7l
Type "help", "copyright", "credits" or "license" for more information.
>>>
"""
update/bump
Ok so looking at the error message again it seems that it wants two prefixes for the $PYTHONHOME variable, I assume two paths and the secon one is to the executable that I put in /system/bin/ which is already in my path hence why python is callable. I had also fumbled around haphazardly with my $PATH vriables the other day and may have added the path to some of the libs python was asking for such as libpython2.6.so, I think I added the directory that lib is found in to my path (its found in "/data/data/com.googlecode.pythonforandroid/files/python/lib/" I think, need to double check that one), so thats what ive done that made this 'click' so to speak into popping out the python interpretor.
Also I found this file...MSM8960_lpm.rc but I forgot from where it came. It looks as if it contains some global variables that get set during boot, am I right?
This is the top part of it...
"""
on early-init
start ueventd
on init
sysclktz 0
loglevel 3
# setup the global environment
export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
export LD_LIBRARY_PATH /vendor/lib:/system/lib
export ANDROID_BOOTLOGO 1
export ANDROID_ROOT /system
export ANDROID_ASSETS /system/app
export ANDROID_DATA /data
export EXTERNAL_STORAGE /mnt/sdcard
export EXTERNAL_STORAGE2 /mnt/sdcard/external_sd
export USBHOST_STORAGE /mnt/sdcard/usbStorage
export ASEC_MOUNTPOINT /mnt/asec
export LOOP_MOUNTPOINT /mnt/obb
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
"""
So I am thinking that if I set the paths to my Python exec and libs here, as well as Paths for Lua, Perl, JRuby, Python 2.7, Etc, etc then I would have an assortment of scripting languages to launch into ffrom ADB, am I right? This would help me and others write scripts for ADB in many languages to do repetitive grunt work from scripts.
Any advice would be great as it works but its like python is injured, "import os" didnt work ;( but "import sys" did
It would also be nice if these same vriables could be set for Terminal Emulator, Terminal IDE, and the like, I know SSH is in the works with T. IDE and that one has telnet though I havent figured that out yet.
What should I do? This seems like an OS related issue but if the interpreter is there and compiled for arm and the libs aswell why would this not work?
python -v output
this is the "python -v" output to show what's happening, maybe it'll help....
"""
[email protected]:/ # python -v
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
'import site' failed; traceback:
ImportError: No module named site
Python 2.6.2 (r262:71600, Mar 20 2011, 16:54:21)
[GCC 4.4.3] on linux-armv7l
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import os
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named os
>>>
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# clear sys.flags
# clear sys.float_info
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] zipimport
# cleanup[1] signal
# cleanup[1] exceptions
# cleanup[1] _warnings
# cleanup sys
# cleanup __builtin__
# cleanup ints: 3 unfreed ints
# cleanup floats
[email protected]:/ #
"""
That snippet you posted is from the init.rc inside the boot.img...so yes, it has all sorts of initialization code
CNexus said:
That snippet you posted is from the init.rc inside the boot.img...so yes, it has all sorts of initialization code
Click to expand...
Click to collapse
Ok, so I'll so some reading on setting $PYTHONHOME variable and others, I need to learn how that all works anyways. Most if not all of what I find documents how to set the variables for Windows, Mac, or Linux and not for Android. I will do my best to use that knowledge to fit this situation. I also need to dive around the file system a bit more and find all those libs and try to get the paths set for those to work with ADB and not just SL4A.
If I can do that maybe some more Linux programs/commands can be moved into Android's system, I know alot of the GUI apps for Linux have dependencies for python and gtk and qt, those modules might be portable to Android if they haven't already done so. Not to mention the other interpreters like Perl. To be perfectly honest what I want to do is port over Kali's toolset (at least the cmd line tools) over to android to they can be run from a terminal emulator or adb its self. Thats what I want to do with it, then wrap it all up into a ROM and build it. I know they have already compiled most of Kali's and BackTrack's programs on ARM so I was thinking of pulling those apps from there after an upgrade and then moving them into Androids system e.g /system/bin : /system/lib : /etc/* and so on, if the file systems are too different I suppose I can add directories and make a PATH for them or add them to $PATH once I learn how all that works.
Any good documentation on related issued anyone might be able to link to would be great, I'll be droppin by every so often while I'm grinding through google, thanks in advance for any help and thank you for your time, a bit of a read I suppose.
Environment variables like that would need to be set inside the boot.img, so if you want to unpack it and see exactly how things are defined and what other files are there (good exercise all around IMO), grab my tools from over here and unpack it for yourself and take a look:
cool tools
CNexus said:
Environment variables like that would need to be set inside the boot.img, so if you want to unpack it and see exactly how things are defined and what other files are there (good exercise all around IMO), grab my tools from over here and unpack it for yourself and take a look:
Click to expand...
Click to collapse
Well I downloaded twrp 2.3.1.0-d2spr and I used the split_boot tool in the package and got a little tree of files including the init.rc and the other msm one, they seem very similar if not identical (?), weird.
I just have a quick question, do I need to repack all this at a certain size? In other words, if I make any changes in the ramdisk image will it refuse to boot? I browsed over some sites and read somewhere that if I changed the kernal image it would fail a hash check and that the type of hashing ( I use bubble bags, but that's for another forum). How much attention do I need to pay to the size of these files I may alter before I repack and flash to the device?
Edge-Case said:
Well I downloaded twrp 2.3.1.0-d2spr and I used the split_boot tool in the package and got a little tree of files including the init.rc and the other msm one, they seem very similar if not identical (?), weird.
I just have a quick question, do I need to repack all this at a certain size? In other words, if I make any changes in the ramdisk image will it refuse to boot? I browsed over some sites and read somewhere that if I changed the kernal image it would fail a hash check and that the type of hashing ( I use bubble bags, but that's for another forum). How much attention do I need to pay to the size of these files I may alter before I repack and flash to the device?
Click to expand...
Click to collapse
Yes, actually. You need to repack at certain offsets/addresses or the device will be unable to read it properly
Run the boot_info script on your .img file and it will give you everything you need to know to repack the boot.img correctly
First you gotta repack the ramdisk (repack_ramdisk [optional out file])
Then after you do that, you can use the mkbootimg binary along with the info from my boot_info script to make a new boot.img with the right offsets
I've done a ton of boot.img splitting, so here's what it should look like (I forget the cmdline parameter)
Code:
mkbootimg --kernel KERNEL --ramdisk RAMDISK --base 0x80200000 --oversize 2048 --cmdline 'android.I.don't.remember.this.one' --ramdiskaddr 0x81500000 -o new_boot.img
Sent from my S3 on Sense 5 (you jelly?)
CNexus said:
Yes, actually. You need to repack at certain offsets/addresses or the device will be unable to read it properly
Run the boot_info script on your .img file and it will give you everything you need to know to repack the boot.img correctly
First you gotta repack the ramdisk (repack_ramdisk [optional out file])
Then after you do that, you can use the mkbootimg binary along with the info from my boot_info script to make a new boot.img with the right offsets
I've done a ton of boot.img splitting, so here's what it should look like (I forget the cmdline parameter)
Code:
mkbootimg --kernel KERNEL --ramdisk RAMDISK --base 0x80200000 --oversize 2048 --cmdline 'android.I.don't.remember.this.one' --ramdiskaddr 0x81500000 -o new_boot.img
Sent from my S3 on Sense 5 (you jelly?)
Click to expand...
Click to collapse
Thanks,
I actually just got the CWM ROM manager, I updated my CWM and am backing up my rom now, its pretty much stock lacking updates cuz of root I think, I eventually wanna get over to CM or some other rom but CM seems to be supported pretty well.
1) So the backup just finished a second ago, can I pull a boot image out of that? :EDIT: Check. I saw it in the recovered folder.
2) I'll use the boot info on that img when I get it.
3) I guess this is all for testing the variables and getting interpreters to run from adb and T.E. after that I need to install CM 10 to get some blobs, thats all thats hanging me up from modifying the source to build my own version, this is great exercise as it will need to be done when building this "Cyano-Kali" or whatever, I was also thinking "Kali0id" as in Kalioid and Kali zero i.d.
ok well I did some messing around and I got this lill chroot setup working from adb which is kool, I just took a no gui kali.img and a script I found to chroot into it ( Maybe Google "Weaponizing Android"), it needs a lil investigating though I get a couple errors, it looks like it was modified from a chroot into ubuntu (arm).
I put the script into /system/xbin/ and then made it executable (that seems to be the only place I could chmod), I looked at the sript at it points to a coded directory for the kali.img which is something like "/storage/sdcard0/kali/kail.img". This puts the script in a location that is already in the environ variable and you can call it from any cwd by typing "kali".
Note: Interesting tip (may be trivial to the pros), typing "bash" gives me a colorful interface and the bash interpreter, this is good for a first command when entering the terminal or adb because then you can modify the bash rc file found in "/system/etc/bash/" (I think, I'll double check later.*FIXED*).
So, I think I might be able to mod those variables there to include PYTHONPATH, PYTHONHOME, etc...
Then when I launch bash i should be able to launch python and whatever else. (*Check*, it works but you must first "bash" and then "python" to allow the bashrc file to get ran and add PYTHONHOME and PYTHONPATH to the enviroment)
I think the first shell that you get put into is shell and not bash but maybe I'm wrong.
*side note, If you want to su into bash its best ime to do that first, then bash, otherwise when you su while in bash you loose the color, idk why.
heres my results so far...
Code:
[email protected]:~$ adb devices
List of devices attached
xxxxxxxxxx device
[email protected]:~$ adb shell
[email protected]:/ $ su
[email protected]:/ # bash
void endpwent()(3) is not implemented on Android
localhost / # kali
ioctl LOOP_SET_FD failed: Device or resource busy
mount: Device or resource busy
net.ipv4.ip_forward = 1
[[email protected] ~$ cd .. && ls
bin dev home lost+found mnt proc run selinux sys usr
boot etc lib media opt root sbin srv tmp var
[[email protected] /$ which macchanger
/usr/bin/macchanger
[[email protected] /$ which ophcrack
/usr/bin/ophcrack
[[email protected] /$ which reaver
/usr/bin/reaver
[[email protected] /$ which aircrack-ng
/usr/bin/aircrack-ng
[[email protected] /$ python --version
Python 2.7.3
[[email protected] /$ perl --version
This is perl 5, version 14, subversion 2 (v5.14.2) built for arm-linux-gnueabi-thread-multi-64int
(with 80 registered patches, see perl -V for more detail)
Copyright 1987-2011, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
[[email protected] /$ bash --version
GNU bash, version 4.2.37(1)-release (arm-unknown-linux-gnueabi)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[[email protected] /$ python
Python 2.7.3 (default, Jan 2 2013, 22:35:13)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import sys
>>>
[[email protected] /$ exit
Shutting down Kali ARM
failed: Device or resource busy
losetup: /dev/block/loop255: Device or resource busy
localhost / # exit
1|[email protected]:/ # ^D
1|[email protected]:/ $ ^D
[email protected]:~$
Does anybody know how to mount an external sdcard from the command line on the Debian version of Linux on Android?
Is that even possible, like driver wise and what not?
Nice!
To mount it, first you would need it's device name or UUID..
Sent from my S3 on Sense 5 (you jelly?)
Success!
Alright! I got Python working from the terminal emulator!
I ended up copying the files that got installed by the original installer into my system/ lib, xbin, and, bin directories I just kinda put stuff here or there and then I just got one error about platform independent libraries instead of both dependent and independent. I'm alil add about things sometimes. Then about ten minutes ago while chilling on the patio the syntax for the PythonHome and path variables became clear to me. So i changed it to export and wrapped the paths in quotes and figured out the prefix : exec_prefex thing.
Now python works!!!!!!! ill run it on adb tomorrow and show the results as well as exactly how to get it working after i figure out exactly what i did right. It was probably the last thing.
Edge-Case said:
Alright! I got Python working from the terminal emulator!
I ended up copying the files that got installed by the original installer into my system/ lib, xbin, and, bin directories I just kinda put stuff here or there and then I just got one error about platform independent libraries instead of both dependent and independent. I'm alil add about things sometimes. Then about ten minutes ago while chilling on the patio the syntax for the PythonHome and path variables became clear to me. So i changed it to export and wrapped the paths in quotes and figured out the prefix : exec_prefex thing.
Now python works!!!!!!! ill run it on adb tomorrow and show the results as well as exactly how to get it working after i figure out exactly what i did right. It was probably the last thing.
Click to expand...
Click to collapse
Nice
Sent from my S3 on Sense 5 (you jelly?)
Solution !
Ok I got everything cleaned up a bit, lets see whats going on here...
So hopefully bash is preinstalled for everyone, I just found it, the only changes I made in the past week are installing...
1) CyanogenMod, I believe you will need to already be rooted, have busybox, and a custom recovery to get this far. If you can get CyanogenMod working then you'll probably be able to replicate this, mayeb even with just root and busybox on a stock sprint rom, idk.
2) SL4A along with Python 2.6, Perl, and JRuby. (I hope normal ruby programs can be ran will JRuby, if not I'll either mod the programs or port ruby to android or look for another port.
3) Terminal IDE. This could have been a source of bash if it wasn't native to android or the Terminal Emulator/busybox.
Once you have The above, at least python 2.6 with SL4A, Terminal Emulator, Busybox, and root.
You can (the file system maybe different for different phones but since we are in a specific place of this forum I'll stick with what I found on my phone specifically)
Use a root browser and find a way to remount your file system to read/write or r/w or rw mode so you can write to /system directory. It is located in the / directory of the entire system, not just the sdcard0 partition.
You can open a terminal and type "set" to get a closer look at whats happening here on Android. We are mainly interested in the Environment Variables.
What I did was copy
"/storage/sdcard0/com.googlecode.pythonforandroid/extras/python" ----> "/system/etc/python" ##THIS IS A DIRECTORY
"/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6" ----> "/system/lib/python2.6" ##THIS IS A DIRECTORY
"/data/data/com.googlecode.pythonforandroid/files/python/bin/python" -> "/system/xbin/python ##THIS IS A FILE, IT IS AN EXECUTABLE!
"/"/data/data/com.googlecode.pythonforandroid/files/python/lib/" ----> "/system/lib/python2.6/" ##WE WANT ALL THE "*.so" FILES NEXT TO THE ORIGIONAL "*/PYTHON2.6/" DIR IN THE "DATA/DATA/" SIDE OF THE TREE TO BE COPIED TO THE SYSTEM SIDE AND INTO THE "/system/lib/python2.6/" DIR NEXT TO THE "/system/lib/python2.6/lib-dynload/" DIR
We want our "/system/lib/python2.6" directory to contain the following :
"/lib-dynload" is a dir; and all the .so files from earlier there are about 8 with a fresh install of python and no modules, some of you may already know how to incorporate modules from this point, but I still need to do some experimenting.
---------------------------------------------------------
OK
if you still following then your gonna wanna do the following
go to "/system/etc/bash" and open the bashrc file, we need to add PYTHONPATH and PYTHONHOME to it, this is how I set it up....
About half way down it will read
Code:
"""
# set some environment variables
HOME=/sdcard
TERM=linux (maybe change this to "Administrator" but that may break something)
"""
# Our additions follow:
export PYTHONHOME="/system/etc/python:/system/xbin/python"
export PYTHONPATH="/system/etc/python:/system/lib/python2.6/lib-dynload:/system/lib/python2.6"
Ok, now if you go to your teminal emulator or ADB shell you can type:
bash [press enter]
python [press enter]
and check out the results
or
su [enter]
bash [enter]
python [enter]
and see what happens
whats happening is that your PYTHONHOME and PYTHONPATH variables are being set when you enter bash, and since they are exported from the bashrc file they get carried over to any child activities that may spawn, such as "python". Correct me if I am wrong.
I may have forgot some little file I put somewere a few days ago or something so let me know if it doesn't work for you i'll do my best to help you get it working on your phone to,
other then finding a rc file for the shell that you start with when you launch the terminal or any other process maybe even, I may need to do what CNex suggested and complete the change in a boot.img to flash to my phone. that should result in the variables being passed to all activities.
Peace yo
Any questions I'll drop around if this dies of from here, well live and let die I suppose.
Just a screen shot
Just a screen shot.
I found the "mkshrc" file in "/system/etc" today so I added the PATHs to that file and now when teminal emulator starts it has access to python's libs. ("/system/etc/mkshrc" should be the location)
I've run into two problems, the first I can live with, the second is only more reason to port Kali's toolset into android.
1) I can't yet access the pydocs for interactive help, for example...
Code:
[email protected]:~$ adb shell
[email protected]:/ $ python
dlopen libpython2.6.so
Python 2.6.2 (r262:71600, Mar 20 2011, 16:54:21)
[GCC 4.4.3] on linux-armv7l
Type "help", "copyright", "credits" or "license" for more information.
>>> import android
>>> help (android)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/site.py", line 431, in __call__
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/pydoc.py", line 1720, in __call__
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/pydoc.py", line 1766, in help
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/pydoc.py", line 1508, in doc
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/pydoc.py", line 1314, in pager
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/pydoc.py", line 1338, in getpager
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/tempfile.py", line 286, in mkstemp
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/tempfile.py", line 254, in gettempdir
File "/home/manuel/AptanaStudio3Workspace/python-for-android/python-build/output/usr/lib/python2.6/tempfile.py", line 201, in _get_default_tempdir
IOError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/']
>>>
And
2) When I chroot into Kali.img the PYTHONPATH and PYTHONHOME variables get carried over and interfear with python within Kali. ????
Work around: is just modifing "bashrc" then when you want python or other inerpreters launch bash first and call kali from shell.
Solution: is porting Kali's Toolkit and more Linux programs and commands into Android. Then release as rom or give instructions on how to set up.
No Really, I think I got it figured out this time.
If your running python 2.6 via Py4a then youll use the first script to access python from the command line or over adb, you'll need su to but it in /system/bin or /system/xbin and to use this command to write to the system partition "mount -wo remount systemfs /system" when your done use "mount -ro remount systemfs /system" (with out the quotes of course).
Note: adbd can only be ran as root, so this method will only work as root. Also I had some trouble disconnecting from adb as "exit", it hung till I unplugged the phone from usb. But, still I got to run scripts python that utilize the androids api with-out having to directly open sl4a and then the python interpreter from there.
Note2: Maybe one who was slick enough could get the source for sl4a and pick out the server and facade code, then make a little dex to be ran from the command-line instead of starting the server via "am" and instead of using sockets, maybe ashmem to share the JSON results that get sent back to python.
This is the script for 2.6 :​
Code:
#!/system/bin/sh
am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER \
-n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher \
--ei com.googlecode.android_scripting.extra.USE_SERVICE_PORT 54326
export AP_PORT=54326
export AP_HOST=127.0.0.1
adbd &
export EXTERNAL_STORAGE=/mnt/sdcard/com.googlecode.pythonforandroid
export PY4A=/data/data/com.googlecode.pythonforandroid/files/python
export PY4A_EXTRAS=$EXTERNAL_STORAGE/extras
PYTHONPATH=$EXTERNAL_STORAGE/extras/python
PYTHONPATH=${PYTHONPATH}:$PY4A/lib/python2.6/lib-dynload
export PYTHONPATH
export TEMP=$EXTERNAL_STORAGE/extras/python/tmp
export HOME=/sdcard
export PYTHON_EGG_CACHE=$TEMP
export PYTHONHOME=$PY4A
export LD_LIBRARY_PATH=$PY4A/lib
$PYTHONHOME/bin/python "[email protected]"
This one is for 3.2 :​
Code:
#!/system/bin/sh
am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER \
-n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher \
--ei com.googlecode.android_scripting.extra.USE_SERVICE_PORT 54332
export AP_PORT=54332
export AP_HOST=127.0.0.1
adbd &
export EXTERNAL_STORAGE=/mnt/sdcard/com.googlecode.python3forandroid
export PY34A=/data/data/com.googlecode.python3forandroid/files/python3
export PY4A_EXTRAS=$EXTERNAL_STORAGE/extras
PYTHONPATH=$EXTERNAL_STORAGE/extras/python3
PYTHONPATH=${PYTHONPATH}:$PY34A/lib/python3.2/lib-dynload
export PYTHONPATH
export TEMP=$EXTERNAL_STORAGE/extras/python3/tmp
export HOME=/sdcard
export PYTHON_EGG_CACHE=$TEMP
export PYTHONHOME=$PY34A
export LD_LIBRARY_PATH=$PY34A/lib
$PYTHONHOME/bin/python3 "[email protected]"
Explanation:​-First, the server which handles calls to Android's APIs gets starts by it's activity with am and port is set.
-Second, AP_PORT and AP_HOST get exported so that android.py will have its parameters set to interact with the "facade"
-Third, adbd gets started in the background (I cant give a full explanation, but I found the RPC mechanism between the python interpreter and the sl4a server when android.py is imported and droid.* is attempted)
-Fourth, Python's environment variables get set, doing it this way helps to avoid copying the whole python installation to /system (as I did in the past ), just put one of these scripts in /system/bin or /system/xbin and name it "python" then chmod the script "chmod 755 python" you will be able to call the interpreter and put the shabang in your python scripts (ie "#!/system/bin/python").
-Fifth, launch the interpreter.
Here is a short session over adb:​
Code:
[email protected]:/ # python
dlopen libpython2.6.so
Python 2.6.2 (r262:71600, Mar 20 2011, 16:54:21)
[GCC 4.4.3] on linux-armv7l
Type "help", "copyright", "credits" or "license" for more information.
>>> import android
>>> droid = android.Android()
>>> droid.makeToast("Hello!")
Result(id=0, result=None, error=None)
>>> droid.getLastKnownLocation()
Result(id=1, result={u'passive': {u'bearing': 0, u'altitude': 0, u'time': 1384816643565L, u'longitude': -67.551754299999999,
u'provider': u'network', u'latitude': 96.0520909, u'speed': 0, u'accuracy': 3533}, u'network': {u'bearing': 0, u'altitude': 0, u'time':
1384816643565L, u'longitude': -67.551754299999999, u'provider': u'network', u'latitude': 96.0520909, u'speed': 0, u'accuracy':
3533}, u'gps': None}, error=None)
>>> exit()
And some credit to others:
http://code.google.com/p/python-for...sh?r=997929b1bbaa53cdf76acfff419ec13c13f869b7
http://stackoverflow.com/questions/10839879/python-sl4a-development
Those are links to where I got some info from to help put this together. The adbd thing was just trying "adb forward tcp:xxxx tcp:xxxx" but that didn't work, so I tried adbd forward tcp:xxxx tcp:xxxx and it looked like it hung there, so I ctl^ c and then just adbd and it hung there again, but when used the "&" to background it and then went to python to try android.py, it worked:good:
And for a lot of fun, go here:
http://code.google.com/p/android-scripting/wiki/ApiReference
-or here-
http://www.mithril.com.au/android/doc/index.html

Categories

Resources