Skip to content

Commit ff8411e

Browse files
committed
moved files to new directory
minor refactors
1 parent 5db1aad commit ff8411e

File tree

11 files changed

+48
-39
lines changed

11 files changed

+48
-39
lines changed

Raccine.sln

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30413.136
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Raccine", "Raccine.vcxproj", "{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}"
7-
EndProject
86
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Raccine-Test", "tests\Raccine-Test\Raccine-Test.vcxproj", "{B6CF8E12-D257-4E81-8634-3D5E4320B7E9}"
97
EndProject
108
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RaccineLib", "source\RaccineLib\RaccineLib.vcxproj", "{1E00BDF5-F2B2-4A59-8E3A-58EDBFE0E420}"
119
EndProject
10+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Raccine", "source\Raccine\Raccine.vcxproj", "{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}"
11+
EndProject
1212
Global
1313
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1414
Debug|x64 = Debug|x64
@@ -17,14 +17,6 @@ Global
1717
Release|x86 = Release|x86
1818
EndGlobalSection
1919
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x64.ActiveCfg = Debug|x64
21-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x64.Build.0 = Debug|x64
22-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x86.ActiveCfg = Debug|Win32
23-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x86.Build.0 = Debug|Win32
24-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x64.ActiveCfg = Release|x64
25-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x64.Build.0 = Release|x64
26-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x86.ActiveCfg = Release|Win32
27-
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x86.Build.0 = Release|Win32
2820
{B6CF8E12-D257-4E81-8634-3D5E4320B7E9}.Debug|x64.ActiveCfg = Debug|x64
2921
{B6CF8E12-D257-4E81-8634-3D5E4320B7E9}.Debug|x64.Build.0 = Debug|x64
3022
{B6CF8E12-D257-4E81-8634-3D5E4320B7E9}.Debug|x86.ActiveCfg = Debug|Win32
@@ -41,6 +33,14 @@ Global
4133
{1E00BDF5-F2B2-4A59-8E3A-58EDBFE0E420}.Release|x64.Build.0 = Release|x64
4234
{1E00BDF5-F2B2-4A59-8E3A-58EDBFE0E420}.Release|x86.ActiveCfg = Release|Win32
4335
{1E00BDF5-F2B2-4A59-8E3A-58EDBFE0E420}.Release|x86.Build.0 = Release|Win32
36+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x64.ActiveCfg = Debug|x64
37+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x64.Build.0 = Debug|x64
38+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x86.ActiveCfg = Debug|Win32
39+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Debug|x86.Build.0 = Debug|Win32
40+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x64.ActiveCfg = Release|x64
41+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x64.Build.0 = Release|x64
42+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x86.ActiveCfg = Release|Win32
43+
{E402FCEB-A95B-44FF-BC00-B24CE6DAF0AB}.Release|x86.Build.0 = Release|Win32
4444
EndGlobalSection
4545
GlobalSection(SolutionProperties) = preSolution
4646
HideSolutionNode = FALSE

source/Raccine/Raccine.aps

1.4 KB
Binary file not shown.

Raccine.rc renamed to source/Raccine/Raccine.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ END
5959
/////////////////////////////////////////////////////////////////////////////
6060
#endif // not APSTUDIO_INVOKED
6161

62-
MAINICON ICON "Raccine.ico"
62+
MAINICON ICON "..\\..\\Raccine.ico"

Raccine.vcxproj renamed to source/Raccine/Raccine.vcxproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<LanguageStandard>stdcpplatest</LanguageStandard>
9696
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
9797
<TreatWarningAsError>true</TreatWarningAsError>
98+
<AdditionalIncludeDirectories>$(SolutionDir)source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9899
</ClCompile>
99100
<Link>
100101
<SubSystem>Console</SubSystem>
@@ -112,6 +113,7 @@
112113
<LanguageStandard>stdcpplatest</LanguageStandard>
113114
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
114115
<TreatWarningAsError>true</TreatWarningAsError>
116+
<AdditionalIncludeDirectories>$(SolutionDir)source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
115117
</ClCompile>
116118
<Link>
117119
<SubSystem>Console</SubSystem>
@@ -129,6 +131,7 @@
129131
<LanguageStandard>stdcpplatest</LanguageStandard>
130132
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
131133
<TreatWarningAsError>true</TreatWarningAsError>
134+
<AdditionalIncludeDirectories>$(SolutionDir)source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
132135
</ClCompile>
133136
<Link>
134137
<SubSystem>Console</SubSystem>
@@ -146,6 +149,7 @@
146149
<LanguageStandard>stdcpplatest</LanguageStandard>
147150
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
148151
<TreatWarningAsError>true</TreatWarningAsError>
152+
<AdditionalIncludeDirectories>$(SolutionDir)source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
149153
</ClCompile>
150154
<Link>
151155
<SubSystem>Console</SubSystem>
@@ -167,8 +171,9 @@
167171
<ClCompile Include="Raccine.cpp" />
168172
</ItemGroup>
169173
<ItemGroup>
170-
<ProjectReference Include="source\RaccineLib\RaccineLib.vcxproj">
174+
<ProjectReference Include="..\RaccineLib\RaccineLib.vcxproj">
171175
<Project>{1e00bdf5-f2b2-4a59-8e3a-58edbfe0e420}</Project>
176+
<Private>false</Private>
172177
</ProjectReference>
173178
</ItemGroup>
174179
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
File renamed without changes.

