static int SaveDialog(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    HWND hCombo = GetDlgItem(hDlg, IDC_CREATE_DISPOSITION);
    int nError;

    GetDlgItemText(hDlg, IDC_DIRECTORY_NAME, pData->szDirName, _maxchars(pData->szDirName));
    GetDlgItemText(hDlg, IDC_FILE_NAME, pData->szFileName1, _maxchars(pData->szFileName1));

    if((nError = DlgText2Hex32(hDlg, IDC_OBJ_ATTR_FLAGS, &pData->dwObjAttrFlags)) != ERROR_SUCCESS)
        return nError;
    if((nError = DlgText2Hex32(hDlg, IDC_DESIRED_ACCESS, &pData->dwDesiredAccess)) != ERROR_SUCCESS)
        return nError;
    if((nError = DlgText2Hex32(hDlg, IDC_FILE_ATTRIBUTES, &pData->dwFileAttributes)) != ERROR_SUCCESS)
        return nError;
    if((nError = DlgText2Hex32(hDlg, IDC_SHARE_ACCESS, &pData->dwShareAccess)) != ERROR_SUCCESS)
        return nError;
    if((nError = DlgText2Hex32(hDlg, IDC_CREATE_OPTIONS, &pData->dwCreateOptions)) != ERROR_SUCCESS)
        return nError;
    if((nError = DlgText2Hex64(hDlg, IDC_ALLOCATION_SIZE, &pData->AllocationSize)) != ERROR_SUCCESS)
        return nError;

    pData->dwCreateDisposition2 = ComboBox_GetCurSel(hCombo);
    pData->bUseTransaction      = (IsDlgButtonChecked(hDlg, IDC_TRANSACTED) == BST_CHECKED);
    return ERROR_SUCCESS;
}
Exemple #2
0
// Try to recognize the AM/PM string
static BOOL AmPmNameToWord(LPCTSTR szStr, WORD & wHourModifier, int & nAmPmNameLength)
{
    TCHAR szAmPmStr[10];
    int nLength;

    // Check AM
    nLength = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_S1159, szAmPmStr, _maxchars(szAmPmStr));
    if(nLength > 0 && szStr[0] == szAmPmStr[0])
    {
        nAmPmNameLength = nLength;
        wHourModifier = 0;
        return TRUE;
    }

    // Check PM
    nLength = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_S2359, szAmPmStr, _maxchars(szAmPmStr));
    if(nLength > 0 && szStr[0] == szAmPmStr[0])
    {
        nAmPmNameLength = nLength;
        wHourModifier = 12;
        return TRUE;
    }

    // Not recognized
    return FALSE;
}
static int SaveDialog(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);

    if((pData->dwCreateOptions & FILE_OPEN_BY_FILE_ID) == 0)
        GetDlgItemText(hDlg, IDC_FILE_NAME1, pData->szFileName1, _maxchars(pData->szFileName1));
    GetDlgItemText(hDlg, IDC_FILE_NAME2, pData->szFileName2, _maxchars(pData->szFileName2));
    return ERROR_SUCCESS;
}
static int OnRelativeFileHelp(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    LPTSTR szBuffer;
    TCHAR szDesiredAccess[0x100];
    TCHAR szShareAccess[0x100];
    TCHAR szOpenOptions[0x100];
    TCHAR szMsgFormat[512];
    size_t cchBuffer = 0x1000;
    int nLength = 0;

    // Load both parts of the message
    nLength = LoadString(g_hInst, IDS_RELATIVE_FILE_HELP, szMsgFormat, _maxchars(szMsgFormat));
    if(nLength > 0)
    {
        // Allocate big buffer for the entire text
        szBuffer = new TCHAR[cchBuffer];
        if(szBuffer != NULL)
        {
            // Format the result string
            StringCchPrintf(szBuffer, cchBuffer, szMsgFormat,
                            pData->dwDesiredAccessRF, FlagsToString(DesiredAccessValues, szDesiredAccess, _countof(szDesiredAccess), pData->dwDesiredAccessRF, false),
                            pData->dwShareAccessRF,   FlagsToString(ShareAccessValues,   szShareAccess, _countof(szShareAccess), pData->dwShareAccessRF, false),
                            pData->dwOpenOptionsRF,   FlagsToString(CreateOptionsValues, szOpenOptions, _countof(szOpenOptions), pData->dwOpenOptionsRF, false));

            // Display the message box
            MessageBoxRc(hDlg, IDS_INFO, (UINT_PTR)szBuffer);
            delete [] szBuffer;
        }
    }
    return TRUE;
}
static int OnCopyFileClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    int nError;

    // Get the source and target file
    GetDlgItemText(hDlg, IDC_FILE_NAME1, pData->szFileName1, _maxchars(pData->szFileName1));
    GetDlgItemText(hDlg, IDC_FILE_NAME2, pData->szFileName2, _maxchars(pData->szFileName2));

    // Run the copy file dialog
    nError = (int)CopyFileDialog(hDlg, pData);

    // Set the result
    SetResultInfo(hDlg, nError);
    return TRUE;
}
Exemple #6
0
static WORD LocaleNameToNumber(LPCTSTR szStr, LCID lcMin, LCID lcMax, LCID lcExtra, int * piNameLength)
{
    TCHAR szLocaleName[80];
    LCID lcid;
    int nLength;

    // Set the length to zero as default
    *piNameLength = 0;

    // We have to go from December downto January. THe reason behind this
    // is that we might confuse "1" with "10".
    for(lcid = lcMax; lcid >= lcMin; lcid--)
    {
        // Get the localized month name
        nLength = GetLocaleInfo(LOCALE_USER_DEFAULT, lcid, szLocaleName, _maxchars(szLocaleName));
        if(nLength == 0)
            break;

        // If the month name is identical, we found it
        if(!_tcsnicmp(szStr, szLocaleName, (nLength - 1)))
        {
            *piNameLength = (nLength - 1);
            return (WORD)(lcid - lcMin + 1);
        }
    }

    // Last chance: check extra locale (for example, 13th month name)
    if(lcExtra != 0)
    {
        // Get the localized 13th month name
        nLength = GetLocaleInfo(LOCALE_USER_DEFAULT, lcExtra, szLocaleName, _maxchars(szLocaleName));
        if(nLength > 1)
        {
            // If the month name is identical, we found it
            if(!_tcsnicmp(szStr, szLocaleName, (nLength - 1)))
            {
                *piNameLength = (nLength - 1);
                return 13;
            }
        }
    }

    // Invalid or unrecognized locale name
    return 0xFFFF;
}
static int OnFileIdUse(HWND hDlg, UINT nIDEdit)
{
    TCHAR szFileId[0x100] = _T("");

    // Retrieve the file ID or object ID from the edit box
    GetDlgItemText(hDlg, nIDEdit, szFileId, _maxchars(szFileId));
    NtUseFileId(hDlg, szFileId);
    return TRUE;
}    
static int OnEditEaClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    TCHAR szEaInfo[128];

    // Invoke the editor of the extended attributes
    if(ExtendedAtributesEditorDialog(hDlg, pData) == IDOK)
    {
        // Update the info about extended attributes
        rsprintf(szEaInfo, _maxchars(szEaInfo), IDS_EA_INFO, pData->pFileEa, pData->dwEaSize);
        SetDlgItemText(hDlg, IDC_EXTENDED_ATTRIBUTES, szEaInfo);
    }

    return TRUE;
}
static void GetFileTestAppTitle(LPTSTR szTitle, int nMaxChars)
{
    TCHAR szUserName[256] = _T("");
    DWORD dwSize = _maxchars(szUserName);
    UINT nIDTitle = IDS_APP_TITLE;
    BOOL bElevated = FALSE;

    // Get the elevation flags. Note that this returns FALSE on pre-Vista
    if(GetTokenElevation(&bElevated))
    {
        nIDTitle = bElevated ? IDS_APP_TITLE_VISTA1 : IDS_APP_TITLE_VISTA2;
    }

    GetUserName(szUserName, &dwSize);
    rsprintf(szTitle, nMaxChars, nIDTitle, szUserName);
}
Exemple #10
0
static int ParseAgentFile(TCascStorage * hs, void * pvListFile)
{
    const char * szLinePtr;
    const char * szLineEnd;
    char szOneLine[0x200];
    size_t nLength;
    int nError;

    // Load the single line from the text file
    nLength = ListFile_GetNextLine(pvListFile, szOneLine, _maxchars(szOneLine));
    if(nLength == 0)
        return ERROR_BAD_FORMAT;

    // Set the line range
    szLinePtr = szOneLine;
    szLineEnd = szOneLine + nLength;

    // Extract the CDN build key
    nError = LoadInfoVariable(&hs->CdnBuildKey, szLinePtr, szLineEnd, true);
    if(nError == ERROR_SUCCESS)
    {
        // Skip the variable
        szLinePtr = SkipInfoVariable(szLinePtr, szLineEnd);

        // Load the CDN config hash
        nError = LoadInfoVariable(&hs->CdnConfigKey, szLinePtr, szLineEnd, true);
        if(nError == ERROR_SUCCESS)
        {
            // Skip the variable
            szLinePtr = SkipInfoVariable(szLinePtr, szLineEnd);

            // Skip the Locale/OS/code variable
            szLinePtr = SkipInfoVariable(szLinePtr, szLineEnd);

            // Load the URL
            hs->szUrlPath = CascNewStrFromAnsi(szLinePtr, szLineEnd);
            if(hs->szUrlPath == NULL)
                nError = ERROR_NOT_ENOUGH_MEMORY;
        }
    }

    // Verify all variables
    if(hs->CdnBuildKey.pbData == NULL || hs->CdnConfigKey.pbData == NULL || hs->szUrlPath == NULL)
        nError = ERROR_BAD_FORMAT;
    return nError;
}
Exemple #11
0
static void SetWindowModuleVersion(HWND hWndChild, LPCTSTR szModuleName)
{
    LARGE_INTEGER Version;
    TCHAR szFormat[255];
    TCHAR szText[255];

    // Is such window really there ?
    if(hWndChild != NULL)
    {
        GetWindowText(hWndChild, szFormat, _maxchars(szFormat));
        GetModuleVersion(szModuleName, &Version);
        StringCchPrintf(szText, _countof(szText), szFormat,
                                                  HIWORD(Version.HighPart),
                                                  LOWORD(Version.HighPart),
                                                  HIWORD(Version.LowPart),
                                                  LOWORD(Version.LowPart));
        SetWindowText(hWndChild, szText);
    }
}
Exemple #12
0
static int OnSetActive(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    TCHAR szEaInfo[128];
    BOOL bEnabled;
    int nChecked;

    // Set directory name and file name
    SetDlgItemText(hDlg, IDC_DIRECTORY_NAME, pData->szDirName);
    SetDlgItemText(hDlg, IDC_FILE_NAME, pData->szFileName1);

    // Convert both to NT name.
    if(GetWindowTextLength(GetDlgItem(hDlg, IDC_DIRECTORY_NAME)) == 0)
        ConvertToNtName(hDlg, IDC_FILE_NAME);
    ConvertToNtName(hDlg, IDC_DIRECTORY_NAME);

    // Set the various create options
    Hex2DlgText32(hDlg, IDC_OBJ_ATTR_FLAGS, pData->dwObjAttrFlags);
    Hex2DlgText32(hDlg, IDC_DESIRED_ACCESS, pData->dwDesiredAccess);
    Hex2DlgText64(hDlg, IDC_ALLOCATION_SIZE, pData->AllocationSize);
    Hex2DlgText32(hDlg, IDC_FILE_ATTRIBUTES, pData->dwFileAttributes);
    Hex2DlgText32(hDlg, IDC_SHARE_ACCESS, pData->dwShareAccess);
    Hex2DlgText32(hDlg, IDC_CREATE_OPTIONS, pData->dwCreateOptions);

    // Update the info about extended attributes
    rsprintf(szEaInfo, _maxchars(szEaInfo), IDS_EA_INFO, pData->pFileEa, pData->dwEaSize);
    SetDlgItemText(hDlg, IDC_EXTENDED_ATTRIBUTES, szEaInfo);

    // Enable/disable transaction
    bEnabled = (pfnRtlSetCurrentTransaction != NULL && IsHandleValid(pData->hTransaction));
    EnableDlgItems(hDlg, bEnabled, IDC_TRANSACTED, 0);
    nChecked = (bEnabled && pData->bUseTransaction) ? BST_CHECKED : BST_UNCHECKED;
    CheckDlgButton(hDlg, IDC_TRANSACTED, nChecked);

    // Check/uncheck virtualization
    nChecked = (GetTokenVirtualizationEnabled(&bEnabled) && bEnabled) ? BST_CHECKED : BST_UNCHECKED;
    CheckDlgButton(hDlg, IDC_VIRTUALIZATION, nChecked);

    // Enable/disable "NtClose"
    bEnabled = IsHandleValid(pData->hFile) ? TRUE : FALSE;
    EnableDlgItems(hDlg, bEnabled, IDC_CLOSE_HANDLE, 0);
    return TRUE;
}
BOOL TToolTip::AddToolTipInternal(HWND hDlg, UINT nIDCtrl, LPCTSTR szTip, LPARAM lParam)
{
    TTTOOLINFO ti;
    TCHAR szClassName[0x80];
    DWORD dwStyle;
    HWND hWndChild;
    BOOL bResult = FALSE;

    // Only if we actually have a tooltip
    if(hWndToolTip != NULL)
    {
        // If the child window is not valid, do nothing
        hWndChild = GetDlgItem(hDlg, nIDCtrl);
        if(hWndChild != NULL)
        {
            // If the child window is a static text without SS_NOTIFY,
            // the tooltip would not activate. We need to set the SS_NOTIFY flag
            GetClassName(hWndChild, szClassName, _maxchars(szClassName));
            if(!_tcsicmp(szClassName, WC_STATIC))
            {
                dwStyle = GetWindowLong(hWndChild, GWL_STYLE);
                if((dwStyle & SS_NOTIFY) == 0)
                    SetWindowLong(hWndChild, GWL_STYLE, dwStyle | SS_NOTIFY);
            }

            // Note: Make sure we put the size for COMCTL32.dll version 4.70
            ZeroMemory(&ti, sizeof(TTTOOLINFO));
            ti.cbSize   = CCSIZEOF_STRUCT(TTTOOLINFO, lParam);
            ti.uFlags   = TTF_IDISHWND | TTF_SUBCLASS;
            ti.hwnd     = hDlg;
            ti.uId      = (UINT_PTR)hWndChild;
            ti.hinst    = g_hInst;
            ti.lpszText = (LPTSTR)szTip;
            ti.lParam   = lParam;
            bResult = (BOOL)SendMessage(hWndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
        }
    }

    return bResult;
}
static void AddAboutToSystemMenu(HWND hDlg)
{
    MENUITEMINFO mii;
    HMENU hSysMenu;
    TCHAR szItemText[256];
    int nSeparatorIndex = -1;
    int nMenuCount;

    // Retrieve system menu
    hSysMenu = GetSystemMenu(hDlg, FALSE);
    if(hSysMenu != NULL)
    {
        // Find the separator
        nMenuCount = GetMenuItemCount(hSysMenu);
        for(int i = 0; i < nMenuCount; i++)
        {
            // Retrieve the item type
            ZeroMemory(&mii, sizeof(MENUITEMINFO));
            mii.cbSize = sizeof(MENUITEMINFO);
            mii.fMask = MIIM_FTYPE;
            GetMenuItemInfo(hSysMenu, i, TRUE, &mii);

            // Separator?
            if(mii.fType == MFT_SEPARATOR)
            {
                nSeparatorIndex = i;
                break;
            }
        }

        // If we found a separator, we need to add two more items
        if(nSeparatorIndex != -1)
        {
            LoadString(g_hInst, IDS_HELP_ABOUT, szItemText, _maxchars(szItemText));
            InsertMenu(hSysMenu, nSeparatorIndex, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
            InsertMenu(hSysMenu, nSeparatorIndex+1, MF_BYPOSITION | MF_STRING, SC_HELP_ABOUT, szItemText);
        }
    }
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int)
{
    TFileTestData * pData;
    DWORD dwDesiredAccess = GENERIC_READ;
    DWORD dwShareAccess = FILE_SHARE_READ;
    DWORD dwCopyFileFlags = 0;
    DWORD dwMoveFileFlags = 0;
    bool bAsynchronousOpen = false;
    int nFileNameIndex = 0;

    // Save the instance
    g_hInst = hInstance;
    g_hHeap = GetProcessHeap();
    InitCommonControls();

    // Get the Windows version
    g_dwWinVer = GetWindowsVersion();

    // Allocate and fill our working structure with command line parameters
    pData = (TFileTestData *)HeapAlloc(g_hHeap, HEAP_ZERO_MEMORY, sizeof(TFileTestData));

    // Parse command line arguments
    for(int i = 1; i < __argc; i++)
    {
        // If the argument a file name?
        if(!IsCommandSwitch(__targv[i]))
        {
            switch(nFileNameIndex)
            {
                case 0: // The first file name argument
                    StringCchCopy(pData->szFileName1, _countof(pData->szFileName1), __targv[i]);
                    nFileNameIndex++;
                    break;

                case 1: // The second file name argument
                    StringCchCopy(pData->szFileName2, _countof(pData->szFileName2), __targv[i]);
                    nFileNameIndex++;
                    break;

                case 2: // The directory file name argument
                    StringCchCopy(pData->szDirName, _countof(pData->szFileName2), __targv[i]);
                    nFileNameIndex++;
                    break;
            }
        }
        else
        {
            LPCTSTR szArg = __targv[i] + 1;

            // Check for default read+write access
            if(!_tcsnicmp(szArg, _T("DesiredAccess:"), 14))
                Text2Hex32(szArg+14, &dwDesiredAccess);
            
            // Check for default share read+write
            if(!_tcsnicmp(szArg, _T("ShareAccess:"), 12))
                Text2Hex32(szArg+12, &dwShareAccess);

            if(!_tcsnicmp(szArg, _T("CopyFileFlags:"), 14))
                Text2Hex32(szArg+14, &dwCopyFileFlags);

            if(!_tcsnicmp(szArg, _T("MoveFileFlags:"), 14))
                Text2Hex32(szArg+14, &dwMoveFileFlags);

            // Check for asynchronous open
            if(!_tcsnicmp(szArg, _T("AsyncOpen:"), 10))
                Text2Bool(szArg+10, &bAsynchronousOpen);
        }
    }

    // Set default file name
    if(pData->szFileName1[0] == 0)
        StringCchCopy(pData->szFileName1, _countof(pData->szFileName1), _T("C:\\TestFile.bin"));

    //
    // DEVELOPMENT CODE: Build the NT status table from the NTSTATUS.h
    //

//  BuildNtStatusTableFromNTSTATUS_H();
//  VerifyNtStatusTable();

    //
    // Resolve the dynamic loaded APIs
    //

    ResolveDynamicLoadedAPIs();

    //
    // On Vista or newer, set the required integrity level of our token object
    // to lowest possible value. This will allow us to open our token even if the user
    // lowers the integrity level.
    //
    
    SetTokenObjectIntegrityLevel(SECURITY_MANDATORY_UNTRUSTED_RID);

    //
    // Save the application initial directory
    //

    GetCurrentDirectory(_maxchars(g_szInitialDirectory), g_szInitialDirectory);

    //
    // Register the data editor window
    //

    RegisterDataEditor(hInstance);

    //
    // To make handles obtained by NtCreateFile usable for calling ReadFile and WriteFile,
    // we have to set the FILE_SYNCHRONOUS_IO_NONALERT into CreateOptions
    // and SYNCHRONIZE into DesiredAccess.
    //

    // Allocate default size for the FileInfo.
    pData->pbNtInfoBuff = (LPBYTE)HeapAlloc(g_hHeap, HEAP_ZERO_MEMORY, INITIAL_FILEINFO_BUFFER_SIZE);
    pData->cbNtInfoBuff = INITIAL_FILEINFO_BUFFER_SIZE;

    // Set default values for opening relative file by NtOpenFile
    pData->dwDesiredAccessRF     = FILE_READ_DATA;
    pData->dwOpenOptionsRF       = 0;
    pData->dwShareAccessRF       = FILE_SHARE_READ | FILE_SHARE_WRITE;

    // Set default values for CreateFile and NtCreateFile
    pData->dwCreateDisposition1  = OPEN_ALWAYS;
    pData->dwCreateDisposition2  = FILE_OPEN_IF;
    pData->dwDesiredAccess       = dwDesiredAccess;
    pData->dwFileAttributes      = FILE_ATTRIBUTE_NORMAL;
    pData->dwShareAccess         = dwShareAccess;
    pData->dwCreateOptions       = 0;
    pData->dwObjAttrFlags        = OBJ_CASE_INSENSITIVE;
    pData->dwMoveFileFlags       = MOVEFILE_COPY_ALLOWED;
    pData->dwOplockLevel         = OPLOCK_LEVEL_CACHE_READ | OPLOCK_LEVEL_CACHE_WRITE;
    pData->dwCopyFileFlags       = dwCopyFileFlags;
    pData->dwMoveFileFlags       = dwMoveFileFlags;

    // Modify for synchronous open, if required
    if(bAsynchronousOpen == false)
    {
        pData->dwCreateOptions |= FILE_SYNCHRONOUS_IO_NONALERT;
        pData->dwDesiredAccess |= SYNCHRONIZE;
    }

    // Set default values for NtCreateSection/NtOpenSection
    pData->dwSectDesiredAccess   = SECTION_MAP_READ;
    pData->dwSectPageProtection  = PAGE_READONLY;
    pData->dwSectAllocAttributes = SEC_COMMIT;
    pData->dwSectWin32Protect    = PAGE_READONLY;

    // Call the dialog
    FileTestDialog(NULL, pData);

    // Cleanup the TFileTestData structure and exit
    if(pData->pFileEa != NULL)
        delete [] pData->pFileEa;
    if(pData->pbFileData != NULL)
        VirtualFree(pData->pbFileData, pData->cbFileDataMax, MEM_RELEASE);
    if(pData->pbNtInfoBuff != NULL)
        HeapFree(g_hHeap, 0, pData->pbNtInfoBuff);
    HeapFree(g_hHeap, 0, pData);

    UnloadDynamicLoadedAPIs();
    return 0;
}
Exemple #16
0
static int ParseInfoFile(TCascStorage * hs, void * pvListFile)
{
    QUERY_KEY Active = {NULL, 0};
    QUERY_KEY TagString = {NULL, 0};
    QUERY_KEY CdnHost = {NULL, 0};
    QUERY_KEY CdnPath = {NULL, 0};
    char szOneLine1[0x200];
    char szOneLine2[0x200];
    size_t nLength1;
    size_t nLength2;
    int nError = ERROR_BAD_FORMAT;

    // Extract the first line, cotaining the headers
    nLength1 = ListFile_GetNextLine(pvListFile, szOneLine1, _maxchars(szOneLine1));
    if(nLength1 == 0)
        return ERROR_BAD_FORMAT;

    // Now parse the second and the next lines. We are looking for line
    // with "Active" set to 1
    for(;;)
    {
        const char * szLinePtr1 = szOneLine1;
        const char * szLineEnd1 = szOneLine1 + nLength1;
        const char * szLinePtr2 = szOneLine2;
        const char * szLineEnd2;

        // Read the next line
        nLength2 = ListFile_GetNextLine(pvListFile, szOneLine2, _maxchars(szOneLine2));
        if(nLength2 == 0)
            break;
        szLineEnd2 = szLinePtr2 + nLength2;

        // Parse all variables
        while(szLinePtr1 < szLineEnd1)
        {
            // Check for variables we need
            if(IsInfoVariable(szLinePtr1, szLineEnd1, "Active", "DEC"))
                LoadInfoVariable(&Active, szLinePtr2, szLineEnd2, false);
            if(IsInfoVariable(szLinePtr1, szLineEnd1, "Build Key", "HEX"))
                LoadInfoVariable(&hs->CdnBuildKey, szLinePtr2, szLineEnd2, true);
            if(IsInfoVariable(szLinePtr1, szLineEnd1, "CDN Key", "HEX"))
                LoadInfoVariable(&hs->CdnConfigKey, szLinePtr2, szLineEnd2, true);
            if(IsInfoVariable(szLinePtr1, szLineEnd1, "CDN Hosts", "STRING"))
                LoadInfoVariable(&CdnHost, szLinePtr2, szLineEnd2, false);
            if(IsInfoVariable(szLinePtr1, szLineEnd1, "CDN Path", "STRING"))
                LoadInfoVariable(&CdnPath, szLinePtr2, szLineEnd2, false);
            if(IsInfoVariable(szLinePtr1, szLineEnd1, "Tags", "STRING"))
                LoadInfoVariable(&TagString, szLinePtr2, szLineEnd2, false);

            // Move both line pointers
            szLinePtr1 = SkipInfoVariable(szLinePtr1, szLineEnd1);
            if(szLinePtr1 == NULL)
                break;

            szLinePtr2 = SkipInfoVariable(szLinePtr2, szLineEnd2);
            if(szLinePtr2 == NULL)
                break;
        }

        // Stop parsing if found active config
        if(Active.pbData != NULL && *Active.pbData == '1')
            break;

        // Free the blobs
        FreeCascBlob(&CdnHost);
        FreeCascBlob(&CdnPath);
        FreeCascBlob(&TagString);
    }

    // All four must be present
    if(hs->CdnBuildKey.pbData != NULL &&
       hs->CdnConfigKey.pbData != NULL &&
       CdnHost.pbData != NULL &&
       CdnPath.pbData != NULL)
    {
        // Merge the CDN host and CDN path
        hs->szUrlPath = CASC_ALLOC(TCHAR, CdnHost.cbData + CdnPath.cbData + 1);
        if(hs->szUrlPath != NULL)
        {
            CopyString(hs->szUrlPath, (char *)CdnHost.pbData, CdnHost.cbData);
            CopyString(hs->szUrlPath + CdnHost.cbData, (char *)CdnPath.pbData, CdnPath.cbData);
            nError = ERROR_SUCCESS;
        }
    }

    // If we found tags, we can extract language build from it
    if(TagString.pbData != NULL)
        GetDefaultLocaleMask(hs, &TagString);

    FreeCascBlob(&CdnHost);
    FreeCascBlob(&CdnPath);
    FreeCascBlob(&TagString);
    FreeCascBlob(&Active);
    return nError;
}
static int OnObjectIdMoreClick(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    FILE_OBJECTID_BUFFER ObjId = {0};
    UINT_PTR nAction;
    HANDLE hFile = INVALID_HANDLE_VALUE;
    TCHAR szObjectID[0x40];
    DWORD dwFlagsAndAttributes = 0;
    DWORD dwDesiredAccess = FILE_READ_ATTRIBUTES;
    DWORD dwBytesReturned;
    DWORD dwIoctlCode = FSCTL_CREATE_OR_GET_OBJECT_ID;
    int nError = ERROR_SUCCESS;

    // Ask the user for the action
    nAction = ObjectIDActionDialog(hDlg);
    if(nAction == IDCANCEL)
        return TRUE;
    SaveDialog(hDlg);
    
    // Use the proper desired access
    // Note that we also need restore privilege in order to succeed
    if(nAction == IDC_SET_OBJECT_ID)
    {
        dwFlagsAndAttributes = FILE_FLAG_BACKUP_SEMANTICS;
        dwDesiredAccess = FILE_WRITE_DATA;
    }

    // Convert the file name to the NT file name
    hFile = CreateFile(pData->szFileName1, dwDesiredAccess, 0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
    if(hFile == INVALID_HANDLE_VALUE)
        nError = GetLastError();

    // Perform an action specific to 
    if(nError == ERROR_SUCCESS)
    {
        switch(nAction)
        {
            case IDC_CREATE_OR_GET:
            case IDC_GET_OBJECT_ID:

                if(nAction == IDC_GET_OBJECT_ID)
                    dwIoctlCode = FSCTL_GET_OBJECT_ID;

                memset(&ObjId, 0, sizeof(FILE_OBJECTID_BUFFER));
                if(DeviceIoControl(hFile, dwIoctlCode,
                                          NULL,
                                          0,
                                         &ObjId,
                                          sizeof(FILE_OBJECTID_BUFFER),
                                         &dwBytesReturned,
                                          NULL))
                {
                    ObjectIDToString(ObjId.ObjectId, pData->szFileName1, szObjectID);
                    SetDlgItemText(hDlg, IDC_OBJECT_ID, szObjectID);
                }
                else
                {
                    nError = GetLastError();
                }
                break;
            
            case IDC_SET_OBJECT_ID:

                GetDlgItemText(hDlg, IDC_OBJECT_ID, szObjectID, _maxchars(szObjectID));
                nError = StringToFileID(szObjectID, NULL, ObjId.ObjectId, NULL);
                if(nError != ERROR_SUCCESS)
                    break;

                if(!DeviceIoControl(hFile, FSCTL_SET_OBJECT_ID,
                                          &ObjId,
                                           sizeof(FILE_OBJECTID_BUFFER),
                                           NULL,
                                           0,
                                          &dwBytesReturned,
                                           NULL))
                {
                    nError = GetLastError();
                }
                break;
        }
    }

    if(hFile != INVALID_HANDLE_VALUE)
        CloseHandle(hFile);
    SetResultInfo(hDlg, nError);
    return TRUE;
}
Exemple #18
0
// Converts locale-specific month name to month number
// Only converts genitives
static WORD MonthNameGenitiveToNumber(LPCTSTR szStr, int * piMonthNameLength)
{
    SYSTEMTIME stTemp = {0};
    TCHAR szMonthName[80];
    int nLength;

    // Prepare the temporary SYSTEMTIME structure
    // Note: The recommended way to get month name as genitive is to use GetDateFormat
    // with "ddMMMM" and compare month name starting at second position
    stTemp.wDay = 1;
    stTemp.wYear = 2000;

    // Go through all month names.
    for(stTemp.wMonth = 1; stTemp.wMonth <= 13; stTemp.wMonth++)
    {
        // Get genitive of month name
        nLength = GetDateFormat(LOCALE_USER_DEFAULT, 0, &stTemp, _T("ddMMMM"), szMonthName, _maxchars(szMonthName));
        if(nLength < 3)
            break;

        // Compare the month name
        if(!_tcsnicmp(szStr, &szMonthName[2], nLength - 3))
        {
            *piMonthNameLength = (nLength - 3);
            return stTemp.wMonth;
        }
    }

    // Month name genitive not recognized
    return 0xFFFF;
}
Exemple #19
0
// Arranging the dialog layout for empty dialogs, where the controls need to be created
static void CreateDialogLayout_Empty(TFlagDialogData * pData)
{
    TFlagInfo * pFlags;
    HWND hWndGroup = GetDlgItem(pData->hDlg, IDC_GROUPBOX);
    HWND hWndFirst = GetDlgItem(pData->hDlg, IDC_CHILD_MUSTER);
    HWND hWndChild = hWndFirst;
    RECT DialogRect;                        // Rectangle of the dialog (screen-relative)
    RECT ParentRect;                        // Rectangle of the dialog's parent (screen-relative)
    RECT ClientRect;                        // Rectangle of the dialog client area (screen-relative)
    RECT GroupRect;                         // Rectangle of the group box
    RECT CheckBoxRect;                      // Rectangle of the checkbox
    DWORD dwFlags = pData->dwFlags;
    int nChecked = BST_UNCHECKED;
    int x, y, cx, cy;

    // Get the size of the parent
    if(pData->hWndParent != NULL)
        GetWindowRect(pData->hWndParent, &ParentRect);
    else
        SystemParametersInfo(SPI_GETWORKAREA, 0, &ParentRect, FALSE);

    // Set the dialog title
    SetWindowTextRc(pData->hDlg, pData->nIDTitle);

    // Get the size of the dialog and the "master" settings
    GetWindowRect(pData->hDlg, &DialogRect);
    GetClientRect(pData->hDlg, &ClientRect);
    pData->hFont = (HFONT)SendMessage(hWndChild, WM_GETFONT, 0, 0);

    // Get the position of the groupbox and the child muster
    GetWindowRect(hWndGroup, &GroupRect);
    ScreenRectToClientRect(pData->hDlg, &GroupRect);
    
    GetWindowRect(hWndChild, &CheckBoxRect);
    ScreenRectToClientRect(pData->hDlg, &CheckBoxRect);

    // Get the settings of the "master" checkbox
    pData->dwExStyle = GetWindowLong(hWndChild, GWL_EXSTYLE);
    pData->dwStyle = GetWindowLong(hWndChild, GWL_STYLE) & ~(WS_TABSTOP | WS_GROUP);

    // Create all switch items
    for(pFlags = pData->pFlags; pFlags->szFlagText != NULL; pFlags++)
    {
        // Create the (next) switch item
        hWndChild = CreateSwitchItem(pData, pFlags, CheckBoxRect, hWndChild);
        nChecked = BST_UNCHECKED;

        // Check/uncheck the box
        if(pFlags->dwValue != FLAG_SEPARATOR)
        {
            // Do we have radio buttons?
            if(pData->IsValueDialog)
            {
                if(dwFlags == pFlags->dwValue)
                {
                    nChecked = BST_CHECKED;
                    dwFlags = 0;
                }
            }
            else
            {
                if((dwFlags & pFlags->dwMask) == pFlags->dwValue)
                {
                    nChecked = BST_CHECKED;
                    dwFlags = dwFlags & ~pFlags->dwValue;
                }
            }

            // Check or uncheck the button
            Button_SetCheck(hWndChild, nChecked);
        }

        // The next control will be created dynamically, 6 dialog units lower
        hWndChild = NULL;
    }

    // If there is at least one flag unused, we need to create an extra button
    if(dwFlags != 0)
    {
        LoadString(g_hInst, IDS_CUSTOM_VALUE, pData->szCustomValue, _maxchars(pData->szCustomValue));
        pData->ExtraFlag.dwValue = dwFlags;
        pData->ExtraFlag.dwMask  = 0xFFFFFFFF;
        pData->ExtraFlag.szFlagText = pData->szCustomValue;
        hWndChild = CreateSwitchItem(pData, &pData->ExtraFlag, CheckBoxRect, hWndChild);
        Button_SetCheck(hWndChild, BST_CHECKED);
    }

    // Resize the group box so it covers all buttons
    cx = (GroupRect.right - GroupRect.left);
    cy = (GroupRect.bottom - GroupRect.top) + pData->nDeltaY;
    SetWindowPos(hWndGroup, NULL, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

    // Move the buttons
    ArrangeDialogButton(pData->hDlg, ClientRect, IDC_SELECT_ALL, pData->nDeltaY);
    ArrangeDialogButton(pData->hDlg, ClientRect, IDC_CLEAR_ALL, pData->nDeltaY);
    ArrangeDialogButton(pData->hDlg, ClientRect, IDOK, pData->nDeltaY);

    // Resize and center the dialog
    cx = (DialogRect.right - DialogRect.left);
    cy = (DialogRect.bottom - DialogRect.top) + pData->nDeltaY;
    x = ParentRect.left + ((ParentRect.right - ParentRect.left) - cx) / 2;
    y = ParentRect.top + ((ParentRect.bottom - ParentRect.top) - cy) / 2;
    SetWindowPos(pData->hDlg, NULL, x, y, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
}
void TToolTip::OnGetTooltipText(LPNMTTDISPINFO pTTDispInfo)
{
    TFlagInfo * pFlags = (TFlagInfo *)pTTDispInfo->lParam;
    LPTSTR szTextBuffEnd = szToolTipText + cchTooltipText;
    LPTSTR szTextBuff = szToolTipText;
    TCHAR szWindowText[0x80];
    DWORD dwValue32 = 0;
    HWND hWndChild = (HWND)pTTDispInfo->hdr.idFrom;

    // Only if the text buffer has been allocated
    if(pFlags != NULL && szTextBuff != NULL)
    {
        // Reset the tooltip info to an empty string
        szToolTipText[0] = 0;

        // Retrieve the window text and convert it to 32-bit hexa value
        GetWindowText(hWndChild, szWindowText, _maxchars(szWindowText));
        if(Text2Hex32(szWindowText, &dwValue32) == ERROR_SUCCESS)
        {
            // Supply the flags
            while(dwValue32 != 0 && pFlags->szFlagText != NULL)
            {
                // Is that flag set?
                if(IS_FLAG_SET(pFlags, dwValue32))
                {
                    size_t nLength = _tcslen(pFlags->szFlagText);

                    // Is there enough space left?
                    if((size_t)(szTextBuffEnd - szTextBuff) < (nLength + 0x20))
                        break;

                    // If there is a flag from the previous pass, append newline to it
                    if(szTextBuff > szToolTipText)
                        szTextBuff = AddNewLine(szTextBuff, (szTextBuffEnd - szTextBuff));

                    // Append the flag text
                    memcpy(szTextBuff, pFlags->szFlagText, (nLength + 1) * sizeof(TCHAR));
                    szTextBuff += nLength;

                    // Clear the bit from the 
                    dwValue32 &= ~pFlags->dwValue;
                }

                // Move to the next flag
                pFlags++;
            }

            // If there is no text or there are unknown flags left, put them as hexa value
            if(szTextBuff == szToolTipText || dwValue32 != 0)
            {
                // If there is a flag from the previous pass, append newline to it
                if(szTextBuff > szToolTipText)
                    szTextBuff = AddNewLine(szTextBuff, (szTextBuffEnd - szTextBuff));

                StringCchPrintf(szTextBuff, (szTextBuffEnd - szTextBuff), _T("0x%08X"), dwValue32);
            }

            // Supply the text to the tooltip
            pTTDispInfo->lpszText = szToolTipText;
            pTTDispInfo->szText[0] = 0;
        }
        else
        {
            StringCchPrintf(pTTDispInfo->szText, _countof(pTTDispInfo->szText), _T("Error converting \"%s\" to 32-bit integer"), szWindowText);
        }
    }
}
static void InitializeTabControl(HWND hDlg, TWindowData * pData)
{
    PROPSHEETHEADER psh;
    PROPSHEETPAGE psp[13];
    TCHAR szAppTitle[256];
    HWND hTabCtrl = GetDlgItem(hDlg, IDC_TAB);
    int nPages = 0;

    // Get the title of FileTest application
    GetFileTestAppTitle(szAppTitle, _maxchars(szAppTitle));

    // Fill the property sheet header
    ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
    psh.dwSize     = sizeof(PROPSHEETHEADER);
    psh.dwFlags    = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP | PSH_MODELESS;
    psh.hwndParent = hDlg;
    psh.hInstance  = g_hInst;
    psh.pszIcon    = MAKEINTRESOURCE(IDI_FILE_TEST);
    psh.pszCaption = szAppTitle;
    psh.nStartPage = 1;
    psh.ppsp       = psp;

    // Fill the "Transaction" page (Vista only)
    if(pfnCreateTransaction != NULL)
    {
        ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
        psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
        psp[nPages].dwFlags     = PSP_DEFAULT;
        psp[nPages].hInstance   = g_hInst;
        psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE00_TRANSACTION);
        psp[nPages].pfnDlgProc  = PageProc00;
        psp[nPages].lParam      = (LPARAM)pData;
        nPages++;
    }

    // Fill the "CreateFile" page
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE01_CREATE);
    psp[nPages].pfnDlgProc  = PageProc01;
    psp[nPages].lParam      = (LPARAM)pData;
    psh.nStartPage = nPages;
    nPages++;

    // Fill the "NtCreateFile"
    // Note: If the file name looks like an NT name, go to NtCreateFile page
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE02_NTCREATE);
    psp[nPages].pfnDlgProc  = PageProc02;
    psp[nPages].lParam      = (LPARAM)pData;
    if(IsNativeName(((TFileTestData *)pData)->szFileName1))
        psh.nStartPage = nPages;
    nPages++;

    // Fill the "ReadWrite"
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE03_READWRITE);
    psp[nPages].pfnDlgProc  = PageProc03;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

    // Fill the "Mapping"
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE04_MAPPING);
    psp[nPages].pfnDlgProc  = PageProc04;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

    // Fill the "File Ops".
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE05_FILEOPS);
    psp[nPages].pfnDlgProc  = PageProc05;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

    // Fill the "NtFileInfo" page
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE06_NTFILEINFO);
    psp[nPages].pfnDlgProc  = PageProc06;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

#ifdef _DEBUG
//  psh.nStartPage = nPages - 1; // Set the "FileOps" as starting page for debug purposes
#endif

    // Fill the "NtFsInfo" page.
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE07_NTVOLINFO);
    psp[nPages].pfnDlgProc  = PageProc06;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

    // Fill the "EA" page.
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE08_EA);
    psp[nPages].pfnDlgProc  = PageProc08;       // The same like NtFileInfo
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

    // Fill the "Security".
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE09_SECURITY);
    psp[nPages].pfnDlgProc  = PageProc09;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

    // Fill the "Links".
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE10_LINKS);
    psp[nPages].pfnDlgProc  = PageProc10;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;

    // Fill the "Streams".
    ZeroMemory(&psp[nPages], sizeof(PROPSHEETPAGE));
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGE);
    psp[nPages].dwFlags     = PSP_DEFAULT;
    psp[nPages].hInstance   = g_hInst;
    psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_PAGE11_STREAMS);
    psp[nPages].pfnDlgProc  = PageProc11;
    psp[nPages].lParam      = (LPARAM)pData;
    nPages++;
    psh.nPages = nPages;

    // Create Tab Control
    TabCtrl_Create(hTabCtrl, &psh);

    // Get the currently selected page HWND
    pData->hWndPage = TabCtrl_GetSelectedPage(hTabCtrl);
}