25

原来在delphi ,我用的是7
new不但是过程,还是函数
本来是手误
var p:pVar;
p:=new(pvar) 和new(p)是一样的。
打开cpu窗口,产生的汇编代码是一模一样的。
帮助中说new 是一个procedure
第一句逻辑意义正确,第二句简练。

标签:,

8

如何编程实现ISAPI筛选器 (呆呆abingle.com原创文章,欢迎保留作者信息转载)

本文将详细地讲解如何制作isapi筛选器,以iis6.0为实验平台,结合实例代码,讲讲isapi(isapiFilter)筛选器制作。水平有限,有些地方谨凭主观臆测。

isapi传统意义应该是isapiExtention,是与cgi(但比cgi效率高)相并列的一组概念,与filter是两种完全不同的概念。这是微软一种不负责任的定义,Internet Server Application Programming Interface,不做深究。

isapifilter是iis的一种回调机制。

做一个dll,只要实现两个导出函数就可以被iis加载。
Function GetFilterVersion(Var Ver: THTTP_FILTER_VERSION): BOOL; Stdcall;
ver是一个纪录,传递描述和一些参数(80-ssl类型,优先级,以及需要得到的通知类型)
Function HttpFilterProc(Var pfc: THTTP_FILTER_CONTEXT;NotificationType: DWORD; pvNotification: pointer): DWORD; Stdcall;
pfc是一个当前过滤器的环境纪录,notificationtype,就是上面所说的通知类型,pvnotification一个数据指针,依据不同的通知类型而有不同的定义。

上面两个导出函数实现了就可以正常工作。
Function TerminateFilter (dwFlags : DWORD): BOOL stdcall;
这个也可以导出,用于iis释放filter时做一些清理收场工作,可有可无。

