3 /// Tool for probing identifying Blackberry devices
7 Copyright (C) 2005-2013, 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>
25 #include "barrygetopt.h"
29 using namespace Barry
;
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-2013, Net Direct Inc. (http://www.netdirect.ca/)\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"
46 " -s Also show the device's USB serial number (same as shown by lsusb)\n"
48 " -v Dump protocol data during operation\n"), Version
)
52 std::string
FetchMEID(Barry::Mode::Desktop
&desktop
)
54 using namespace Barry
;
56 unsigned int dbId
= desktop
.GetDBID(HandheldAgent::GetDBName());
57 RecordStateTable state
;
58 desktop
.GetRecordStateTable(dbId
, state
);
60 unsigned int recId
= HandheldAgent::GetMEIDRecordId();
62 RecordStateTable::IndexType meid_index
;
63 if( state
.GetIndex(recId
, &meid_index
) ) {
64 NullStore
<HandheldAgent
> store
;
65 RecordParser
<HandheldAgent
, NullStore
<HandheldAgent
> > parser(store
);
66 desktop
.GetRecord(dbId
, meid_index
, parser
);
67 return parser
.GetRecord().MEID
;
74 int main(int argc
, char *argv
[])
78 cout
.sync_with_stdio(true); // leave this on, since libusb uses
79 // stdio for debug messages
83 bool data_dump
= false,
85 get_usb_serial
= false,
90 // process command line options
92 int cmd
= getopt(argc
, argv
, "B:hN:vmsc");
106 case 'c': // show both hex and dec
110 case 'm': // get meid / esn
114 case 's': // get usb serial number
115 get_usb_serial
= true;
118 case 'v': // data dump on
129 Barry::Init(data_dump
, &std::cerr
);
130 Barry::Probe
probe(busname
.c_str(), devname
.c_str());
132 // show all successfully found devices
133 for( int i
= 0; i
< probe
.GetCount(); i
++ ) {
134 const ProbeResult
&pr
= probe
.Get(i
);
135 cout
<< pr
.m_pin
.Str() << ", "
139 Barry::Controller
con(pr
);
140 Barry::Mode::Desktop
desktop(con
);
143 // store as temporary in case of exceptions
144 string meid
= FetchMEID(desktop
);
145 cout
<< ", " << meid
;
148 if( HandheldAgent::IsESNHex(meid
) ) {
149 cout
<< " (" << HandheldAgent::ESNHex2Dec(meid
) << ")";
151 else if( HandheldAgent::IsESNDec(meid
) ) {
152 cout
<< " (" << HandheldAgent::ESNDec2Hex(meid
) << ")";
156 catch( Barry::BadPassword
& ) {
157 // ignore password protected devices
159 catch( Barry::Error
&e
) {
160 // output on cerr so as not to mess up
161 // the identify output
162 cerr
<< _("Error on PIN: ") << pr
.m_pin
.Str() << ": " << e
.what() << endl
;
165 if( get_usb_serial
) {
166 Usb::Device
dev(pr
.m_dev
);
167 cout
<< ", " << dev
.GetSimpleSerialNumber();
170 // finish the identity line
174 return probe
.GetFailCount();
177 catch( std::exception
&e
) {
178 cerr
<< _("exception caught: ") << e
.what() << endl
;