raccine.cpp renamed to source/Raccine/raccine.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
// Florian Roth, Ollie Whitehouse, Branislav Djalic, John Lambert
66
// with help of Hilko Bengen
77

8-
#include "source/RaccineLib/Raccine.h"
8+
#include "RaccineLib/Raccine.h"
99

1010
#include <Shlwapi.h>
1111

12-
13-
#include "source/RaccineLib/HandleWrapper.h"
14-
#include "source/RaccineLib/RaccineConfig.h"
15-
#include "source/RaccineLib/Utils.h"
12+
#include "RaccineLib/RaccineConfig.h"
13+
#include "RaccineLib/Utils.h"
1614

1715
int wmain(int argc, WCHAR* argv[])
1816
{
@@ -36,11 +34,11 @@ int wmain(int argc, WCHAR* argv[])
3634
//skip argv[0] and create a new command line string from our argv,
3735
//if we get a quoted path for the exe back, adjust the command line to skip past that.
3836
LPWSTR lpzchildCommandLine = GetCommandLine() + (wcslen(argv[0]) + 1);
39-
std::wstring originalCommandLine(GetCommandLine());
37+
const std::wstring originalCommandLine(GetCommandLine());
4038
if (originalCommandLine.starts_with(L"\"") && (wcslen(argv[0]) + 3) < originalCommandLine.length())
4139
lpzchildCommandLine = GetCommandLine() + (wcslen(argv[0]) + 3);
4240
if (needs_powershell_workaround(sCommandLine)) {
43-
lpzchildCommandLine = (LPWSTR)std::wstring(L"powershell.exe ").append(sCommandLine).c_str();
41+
lpzchildCommandLine = static_cast<LPWSTR>(std::wstring(L"powershell.exe ").append(sCommandLine).data());
4442
}
4543

4644
auto [dwChildPid, hProcess, hThread] = createChildProcessWithDebugger(lpzchildCommandLine, CREATE_SUSPENDED);
File renamed without changes.

source/RaccineLib/Raccine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ void find_and_kill_processes(bool log_only,
8484
const std::wstring& sCommandLine,
8585
std::wstring& sListLogs);
8686

87-
std::wstring CreateContextForProgram(DWORD pid, std::wstring szDefinePrefix);
87+
std::wstring CreateContextForProgram(DWORD pid, const std::wstring& szDefinePrefix);

source/RaccineLib/Utils.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ ProcessDetail::ProcessDetail(DWORD dwPid) :
309309
ProcessDetailStruct.TimeSinceExeCreation = getLastWriteTime(ProcessDetailStruct.ExePath);
310310
}
311311

312-
std::wstring ProcessDetail::ToString(const std::wstring szPrefix) const
312+
std::wstring ProcessDetail::ToString(const std::wstring& szPrefix) const
313313
{
314314
const std::wstring YaraDef = L" -d ";
315315

@@ -336,25 +336,30 @@ std::wstring expand_environment_strings(const std::wstring& input)
336336
return std::wstring(output.data());
337337
}
338338