下面为代码:
Function GetFilterVersion(Var Ver: THTTP_FILTER_VERSION): BOOL; Stdcall;
Begin
Ver.lpszFilterDesc := ‘dyydyysoft For iis5-6′;
Ver.dwFilterVersion := MakeLong(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
Ver.dwFlags := SF_NOTIFY_NONSECURE_PORT //非ssl
Or SF_NOTIFY_SECURE_PORT //ssl
Or SF_NOTIFY_ORDER_DEFAULT //缺省优先级,按照msdn上说 ,default应该是中优先级,但isapi4中为low,可以手工修正。当然也无所谓,优先级只是排定几个isapifilter加载时的顺序,谁也不会往筛选器上加几个,影响iis效率的。
Or SF_NOTIFY_URL_MAP ;//拦截的通知类型,这里指定了,才会在后面的httpfilterproc回调中得到宿主iis的通知。
Result := True;
End;

delphi中怎么导出函数呢?export or exports 有什么区别? 其实我也不明白。查看帮助,其实export是16位编程用的导出函数的方法,而32位编程用exports导出。
所以function a();bool;stdcall;export;不能导出函数,只是为了向前兼容,要用exports导出。如下:
exports funca,funcb;

好了,下面是一个完整的代码,编译后只有15.5K,只是简单注册了下通知,而没有实际功能。
_____________________________________________________________________

library IISfilter;
uses ISAPI4,Windows;
Function GetFilterVersion(Var Ver: THTTP_FILTER_VERSION): BOOL; Stdcall;
Begin
Ver.lpszFilterDesc := ‘dyydyysoft For iis5-6 abingle.com’;
Ver.dwFilterVersion := MakeLong(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
Ver.dwFlags := SF_NOTIFY_NONSECURE_PORT //非ssl
Or SF_NOTIFY_SECURE_PORT //ssl
Or SF_NOTIFY_ORDER_DEFAULT //缺省优先级,按照msdn上说 ,default应该是中优先级,但isapi4中为low,可以手工修正。当然也无所谓,优先级只是排定几个isapifilter加载时的顺序,谁也不会往筛选器上加几个,影响iis效率的。
Or SF_NOTIFY_URL_MAP ;//拦截的通知类型,这里指定了,才会在后面的httpfilterproc回调中得到宿主iis的通知。
Result := True;
End;
Function HttpFilterProc(Var pfc: THTTP_FILTER_CONTEXT;NotificationType: DWORD; pvNotification: pointer): DWORD; Stdcall;
begin
Result := SF_STATUS_REQ_NEXT_NOTIFICATION;//继续处理。
end;
Exports
GetFilterVersion,
HttpFilterProc;
begin
end.
_______________________________________________________________________________________

(全文…)

标签:,

18

deflate(RFC1951):一种压缩算法,使用LZ77和哈弗曼进行编码;
zlib(RFC1950):一种格式,是对deflate进行了简单的封装,他也是一个实现库(delphi中有zlib,zlibex)
gzip(RFC1952):一种格式,也是对deflate进行的封装。

gzip = gzip头 + deflate编码的实际内容 + gzip尾
zlib = zlib头 + deflate编码的实际内容 + zlib尾

因最近在做一些关于网页解码方面的事情,压缩都是gzip,deflate.

deflate返回的就是zlib格式。浏览器可以解压,但ie系列要求必需是纯正的deflate格式,故解压时必须手动的添加一个头和尾,原来采集finance.sina.com.cn上的数据就是deflate格式,今天看了下,改用gzip压缩了。当时,只在deflate数据前加了两个字节:#$78#$9c,就可以用zlib解压了。

gzip格式和deflate相比,有了一些头信息:
GZIP文件由1到多个“块”组成,实际上通常只有1块。每个块包含头、数据和尾三部分。块的概貌如下:

+—+—+—+—+—+—+—+—+—+—+========//========+===========//==========+—+—+—+—+—+—+—+—+
|ID1|ID2| CM|FLG| MTIME |XFL| OS| 额外的头字段 | 压缩的数据 | CRC32 | ISIZE |
+—+—+—+—+—+—+—+—+—+—+========//========+===========//==========+—+—+—+—+—+—+—+—+
1. 头部分
ID1与ID2:各1字节。固定值,ID1 = 31 (0×1F),ID2 = 139(0×8B),指示GZIP格式。
CM:1字节。压缩方法。目前只有一种:CM = 8,指示DEFLATE方法。
FLG:1字节。标志。
bit 0 FTEXT – 指示文本数据
bit 1 FHCRC – 指示存在CRC16头校验字段
bit 2 FEXTRA – 指示存在可选项字段
bit 3 FNAME – 指示存在原文件名字段
bit 4 FCOMMENT – 指示存在注释字段
bit 5-7 保留

MTIME:4字节。更改时间。UINX格式。
XFL:1字节。附加的标志。当CM = 8时,XFL = 2 – 最大压缩但最慢的算法;XFL = 4 – 最快但最小压缩的算法
OS:1字节。操作系统,确切地说应该是文件系统。有下列定义:
0 – FAT文件系统 (MS-DOS, OS/2, NT/Win32)
1 – Amiga
2 – VMS/OpenVMS
3 – Unix
4 – VM/CMS
5 – Atari TOS
6 – HPFS文件系统 (OS/2, NT)
7 – Macintosh
8 – Z-System
9 – CP/M
10 – TOPS-20
11 – NTFS文件系统 (NT)
12 – QDOS
13 – Acorn RISCOS
255 – 未知

额外的头字段:
(若 FLG.FEXTRA = 1)

+—+—+—+—+===============//================+
|SI1|SI2| XLEN | 长度为XLEN字节的可选项 |
+—+—+—+—+===============//================+
(若 FLG.FNAME = 1)

+=======================//========================+
| 原文件名(以NULL结尾) |
+=======================//========================+
(若 FLG.FCOMMENT = 1)

+=======================//========================+
| 注释文字(只能使用iso-8859-1字符,以NULL结尾) |
+=======================//========================+
(若 FLG.FHCRC = 1)

+—+—+
| CRC16 |
+—+—+
存在额外的可选项时,SI1与SI2指示可选项ID,XLEN指示可选项字节数。如 SI1 = 0×41 (‘A’),SI2 = 0×70 (‘P’),表示可选项是Apollo文件格式的额外数据。

2. 数据部分
DEFLATE数据格式,包含一系列子数据块。子块概貌如下:

+……+……+……+=============//============+
|BFINAL| BTYPE | 数据 |
+……+……+……+=============//============+
BFINAL:1比特。0 – 还有后续子块;1 – 该子块是最后一块。
BTYPE:2比特。00 – 不压缩;01 – 静态Huffman编码压缩;10 – 动态Huffman编码压缩;11 – 保留。
各种情形的处理过程,请参考后面列出的RFC文档。

3. 尾部分
CRC32:4字节。原始(未压缩)数据的32位校验和。
ISIZE:4字节。原始(未压缩)数据的长度的低32位。
GZIP中字节排列顺序是LSB方式,即Little-Endian,与ZLIB中的相反。

deflate使用inflateInit(),而gzip使用inflateInit2()进行初始化,比 inflateInit()多一个参数: -MAX_WBITS,表示处理raw deflate数据。因为gzip数据中的zlib压缩数据块没有zlib header的两个字节。使用inflateInit2时要求zlib库忽略zlib header。在zlib手册中要求windowBits为8..15,但是实际上其它范围的数据有特殊作用,见zlib.h中的注释,如负数表示raw deflate。
Apache的deflate变种可能也没有zlib header,需要添加假头后处理。即MS的错误deflate (raw deflate).zlib头第1字节一般是0×78, 第2字节与第一字节合起来的双字节应能被31整除,详见rfc1950。例如Firefox的zlib假头为0×7801,python zlib.compress()结果头部为0×789c。

注:以上文字属于多段摘抄,非原创。收录于此,感谢原作者们。

标签:, ,

27

某人,手工刷分,很辛苦。

做个程序模拟下,方便些。

必要条件:大厅双开,上网找找有。要么用沙盘运行吧,没测试,应该可以。

刷分流程:垃圾号一个,中分号一个(50-60分),高分号一个,为的就是给这个号刷分。

让垃圾号输分给中分号,中分号输给高分号,注意,不能让中分号的分值始终在50-60分之间,这样,他既可以在低分号上桌,也可以在高分号立脚。分就源源不断从垃圾号经跳板中分号输送到高分号。

刷分器是个模拟程序,即模拟下棋。

界面巨丑,如图qq游戏|四国军棋|刷分器

框中是坐标数据。我的屏幕是1440X900。自己可以录制。

使用方法,开四个军棋窗口。高分一个,中分(跳板号)两个,低分号一个。

高分<-中分;中分<-低分

高分按F1定位窗口,中分失分按F2定位窗口,中分得分按F3定位,低分按F4定位。这一步必须要做。

好了按F6开始吧,中间可以按F9停止。F7,F8 用于录制坐标。

源代码全部奉上,如下,have fun

unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, HotKeyManager, StdCtrls;

type
  TForm1 = class(TForm)
    hkMgr: THotKeyManager;
    mmo1: TMemo;
    procedure hkMgrHotKeyPressed(HotKey: Cardinal; Index: Word);
    procedure FormCreate(Sender: TObject);
  private
    w1, w2, w3, w4: HWND;
    running:integer;
    procedure locWind(hk: Cardinal);
    procedure startIt;
  public
    { Public declarations }
  end;

var
  Form1             : TForm1;
  acmd              : string;
implementation

uses
  RegExpr;

{$R *.dfm}

procedure TForm1.hkMgrHotKeyPressed(HotKey: Cardinal; Index: Word);
var
  p                 : TPoint;
  r                 : TRect;
  theH              : HWND;
begin
  case HotKey of
    112, 113, 114, 115: locWind(HotKey);
    117: startIt;
    118:
      begin
        GetCursorPos(p);
        theH := WindowFromPoint(p);
        if theH = w1 then
          acmd := ‘1′
        else
          if theH = w2 then
            acmd := ‘2′
          else
            if theH = w3 then
              acmd := ‘3′
            else
              acmd := ‘4′;
        GetWindowRect(theH, r);
        acmd := acmd + ‘-’ + Format(‘%d-%d’, [p.X - r.Left, p.Y - r.Top]);
      end;
    119:
      begin
        GetCursorPos(p);
        theH := WindowFromPoint(p);
        GetWindowRect(theH, r);
        acmd := acmd + ‘-’ + Format(‘%d-%d’, [p.X - r.Left, p.Y - r.Top]);
        mmo1.Lines.Add(acmd);
        acmd := ”;
      end;
    120: running := 1;
  else
  end;
end;

function ForceForegroundWindow(hwnd: THandle): Boolean;
const
  SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
  SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
  ForegroundThreadID: DWORD;
  ThisThreadID      : DWORD;
  timeout           : DWORD;
begin
  if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE);
  if GetForegroundWindow = hwnd then
    Result := True
  else
  begin
        // Windows 98/2000 doesn’t want to foreground a window when some other
        // window has keyboard dyydyysoft focus
    if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
      ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
      ((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
      (Win32MinorVersion > 0)))) then
    begin
      Result := False;
      ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil);
      ThisThreadID := GetWindowThreadProcessID(hwnd, nil);
      if AttachThreadInput(ThisThreadID, ForegroundThreadID, True) then
      begin
        BringWindowToTop(hwnd);         // IE 5.5 related hack
        SetForegroundWindow(hwnd);
        AttachThreadInput(ThisThreadID, ForegroundThreadID, False);
        Result := (GetForegroundWindow = hwnd);
      end;
      if not Result then
      begin
              // Code by Daniel P. Stasinski
        SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE);
        BringWindowToTop(hwnd);         // IE 5.5 related hack
        SetForegroundWindow(hwnd);
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);
      end;
      ShowWindow(hwnd, SW_SHOWNORMAL);
    end
    else
    begin
      BringWindowToTop(hwnd);           // IE 5.5 related hack
      SetForegroundWindow(hwnd);
      ShowWindow(hwnd, SW_SHOWNORMAL);
    end;
    Result := (GetForegroundWindow = hwnd);
  end;
