2010年11月27日 星期六

[Android] Install Android market in Android emulator 2.2

使用SDK下載回來的avd:
1.Download Android market apk
$ wget http://goo.gl/dz3ZB
2.Create froyo AVD
$ android create avd --target 8 --name froyo
3.Start emulator
$ emulator -avd froyo -partition-size 96
3.Modified build.prop and comment "ro.config.nocheckin=yes"
$ adb pull /system/build.prop
$ vim build.prop
#ro.config.nocheckin=yes
4.Restore to system
$ adb remount /system
$ adb push build.prop /system
5.Remove SdkSetup.apk
$ adb shell rm /system/app/SdkSetup.apk
$ adb push GoogleServicesFramework.apk /system/app
$ adb push Vending.apk /system/app
6.Shut down the emulator
$ adb reboot
7.Remove emulator image
$ cd /path/to/avd
$ rm userdata-qemu.img userdata.img cache.img
8.Restart emulator


使用自己編出來的system.img:
1.直接安裝Vending.apk和GoogleServicesFramework.apk就好了
$ adb install GoogleServicesFramework.apk
$ adb install Vending.apk
2.Restart emulator

reference:
* [Android]在SDK 2.2模擬器中安裝Market

2010年11月26日 星期五

[Security] 看雪論壇十週年

大陸最有名的資訊安全論壇看雪論壇中秋禮物(當然還有很多有名的論壇,比如說邪惡八進制等...),裡面有很多好東西,先備份一下,未來再慢慢研究吧...

順道一提完全無關的事,就是剛好在備份的時候發現,不同的壓縮演算法其實壓縮比差蠻多的,我是比了bzip2,rar,gzip,zip四種格式而已(使用預設壓縮比率)
-rw-r--r--  1 44768826 2010-11-24 11:11 pediy.tar.bz
-rw-r--r--  1 47059808 2010-11-24 11:25 pediy.rar
-rw-r--r--  1 45356338 2010-11-24 11:27 pediy.tar.gz
-rw-r--r--  1 45355127 2010-11-24 11:18 pediy.zip
這四種格式看起來是bzip2的壓縮效率最好,雖然沒有在網路上找到壓縮比的評比來實證,但wikipedia還是有列出一些其他方面的比較

2010年11月23日 星期二

[Tips] Tips to make Ubuntu faster

最近遇到問題是檔案夾開啟的速度非常緩慢,就看看是否有什麼方法可以調整一下Ubuntu的效能,目前照網路上常見的幾招來改,看起來效果不錯: )

1.更改置換檔(swap)使用率設定
$ sudo vim /etc/sysctl.conf
新增一行
vm.swappiness=10
重啟sysctl讓設定生效
$ sudo sysctl -p

2.使用readahead(不用設定)
$ sudo apt-get install readahead

3.使用localepurge清除不需要的語言檔
$ sudo apt-get install localepurge

4.使用Preload(不用設定)
$ sudo apt-get install preload

5.使用Prelink
$ sudo apt-get install prelink
修改設定
$ sudo vim /etc/default/prelink
新增一行
PRELINKING=yes
執行cron
$ /etc/cron.daily/prelink

6.關閉不需要的Gnome作業階段
System -> Preferences -> Startup Applications

7.關閉不必要的系統服務(Service)
sysv-rc-conf修改不同runlevel服務啟動的狀態
$ sudo apt-get install sysv-rc-conf
$ sudo sysv-rc-conf

8.同步啟動(Concurrent Booting)
修改啟動的rc設定檔
$ sudo vim /etc/init.d/rc
修改CONCURRENCY從none改為shell
CONCURRENCY=shell

有些設定還沒完全瞭解原理,之後碰到再寫清楚吧

reference: Ubuntu 進階優化和調校

2010年11月22日 星期一

[Android] Build Android bootchart

bootchart是一套可視覺化分析GNU/Linux啟動過程的工具,它可蒐集啟動的資訊,並產生PNG/SVG/EPS等格式的圖檔,提供我們做進一步的效能分析,以下簡述安裝過程:

1.安裝bootchart工具
$ sudo apt-get install bootchart

2.重新編譯init(讓init支援bootchart)
切換到Android source code目錄下
$ cd /path/to/android
改變init系統時間
$ touch system/core/init/init.c
載入Android bash工具
$ . build/envsetup.sh
編譯init模組
$ m INIT_BOOTCHART=true
啟動機器
$ emulator -system {/path/to}/system.img -data {/path/to}/userdata.img -ramdisk {/path/to}/ramdisk.img
設定init的time out
$ adb shell 'echo 180 > /data/bootchart-start'
$ adb shell 'mkdir /data/bootchart'

3.重新啟動機器
$ adb reboot

4.重新開機完成後檢視是否有紀錄
$ adb shell ls /data/bootchart
header
kernel_pacct
proc_diskstats.log
proc_ps.log
proc_stat.log

5.下載開機紀錄
$ cd /whatever/path
$ adb pull /data/bootchart/header
$ adb pull /data/bootchart/kernel_pacct
$ adb pull /data/bootchart/proc_diskstats.log
$ adb pull /data/bootchart/proc_ps.log
$ adb pull /data/bootchart/proc_stat.log

6.產生bootchart.tgz
$ {path/to/android}/system/core/init/grab-bootchart.sh

7.產生bootchart圖檔
$ java -jar /usr/share/bootchart/bootchart.jar bootchart.tgz
Parsing /tmp/android-bootchart/bootchart.tgz
Wrote image: ./bootchart.png


