function CodingApply: integer; //申请打码显示资源,如果申请成功,返回显示的标号,否则返回-1
function CodingRelease(CodeIdx: Integer): string; //释放显示资源,返回的是打码的信息
function CodingWait(CodeIdx: Integer): Boolean; //将状态更改为等待
function CodingOK(CodeIdx: Integer): Boolean; //将状态更改为处理完毕
function CodingStatus(CodeIdx: Integer): integer; //获取当前状态
具体的线程池设置代码,对于申请打码区资源,及其释放打码区资源,都写得有具体的方案
代码
function CodingApply: integer;
var
i: integer;
begin
CodingCs.Enter;
Result:= -1;
try
for i := 1 to 9 do begin
if Codings[i].Status=0 then begin
Result:= i;
Codings[i].Status:= 1;
Break;
end;
end;
finally
CodingCs.Leave;
Sleep(0);
end;
end;
function CodingRelease(CodeIdx: Integer): string;
begin
if (CodeIdx<0) or (CodeIdx>9) then Exit;
CodingCs.Enter;
try
try
Result:= TEdit(MainForm.FindComponent('Input'+ IntToStr(CodeIdx))).Text;
except
Result:= '';
end;
Codings[CodeIdx].Status:= 0;
finally
CodingCs.Leave;
Sleep(0);
end;
end;
function CodingWait(CodeIdx: Integer): Boolean;
begin
if (CodeIdx<0) or (CodeIdx>9) then Exit;
Result:= True;
CodingCs.Enter;
try
try
Codings[CodeIdx].Status:= 2;
except
Result:= False;
end;
finally
CodingCs.Leave;
Sleep(0);
end;
end;
function CodingOK(CodeIdx: Integer): Boolean;
begin
if (CodeIdx<0) or (CodeIdx>9) then Exit;
Result:= True;
CodingCs.Enter;
try
try
Codings[CodeIdx].Status:= 3;
except
Result:= False;
end;
finally
CodingCs.Leave;
Sleep(0);
end;
end;
function CodingStatus(CodeIdx: Integer): integer;
begin
if (CodeIdx<0) or (CodeIdx>9) then Exit;
CodingCs.Enter;
try
Result:= Codings[CodeIdx].Status;
finally
CodingCs.Leave;
Sleep(0);
end;
end;
constructor TRegData.Create(const AId: string);
begin
FId:= AId;
end;
function TRegData.Duplicate(DataObj: TPNTaskObject;
const Processing: Boolean): Boolean;
begin
Result := (not Processing) and
(FId = TRegData(DataObj).FId);
end;
function TRegData.Info: string;
begin
Result:= 'FId='+ FId+ ';';
end;
procedure TRegThread.ShowImg1;
begin
try
TImage(MainForm.FindComponent('Img'+ IntToStr(MyCodeIdx))).Picture.Assign(bmp);
TEdit(MainForm.FindComponent('Input'+ IntToStr(MyCodeIdx))).Text:= '';
except
end;
CodingWait(MyCodeIdx);
end;
procedure TRegThread.ShowImg;
begin
Synchronize(ShowImg1);
end;
destructor TRegThread.Destroy;
begin
try
if bmp<>nil then bmp.Free;
except
end;
inherited Destroy;
end;
function HexToInt(const S: String): DWORD;
asm
PUSH EBX
PUSH ESI
MOV ESI, EAX //字符串地址
MOV EDX, [EAX-4] //读取字符串长度
XOR EAX, EAX //初始化返回值
XOR ECX, ECX //临时变量
TEST ESI, ESI //判断是否为空指针
JZ @@2
TEST EDX, EDX //判断字符串是否为空
JLE @@2
MOV BL, $20
@@0:
MOV CL, [ESI]
INC ESI
OR CL, BL //如果有字母则被转换为小写字母
SUB CL, '0'
JB @@2 // < '0' 的字符
CMP CL, $09
JBE @@1 // '0'..'9' 的字符
SUB CL, 'a'-'0'-10
CMP CL, $0A
JB @@2 // < 'a' 的字符
CMP CL, $0F
JA @@2 // > 'f' 的字符
@@1: // '0'..'9', 'A'..'F', 'a'..'f'
SHL EAX, 4
OR EAX, ECX
DEC EDX
JNZ @@0
JMP @@3
@@2:
XOR EAX, EAX // 非法16进制字符串
@@3:
POP ESI
POP EBX
RET
end;
procedure TMainForm.DownProcessRequest(Sender: TPNThreadPool;
aDataObj: TPNTaskObject; aThread: TPNPoolThread);
var
Http: TPNHttp;
i,j,LBase,IdxA,IdxB: integer;
RndStr,FormParams,StrResult,StrQQ,StrCookie,StrIP: string;
SListA,SListB: TStringList;
Reg: TPerlRegEx;
ParamArray: array[0..14] of string;
begin
// FPNWriteLnText('日志.txt',TRegData(aDataObj).FId+'开始注册',False);
Http:= TPNHttp.Create(nil,True,True);
Randomize;
StrIP:= '1.193.86.'+ IntToStr(Random(255)+ 1);
// StrIP:= IntToStr(Random(255)+ 1)+'.'+ IntToStr(Random(255)+ 1)+'.'+ IntToStr(Random(255)+ 1)+'.'+ IntToStr(Random(255)+ 1);
Http.Request.CustomHeaders.Add('X-Forwarded-For:'+ StrIP);
try
try
Http.HttpGet('http://reg.qq.com/');
// FPNWriteLnText(TRegData(aDataObj).FId+'HEADER信息.txt','首页:'+ Http.HttpHeader,False);
TRegThread(aThread).MyCodeIdx:= CodingApply;
///等待获取打码资源
while TRegThread(aThread).MyCodeIdx=-1 do begin
sleep(500);
TRegThread(aThread).MyCodeIdx:= CodingApply;
end;
try
TRegThread(aThread).Bmp:= Http.HttpBmp('http://captcha.qq.com/getimage?aid=1007901&0.9408595752591837');
// FPNWriteLnText(TRegData(aDataObj).FId+'HEADER信息.txt','验证码:'+ Http.HttpHeader,False);
TRegThread(aThread).ShowImg;
finally
if TRegThread(aThread).Bmp<>nil then
TRegThread(aThread).Bmp.Free;
end;
while CodingStatus(TRegThread(aThread).MyCodeIdx)=2 do begin
Sleep(200);
end;
RndStr:= CodingRelease(TRegThread(aThread).MyCodeIdx);
// FPNWriteLnText('日志.txt',TRegData(aDataObj).FId+':RndStr='+ RndStr,False);
FormParams:= Http.HttpGet('http://reg.qq.com/cgi-bin/checkconn?seed0.8865932116432269');
// FPNWriteLnText(TRegData(aDataObj).FId+'HEADER信息.txt','CheckConn:'+ Http.HttpHeader,False);
// FPNWriteLnText(TRegData(aDataObj).FId+'数据日志.txt','返回的参数集:'+ FormParams,False);
// FormParams:= Copy(FormParams,33,402);
StrCookie:= Http.CookieMgr.CookieCollection.Cookie['PCCOOKIE','qq.com'].Value;
// FPNWriteLnText(TRegData(aDataObj).FId+'数据日志.txt','PCCOOKIE值为:'+ StrCookie,False);
StrCookie:= copy(StrCookie,length(StrCookie)-1,2);
// FPNWriteLnText(TRegData(aDataObj).FId+'数据日志.txt','LBASE值为:'+ StrCookie,False);
LBase:= HexToInt(StrCookie);
ParamArray[0]:= 'QQ';
ParamArray[1]:= 'EMAIL';
ParamArray[2]:= 'zeze';
ParamArray[3]:= '0';
ParamArray[4]:= '1985';
ParamArray[5]:= '1';
ParamArray[6]:= '2';
ParamArray[7]:= '1';
ParamArray[8]:= '2';
ParamArray[9]:= 'abc111111';
ParamArray[10]:= 'abc111111';
ParamArray[11]:= '1';
ParamArray[12]:= '11';
ParamArray[13]:= '1';
ParamArray[14]:= RndStr;
try
SListA:= FPNSplit(Copy(FormParams,33,402),',');
SListB:= FPNSplit(Copy(FormParams,447,64),',');
// FPNWriteLnText(TRegData(aDataObj).FId+'数据日志.txt',Copy(FormParams,447,64),False);
FormParams:= '';
for i := 0 to 12 do begin
IdxA:= StrToInt(SListB[i]) xor LBase;
IdxB:= 12-i;
IdxA:= IdxA xor 6818;
IdxA:= IdxA xor 8315;
IdxA:= IdxA xor 5123;
IdxA:= IdxA xor 2252;
for j := 0 to 5 do
IdxA:= IdxA xor 0;
IdxA:= IdxA mod 15;
// FPNWriteLnText(TRegData(aDataObj).FId+'数据日志.txt','IdxA:'+ IntToStr(IdxA),False);
procedure TMainForm.btn1Click(Sender: TObject);
var
i: integer;
begin
for i := 1 to StrToInt(RegNum.Text) do begin
RegId:= RegId+ 1;
PoolReg.AddRequest(TRegData.Create(IntToStr(RegId)));
end;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
PoolReg.Free;
CodingCs.Free;
end;
procedure TMainForm.Input1KeyPress(Sender: TObject; var Key: Char);
var
CodeIdx: integer;
ObjName: string;
begin
if Key= Char(13) then begin
ObjName:= (Sender as TRzEdit).Name;
CodeIdx:= StrToInt(Copy(ObjName,6,1));
CodingOK(CodeIdx);
if CodeIdx=9 then
CodeIdx:= 1
else
CodeIdx:= CodeIdx+ 1;
TRzEdit(FindComponent('Input'+ IntToStr(CodeIdx))).SetFocus;
end;
end;
本文只是对QQ注册页面进行一些分析,供大家参考,其实大家在做WEB设计的时候,如何防止批量注册这块,也可以参考下QQ,比较变态一些,但是感觉腾讯做的还不完善。