Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <barry/barry.h>
00025 #include <iostream>
00026 #include <string>
00027 #include "i18n.h"
00028
00029 using namespace std;
00030 using namespace Barry;
00031
00032
00033 void printMessage(const std::string &message);
00034
00035
00036 void Usage()
00037 {
00038 int major, minor;
00039 const char *Version = Barry::Version(major, minor);
00040
00041 cerr
00042 << "bjdwp - Command line USB Blackberry JDWP\n"
00043 << " Copyright 2008-2009, Nicolas VIVIEN.\n"
00044 << " Using: " << Version << "\n"
00045 << "\n"
00046 << " -h This help\n"
00047 << " -p pin PIN of device to talk with\n"
00048 << " If only one device is plugged in, this flag is optional\n"
00049 << " -P pass Simplistic method to specify device password\n"
00050 << " -v Dump protocol data during operation\n"
00051 << "\n"
00052 << "arguments\n"
00053 << "\n"
00054 << " <address> Interface\n"
00055 << " <port> Listen port\n"
00056 << endl;
00057 }
00058
00059
00060 int main(int argc, char *argv[], char *envp[])
00061 {
00062 INIT_I18N(PACKAGE);
00063
00064 try {
00065 uint32_t pin = 0;
00066 bool data_dump = false;
00067 string password;
00068 vector<string> params;
00069 string iconvCharset;
00070
00071
00072 for(;;) {
00073 int cmd = getopt(argc, argv, "hp:P:v");
00074 if( cmd == -1 )
00075 break;
00076
00077 switch( cmd )
00078 {
00079 case 'p':
00080 pin = strtoul(optarg, NULL, 16);
00081 break;
00082
00083 case 'P':
00084 password = optarg;
00085 break;
00086
00087 case 'v':
00088 data_dump = true;
00089 break;
00090
00091 case 'h':
00092 default:
00093 Usage();
00094 return 0;
00095 }
00096 }
00097
00098 argc -= optind;
00099 argv += optind;
00100
00101 if( argc != 2 ) {
00102 cerr << "missing command" << endl;
00103 Usage();
00104 return 1;
00105 }
00106
00107
00108 char *address = argv[0];
00109 int port = atoi(argv[1]);
00110
00111
00112
00113
00114 Barry::Init(data_dump);
00115
00116
00117
00118
00119 Barry::Probe probe;
00120 int activeDevice = probe.FindActive(pin);
00121 if( activeDevice == -1 ) {
00122 cerr << "No device selected, or PIN not found" << endl;
00123 return 1;
00124 }
00125
00126 Barry::Controller con(probe.Get(activeDevice));
00127 Barry::Mode::JVMDebug jvmdebug(con);
00128
00129
00130
00131
00132
00133 JDWP::JDWServer server(jvmdebug, address, port);
00134
00135
00136 server.SetPasswordDevice(password);
00137
00138
00139 server.SetConsoleCallback(&printMessage);
00140
00141 server.Start();
00142
00143
00144 while (true)
00145 sleep(1);
00146
00147 server.Stop();
00148 }
00149 catch( Usb::Error &ue) {
00150 std::cout << endl;
00151 std::cerr << "Usb::Error caught: " << ue.what() << endl;
00152 return 1;
00153 }
00154 catch( Barry::Error &se ) {
00155 std::cout << endl;
00156 std::cerr << "Barry::Error caught: " << se.what() << endl;
00157 return 1;
00158 }
00159 catch( std::exception &e ) {
00160 std::cout << endl;
00161 std::cerr << "std::exception caught: " << e.what() << endl;
00162 return 1;
00163 }
00164
00165 return 0;
00166 }
00167
00168
00169 void printMessage(const std::string &message)
00170 {
00171 const char esc = 27;
00172 const int green = 32;
00173 const int blue = 34;
00174
00175 std::cout << esc << '[' << green << "mJVM>" << esc << '[' << blue << "m " << message << esc << "[0m";
00176 }
00177