desktop: show the modem pppd command in the modem script
[barry.git] / tools / bjvmdebug.cc
blobd880958659423e2b342f72cbc66e2a8d8adc8897
1 ///
2 /// \file bjvmdebug.cc
3 ///
4 ///
6 /*
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>
25 #include <iostream>
26 #include <vector>
27 #include <string>
28 #include <cstring>
29 #include <algorithm>
30 #include <fstream>
31 #include <string.h>
32 #include "i18n.h"
34 #include "barrygetopt.h"
36 using namespace std;
37 using namespace Barry;
39 void Usage()
41 int logical, major, minor;
42 const char *Version = Barry::Version(logical, major, minor);
44 cerr
45 << "bjvmdebug - Command line USB Blackberry Java Debugger\n"
46 << " Copyright 2008-2009, Nicolas VIVIEN.\n"
47 << " Copyright 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
48 << " Using: " << Version << "\n"
49 << "\n"
50 << " -h This help\n"
51 << " -p pin PIN of device to talk with\n"
52 << " If only one device is plugged in, this flag is optional\n"
53 << " -P pass Simplistic method to specify device password\n"
54 << " -v Dump protocol data during operation\n"
55 << endl;
59 int main(int argc, char *argv[])
61 INIT_I18N(PACKAGE);
63 try {
65 uint32_t pin = 0;
66 bool data_dump = false;
67 string password;
68 vector<string> params;
69 string iconvCharset;
71 // process command line options
72 for(;;) {
73 int cmd = getopt(argc, argv, "hp:P:v");
74 if( cmd == -1 )
75 break;
77 switch( cmd )
79 case 'p': // Blackberry PIN
80 pin = strtoul(optarg, NULL, 16);
81 break;
83 case 'P': // Device password
84 password = optarg;
85 break;
87 case 'v': // data dump on
88 data_dump = true;
89 break;
91 case 'h': // help
92 default:
93 Usage();
94 return 0;
98 // Initialize the barry library. Must be called before
99 // anything else.
100 Barry::Init(data_dump);
102 // Probe the USB bus for Blackberry devices and display.
103 // If user has specified a PIN, search for it in the
104 // available device list here as well
105 Barry::Probe probe;
106 int activeDevice = probe.FindActive(pin);
107 if( activeDevice == -1 ) {
108 cerr << "No device selected, or PIN not found" << endl;
109 return 1;
112 // Create our controller object
113 Barry::Controller con(probe.Get(activeDevice));
114 Barry::Mode::JVMDebug jvmdebug(con);
117 // execute each mode that was turned on
119 jvmdebug.Open(password.c_str());
120 jvmdebug.Attach();
122 // ...Unit tests...
123 jvmdebug.Unknown01();
124 jvmdebug.Unknown02();
125 jvmdebug.Unknown03();
126 jvmdebug.Unknown04();
127 jvmdebug.Unknown05();
130 cout << "Java Modules List :" << endl;
131 JVMModulesList list;
132 jvmdebug.GetModulesList(list);
133 cout << list;
137 cout << "Java Threads currently running :" << endl;
138 JVMThreadsList list;
139 jvmdebug.GetThreadsList(list);
140 cout << list;
143 jvmdebug.Unknown06();
144 jvmdebug.Unknown07();
145 jvmdebug.Unknown08();
146 jvmdebug.Unknown09();
147 jvmdebug.Unknown10();
149 jvmdebug.Go();
151 for (int i=0; i<20; i++) {
152 int ret;
153 string msg;
154 ret = jvmdebug.GetConsoleMessage(msg);
156 if (ret < 0) {
157 int status;
158 jvmdebug.GetStatus(status);
160 else {
161 cout << "JVM message : " << msg << endl;
165 // End of session
166 jvmdebug.Detach();
168 catch( Usb::Error &ue) {
169 std::cout << endl; // flush any normal output first
170 std::cerr << "Usb::Error caught: " << ue.what() << endl;
171 return 1;
173 catch( Barry::Error &se ) {
174 std::cout << endl;
175 std::cerr << "Barry::Error caught: " << se.what() << endl;
176 return 1;
178 catch( std::exception &e ) {
179 std::cout << endl;
180 std::cerr << "std::exception caught: " << e.what() << endl;
181 return 1;
184 return 0;