end;

procedure TForm1.startIt;
var
  i                 : Integer;
  th                : HWND;
  r                 : TRect;
begin
  running := 0;
  while running = 0 do
  begin
    Sleep(1000);
    for i := 0 to mmo1.lines.count – 1 do
    begin
      Application.ProcessMessages ;
      if running = 1 then Break;
      with TRegExpr.Create do
      try
        Expression := ‘([1-4])\-(\d*)\-(\d*)-(\d*)-(\d*)’;
        if Exec(mmo1.Lines[i]) then
        begin
          case StrToIntdef(match[1], 0) of
            1: th := w1;
            2: th := w2;
            3: th := w3;
            4: th := w4;
          else
            Continue;
          end;
          Sleep(600);
          if th <> 0 then ForceForegroundWindow(th);
          GetWindowRect(th, r);
          SetCursorPos(r.Left + StrToInt(Match[2]), r.Top + StrToInt(Match[3]));
          mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
          Sleep(10);
          mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
          Sleep(10);
          mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
          Sleep(10);
          mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
          Sleep(600);
          SetCursorPos(r.Left + StrToInt(Match[4]), r.Top + StrToInt(Match[5]));
          mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
          Sleep(10);
          mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
          Sleep(10);
          mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
          Sleep(10);
          mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
        end;
      finally
        Free;
      end;
    end;
    Application.ProcessMessages;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  hkMgr.AddHotKey(112);
  hkMgr.AddHotKey(113);
  hkMgr.AddHotKey(114);
  hkMgr.AddHotKey(115);
  hkMgr.AddHotKey(117);
  hkMgr.AddHotKey(118);
  hkMgr.AddHotKey(119);
  hkMgr.AddHotKey(120);
