2011年3月15日 星期二

[阿宅專區] 好高的槓桿

上週五(2011/03/11)日本發生8.9規模大地震,造成非常嚴重的傷亡,先默哀一分鐘...

而今天福島核電廠傳出輻射外洩,更衝擊了全球的金融市場,台股也一度下挫447點,這時候就可看出衍生性金融商品恐怖的槓桿

source: http://tw.futures.finance.yahoo.com/future/q/q_option.php?oid=TXO&cp=8100&cm=201103&bs=1&rr=13002093960050.6967458370863815

仔細看,昨收1.6,今日最高135,單日漲幅8437.5%,就是84倍多,如果是上週五開始買,那到今天有500倍的獲利應該也不奇怪了...

好高的槓桿

2011年3月14日 星期一

[Tips] Remove a PDF File Password in Ubuntu

1.pdftk - A handy tool for manipulating PDF file.
2.qpdf - The qpdf program is used to convert one PDF file to another equivalent PDF file.
3.xpdf-utils - Portable Document Format (PDF) suite -- utilities such as pdftops and ps2pdf.

1.pdftk:
download
$ sudo apt-get install pdftk
decrypt
$ pdftk input.pdf output output.pdf user_pw YOURPASSWORD-HERE
OR
$ pdftk input.pdf output output.pdf user_pw YOURPASSWORD-HERE owner_pw YOURPASSWORD-HERE
OR
$ pdftk input.pdf output output.pdf input_pw YOURPASSWORD-HERE
WHERE
input_pw password : Input PDF owner passwords
user_pw password : Input PDF user passwords
owner_pw password : Input PDF owner passwords same as input_pw.

2.qpdf:
download
$ sudo apt-get install qpdf
decrypt
$ qpdf --password=YOURPASSWORD-HERE --decrypt input.pdf output.pdf

3.xpdf-utils:
$ sudo apt-get install xpdf-utils
decrypt and create a postscript file
$ pdftops -upw YOURPASSWORD-HERE input.pdf
convert postscript to PDF
$ ps2pdf input.ps

reference: HowTo: Linux Remove a PDF File Password Using Command Line Options

2011年3月10日 星期四

[Embedded] How to Cross Compile GNU Project Debugger

0.assume that your toolchain is
arm-linux-gcc
arm-linux-g++
arm-linux-ar
arm-linux-ld
arm-linux-as
arm-linux-strip
...
and under your PATH

1.download termcap
$ wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz

2.configure termcap
$ ./configure --target=arm-linux --prefix=/path/to/install/termcap

3.modify Makefile
$ vim Makefile
-CC = gcc
-AR = ar
-RANLIB = ranlib
+CC = arm-linux-gcc
+AR = arm-linux-ar
+RANLIB = arm-linux-ranlib

4.install
$ make && sudo make install

5.download GDB
$ wget ftp://ftp.gnu.org/gnu/gdb/gdb-6.7.1.tar.gz

6.configure GDB
$ env CPPFLAGS=-I/path/to/install/termcap/include LDFLAGS=-L/path/to/install/termcap/lib ./configure --target=arm-linux --prefix=/path/to/install/gdb

7.if error has occurred like this:
cc1: warnings being treated as errors
eval.c: In function 'evaluate_subexp_standard':
eval.c:1676: error: 'subscript_array' may be used uninitialized in this function
make[2]: *** [eval.o] Error 1
make[2]: Leaving directory `/usr/local/src/gdb-6.7.1/gdb'
make[1]: *** [all-gdb] Error 2
make[1]: Leaving directory `/usr/local/src/gdb-6.7.1'
make: *** [all] Error 2

patch code
--- insight-6.7.1.dfsg.1.orig/gdb/eval.c
+++ insight-6.7.1.dfsg.1/gdb/eval.c
@@ -1627,6 +1627,8 @@
if (nargs != ndimensions)
error (_("Wrong number of subscripts"));

+       memset(&subscript_array, 0, sizeof(subscript_array));
+
/* Now that we know we have a legal array subscript expression
let us actually find out where this element exists in the array. */

8.modify Makefile
$ vim Makefile
-CC = gcc
-CXX = g++
+CC = arm-linux-gcc
+CXX = arm-linux-gcc++

9.make & check
$ make && make install
$ file /path/to/install/gdb/bin/gdb: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.27, dynamically linked (uses shared libs), not stripped


/** install gdb-7.3.1 @ 2011-12-14 **/
1.get source
wget http://ftp.gnu.org/gnu/gdb/gdb-7.3.1.tar.gz
wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz

