menu: added new Keywords tag to .desktop files
[barry.git] / tools / brecsum.cc
blob465a438d601d0e018cfccbe9522d2bd1d54ecb7b
1 ///
2 /// \file brecsum.cc
3 /// Generate SHA1 sums of raw Blackberry database records.
4 /// This is mostly useful for data verification during testing.
5 ///
7 /*
8 Copyright (C) 2008-2013, 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>
24 #include <iomanip>
25 #include <iostream>
26 #include <vector>
27 #include <string>
28 #include <stdlib.h>
29 #include "i18n.h"
30 #include "brecsum.h"
31 #include "barrygetopt.h"
33 using namespace std;
34 using namespace Barry;
36 void Usage()
38 int logical, major, minor;
39 const char *Version = Barry::Version(logical, major, minor);
41 cerr << string_vprintf(
42 _("brecsum - Generate SHA1 sums of raw Blackberry database records.\n"
43 " Copyright 2008-2013, Net Direct Inc. (http://www.netdirect.ca/)\n"
44 " Using: %s\n"
45 "\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"
48 " -h This help\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"),
54 Version)
55 << endl;
58 int main(int argc, char *argv[])
60 INIT_I18N(PACKAGE);
62 cout.sync_with_stdio(true); // leave this on, since libusb uses
63 // stdio for debug messages
65 try {
67 uint32_t pin = 0;
68 bool
69 data_dump = false,
70 include_ids = false;
71 string password;
72 vector<string> dbNames;
74 // process command line options
75 for(;;) {
76 int cmd = getopt(argc, argv, "d:hip:P:v");
77 if( cmd == -1 )
78 break;
80 switch( cmd )
82 case 'd': // show dbname
83 dbNames.push_back(string(optarg));
84 break;
86 case 'i': // Include IDs
87 include_ids = true;
88 break;
90 case 'p': // Blackberry PIN
91 pin = strtoul(optarg, NULL, 16);
92 break;
94 case 'P': // Device password
95 password = optarg;
96 break;
98 case 'v': // data dump on
99 data_dump = true;
100 break;
102 case 'h': // help
103 default:
104 Usage();
105 return 0;
109 // Display usage info if user appears confused
110 if( !dbNames.size() ) {
111 Usage();
112 return 0;
115 // Initialize the barry library. Must be called before
116 // anything else.
117 Barry::Init(data_dump);
119 // Probe the USB bus for Blackberry devices and display.
120 Barry::Probe probe;
121 int activeDevice = probe.FindActive(pin);
122 if( activeDevice == -1 ) {
123 cerr << _("No device selected, or PIN not found")
124 << endl;
125 return 1;
128 // Create our controller object
129 Barry::Controller con(probe.Get(activeDevice));
130 Barry::Mode::Desktop desktop(con);
132 // Sum all specified databases
133 if( dbNames.size() ) {
134 vector<string>::iterator b = dbNames.begin();
135 ChecksumParser parser(include_ids);
137 desktop.Open(password.c_str());
138 for( ; b != dbNames.end(); b++ ) {
139 unsigned int id = desktop.GetDBID(*b);
140 desktop.LoadDatabase(id, parser);
145 catch( std::exception &e ) {
146 std::cerr << e.what() << endl;
147 return 1;
150 return 0;