Apr 27, 2010

Boot process.... BIOS.... SCSI..... demystified....!!!!

When computer is turned on....


In short : BIOS will find the primary boot device(Hard Disk (HD) ) and loads first 512 bytes of it (MBR area)..
MBR area contains GRUB stage 1 which loads stage 1.5 ( 30kb immediately after 512b ). stage 1.5 loads stage 2...

So BIOS...?

Mar 22, 2010

android file handling

So start an emulator with sdcard some things that I tried ---->
  • emulator -sdcard sdcard1.iso -avd avd_1.5
  • mksdcard 8M sdcard
  • emulator -sdcard sdcard &
  • adb push YOUR_FILE_A /sdcard
list the files(directories also) on an SD card : http://markmail.org/message/qgfx35u7sjb4z4wr

Mar 21, 2010

setting Samsung Galaxy in Ubuntu 9.04


So here it goes…. the environment that I worked with is Ubuntu 9.04… Samsung Galaxy. It was not detecting in my ubuntu… so I fallowed these steps to detect it.. ( Thanks Saurav )….
Steps
Make a file 50-android.rules in /etc/udev/rules.d/ folder and add the following into that
SUBSYSTEM==”usb”, SYSFS{idVendor}==”18d1″, MODE=”0666″
———————————————————————————————
Make another file 90-android.rules in the same folder /etc/udev/rules.d/ and add this into that
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”04e8″, ATTRS{idProduct}==”6640″, MODE=”0660″, OWNER=”root”, GROUP=”androiddev”, SYMLINK+=”android%n”
SUBSYSTEM==”usb”, SYSFS{idVendor}==”04e8″, MODE=”0666″

———————————————————————————————-
Now do this /etc/init.d/udev restart
———————————————————————————————-
Now connect the Galaxy phone into PC
Next go to android-sdk/tools/ then do the following
./adb kill-server
./adb start-server
./adb devices

If it is detected you r lucky…. otherwise you are more lucky, coz you r goin to learn more….
so,…. it should show something like the following
List of devices attached
I7500bH2irb7283 device

If your emulator is running it will show that also.
or if it is showing this…..
List of devices attached
then you have to change the adb with a patch version..
open a terminal
go to android-dk/tools/ folder then do the following….
wget http://floe.butterbrot.org/external/adb.gz
gunzip adb.gz
chmod +x adb

Now do this, ./adb devices.. I am sure it will show the device…. if it is connected… if not check following steps…
Note: here I have used Galaxy model I7500 its ID vendor and ID product is given 04e8 and 6640 respectively. That is why in the rules files I gave like this
ATTRS{idVendor}==”04e8″, ATTRS{idProduct}==”6640″
S if your are using a different model like Galexy I9000 or any other vendor product, you have to change these numbers accordingly. So for to get the number. Connect the mobile to the system and then open a terminal and type lsusb . Then you can see something like this

Bus 001 Device 003: ID 0fca:8004 Research In Motion, Ltd.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 046d:c018 Logitech, Inc. Optical Wheel Mouse
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
ID vendor: product I have highlighted in green. First is my RIM blackberry. so find that two IDs and update that in rules files

Make a file 50-android.rules in /etc/udev/rules.d/ folder and add the following into that
SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"
---------------------------------------------------------------------------------------------
Make another file 90-android.rules in the same folder /etc/udev/rules.d/ and add this into that
SUBSYSTEMS=="usb", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="6640", MODE="0660", OWNER="root", GROUP="androiddev", SYMLINK+="android%n"
SUBSYSTEM=="usb", SYSFS{idVendor}=="04e8", MODE="0666"
----------------------------------------------------------------------------------------------

Actually I am working with number of mobiles, I have lot of rules files... so edit your rules files as shown in lsusb ... for u r mobile model surely that will be different..

Mar 16, 2010

Android-Content Providers...

