Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislav-zezula committed May 6, 2021
1 parent e0de63d commit 6c18e4d
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 78 deletions.
5 changes: 4 additions & 1 deletion DlgDataEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ static void OnInitDialog(HWND hDlg, LPARAM lParam)

// Initialize dialog data
SetDialogIcon(hDlg, IDI_FILE_TEST);
pData->hDlg = hDlg;
SetDialogData(hDlg, pData);
pData->hDlg = hDlg;

// Center the dialog to parent
CenterWindowToParent(hDlg);

// Configure the anchors
pData->pAnchors = pAnchors = new TAnchors();
Expand Down
37 changes: 28 additions & 9 deletions DlgEasEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ static TListViewColumns Columns[] =
//-----------------------------------------------------------------------------
// Local functions

static ULONG CopyEaItem(PFILE_FULL_EA_INFORMATION pTrg, PFILE_FULL_EA_INFORMATION pSrc, bool bSetNextOffset)
{
// Things checked by nt!IoCheckEaBufferValidity:
// 1) There must be zero after the EA name
// 2) NextEntryOffset must be aligned to DWORD boundary
ULONG EntryLength = FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName) + pSrc->EaNameLength + sizeof(CHAR) + pSrc->EaValueLength;

// Copy the entire entry
memcpy(pTrg, pSrc, EntryLength);
pTrg->EaName[pTrg->EaNameLength] = 0;
pTrg->NextEntryOffset = 0;

// Set the offset of the next entry, if needed
if(bSetNextOffset)
pTrg->NextEntryOffset = ALIGN_TO_SIZE(EntryLength, sizeof(DWORD));
return EntryLength;
}

