论坛: 编程破解 标题: 网络蚂蚁源代码(不完全) 复制本贴地址    
作者: battle [battle]    论坛用户   登录

--------------------------------------------------------------------------------

发信人:killer(killer),信区:网络编程精华区
// Component for Drag&Drop, from drop.dll
class CDropTarget : IDropTarget
{
public:
    HWND hChildWnd;
    HWND hMainWnd;
    cRefCount;
};

CDropTarget::CDropTarget(HWND hChild, HWND hMain)
{
    hChildWnd = hChildWnd;
    hMainWnd = hMain;
    cRefCount = 0;
}
   
CDropTarget* CreateDropTarget(HWND hChildWnd, HWND hMainWnd)
{
    CDropTarget* pDropTarget = new CDropTarget(hChildWnd, hMainWnd);
    pDropTarget->AddRef();

    // lock an object to ensure that it stays in memory.
    CoLockObjectExternal((IUnknown*)pDropTarget, 1, 0);
    RegisterDragDrop(hMainWnd, (IDropTarget*)pDropTarget);

    return pDropTarget;
}

//------------------------------------------------------------------------------

const char NullChar[]    = '\0';
const char language[]    = "language";
const char Language[]    = "Language";
const char English[]    = "English"
const char String[]        = "String";

char* GetModuleName(char* ModuleFileName)
{
    char* ret, p;

    if (ModuleFileName == NULL)
        return 0;;

    for (ret = p = ModuleFileName; *p; p++)
        if (*p == '\\' || *p == ':')
            ret = p + 1;

    return ret;
}

void CentralizeWindow(HWND hWnd)
{
    RECT r;
    int cx, cy;

    GetWindowRect(hWnd, &r);
    cx = r.right - r.left;
    cy = r.bottom - r.top;

    SetWindowPos(hWnd, NULL,
        (GetSystemMetrics(SM_CXSCREEN) - cx) / 2,
        (GetSystemMetrics(SM_CYSCREEN) - cy) / 2, cx, cy, SWP_NOSIZE | SWP_NOZORDER);
}

LPPICTURE LoadOemSplash(IStream* is)
{
    OFSTRUCT of;
    DWORD NumOfBytesRead, FileSize, FileSizeHigh;
    HANDLE hFile;
    HGLOBAL hGlb;
    LPPICTURE pPicture;

    if ((hFile = OpenFile((LPCSTR)is, &of, OF_READ)) == HFILE_ERROR)
        return NULL;

    FileSize = GetFileSize(hFile, &FileSizeHigh);

    if ((hGlb = GlobalAlloc(GMEM_MOVEABLE, FileSize)) == 0) {
        ShowErrMsg("GlobalAlloc");
        CloseHandle(hFile);
        return NULL;
    }

    ReadFile(hFile, GlobalLock(hGlb), FileSize, &NumOfBytesRead, 0);

    if (NumOfBytesRead != FileSize) {
        ShowErrMsg("ReadFile");
        CloseHandle(hFile);
        GlobalUnlock(hGlb);
        GlobalFree(hGlb);
        return NULL;
    }

    CloseHandle(hFile);
    GlobalUnlock(hGlb);

    if (CreateStreamOnHGlobal(hGlb, 1, &is)) {
        ShowErrMsg("IStorage->CreateStream");
        GlobalFree(hGlb);
        return NULL;
    }

    if (OleLoadPicture(is, 0, FALSE, IID_IPicture, (LPVOID *)&pPicture)) {
        is->Release();
        return NULL;
    }

    is->Release();
    return pPicture;
}

HPALETTE CreatePaletteForBmp(LPBITMAPINFOHEADER pBmp, int* ColorCount)
{
    LPLOGPALETTE lpLp;
    HPALETTE hPal;

    *ColorCount = (pBmp->biBitCount <= 8)? (1 << pBmp->biBitCount) : 0;

    if (*ColorCount == 0)
        return 0;

    if ((lpLp = (LPLOGPALETTE)malloc(sizeof(LOGPALETTE) + *ColorCount * sizeof(DWORD))) == NULL) {
        ShowErrMsg("Malloc");
        return 0;
    }

    lpLp->palVersion = 0x300;
    lpLp->palNumEntries = *ColorCount;

    if (*ColorCount > 0) {
        LPRGBQUAD lpRgb = (char*)pBmp + sizeof(BITMAPINFOHEADER);
        LPPALETTEENTRY lpPe = &lpLp->palPalEntry;
        for (i = 0; i < *ColorCount; i++) {
            lpPe->peRed = lpRgb->rgbRed;
            lpPe->peBlue = lpRgb->rgbBlue;
            lpPe->peGreen = lpRgb->rgbGreen;
            lpPe->peFlags = 0;
            lpPe++;
            lpRgb++;
        }
    }

    if ((hPal = CreatePalette(lpLp)) == NULL)
        ShowErrMsg("CreatePalette");

    free(lpLp);

    return hPal;
}

HBITMAP LoadDIBitmap(HINSTANCE hInst, short RID, int* p)
{
    HDC hDC;
    HRSRC hRsc;
    HGLOBAL hGlb;
    HPALETTE hPal;
    HBITMAP hBmp;
    int ColorCount;

    if ((hDC = GetDC(NULL)) == NULL) {
        ShowErrMsg("GetDC");
        return 0;
    }

    if ((hRsc = FindResource(hInst, MAKEINTRESOURCE(RID), RT_BITMAP)) == NULL) {
        ShowErrMsg("FindResource");
        return 0;
    }

    if ((hGlb = LoadResource(hInst, hRsc)) == NULL) {
        ShowErrMsg("LoadResource");
        ReleaseDC(NULL, hDC);
        return 0;
    }

    if ((lpv = LockResource(hRsc)) == NULL) {
        ShowErrMsg("LockResource");
        ReleaseDC(NULL, hDC);
        FreeResource(hRsc);
        return 0;
    }

    if ((hPal = CreatePaletteForBmp((LPBITMAPINFOHEADER)lpv, &ColorCount)) == NULL) {
        ReleaseDC(NULL, hDC);
        FreeResource(hRsc);
        return 0;
    }

    *p = hPal;

    SelectPalette(hDC, hPal, FALSE);
    RealizePalette(hDC);

    if ((hBmp = CreateDIBitmap(hDC, (LPBITMAPINFOHEADER)lpv, CBM_INIT, lpv + *(WORD*)lpv + ColorCount * sizeof(RGBQUAD), (BITMAPINFO)lpv, 0)) == NULL) {
        ShowErrMsg("CreateDIBitmap");
        ReleaseDC(NULL, hDC);
        FreeResource(hRsc);
        return 0;
    }

    ReleaseDC(NULL, hDC);
    FreeResource(hRsc);
    return hBmp;
}