Activities, Service, Content providers, Broadcast receivers the four heros of android... hu hu ha ha.. So this scratch is for the content providers.. simple defnition is 'provider of the content' or database...

Some points...
  1. Android applications can use a file or sqlite database to store data.
  2. CP provides a way in which we can share data b/w multiple applications
  3. Consider Contact DB.. If it is used by different apps,... put it in CP for to hv common access.
  4. if u want u r data to b public and accessed by many apps,.. put it in u r own content provider.
Apps can do following operations on CP
  1. Querying data
  2. Modify records
  3. Add records
  4. Delete Records
Standard CP are there : contacts, images.. implemented by android.

Querying data: We require content provider URI, URI consist of 3 parts..
  1. the string “content://”,
  2. segment representing kind of data to retrieve and
  3. optional ID of specific item of the specified content provider
URI : ( what is its full form ? )
  1. query URIs are somewhat arbitrary and confusing.
  2. For this android provide list of helper classes in android.provider package that define these query strings
this much is from : http://www.androidcompetencycenter.com/category/android-basics/

------------------------------------PART II-----------------------------------

So some scratches about Database ( before CP ) Okie ?.. Okie...
  1. Android uses Sqlite database system
  2. the database that you create for an application is only accessible to itself, others can't access it. is stored in the/data/data//databases folder
  3. Creating the 'DBAdapter' Helper Class; that creates, opens, closes, and uses a SQLite database. encapsulate all the complexities of accessing the database.
More about tat in this link: http://www.devx.com/wireless/Article/40842

Try with the Listings.. I m gonna try....

uph... a little difficult.. okie.. again bk to basics.... hureeee..... HLT

next Page: http://www.devx.com/wireless/Article/40842/0/page/2


reference
Cursor: http://developer.android.com/reference/android/database/Cursor.html
Context: http://developer.android.com/reference/android/content/Context.html

Dec 10, 2009

access google contacts through python using google apis

An address book completely online, it can be accessed from net from mobile, from netbook, pdas...gud idea right !!. well here comes google's address book APIs. There is no argument that google's address book is the best online address book.
So lets go to live with it.... ( 1 hrs )
Google contact APIs are available for python, java, javaScript,... But to explain I think python is best as it is very simple.
Requirements : Google contact APIs for python ( google it to download ), Python 2.x( mine is 2.6 ), my operating system is ubuntu. PS: Net connection is a must.
Here as I am using Linux, the explenation is based on linux.
First set the path to the apis. For that, first untar the tar file to some place. Inside that there are two folders atom and gdata. set python path to that folders as follows.
Open a terminal and type,
PYTHONPATH=$PYTHONPATH:/folder/folder/.../ folder/gdata/
okie then enter into python. type python2.6 in terminal ( or python2.x, x is your version, type python and press "tab" ). Then do the following scripts.
import atom
import gdata.contacts
import gdata.contacts.service
gd_client = gdata.contacts.service.ContactsService()
gd_client.email = 'yourmail@gmail.com'
gd_client.password = 'yourpassword'
gd_client.ProgrammaticLogin()

feed = gd_client.GetContactsFeed()

for i, entry in enumerate(feed.entry):
print '\n%s %s' % (i+1, entry.title.text)
if entry.content:
print ' %s' % (entry.content.text)
for email in entry.email:
if email.primary and email.primary == 'true':
print ' %s' % (email.address)

You can write it into a name.py file and run with python command or write each line one by one in python command line. Okie, you got your contacts. This is just for testing google Contact APIs. The APIs provides all the main functions like new, update, retrive,etc..
So the real code we can try in java and j2me as j2me is used for mobile, pdas and java is good for netbooks, touch pads etc.. So it is like a single contact book.
In mobile speed will not be a big problem as one contact set size will go only to some few bytes ( some 50, 60 bytes ). And even if GPRS is as slow as 1kbps( ie 1000bits = 125 bytes ). So it will load in a half second. It is more fast than mobile address book. mmmmm.... really the juice is worth the squeeze.

