lib: show offset and rectype in HexDumpParser
[barry.git] / tools / bjvmdebug.cc
blobf9a0b0ff492e44fc4a84ecfddfc6a774560ac13c
1 ///
2 /// \file bjvmdebug.cc
3 ///
4 ///
6 /*
7 Copyright (C) 2008-2009, Nicolas VIVIEN
8 Copyright (C) 2005-2010, 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 <getopt.h>
31 #include <fstream>
32 #include <string.h>
33 #include "i18n.h"
35 using namespace std;
36 using namespace Barry;
38 void Usage()
40 int major, minor;
41 const char *Version = Barry::Version(major, minor);
43 cerr
44 << "bjvmdebug - Command line USB Blackberry Java Debugger\n"
45 << " Copyright 2008-2009, Nicolas VIVIEN.\n"
46 << " Copyright 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)\n"
47 << " Using: " << Version << "\n"
48 << "\n"
49 << " -h This help\n"
50 << " -p pin PIN of device to talk with\n"
51 << " If only one device is plugged in, this flag is optional\n"
52 << " -P pass Simplistic method to specify device password\n"
53 << " -v Dump protocol data during operation\n"
54 << endl;
58 int main(int argc, char *argv[])
60 INIT_I18N(PACKAGE);
62 try {
64 uint32_t pin = 0;
65 bool data_dump = false;
66 string password;
67 vector<string> params;
68 string iconvCharset;
70 // process command line options
71 for(;;) {
72 int cmd = getopt(argc, argv, "hp:P:v");
73 if( cmd == -1 )
74 break;
76 switch( cmd )
78 case 'p': // Blackberry PIN
79 pin = strtoul(optarg, NULL, 16);
80 break;
82 case 'P': // Device password
83 password = optarg;
84 break;
86 case 'v': // data dump on
87 data_dump = true;
88 break;
90 case 'h': // help
91 default:
92 Usage();
93 return 0;
97 // Initialize the barry library. Must be called before
98 // anything else.
99 Barry::Init(data_dump);
101 // Probe the USB bus for Blackberry devices and display.
102 // If user has specified a PIN, search for it in the
103 // available device list here as well
104 Barry::Probe probe;
105 int activeDevice = probe.FindActive(pin);
106 if( activeDevice == -1 ) {
107 cerr << "No device selected, or PIN not found" << endl;
108 return 1;
111 // Create our controller object
112 Barry::Controller con(probe.Get(activeDevice));
113 Barry::Mode::JVMDebug jvmdebug(con);
116 // execute each mode that was turned on
118 jvmdebug.Open(password.c_str());
119 jvmdebug.Attach();
121 // ...Unit tests...
122 jvmdebug.Unknown01();
123 jvmdebug.Unknown02();
124 jvmdebug.Unknown03();
125 jvmdebug.Unknown04();
126 jvmdebug.Unknown05();
129 cout << "Java Modules List :" << endl;
130 JVMModulesList list;
131 jvmdebug.GetModulesList(list);
132 cout << list;
136 cout << "Java Threads currently running :" << endl;
137 JVMThreadsList list;
138 jvmdebug.GetThreadsList(list);
139 cout << list;
142 jvmdebug.Unknown06();
143 jvmdebug.Unknown07();
144 jvmdebug.Unknown08();
145 jvmdebug.Unknown09();
146 jvmdebug.Unknown10();
148 jvmdebug.Go();
150 for (int i=0; i<20; i++) {
151 int ret;
152 string msg;
153 ret = jvmdebug.GetConsoleMessage(msg);
155 if (ret < 0) {
156 int status;
157 jvmdebug.GetStatus(status);
159 else {
160 cout << "JVM message : " << msg << endl;
164 // End of session
165 jvmdebug.Detach();
167 catch( Usb::Error &ue) {
168 std::cout << endl; // flush any normal output first
169 std::cerr << "Usb::Error caught: " << ue.what() << endl;
170 return 1;
172 catch( Barry::Error &se ) {
173 std::cout << endl;
174 std::cerr << "Barry::Error caught: " << se.what() << endl;
175 return 1;
177 catch( std::exception &e ) {
178 std::cout << endl;
179 std::cerr << "std::exception caught: " << e.what() << endl;
180 return 1;
183 return 0;