static BOOL UpdateDialogButtons(HWND hDlg)
{
HWND hListView = GetDlgItem(hDlg, IDC_EA_LIST);
Expand Down Expand Up @@ -245,7 +263,7 @@ static int OnEditEa(HWND hDlg)
static int OnDeleteEa(HWND hDlg)
{
HWND hListView = GetDlgItem(hDlg, IDC_EA_LIST);
int nSelected = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
int nSelected = ListView_GetNextItem(hListView, -1, LVNI_FOCUSED);

// If no item selected, do nothing
if(nSelected != -1)
Expand Down Expand Up @@ -289,7 +307,7 @@ static BOOL OnSaveDialog(HWND hDlg)
{
// Delete the existing EAs
if(pData->pFileEa != NULL)
delete [] pData->pFileEa;
HeapFree(g_hHeap, 0, pData->pFileEa);
pData->pFileEa = NULL;
pData->dwEaSize = 0;

Expand Down Expand Up @@ -409,7 +427,7 @@ void ExtendedAttributesToListView(HWND hDlg, PFILE_FULL_EA_INFORMATION pFileEa)

PFILE_FULL_EA_INFORMATION ListViewToExtendedAttributes(HWND hDlg, DWORD & dwOutEaLength)
{
PFILE_FULL_EA_INFORMATION pEaItemCopy;
PFILE_FULL_EA_INFORMATION pFileEaPtr;
PFILE_FULL_EA_INFORMATION pEaItem;
PFILE_FULL_EA_INFORMATION pFileEa = NULL;
DWORD dwEaLength = 0;
Expand All @@ -423,25 +441,26 @@ PFILE_FULL_EA_INFORMATION ListViewToExtendedAttributes(HWND hDlg, DWORD & dwOutE
pEaItem = (PFILE_FULL_EA_INFORMATION)ListView_GetItemParam(hListView, nIndex);
if(pEaItem != NULL)
{
dwEaLength += pEaItem->NextEntryOffset;
// The size of the previous EA item must be aligned to 4 bytes
dwEaLength = ALIGN_TO_SIZE(dwEaLength, sizeof(DWORD));
dwEaLength = dwEaLength + FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName) + pEaItem->EaNameLength + 1 + pEaItem->EaValueLength;
}
}

// Allocate buffer for the complete EA list and copy the EAs to that buffer
pEaItemCopy = pFileEa = (PFILE_FULL_EA_INFORMATION)(new BYTE[dwEaLength]);
pFileEaPtr = pFileEa = (PFILE_FULL_EA_INFORMATION)HeapAlloc(g_hHeap, HEAP_ZERO_MEMORY, dwEaLength);
if(pFileEa != NULL)
{
for(nIndex = 0; nIndex < nItemCount; nIndex++)
{
pEaItem = (PFILE_FULL_EA_INFORMATION)ListView_GetItemParam(hListView, nIndex);
if(pEaItem != NULL)
{
memcpy(pEaItemCopy, pEaItem, pEaItem->NextEntryOffset);
// Copy the EA item to the list. If this is the last item, we want NextEntryOffset to be zero
CopyEaItem(pFileEaPtr, pEaItem, (nIndex < (nItemCount - 1)));

// If this is the last item, we have to set zero as NextEntryOffset
if(nIndex == nItemCount - 1)
pEaItemCopy->NextEntryOffset = 0;
pEaItemCopy = (PFILE_FULL_EA_INFORMATION)((LPBYTE)pEaItemCopy + pEaItemCopy->NextEntryOffset);
pFileEaPtr = (PFILE_FULL_EA_INFORMATION)((LPBYTE)pFileEaPtr + pFileEaPtr->NextEntryOffset);
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions DlgFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ typedef std::vector<TDlgFlagInfo> TFlagList;

struct TFlagDialogData
{
TFlagDialogData()
{
ZeroMemory(&pFlags, sizeof(TFlagDialogData) - FIELD_OFFSET(TFlagDialogData, pFlags));
}

TFlagList FlagList;
TFlagInfo * pFlags; // Flags (structure array)
HWND hWndParent; // Parent of the dialog
Expand Down Expand Up @@ -176,7 +181,7 @@ static HWND CreateButtonItem(
else
{
// Set the child type to radio button, if needed
SetWindowLong(hWndChild, GWL_STYLE, pData->dwStyle | FlagInfo.dwButtonType | WS_VISIBLE);
SetWindowLong(hWndChild, GWL_STYLE, pData->dwStyle | FlagInfo.dwButtonType | WS_VISIBLE | WS_GROUP | WS_TABSTOP);
}

// Set the button text and user data, if not a separator
Expand Down Expand Up @@ -288,7 +293,7 @@ static void CreateDialogLayout(TFlagDialogData * pData)
// If 20 flags or more, we split the dialog into more columns
pData->nColumn1 = pData->FlagList.size();
pData->nColumns = 1;
while(pData->nColumn1 > 20)
while(pData->nColumn1 > 23)
{
pData->nColumns++;
pData->nColumn1 = (dwFlagCount / pData->nColumns) + ((dwFlagCount % pData->nColumns) ? 1 : 0);
Expand Down Expand Up @@ -455,7 +460,6 @@ INT_PTR FlagsDialog(HWND hWndParent, UINT nIDTitle, TFlagInfo * pFlags, DWORD &
INT_PTR Result;

// Retrieve the flags
ZeroMemory(&fdd, sizeof(TFlagDialogData));
fdd.hWndParent = hWndParent;
fdd.pFlags = pFlags;
fdd.dwBitMask = dwBitMask;
Expand Down
14 changes: 7 additions & 7 deletions FileTest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,7,0,598
PRODUCTVERSION 2,7,0,598
FILEVERSION 2,7,0,601
PRODUCTVERSION 2,7,0,601
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -127,13 +127,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Ladislav Zezula"
VALUE "FileDescription", "Interactive File System API Test"
VALUE "FileVersion", "2, 7, 0, 598"
VALUE "FileVersion", "2, 7, 0, 601"
VALUE "InternalName", "FileTest"
VALUE "LegalCopyright", "Copyright � 2004 - 2018 Ladislav Zezula"
VALUE "LegalTrademarks", "http://www.zezula.net"
VALUE "OriginalFilename", "FileTest.exe"
VALUE "ProductName", "FileTest"
VALUE "ProductVersion", "2, 7, 0, 598"
VALUE "ProductVersion", "2, 7, 0, 601"
END
END
BLOCK "VarFileInfo"
Expand Down Expand Up @@ -323,13 +323,13 @@ BEGIN
LTEXT "Allocation size:",IDC_STATIC,12,91,60,14,SS_CENTERIMAGE
EDITTEXT IDC_ALLOCATION_SIZE,73,91,200,14,ES_AUTOHSCROLL
CONTROL "Spin1",IDC_ALLOCATION_SIZE_UPDOWN,"msctls_updown32",UDS_ARROWKEYS | UDS_HOTTRACK,278,91,15,14
LTEXT "File attributes:",IDC_STATIC,11,109,60,14,SS_CENTERIMAGE
LTEXT "File attributes:",IDC_STATIC,12,109,60,14,SS_CENTERIMAGE
EDITTEXT IDC_FILE_ATTRIBUTES,73,109,200,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_FILE_ATTRIBUTES_BROWSE,278,109,15,14
LTEXT "Share access:",IDC_STATIC,11,128,60,14,SS_CENTERIMAGE
LTEXT "Share access:",IDC_STATIC,12,128,60,14,SS_CENTERIMAGE
EDITTEXT IDC_SHARE_ACCESS,73,128,200,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_SHARE_ACCESS_BROWSE,278,128,15,14
LTEXT "Create disposition:",IDC_STATIC,11,146,60,12,SS_CENTERIMAGE
LTEXT "Create disposition:",IDC_STATIC,12,146,60,12,SS_CENTERIMAGE
COMBOBOX IDC_CREATE_DISPOSITION,73,146,200,57,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Create options:",IDC_STATIC,12,162,60,14,SS_CENTERIMAGE
EDITTEXT IDC_CREATE_OPTIONS,73,162,200,14,ES_AUTOHSCROLL
Expand Down
4 changes: 3 additions & 1 deletion FileTest_vs08.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
AdditionalIncludeDirectories="../aaa/inc"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
ExceptionHandling="1"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="2"
Expand Down Expand Up @@ -206,6 +207,7 @@
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../aaa/inc"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
ExceptionHandling="1"
RuntimeLibrary="0"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="FileTest.h"
Expand Down Expand Up @@ -288,7 +290,7 @@
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../aaa/inc"
PreprocessorDefinitions="WIN64;NDEBUG;_WINDOWS"
ExceptionHandling="0"
ExceptionHandling="1"
RuntimeLibrary="0"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="FileTest.h"
Expand Down
2 changes: 1 addition & 1 deletion FileTest_vs17.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
<ClCompile>
<AdditionalIncludeDirectories>../aaa/inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN64;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling />
<ExceptionHandling>Sync</ExceptionHandling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>FileTest.h</PrecompiledHeaderFile>
Expand Down
14 changes: 7 additions & 7 deletions Page01Create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ static TFlagInfo FlagsAndAttributesValues[] =
FLAGINFO_BITV(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED), // 0x00002000
FLAGINFO_BITV(FILE_ATTRIBUTE_ENCRYPTED), // 0x00004000
FLAGINFO_BITV(FILE_ATTRIBUTE_INTEGRITY_STREAM), // 0x00008000
FLAGINFO_BITV(SECURITY_SQOS_PRESENT), // 0x00100000
FLAGINFO_BITV(SECURITY_EFFECTIVE_ONLY), // 0x00080000
FLAGINFO_BITV(SECURITY_CONTEXT_TRACKING), // 0x00040000
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_ANONYMOUS), // 0x00000000*
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_IDENTIFICATION), // 0x00010000*
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_IMPERSONATION), // 0x00020000*
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_DELEGATION), // 0x00030000*
FLAGINFO_BITV(FILE_FLAG_OPEN_REPARSE_POINT), // 0x00200000
FLAGINFO_BITV(FILE_FLAG_POSIX_SEMANTICS), // 0x01000000
FLAGINFO_BITV(FILE_FLAG_BACKUP_SEMANTICS), // 0x02000000
Expand All @@ -48,6 +41,13 @@ static TFlagInfo FlagsAndAttributesValues[] =
FLAGINFO_BITV(FILE_FLAG_NO_BUFFERING), // 0x20000000
FLAGINFO_BITV(FILE_FLAG_OVERLAPPED), // 0x40000000
FLAGINFO_BITV(FILE_FLAG_WRITE_THROUGH), // 0x80000000
FLAGINFO_BITV(SECURITY_SQOS_PRESENT), // 0x00100000
FLAGINFO_BITV(SECURITY_EFFECTIVE_ONLY), // 0x00080000
FLAGINFO_BITV(SECURITY_CONTEXT_TRACKING), // 0x00040000
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_ANONYMOUS), // 0x00000000*
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_IDENTIFICATION), // 0x00010000*
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_IMPERSONATION), // 0x00020000*
FLAGINFO_MASK(SECURITY_VALUE_MASK,SECURITY_DELEGATION), // 0x00030000*
FLAGINFO_END()
};

Expand Down
3 changes: 3 additions & 0 deletions Page04Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static TFlagInfo SectionAccessValues[] =

TFlagInfo AllocationAttributesValues[] =
{
FLAGINFO_BITV(SEC_PARTITION_OWNER_HANDLE),
FLAGINFO_BITV(SEC_64K_PAGES),
FLAGINFO_BITV(SEC_FILE),
FLAGINFO_BITV(SEC_IMAGE),
FLAGINFO_BITV(SEC_PROTECTED_IMAGE),
Expand All @@ -64,6 +66,7 @@ static TFlagInfo AllocationTypeValues[] =
FLAGINFO_BITV(MEM_WRITE_WATCH),
FLAGINFO_BITV(MEM_PHYSICAL),
FLAGINFO_BITV(MEM_ROTATE),
FLAGINFO_BITV(MEM_RESET_UNDO),
FLAGINFO_BITV(MEM_LARGE_PAGES),
FLAGINFO_BITV(MEM_4MB_PAGES),
FLAGINFO_END()
Expand Down
74 changes: 36 additions & 38 deletions Page08Ea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static int OnSetActive(HWND hDlg)

static int OnQueryEa(HWND hDlg)
{
PFILE_FULL_EA_INFORMATION NewEaBuffer;
PFILE_FULL_EA_INFORMATION EaBuffer = NULL;
FILE_EA_INFORMATION FileEaInfo;
TFileTestData * pData = GetDialogData(hDlg);
Expand Down Expand Up @@ -95,55 +96,53 @@ static int OnQueryEa(HWND hDlg)
// double its size and try again
if(Status == STATUS_SUCCESS && EaBufferSize > 0)
{
BOOL bEndLoop = FALSE;

while(bEndLoop == FALSE)
__TryQueryEA:

// Retrieve the extended attributes
Status = NtQueryEaFile(pData->hFile,
&IoStatus,
EaBuffer,
EaBufferSize,
FALSE,
NULL,
0,
NULL,
TRUE);

switch(Status)
{
Status = NtQueryEaFile(pData->hFile,
&IoStatus,
EaBuffer,
EaBufferSize,
FALSE,
NULL,
0,
NULL,
TRUE);

if(Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL)
{
PFILE_FULL_EA_INFORMATION NewEaBuffer;
// If not enough memory, then reallocate buffer
case STATUS_BUFFER_OVERFLOW:
case STATUS_BUFFER_TOO_SMALL:

// Allocate new buffer. If succeeded, we try to query again
EaBufferSize = EaBufferSize << 1;
NewEaBuffer = (PFILE_FULL_EA_INFORMATION)HeapReAlloc(g_hHeap, 0, EaBuffer, EaBufferSize);
if(NewEaBuffer != NULL)
{
EaBuffer = NewEaBuffer;
continue;
goto __TryQueryEA;
}

// Failed to reallocate - free the buffer and stop
HeapFree(g_hHeap, 0, EaBuffer);
Status = STATUS_INSUFFICIENT_RESOURCES;
EaBuffer = NULL;
break;
}
}
}

// If we got something, fill the listview
if(Status == STATUS_SUCCESS)
{
ExtendedAttributesToListView(hDlg, EaBuffer);
HeapFree(g_hHeap, 0, EaBuffer);
// If OK, format the list view with extended attributes
case STATUS_SUCCESS:
ExtendedAttributesToListView(hDlg, EaBuffer);
HeapFree(g_hHeap, 0, EaBuffer);
break;
}
}

// Set the result to the dialog
SetResultInfo(hDlg, RSI_NTSTATUS | RSI_INFORMATION, Status, &IoStatus);
return TRUE;
}


static int OnSetEa(HWND hDlg)
{
PFILE_FULL_EA_INFORMATION pFileEa = NULL;
Expand All @@ -154,19 +153,18 @@ static int OnSetEa(HWND hDlg)

// Get the EA buffer and size
pFileEa = ListViewToExtendedAttributes(hDlg, dwEaLength);

// Set the extended attributes to the file
Status = NtSetEaFile(pData->hFile,
&IoStatus,
pFileEa,
dwEaLength);

// Set the result to the dialog
SetResultInfo(hDlg, RSI_NTSTATUS | RSI_INFORMATION, Status, &IoStatus);

// Delete buffers and exit
if(pFileEa != NULL)
delete [] pFileEa;
{
// Set the extended attributes to the file
Status = NtSetEaFile(pData->hFile,
&IoStatus,
pFileEa,
dwEaLength);

// Set the result to the dialog
SetResultInfo(hDlg, RSI_NTSTATUS | RSI_INFORMATION, Status, &IoStatus);
HeapFree(g_hHeap, 0, pFileEa);
}
return TRUE;
}

Expand Down
2 changes: 1 addition & 1 deletion TFlagString.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline const char * GetNewLineSeparator()
#define FLAGINFO_SEPARATOR() { (LPCSTR)1, 0, 0 }
#define FLAGINFO_END() { (LPCSTR)0, 0, 0 }

typedef struct TFlagInfo
struct TFlagInfo
{
bool IsValuePresent(unsigned int dwBitMask)
{
Expand Down
Loading

0 comments on commit 6c18e4d

Please sign in to comment.