2013/01/26

PHP5 FastCGI init.d scriipt for Debian/Ubuntu

Recently, I am using Nginx + PHP5 FastCGI as the new web platform. I really need a init.d script for PHP5 FastCGI. It is not so difficult according to the skeleton.

First of all, make sure to install php5-cgi and spawn-fcgi.

sudo apt-get install php5-cgi spawn-fcgi
Second, create the /etc/init.d/php-fastcgi script, as below:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          php-fastcgi
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: PHP5 FastCGI mode
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

# Author: Yi Zhao

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="PHP5 FastCGI Service"
NAME=php5-cgi
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
SOCKET=/var/run/php-fastcgi.sock
PHP5=/usr/bin/php5-cgi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
CHILDREN=2
DAEMON=/usr/bin/spawn-fcgi
DAEMON_ARGS="-s $SOCKET -C $CHILDREN -P $PIDFILE -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5"

# Exit if the package is not installed
[ -x "$DAEMON" -a -x "$PHP5" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
#. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
        # Add code here, if necessary, that waits for the process to be ready
        # to handle requests from services started subsequently which depend
        # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --name $NAME
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
        #
        # If the daemon can reload its configuration without
        # restarting (for example, when it is sent a SIGHUP),
        # then implement that here.
        #
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
        return 0
}

case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  status)
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
       ;;
  #reload|force-reload)
        #
        # If do_reload() is not implemented then leave this commented out
        # and leave 'force-reload' as an alias for 'restart'.
        #
        #log_daemon_msg "Reloading $DESC" "$NAME"
        #do_reload
        #log_end_msg $?
        #;;
  restart|force-reload)
        #
        # If the "reload" option is implemented then remove the
        # 'force-reload' alias
        #
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
        exit 3
        ;;
esac

:
Add php-fastcgi into the start list

sudo update-rc.d php-fastcgi default
this will start for init level 2,3,4,5

2012/04/12

Firefox 免插件 发 新浪 weibo 大法


Firefox 具有 Smart Keywords这个功能。她让我们可以 定义一个关键字 并用这个关键字来标示一个特定的网址。 利用这个功能,我们实际上可以做很多有趣的事情,比如发Sina围脖。 具体步骤如下:

  1. 使用 Firefox
  2. 打开 baidu.com 在搜索框上点右键
  3. 点 "Add Keyword for this Search..."
  4. 这时会弹出一个对话框, 在 "Name" 项输入 "sina weibo" 其实输入什么都可以, “keyword" 可以选 wb
  5. 然后保存
  6. 用 bookmark manager 打开这个新建的 Smart Keyword, 打开 properties 属性 对话框。然后在 “Location” 里面输入 下面的代码:
javascript:(function(){f='http://v.t.sina.com.cn/share/share.php?url='+encodeURIComponent(window.location.href)+'&title=%s';a=function(){if(!window.open(f,'location=yes,links=no,scrollbars=no,toolbar=no,width=550,height=550'))location.href=f};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()

这就全部搞定了!  今后 在任何一个网页, 你只要切换到Address Bar。 可以用Ctrl+D/Ctrl+L 快速切换。 然后输入:  wb 任何你想输入的文字。 回车, 这就会打开一个新的窗口/tab 提示你 围脖的内容。Over!

2011/04/20

2011/02/28

List of freely available programming books

Meta-List

Graphics Programming

Language Agnostic:

ASP.NET MVC:

Assembly Language:

Bash

C/C++

C#

  • See .NET below

Django

Erlang

F#

Forth

Git

Grails - Getting Start with Grails

Haskell

HTML

Java

JavaScript

Linux

Lisp

Lua

Maven

Mercurial

.NET (C#)

NoSQL

Objective-C

Oracle Server

Oracle PL/SQL

Parrot / Perl 6

Perl

PHP

PowerShell

Prolog

PostgreSQL

Python

Ruby

Scala

Scheme

Smalltalk

Subversion

SQL (Implementation agnostic)

Vim

2011/01/28

Access Ubuntu GPG Keyserver behind restrict firewall

Ubuntu PPA is a very good apt source-list expansion mechanism, but it requires to install new GPG public key for the PPA repository. It isn't a big problem for user without a restrict firewall.

ubuntu keyserver is using standard GPG keyserver port keyserver.ubuntu.com:11371. It will be blocked by restrict firewall. While Ubuntu.com has enable the 80 on the keyserver, we should add some options to let gpg to use hkp:80 to access the keyserver.


For my example,
gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=http://webproxy.yourdomain.com:80 --recv 36E81C9267FD1383FCC4490983FBA1751378B444


We will be able to retrieve the GPG key through restrict firewall. :)

2010/10/18

A shell script to extract JDK/JRE .pack files using shell

#!/bin/sh

if [ ! -x $1/bin/unpack200 ];then
    echo "Usage: $0 <java_home_dir>"
    exit 1
fi

for i in `find $1 -name '*.pack'`;do
    echo $i
    $1/bin/unpack200.exe $i ${i/%.pack/.jar}
    rm -f $i
done

2010/09/06

How to Crack Excel VBA Password

Let's make it faster! I did a Perl script to handle the string replacement for you!




#!/usr/bin/perl -W

use strict;
use warnings;

use IO::File;

print "Reset .XLA Password AS: ZZZZXXXX\n";

my $fname;
while ($fname = shift) {
my $fh = new IO::File;
my $fx = new IO::File;

# backup
#qx(copy $_ $_.orig) if [ -f $_ ];

# open file
if ($fh->open("< $fname")) {
$fh->binmode();

$fx->open("> $fname.new") || die qq(unable to create $fname.new! $@\n);
$fx->binmode();

my $l;
while ($l = <$fh>) {
$l =~ s/CMG="\w+"/CMG="C2C06EAE34B234B230B630B6"/;
$l =~ s/DPB="\w+"/DPB="848628F028AF45AF4550BBB0458ED7A55404135266B71BBB11B340F5CB0445BD26CDE2C6BA5A"/;
$l =~ s/GC="\w+"/GC="4644EA326E363137313731"/;

# write into new file.
print $fx $l;
}

$fh->close();
$fx->close();

# rename
qx(ren $fname $fname.orig);
qx(ren $fname.new $fname);

# print ok
print "$fname ... done!\n";
}
}

2010/03/15

My First Perl XS module

In recent days, I created my first Perl XS module -- Perl Win32::Oleaccxs.
Win32::Oleaccxs is a module which depended on Microsoft Active Accessibility UI API to go through all the GUI widgets in Microsoft Windows system. This module is just a simple wrapper to the client APIs. By using this module, you can navigate most of the Windows GUI widgets by using Perl.

This is very early version -- v0.01, It is undocumented yet. I will finish the document and upload it to CPAN some times later. :)

TCP 状态混淆

看图说话: http://img.ly/images/152662/full

客户端在收到服务器的 SYN+ACK 响应之后,注入一个非法的RST 和另一个非法的ACK包, 服务器端会针对这个非法的ACK报文发出RST报文。 这样从中间人的角度看, 客户端和服务器都通过RST结束了TCP通讯。
太强大了~~~

2010/02/08

《后来》 北电2010年年会版

感慨中......

《后来》
后来
你还是选择了分拆拍卖,
可惜你辉煌远去,
消失在未来
后来
终于在竞争中落败
有时侯一旦倒下就不再
无线网,光网络
纷纷落入他人口袋
“爱你” 我轻声说
但无奈你欠了太多的债
百年悠久的品牌
两千亿市值
巅峰时的那个北电
让我往后的时光
每当有感叹
总想起当年的光环
那时候的光纤
为什么就能那么好卖
而又是为什么不差钱后
还有财务丑闻让人发呆
在这场金融风暴中
你是否一样
也在苦苦裁员简政
如果当时我们能不聘用MikeZ
现在也不至于破产
让我如何拯救你
你的Logo被摘去
时光倒流有没有可能让你再选择
后来,
你还是选择了分拆拍卖,
可惜你辉煌远去,
消失在未来
后来
我终于习惯了等待
有些事历练之后才明白

sub GetTreeViewItemRect of Win32::GuiTest functions

Win32::GuiTest is a powerful tool for Windows GUI testing. I love it! This is a small function which allow GuiTest to send Mouse Events to the item inside TreeCtrl.




#!/usr/bin/perl
## Initially generated by Win32-GuiTest Recorder (v1.03)

## Pragmas/Directives
use strict;
use warnings;

use 5.010;

## Imports
use Win32::GuiTest qw/:ALL/;

$Win32::GuiTest::debug = 0; # Set to "1" to enable debug output.

use constant {
    TVM_EXPAND        => 0x1100 + 2,
    TVM_GETITEMRECT   => 0x1100 + 4,
    TVM_GETNEXTITEM   => 0x1100 + 10,
    TVM_SELECTITEM    => 0x1100 + 11,
    TVM_GETITEM       => 0x1100 + 12,
    TVM_ENSUREVISIBLE => 0x1100 + 20,
    TVGN_ROOT   => 0,
    TVGN_NEXT   => 1,
    TVGN_CHILD  => 4,
    TVGN_CARET  => 9,
    TVE_EXPAND  => 2,
};

=item
    Helper function to go through Items inside TreeCtrl.
    It is as same as the internal function of Win32::GuiTest
    But it allows to use REGEX as the item name
=cut
sub xTVPathWalk
{
    my $hwnd     = shift;
    my $tvitem   = shift;
    my $text_buf = shift;
    my $hItem    = shift;
    my $max_buf  = shift;
    my $delay    = shift;
    my @parts    = @_;
    SendMessage( $hwnd, TVM_ENSUREVISIBLE(), 0, $hItem );
    while( $hItem != 0 ){
        my $str_long = pack( "L L L L L L L L L L",
            0x41, #mask (TVIF_TEXT | TVIF_CHILDREN)
            $hItem, #hItem
            0, #state
            0, #stateMask
            $text_buf->{ 'ptr' }, #pszText
            100, #cchTextMax
            0, #iImage
            0, #iSelectedImage
            0, #cChildren
            0  #lParam
        );

        WriteToVirtualBuffer( $tvitem, $str_long );
        SendMessage( $hwnd, TVM_GETITEM(), 0, $tvitem->{ 'ptr' } );
        my $text = ReadFromVirtualBuffer( $text_buf, $max_buf );
        $text =~ s/\0.+$//;
        my $struct = ReadFromVirtualBuffer( $tvitem, 40 );
        my @fields = unpack( "L10", $struct );
        my $titlere = $parts[0];
        if( $text =~ /$titlere/i ){
            SendMessage( $hwnd, TVM_EXPAND(), TVE_EXPAND(), $hItem );
            #
            # Give the node some time to expand...
            #
            select(undef, undef, undef, $delay) if $delay;
            if( @parts == 1 ){
                return $hItem;
            }
            if( $fields[ 8 ] ){
                my $hChild = SendMessage( $hwnd,
                                       TVM_GETNEXTITEM(),
                                       TVGN_CHILD(),
                                       $hItem );
                shift( @parts );
                return xTVPathWalk( $hwnd,
                                   $tvitem,
                                   $text_buf,
                                   $hChild,
                                   $max_buf,
                                   $delay,
                                   @parts );
            }
        }else{
            $hItem = SendMessage( $hwnd,
                                  TVM_GETNEXTITEM(),
                                  TVGN_NEXT(),
                                  $hItem );
        }
    }
    return 0;
}    

=item GetTreeViewItemRect
 Return the RECT of Item related to Screen.
 Parameters are as same parameters as SelTreeViewItem
=cut
sub GetTreeViewItemRect
{
    my $hwnd = shift;
    my $path = shift;
    my $max_buf = shift;
    my $delay = shift;

    if( !$max_buf ){
        $max_buf = 124;
    }
    if( !$delay ){
        $delay = 0.50;
    }
    
    my @parts = split( /\|/, $path );
 
    my $tvitem;
    eval{
        $tvitem = AllocateVirtualBuffer( $hwnd, 50 );
    };
    if( $@ ){
        die "Allocation failed with message ---> $@";
    }
    
    my $text_buf = AllocateVirtualBuffer( $hwnd, $max_buf );

    my $item_rect = AllocateVirtualBuffer( $hwnd, 16 );
 
    my $hItem = SendMessage( $hwnd, TVM_GETNEXTITEM(), TVGN_ROOT(), 0 );
    $hItem = xTVPathWalk( $hwnd,
                          $tvitem,
                          $text_buf,
                          $hItem,
                          $max_buf,
                          $delay,
                          @parts );
    SendMessage( $hwnd, TVM_SELECTITEM(), TVGN_CARET(), $hItem );

    my @rect = (0, 0, 0, 0);
    if ($hItem) {            # TVM_GETITEMRECT = 0x1104
        say "Got the item: $hItem";
        
        SendMessage( $hwnd, TVM_ENSUREVISIBLE(), 0, $hItem );

        WriteToVirtualBuffer( $item_rect, pack('L L L L', $hItem, 0, 0, 0));
        if (SendMessage ( $hwnd, TVM_GETITEMRECT(), 1, $item_rect->{ 'ptr' } ) ) {
            @rect = unpack('L4', ReadFromVirtualBuffer( $item_rect, 16 ) );
        }
    }
    FreeVirtualBuffer( $item_rect );
    FreeVirtualBuffer( $tvitem );
    FreeVirtualBuffer( $text_buf );

    @rect[0,1] = ClientToScreen( $hwnd, $rect[0], $rect[1] );
    @rect[2,3] = ClientToScreen( $hwnd, $rect[2], $rect[3] );

    return @rect;
}

=item SendMouseToTreeViewItem($hwndTreectrl, $path, $mouseevents)
    $hwndTrectrl - the HWND of TreeCtrl
    $path - full path of TreeCtrl item
    $mouseevents - mouse events, please refer to Win32::GuiTest::SendMouse
=cut
sub SendMouseToTreeViewItem {
    
    my $hwnd = shift;
    my $path = shift;

    my @rect = GetTreeViewItemRect($hwnd, $path);
    if ($rect[2] - $rect[0] != 0) {
        MouseMoveAbsPix($rect[0] + 1, $rect[1] + 1);
        SendMouse(shift);
    }
}



Here is a exameple. It will find the first `Windows Explorer' window,

my @windows = FindWindowLike(undef,undef,"ExploreWClass");
if (scalar @windows) {
SetForegroundWindow($windows[0]);
SetActiveWindow($windows[0]);
my ($treectl) = FindWindowLike($windows[0], undef, 'SysTreeView32');
if ($treectrl) {
SendMouseToTreeViewItem($treectl, 'desktop|my computer|c:|perl', '{leftclick}{leftclick}')
}
}

2010/01/22

Windows Side-by-side Assemblies

From Visual Studio 2005, WinSxS became a mandatory things for Windows application. Especially when you depends on some common DLL components, for example, Common Controls, MS VC CRT, MS GdiPlus. All this need to be specified with the MANIFEST file.
It is a little noisily to generate the MANIFEST manually. So Microsoft do this for you. Indeed, the MANIFEST file was created by `link.exe'. In the C/C++ header file, it is using #pragma instrument to specify the DLL dependency explicitly.

For example MSVCRT: it is specified by 'crtdefs.h' and 'crtassem.h'.
Inside crtdefs.h, it defines the linker comment, like below:

#ifdef _DEBUG
#pragma comment(linker,"/manifestdependency:\"type='win32' "            \
        "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".DebugCRT' "         \
        "version='" _CRT_ASSEMBLY_VERSION "' "                          \
        "processorArchitecture='x86' "                                  \
        "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' "            \
        "name='" __LIBRARIES_ASSEMBLY_NAME_PREFIX ".CRT' "              \
        "version='" _CRT_ASSEMBLY_VERSION "' "                          \
        "processorArchitecture='x86' "                                  \
        "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'\"")
#endif

and all the variants, e.g. __LIBRARIES_ASSEMBLY_NAME_PREFIX, __VCASSEMBLY_PUBLICKEYTOKEN, were defined inside `crtassem.h'.

2010/01/20

Perl regular expression tip: return all the matched things


Perl的正则表达式异常强悍,介绍一个不太引人注意但是又非常有用的功能:那就是返回所有匹配到的内容:“使用 //g 匹配”。 这时 $var =~ /regex/g 将会返回一个array,里面有所有匹配到的内容。如果在正则表达式中定义了group,就返回所有的groups;如果没有定义group,就返回所有匹配到的内容。
In list context, //g returns a list of matched groupings, or if there are no groupings, a list of matches to the whole regexp. So if we wanted just the words, we could use

        @words = ($x =~ /(\w+)/g);  # matches,
                                    # $word[0] = 'cat'
                                    # $word[1] = 'dog'
                                    # $word[2] = 'house'
需要注意,需要在一个 list context。说简单一点,就像上面的例子做就好。把匹配的结果赋值给一个array。

2009/12/21

Perl Threads

不得不说,perl 在M$ windows 下面实现的模拟fork真的是不堪一用,有很多限制,比如说: 不能fork 超过64次。也不能怪Perl,windows 对进程的处理就跟 Unix 大不相同!不过好在对于Thread的支持 Windows倒是没什么大问题。

给一个Windows下Perl多线程编程的小例子,自己留着慢慢用:) 里面用到:线程同步,变量共享。(需要Perl 5.8或者以上版本来支持 threads模块; say 这个好像是 Perl 5.10的feature, 其实就就print自动帮你加一个回车换行!)

use strict;
use warnings;

use feature qw(switch say);

use threads;
use threads::shared;
use Thread::Semaphore;

my $n = 9;

# shared variant across threads
my $arg :shared;

sub thread_proc
{
    my $sem = shift;

    for (1..$n) {
        # TODO: prepare works.
        sleep(1); # dummy 
        
        # wait until main thread wait me up!
        $sem->down;

        # TODO: Do my business~~~
        say "thread: $arg"; # dummy task
        sleep(1);   # dummy
    }

    say "thread_proc is over";
}

my $sem = new Thread::Semaphore();
my $thr = threads->create('thread_proc', $sem);
$sem->down; # Lock the semaphore

# Main thread
for(1..9)
{           
    # TODO: prepare works
    $arg = "$_ String " . ($_ * 1273);
    say "main: $arg";

    # Wait up the thread
    $sem->up;

    # TODO: Do some other works.
    sleep(3); # dummy task;
}

# wait for the thread to die
$thr->join();

print "end \n";

2009/12/14

通过虚拟机进行 Windows Kernel Debug

文介绍了硬件方式,这次来个更快的,通过虚拟机进行 Windows Kernel Debug。现在计算机硬件如此强大,我们完全可以把Target运行在一个虚拟机内,然后通过宿主机来调试。

首先,target——也就是虚拟机,也要进行同样的启动配置,让它进入debug模式。

其次,配置虚拟机程序,让它把target的COM端口 映射到一个命名管道。


以Virtual PC2007为例子,需要把Target的端口映射成一个 命名管道。其他的虚拟及程序如 VMWare 以及 VirtualBox也都有相应的设置。

然后,修改 windbg的参数,通过命名管道连接target
windbg -k com:pipe,port=\\.\pipe\com2,resets=0,reconnect
连接搞定!!!

效果和使用一个 单独的target计算机一样 :D

Windows Kernel Debug

Debug 对于程序开发来说是非常非常重要的手段。一个良好的Debug开发环境会让开发工作无往而不利。 对于 Microsoft Windows这样的庞然大物,内核开发的调试工作是非常有挑战性的。Windows 驱动程序开发,这些都需要进行内核级别的调试。当然,Microsoft的同志们,感触肯定比我们要多,因为他们每天都要在上面工作。
Microsoft实际上也已经作了大量的工作,对于Windows内核开发而言,内核的调试其实还是很简单的。

1, 硬件环境准备
进行windows内核调试,原则上需要两台计算机:一个运行测试代码叫做target;另一个运行debugger 叫做 Host。在Target与Host之间需要 通讯连接。目前比较常见的有三种: 串口,USB, 和1394。 串口是最常见的,下面就以串口为例。

Figure 1 Target and Host.
(from http://www.wd-3.com/archive/RemoteDbg.htm, Author: Jolyon Wright)
可以把 Host COM1 连接 Target COM1;也可以 Host COM2 连 Target COM1。
连接的时候不需要 一一对应。

2,Target 设置
所谓Target设置,其实就是打开Target计算机 Windows操作系统的调试选项。Windows都是内置内核调试功能的, 但是缺省关闭的。需要通过修改启动参数 (boot option) 打开。

对于Windows server 2003/XP/2000 操作系统,可以修改 Boot.ini 在启动项的后面加上
“/debug /debugport=COM2 /baudrate=115200”
看起来就象下面这样:
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows XP Debug1" /fastdetect /debug /debugport=COM1 /baudrate=115200
这里 debugport 可以用COM1/2, Baudrate也可以作相应的调整 115200是不错的选择。

对于Windows Vista/2008/7 操作系统,需要使用 bcdedit来设置。这里需要两步:
第一: 打开debug
bcdedit /debug [on | off]
第二: 设置debug参数
bcdedit /dbgsettings SERIAL DEBUGPORT:2 BAUDRATE:115200
第二步其实可以跳过,系统缺省使用串口COM1, 速率:115200。

然后重新启动Target,进入调试模式。 其实在调试模式下,如果没有连上Debugger,系统运行起来就跟普通的系统差不多,可能会慢一些。


3, Host调试软件
Host 需要安装 Debugging Tools for Windows (http://www.microsoft.com/whdc/devtools/downloads.mspx)
安装完毕后,就可以使用Windbg连接 target。建议使用 6.11或更高的版本。

运行参数:
windbg -k com:port=Com1,baud=115200

Windbg启动后应该显示:
Microsoft (R) Windows Debugger Version 6.1.0017.2
Copyright (c) Microsoft Corporation. All rights reserved.
Opened \\.\com1
Waiting to reconnect...

Target连接成功后应该显示:
Connected to Windows XP 2600 x86 compatible target, ptr64 FALSE
Kernel Debugger connection established.
Symbol search path is: \\Sysphus\softshared\symbols\KillerApp\sym;SRV*\\Sysphus\softshared\symbols\SymStore*http://msdl.microsoft.com/download/symbols
Executable search path is:
Windows XP Kernel Version 2600 MP (1 procs) Checked x86 compatible
Built by: 2600.xpsp1.020828-1920

显示的内容会随着Target运行软件的版本而有些不同。
在windbg 通过 ctrl+break键 来中断 target,进入调试交互状态,这时候Target就像死了一样,别紧张,这是因为你再通过debugger来 控制它。

4, Host 配置Symbol Path
调试中有一个很重的步骤就是 Symbol,没有Symbol 在调试中寸步难行,我们只能面对一堆二进制代码。微软提供的Symbol支持方案配置很灵活,可以有本地symbol 也可以通过Symbol server, symbol cache。 关于symbol 在 Debugging Tools for Windows的 帮助文件中 专门有一个章节介绍: Debuggers >> Symbols
比较快捷的办法:下载 Windows Symbol Files;同时配置 Microsoft的symbol server。
A, 下载相应版本的 Windows Symbol Files http://www.microsoft.com/whdc/devtools/debugging/symbolpkg.mspx
安装到 一个位置:如 C:\WinSymbols
B, 在Windbg中设置 Symbol paths: File--> Symbol File Path 快捷方式(Ctrl+S)
设置path 为:
C:\WinSymbols;d:\OtherPath\To\the\build\pdb;srv*D:\Symbols*http://msdl.microsoft.com/download/symbols
这里D:\Symbols 是用来保存从 Microsoft symbol服务器下载回来的 pdb。

剩下的工作就是学习如何使用 windbg了。 :)

Goood luck~~~

2009/11/30

如果安装 Chrome OS 的系统免费怎样?

关于Google Chrome OS的讨论已经很多了,有人说好,有人说滥。总的来说 Chrome OS 的核心问题还是PC的味道还不足!怎么都还是一个 Internet 的终端,虽然它也许能够在浏览器中执行 native code,但是再怎么搞也还不是全功能的 PC,不能与 Microsoft Windows 抗衡。

但是如果 安装了 Chrome OS 的netbook 免费送给你那会怎样? 你会不会想要一个? 比较可能的方案是: 将Chrome OS上网本与无线运营商的宽带服务绑定, 签一个 2年的每月 $30 的合约,白送你一个 Chrome OS 上网本!WIFI 自然是由Google 自家提供! Chrome OS 功能虽然弱,比起手机啥的还是要强大很多了吧?

这可以制造一个传统PC完全不同的用户体验,完全不一样的应用环境,完全不同的商业模式。如果用户完全适应了这样的 应用环境,还有谁会去买Windows? 微软的用户优势将当然无存! 有点耸人听闻? :)

也许这就是将来的互联网, 就如同 Sun Microsystem 的口号:网络就是计算机!

BlockChain 相关电子书

@copyright of Sam Chadwick   - https://thehub.thomsonreuters.com/groups/bitcoin/blog/2017/09/10/blockchain-paper Blockchain Papers A c...