//--------------------------------------------------------------------------- #include #pragma hdrstop #include "LoginUnit.h" #include "UtilityUnit.h" #include "GlobalUnit.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" bool g_bAutoLogin = true; String GetValueByKey(String key, String str) { String ret; int klen = key.Length(), slen = str.Length(); int p0 = 1; //外部搜索key的游标 while((p0 = Pos(key, str, p0))!=0){ p0 += klen; int p1 = p0; //p1为内部搜索游标 bool bOk = false; while(p10 && len>0){ ret = str.SubString(p2, len); break; } } return ret; } //--------------------------------------------------------------------------- __fastcall TLoginForm::TLoginForm(TComponent* Owner, int iPF) : TForm(Owner) { m_iPlatform = iPF; } //--------------------------------------------------------------------------- void __fastcall TLoginForm::OnLoginClick(TObject *Sender) { if(!m_memTxt->Lines->Count){ if(m_iPlatform==PF_PA) ShowMessage("请按提示复制网页内容到编辑框"); else if(m_iPlatform==PF_AB) ShowMessage("请按提示复制网页完整地址到编辑框"); else if(m_iPlatform==PF_DB) ShowMessage("请按操作说明复制网页地址到编辑框"); } else if(m_iPlatform==PF_PA && GetLoginValues(m_memTxt->Text) || m_iPlatform!=PF_PA && GetUrl(m_memTxt->Text)){ ModalResult = mrOk; } else ShowMessage("复制的内容无效,请重新复制"); } //--------------------------------------------------------------------------- void __fastcall TLoginForm::FormCreate(TObject *Sender) { if(m_iPlatform==PF_PA) Caption = Caption + " - PA视讯(AG)"; else if(m_iPlatform==PF_AB) Caption = Caption + " - 欧博(ABG)"; else if(m_iPlatform==PF_DB) Caption = Caption + " - 多宝(DB)"; m_cbAuto->Checked = g_bAutoLogin; m_imgSpec = new TPngImage(); TResourceStream * pResStream = new TResourceStream(int(HInstance), m_iPlatform==PF_DB ? L"PNG_DBSPEC" : m_iPlatform==PF_AB ? L"PNG_ABSPEC" : L"PNG_PASPEC", RT_RCDATA); m_imgSpec->LoadFromStream(pResStream); delete pResStream; m_imgBack->Picture->Bitmap->Assign(m_imgSpec); m_memTxt->Lines->Add(m_iPlatform==PF_PA ? "请将网页内容复制到这里" : m_iPlatform==PF_DB ? "按操作说明打开调试控制台,复制粘贴以下代码并回车" : "请将网页完整地址复制到这里" ); if(m_iPlatform==PF_DB){ m_memTxt->Lines->Add(" history.replaceState(0,'',location.href+'&deviceId='+localStorage.getItem('fixedDeviceId'))"); m_memTxt->Lines->Add("然后复制网页完整地址到这里"); } AddClipboardFormatListener(Handle); } //--------------------------------------------------------------------------- void __fastcall TLoginForm::FormClose(TObject *Sender, TCloseAction &Action) { RemoveClipboardFormatListener(Handle); delete m_imgSpec; } //--------------------------------------------------------------------------- void __fastcall TLoginForm::WMClipboardUpdate(TMessage &msg) { Sleep(100); //处理剪贴板延迟呈现 if(ModalResult!=mrNone) return; if( !OpenClipboard( Handle ) ){ OutputDebugString(L"OpenClipboard faild!"); return; } String txt; if( IsClipboardFormatAvailable(CF_UNICODETEXT) ){ HANDLE h = GetClipboardData(CF_UNICODETEXT);//获取剪切板数据 if(h){ txt = static_cast(GlobalLock(h)); GlobalUnlock(h); } } else if( IsClipboardFormatAvailable(CF_TEXT) ){ HANDLE h = GetClipboardData(CF_TEXT);//获取剪切板数据 if(h){ txt = static_cast(GlobalLock(h)); GlobalUnlock(h); } } if(txt.Length()>0 && ( m_iPlatform==PF_PA && GetLoginValues(txt) || m_iPlatform!=PF_PA && GetUrl(txt))){ SetWindowPos(Application->Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE); SetWindowPos(Application->Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE); ModalResult = mrOk; // mrCancel;// } CloseClipboard();//关闭剪贴板 } //--------------------------------------------------------------------------- void __fastcall TLoginForm::AutoClick(TObject *Sender) { g_bAutoLogin = m_cbAuto->Checked; } //--------------------------------------------------------------------------- bool __fastcall TLoginForm::GetLoginValues(String in) { static String keys[] = {"pid", "tempLangInt", "myGametype", "username", "myDm", "myDofoward"}; for(int i=0; i<6; i++){ m_values[i] = GetValueByKey(keys[i], in); if(m_values[i].Length()==0) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TLoginForm::GetUrl(String in) { int p0 = in.Pos("https://"); if(!p0) return false; if(m_iPlatform==PF_AB){ int p1 = Pos("\/?", in, p0+8); if(!p1) return false; m_url = in.SubString(p0, p1+2 - p0); if(!(p0 = Pos("sessionId=", in, p1+2)) && !(p0 = Pos("sessionid=", in, p1+2))) return false; if(!(p1 = Pos("&", in, p0+10)) && !(p1 = Pos("#", in, p0+10))) p1 = in.Length()+1; if(p1-p0 < 50) return false; m_url += in.SubString(p0, p1-p0); return true; } else if(m_iPlatform==PF_DB){ int p1 = Pos("egret\/", in, p0+8); if(!p1) return false; m_url = in.SubString(p0, p1+6 - p0) + "multi"; //"hall"; // if(!(p0 = Pos("?params=", in, p1+6))) return false; if(!(p1 = Pos("&signature=", in, p0+20)) || !(p1 = Pos("&ttl=", in, p0+20))) return false; int p2 = Pos("&deviceId=", in, p1+16); if(!p2) return false; if(!(p1 = Pos("&", in, p2+10))) p1 = in.Length()+1; m_values[0] = in.SubString(p2+10, p1 - p2 - 10); if(p2-p0 < 1700) return false; m_url += in.SubString(p0, p2-p0); return true; } return false; } //--------------------------------------------------------------------------- void __fastcall TLoginForm::OnSpecClick(TObject *Sender) { PostMessage(Application->MainFormHandle, UM_OPENMAUAL, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TLoginForm::SpecMouseEnter(TObject *Sender) { m_lblSpec->Font->Color = clHighlight; } //--------------------------------------------------------------------------- void __fastcall TLoginForm::SpecMouseLeave(TObject *Sender) { m_lblSpec->Font->Color = clBlue; } //---------------------------------------------------------------------------