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>
34 using namespace Barry
;
38 int logical
, major
, minor
;
39 const char *Version
= Barry::Version(logical
, major
, minor
);
42 << "brecsum - Generate SHA1 sums of raw Blackberry database records.\n"
43 << " Copyright 2008-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
44 << " Using: " << Version
<< "\n"
46 << " -d db Read database 'db' and sum all its records.\n"
47 << " Can be used multiple times to fetch more than one DB\n"
49 << " -i Include DB Name, Type, and Unique record IDs in the checksums\n"
50 << " -p pin PIN of device to talk with\n"
51 << " If only one device is plugged in, this flag is optional\n"
52 << " -P pass Simplistic method to specify device password\n"
53 << " -v Dump protocol data during operation\n"
57 int main(int argc
, char *argv
[])
61 cout
.sync_with_stdio(true); // leave this on, since libusb uses
62 // stdio for debug messages
71 vector
<string
> dbNames
;
73 // process command line options
75 int cmd
= getopt(argc
, argv
, "d:hip:P:v");
81 case 'd': // show dbname
82 dbNames
.push_back(string(optarg
));
85 case 'i': // Include IDs
89 case 'p': // Blackberry PIN
90 pin
= strtoul(optarg
, NULL
, 16);
93 case 'P': // Device password
97 case 'v': // data dump on
108 // Display usage info if user appears confused
109 if( !dbNames
.size() ) {
114 // Initialize the barry library. Must be called before
116 Barry::Init(data_dump
);
118 // Probe the USB bus for Blackberry devices and display.
120 int activeDevice
= probe
.FindActive(pin
);
121 if( activeDevice
== -1 ) {
122 cerr
<< "No device selected, or PIN not found" << endl
;
126 // Create our controller object
127 Barry::Controller
con(probe
.Get(activeDevice
));
128 Barry::Mode::Desktop
desktop(con
);
130 // Sum all specified databases
131 if( dbNames
.size() ) {
132 vector
<string
>::iterator b
= dbNames
.begin();
133 ChecksumParser
parser(include_ids
);
135 desktop
.Open(password
.c_str());
136 for( ; b
!= dbNames
.end(); b
++ ) {
137 unsigned int id
= desktop
.GetDBID(*b
);
138 desktop
.LoadDatabase(id
, parser
);
143 catch( std::exception
&e
) {
144 std::cerr
<< e
.what() << endl
;