3 /// Tool for probing identifying Blackberry devices
7 Copyright (C) 2005-2011, 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>
29 using namespace Barry
;
33 int logical
, major
, minor
;
34 const char *Version
= Barry::Version(logical
, major
, minor
);
37 << "bidentify - USB Blackberry Identifier Tool\n"
38 << " Copyright 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
39 << " Using: " << Version
<< "\n"
41 << " -B bus Specify which USB bus to search on\n"
42 << " -N dev Specify which system device, using system specific string\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"
47 << " -v Dump protocol data during operation\n"
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
;
73 int main(int argc
, char *argv
[])
77 cout
.sync_with_stdio(true); // leave this on, since libusb uses
78 // stdio for debug messages
82 bool data_dump
= false,
88 // process command line options
90 int cmd
= getopt(argc
, argv
, "B:hN:vmc");
104 case 'c': // show both hex and dec
108 case 'm': // get meid / esn
112 case 'v': // data dump on
123 Barry::Init(data_dump
);
124 Barry::Probe
probe(busname
.c_str(), devname
.c_str());
126 // show any errors during probe first
127 if( probe
.GetFailCount() ) {
128 cerr
<< "Blackberry device errors with errors during probe:" << endl
;
129 for( int i
= 0; i
< probe
.GetFailCount(); i
++ ) {
130 cerr
<< probe
.GetFailMsg(i
) << endl
;
134 // show all successfully found devices
135 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
136 const ProbeResult
&pr
= probe
.Get(i
);
137 cout
<< pr
.m_pin
.Str() << ", "
141 Barry::Controller
con(pr
);
142 Barry::Mode::Desktop
desktop(con
);
145 // store as temporary in case of exceptions
146 string meid
= FetchMEID(desktop
);
147 cout
<< ", " << meid
;
150 if( HandheldAgent::IsESNHex(meid
) ) {
151 cout
<< " (" << HandheldAgent::ESNHex2Dec(meid
) << ")";
153 else if( HandheldAgent::IsESNDec(meid
) ) {
154 cout
<< " (" << HandheldAgent::ESNDec2Hex(meid
) << ")";
158 catch( Barry::BadPassword
& ) {
159 // ignore password protected devices
161 catch( Barry::Error
&e
) {
162 // output on cerr so as not to mess up
163 // the identify output
164 cerr
<< "Error on PIN: " << pr
.m_pin
.Str() << ": " << e
.what() << endl
;
167 // finish the identity line
171 return probe
.GetFailCount();
174 catch( std::exception
&e
) {
175 cerr
<< "exception caught: " << e
.what() << endl
;