2.configure termcap
$ ./configure --target=arm-linux --prefix=/path/to/termcap
$ make && sudo make install

3.configure gdb & gdbserver
$ cd gdb-7.3.1
$ env CPPFLAGS=-I/path/to/termcap/include LDFLAGS=-L/path/to/termcap/lib ./configure --target=arm-linux
$ make
$ file gdb/gdb
gdb/gdb: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped
$ file gdbserver
gdb/gdbserver/gdbserver: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped


reference:
* How to Cross Compile GNU Project Debugger a Step by Step Guide
* insight: FTBFS: configure: error: /bin/bash '../.././itcl/itk/configure' failed for itk
* Cross-compile GDB 6.8 for Android

[Embedded] How to Cross Compile tcpdump

0.assume that your toolchain is
arm-linux-gcc
arm-linux-g++
arm-linux-ar
arm-linux-ld
arm-linux-as
arm-linux-strip
...
and under your $PATH

1.download libpcap and tcpdump
$ wget http://www.tcpdump.org/release/libpcap-1.1.1.tar.gz
$ wget http://www.tcpdump.org/release/tcpdump-4.1.1.tar.gz

2.configure libpcap
$ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/path/to/install

if error has occurred like this:
configure: error: pcap type not determined when cross-compiling; use --with-pcap=...

the type of packet capture could be found in configure
 6914 if test ! -z "$with_pcap" ; then
 6915     V_PCAP="$withval"
 6916 elif test -r /dev/bpf -o -h /dev/bpf ; then
 6917     #
 6918     # Cloning BPF device.
 6919     #
 6920     V_PCAP=bpf
 6921 
 6922 cat >>confdefs.h <<\_ACEOF
 6923 #define HAVE_CLONING_BPF 1
 6924 _ACEOF
 6925 
 6926 elif test -r /dev/bpf0 ; then
 6927     V_PCAP=bpf
 6928 elif test -r /usr/include/net/pfilt.h ; then
 6929     V_PCAP=pf
 6930 elif test -r /dev/enet ; then
 6931     V_PCAP=enet
 6932 elif test -r /dev/nit ; then
 6933     V_PCAP=snit
 6934 elif test -r /usr/include/sys/net/nit.h ; then
 6935     V_PCAP=nit
 6936 elif test -r /usr/include/linux/socket.h ; then
 6937     V_PCAP=linux
 6938 elif test -r /usr/include/net/raw.h ; then
 6939     V_PCAP=snoop
 6940 elif test -r /usr/include/odmi.h ; then
 6941     #
 6942     # On AIX, the BPF devices might not yet be present - they're
 6943     # created the first time libpcap runs after booting.
 6944     # We check for odmi.h instead.
 6945     #
 6946     V_PCAP=bpf
 6947 elif test -c /dev/bpf0 ; then       # check again in case not readable
 6948     V_PCAP=bpf
 6949 elif test -r /usr/include/sys/dlpi.h ; then
 6950     V_PCAP=dlpi
 6951 elif test -c /dev/enet ; then       # check again in case not readable
 6952     V_PCAP=enet
 6953 elif test -c /dev/nit ; then        # check again in case not readable
 6954     V_PCAP=snit
 6955 else
 6956     V_PCAP=null
 6957 fi
configure with pcap type=null could avoid error,
$ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/path/to/install --with-pcap=null

OR
modify configure(mark cross-compiling linux version check)
$ vim configure
 6901 #if test -z "$with_pcap" && test "$cross_compiling" = yes; then
 6902 #   { { echo "$as_me:$LINENO: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&5
 6903 #echo "$as_me: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&2;}
 6904 #   { (exit 1); exit 1; }; }
 6905 #fi
 ...
 7237 #   if test $ac_cv_linux_vers = unknown ; then
 7238 #       { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
 7239 #echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
 7240 #   { (exit 1); exit 1; }; }
 7241 #   fi
 7242 #   if test $ac_cv_linux_vers -lt 2 ; then
 7243 #       { { echo "$as_me:$LINENO: error: version 2 or higher required; see the INSTALL doc for more info" >&5
 7244 #echo "$as_me: error: version 2 or higher required; see the INSTALL doc for more info" >&2;}
 7245 #   { (exit 1); exit 1; }; }
 7246 #   fi

make and install
$ sudo make && sudo make install

