Tuesday, January 25, 2011

The Rock

昨天看到老片 The Rock
絕地任務

看到史恩康那萊要滾進一直噴火的地方
然後他從裡面打開門讓大家進來

我就想到
那當年他不就這樣出來就好了嗎
幹嘛還算timing


這是bug

Wednesday, January 19, 2011

signing multiple certificates on apk

繼上次更新如何把android裡的key轉成keystore後
http://allstarschh.blogspot.com/2009/08/blog-post.html

這次要來看看 把Apk sign多個certificate的問題

雖然Apk是可以被多個certificate sign的

但是Android Group裡一直不建議用multiple certificates來sign
應該跟指定process(uid)有關就是了


在Android上的document寫
http://neacm.fe.up.pt/docs/android/guide/publishing/app-signing.html


When the system is installing an update to an application, if any of the certificates in the new version match any of the certificates in the old version, then the system allows the update

code就是在
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=services/java/com/android/server/PackageManagerService.java;h=86504a095daf999724611f77ec6ba924dc744d7a;hb=refs/heads/eclair-release#l1349

要注意 s1是新的  s2是本來的
所以新的signature裡 只要有一個跟舊的signature中某一個match
就可以install了


不過這件code到froyo上就改了
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=services/java/com/android/server/PackageManagerService.java;h=b70d69bab7d81c72e9a84a736befeeb455e61609;hb=refs/heads/froyo-release#l1853

變成用HashSet.equals

所以現在變成兩個apk的certificates要完全一樣(不按照順序)才能upgrade了

PS.
要sign multiple certificates的話應該要用jarsigner了
signapk.jar只能用固定的alias
http://android.git.kernel.org/?p=platform/build.git;a=blob;f=tools/signapk/SignApk.java;h=c4d73c8cfba5a7784b4ad9196e4a388ebd8920df;hb=HEAD#l76

Friday, January 14, 2011

ant build to include jars

在android上
用ant build時 他會自動幫你把libs/裡的jar包到dex裡面

可是在最近的sdk Gingerbread一樣用ant build
發現不行了

看一看ant的build  $SDK/tools/ant/main_rules.xml
原來是在 dex-helper裡
apply  dx的tag裡 新的把include jar的tag拿掉了
所以把<fileset dir="${jar.libs.absolute.dir}" includes="*.jar" />加上就好了

不過話說我要用mydroid build時
又發現他的resources.arsc又不一樣了
http://allstarschh.blogspot.com/2010/10/resourcesarsc.html

__aeabi_f2uiz

之前一直遇到jni lib load不起來的問題
一直苦於無法在device上打開linker的log
所以一直不知道到底是什麼原因dlopen會fail掉
而且如果直接把linker換掉
device也就直接爛掉了....

最後只好用肉眼來比較可以load的library跟load 不起來的library
幸好在plt 就看到不一樣了
不能動的lib那多了一個 __aeabi_f2uiz

幸好也有人遇到跟我一樣的問題
而David Tuner剛好也回了他
讓我有個方向來進行
http://groups.google.com/group/android-developers/browse_thread/thread/636d11723aae3117


最後發現 我build的時候 是for emulator的
所以在device上會跑不起來

最後就
source build/envsetup.sh
lunch
然後選要跑的device就解決了aeabi_f2uiz的問題了

2011.11.17
在android-4.0的AOSP裡 libbcc的code
也在RuntimeStub.c看到 他們也遇到 __aeabi_f2uiz missing的問題


 82 #if defined(__arm__)
 83 // NOTE: __aeabi_f2uiz is missing from libgcc which comes with android,
 84 // so here's the workaround.  Remove this when __aeabi_f2uiz is available
 85 // from libgcc.
 86 unsigned int __aeabi_f2uiz(float a)
 87   __attribute__((weak, alias("__fixunssfsi")));
 88 #endi

Wednesday, January 12, 2011

android 上的dynamic linker

之前想在android上的 dynamic linker (/system/bin/linker) 上debug

source 在 bionic/linker
http://android.git.kernel.org/?p=platform/bionic.git;a=tree;f=linker;h=fc0953ae9b536b112c5a8afbfbe4548125123313;hb=HEAD

可是目前不知道如何來enable linker.c裡的debug_verbosity
因為目前發現
並不是新process起來後都會來用linker