LRESULT SplashWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    LPPICTURE pPicture;
    HBITMAP hBmp;
    RECT r;
    short width;

    switch (uMsg)
    {
    case WM_CREATE:
        if (!SetTimer(hWnd, 14, 2000, NULL))
            ShowErrMsg("SetTimer");
        CentralizeWindow(hWnd);
        return 0;

    case WM_DESTROY:
        KillTimer(hWnd, 14);
        return 0;

    case WM_PAINT:
        if ((hDC = BeginPaint(hWnd, &ps) == 0) {
            ShowErrMsg("BeginPaint");
            return 0;
        }

        if (gsOemSplash) {
            char OemSplash[MAX_PATH];
            sprintf(OemSplash, "%s\\%s", ModuleDir, gsOemSplash);
            pPicture = LoadOemSplash(OemSplash);
        }
        else
            pPicture = NULL;

        if (pPicture) {
            pPicture->get_Width(&width);
            pPicture->get_Height(&wParam);
            pPicture->Render(hDC, 0, 0, 300, 200, 0, wParam, width, -wParam, 0);
            pPicture->Release();
        }
        else {
            if ((uMsg = CreateCompatibleDC(hDC)) == NULL) {
                ShowErrMsg("CreateCompatibleDC");
                EndPaint(&ps);
                return 0;
            }

            if ((hBmp = LoadDIBitmap(gInstance, MAKEINTRESOURCE(138), &lParam)) == NULL) {
                EndPaint(&ps);
                DeleteDC(uMsg);
                return 0;
            }

            SelectPalette(hDC, (HPALETTE)lParam, FALSE);
            RealizePalette(hDC);

            SelectPalette(uMsg, (HPALETTE)lParam, FALSE);
            RealizePalette(uMsg);

            hBmp = SelectObject(uMsg, hBmp);
            BitBlt(hDC, 0, 0, 300, 200, uMsg, 0, 0, SRCCOPY);

            DeleteObject(SelectObject(uMsg, hBmp));
            DeleteDC(uMsg);
            DeleteObject((HGDIOBJ)lParam);
        }

        if (gbOemTitle) {
            uMsg = SelectObject(hDC, GetStockObject(ANSI_FIXED_FONT));
            SetRect(&r, 3, 3, 0, 0);
            DrawText(hDC, gsOEMTitle, -1, &r, DT_CALCRECT | DT_SINGLELINE);
            r.right += 4;
            r.bottom += 4;
            FillRect(hDC, &r, GetStockObject(BLACK_BRUSH));
            SetTextColor(hDC, RGB(0xff, 0xff, 0xff));
            SetBkMode(hDC, TRANSPARENT);
            DrawText(hDC, gsOEMTitle, -1, &r, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
            SelectObject(hDC, uMsg);
        }
        EndPaint(&ps);
        return 0;

    case WM_LBUTTONDOWN:
    case WM_TIMER:
        DestroyWindow(hWnd);
        return 0;

    default:
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
}

BOOL ShowSplashWindow()
{
    HKEY hKey;
    HWND hWnd;
    BOOL NoSplash;
    DWORD sz;

    WNDCLASS wc;

    RegOpenKeyEx(HKEY_CURRENT_USER, "Software\NetAnts\Layout", NULL, KEY_ALL_ACCESS, &hKey);
    if (RegQueryValueEx(hKey, "NoSplash", NULL, NULL, &NoSplash, &sz))
        NoSplash = FALSE;

    if (!NoSplash) {
        wc.s tyle = 0;
        wc.lpfnWndProc = SplashWinProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = ghInstance;
        wc.hIcon = 0;
        wc.hCursor = LoadCursor(0, IDC_ARROW);
        wc.hbrBackground = 0;
        wc.lpszMenuName = 0;
        wc.plszClassName = "NA_Splash";
        if (!RegisterClass(&wc)) {
            ShowErrMsg("RegisterClass");
            return FALSE;
        }

        hWnd = CreateWindowEx(0x88h, "NA_Splash, 0, 0x96000000, 0, 0, 300, 200, 0, 0, ghInstance, 0);
        if (hWnd == 0) {
            ShwoErrMsg("CreateWindowEx(Splash)");
            return FALSE;
        }
        ShowWindow(hWnd);
        UpdateWindow(hWnd);
    }

    return TRUE;
}

BOOL NetInit()
{
    WNDCLASS wc;
    WSADATA wd;

    wc.s tyle = 0;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = 0;
    wc.hCursor = 0;
    wc.hbrBackground = 0;
    wc.plszMenuName = 0;
    wc.lpfnWndProc = DefWindowProc;
    wc.hInstance = ghInstance;
    wc.plszClassName = "Dummy";
    if (!RegisterClass(&wc)) {
        ShowErrMsg("RegisterClass");
        return FALSE;
    }

    if (WSAStartup(0x101, &wd))
        return 0;
    if ((byte)wd.wVersion != 1 || *((byte*)&wd.wVersion + 1) != 1) {
        WSACleanup();
        return 0;
    }
}

int CreateContextMenu(HMENU hMenu)
{
    HMENU hContextMenu;
    LanguageData* ld;
    MENUITEMINFO mi;
    int i;

    if ((mi.hbmpItem = CreatePopupMenu()) == NULL) {
        ShowErrMsg("CreatePopupMenu");
        return -1;
    }

    for (i = 0, ld = gLanguageDataPtr; ld; ld = ld->next) {
        ZeroMemory(&mi, sizeof(mi));
        mi.fType = MFT_STRING;
        mi.wID = 50000 + i;
        mi.cbSize = sizeof(mi);
        mi.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA;
        mi.dwItemData = (ULONG_PTR)ld;
        mi.dwTypeData = (LPTSTR)ld;
        if (InsertMenuItem(mi.hbmpItem, i++, TRUE, &mi) == 0) {
            ShowErrMsg("InsertMenuItem");
            return -1;
        }
    }

    if (AppendMenu(hMenu, MF_SEPARATOR, 0, 0) == 0 ||
        AppendMenu(hMenu, MF_POPUP, mi.hbmpItem, "&Language") == 0)
    {
        ShowErrMsg("AppendMenu");
        return -1;
    }

    return 1;
}

int ClearOwnerDrawMenu(HMENU hMenu, BOOL IsTop)
{
    MENUITEMINFO mii;
    int sz = sizeof(mii) - sizeof(mii.hbmpItem);

    if (!IsMenu(hMenu))
        return -1;

    // This member is available only for Windows 98 and Windows 2000 or later,
    // The menu can display items using text, bitmaps, or both.
    for (mii.hbmpItem = 0; mii.hbmpItem < GetMenuItemCount(hMenu); mii.hbmpItem++) {
        memset(mii, 0, sz); // for windows 95 compatibility
        mii.cbSize = sz;
        mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_DATA;
        mii.dwTypeData = 0;
        mii.cch = 0;

        if (!GetMenuItemInfo(hMenu, mii.hbmpItem, TRUE, &mii)) {
            ShowErrMsg("GetMenuItemInfo");
            return -1;
        }
        if (mii.hSubMenu) {
            ClearOwnerDrawMenu(mii.hSubMenu, FALSE);
            if (IsTop) continue;
        }

        int type = mii.fType;
        if (type & MFT_OWNERDRAW) {
            MenuData* md = mii.dwItemData;
            if (md) {
                memset(&mii, 0, sz);
                mii.cbSize = sz;
                mii.fMask = MIIM_TYPE | MIIM_DATA;
                mii.fType = type & ~MFT_OWNERDRAW;
                mii.dwTypeData = &md->str;
                mii.dwItemData = md->OrgItemData;
                if (!SetMenuItemInfo(hMenu, mii.hbmpItem, TRUE/*by pos*/, &mii)) {
                    ShowErrMsg("SetMenuInfo");
                    return -1;
                }
                free(md);
            }
        }
    }

    return 1;
}

void MinimizeWindow(HWND hWnd)
{
    ShowWindow(hWnd, SW_HIDE);
}

typedef struct BandwidthNode
{
    int Bandwidth;
    HEVENT hEvent;
    BandwidthNode * next;
};

int DoMenuLocalization(HMENU hMenu) // @41925c
{
    char *ptr, String1[100], String2[100];
    MENUITEMINFO mi;

    mi.hbmpItem = 0;
    if (GetMenuItemCount(hMenu) > 0) do {
        ZeroMemory(&mi);
        mi.dwTypeData = &String2;
        mi.cbSize = sizeof(mi);
        mi.fMask = MIIM_ID | MIID_SUBMENU | MIIM_TYPE;
        mi.cch = sizeof(String2);
        if (GetMenuItemInfo(hMenu, mi.hbmpItem, TRUE, &mi) == 0) {
            ShowErrMsg("GetMenuItemInfo");
            return -1;
        }
        if (mi.hSubMenu) DoMenuLocalization(mi.hSubMenu);

        if (mi.fType == MFT_STRING) {
            if ((ptr = strchr(String2, '\t')) != NULL) *ptr = '\0';
            GetPrivateProfileString(String, String2, &NullChar, String1, sizeof(String1), gpCurrentLanguage->LanguagePath);
            if (lstrlen(String1) == 0) lstrcpy(String1, String2);
            ZeroMemory(&mi, sizeof(mi));
            mi.dwTypeData = &String1;
            mi.cbSize = sizeof(mi);
            mi.fMask = MIIM_TYPE;
            mi.fType = MFT_STRING;
            if (SetMenuItemInfo(hMenu, mi.hbmpItem, TRUE, &mi) == 0) {
                ShowErrMsg("SetMenuItemInfo");
                return -1;
            }
        }
    } while (++mi.hbmpItem < GetMenuItemCount(hMenu));

    return 1;
}

HMENU LocalizeMenu(HINSTANCE hInst, LPCTSTR lpMenuName)
{
    HMENU hMenu;

    if ((hMenu = LoadMenu(hInst, lpMenuName)) == NULL)
        return NULL;

    if (lstrlen(gLanguageDataPtr->LanguagePath))
        DoMenuLocalization(hMenu);

    return hMenu;
}
typedef struct tagMenuData
{
    HMENU hMenu;
    char str[100];
    int ImageIndex;
    int OrgItemData;
} MenuData;

typedef struct tagIndexMap
{
    int index;
    int MenuId;
} IndexMap;

IndexMap aIndexMap[38] = {
    {0, -1},  {1,40041},  {2,40042}, {3,40045}, {4, 40006},
    {4, 40053}, {5, 40007}, {5,40054}, {6,40010}, {6, 40046},
    {7, 40011}, {8,40012},  {9,40013}, {10,40014},{11, 40015},
    {12,40016}, {13,40017}, {14,40018},{15,40501},{16, 40019},
    {17,40001}, {18,40004}, {19,40025},{19,40049},{19, 40028},
    {20,40022}, {20,40068}, {20,40073},{21,40021},{21, 40066},
    {22,40002}, {23,40020}, {24,40023},{25,40044},{26, 40043},
    {27,40069}, {28,40071}, {28,40072}
};

int GetImageIndex(int ID)
{
    int i = 0;
    IndexMap* im = &aIndexMap[0];

    do {
        if (im->MenuId == ID)
            break;
        im++;
        i++;
        if (im >= md2list + sizeof(aIndexMap)
            return -1;
    } while (1);

    return im->index;
}

int LocalizeContextMenu(HMENU hMenu, BOOL SkipLocaleSubMenuItem)
{
    char *ptr, String2[100];
    MENUITEMINFO mi;
    HMENU hm = hMenu;
    MenuData* md;

    if (!IsMenu(hMenu))
        return -1;

    hm = hMenu;
    hMenu = 0;
    if (GetMenuItemCount(hm) > 0) do {
        ZeroMemory(&mi);
        mi.dwTypeData = &String2;
        mi.cbSize = sizeof(mi);
        mi.fMask = MIIM_ID | MIID_SUBMENU | MIIM_TYPE | MIIM_DATA;
        mi.cch = sizeof(String2);
        if (GetMenuItemInfo(hm, hMenu, TRUE, &mi) == 0) {
            ShowErrMsg("GetMenuItemInfo");
            return -1;
        }
        if (mi.hSubMenu) {
            LocalizeContextMenu(mi.hSubMenu, FALSE);
            if (SkipLocaleSubMenuItem) continue;
        }

        if (mi.fType == MFT_STRING) {
            if ((md = (MenuData*)malloc(sizeof(MenuData))) == NULL) {
                ShowErrMsg("Malloc");
                return -1;
            }
            md.hMenu = hm;
            lstrcpy(md.str, String2);
            md.ImageIndex= GetImageIndex(mi.wID);
            md.OrgItemData = mi.dwItemData;

            ZeroMemory(&mi, sizeof(mi));
            mi.dwTypeData = 0;
            mi.cbSize = sizeof(mi);
            mi.fMask = MIIM_TYPE | MIIM_DATA;
            mi.fType = MFT_OWNERDRAW;
            mi.dwItemData = md;
            if (SetMenuItemInfo(hm, hMenu, TRUE, &mi) == 0) {
                ShowErrMsg("SetMenuItemInfo");
                free(md);
                return -1;
            }
        }
    } while (++hMenu < GetMenuItemCount(hm));

    return 1;
}

int MeasureMenuItem(LPMEASUREITEMSTRUCT m)
{
    HDC hDC;
    RECT r;
    MenuData* md;

    if ((md = (MenuData*)m->itemData) == NULL)
        return -1;

    if ((hDC = GetDC(ghWndMain) == 0) {
        ShowErrMsg("GetDC");
        return -1;
    }

    SetRectEmpty(&r);
    DrawText(hDC, md->str, -1, &r, DT_CALCRECT | DT_SINGLELINE | DT_VCENTER);
    m->itemWidth = r.right + 20;
    m->itemHeight = GetSystemMetrics(SM_CYMENU) <= 20? 20: GetSystemMetrics(SM_CYMENU);
    ReleaseDC(hDC);
    return 1;
}

typedef struct tagDRAWITEMSTRUCT {
    UINT        CtlType;    //0
    UINT        CtlID;        //4
    UINT        itemID;        //8
    UINT        itemAction; //c
    UINT        itemState;    //10
    HWND        hwndItem;    //14
    HDC        hDC;        //18
    RECT        rcItem;        //1c
    DWORD      itemData;    //2c
} DRAWITEMSTRUCT, NEAR *PDRAWITEMSTRUCT, FAR *LPDRAWITEMSTRUCT;

BOOL CALLBACK DrawMenuImageProc(HDC hdc, LPARAM lData, WPARAM wData, int cx, int cy)
{
    ImageList_Draw(lData, wData, hdc, 0, 0, ILD_TRANSPARENT);
    return TRUE;
}

BOOL CALLBACK DrawMenuTextProc(HDC hdc, LPARAM lData, WPARAM wData, int cx, int cy)
{
    char* str, *ptr;
    Rect r;

    if ((str = wData) != NULL)
        ptr = str + strlen(str) + 1;
    else
        ptr = NULL;

    SetRect(&r, 0, 0, cx, cy);

    DrawText(hdc, str, -1, &r, DT_SINGLELINE | DT_VCENTER);

    if (ptr)
        DrawText(hdc, ptr, -1, &r, DT_SINGLELINE | DT_VCENTER | DT_RIGHT);

    return TRUE;
}

int DrawMenuItem(LPARAM lParam)
{
    HDC hDC;
    RECT rc, Rect, qrc, r;
    MenuData* md;
    LPDRAWITEMSTRUCT d = (LPDRAWITEMSTRUCT)lParam;
    int SavedDC;
    char* str;

    if ((md = (MenuData*)d->itemData) == NULL)
        return -1;

    if (md->ImageIndex != -1)
        lParam = md->ImageIndex;
    else
        lParam = d->itemState & ODS_CHECKED? 0 : -1;

    CopyRect(&rc, d->rcItem);

    Rect.top = rc.top;
    qrc.left = rc.left + 2;
    qrc.right = qrc.left + 20;
    Rect.left = qrc.right + 2;
    qrc.top = (rc.bottom - rc.top - 20) / 2 + rc.top;
    qrc.bottom = qrc.top + 20;
    Rect.right = rc.right - 10;
    Rect.bottom = rc.bottom;
    CopyRect(&r, &rc);

    if (lParam != -1)
        r.left = qrc.right;

    hDC = d->hDC;
    SavedDC = SaveDC(hDC);
    SetBkMode(hDC, TRANSPARENT);
    FillRect(hDC, &rc, NULL_BRUSH);
    if (d->itemState & (ODS_DISABLED | ODS_SELECTED))
        FillRect(hDC, &r, DEVICE_DEFAULT_FONT);

    // ODS_SELEC
// ODS_SELECTED = 0x0001  ODS_GRAYED = 0x0002  ODS_CHECKED = 0x0008
    // NULL_BRUSH = 5  DEFAULT_GUI_FONT = 17
    if (ghImageList != 0 && lParam != -1) {
        FillRect(hDC, &qrc,
            ((d->itemState & ODS_CHECKED) == 0 || d->itemState & ODS_SELECTED)?
            NULL_BRUSH : DEFAULT_GUI_FONT);
        if (d->itemState & ODS_CHECKED)
            DrawEdge(hDC, &qrc, BDR_SUNKENOUTER, BF_RECT);
        else if ((d->itemState & ODS_SELECTED) != 0 && d->itemState & ODS_GRAYED == 0)
            DrawEdge(hDC, &qrc, BDR_RAISEDOUTER, BF_RECT);
        InflateRect(&prc, -2, -2);
        if (d->itemState & ODS_GRAYED)
            DrawState(hDC, WHITE_BRUSH, DrawMenuImageProc, ghImageList, lParam,
                qrc.left, qrc.top, qrc.right - qrc.left, qrc.bottom - qrc.top,
                DSS_DISABLED);
        else
            ImageList_Draw(ghImageList, lParam, hDC, qrc.left, qrc.top, ILD_TRANSPARENT);
    }

    str = md->str;
    if ((md = strchr(str, '\t')) != NULL) {
        *(char*)md = '\0';
        lParam = str;
        str = (char*)md + 1;
    }
    else {
        lParam = str;
        str = NULL;
    }

    if ((d->itemState & ODS_SELECTED) == 0 && d->itemState & ODS_GRAYED) {
        DrawState(hDC, WHITE_BRUSH, DrawMenuTextProc, lParam,
            str == 0? 0 : 1, Rect.left, Rect.top, Rect.right - Rect.left,
            Rect.bottom - Rect.top, DSS_DISABLED/*0x0020*/);
    }
    else {
        if ((d->itemState & ODS_SELECTED) == 0)
            SetTextColor(hDC, GetSysColor(COLOR_MENUTEXT));
        else if ((d->itemState & ODS_GRAYED) == 0)
            SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
        else
            SetTextColor(hDC, GetSysColor(COLOR_MENU));
        DrawText(hDC, lParam, -1, &Rect, DT_SINGLELINE | DT_VCENTER);
        if (str)
            DrawText(hDC, str, -1, &Rect, DT_SINGLELINE | DT_VCENTER | DT_RIGHT);
    }

    if (md) *(char*)md = '\t';

    RestoreDC(hDC, SavedDC);
    return TRUE;
}

RECT grSize1, grSize2;
LRESULT MainWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static UINT uTaskBarCreatedMsg = 0;

    NMHDR* nmh;
    NOTIFYICONDATA nid;
    RECT rc, rcRebar, x;
    HDWP hDWP;
    SYSTEMTIME st;

    if (!uTaskBarCreatedMsg)
        uTaskBarCreatedMsg = RegisterWindowMessage("TaskbarCreated");

    if (uMsg == uTaskBarCreatedMsg)
        uMsg = 0x7fe;

    switch (uMsg)
    {
    case WM_NOTIFY:
        if (lParam == 0) break;
        nmh = (NMHDR*)lParam;

        if (nmh->code == TTN_FIRST)
            if (SendMessage(ghToolbar, 0x423, 0, 0) == nmh->hwndFrom)
                ;
        break;

    case WM_CREATE:
        gbTrayIconPresent = FALSE;
        ghWndMain = hWnd;
        GetConfigFromReg();
        GetMostRecentlyURL();
        GetLastDir();
        GetCategory();
        GetLoginInfo();
        GetDefaultHttpProxy();
        GetBookmark();
        ghMenu = LocalizeMenu(ghInstance, MAKEINTRESOURCE(102));
        CreateContextMenu(GetSubMenu(ghMenu, 3));
        LocaleContextMenu(ghMenu, 1);
        SetMenu(hWnd, ghMenu);
        ghRebar = CreateRebar(hWnd);
        ghToolbar = CreateMyToolbar(ghRebar);
        ghWaveBar = CreateWaveBar(ghRebar);
        ghAdvWin = CreateAdvWindow(hWnd);
        ghStatusbar = CreateStatusbar(hWnd);
        ghFolderWin = CreateFolderWin(hWnd);
        ghJobList = CreateJobPane(hWnd);
        ghBlockWin = CreateBlockWin(hWnd);
        ghLogWin = CreateLogWin(hWnd);
        ghInfoListWin = CreateInfoWin(hWnd);
        ghLinkListWin = CreateLinkWin(hWnd);
        ghTabWin = CreateTabWin(hWnd);
        ghDropBasketWin = CreateDropBasket();
        gpJobDropTarget = CreateDropTarget(ghJobList, hWnd);
        gpBasketDropTarget = CreateDropTarget(ghDropBasketWin, hWnd);

        nid.cbSize = sizeof(NOTIFYICONDATA);
        nid.hWnd = hWnd;
        nid.uID = 0x6b;
        nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        nid.uCallbackMessage = 0x7ec;
        nid.hIcon = LoadIcon(hgInstance, IDI_NETANTS);
        sprintf(nid.szTip, "%lu bytes received", gReceivedBytes);
        if (!Shell_NofifyIcon(NIM_ADD, &nid)) {
            ShowErrMsg("Shell_NotifyIcon(Add)");
            return -1;
        }
        gbTrayIconPresent = TRUE;

        SendMessage(ghWaveBar, 0x7f2, gBandWidthScale, 0);
       
        ghThreadHandle = _beginthreadex(NULL, NULL, WorkThread, NULL, NULL, &gThreadID);
        if (hHandle == 0) {
            ShowErrMsg("_beginthreadex");
            return -1;
        }
 
        if (!SetTimer(hWnd, 2, 1000, NULL))
            ShowErrMsg("SetTimer");
        if (!SetTimer(hWnd, 3, 60000, NULL))
            ShowErrMsg("SetTimer");
        if (!SetTimer(hWnd, 4, gSampleFrequency * 1000, NULL))
            ShowErrMsg("SetTimer");
        if (!SetTimer(hWnd, 8, 60000, NULL))
            ShowErrMsg("SetTimer");
        if (!SetTimer(hWnd, 9, 1000, NULL))
            ShowErrMsg("SetTimer");
        break;

    case WM_SIZE:
        if (wParam == SIZE_MINIMIZED)
            MinimizeMainWindow(hWnd);
        else if (var != 0)
            var = 0;

        GetClientRect(hWnd, &rc);
        if (gnWidth == 0)
            gnWidth = rc.right / 4;
        if (gyTop == 0)
            gyTop = rc.bottom / 2;
        SetRect(&grSize1, gnWidth, 0, gnWidth + 3, rc.bottom);
        SetRect(&grSize2, 0, gyTop, rc.right, nyTop + 3);
        if (gbHideToolbar) {
            MoveWindow(ghRebar, rc.left, rc.top, rc.right, rc.bottom, TRUE);
            GetWindowRect(ghRebar, rcRebar);
            rc.top = rcRebar.bottom - rcRebar.top + rc.top + 1;
            grSize1.top += rcRebar.bottom - rcRebar.top + 1;
        }

        if (gbShowStatusBar) {
            SendMessage(ghStatusbar, WM_SIZE, 0, 0);
            GetWindowRect(ghStatusBar, rcRebar);
            grSize1.bottom += rcRebar.top - rcRebar.bottom - 1;
            rc.bottom += rcRebar.top - rcRebar.bottom - 1;
        }

        if (gbShowFolderWindow) {
            MoveWindow(ghFolderWindow, rc.left, rc.top, nVSplitPos, rc.bottom - rc.top, TRUE);
            rc.left = nVSplitPos + rc.left + 3;
            grSize2.left += nVSplitPos + 3;
        }
        else {
            grSize1.left = 0;
            grSize1.right = 0;
        }

        MoveWindow(ghAdvWin, rc.left, rc.top, rc.right - rc.left, 0/* Org 0x42*/, TRUE);
        rc.top += 0; /* Org 0x43 */

        if (gbShowTaskStatusPane) {
            hDWP = BeginDeferWindowPos(5);
            SetRect(&x, rc.left, nHSplitPos + 3, rc.right, rc.bottom);
            DeferWindowPos(hDWP, ghTabWin, 0, x.left, x.top, x.right -  x.left, x.bottom - x.top, SWP_NOZORDER);
            SendMessage(ghTabWin, 0x1328, 0, &x);
            DeferWindowPos(hDWP, ghLogWin, 0, x.left, x.top, x.right -  x.left, x.bottom - x.top, SWP_NOZORDER);
            DeferWindowPos(hDWP, ghInfoListWin, 0, x.left, x.top, x.right -  x.left, x.bottom - x.top, SWP_NOZORDER);
            DeferWindowPos(hDWP, ghLinkListWin, 0, x.left, x.top, x.right -  x.left, x.bottom - x.top, SWP_NOZORDER);
            EndDeferWindowPos(hDWP);
            rc.bottom = nHSplitPos;
        }
        else {
            grSize2.top = 0;
            grSize2.bottom = 0;
        }
        MoveWindow(ghJobList, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);

        break;

    case WM_POWERBROADCAST:
        if (wParam == PBT_APMQUERYSUSPEND)
            return gRunningJobCount > 0? BROADCAST_QUERY_DENY : TRUE;
        break;

    case WM_TIMER:
        switch (wParam)
        {
        case 2:
            Timer2(ghJobList);
            break;
        case 3:
            while (!PostThreadMessage(gThreadID, 0x407, 0, 0))
                if (GetLastError() == ERROR_INVALID_THREAD_ID) break;
            break;

        // updating bandwidth display and received datasize on statusbar
        case 4:
            Bandwidth = SampledDataSize / gHistoSampleFrequency;
            BandwidthScale = gBandwidthScale * 1024;
            SendMessage(ghWaveBar, 0x7f1, Bandwidth, 0);
            ShowBandwidthOnStatusbar(ghStatusbar, Bandwidth);
            if (Bandwidth > BandwidthScale)
                Bandwidth = BandwidthScale;

            if (Bandwidth) {
                if (!SetTimer(hWnd, 13, 200 * (4 - 3 * Bandwidth / BandwidthScale), 0)
                    ShowErrMsg("SetTimer");
                gbBasketTimer = TRUE;
            }
            else if (gbBasketTimer) {
                KillTimer(hWnd, 13);
                gbBasketTimer = FALSE;
            }

            SampledDataSize = 0;
            ShowReceivedSizeOnStatusbar(ghStatusbar, gReceivedBytes);
            break;

        //Schedule timer for scheduled downloading & hangup
        case 8:
            GetLocalTime(&st);

            if (gbScheduleDownload &&
                st.wHour == gScheduleDownloadHour && st.wMinute == gScheduleDownloadMinute)
            {
                SechduleDownload();
            }
            if (gbScheduleHangup &&
                st.wHour == gScheduleDownloadHour && st.wMinute == gScheduleDownloadMinute)
            {
                SechduleHangup();
                if (gbAutoHangup)
                    Hangup();
            }
            break;
       
        case 9:
            if (gnSpeedMode == 0) {
                UpdateBandwidth(-1);
            }
            else (gnSpeedMode == 1) {
                UpdateBandwidth(gnBandwidth);
            }
            else if (gnSpeedMode == 2) {
            }
            break;
       
        case 12:
            break;

        case 13: // Basket timer
            break;
        }
        return TRUE;;

    case WM_NCHITTEST:
        break;

    case WM_COPYDATA:
        break;

    case WM_CONTEXTMENU:
        break;

    case WM_INITMENU:
        break;

    case WM_MENUSELECT:
        break;

    case WM_MENUCHAR:
        break;

    case WM_LBUTTONDOWN:
        break;

    case WM_SETCURSOR:
        break;

    case WM_DRAWITEM:
        if (wParam == 0 || ((MEASUREITEMSTRUCT*)lParam)->CtlType != ODT_MENU)
            break;
        DrawMenuItem((LPMEASUREITEMSTRUCT)lParam);
        return TRUE

    case WM_MEASUREITEM:
        if (wParam == 0 || ((MEASUREITEMSTRUCT*)lParam)->CtlType != ODT_MENU)
            break;
        MeasureMenuItem((LPMEASUREITEMSTRUCT)lParam);
        return TRUE

    case 0x7eb:
        break;

    case 0x7ec:
        break;

    case 0x7ed:
        break;

    case 0x7ee:
        break;

    case 0x7f0:
        break;

    case 0x7f3:
        break;

    case 0x7f4:
        break;

    case 0x7f5:
        break;

    case 0x7f7:
        break;

    case 0x7fe:
        break;

    case 0x7ff:
        break;

    case 0x801:
    case WM_DRAWCLIPBOARD:
    case WM_CHANGECBCHAIN:
        break;

    case 0x802:
        break;

    case 0x803:
        break;

    case 0x804:
        break;

    case 0x810:
        if (ghMenu) {
            ClearOwnerDrawMenu(ghMenu, 1);
            DestroyMenu(ghMenu);
        }
        ghMenu = LocalizeMenu(ghInstance, MAKEINTRESOURCE(102));
        CreateContextMenu(GetSubMenu(ghMenu, 3));
        LocalizeContextMenu(ghMenu, TRUE);
        SetMenu(hWnd, ghMenu);
        return 0;

    case WM_HELP:
        break;

    case WM_DESTROY:
    case WM_ENDSESSION:
        ResetEvent(ghEvent);
        if (gbTrayIconPresent) {
            gbTrayIconPresent = FALSE;
            nid.cbSize = sizeof(NOTIFYICONDATA);
            nid.hWnd = hWnd;
            nid.uID = 0x6b;
            if (!Shell_NofifyIcon(NIM_DELETE, &nid) && uMsg == WM_DESTROY)
                ShowErrMsg("Shell_NotifyIcon(Delete)");
        }
       
        while (!PostThreadMessage(idThread, 0x405, 0, 0))
            if (GetLastError() == 0x5a4) break;
        WaitForSingleObject(ghThreadHandle, INFINITE);
        CloseHandle(ghThreadHandle);

        if (gpJobDropTarget) gpJobDropTarget->DeleteDropTarget();
        if (gpBasketDropTarget) gpBasketDropTarget->DeleteDropTarget();
        DestroyWindow(ghDropBasketWin);
        if (ghMenu) {
            SetMenu(hWnd, 0);
            ClearOwnerDrawMenu(ghMenu, 1);
            DestroyMenu(ghMenu);
        }

        ImageList_Destroy(SendMessage(ghTabWin, 0x1302, 0, 0));
        ClearClipViewer(hWnd);
        UninitDDE();
        SaveJobs();
        CleanLogWinAndStatusbar();
        BackupJobHistory();
        KillTimer(hWnd, 2);
        KillTimer(hWnd, 3);
        KillTimer(hWnd, 4);
        KillTimer(hWnd, 8);
        KillTimer(hWnd, 9);
        if (gbBasketTimer)
            KillTimer(hWnd, 13);
        PostQuitMessage(0);
        break;

    case WM_QUERYENDSESSION:
        break;

    case WM_COMMAND:
        break;
    }

    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

// sizeof(LanguageData) == 0x13c
typedef struct tagLanguageData {
    char LanguageName[50];
    char LanguagePath[MAX_PATH + 2];
    LanguageData* next;
} LanguageData, *PLanguageData;

// Search a specific language from a linked list
LanguageData* SearchLanguageDataList(const char* LanguageName)
{
    for (LanguageData* ld = gLanguageDataPtr; ld; ld = ld->next)
        if (!lstrcmp(ld->LanguageName, LanguageName))
            return ld;
    return NULL;
}

// Add a language to the linked list
LanguageData* AddLanguageData(const char* LanguageName, const char* LanguagePath)
{
    if (SearchLanguageDataList(LanguageName))
        return NULL;

    LanguageData* NewLd = (LanguageData*)malloc(sizeof(LanguageData));
    if (NewLd == NULL) {
        ShowErrMsg("Malloc");
        return NULL;
    }

    strcpy(NewLd->LanguageName, LanguageName);
    if (LanguagePath)
        lstrcpy(NewLd->LanguagePath, LanguagePath);
    else
        NewLd->LanguagePath[0] = 0;

    LanguageData* InsertAfter = NULL;
    for (LanguageData* ld = gLageuageDataPtr; ld; ld = ld->next) {
        if (lstrcmp(ld->LanguageName, LanguageName) >= 0) break;
        InsertAfter = ld;
    }

    if (InsertAfter == NULL) {
        NewLd->next = gLanguageDataPtr;
        gLanguageDataPtr = NewLd;
    }
    else {
        NewLd->next = InsertAfter->next;
        InsertAfter->next = NewLd;
    }
    gLanguageDataCount++;

    return NewLd;
}

// Wrap of _vsnprintf, initialize the buf with 0 before call _vsnprintf
int ZeroVsnprintf(char* buf, int sz, const char* form, va_list argptr)
{
    //////////////////////////////////////////////////////////////////////////
    // From the disassembly code, the author seemed to use folling statement:
    // memset(buf, sz, 0);
    // I think it's wrong
    //////////////////////////////////////////////////////////////////////////
    memset(buf, 0, sz);
    _vsnprintf(buf, sz, form, argptr);
}

int SetLanguage(const char* LanguageName)
{
    LanguageData* ld;
    if ((ld = SearchLanguageDataList(LanguageName)) == NULL)
        return -1;

    gpCurrentLanguage = ld;

    SendMessage(ghWndMain, 0x810, 0, 0);
    SendMessage(ghFolderWin, 0x810, 0, 0);
    SendMessage(ghJobList, 0x810, 0, 0);
    SendMessage(ghTabWin, 0x810, 0, 0);
    SendMessage(ghStatusbar, 0x810, 0, 0);
    SendMessage(ghLogWin, 0x810, 0, 0);
    SendMessage(ghInfoListWin, 0x810, 0, 0);
    SendMessage(ghLinkListWin, 0x810, 0, 0);

    return 1;
}

void InitLanguage()
{
    char FileName[MAX_PATH], LanguagePath[MAX_PATH];
    WIN32_FIND_DATA fd;
    HANDLE hFind;
    char LanguageName[52];
    HKEY hKey;
    DWORD cbData;

    memset(LanguageName, 0, 50);
    AddLanguageData(English, NULL);
   
    // Get all language data
    ZeroVsnprintf(FileName, MAX_PATH, "%s\\%s\\*.ini", ModuleDir, language);
    if ((hFind = FindFirstFile(FileName, &fd) != INVALID_HANDLE_VALUE)
        do {
            ZeroVsnprintf(LanguagePath, MAX_PATH, "%s\\%s\\%s", ModuleDir, language, fd.cFileName);
            GetPrivateProfileString("Info", Language, &NullChar, LanguageName, 50, buf);
            if (lstrlen(LanguageName) && lstrcmp(LanguageName, English))
                AddLanguageData(LanguageName, LanguagePath);
        } while (FindNextFile(hFind, &fd));
    FindClose(hFind);
   
    // Set current language to the one specified in Registry
    RegOpenKeyEx(HKEY_CURRENT_USER, "Software\NetAnts\Localization", 0, KEY_ALL_ACCESS, &hKey);
    cbData = 50;
    if (RegQueryValueEx(hKey, Language, NULL, NULL, NULL, &cbData) != ERROR_SUCCESS ||
        !lstrlen(LanguageName) || !SearchLanguageDataList(LanguageName))
    {
        lstrcpy(LanguageName, English);
    }
    SetLanguage(LanguageName);
    RegCloseKey(hKey);
   
    return TRUE;
}

char gsOemTitle[100];
char gsOemWebsite[100];
char gsOemSplash[MAX_PATH];
int GetOemData(void)
{
    HKEY hKey;
    int cbData;

    RegOpenKeyEx(HKEY_CURRENT_USER, "Software\NetAnts\OEM", NULL, KEY_ALL_ACCESS, &hKey);
    cbData = 100;
    if (RegQueryValueEx(hKey, "Title", NULL, NULL, &gsOemTitle, &cbData))
        gsOemTitle[0] = 0;

    cbData = 100;
    if (RegQueryValueEx(hKey, "Website", NULL, NULL, &gsOemWebsite, &cbData))
        gsOemWebsite[0] = 0;

    cbData = MAX_PATH;
    if (RegQueryValueEx(hKey, "Splash", NULL, NULL, &gsOemSplash, &cbData))
        gsOemSplash[0] = 0;

    RegCloseKey(hKey);
    return TRUE;
}

HANDLE ghSubagentTrapEvent;
AsnObjectIdentifier gFirstSupportedRegion;

BOOL (*pfnSnmpExtensionInit)(
  DWORD dwUptimeReference,                    // see NOTE below
  HANDLE *phSubagentTrapEvent,                // trap event handle
  AsnObjectIdentifier *pFirstSupportedRegion  // first MIB subtree
);
BOOL (*pfnSnmpExtensionQuery)(
  BYTE bPduType,                  // SNMPv1 PDU request type
  SnmpVarBindList *pVarBindList,  // pointer to variable bindings
  AsnInteger32 *pErrorStatus,    // pointer to SNMPv1 error status
  AsnInteger32 *pErrorIndex      // pointer to the error index
);

#include "snmp.h"

// load inetmib1.dll (Small Netword Management Protocol) and get the address of
//    SnmpExtensionInit
//    SnmpExtensionQuery
int InitSNMP(void)
{
    HMODULE hModule;

    gbSnmpInitialized = FALSE;

    if ((hModule = LoadLibrary("inetmib1.dll")) == NULL)
        return -1;

    pfnSnmpExtensionInit = GetProcAddress(hModule, "SnmpExtensionInit");
    pfnSnmpExtensionQuery = GetProcAddress(hModule, "SnmpExtensionQuery");
    if (pfnSnmpExtensionInit == NULL || pfnSnmpExtensionQuery == NULL) {
        FreeLibrary(hModule);
        return -1;
    }
   
    if (!(*pfnSnmpExtensionInit)(GetTickCount(),
        &ghSubagentTrapEvent, &gFirstSupportedRegion))
    {
        ShowErrMsg("SnmpExtensionInit");
        return -1;
    }
    gbSnmpInitialized = TRUE;
    return 1;
}

DWORD (*pfnRasDial) (
  LPRASDIALEXTENSIONS lpRasDialExtensions,
DWORD (*pfnRasDial) (
  LPRASDIALEXTENSIONS lpRasDialExtensions,
                          // pointer to function extensions data
  LPCTSTR lpszPhonebook,  // pointer to full path and file
                          //  name of phone-book file
  LPRASDIALPARAMS lpRasDialParams,
                          // pointer to calling parameters data
  DWORD dwNotifierType,  // specifies type of RasDial event handler
  LPVOID lpvNotifier,    // specifies a handler for RasDial events
  LPHRASCONN lphRasConn  // pointer to variable to receive
                          //  connection handle
);

DWORD (*pfnRasHangUp) (
  HRASCONN hrasconn  // handle to the RAS connection to hang up
);

DWORD (*pfnRasEnumEntries*) (
  LPCTSTR reserved,              // reserved, must be NULL
  LPTCSTR lpszPhonebook,        // pointer to full path and
                                //  file name of phone-book file
  LPRASENTRYNAME lprasentryname, // buffer to receive
                                //  phone-book entries
  LPDWORD lpcb,                  // size in bytes of buffer
  LPDWORD lpcEntries            // number of entries written
                                //  to buffer
);

DWORD (*pfnRasEnumConnections)(
  LPRASCONN lprasconn,  // buffer to receive connections data
  LPDWORD lpcb,          // size in bytes of buffer
  LPDWORD lpcConnections // number of connections written to buffer
);

DWORD (*pfnRasGetConnectStatus) (
  HRASCONN hrasconn,  // handle to RAS connection of interest
  LPRASCONNSTATUS lprasconnstatus
                      // buffer to receive status data
);

DWORD (*pfnRasGetErrorString)(
  UINT uErrorValue,        // error to get string for
  LPTSTR lpszErrorString,  // buffer to hold error string
  DWORD cBufSize          // size, in characters, of buffer
);

DWORD (*pfnRasGetEntryDialParams)(
  LPCTSTR lpszPhonebook,  // pointer to the full path and
                          //  file name of the phone-book file
  LPRASDIALPARAMS lprasdialparams,
                          // pointer to a structure that
                          //  receives the connection parameters
  LPBOOL lpfPassword      // indicates whether the user's
                          //  password was retrieved
);

// Create a mutex and load RASAPI32.DLL (For Remote Access Service). Get following addresses:
//    RasDial
//    RasHangUp
//    RasEnumEntries
//    RasEnumConnections
//    RasGetConnectStatus
//    RasGetErrorString
//    RasGetEntryDialParams
int InitRAS(void)
{
    HMODULE hModule;

    if ((ghMutexObject = CreateMutex(NULL, NULL, NULL)) == NULL) {
        ghMutexObject = -1;
        ShowErrMsg("CreateMutex");
        gbIsRASAvailable = FALSE;
        return -1;
    }
    if ((hModuel = LoadLibrary("RASAPI32.DLL")) == NULL) {
        gbIsRASAvailable = FALSE;
        return 1;
    }

    pfnRasDial = GetProcAddress(hModule, "RasDial");
    pfnRasHangUp = GetProcAddress(hModule, "RasHangUp");
    pfnRasEnumEntries = GetProcAddress(hModule, "RasEnumEntries");
    pfnRasEnumConnections = GetProcAddress(hModule, "RasEnumConnections");
    pfnRasGetConnectStatus = GetProcAddress(hModule, "RasGetConnectStatus");
    pfnRasGetErrorString = GetProcAddress(hModule, "RasGetErrorString");
    pfnRasGetEntryDialParams = GetProcAddress(hModule, "RasGetEntryDialParams");

    gbIsRASAvailable =
        pfnRasDial != NULL &&
        pfnRasHangUp != NULL &&
        pfnRasEnumEntries != NULL &&
        pfnRasEnumConnections != NULL &&
        pfnRasGetConnectStatus != NULL &&
        pfnRasGetErrorString != NULL &&
        pfnRasGetEntryDialParams != NULL;
    return 1;
}

BYTE data1[64] = {
    0x3A, 0x32, 0x2A, 0x22, 0x1A, 0x12, 0x0A, 0x02,
    0x3C, 0x34, 0x2C, 0x24, 0x1C, 0x14, 0x0C, 0x04,
    0x3E, 0x36, 0x2E, 0x26, 0x1E, 0x16, 0x0E, 0x06,
    0x40, 0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08,
    0x39, 0x31, 0x29, 0x21, 0x19, 0x11, 0x09, 0x01,
    0x3B, 0x33, 0x2B, 0x23, 0x1B, 0x13, 0x0B, 0x03,
    0x3D, 0x35, 0x2D, 0x25, 0x1D, 0x15, 0x0D, 0x05,
    0x3F, 0x37, 0x2F, 0x27, 0x1F, 0x17, 0x0F, 0x07
};

BYTE data2[64] = {
    0x28h, 0x08, 0x30, 0x10, 0x38, 0x18, 0x40, 0x20,
    0x27h, 0x07, 0x2F, 0x0F, 0x37, 0x17, 0x3F, 0x1F,
    0x26h, 0x06, 0x2E, 0x0E, 0x36, 0x16, 0x3E, 0x1E,
    0x25h, 0x05, 0x2D, 0x0D, 0x35, 0x15, 0x3D, 0x1D,
    0x24h, 0x04, 0x2C, 0x0C, 0x34, 0x14, 0x3C, 0x1C,
    0x23h, 0x03, 0x2B, 0x0B, 0x33, 0x13, 0x3B, 0x1B,
    0x22h, 0x02, 0x2A, 0x0A, 0x32, 0x12, 0x3A, 0x1A,
    0x21h, 0x01, 0x29, 0x09, 0x31, 0x11, 0x39, 0x19
};

DWORD dw[4] = {8, 4, 2, 1};
DWORD dw0[8] = {0x80, 0x40, 0x20, 0x10, 8, 4, 2, 1};

char addr1[1024];
char addr2[1024];

void sub1(BYTE* addr, BYTE* data)
{
    int i, j, var_4, l;
    ZeroMemory(addr, 0, 1024);

    for (var_4 = 0, l = 0; l < 256; l += 16, var_4++) {
        for (i = 0; i < 16; i++) {
            for (j = 0; i < 64; j++) {
                if ((data[j] - 1) / 4 == var_4 && (dw[(data[j] - 1) % 4] & i))
                    addr[j / 8 + (l + i) * 8] |= dw0[j % 8];
            }
        }
    }
}

BYTE data3[56] = {
    0x39, 0x31, 0x29, 0x21, 0x19, 0x11, 0x09, 0x01,
    0x3A, 0x32, 0x2A, 0x22, 0x1A, 0x12, 0x0A, 0x02,
    0x3B, 0x33, 0x2B, 0x23, 0x1B, 0x13, 0x0B, 0x03,
    0x3C, 0x34, 0x2C, 0x24, 0x3F, 0x37, 0x2F, 0x27,
    0x1F, 0x17, 0x0F, 0x07, 0x3E, 0x36, 0x2E, 0x26,
    0x1E, 0x16, 0x0E, 0x06, 0x3D, 0x35, 0x2D, 0x25,
    0x1D, 0x15, 0x0D, 0x05, 0x1C, 0x14, 0x0C, 0x04
}

BYTE data4[] = {1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28};
BYTE data5[] = {
    0x0E, 0x11, 0x0B, 0x18, 0x01, 0x05, 0x03, 0x1C,
    0x0F, 0x06, 0x15, 0x0A, 0x17, 0x13, 0x0C, 0x04,
    0x1A, 0x08, 0x10, 0x07, 0x1B, 0x14, 0x0D, 0x02,
    0x29, 0x34, 0x1F, 0x25, 0x2F, 0x37, 0x1E, 0x28,
    0x33, 0x2D, 0x21, 0x30, 0x2C, 0x31, 0x27, 0x38,
    0x22, 0x35, 0x2E, 0x2A, 0x32, 0x24, 0x1D, 0x20
}

BYTE addr3[63];
BYTE addr4[96];
BYTE addr5[64];
void sub2(char* str)
{
    int edx, edi, ecx, eax, ebx, esi;

    for (edi = 0; edi < sizeof(data3); edi++)
        addr3[edi] = (dw0[(data3[edi] - 1) % 8] & str[(data3[edi] - 1) / 8])? 1 : 0;
    ZeroMemory(addr4, 0, sizeof(addr4));

    for (edx = 0; edi = 0; edi < 96; edi += 6, edx++) {
        for (eax = data4[i], ecx = 0; ecx < 56; eax++, ecx++) {
            esi = eax;
            ebx = (ecx == 28)? 0 : 1;
            ebx--;
            ebx &= 0xFFFFFFE4;
            ebx += 56;
            if (eax > ebx) esi = eax - 28;
            addr5[ecx] = addr3[esi];
        }
        for (ecx = 0; ecx < 48; ecx++)
            if (addr5[data5[ecx] - 1])
                addr4[edi + ecx / 8] = dw0[ecx % 8];
    }
}

BYTE data6[512] = {
    0Eh, 04h, 0Dh, 01h, 02h, 0Fh, 0Bh, 08h, 03h, 0Ah
    06h, 0Ch, 05h, 09h, 00h, 07h, 00h, 0Fh, 07h, 04h
    0Eh, 02h, 0Dh, 01h, 0Ah, 06h, 0Ch, 0Bh, 09h, 05h
    03h, 08h, 04h, 01h, 0Eh, 08h, 0Dh, 06h, 02h, 0Bh
    0Fh, 0Ch, 09h, 07h, 03h, 0Ah, 05h, 00h, 0Fh, 0Ch
    08h, 02h, 04h, 09h, 01h, 07h, 05h, 0Bh, 03h, 0Eh
    0Ah, 00h, 06h, 0Dh, 0Fh, 01h, 08h, 0Eh, 06h, 0Bh
    03h, 04h, 09h, 07h, 02h, 0Dh, 0Ch, 00h, 05h, 0Ah
    03h, 0Dh, 04h, 07h, 0Fh, 02h, 08h, 0Eh, 0Ch, 00h
    01h, 0Ah, 06h, 09h, 0Bh, 05h, 00h, 0Eh, 07h, 0Bh
    0Ah, 04h, 0Dh, 01h, 05h, 08h, 0Ch, 06h, 09h, 03h
    02h, 0Fh, 0Dh, 08h, 0Ah, 01h, 03h, 0Fh, 04h, 02h
    0Bh, 06h, 07h, 0Ch, 00h, 05h, 0Eh, 09h, 0Ah, 00h
    09h, 0Eh, 06h, 03h, 0Fh, 05h, 01h, 0Dh, 0Ch, 07h
    0Bh, 04h, 02h, 08h, 0Dh, 07h, 00h, 09h, 03h, 04h
    06h, 0Ah, 02h, 08h, 05h, 0Eh, 0Ch, 0Bh, 0Fh, 01h
    0Dh, 06h, 04h, 09h, 08h, 0Fh, 03h, 00h, 0Bh, 01h
    02h, 0Ch, 05h, 0Ah, 0Eh, 07h, 01h, 0Ah, 0Dh, 00h
    06h, 09h, 08h, 07h, 04h, 0Fh, 0Eh, 03h, 0Bh, 05h
    02h, 0Ch, 07h, 0Dh, 0Eh, 03h, 00h, 06h, 09h, 0Ah
    01h, 02h, 08h, 05h, 0Bh, 0Ch, 04h, 0Fh, 0Dh, 08h
    0Bh, 05h, 06h, 0Fh, 00h, 03h, 04h, 07h, 02h, 0Ch
    01h, 0Ah, 0Eh, 09h, 0Ah, 06h, 09h, 00h, 0Ch, 0Bh
    07h, 0Dh, 0Fh, 01h, 03h, 0Eh, 05h, 02h, 08h, 04h
    03h, 0Fh, 00h, 06h, 0Ah, 01h, 0Dh, 08h, 09h, 04h
    05h, 0Bh, 0Ch, 07h, 02h, 0Eh, 02h, 0Ch, 04h, 01h
    07h, 0Ah, 0Bh, 06h, 08h, 05h, 03h, 0Fh, 0Dh, 00h
    0Eh, 09h, 0Eh, 0Bh, 02h, 0Ch, 04h, 07h, 0Dh, 01h
    05h, 00h, 0Fh, 0Ah, 03h, 09h, 08h, 06h, 04h, 02h
    01h, 0Bh, 0Ah, 0Dh, 07h, 08h, 0Fh, 09h, 0Ch, 05h
    06h, 03h, 00h, 0Eh, 0Bh, 08h, 0Ch, 07h, 01h, 0Eh
    02h, 0Dh, 06h, 0Fh, 00h, 09h, 0Ah, 04h, 05h, 03h
    0Ch, 01h, 0Ah, 0Fh, 09h, 02h, 06h, 08h, 00h, 0Dh
    03h, 04h, 0Eh, 07h, 05h, 0Bh, 0Ah, 0Fh, 04h, 02h
    07h, 0Ch, 09h, 05h, 06h, 01h, 0Dh, 0Eh, 00h, 0Bh
    03h, 08h, 09h, 0Eh, 0Fh, 05h, 02h, 08h, 0Ch, 03h
    07h, 00h, 04h, 0Ah, 01h, 0Dh, 0Bh, 06h, 04h, 03h
    02h, 0Ch, 09h, 05h, 0Fh, 0Ah, 0Bh, 0Eh, 01h, 07h
    06h, 00h, 08h, 0Dh, 04h, 0Bh, 02h, 0Eh, 0Fh, 00h
    08h, 0Dh, 03h, 0Ch, 09h, 07h, 05h, 0Ah, 06h, 01h
    0Dh, 00h, 0Bh, 07h, 04h, 09h, 01h, 0Ah, 0Eh, 03h
    05h, 0Ch, 02h, 0Fh, 08h, 06h, 01h, 04h, 0Bh, 0Dh
    0Ch, 03h, 07h, 0Eh, 0Ah, 0Fh, 06h, 08h, 00h, 05h
    09h, 02h, 06h, 0Bh, 0Dh, 08h, 01h, 04h, 0Ah, 07h
    09h, 05h, 00h, 0Fh, 0Eh, 02h, 03h, 0Ch, 0Dh, 02h
    08h, 04h, 06h, 0Fh, 0Bh, 01h, 0Ah, 09h, 03h, 0Eh
    05h, 00h, 0Ch, 07h, 01h, 0Fh, 0Dh, 08h, 0Ah, 03h
    07h, 04h, 0Ch, 05h, 06h, 0Bh, 00h, 0Eh, 09h, 02h
    07h, 0Bh, 04h, 01h, 09h, 0Ch, 0Eh, 02h, 00h, 06h
    0Ah, 0Dh, 0Fh, 03h, 05h, 08h, 02h, 01h, 0Eh, 07h
    04h, 0Ah, 08h, 0Dh, 0Fh, 0Ch, 09h, 00h, 03h, 05h
    06h, 0Bh
};

BYTE addr6[16384];

BYTE subsub(int v1, int v2)
{
    return data6[((v2 >> 4 & 2 | v2 & 1) + v1 * 4) << 4 + v2 >> 1 & 0xf];
}

void sub3(void)
{
    int edi, esi;
    BYTE* ptr;

    for (ptr = addr6, edi = 0; ptr < addr6 + sizeof(addr6); edi++, ptr += 4096)
        for (esi = 0; esi < 4096; esi++)
            ptr[esi] = subsub(edi, esi / 64) | subsub(edi + 1, esi & 0x3f);
}

void sub(char* str)
{
    sub1(add1, data1);
    sub1(add2, data2);
    sub2(str);
    sub3();
}

void InitVariables()
{
    sub("ftp&http");
}

BOOL (*pfnInternetGetCookie)(
    LPCTSTR lpszUrlName,
    LPCTSTR lpszCookieName,
    LPTSTR lpszCookieData,
    LPDWORD lpdwSize
);

BOOL GetInternetGetCookieFunc(void)
{
    HMODULE hModule = LoadLibrary("WININET.DLL");

    if (hModule == NULL) return FALSE;

    if ((pfnInternetGetCookie = GetProcAddress(hModule, "InternetGetCookie")) == NULL) {
        FreeLibrary(hModule);
        return FALSE;
    }

    return TRUE;
}

void InitCookie(void)
{
    gbIsInternetGetCookieFuncAvail = GetInternetGetCookieFunc();
    gbVal = GetRegVals();
}
       
int WinMain(HINSTANCE hInst,HINSTANCE hPreInst,LPSTR lpszCmdLine,int nCmdShow)
{
    HANDLE hEvent;
    WNDCLASS wc;
    MSG Msg;
    char WindowName[116];

    ghInstance = hInst;
    GetModuleFileName(hInst, ModuleDir, MAX_PATH);
    *(GetModuleName(ModuleDir) - 1) = '\0';

    // Get all available languages and set the one specified by registration
    InitLanguage();
   
    // Get OEM Title, Website, Splash from LKCU\NetAnt\OEM
    GetOemData();

    hInst = LoadLibrary("comctl32.dll");

    if ((pf = GetProcAddress(hInst, "DllGetVersion")) == 0) {
        ShowErrorMsg("Load comctl32.dll error");
        exit(0);
    }

    memset(version, 0, sizeof(version));
    pf(version);
    if (versin.main < 4 || version.minor < 72) {
        ShowErrorMsg("low comctl32 version");
        exit(0);
    }

    pf = GetProcAddress(hInst, InitCommonControlsEx);
    pf();

    GetVersionEx(osv);
    IsWin9598Nt =    osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
                    osvi.dwMajorVersion == 4;

    IsSimplifiedChinese = GetSystemDefaultLangID() == 0x804;

    // If an instance is already runing, show the instance and quit
    if (IsWindow(hWnd = FindWindow("NA_MainWin", 0))) {
        while (!PostMessage(hWnd, WM_COMMAND, IDM_SHOWMAINWINDOW /*0x9c58*/, 0);
        return 0;
    }

    ShowSplashWindow();

    hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE/*bInheritHandle*/, "NetAnts_Running");
    if (!hEvent) {
        hEvent = CreateEvent(0, TRUE/*ManualReset*/, 0/*InitialState*/, "NetAnts_Running");
        if (hEvent == 0) {
            ShowErrMsg("CreateEvent");
            return 0;
        }
    }

    if (!NetInit()) {
        CloseHandle(hEvent);
        return -1;
    }

    InitSNMP();
    InitRAS();

    if (OleInitialize(0)) {
        ShowErrMsg("OleInitialize");
        OleUninitialize();
    }

    InitVariables();
    InitCookie();
    InitImageList();

    wc.s tyle = WS_OVERLAPPEDWINDOW;
    wc.lpfnWndProc = MainWinProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = ghInstance;
    wc.hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_MAIN));
    wc.hCursor = LoadCursor(0, IDC_ARROW);
    wc.hbrBack





地主 发表时间: 04-06-25 03:49

回复: www [wish259]   论坛用户   登录
哪整的?

B1层 发表时间: 04-06-25 11:08

回复: bailove [bailove]   论坛用户   登录
想研究...还真要费一大工夫.

B2层 发表时间: 04-06-25 12:08

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号