Barry debian version 0.18.5-1
[barry.git] / tools / bjvmdebug.cc
blob9ae872a033982a8807c813c4ea736b9d24c77c11
1 ///
2 /// \file bjvmdebug.cc
3 ///
4 ///
6 /*
7 Copyright (C) 2008-2009, Nicolas VIVIEN
8 Copyright (C) 2005-2013, 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 << string_vprintf(
45 _("bjvmdebug - Command line USB Blackberry Java Debugger\n"
46 " Copyright 2008-2009, Nicolas VIVIEN.\n"
47 " Copyright 2005-2013, Net Direct Inc. (http://www.netdirect.ca/)\n"
48 " Using: %s\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"), Version)
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")
109 << endl;
110 return 1;
113 // Create our controller object
114 Barry::Controller con(probe.Get(activeDevice));
115 Barry::Mode::JVMDebug jvmdebug(con);
118 // execute each mode that was turned on
120 jvmdebug.Open(password.c_str());
121 jvmdebug.Attach();
123 // ...Unit tests...
124 jvmdebug.Unknown01();
125 jvmdebug.Unknown02();
126 jvmdebug.Unknown03();
127 jvmdebug.Unknown04();
128 jvmdebug.Unknown05();
131 cout << _("Java Modules List :") << endl;
132 JVMModulesList list;
133 jvmdebug.GetModulesList(list);
134 cout << list;
138 cout << _("Java Threads currently running :") << endl;
139 JVMThreadsList list;
140 jvmdebug.GetThreadsList(list);
141 cout << list;
144 jvmdebug.Unknown06();
145 jvmdebug.Unknown07();
146 jvmdebug.Unknown08();
147 jvmdebug.Unknown09();
148 jvmdebug.Unknown10();
150 jvmdebug.Go();
152 for (int i=0; i<20; i++) {
153 int ret;
154 string msg;
155 ret = jvmdebug.GetConsoleMessage(msg);
157 if (ret < 0) {
158 int status;
159 jvmdebug.GetStatus(status);
161 else {
162 cout << _("JVM message : ") << msg << endl;
166 // End of session
167 jvmdebug.Detach();
169 catch( Usb::Error &ue) {
170 std::cout << endl; // flush any normal output first
171 std::cerr << _("Usb::Error caught: ") << ue.what() << endl;
172 return 1;
174 catch( Barry::Error &se ) {
175 std::cout << endl;
176 std::cerr << _("Barry::Error caught: ") << se.what() << endl;
177 return 1;
179 catch( std::exception &e ) {
180 std::cout << endl;
181 std::cerr << _("std::exception caught: ") << e.what() << endl;
182 return 1;
185 return 0;