Skip to content

Commit 1bb4c75

Browse files
authored
Merge pull request #32 from APriestman/11118_addImageSupportedDll
11118 Add image supported dll
2 parents b4d18bc + 80c1b84 commit 1bb4c75

9 files changed

Lines changed: 423 additions & 0 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
** The Sleuth Kit
3+
**
4+
** Brian Carrier [carrier <at> sleuthkit [dot] org]
5+
** Copyright (c) 2024 Sleuth Kit Labs, LLC. All Rights reserved
6+
** Copyright (c) 2010-2021 Brian Carrier. All Rights reserved
7+
**
8+
** This software is distributed under the Common Public License 1.0
9+
*/
10+
11+
// Library to check if an image can be opened by TSK
12+
#include "pch.h"
13+
#include "IsImageSupportedLib.h"
14+
15+
#include "tsk/auto/tsk_is_image_supported.h"
16+
#include "tsk/tsk_tools_i.h"
17+
#include "tsk/fs/apfs_fs.h"
18+
#include <stdlib.h>
19+
20+
21+
/**
22+
* Try to open an image. Use the password if supplied.
23+
*
24+
* @param path Path to the image
25+
* @param password Password. May be null.
26+
*
27+
* @return On success: Empty string
28+
On failure: Non-empty string containing the reason image opening failed if the tests were completed
29+
Null pointer if tests could not be run (memory allocation or path conversion issues)
30+
If return value is non-null it must be freed by the caller
31+
*/
32+
char* isImageSupported(const char* path, const char* password) {
33+
TskIsImageSupported tskIsImage;
34+
if (password != NULL) {
35+
std::string passwordStr(password);
36+
if (!passwordStr.empty()) {
37+
tskIsImage.setFileSystemPassword(password);
38+
}
39+
}
40+
41+
TSK_TCHAR* imagePathT = NULL;
42+
#ifdef TSK_WIN32
43+
// If we're on Windows, TSK_TCHAR is a wchar so we need to convert the path
44+
size_t pathLen = strlen(path);
45+
imagePathT = (TSK_TCHAR*)tsk_malloc((pathLen + 1) * sizeof(TSK_TCHAR));
46+
if (imagePathT == nullptr) {
47+
return nullptr;
48+
}
49+
50+
UTF8* utf8 = (UTF8*)path;
51+
UTF16* utf16 = (UTF16*)imagePathT;
52+
int ret = tsk_UTF8toUTF16((const UTF8**)&utf8, &utf8[pathLen],
53+
&utf16, &utf16[pathLen], TSKlenientConversion);
54+
if (ret != TSKconversionOK) {
55+
free(imagePathT);
56+
return nullptr;
57+
}
58+
#else
59+
// If we're not on Windows then TSK_TCHAR is just char and we don't need to convert
60+
imagePathT = path;
61+
#endif
62+
63+
TSK_TCHAR** imagePaths = (TSK_TCHAR**)tsk_malloc((1) * sizeof(TSK_TCHAR*));
64+
imagePaths[0] = imagePathT;
65+
std::string resultStr = "";
66+
if (tskIsImage.openImage(1, imagePaths, TSK_IMG_TYPE_DETECT, 0)) {
67+
resultStr = "Error opening image";
68+
}
69+
else {
70+
tskIsImage.findFilesInImg();
71+
resultStr = tskIsImage.getMessageForIsImageSupportedNat();
72+
}
73+
74+
// Cleanup
75+
tskIsImage.closeImage();
76+
free(imagePaths);
77+
#ifdef TSK_WIN32
78+
if (imagePathT != nullptr) {
79+
free(imagePathT);
80+
}
81+
#endif
82+
83+
// Make a new result string to return to the caller
84+
char* result_cStr = nullptr;
85+
if (resultStr.empty()) {
86+
result_cStr = (char*)malloc(1 * sizeof(char));
87+
if (result_cStr != nullptr) {
88+
result_cStr[0] = '\0';
89+
} // We return nullptr on error so we're already good
90+
}
91+
else {
92+
size_t resultLen = resultStr.size();
93+
result_cStr = (char*)malloc((resultLen + 1) * sizeof(char));
94+
if (result_cStr != nullptr) {
95+
strncpy_s(result_cStr, resultLen + 1, resultStr.c_str(), resultLen);
96+
}// We return nullptr on error so we're already good
97+
}
98+
99+
return result_cStr;
100+
}
101+
102+
/**
103+
* Free a string. Intended to be used to free the result of isImageSupported();
104+
*
105+
* @param str The string to free
106+
*/
107+
void freeString(char* str) {
108+
if (str != NULL) {
109+
free(str);
110+
}
111+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
** The Sleuth Kit
3+
**
4+
** Brian Carrier [carrier <at> sleuthkit [dot] org]
5+
** Copyright (c) 2024 Sleuth Kit Labs, LLC. All Rights reserved
6+
** Copyright (c) 2010-2021 Brian Carrier. All Rights reserved
7+
**
8+
** This software is distributed under the Common Public License 1.0
9+
*/
10+
#pragma once
11+
12+
#ifdef ISIMAGESUPPORTEDLIB_EXPORTS
13+
#define ISIMAGESUPPORTEDLIB_API __declspec(dllexport)
14+
#else
15+
#define ISIMAGESUPPORTEDLIB_API __declspec(dllimport)
16+
#endif
17+
18+
extern "C" ISIMAGESUPPORTEDLIB_API char* isImageSupported(const char* path, const char* password);
19+
extern "C" ISIMAGESUPPORTEDLIB_API void freeString(char* str);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// dllmain.cpp : Defines the entry point for the DLL application.
2+
#include "pch.h"
3+
4+
BOOL APIENTRY DllMain( HMODULE hModule,
5+
DWORD ul_reason_for_call,
6+
LPVOID lpReserved
7+
)
8+
{
9+
switch (ul_reason_for_call)
10+
{
11+
case DLL_PROCESS_ATTACH:
12+
case DLL_THREAD_ATTACH:
13+
case DLL_THREAD_DETACH:
14+
case DLL_PROCESS_DETACH:
15+
break;
16+
}
17+
return TRUE;
18+
}
19+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
4+
// Windows Header Files
5+
#include <windows.h>
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{6666e9a0-2a86-426c-a17e-a6fb9352009d}</ProjectGuid>
25+
<RootNamespace>isimagesupportedlib</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>DynamicLibrary</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v142</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>DynamicLibrary</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v142</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>DynamicLibrary</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v142</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>DynamicLibrary</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v142</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<LinkIncremental>true</LinkIncremental>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
77+
<LinkIncremental>false</LinkIncremental>
78+
</PropertyGroup>
79+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
80+
<LinkIncremental>true</LinkIncremental>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
83+
<LinkIncremental>false</LinkIncremental>
84+
</PropertyGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<SDLCheck>true</SDLCheck>
89+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
90+
<PreprocessorDefinitions>WIN32;_DEBUG;ISIMAGESUPPORTEDLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
91+
<ConformanceMode>true</ConformanceMode>
92+
<PrecompiledHeader>Use</PrecompiledHeader>
93+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
94+
</ClCompile>
95+
<Link>
96+
<AdditionalDependencies>libvhdi.lib;libvmdk.lib;libewf.lib;zlib.lib;libcrypto.lib;libssl.lib;%(AdditionalDependencies)</AdditionalDependencies>
97+
<AdditionalLibraryDirectories>$(TskNugetLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
98+
<SubSystem>Windows</SubSystem>
99+
<GenerateDebugInformation>true</GenerateDebugInformation>
100+
<EnableUAC>false</EnableUAC>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
<Import Project="$(SolutionDir)\NugetPackages.props" />
104+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
105+
<ClCompile>
106+
<WarningLevel>Level3</WarningLevel>
107+
<FunctionLevelLinking>true</FunctionLevelLinking>
108+
<IntrinsicFunctions>true</IntrinsicFunctions>
109+
<SDLCheck>true</SDLCheck>
110+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
111+
<PreprocessorDefinitions>WIN32;NDEBUG;ISIMAGESUPPORTEDLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
112+
<ConformanceMode>true</ConformanceMode>
113+
<PrecompiledHeader>Use</PrecompiledHeader>
114+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
115+
</ClCompile>
116+
<Link>
117+
<AdditionalDependencies>libvhdi.lib;libvmdk.lib;libewf.lib;zlib.lib;libcrypto.lib;libssl.lib;%(AdditionalDependencies)</AdditionalDependencies>
118+
<AdditionalLibraryDirectories>$(TskNugetLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
119+
<SubSystem>Windows</SubSystem>
120+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
121+
<OptimizeReferences>true</OptimizeReferences>
122+
<GenerateDebugInformation>true</GenerateDebugInformation>
123+
<EnableUAC>false</EnableUAC>
124+
</Link>
125+
</ItemDefinitionGroup>
126+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
127+
<ClCompile>
128+
<WarningLevel>Level3</WarningLevel>
129+
<SDLCheck>true</SDLCheck>
130+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
131+
<PreprocessorDefinitions>_DEBUG;ISIMAGESUPPORTEDLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132+
<ConformanceMode>true</ConformanceMode>
133+
<PrecompiledHeader>Use</PrecompiledHeader>
134+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
135+
</ClCompile>
136+
<Link>
137+
<AdditionalDependencies>libvhdi.lib;libvmdk.lib;libewf.lib;zlib.lib;libcrypto.lib;libssl.lib;%(AdditionalDependencies)</AdditionalDependencies>
138+
<AdditionalLibraryDirectories>$(TskNugetLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
139+
<SubSystem>Windows</SubSystem>
140+
<GenerateDebugInformation>true</GenerateDebugInformation>
141+
<EnableUAC>false</EnableUAC>
142+
</Link>
143+
</ItemDefinitionGroup>
144+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
145+
<ClCompile>
146+
<WarningLevel>Level3</WarningLevel>
147+
<FunctionLevelLinking>true</FunctionLevelLinking>
148+
<IntrinsicFunctions>true</IntrinsicFunctions>
149+
<SDLCheck>true</SDLCheck>
150+
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
151+
<PreprocessorDefinitions>NDEBUG;ISIMAGESUPPORTEDLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
152+
<ConformanceMode>true</ConformanceMode>
153+
<PrecompiledHeader>Use</PrecompiledHeader>
154+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
155+
</ClCompile>
156+
<Link>
157+
<AdditionalDependencies>libvhdi.lib;libvmdk.lib;libewf.lib;zlib.lib;libcrypto.lib;libssl.lib;%(AdditionalDependencies)</AdditionalDependencies>
158+
<AdditionalLibraryDirectories>$(TskNugetLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
159+
<SubSystem>Windows</SubSystem>
160+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
161+
<OptimizeReferences>true</OptimizeReferences>
162+
<GenerateDebugInformation>true</GenerateDebugInformation>
163+
<EnableUAC>false</EnableUAC>
164+
</Link>
165+
</ItemDefinitionGroup>
166+
<ItemGroup>
167+
<ClInclude Include="framework.h" />
168+
<ClInclude Include="IsImageSupportedLib.h" />
169+
<ClInclude Include="pch.h" />
170+
</ItemGroup>
171+
<ItemGroup>
172+
<ClCompile Include="dllmain.cpp" />
173+
<ClCompile Include="IsImageSupportedLib.cpp" />
174+
<ClCompile Include="pch.cpp">
175+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
176+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
177+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
178+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
179+
</ClCompile>
180+
</ItemGroup>
181+
<ItemGroup>
182+
<ProjectReference Include="..\libtsk\libtsk.vcxproj">
183+
<Project>{76efc06c-1f64-4478-abe8-79832716b393}</Project>
184+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
185+
</ProjectReference>
186+
</ItemGroup>
187+
<ItemGroup>
188+
<None Include="packages.config" />
189+
</ItemGroup>
190+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
191+
<ImportGroup Label="ExtensionTargets">
192+
</ImportGroup>
193+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="framework.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
<ClInclude Include="pch.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
24+
<ClInclude Include="IsImageSupportedLib.h">
25+
<Filter>Header Files</Filter>
26+
</ClInclude>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<ClCompile Include="dllmain.cpp">
30+
<Filter>Source Files</Filter>
31+
</ClCompile>
32+
<ClCompile Include="pch.cpp">
33+
<Filter>Source Files</Filter>
34+
</ClCompile>
35+
<ClCompile Include="IsImageSupportedLib.cpp">
36+
<Filter>Source Files</Filter>
37+
</ClCompile>
38+
</ItemGroup>
39+
</Project>

0 commit comments

Comments
 (0)