From 1a00e1c04a88b2f3d9f3b0ad40aca10461719776 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Thu, 1 May 2008 21:45:36 -0400 Subject: [PATCH] Added tools/brecsum program. brecsum calculates SHA1 checksums on database records, for testing. --- ChangeLog | 2 + tools/Makefile.am | 6 ++- tools/brecsum.cc | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 tools/brecsum.cc diff --git a/ChangeLog b/ChangeLog index 60603bf7..297b6657 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ Release: version 0.13 - 2008/05/?? - fixed missing fields in the Calendar record build process - added Calendar to list of Builders in tools/btool... it is now possible to run: btool -s "Calendar" -f datafile + - added tools/brecsum program, which calculates SHA1 checksums + on database records, for testing 2008/04/29 - applied Jason Thomas's ACLOCAL_FLAGS patch to make autoreconf work again... Thanks! diff --git a/tools/Makefile.am b/tools/Makefile.am index 13bed000..612b1328 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -5,7 +5,7 @@ INCLUDES = $(LIBUSB_CFLAGS) #AM_CXXFLAGS = -ansi -Wall -fno-strict-aliasing -g AM_CXXFLAGS = -ansi -Wall -g -bin_PROGRAMS = btool bidentify upldif btranslate bktrans +bin_PROGRAMS = btool bidentify upldif btranslate bktrans brecsum if WITH_BOOST bin_PROGRAMS += bs11nread endif @@ -55,3 +55,7 @@ breset_LDADD = $(LIBUSB_LIBS) pppob_SOURCES = pppob.cc pppob_LDADD = ../src/libbarry.la $(LIBUSB_LIBS) -lpthread +brecsum_CXXFLAGS = $(OPENSSL_CFLAGS) +brecsum_SOURCES = brecsum.cc +brecsum_LDADD = ../src/libbarry.la $(LIBUSB_LIBS) $(OPENSSL_LIBS) -lpthread + diff --git a/tools/brecsum.cc b/tools/brecsum.cc new file mode 100644 index 00000000..9849634c --- /dev/null +++ b/tools/brecsum.cc @@ -0,0 +1,150 @@ +/// +/// \file brecsum.cc +/// Generate SHA1 sums of raw Blackberry database records. +/// This is mostly useful for data verification during testing. +/// + +/* + Copyright (C) 2008, Net Direct Inc. (http://www.netdirect.ca/) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License in the COPYING file at the + root directory of this project for more details. +*/ + +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace Barry; + +void Usage() +{ + int major, minor; + const char *Version = Barry::Version(major, minor); + + cerr + << "brecsum - Generate SHA1 sums of raw Blackberry database records.\n" + << " Copyright 2008, Net Direct Inc. (http://www.netdirect.ca/)\n" + << " Using: " << Version << "\n" + << "\n" + << " -d db Read database 'db' and sum all its records.\n" + << " Can be used multiple times to fetch more than one DB\n" + << " -h This help\n" + << " -p pin PIN of device to talk with\n" + << " If only one device is plugged in, this flag is optional\n" + << " -P pass Simplistic method to specify device password\n" + << " -v Dump protocol data during operation\n" + << endl; +} + +class ChecksumParser : public Barry::Parser +{ +public: + virtual void ParseFields(const Barry::Data &data, size_t &offset) + { + unsigned char sha1[SHA_DIGEST_LENGTH]; + SHA1(data.GetData() + offset, data.GetSize() - offset, sha1); + + for( int i = 0; i < SHA_DIGEST_LENGTH; i++ ) { + cout << hex << setfill('0') << setw(2) + << (unsigned int) sha1[i]; + } + cout << endl; + } +}; + +int main(int argc, char *argv[]) +{ + cout.sync_with_stdio(true); // leave this on, since libusb uses + // stdio for debug messages + + try { + + uint32_t pin = 0; + bool + data_dump = false; + string password; + vector dbNames; + + // process command line options + for(;;) { + int cmd = getopt(argc, argv, "d:hp:P:v"); + if( cmd == -1 ) + break; + + switch( cmd ) + { + case 'd': // show dbname + dbNames.push_back(string(optarg)); + break; + + case 'p': // Blackberry PIN + pin = strtoul(optarg, NULL, 16); + break; + + case 'P': // Device password + password = optarg; + break; + + case 'v': // data dump on + data_dump = true; + break; + + case 'h': // help + default: + Usage(); + return 0; + } + } + + // Initialize the barry library. Must be called before + // anything else. + Barry::Init(data_dump); + + // Probe the USB bus for Blackberry devices and display. + Barry::Probe probe; + int activeDevice = probe.FindActive(pin); + if( activeDevice == -1 ) { + cerr << "No device selected, or PIN not found" << endl; + return 1; + } + + // Create our controller object + Barry::Controller con(probe.Get(activeDevice)); + Barry::Mode::Desktop desktop(con); + + // Sum all specified databases + if( dbNames.size() ) { + vector::iterator b = dbNames.begin(); + ChecksumParser parser; + + desktop.Open(password.c_str()); + for( ; b != dbNames.end(); b++ ) { + unsigned int id = desktop.GetDBID(*b); + desktop.LoadDatabase(id, parser); + } + } + + } + catch( std::exception &e ) { + std::cerr << e.what() << endl; + return 1; + } + + return 0; +} + -- 2.11.4.GIT