現在的猜想是只有在之前的zygote才會來call 這個linker
所以我在之後launch activity 即使有去load自己的jni lib
也都不能看到__linker__init的log

另外也去找了gcc的code
http://android.git.kernel.org/?p=toolchain/gcc.git;a=summary

目前有看到 BIONIC_DYNAMIC_LINKER的code
但這會被包起來 最後應該是接到gcc.c裡的linker_spec裡

不過還要花時間來証實這些事就是了

Monday, January 10, 2011

call a function before main

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
__attribute__((constructor))


for GCC on Solaris
#pragma init
http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Solaris-Pragmas.html#Solaris-Pragmas


如果是c++的話
當然 最簡單的就是在global scope定義一個object(或new)

vim filetype is unknown

最近發現用vi開一些檔案時
像普通的文字檔 log
整個syntax就變得怪怪的

例如  某些字之後 就全部變highlight了 (像visual mode)

而查到可以用 :set
來看現在的filetype是什麼

看來是vim不能猜出這些檔案是什麼filetype的關系
所以最後在 ~/.vimrc裡加上


if !did_filetype()
    au BufRead,BufNewFile *             setfiletype text
endif


似乎問題就解決了!?


Friday, January 7, 2011

EventLogTags

在android webkit裡的看到了一個EventLogTags的class
但卻遍尋不著他的source

原來他是從EvnetLogTags.logtags產生的
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/webkit/EventLogTags.logtags;h=082a43734976d1570c4db1315ba12d03f48bc4fc;hb=HEAD

愛因斯坦倒了

前幾天才得知
在新生南路上的愛因斯坦已經倒了

很令人訝異的消息
一來是以前常常下課去那逛逛
連書櫃裡很多書都是從那買來的
覺得那裡面裝璜還算不錯的
跟民全舊舊的小房間比起來 愛因斯坦還蠻用心在店面的
(不過民全打九折真的是有夠實在 哈)

二來是如果連開在台大旁的原文書店都會倒的話
那原文書店到底要怎麼生存下去?

這也讓我想起了以前高雄也有一家原文書店(早已忘了店名了)  在中山路 七賢附近吧??
第一本的原文書 Thomas' Calculus 10th 也是那在拿那年的壓歲錢買的
結果後來也是倒了

三是......
最後的清倉大拍賣我竟然沒跟到呀 哭哭~~

Tuesday, January 4, 2011

很特別的comment

http://bluet.org/~bluet/pub/cryptolib.com/ciphers/skype/


把c檔案打開來看
就是很特別的comment


|*| We are reverse engineers.
|*| We can prove if you have used this code in your product.
|*| We will find you.
|*| We will prosecute for copyright infringement.

symbol interposistion

在這裡有講到 symbol interposition
http://www.airs.com/blog/archives/307

就是相同的definition存在時 linker是怎麼決定要用哪一個的

elf的specification裡提到
p82 2-12
http://refspecs.freestandards.org/elf/elf.pdf


When resolving symbolic
references, the dynamic linker examines the symbol tables with a breadth-first search. That is,
it first looks at the symbol table of the executable program itself, then at the symbol tables of
the DT_NEEDED entries (in order), then at the second level DT_NEEDED entries, and so on.
Shared object files must be readable by the process;

這裡講的是dynamic linker ,所以是dynamic linking 而不是static linking

如果是static linking 的話  就會有什麼redefined 的error出來了




突發其想

寫一個compiler, 誰來compile 這個compiler

寫一個debugger, 誰來debug這個debugger

寫一個linker, 誰來幫他link C library


Monday, January 3, 2011

death race

昨天要睡時看了部電影  Death Race



這電影的idea 應該就是來自mario car 吧

覺得最關鍵的地方在於
Frank看到犯人戴GPS tracker時的畫面

"為什麼有帶gps的犯人會來侵入我家!"
-> 一定是warden 派這些犯人來的

而為什麼犯案時還要帶gps呢?
因為如果讓犯人把gps脫掉的話  他很有可能就落跑了
而這個gps device必須安全性很高
讓犯人即使在外面也無法把他脫掉
而最後犯人也很服從的完成了他的任務

當然還有很多其他疑點
不過最後面更想讓人知道的是
warden在這第五場後
如何繼續來把Frank當賣點...