339-
ULONG utils::getLastWriteTime(std::wstring szFilePath)
339+
ULONG getLastWriteTime(const std::wstring& szFilePath)
340340
{
341-
HANDLE hFile = CreateFile(szFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
342-
if (hFile == INVALID_HANDLE_VALUE)
341+
FileHandleWrapper hFile = CreateFileW(szFilePath.c_str(),
342+
GENERIC_READ,
343+
FILE_SHARE_READ,
344+
NULL,
345+
OPEN_EXISTING,
346+
0,
347+
NULL);
348+
if (hFile == INVALID_HANDLE_VALUE){
343349
return 0;
350+
}
344351

345-
ULARGE_INTEGER ulNow = { 0 }, ulFile = { 0 }, ulDiff = { 0 };
346-
ULONG timeDiff = 999999999;
347352
FILETIME timeFile, timeNow = { 0 };
348353
SYSTEMTIME stNow = { 0 };
349354
GetSystemTime(&stNow);
350355
SystemTimeToFileTime(&stNow, &timeNow);
351356

352357
if (!GetFileTime(hFile, NULL, NULL, &timeFile))
353358
{
354-
CloseHandle(hFile);
355359
return 0;
356360
}
357-
CloseHandle(hFile);
361+
362+
ULARGE_INTEGER ulNow = { 0 }, ulFile = { 0 }, ulDiff = { 0 };
358363

359364
ulNow.HighPart = timeNow.dwHighDateTime;
360365
ulNow.LowPart = timeNow.dwLowDateTime;
@@ -368,14 +373,16 @@ ULONG utils::getLastWriteTime(std::wstring szFilePath)
368373
if (ulNow.QuadPart > ulFile.QuadPart)
369374
{
370375
ulDiff.QuadPart = ulNow.QuadPart - ulFile.QuadPart;
371-
ULONG diff = ((ULONG)(ulDiff.QuadPart / (10000 * 1000)) / (60 * 60 * 24)); //
376+
const ULONG diff = (static_cast<ULONG>(ulDiff.QuadPart / (10000 * 1000)) / (60 * 60 * 24));
372377

373378
return diff;
374379
}
380+
381+
const ULONG timeDiff = 999999999;
375382
return timeDiff;
376383
}
377384

378-
bool write_string_to_file(const std::filesystem::path file_path, const std::wstring& string_to_write)
385+
bool write_string_to_file(const std::filesystem::path& file_path, const std::wstring& string_to_write)
379386
{
380387
// Creates the new file to write to for the upper-case version.
381388
FileHandleWrapper hTempFile = CreateFileW(file_path.c_str(), // file name

source/RaccineLib/Utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ProcessDetail final
1515

1616
~ProcessDetail() = default;
1717

18-
[[nodiscard]] std::wstring ToString(const std::wstring szPrefix) const;
18+
[[nodiscard]] std::wstring ToString(const std::wstring& szPrefix) const;
1919

2020
private:
2121
struct PROCESS_DETAIL
@@ -59,10 +59,10 @@ DWORD GetPriorityClassByPid(DWORD pid);
5959

6060
std::wstring expand_environment_strings(const std::wstring& input);
6161

62-
bool write_string_to_file(const std::filesystem::path file_path, const std::wstring& string_to_write);
62+
bool write_string_to_file(const std::filesystem::path& file_path, const std::wstring& string_to_write);
6363

6464
std::optional<std::string> convert_wstring_to_string(const std::wstring& input);
6565

66-
ULONG getLastWriteTime(std::wstring szFilePath);
66+
ULONG getLastWriteTime(const std::wstring& szFilePath);
6767

6868
}

source/RaccineLib/raccine.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <cwchar>
99
#include <Windows.h>
1010
#include <cstdio>
11-
#include <cstring>
1211
#include <string>
1312
#include <array>
1413
#include <chrono>
@@ -59,9 +58,10 @@ bool EvaluateYaraRules(const RaccineConfig& raccine_config,
5958

6059
std::wstring parentContext = CreateContextForProgram(dwParentPid, L"Parent");
6160

62-
std::wstring grandparentContext = L"";
63-
if (dwGrandParentPid != 0)
61+
std::wstring grandparentContext;
62+
if (dwGrandParentPid != 0) {
6463
grandparentContext = CreateContextForProgram(dwGrandParentPid, L"GrandParent");
64+
}
6565

6666
std::wstring combinedContext = childContext + L" " + parentContext +L" " + grandparentContext;
6767

@@ -92,12 +92,11 @@ bool EvaluateYaraRules(const RaccineConfig& raccine_config,
9292
return fRetVal;
9393
}
9494

95-
std::wstring CreateContextForProgram(DWORD pid, std::wstring szDefinePrefix)
95+
std::wstring CreateContextForProgram(DWORD pid, const std::wstring& szDefinePrefix)
9696
{
9797
const utils::ProcessDetail details(pid);
9898

99-
std::wstring strDetails;
100-
strDetails = details.ToString(szDefinePrefix);
99+
std::wstring strDetails = details.ToString(szDefinePrefix);
101100

102101
return strDetails;
103102
}

0 commit comments

Comments
 (0)