Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version. Opens and closes PST files.
- Loading branch information
0 parents
commit 105bb80
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |