Skip to content

Commit

Permalink
Enhanced Streams Removal
Browse files Browse the repository at this point in the history
- Handled case where stream lookup is successful but no stream information exists.
- Added numeric error printout for string removal.
- Adjusted version printout to dynamically lookup information.
  • Loading branch information
NoMoreFood committed Jul 7, 2021
1 parent 2d63ee7 commit 11e3140
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 13 deletions.
Binary file modified Build/Release/x64/repacls.exe
Binary file not shown.
Binary file modified Build/Release/x86/repacls.exe
Binary file not shown.
Binary file modified Build/Repacls.zip
Binary file not shown.
26 changes: 24 additions & 2 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "ConcurrentQueue.h"
#include "DriverKitPartial.h"
#include "Functions.h"
#include "Version.h"

#pragma comment(lib,"version.lib")

constexpr ULONG MAX_DIRECTORY_BUFFER = 65536;

Expand Down Expand Up @@ -447,9 +448,30 @@ int wmain(int iArgs, WCHAR * aArgs[])
_setmode(_fileno(stderr), _O_U16TEXT);
_setmode(_fileno(stdout), _O_U16TEXT);

// fetch currently running executable name
std::wstring sVersion;
LPWSTR sCurrentExe = nullptr;
if (_get_wpgmptr(&sCurrentExe) != 0 || sCurrentExe == nullptr)
{
wprintf(L"%s\n", L"ERROR: Cannot get currently running executable name.");
exit(-1);
}

// fetch the version string
const DWORD iVersionSize = GetFileVersionInfoSize(sCurrentExe, nullptr);
UINT iQueriedSize = 0;
std::vector<BYTE> tVersionInfo = std::vector<BYTE>(iVersionSize);
VS_FIXEDFILEINFO* pVersion = nullptr;
if (GetFileVersionInfo(sCurrentExe, 0, iVersionSize, tVersionInfo.data()) != 0 &&
VerQueryValue(tVersionInfo.data(), L"\\", reinterpret_cast<LPVOID*>(&pVersion), &iQueriedSize) != 0)
{
sVersion = std::to_wstring(HIWORD(pVersion->dwFileVersionMS)) + L"." + std::to_wstring(LOWORD(pVersion->dwFileVersionMS)) +
L"." + std::to_wstring(HIWORD(pVersion->dwFileVersionLS)) + L"." + std::to_wstring(LOWORD(pVersion->dwFileVersionLS));
}

// print standard header
wprintf(L"===============================================================================\n");
wprintf(L"= Repacls Version %hs by Bryan Berns\n", VERSION_STRING);
wprintf(L"= Repacls Version %s by Bryan Berns\n", sVersion.c_str());
wprintf(L"===============================================================================\n");

// translate
Expand Down
6 changes: 3 additions & 3 deletions OperationRemoveStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ void OperationRemoveStreams::ProcessObjectAction(ObjectEntry& tObjectEntry)
}

// loop until we can fill the stream into a buffer
IO_STATUS_BLOCK tIOStatus = {};
NTSTATUS iStatus;
thread_local std::vector<BYTE> sInfoBuffer(16 * 1024, 0);
for (iStatus = STATUS_BUFFER_OVERFLOW; iStatus == STATUS_BUFFER_OVERFLOW;
sInfoBuffer.resize(sInfoBuffer.size() * 2, 0))
{
IO_STATUS_BLOCK tIOStatus = {};
iStatus = NtQueryInformationFile(hFile, &tIOStatus, sInfoBuffer.data(), (ULONG) sInfoBuffer.size(), FileStreamInformation);
if (iStatus == STATUS_SUCCESS) break;
}

// cleanup and verify we got the data we needed
CloseHandle(hFile);
if (iStatus != STATUS_SUCCESS) return;
if (iStatus != STATUS_SUCCESS || tIOStatus.Information == 0) return;

// Loop for all streams
for (PFILE_STREAM_INFORMATION pStreamInfo = (PFILE_STREAM_INFORMATION)sInfoBuffer.data(); pStreamInfo->StreamNameLength != 0;
Expand All @@ -67,7 +67,7 @@ void OperationRemoveStreams::ProcessObjectAction(ObjectEntry& tObjectEntry)
}
else
{
InputOutput::AddError(L"Unable delete stream: " + sStream);
InputOutput::AddError(L"Unable delete stream: " + sStream + L" (" + std::to_wstring(GetLastError()) + L")");
}

// break if no next stream
Expand Down
Binary file modified Resource.rc
Binary file not shown.
4 changes: 0 additions & 4 deletions Version.h

This file was deleted.

1 change: 0 additions & 1 deletion repacls.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@
<ClInclude Include="OperationThreads.h" />
<ClInclude Include="OperationWhatIf.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Version.h" />
</ItemGroup>
<ItemGroup>
<Text Include="Notes.txt" />
Expand Down
3 changes: 0 additions & 3 deletions repacls.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@
<ClInclude Include="OperationReport.h">
<Filter>Includes\Operations</Filter>
</ClInclude>
<ClInclude Include="Version.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="OperationSharePaths.h">
<Filter>Includes\Operations</Filter>
</ClInclude>
Expand Down

0 comments on commit 11e3140

Please sign in to comment.