3 /// bjdwp command line tool
7 Copyright (C) 2008-2009, Nicolas VIVIEN
8 Copyright (C) 2005-2012, 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.
24 #include <barry/barry.h>
32 using namespace Barry
;
35 void printMessage(const std::string
&message
);
40 int logical
, major
, minor
;
41 const char *Version
= Barry::Version(logical
, major
, minor
);
44 << "bjdwp - Command line USB Blackberry JDWP\n"
45 << " Copyright 2008-2009, Nicolas VIVIEN.\n"
46 << " Using: " << Version
<< "\n"
49 << " -p pin PIN of device to talk with\n"
50 << " If only one device is plugged in, this flag is optional\n"
51 << " -P pass Simplistic method to specify device password\n"
52 << " -v Dump protocol data during operation\n"
56 << " <address> Interface\n"
57 << " <port> Listen port\n"
62 int main(int argc
, char *argv
[], char *envp
[])
68 bool data_dump
= false;
70 vector
<string
> params
;
73 // process command line options
75 int cmd
= getopt(argc
, argv
, "hp:P:v");
81 case 'p': // Blackberry PIN
82 pin
= strtoul(optarg
, NULL
, 16);
85 case 'P': // Device password
89 case 'v': // data dump on
104 cerr
<< "missing command" << endl
;
109 // Fetch address & port arguments
110 char *address
= argv
[0];
111 int port
= atoi(argv
[1]);
114 // Initialize the barry library. Must be called before
116 Barry::Init(data_dump
);
118 // Probe the USB bus for Blackberry devices and display.
119 // If user has specified a PIN, search for it in the
120 // available device list here as well
122 int activeDevice
= probe
.FindActive(pin
);
123 if( activeDevice
== -1 ) {
124 cerr
<< "No device selected, or PIN not found" << endl
;
128 Barry::Controller
con(probe
.Get(activeDevice
));
129 Barry::Mode::JVMDebug
jvmdebug(con
);
131 // Start JDW daemon...
132 //---------------------
134 // Create JDWP server and configure
135 JDWP::JDWServer
server(jvmdebug
, address
, port
);
138 server
.SetPasswordDevice(password
);
140 // Redirect console message
141 server
.SetConsoleCallback(&printMessage
);
145 // FIXME - is this needed... couldn't we do a join here?
151 catch( Usb::Error
&ue
) {
152 std::cout
<< endl
; // flush any normal output first
153 std::cerr
<< "Usb::Error caught: " << ue
.what() << endl
;
156 catch( Barry::Error
&se
) {
158 std::cerr
<< "Barry::Error caught: " << se
.what() << endl
;
161 catch( std::exception
&e
) {
163 std::cerr
<< "std::exception caught: " << e
.what() << endl
;
171 void printMessage(const std::string
&message
)
174 const int green
= 32;
177 std::cout
<< esc
<< '[' << green
<< "mJVM>" << esc
<< '[' << blue
<< "m " << message
<< esc
<< "[0m";