设为首页 | 收藏本站 | 每日归档
当前位置:ucbug游戏网 > 新闻中心 > 游戏开发 >
征途外挂的vc部分源码(2)
作者:网络来源:本站整理发布时间:2009-06-25 05:41

    CButton  * cBt = (CButton *)GetDlgItem( IDC_BUTTON2 );
    char cTxt[21];
    cBt->GetWindowText(cTxt,20);
    if( strcmp(cTxt,"自动吃药") == 0 )
    {
        cBt->SetWindowText("不自动吃药");
        SetTimer(1,1000,NULL);
    }
    else
    {
        cBt->SetWindowText("自动吃药");
        KillTimer(1);
    }
}

void CZhengTuDlg::GetData()
{
    if( lNumQuestion > 0 )
        return;

    CDaoDatabase Database;
    char cFileName[1025];

    sprintf( cFileName, "%s\\dat.mdb", gcAppPath );

    BeginWaitCursor();
    try
    {
        Database.Open( cFileName,FALSE,TRUE );
    }
    catch( CDaoException *e )
    {
        char cTmp[1201];
        CString cstr;
        e->GetErrorMessage(cTmp,1000,NULL);
        cstr.Format("打开数据库失败!原因:%s",cTmp);
        AfxMessageBox(cstr);
        EndWaitCursor();
        e->Delete();
        return;
    }

    CDaoRecordset Record(&Database);
    Record.Open(dbOpenDynaset,"select * from DT",dbReadOnly);
    Record.MoveFirst();

    Question = new char * [100000];
    Anser = new char * [100000];

    COleVariant a,b;
    lNumQuestion=0;
    while( !Record.IsEOF() )
    {
        Record.GetFieldValue("题目",a);
        Record.GetFieldValue("答案",b);
        Question[lNumQuestion] = new char[121];
        Anser[lNumQuestion] = new char[51];
        sprintf(Question[lNumQuestion],"%.120s",(LPCSTR)a.bstrVal);
        sprintf(Anser[lNumQuestion],"%.50s",(LPCSTR)b.bstrVal);

        lNumQuestion++;
        Record.MoveNext();
    }
    Record.Close();
    EndWaitCursor();
    Database.Close();
//    char c[130];
//    sprintf( c, "共有[%ld]条记录!", lNumQuestion );
//    AfxMessageBox(c);
}


void CZhengTuDlg::OnButton3()
{
    GetData1();

    if( lAnserAddr == 0 )
    {
        char  cSearch1[31];
        sprintf(cSearch1,"CompetitionNpcDialog");
        HANDLE Process=NULL;
        if( MyOpenProcess( &Process ) )
        {
            AfxMessageBox("征途未运行!");
            return;
        }

        if( SearchKey( Process, 0x00000000,0xefffffff,cSearch1, 1, &lAnserAddr,0 ) )
        {
            AfxMessageBox("智力问答还未开始!!");
            CloseHandle( Process );
            return;
        }
        CloseHandle( Process );
    }

    iAnserCount = 0;
    SetTimer(3,1000,NULL);
}

void CZhengTuDlg::MyAnser()
{
    HANDLE Process=NULL;
    if( MyOpenProcess( &Process ) )
    {
        AfxMessageBox("征途未运行!");
        return;
    }

    ULONG lAnser;        //答题窗口名地址
    ULONG lAnserOffer = 0x300;        //题目相对窗口偏移量
    ULONG lKeyOffer = 0x210;    //答案相对题目的偏移量
    ULONG lNextKey = 0x80;        //下一个答案的偏移量

    lAnser = lAnserAddr;

    char cStr[121];
    memset(cStr, 0x00, sizeof(cStr) );
    ReadProcessMemory(Process,(LPVOID)(lAnser),cStr,20,NULL);
    if( strcmp(cStr,"CompetitionNpcDialog") != 0 )
    {
        m_Anser="答题还未开始!!";
        UpdateData(FALSE);
        KillTimer(3);
        CloseHandle( Process );
        AfxMessageBox("答题还未开始!!");
        return;
    }

    memset(cStr, 0x00, sizeof(cStr) );
    ReadProcessMemory(Process,(LPVOID)(lAnser + lAnserOffer),cStr,2,NULL);
    int iTh=atoi(cStr);
    if ( iTh == iAnserCount || iTh == 0 )
    {
        CloseHandle(Process);
        return;
    }

    memset(cStr, 0x00, sizeof(cStr) );
    ReadProcessMemory(Process,(LPVOID)(lAnser + lAnserOffer+0x10),cStr,120,NULL);
    long i=0;
    for( i=0; i < lNumQuestion; i++ )
    {
        if( strcmp(Question,cStr) == 0 )
            break;
    }
    if( i < lNumQuestion )
    {
            m_Anser.Format("%s",Anser);
    }
    else
    {
        m_Anser.Format("数据库里没找到记录!!%d,[%s]",iTh,cStr);
        CStdioFile fp;
        char cFileName[1025];
        sprintf(cFileName,"%s\\缺题记录.txt",gcAppPath);
        fp.Open(cFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite, NULL );
        fp.SeekToEnd();
        fp.WriteString(cStr);
        fp.WriteString("\n");
        for( int i=0; i<7; i++ )
        {
            ReadProcessMemory(Process,(LPVOID)(lAnser + lAnserOffer+lKeyOffer+lNextKey*i),cStr,120,NULL);
            if( strlen(cStr) == 0 )
                break;
            fp.WriteString(cStr);
            fp.WriteString("\n");
        }
        fp.WriteString("\n");
        fp.Close();
    }
    UpdateData(FALSE);
    iAnserCount = iTh;
    if( iTh >= 30 )
    {
        KillTimer(3);
        Dispose();    //释放内存
        AfxMessageBox("答题结束!!");
    }

    CloseHandle(Process);
}

