lib+tools: updated strings to support i18n translations
[barry.git] / tools / bidentify.cc
blob52012ef47ffb4ee353b469208442c06819083b68
1 ///
2 /// \file bidentify.cc
3 /// Tool for probing identifying Blackberry devices
4 ///
6 /*
7 Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <barry/barry.h>
23 #include <iostream>
24 #include <iomanip>
25 #include "barrygetopt.h"
26 #include "i18n.h"
28 using namespace std;
29 using namespace Barry;
31 void Usage()
33 int logical, major, minor;
34 const char *Version = Barry::Version(logical, major, minor);
36 cerr << string_vprintf(
37 _("bidentify - USB Blackberry Identifier Tool\n"
38 " Copyright 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
39 " Using: %s\n"
40 "\n"
41 " -B bus Specify which USB bus to search on\n"
42 " -N dev Specify which system device, using system specific string\n"
43 "\n"
44 " -c If used with -m, show both hex and dec where possible\n"
45 " -m Also show the device's ESN / MEID / IMEI\n"
46 " -h This help\n"
47 " -v Dump protocol data during operation\n"), Version)
48 << endl;
51 std::string FetchMEID(Barry::Mode::Desktop &desktop)
53 using namespace Barry;
55 unsigned int dbId = desktop.GetDBID(HandheldAgent::GetDBName());
56 RecordStateTable state;
57 desktop.GetRecordStateTable(dbId, state);
59 unsigned int recId = HandheldAgent::GetMEIDRecordId();
61 RecordStateTable::IndexType meid_index;
62 if( state.GetIndex(recId, &meid_index) ) {
63 NullStore<HandheldAgent> store;
64 RecordParser<HandheldAgent, NullStore<HandheldAgent> > parser(store);
65 desktop.GetRecord(dbId, meid_index, parser);
66 return parser.GetRecord().MEID;
68 else {
69 return string();
73 int main(int argc, char *argv[])
75 INIT_I18N(PACKAGE);
77 cout.sync_with_stdio(true); // leave this on, since libusb uses
78 // stdio for debug messages
80 try {
82 bool data_dump = false,
83 get_meid = false,
84 show_both = false;
85 string busname;
86 string devname;
88 // process command line options
89 for(;;) {
90 int cmd = getopt(argc, argv, "B:hN:vmc");
91 if( cmd == -1 )
92 break;
94 switch( cmd )
96 case 'B': // busname
97 busname = optarg;
98 break;
100 case 'N': // Devname
101 devname = optarg;
102 break;
104 case 'c': // show both hex and dec
105 show_both = true;
106 break;
108 case 'm': // get meid / esn
109 get_meid = true;
110 break;
112 case 'v': // data dump on
113 data_dump = true;
114 break;
116 case 'h': // help
117 default:
118 Usage();
119 return 0;
123 Barry::Init(data_dump, &std::cerr);
124 Barry::Probe probe(busname.c_str(), devname.c_str());
126 // show all successfully found devices
127 for( int i = 0; i < probe.GetCount(); i++ ) {
128 const ProbeResult &pr = probe.Get(i);
129 cout << pr.m_pin.Str() << ", "
130 << pr.m_description;
132 if( get_meid ) try {
133 Barry::Controller con(pr);
134 Barry::Mode::Desktop desktop(con);
135 desktop.Open();
137 // store as temporary in case of exceptions
138 string meid = FetchMEID(desktop);
139 cout << ", " << meid;
141 if( show_both ) {
142 if( HandheldAgent::IsESNHex(meid) ) {
143 cout << " (" << HandheldAgent::ESNHex2Dec(meid) << ")";
145 else if( HandheldAgent::IsESNDec(meid) ) {
146 cout << " (" << HandheldAgent::ESNDec2Hex(meid) << ")";
150 catch( Barry::BadPassword & ) {
151 // ignore password protected devices
153 catch( Barry::Error &e ) {
154 // output on cerr so as not to mess up
155 // the identify output
156 cerr << _("Error on PIN: ") << pr.m_pin.Str() << ": " << e.what() << endl;
159 // finish the identity line
160 cout << endl;
163 return probe.GetFailCount();
166 catch( std::exception &e ) {
167 cerr << _("exception caught: ") << e.what() << endl;
168 return 1;