Skip to content

Commit

Permalink
Initial version. Opens and closes PST files.
Browse files Browse the repository at this point in the history
  • Loading branch information
uckelman committed Oct 27, 2011
0 parents commit 105bb80
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Makefile
@@ -0,0 +1,41 @@

INCDIR := include
SRCDIR := src
OBJDIR := bin
DEPDIR := bin
BINDIR := bin

CXX := g++
CPPFLAGS := -c -O -g -pg -W -Wall -Wextra -pedantic -pipe -MMD -MP
#CPPFLAGS := -c -O3 -W -Wall -Wextra -pedantic -pipe -MMD -MP
INCLUDES := -I$(INCDIR)
LDLIBS := -lstdc++ -lpff

SOURCES := main.cpp
OBJECTS := $(SOURCES:.cpp=.o)
DEPS := $(OBJECTS:.o=.d)

SOURCES := $(SOURCES:%=$(SRCDIR)/%)
OBJECTS := $(OBJECTS:%=$(OBJDIR)/%)
DEPS := $(DEPS:%=$(DEPDIR)/%)
BINARY := $(BINDIR)/pstrip

all: $(BINARY)

debug: CPPFLAGS += -g -pg -fprofile-arcs -ftest-coverage
debug: CPPFLAGS := $(filter-out -O3,$(CPPFLAGS))
debug: LDFLAGS += -pg -fprofile-arcs
debug: all

-include $(DEPS)

$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CPPFLAGS) $(INCLUDES) -c -o $@ $<

$(BINARY): $(OBJECTS)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@

clean:
$(RM) $(BINARY) $(OBJECTS) $(DEPS)

.PHONY: all clean debug
77 changes: 77 additions & 0 deletions src/main.cpp
@@ -0,0 +1,77 @@

#include <cstdio>
#include <cstdlib>
#include <exception>
#include <stdexcept>
#include <string>

#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>

#include <libpff.h>


class libpff_error: public std::exception {
public:
libpff_error(libpff_error_t* error) {
char buf[MAXLEN];
libpff_error_sprint(error, buf, MAXLEN);
libpff_error_free(&error);
Msg = buf;
}

virtual ~libpff_error() throw() {}

virtual const char* what() const throw() { return Msg.c_str(); }

private:
static const size_t MAXLEN = 1024;

std::string Msg;
};

libpff_file_t* create_file() {
libpff_file_t* file = 0;
libpff_error_t* error = 0;

if (libpff_file_initialize(&file, &error) != 1) {
throw libpff_error(error);
}

return file;
}

void destroy_file(libpff_file_t* file) {
libpff_error_t* error = 0;
if (libpff_file_free(&file, &error) != 1) {
throw libpff_error(error);
}
}

int main(int argc, char** argv) {
if (argc != 2) {
throw std::runtime_error("Wrong number arguments");
}

libpff_error_t* error = 0;

boost::shared_ptr<libpff_file_t> file(create_file(), &destroy_file);

try {
if (libpff_file_open(file.get(), argv[1], LIBPFF_OPEN_READ, &error) != 1) {
throw libpff_error(error);
}

// do something here

if (libpff_file_close(file.get(), &error) != 1) {
throw libpff_error(error);
}
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

0 comments on commit 105bb80

Please sign in to comment.