From 4e80ead8c5e80af8e62f38253644b55a4e5a5a50 Mon Sep 17 00:00:00 2001
From: Brian Carrier <carrier@sleuthkit.org>
Date: Tue, 17 Sep 2013 17:07:08 -0400
Subject: [PATCH] Minor updates for 64-bit builds

---
 bindings/java/build-windows.xml          | 47 ++++++++++++++----------
 tsk/base/tsk_os.h                        |  6 ++-
 tsk/fs/fs_file.c                         |  5 ++-
 tsk/img/img_io.c                         |  6 +--
 win32/BUILDING.txt                       |  8 +++-
 win32/tsk_comparedir/tsk_compare.vcxproj |  5 ++-
 win32/tsk_gettimes/tsk_gettimes.vcxproj  |  3 ++
 win32/tsk_loaddb/tsk_loaddb.vcxproj      |  6 +--
 win32/tsk_recover/tsk_recover.vcxproj    |  1 +
 9 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/bindings/java/build-windows.xml b/bindings/java/build-windows.xml
index 375e389d1..0356ce1af 100644
--- a/bindings/java/build-windows.xml
+++ b/bindings/java/build-windows.xml
@@ -45,22 +45,25 @@
 	
 	<target name="copyWinLibs64" depends="checkLibDirs" if="win64.exists">
 		<property name="win64dir" location="${basedir}/../../win32/x64/Release" />
+		
 		<fileset dir="${win64dir}" id="win64dlls">
 			<include name="*.dll" />
 		</fileset>
-		<copy todir="${amd64}/win">
-			<fileset refid="win64dlls" />
-		</copy>
-		<copy todir="${x86_64}/win">
-			<fileset refid="win64dlls" />
-		</copy>
 		<fileset dir="${crt}/win64" id="crt64dlls">
 			<include name="*.dll" />
 		</fileset>
-		<copy todir="${amd64}/win">
+		
+		<copy todir="${amd64}/win" overwrite="true">
+			<fileset refid="win64dlls" />
+		</copy>
+		<copy todir="${amd64}/win" overwrite="true">
 			<fileset refid="crt64dlls" />
 		</copy>
-		<copy todir="${x86_64}/win">
+		
+		<copy todir="${x86_64}/win" overwrite="true">
+			<fileset refid="win64dlls" />
+		</copy>		
+		<copy todir="${x86_64}/win" overwrite="true">
 			<fileset refid="crt64dlls" />
 		</copy>
 	</target>
@@ -70,26 +73,30 @@
 		<fileset dir="${win32dir}" id="win32dlls">
 			<include name="*.dll" />
 		</fileset>
-		<copy todir="${i386}/win">
+		<fileset dir="${crt}/win32" id="crt32dlls">
+			<include name="*.dll" />
+		</fileset>
+		
+		<copy todir="${i386}/win" overwrite="true">
 			<fileset refid="win32dlls" />
 		</copy>
-		<copy todir="${x86}/win">
-			<fileset refid="win32dlls" />
+		<copy todir="${i386}/win" overwrite="true">
+			<fileset refid="crt32dlls" />
 		</copy>
-		<copy todir="${i586}/win">
+		
+		<copy todir="${x86}/win" overwrite="true">
 			<fileset refid="win32dlls" />
 		</copy>
-		<fileset dir="${crt}/win32" id="crt32dlls">
-			<include name="*.dll" />
-		</fileset>
-		<copy todir="${i386}/win">
+		<copy todir="${x86}/win" overwrite="true">
 			<fileset refid="crt32dlls" />
 		</copy>
-		<copy todir="${x86}/win">
-			<fileset refid="crt32dlls" />
+		
+		<copy todir="${i586}/win" overwrite="true">
+			<fileset refid="win32dlls" />
 		</copy>
-		<copy todir="${i586}/win">
+		<copy todir="${i586}/win" overwrite="true">
 			<fileset refid="crt32dlls" />
-		</copy>
+		</copy>		
+		
 	</target>
 </project>
diff --git a/tsk/base/tsk_os.h b/tsk/base/tsk_os.h
index 9caf15f3b..e2ab09480 100644
--- a/tsk/base/tsk_os.h
+++ b/tsk/base/tsk_os.h
@@ -98,7 +98,11 @@ typedef int mode_t;
 // if python.h is included
 #if !defined( HAVE_SSIZE_T )
 #define HAVE_SSIZE_T
-typedef int ssize_t;
+#if _WIN64
+typedef int64_t ssize_t;
+#else
+typedef int32_t ssize_t;
+#endif
 #endif
 
 // remap some of the POSIX functions
diff --git a/tsk/fs/fs_file.c b/tsk/fs/fs_file.c
index c737758e2..5b01f03a4 100644
--- a/tsk/fs/fs_file.c
+++ b/tsk/fs/fs_file.c
@@ -609,9 +609,10 @@ tsk_fs_file_hash_calc_callback(TSK_FS_FILE * file, TSK_OFF_T offset,
  * @param a_flags Indicates which hash algorithm(s) to use
  * @returns 0 on success or 1 on error
  */
-extern uint8_t tsk_fs_file_hash_calc(TSK_FS_FILE * a_fs_file, TSK_FS_HASH_RESULTS * a_hash_results, TSK_BASE_HASH_ENUM a_flags){
+extern uint8_t 
+    tsk_fs_file_hash_calc(TSK_FS_FILE * a_fs_file, TSK_FS_HASH_RESULTS * a_hash_results, TSK_BASE_HASH_ENUM a_flags)
+{
 	TSK_FS_HASH_DATA hash_data;
-	int i;
 
     if ((a_fs_file == NULL) || (a_fs_file->fs_info == NULL)
         || (a_fs_file->meta == NULL)) {
diff --git a/tsk/img/img_io.c b/tsk/img/img_io.c
index d69a795d5..df783ed8e 100644
--- a/tsk/img/img_io.c
+++ b/tsk/img/img_io.c
@@ -92,7 +92,7 @@ tsk_img_read(TSK_IMG_INFO * a_img_info, TSK_OFF_T a_off,
             }
             else {
                 memcpy(a_buf, buf2, a_len);
-                nbytes = a_len;
+                nbytes = (ssize_t)a_len;
             }
             free(buf2);
         }
@@ -119,7 +119,7 @@ tsk_img_read(TSK_IMG_INFO * a_img_info, TSK_OFF_T a_off,
 
     // Protect against INT64_MAX + INT64_MAX > value
     if (((TSK_OFF_T) len2 > a_img_info->size)
-        || (a_off >= (a_img_info->size - len2))) {
+        || (a_off >= (a_img_info->size - (TSK_OFF_T)len2))) {
         len2 = (size_t) (a_img_info->size - a_off);
     }
 
@@ -188,7 +188,7 @@ tsk_img_read(TSK_IMG_INFO * a_img_info, TSK_OFF_T a_off,
         // Read a full cache block or the remaining data.
         read_size = TSK_IMG_INFO_CACHE_LEN;
 
-        if ((a_img_info->cache_off[cache_next] + read_size) >
+        if ((a_img_info->cache_off[cache_next] + (TSK_OFF_T)read_size) >
             a_img_info->size) {
             read_size =
                 (size_t) (a_img_info->size -
diff --git a/win32/BUILDING.txt b/win32/BUILDING.txt
index d1bf6f3fa..f0d04218e 100755
--- a/win32/BUILDING.txt
+++ b/win32/BUILDING.txt
@@ -2,6 +2,10 @@ This file describes how to build TSK using Visual Studio (see README_win32.txt f
 
     http://www.microsoft.com/express/vc/
 
+Visual Studio 2010 Express cannot make 64-bit versions of the executables.  To do that, you must download and install an additional SDK:
+
+    http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx
+
 The Visual Studio Solution file has three build targets: Debug, Debug_NoLibs, and Release.  Debug and Release require that libewf exists (to provide support for E01 image files) and that zlib exists (to provide support for HFS+ compressed data).   Debug_NoLibs does not require libewf or zlib and you should be able to compile Debug_NoLibs without any additional setup.
 
 The steps below outline the process required to compile the Debug and Release targets.
@@ -9,7 +13,7 @@ The steps below outline the process required to compile the Debug and Release ta
 1) Download libewf-20130128 (or later) from:
     http://sourceforge.net/projects/libewf/
 
-2) Open archive file and follow the README instructions in libewf to build libewf_dll (at the time of this writing, that includes downloading the zlib dll). Note that TSK will use only the Release version of libewf_dll.  Later steps also depend on the zlib dll being built inside of libewf. 
+2) Open archive file and follow the README instructions in libewf to build libewf_dll (at the time of this writing, that includes downloading the zlib dll). Note that TSK will use only the Release version of libewf_dll.  Later steps also depend on the zlib dll being built inside of libewf.  Note that libewf will need to be converted to Visual Studio 2010 and be upgraded to support a 64-bit build.
 
 3) Set the LIBEWF_HOME environment variable to point to the libewf folder that you created and built in step 2. 
 
@@ -17,7 +21,7 @@ The steps below outline the process required to compile the Debug and Release ta
 
 5) Open the TSK Visual Studio Solution file, tsk-win.sln, in the win32 directory. 
 
-6) Compile a Debug, Debug_NoLibs, or Release version of the libraries and executables.  The resulting libraries and executables will be put in win32/Debug, win32/Debug_NoLibs, or win32/Release as appropriate.
+6) Compile a Debug, Debug_NoLibs, or Release version of the libraries and executables.  The resulting libraries and executables on a 32-bit build will be put in win32/Debug, win32/Debug_NoLibs, or win32/Release as appropriate.  A 64-bit build will put them into the win32/x64 folders. You can change the type of build using the pulldown in Visual Studio and switching between Win32 and x64.
 
 7) Note that the libraries and executables will depend on the libewf and zlib dll files (which are copied to the TSK build directories). 
 
diff --git a/win32/tsk_comparedir/tsk_compare.vcxproj b/win32/tsk_comparedir/tsk_compare.vcxproj
index 817f8b76b..2c203b7a0 100755
--- a/win32/tsk_comparedir/tsk_compare.vcxproj
+++ b/win32/tsk_comparedir/tsk_compare.vcxproj
@@ -37,6 +37,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_NoLibs|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
@@ -46,7 +47,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <PlatformToolset>Windows7.1SDK</PlatformToolset>
   </PropertyGroup>
@@ -56,7 +57,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
diff --git a/win32/tsk_gettimes/tsk_gettimes.vcxproj b/win32/tsk_gettimes/tsk_gettimes.vcxproj
index e059cb5b9..c25e50541 100755
--- a/win32/tsk_gettimes/tsk_gettimes.vcxproj
+++ b/win32/tsk_gettimes/tsk_gettimes.vcxproj
@@ -108,6 +108,7 @@
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug_NoLibs|x64'">$(Configuration)\</IntDir>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug_NoLibs|Win32'">true</LinkIncremental>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug_NoLibs|x64'">true</LinkIncremental>
+    <IgnoreImportLibrary Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</IgnoreImportLibrary>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -177,6 +178,8 @@
       <AdditionalDependencies>libewf.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>$(LIBEWF_HOME)\msvscpp\release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <GenerateDebugInformation>true</GenerateDebugInformation>
+      <OptimizeReferences>true</OptimizeReferences>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_NoLibs|Win32'">
diff --git a/win32/tsk_loaddb/tsk_loaddb.vcxproj b/win32/tsk_loaddb/tsk_loaddb.vcxproj
index 52e526724..74a66a510 100755
--- a/win32/tsk_loaddb/tsk_loaddb.vcxproj
+++ b/win32/tsk_loaddb/tsk_loaddb.vcxproj
@@ -37,7 +37,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_NoLibs|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>NotSet</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
@@ -47,7 +47,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>MultiByte</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
     <WholeProgramOptimization>true</WholeProgramOptimization>
     <PlatformToolset>Windows7.1SDK</PlatformToolset>
   </PropertyGroup>
@@ -57,7 +57,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>NotSet</CharacterSet>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
diff --git a/win32/tsk_recover/tsk_recover.vcxproj b/win32/tsk_recover/tsk_recover.vcxproj
index 92834de08..605fed863 100755
--- a/win32/tsk_recover/tsk_recover.vcxproj
+++ b/win32/tsk_recover/tsk_recover.vcxproj
@@ -39,6 +39,7 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_NoLibs|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <CLRSupport>false</CLRSupport>
+    <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-- 
GitLab