2010/03/15
My First Perl XS module
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 状态混淆
客户端在收到服务器的 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
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
给一个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
windbg -k com:pipe,port=\\.\pipe\com2,resets=0,reconnect
Windows Kernel Debug
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows XP Debug1" /fastdetect /debug /debugport=COM1 /baudrate=115200
Copyright (c) Microsoft Corporation. All rights reserved.
Opened \\.\com1
Waiting to reconnect...
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
C:\WinSymbols;d:\OtherPath\To\the\build\pdb;srv*D:\Symbols*http://msdl.microsoft.com/download/symbols
2009/11/30
如果安装 Chrome OS 的系统免费怎样?
但是如果 安装了 Chrome OS 的netbook 免费送给你那会怎样? 你会不会想要一个? 比较可能的方案是: 将Chrome OS上网本与无线运营商的宽带服务绑定, 签一个 2年的每月 $30 的合约,白送你一个 Chrome OS 上网本!WIFI 自然是由Google 自家提供! Chrome OS 功能虽然弱,比起手机啥的还是要强大很多了吧?
这可以制造一个传统PC完全不同的用户体验,完全不一样的应用环境,完全不同的商业模式。如果用户完全适应了这样的 应用环境,还有谁会去买Windows? 微软的用户优势将当然无存! 有点耸人听闻? :)
也许这就是将来的互联网, 就如同 Sun Microsystem 的口号:网络就是计算机!
2009/11/20
Google Chromium OS 那点儿事儿
Google Chromium OS 的口号就是 “浏览器就是你的操作系统”!
很明显,Chromium的目标就是上网本。NVIDIA 在这里也后很多动作,特别是她们的 Tegra SoC芯片,在这个完全以浏览器为核心的平台上,用户尽可以忘掉自己用的是 Intel, AMD, X86, AMD64, or ARM。 其实这也符合Google的利益, 很难有x86的CPU卖到 20美元以下,而最贵的ARM CPU也就是20美元。 ARM架构的上网本,无疑会极大程度的推动 上网本的价格 更平民化。 越多的人拥有 上网本,就为Google提供了更多的用户。
这里的潜台词就是:“您上internet吗? 如果上internet就用Google吧!我们是最好的!” 听到这个,微软 一定要昏倒了。不过也不必反映过度,这终究只是一个新兴的领域。谁工作做的更到位,谁就会领先。 微软要加油了!
2009/10/02
从Graphic PU走向General PU
G300 作为 nVidia 的下一代GPU,3引入很多变化: 512 CUDA Cores, L1/L2 cache, GigaThread, ECC memory controller. 看起来都更像是一个General Processing Unit.
nVidia 还是有雄心壮志的,对于nVidia而言,这是一个大胆的尝试。
2009/09/28
Google Voice and bandwidth.com
The small high-tech company always be the source of creatures! Why we don't have these in China? //sigh
2009/09/02
VIM Wiki
这个非常简单,可以直接使用内置的`:sort' 命令。当然,还可以剔除重复的 `:sort u'.
2009/08/13
What's Byte Order Mark (BOM) in Unicode
A: No, a BOM can be used as a signature no matter how the Unicode text is transformed: UTF-16, UTF-8, UTF-7, etc. The exact bytes comprising the BOM will be whatever the Unicode character FEFF is converted into by that transformation format. In that form, the BOM serves to indicate both that it is a Unicode file, and which of the formats it is in. Examples:
| Bytes | Encoding Form |
|---|---|
| 00 00 FE FF | UTF-32, big-endian |
| FF FE 00 00 | UTF-32, little-endian |
| FE FF | UTF-16, big-endian |
| FF FE | UTF-16, little-endian |
| EF BB BF | UTF-8 |
链接是 UTF系列问题的权威解答FAQ,强烈建议阅读!
VIM unicode
if has("multi_byte")
set encoding=unicode
let &termencoding = &encoding
" Set default encoding as UTF-8 with BOM
setglobal fileencoding=utf-8 bomb
" Auto detect the file encoding BOM unicode, utf-8, GBK, Big5, Latin1
set fileencodings=ucs-bom,utf-8,cp936,cp950,latin1
" Walkaround the encoding problem for fenc=utf-8 && enc=ucs-2
augroup i18n
autocmd!
autocmd BufReadPost * if &fileencoding == "utf-8" | let &encoding = &fileencoding | endif
augroup END
endif
" Enable the Chinese characters
"set guifont=Bitstream\ Vera\ Sans\ Mono:h10:cANSI,NSimSun:h11:cGB2312
set guifont=Consolas:h11:cANSI,NSimSun:h11:cGB2312
set guifontwide=NSimSun:h11:cGB2312
2009/08/12
Google Wave Sandbox
- IM?
- Word?
- Blog?
- twitter?
- SNS?
It just likes someone said, "It looks more like a Microsoft product, not Google!" I think, it still takes time to figure out "What's a Wave?"
2009/07/14
Hex string to ASCII string in Perl
You can do
$to = join(",", map { unpack('H2', $_) } chr(length($from)), split(/(?=.)/, $from));or
$to = join(",", map { unpack('H2', $_) } split(/(?=.)/, pack('W/a', $from)));How to do the reverse??? A question for you :P
2009/06/30
An English-to-Chinese Dictionary based on the evil Google Suggest Quries
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>gDictionary</ShortName>
<Description>Google English-Chinese Dictionary</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/png;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADs9Pt8xetPtu9FsfFNtu%2BTzvb2%2B%2Fne4dFJeBw0egA%2FfAJAfAA8ewBBegAAAAD%2B%2FPtft98Mp%2BwWsfAVsvE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2F%2F64g1C5VwDMYwK8Yg7y5tz8%2Fv%2FV1PYKDOcAAP0DAf4AAf0AAfYEAOwAAuAAAAD%2F%2FPvi28ymXyChTATRrIb8%2F%2F3v8fk6P8MAAdUCAvoAAP0CAP0AAfYAAO4AAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAA</Image>
<Url type="application/x-suggestions+json" method="GET" template="http://suggestqueries.google.com/complete/search?client=suggest&hjson=t&ds=d&hl=zh-CN&q={searchTerms}"></Url>
<Url type="text/html" method="GET" template="http://www.google.com/dictionary?aq=f&langpair=en|zh-CN&hl=en&q={searchTerms}"></Url>
<SearchForm>http://www.google.com/dictionary</SearchForm>
</SearchPlugin>
2009/06/29
Small Skills of Command Prompt for Windows
1, How to do a substring in the CMD.exe -- %VAR_NAME:~POS
for example
set name=fingercatecho %name:~6,3%
set /p answer=Prompt Message Hereecho %answer%
BlockChain 相关电子书
@copyright of Sam Chadwick - https://thehub.thomsonreuters.com/groups/bitcoin/blog/2017/09/10/blockchain-paper Blockchain Papers A c...
-
Today I do update the JavaScript syntax script for VIM to 0.7.2. Until now PRC 2007.01.30-21:37 my script got: Rating 332/99, Downloaded by ...
-
This is my first VIM syntax file. Personaly, I think it is better than the Javascript syntax packaged with the VIMRUNTIME packages. Origina...
-
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 t...