Oct 2, 2009

Hack your Master Boot Record..

MBR,is the first 512 bytes of any storage system ( can be USB drive hard disk CDROM or any storage media ) is the place where the details about the partitions in that storage drive is kept. More than partition table MBR contains a code area, which contains the code to be executed and some other areas also.

That means when BIOS completes its routne checkups and POST (Power on self test) kind of stuffs, it then loads the code in the code area of the MBR. Loading means fetch the code and put it into the RAM :). Then loads the Program counter with the first address of this loaded code. So this piece of code will starts executing from the next cycle ( what is this cycle? :) )...

So now the ball is in our side. That small code can create magic. Normally it loads the basic OS kernel, it can be GRUB first stage.. ( google GRUB first stage to know it more ) ..

Want to see the MBR ( master boot record )...
If you are using linux, it is easy to see and analyse the MBR..

Before hacking the MBR we need its architecture.. just go through the MBR table given in this wiki link http://en.wikipedia.org/wiki/Master_boot_record

First take a terminal, log in to root and then run cfdisk. This will display the partitions. Check the partition whether it is sda or hda. In my system it is sda, so I am explaining for sda. For hda just change sda to hda.
  • run this line in terminal dd if=/dev/sda of=/root/Desktop/afile bs=512 count=1 ( of can be any path and file ).
  • run hexdump -C /root/Desktop/afile , you can see the canonical hex+ASCII display.
  • to test whether what you got is MBR or not, just check the 01FE and 01FF addresses when you execute the above line. It will be aa and 55 respectively as shown in wikipage.
  • Now lets go to code area ( 0000-01B7), hexdump the file and analyse the code area..
  • the table of primary partitions is from (01BE-01FD), 64 bytes ( Four 16 byte entries )..
  • 01BE-01CD; 01CE-01DD; 01DE-01ED; 01EE-01FD; <- four sixteen byte entries.
  • 01FE and 01FF are explained earilier as 55 and aa.
For eg: in my system the following are the four 16 byte entries.
  • 80 01 01 00 07 fe ff ff 3f 00 00 00 37 16 71 02
  • 00 fe ff ff 07 fe ff ff 76 16 71 02 3f 14 a8 04
  • 00 fe ff ff 83 fe ff ff b5 2a 19 07 ca 7a b5 05
  • 00 fe ff ff 05 fe ff ff 7f a5 ce 0c 33 91 3b 00
In the above four, my first partition only is bootable which shows the first byte(80-bootable, 00-non-bootable).
For to crack the details of other 15 bytes, go to the above mentioned wiki page and refer to "layout of one 16 byte partition record" table.. :).

Next intresting area in the MBR is the code area(446 bytes)... so what is it ?
This code area contains bootstrap program. GRUB is an example for this. GRB contains three stages. Stage 1 resides in the 446 byte code area of the MBR. It loads Stage 1.5.
Stage 1.5 resides in a 30KB immediately following the MBR.
So lets see it in our system.
  • run this line in terminal dd if=/dev/sda of=/root/Desktop/bfile bs=30720 count=1 as we do earlier. 30720 is 512+30KB ( to read the 30KB after first 512).
  • analyse bfile from address 0200( where the 30KB stage 1.5 starts )...
  • run this line to analyse the bfile, hexdump -C /root/Desktop/bfile | less
  • On scrolling the output of above command, you can see some messages and other lines on the fourth column that you have seen rarely while booting...(fourth column is the character printout of the hex files ).
  • hexdump the bfile with its different options ( man hexdump ).
  • In the fourth column you can see a line like "/boot/grub/stage2" and "/boot/grub/menu.lst" which is the stage 2 file, and menu.lst is the file which forms the interactive OS selection in GRUB.
This is some of my views on MBR. Infact, efficent MBR editing programs are available. Editting with dd command is dangerous, but it is the best way to learn the MBR.

For Web Developer

  open -a "Google Chrome" --args --disable-web-security