2007-07-31

分析Delphi编译的程序真郁闷

分析Delphi编译的程序真的很郁闷~~

特别是字符串部分……
Pascal字符串结构是:[字串长]字串字符部分....


Delphi程序的 函数/过程 传值方式大多是以寄存器为主。
其中也有特殊的,比如_LStrCatN:

procedure _LStrCatN (var dest:AnsiString; argCnt: Integer; ...) // AnsiString 的连接

EAX :目标字符串
EDX :源字符串的个数 +2
[ESP+4*i] :第 i 个源字符串的指针

这里的入口参数比较特别

之上有:
push xxx
push xxx
...(EDX个push不一定要在一起)
如:
_LStrCatN (str, 3, LStrFromString(b), LStrFromString(a), IntToStr(n))
这样的就有可能是:
lea    edx, [ebp+tmp1]
mov    eax, [ebp+n]
call   IntToStr
push   [ebp+tmp1]    ; <<== 01
lea    eax, [ebp+tmp2]
mov    edx, ds:off_a
call   LStrFromString
push   [ebp+tmp2]    ; <<== 02
lea    eax, [ebp+tmp3]
lea    edx, [ebp+b]
call   LStrFromString
push   [ebp+tmp3]    ; <<== 03
lea    edx, [ebp+str]
mov    edx, 3
call   LStrCatN

; 这些push分散到了 01,02,03 所指处(一开始我还以为前两个push是LStrFromString的- -)


返回值也不一定在 EAX 中——尽管大多数是在EAX中没错,不过也有放[ESP+4]的。

//EOF Read More...

2007-07-07

Linux下实现getch()

Linux下的int getchar(void)在默认情况下需要Enter后才能继续。那么可否像DOS下那样即时返回的呢?
回答是肯定的:

  1. 使用curses库的getch()。
  2. read /dev/input/event0 (kernel >= 2.6)
  3. 将stdin改成unbuffered:
    #include <stdio.h>
    #include <unistd.h>
    #include <termios.h>
    int getch (void)
    {
        int    c = 0;
        struct termios    tm_old, tm;
        int    ret = 0;

        ret = tcgetattr (STDIN_FILENO, &tm_old);
        assert (ret==0);
        memcpy (&tm, &tm_old, sizeof(tm));
        tm.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
        tcsetattr (STDIN_FILENO, TCSANOW, &tm);
        c = fgetc(stdin);//getchar();
        ret = tcsetattr (STDIN_FILENO, TCSANOW, &tm_old);
        assert (ret==0);

        return c;
    }


//EOF Read More...

2007-07-04

《侠胆雄狮》


最近在看《Dark Angel》,第二季中Joshua("the first one")的出场立刻让我联想到了上世纪90年代中央电视台正大剧场播过的《侠胆雄狮》(Beauty and the Beast)。
很经典的一部电视剧,当时我还很小,很多记忆都模糊了,但是看这部剧的感受还深深的印在我的心头。不过正大剧场好像只引进了第一季呢,没结局。

http://tv.mofile.com/r4s2qzp3/

//EOF Read More...

amulecmd

~/.aMule/amule.conf

AcceptExternalConnections=1
ECPassword=<md5 string> # get this string with this:
$ echo "your passwd" | md5sum | cut -d ' ' -f 1

then:
$ amuled &

you can using amulecmd do a simply control.
$ amulecmd -P "your passwd" [-c "control cmd"]

//EOF Read More...