How to compile Libewf in Windows using Visual Studio 2010

Introduction

Edit: Ok… as I was going to get some specific error codes to put on here (for searching sake) I was able to compile the solution no problem… Sigh… (Such is the life of compiling Libewf I suppose). The zlib requirement is still there, but I didn’t hit the dependency issue. I’ll leave this up so that I may have it for future reference (or if anybody else has these issues).

Ok, so yet another “how to” compile something posts. Whenever you get good software you always over look this step because generally the classic configure; make; make install; is all you need and you’re rocking and rolling. (you might have to do that a million times for each dependency), but in general its rare to come across something that won’t compile because the actual project file, or whatever organizing it is just completely messed up.

Libewf is probably one of the biggest backbones of the Digital Forensics community as it provides the underlying decompressing software for computer images compressed with Encase software. While this library is a dependency to many other tools it contains its own suite of tools for handling Encase Images. I needed the ability to acquire content in the E01 format so I decided to get the latest and use ewfacquire on a Windows machine. I had forgotten the pains of getting this guy to compile last time, and here I found myself again, having forgotten how I did it.

The Main Problems

There are three problems that plague this solution. A. zlib is missing (and you wouldn’t know it by looking at the solution file in visual studio, nor how to fix it without having a keen eye), B. The dependencies for the projects either are not setup, or they’re setup incorrectly, and C. most importantly its using Visual Studio / Windows.

The biggest problem, naturally, of this software is its using Visual Studio. God shoot me for compiling a C++ program with Visual Studio. Its the most annoying and esoteric setup you could possibly have. Since I did it in college (for one class, I wasn’t a computer science major), I had some idea how to link together projects and roughly what was going on, so I’m the “resident expert” for figuring out jacked up c++ solutions. I’m not sure who is the culprit of this problem. The writer of the software, or me for having to want to use it in Windows. (Probably its more like my problem).

The first problem is zlib. zLib is a library that provides adler32 compression. The source must be downloaded and placed into the proper location. This seems easy and obvious enough to do. Unfortunately unlike every other project/source you aren’t supposed to have it INSIDE the solution’s directory… This is a tricky thing to figure out and you’d only know it by looking at the solution file and look where the shortcuts are pointing to and instead of seeing ../../zlib its ../../../zlib.

The dependencies issue is either a new thing, or I don’t remember fixing it this way last time. The version i was using is the 20130416 version. What appears to be going on is the dependencies aren’t properly linked, it may be an issue with the “conversion” that Visual Studio has to do when you open it for the first time, I’m not entirely sure, I just know the projects are not hooked up correctly. If you do a build, they just don’t seem to link properly and you end up getting a bunch of unresolved symbol errors. Effectively it can’t find the DLL that it was expecting. If you look at the dependencies for the project they’re setup correctly, but its not until you look under references do you find the issue. (I have no idea what the difference is, I just know it fixed the problem).

The Fixes

Zlib

Real simple. Download zlib source and put it located in the same parent directory that contains the libewf source. (Don’t put it in the libewf source directory). Make sure that the folder name lines up with the project references.

Dependencies

For each problematic project you’ll need to add the “references” for them. You’ll have to right click on each project, go to References, add each project reference and make sure it says “copy local” (on the right). I basically kept trying to built it, it would fail then I would see the error, and note which file it was (based on the prefix) and made sure to add that as a reference. Eventually once all the references are in there, it’ll work. You could probably also just make all of them a reference and it might end up working.

Summing up

Well that’s all there is to it. That probably took me half a day of working to figure out and I know other people I work with have tried compiling this guy and none of succeeded. So now I have this as a reference for the next time I try and compile this tool… I should do another on running any libewf tool in Linux…. considering the LD_LIBRARY_PATH is always not set…… (I just gave the solution away).

How to compile SQLite (System.Data.SQLite) on Linux / Mono using XBuild.

Background:

(If you want to read it)

