3 /// Tool for probing identifying Blackberry devices
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>
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-2012, 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"
47 " -v Dump protocol data during operation\n"), Version
)
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
, &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() << ", "
133 Barry::Controller
con(pr
);
134 Barry::Mode::Desktop
desktop(con
);
137 // store as temporary in case of exceptions
138 string meid
= FetchMEID(desktop
);
139 cout
<< ", " << meid
;
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
163 return probe
.GetFailCount();
166 catch( std::exception
&e
) {
167 cerr
<< _("exception caught: ") << e
.what() << endl
;