brecsum.cc

Go to the documentation of this file.
00001 ///
00002 /// \file       brecsum.cc
00003 ///             Generate SHA1 sums of raw Blackberry database records.
00004 ///             This is mostly useful for data verification during testing.
00005 ///
00006 
00007 /*
00008     Copyright (C) 2008-2011, Net Direct Inc. (http://www.netdirect.ca/)
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #include <barry/barry.h>
00024 #include <iomanip>
00025 #include <iostream>
00026 #include <vector>
00027 #include <string>
00028 #include <getopt.h>
00029 #include "i18n.h"
00030 #include "brecsum.h"
00031 
00032 using namespace std;
00033 using namespace Barry;
00034 
00035 void Usage()
00036 {
00037    int major, minor;
00038    const char *Version = Barry::Version(major, minor);
00039 
00040    cerr
00041    << "brecsum - Generate SHA1 sums of raw Blackberry database records.\n"
00042    << "        Copyright 2008-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
00043    << "        Using: " << Version << "\n"
00044    << "\n"
00045    << "   -d db     Read database 'db' and sum all its records.\n"
00046    << "             Can be used multiple times to fetch more than one DB\n"
00047    << "   -h        This help\n"
00048    << "   -i        Include DB Name, Type, and Unique record IDs in the checksums\n"
00049    << "   -p pin    PIN of device to talk with\n"
00050    << "             If only one device is plugged in, this flag is optional\n"
00051    << "   -P pass   Simplistic method to specify device password\n"
00052    << "   -v        Dump protocol data during operation\n"
00053    << endl;
00054 }
00055 
00056 int main(int argc, char *argv[])
00057 {
00058         INIT_I18N(PACKAGE);
00059 
00060         cout.sync_with_stdio(true);     // leave this on, since libusb uses
00061                                         // stdio for debug messages
00062 
00063         try {
00064 
00065                 uint32_t pin = 0;
00066                 bool
00067                         data_dump = false,
00068                         include_ids = false;
00069                 string password;
00070                 vector<string> dbNames;
00071 
00072                 // process command line options
00073                 for(;;) {
00074                         int cmd = getopt(argc, argv, "d:hip:P:v");
00075                         if( cmd == -1 )
00076                                 break;
00077 
00078                         switch( cmd )
00079                         {
00080                         case 'd':       // show dbname
00081                                 dbNames.push_back(string(optarg));
00082                                 break;
00083 
00084                         case 'i':       // Include IDs
00085                                 include_ids = true;
00086                                 break;
00087 
00088                         case 'p':       // Blackberry PIN
00089                                 pin = strtoul(optarg, NULL, 16);
00090                                 break;
00091 
00092                         case 'P':       // Device password
00093                                 password = optarg;
00094                                 break;
00095 
00096                         case 'v':       // data dump on
00097                                 data_dump = true;
00098                                 break;
00099 
00100                         case 'h':       // help
00101                         default:
00102                                 Usage();
00103                                 return 0;
00104                         }
00105                 }
00106 
00107                 // Display usage info if user appears confused
00108                 if( !dbNames.size() ) {
00109                         Usage();
00110                         return 0;
00111                 }
00112 
00113                 // Initialize the barry library.  Must be called before
00114                 // anything else.
00115                 Barry::Init(data_dump);
00116 
00117                 // Probe the USB bus for Blackberry devices and display.
00118                 Barry::Probe probe;
00119                 int activeDevice = probe.FindActive(pin);
00120                 if( activeDevice == -1 ) {
00121                         cerr << "No device selected, or PIN not found" << endl;
00122                         return 1;
00123                 }
00124 
00125                 // Create our controller object
00126                 Barry::Controller con(probe.Get(activeDevice));
00127                 Barry::Mode::Desktop desktop(con);
00128 
00129                 // Sum all specified databases
00130                 if( dbNames.size() ) {
00131                         vector<string>::iterator b = dbNames.begin();
00132                         ChecksumParser parser(include_ids);
00133 
00134                         desktop.Open(password.c_str());
00135                         for( ; b != dbNames.end(); b++ ) {
00136                                 unsigned int id = desktop.GetDBID(*b);
00137                                 desktop.LoadDatabase(id, parser);
00138                         }
00139                 }
00140 
00141         }
00142         catch( std::exception &e ) {
00143                 std::cerr << e.what() << endl;
00144                 return 1;
00145         }
00146 
00147         return 0;
00148 }
00149 

Generated on Tue Mar 1 17:50:14 2011 for Barry by  doxygen 1.5.6