Ok. So I do a lot of development with .Net for computer forensics and I have come to really dislike Windows as a development platform (it could be the worst OS of all time). I have become extremely comfortable and prefer a well personalized VIM setup for doing my development. I guess I’m currently left with that I’m a “Command Line Pwns” kinda guy. I forced myself to learn it, and now… well I think it pays dividends.

As a result I consistently try to work less and less in Windows and more and more in Linux but one of the biggest stumbling blocks for me is that our application is .Net and we haven’t spent much time (only me) compiling and running in Linux. I have gotten it to work a few different times, but for some reason or another I would walk away from making it work. SQLite has been one of the biggest pain in the rumps ever. Every new version (because I start this process over and redownload the latest) requires me to compile this thing, or try to work it into the solution, and its always, always been a serious pain. The code works great, zero documentation. (Thanks). I finally found out how to compile and get running the latest SQLite .NET (it has changed recently) and it drove me to create this blog to get it out there, so somebody else could not waste 2 or 3 days trying to do it. Nowhere on their site today has the information to build and deploy a Mono / Linux setup, except a slightly cryptic response in a trouble ticket. (How nice). Also I digged around through some of the text files and eventually found out why things weren’t working.

Effectively now you’ll see that they’re pushing to not have a consolidated dll that has the native C++ sqlite code attached to it. As of Sept 26, 2013, if you go to the main System.Data.SQLite website http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki you will see the explanation of how to setup your solution / output for this to work. This deals with x86 and x64 deployed solutions. There is this website that some build instructions on it http://system.data.sqlite.org/index.html/doc/trunk/www/build.wiki . Nearly none of this website makes much sense to me because it wasn’t written with Mono or Linux in mind. Terrific. Note all of the MSBuild comments. There is no real indications about anything else going on with all the projects in the source (there is alot).

How System.Data.SQLite (SQLite) is Setup

Ok so this is what you need to know regarding a Windows and Linux System.Data.SQLite deployment.

Windows:

You need System.Data.SQLite.dll and you need two directories x86 and x64. These have SQLite.Interop.dll which is pre-compiled for the two platforms. This provided to you on the website, and I won’t go any further than that.

Linux:

You will end up with ONLY System.Data.SQLite.dll and the native sqlite3 binary. (You can get sqlite3 however you please, but it will eventually end up in your output directory for your product).

What and How to Build:

Ok, so immediately do not attempt to build ANY of the projects in the downloaded source. There is only ONE project you need to worry about. In the folder System.Data.SQLite you will find the various versions of System.Data.SQLite.20XX.csproj I can’t comment about them, but i used 2010 in this case. This is the ONLY project you need to get to work. (This is the managed only dll).

You will not be building any other project. (I guess the Linq can be built, but I don’t use it. I tried just now and hit some compiling errors trying to find System.Data.Entity, entity framework, why its not in the gac i have no idea, don’t care).

It is important not to waste your time building anything else, because it WON”T BUILD. They’re using Visual Studio with C++ projects and all sorts of other junk. Don’t even try bringing the solution into monodevelop. You’ll want to shoot yourself twice. (Once for using monodevelop and 2nd because the solution is so totally messed up up when its imported).

Don’t just try and run xbuild on the project because you need to have some added parameters that change whats put into this dll. You’ll need the following args:

/p:UserInteropDll=false

/p:UseSqliteStandard=true

The first means to not use the SQLite.Interop.dll and the 2nd makes it want to use sqlite3 (inside your executables directory). So this is a basic xbuild statement:

xbuild /p:Configuration=Release /p:UseInteropDll=false /p:UseSqliteStandard=true /home/user/sqlite_src/System.Data.SQLite/System.Data.SQLite.2010.csproj

 

Deployment

Now that you have your binaries you just need to drop them in the directory of your application and that’s it. For deploying beyond your own system you’ll need to account for all these things, (moving sqlite3 over, using xbuild on the System.Data.SQLite source, then moving the results over). This could easily be built into a solution I think, but that’s not what this little tutorial is about, since I needed to do it by hand.

Hopefully this helps at least ONE of you out there because it took me way too long to get this to compile because they’ve made the solution overly complex (in my opinion) and mono is an after thought (as is everything else .NET it would appear).