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 <stdlib.h>
00029 #include "i18n.h"
00030 #include "brecsum.h"
00031 #include "barrygetopt.h"
00032
00033 using namespace std;
00034 using namespace Barry;
00035
00036 void Usage()
00037 {
00038 int logical, major, minor;
00039 const char *Version = Barry::Version(logical, major, minor);
00040
00041 cerr
00042 << "brecsum - Generate SHA1 sums of raw Blackberry database records.\n"
00043 << " Copyright 2008-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
00044 << " Using: " << Version << "\n"
00045 << "\n"
00046 << " -d db Read database 'db' and sum all its records.\n"
00047 << " Can be used multiple times to fetch more than one DB\n"
00048 << " -h This help\n"
00049 << " -i Include DB Name, Type, and Unique record IDs in the checksums\n"
00050 << " -p pin PIN of device to talk with\n"
00051 << " If only one device is plugged in, this flag is optional\n"
00052 << " -P pass Simplistic method to specify device password\n"
00053 << " -v Dump protocol data during operation\n"
00054 << endl;
00055 }
00056
00057 int main(int argc, char *argv[])
00058 {
00059 INIT_I18N(PACKAGE);
00060
00061 cout.sync_with_stdio(true);
00062
00063
00064 try {
00065
00066 uint32_t pin = 0;
00067 bool
00068 data_dump = false,
00069 include_ids = false;
00070 string password;
00071 vector<string> dbNames;
00072
00073
00074 for(;;) {
00075 int cmd = getopt(argc, argv, "d:hip:P:v");
00076 if( cmd == -1 )
00077 break;
00078
00079 switch( cmd )
00080 {
00081 case 'd':
00082 dbNames.push_back(string(optarg));
00083 break;
00084
00085 case 'i':
00086 include_ids = true;
00087 break;
00088
00089 case 'p':
00090 pin = strtoul(optarg, NULL, 16);
00091 break;
00092
00093 case 'P':
00094 password = optarg;
00095 break;
00096
00097 case 'v':
00098 data_dump = true;
00099 break;
00100
00101 case 'h':
00102 default:
00103 Usage();
00104 return 0;
00105 }
00106 }
00107
00108
00109 if( !dbNames.size() ) {
00110 Usage();
00111 return 0;
00112 }
00113
00114
00115
00116 Barry::Init(data_dump);
00117
00118
00119 Barry::Probe probe;
00120 int activeDevice = probe.FindActive(pin);
00121 if( activeDevice == -1 ) {
00122 cerr << "No device selected, or PIN not found" << endl;
00123 return 1;
00124 }
00125
00126
00127 Barry::Controller con(probe.Get(activeDevice));
00128 Barry::Mode::Desktop desktop(con);
00129
00130
00131 if( dbNames.size() ) {
00132 vector<string>::iterator b = dbNames.begin();
00133 ChecksumParser parser(include_ids);
00134
00135 desktop.Open(password.c_str());
00136 for( ; b != dbNames.end(); b++ ) {
00137 unsigned int id = desktop.GetDBID(*b);
00138 desktop.LoadDatabase(id, parser);
00139 }
00140 }
00141
00142 }
00143 catch( std::exception &e ) {
00144 std::cerr << e.what() << endl;
00145 return 1;
00146 }
00147
00148 return 0;
00149 }
00150