end;

procedure TForm1.locWind(hk: Cardinal);
var
  p                 : TPoint;
  r                 : TRect;
var
  Buf               : array[0..255] of Char;
  tH                : HWND;
  FLASHWINFO        : TFLASHWINFO;
  i                 : integer;
begin
  GetCursorPos(p);
  th := WindowFromPoint(p);
  FillChar(Buf, 256, #0);
//  tH := GetTopWindow(GetDesktopWindow);
//  th:=GetParent(th);
  SendMessage(tH, WM_GETTEXT, 256, Integer(@Buf)); // 得到标题
  //if IsWindowUnicode(th) then StrCopy(@Buf, PAnsiChar(@Buf));
  //for i := 0 to 10 do     FlashWindow(th, True);welcome2abingle.com
  if Pos(‘四国军棋’, StrPas(@Buf)) > 0 then
  begin
    FLASHWINFO.cbSize := sizeof(FLASHWINFO);
    FLASHWINFO.hwnd := th;
    FLASHWINFO.dwFlags := FLASHW_ALL or FLASHW_STOP; //同时闪烁标题栏和托盆窗口
    FLASHWINFO.uCount := 5;
    FLASHWINFO.dwTimeout := 10;         //闪烁时间间隔为10毫秒
    FlashWindowEx(FLASHWINFO);          //开始闪烁,将填充的FLASHWINFO结构作为参数
    GetWindowRect(tH, r);

    for i := 0 to 4 do                  //抖动窗口
    begin
      MoveWindow(th, r.Left + 2, r.Top, r.Right – r.Left, r.Bottom – r.Top, True);
      MoveWindow(th, r.Left + 2, r.Top + 2, r.Right – r.Left, r.Bottom – r.Top, True);
      MoveWindow(th, r.Left – 2, r.Top + 2, r.Right – r.Left, r.Bottom – r.Top, True);
      MoveWindow(th, r.Left – 2, r.Top – 2, r.Right – r.Left, r.Bottom – r.Top, True);
    end;

    case hk of
      112:
        begin
          w1 := tH;
          Buf := ‘高分得分四国军棋’;
          SendMessage(th, WM_SETTEXT, 0, Integer(@Buf));
        end;
      113:
        begin
          w2 := tH;
          Buf := ‘中分失分四国军棋’;
          SendMessage(th, WM_SETTEXT, 0, Integer(@Buf));
        end;
      114:
        begin
          w3 := tH;
          Buf := ‘中分得分四国军棋’;
          SendMessage(th, WM_SETTEXT, 0, Integer(@Buf));
        end;
      115:
        begin
          w4 := tH;
          Buf := ‘垃圾号四国军棋’;
          SendMessage(th, WM_SETTEXT, 0, Integer(@Buf));
        end;
    end;

  end;
end;

end. 

标签:, ,

22

原文地址:http://hi.baidu.com/rarnu/blog/item/4ec80608022766d663d986ea.html

在JS中,有一个比较特殊的对象,即window.external,用它可以调用浏览器提供的外部方法
一个很简单的例子就是将当前页添加到收藏夹

(全文…)

标签:

22

author:BaraoZemo
Since TWebBrowser is just an IE wrapper the only way to view a page via a proxy is to change the "Internet Options" proxy settings.
And you can set it using windows registry…
You can simply do this with registry keys. Internet Explorer adds and removes registry keys to get it worked. Don’t forget the proxy will be applied on browsers and internet activities.
Here it is:
This uses registry and wininet.
Procedure SetProxy(cost Server: String);
var
Reg : TRegistry;
begin
Reg := TRegistry.Create;
Reg.OpenKey(‘Software\Microsoft\Windows\CurrentVer sion\Internet Settings’,False);
Reg.WriteString(‘ProxyServer’,Server);
Reg.WriteBool(‘ProxyEnable,True);
Reg.CloseKey;
Reg.Free;
InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0);
end;
This is how to use:
SetProxy(‘Proxy:Port’);
Procedure 2 to disable:
Procedure DisableProxy;
var
Reg : TRegistry;
begin
Reg := TRegistry.Create;
Reg.OpenKey(‘Software\Microsoft\Windows\CurrentVer sion\Internet Settings’,False);
Reg.WriteBool(‘ProxyEnable,False);
Reg.CloseKey;
Reg.Free;
InternetSetOption(0, INTERNET_OPTION_SETTINGS_CHANGED, 0, 0);
end;
This is how to use:
DisableProxy;
If IE is running and those new proxy settings are applied, IE will not read the new settings.
To get the new settings it’ll need to not have Internet explorer open.
So if the user has InternetExplorer Running you can use read_internet procedure:
procedure IE_Read;
var
HInet: HINTERNET;
begin
hInet := InternetOpen(PChar(‘myappname’), INTERNET_OPEN_TYPE_DIRECT,
nil, nil, INTERNET_FLAG_OFFLINE);
try
if hInet <> nil then
InternetSetOption(hInet, INTERNET_OPTION_SETTINGS_CHANGED, nil, 0);
finally
InternetCloseHandle(hInet);
end;
end;
This is how to use it:
IE_Read;
[DELPHI]
Regards
BaraoZemo

