Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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);
00061
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
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':
00081 dbNames.push_back(string(optarg));
00082 break;
00083
00084 case 'i':
00085 include_ids = true;
00086 break;
00087
00088 case 'p':
00089 pin = strtoul(optarg, NULL, 16);
00090 break;
00091
00092 case 'P':
00093 password = optarg;
00094 break;
00095
00096 case 'v':
00097 data_dump = true;
00098 break;
00099
00100 case 'h':
00101 default:
00102 Usage();
00103 return 0;
00104 }
00105 }
00106
00107
00108 if( !dbNames.size() ) {
00109 Usage();
00110 return 0;
00111 }
00112
00113
00114
00115 Barry::Init(data_dump);
00116
00117
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
00126 Barry::Controller con(probe.Get(activeDevice));
00127 Barry::Mode::Desktop desktop(con);
00128
00129
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