Celerbrate my StackOverflow.com account get over 500 reputations

费尽九牛二虎之力 终于让我在StackOverflow的账号reputation 过了500!!!

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

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. :)

A shell script to extract JDK/JRE .pack files under MSYS

#!/bin/sh

if [ ! -x $1/bin/unpack200.exe ];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

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";
}
}

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年年会版

感慨中......

《后来》
后来
你还是选择了分拆拍卖,
可惜你辉煌远去,
消失在未来
后来
终于在竞争中落败
有时侯一旦倒下就不再
无线网,光网络
纷纷落入他人口袋
“爱你” 我轻声说
但无奈你欠了太多的债
百年悠久的品牌
两千亿市值
巅峰时的那个北电
让我往后的时光
每当有感叹
总想起当年的光环
那时候的光纤
为什么就能那么好卖
而又是为什么不差钱后
还有财务丑闻让人发呆
在这场金融风暴中
你是否一样
也在苦苦裁员简政
如果当时我们能不聘用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}')
}
}

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'.