标签:

22

twebbrowser在使用中会产生内存泄漏,而实际上是olectrls.pas中产生的。

修改并重编译这个单元。

function TOleControl.GetIDispatchProp(Index: Integer): IDispatch;
var
  Temp: TVarData;
begin
  GetProperty(Index, Temp);
  //Result := IDispatch(Temp.VDispatch);
  Pointer(Result) := Temp.VDispatch;
end;

function TOleControl.GetIUnknownProp(Index: Integer): IUnknown;
var
  Temp: TVarData;
begin
  GetProperty(Index, Temp);
  //Result := IUnknown(Temp.VUnknown);//原来的会无端增加一个引用计数。
  Pointer(Result) := Temp.VUnknown;
end;

这个解决方案是zhongs提供的,注。

标签:,

23

作者:呆呆(abingle.com)

我只会用delphi,也深感于delphi的灵气。

1.调试delphi 写的服务程序,有这么一个办法。原来每次都是用attach to process方法,很麻烦。并且按照服务线程的执行线路,可能会停不到想要的断点。笨办法是,在procedure TsvcFrm.ServiceExecute(Sender: TService);中想要下断的语句前加个人定胜天的sleep(20000),但实际上这种办法是主观臆测的。可行,没问题。记得大学时,俺一同学,也会修电视,他的办法是弄个小锤子,四处敲击,没两下就好了,和我用万用表的方法不一样,万用表他根本不会用。而且产生的效益比我的要乐观。毕业了,他回家开个网吧,也算是做IT,而我成了一位对编程颇有研究的IT业余人士,结果他收入还是比我高。日,下辈子,老子扛大炮去修劳力士去。回忆回忆过去,展望展望未来,无限感慨。上面的方法是可以的,如同锤子,仔细了解下服务程序的执行过程,你会发现,用下面的方法,就可以把服务程序当普通程序调试了。

(全文…)

标签:, ,

 
© 呆呆的博客