如果沒有/usr/share/bootchar/bootchart.jar這個檔案,可以在這裡取得source,解開後執行ant將會編出bootchart.jar

reference:
* Build Android Bootchart
* Using Bootchart on Android

2010年11月20日 星期六

[Android] Modify ramdisk.img on Android

ramdisk.img
A small partition image with gzipped cpio archive that is mounted read-only by the kernel at boot time. It only contains /init and a few config files. It is used to start init which will mount the rest of the system images properly and run the init procedure. A Ramdisk is a standard Linux feature.

system.img
A partition image that will be mounted as /system and thus contains all system binaries

userdata.img
A partition image that can be mounted as /data and thus contains all application-specific and user-specific data.

Here is the steps:
1.Change directory to whatever/path
$ cd whatever/path
2.Copy the original ramdisk.img
$ cp /path/to/ramdisk.img .
3.Create a temporary folder, say ramdisk-ext
$ mkdir ramdisk-ext
4.Change directory to ramdisk-ext
$ cd ramdisk-ext
5.Extract the ramdisk.cpio in the ramdisk-ext folder
$ gunzip -dcv ../ramdisk.img | cpio -idm
6.Check out the directories in ramdisk.img
$ ls
data          dev   init.goldfish.rc  proc  sys
default.prop  init  init.rc           sbin  system
7.Do some modifications
$ touch foo
$ mkdir bar
8.Recreate the ramdisk.cpio
$ find . | cpio -H newc -o | gzip -9 >../ramdisk.img
9.Start the emulator
$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img
10.Check out the directories in the emulator
$ adb shell ls -l
drwxrwxrwt root     root              2010-11-26 16:54 sqlite_stmt_journals
drwxrwx--- system   cache             2010-11-26 16:54 cache
d--------- system   system            2010-11-26 16:54 sdcard
lrwxrwxrwx root     root              2010-11-26 16:54 etc -> /system/etc
drwxr-xr-x root     root              2010-11-15 07:33 system
drwxr-xr-x system   system            2010-11-26 16:53 bar
drwxr-x--- system   system            2010-11-26 16:52 sbin
-rwxr-x--- system   system       1677 1970-01-01 00:00 init.goldfish.rc
dr-xr-xr-x root     root              1970-01-01 00:00 proc
-rw-r--r-- system   system          0 2010-11-26 16:52 foo
-rwxr-x--- system   system     106696 1970-01-01 00:00 init
-rwxr-x--- system   system      10700 1970-01-01 00:00 init.rc
drwxr-xr-x root     root              1970-01-01 00:00 sys
-rw-r--r-- system   system        118 1970-01-01 00:00 default.prop
drwxrwx--x system   system            2010-11-16 09:04 data
drwx------ root     root              2009-08-07 03:35 root
drwxr-xr-x root     root              2010-11-26 16:54 dev

gunzip options:
-c, --stdout      write on standard output, keep original files unchanged
-d, --decompress  decompress
-v, --verbose     verbose mode
-1, --fast        compress faster
-9, --best        compress better

cpio options:
-i, --extract                    Extract files from an archive (run in copy-in mode)
-d, --make-directories           Create leading directories where needed
-m, --preserve-modification-time Retain previous file modification times when creating files
-H, --format=FORMAT              Use given archive FORMAT
-c                               Use the old portable (ASCII) archive format
-o, --create                     Create the archive (run in copy-out mode)
-v, --verbose                    Verbosely list the files processed
-B                               Set the I/O block size to 5120 bytes
-u, --unconditional              Replace all files unconditionally

Examples:
  cpio -covB  > [file|device]<== Backup
  cpio -icduv < [file|device]<== Restore

"-H newc" use the new (SVR4) portable format. If you wish the old portable (ASCII) archive format, use "-H odc" instead. 

reference:
* Android ramdisk.img system.img userdata.img
* android ramdisk的壓縮與解壓縮

人肉搜尋

剛剛無聊,逛到一個我覺的還蠻人肉搜尋的網站,只要打上想要查詢的帳號,就可以搜尋到許多跟該帳號相關的資料
如果你的帳號比較特別的話,目標就很明顯了...

在網路上果然要匿名的好阿...

[Tips] screen教學

screen是非常好用的工具,男人告訴我們
screen - screen manager with VT100/ANSI terminal emulation

screen的指令都是以Ctrl鍵加上a鍵開始的,後面將以C-a代表按住Ctrl鍵+a鍵,後面將以"視窗"代表screen,基本使用到的指令大概如下:

進入screen模式
$ screen

建立screen (同時切換到新視窗)
$ C-a c

查詢所有開啟的視窗號碼,列出*號表示目前所在視窗
$ C-a w
0-$ bash 1$ bash 2*$ bash

切換視窗(# 切換到第{1..9}個視窗)
$ C-a {1..9}

清除目前視窗內容
$ C-a c

查詢全部的視窗
$ screen -ls
There is a screen on:
13931.pts-6.ubuntu (11/20/2010 06:52:09 PM) (Attached)

脫離視窗
$ C-a d
There is a screen on:
13931.pts-6.ubuntu (11/20/2010 06:52:09 PM) (Detached)

連接視窗(根據screen -ls所顯示的號碼,連接到第{號碼}的視窗)
$ screen -r {號碼}
$ screen -r 13931
There is a screen on:
13931.pts-6.ubuntu (11/20/2010 06:52:09 PM) (Attached)

更多指令教學可參考這篇