3 /// Generate SHA1 sums of raw Blackberry database records.
4 /// This is mostly useful for data verification during testing.
8 Copyright (C) 2008-2011, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include <barry/barry.h>
33 using namespace Barry
;
38 const char *Version
= Barry::Version(major
, minor
);
41 << "brecsum - Generate SHA1 sums of raw Blackberry database records.\n"
42 << " Copyright 2008-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
43 << " Using: " << Version
<< "\n"
45 << " -d db Read database 'db' and sum all its records.\n"
46 << " Can be used multiple times to fetch more than one DB\n"
48 << " -i Include DB Name, Type, and Unique record IDs in the checksums\n"
49 << " -p pin PIN of device to talk with\n"
50 << " If only one device is plugged in, this flag is optional\n"
51 << " -P pass Simplistic method to specify device password\n"
52 << " -v Dump protocol data during operation\n"
56 int main(int argc
, char *argv
[])
60 cout
.sync_with_stdio(true); // leave this on, since libusb uses
61 // stdio for debug messages
70 vector
<string
> dbNames
;
72 // process command line options
74 int cmd
= getopt(argc
, argv
, "d:hip:P:v");
80 case 'd': // show dbname
81 dbNames
.push_back(string(optarg
));
84 case 'i': // Include IDs
88 case 'p': // Blackberry PIN
89 pin
= strtoul(optarg
, NULL
, 16);
92 case 'P': // Device password
96 case 'v': // data dump on
107 // Display usage info if user appears confused
108 if( !dbNames
.size() ) {
113 // Initialize the barry library. Must be called before
115 Barry::Init(data_dump
);
117 // Probe the USB bus for Blackberry devices and display.
119 int activeDevice
= probe
.FindActive(pin
);
120 if( activeDevice
== -1 ) {
121 cerr
<< "No device selected, or PIN not found" << endl
;
125 // Create our controller object
126 Barry::Controller
con(probe
.Get(activeDevice
));
127 Barry::Mode::Desktop
desktop(con
);
129 // Sum all specified databases
130 if( dbNames
.size() ) {
131 vector
<string
>::iterator b
= dbNames
.begin();
132 ChecksumParser
parser(include_ids
);
134 desktop
.Open(password
.c_str());
135 for( ; b
!= dbNames
.end(); b
++ ) {
136 unsigned int id
= desktop
.GetDBID(*b
);
137 desktop
.LoadDatabase(id
, parser
);
142 catch( std::exception
&e
) {
143 std::cerr
<< e
.what() << endl
;