check
$ file /path/to/install/libpcap
/path/to/install/libpcap/lib/libpcap.so.1.1.1: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped

4.configure tcpdump
$ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/path/to/install

if error has occurred like this:
configure: error: cannot determine linux version when cross-compiling

modify configure(mark cross-compiling linux version check)
$ vim configure
4393 #   if test "$cross_compiling" = yes; then
 4394 #       if test "${ac_cv_linux_vers+set}" = set; then
 4395 #  echo $ECHO_N "(cached) $ECHO_C" >&6
 4396 #else
 4397 #  ac_cv_linux_vers=unknown
 4398 #fi
 4399 #
 4400 #   else
 4401 #       if test "${ac_cv_linux_vers+set}" = set; then
 4402 #  echo $ECHO_N "(cached) $ECHO_C" >&6
 4403 #else
 4404 #  ac_cv_linux_vers=`uname -r 2>&1 | \
 4405 #           sed -n -e '$s/.* //' -e '$s/\..*//p'`
 4406 #fi
 4407 #
 4408 #   fi
 4409 #    { echo "$as_me:$LINENO: result: $ac_cv_linux_vers" >&5
 4410 #echo "${ECHO_T}$ac_cv_linux_vers" >&6; }
 4411 #   if test $ac_cv_linux_vers = unknown ; then
 4412 #       { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
 4413 #echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
 4414 #   { (exit 1); exit 1; }; }
 4415 #   fi

make and install
$ sudo make && sudo make install

if error has occurred like this:
./addrtoname.c: In function 'ipxsap_string':
./addrtoname.c:682: error: invalid 'asm': invalid operand for code 'w'
make: *** [addrtoname.o] Error 1

modify Makefile
$ vim Makefile
-INCLS = -I. -I./../libpcap-1.1.1  -I/usr/include -I$(srcdir)/missing
-DEFS = -DHAVE_CONFIG_H  -I./../libpcap-1.1.1  -I/usr/include -I$(srcdir)/missing  -D_U_="__attribute__((unused))"
+INCLS = -I. -I./../libpcap-1.1.1 -I$(prefix)/include -I$(srcdir)/missing
+DEFS = -DHAVE_CONFIG_H -I./../libpcap-1.1.1 -I$(prefix)/include -I$(srcdir)/missing -D_U_="__attribute__((unused))"

make and install again
$ sudo make && sudo make install

check
$ file /path/to/install/tcpdump/sbin/tcpdump
/path/to/install/tcpdump/sbin/tcpdump: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped


reference: 如何將tcpdump移植到arm嵌入式系統

[Tips] 在Ubuntu合併多個PDF

Ghostscript
$ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=firstANDsecond.pdf -dBATCH first.pdf second.pdf

pdf toolkit
$ pdftk first.pdf second.pdf output firstANDsecond.pdf

2011年3月9日 星期三

[Tips] tcpdump for wireshark

tcpdump抓到的封包轉為wireshark可以讀的格式

$ sudo tcpdump -i {interface_name} -s 0 -w {file_name}

$ tcpdump --help
Usage: tcpdump [-aAdDefIKlLnNOpqRStuUvxX] [ -B size ] [ -c count ]
  [ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]
  [ -i interface ] [ -M secret ] [ -r file ]
  [ -s snaplen ] [ -T type ] [ -w file ] [ -W filecount ]
  [ -y datalinktype ] [ -z command ] [ -Z user ]
  [ expression ]

-a   將網路位址和廣播地址轉變成名稱
-d   將匹配的封包代碼以人能理解的格式輸出
-dd  將匹配的封包代碼以c語言的格式輸出
-ddd 將匹配的封包代碼以十進位的形式輸出
-e   在輸出行列印出資料連結層的header資訊
-f   將外部的Internet位址以二進位的形式列印
-l   使標準輸出變為緩衝行形式
-n   不把網路位址轉換成名稱
-t   在輸出的每一行不列印時間戳
-v   輸出稍微詳細的資訊例如在ip封包中可以包括ttl和服務類型的資訊
-vv  輸出詳細的資訊
-c   在收到指定的封包的數目後tcpdump就會停止
-F   從指定的文件中讀取運算式,忽略其他的運算式
-i   指定監聽的網路介面
-r   從指定的檔中讀取封包(這些封包一般通過-w選項產生)
-s   擷取frame的大小,0表示無限制
-w   直接將封包寫入檔中並不分析和列印出來
-T   將監聽到的封包直接解釋為指定的類型,常見的類型有rpc和snmp