CZhengTuDlg::~CZhengTuDlg()
{
    Dispose();    //释放内存
}

int CZhengTuDlg::SearchKey(HANDLE Process,ULONG lStart,ULONG lEnd,char *cSearch,int iFindN,ULONG *lFoundAddr,int iLen)
{
    // TODO: Add your control notification handler code here
    const ULONG lSize = 1024;
    ULONG lAddr = 0x02000000;
    ULONG lOld = 0;
    int  iLength;
    UCHAR cMax,cMin;

    char cTmp[lSize+21];
    memset(cTmp,0x00,lSize);

    *lFoundAddr = 0 ;

    lAddr = lStart;
    if( iLen == 0 )
        iLength = strlen(cSearch);
    else
        iLength = iLen;
    cMax = cMin = cSearch[0];
    for( int i=1;i<iLength;i++)
    {
        if( (UCHAR)cSearch > cMax )
            cMax = (UCHAR)cSearch;
        if( (UCHAR)cSearch < cMin )
            cMin = (UCHAR)cSearch;
    }

    while( lAddr < lEnd  )
    {
        memset(&cTmp[20],0x00,lSize);
        if(ReadProcessMemory(Process,(LPVOID)(lAddr),&cTmp[20],lSize,NULL) == TRUE)
        {
            long k=0;
            for( k=0;k<=lSize;k++)
            {
                if( (UCHAR)cTmp[k] > cMax  || (UCHAR)cTmp[k] < cMin )
                {
                    k = k + iLength -2;
                    continue;
                }
                int iFlag=0;
                for( int j=0;j<iLength;j++ )
                {
                    if( (UCHAR)cTmp[k] == (UCHAR)cSearch[j] )
                    {
                        iFlag = 1;
                        break;
                    }
                }
                if( iFlag == 0 )
                {
                    k = k + iLength -2;
                    continue;
                }
                for( long i=k-iLength;i<=k;i++)
                {
                    if( iLen == 0 )        /** 非二进制查找 **/
                    {
                        if( strcmp(cSearch,&cTmp) == 0 )
                        {
                            *lFoundAddr = lAddr + i - 20;
                            k = k + iLength;
                            i = i + iLength;
                            iFindN--;
                            if( iFindN == 0 )
                                return 0;

                            break;
                        }
                    }
                    else
                    {
                        if( memcmp( cSearch, &cTmp, iLen ) == 0 )
                        {
                            *lFoundAddr = lAddr + i - 20;
                            k = k + iLength;
                            i = i + iLength;
                            iFindN--;
                            if( iFindN == 0 )
                                return 0;

                            break;
                        }
                    }
                }
            }
            memcpy(&cTmp[lSize],&cTmp,20);
        }
        lAddr = lAddr + lSize;
    }

    if( iFindN > 0 )
    {
        return -1;        //没找到
    }
    return 0;
}

声明:本站所有资源均来自网络,版权归原公司及个人所有。如有版权问题,请及时与我们联系,我们在第一时间予以删除,谢谢!
ucbug游戏网
关于我们 | 下载帮助 | 广告&合作 | 下载声明 | 版权声明
Copyright © 2010-2016 ucbug.com. All Rights Reserved ucbug游戏网
皖ICP备15003425号 适度游戏娱乐,沉迷游戏伤身。