bjvmdebug.cc
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 <vector>
00027 #include <string>
00028 #include <cstring>
00029 #include <algorithm>
00030 #include <getopt.h>
00031 #include <fstream>
00032 #include <string.h>
00033 #include "i18n.h"
00034
00035 using namespace std;
00036 using namespace Barry;
00037
00038 void Usage()
00039 {
00040 int major, minor;
00041 const char *Version = Barry::Version(major, minor);
00042
00043 cerr
00044 << "bjvmdebug - Command line USB Blackberry Java Debugger\n"
00045 << " Copyright 2008-2009, Nicolas VIVIEN.\n"
00046 << " Copyright 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
00047 << " Using: " << Version << "\n"
00048 << "\n"
00049 << " -h This help\n"
00050 << " -p pin PIN of device to talk with\n"
00051 << " If only one device is plugged in, this flag is optional\n"
00052 << " -P pass Simplistic method to specify device password\n"
00053 << " -v Dump protocol data during operation\n"
00054 << endl;
00055 }
00056
00057
00058 int main(int argc, char *argv[])
00059 {
00060 INIT_I18N(PACKAGE);
00061
00062 try {
00063
00064 uint32_t pin = 0;
00065 bool data_dump = false;
00066 string password;
00067 vector<string> params;
00068 string iconvCharset;
00069
00070
00071 for(;;) {
00072 int cmd = getopt(argc, argv, "hp:P:v");
00073 if( cmd == -1 )
00074 break;
00075
00076 switch( cmd )
00077 {
00078 case 'p':
00079 pin = strtoul(optarg, NULL, 16);
00080 break;
00081
00082 case 'P':
00083 password = optarg;
00084 break;
00085
00086 case 'v':
00087 data_dump = true;
00088 break;
00089
00090 case 'h':
00091 default:
00092 Usage();
00093 return 0;
00094 }
00095 }
00096
00097
00098
00099 Barry::Init(data_dump);
00100
00101
00102
00103
00104 Barry::Probe probe;
00105 int activeDevice = probe.FindActive(pin);
00106 if( activeDevice == -1 ) {
00107 cerr << "No device selected, or PIN not found" << endl;
00108 return 1;
00109 }
00110
00111
00112 Barry::Controller con(probe.Get(activeDevice));
00113 Barry::Mode::JVMDebug jvmdebug(con);
00114
00115
00116
00117
00118 jvmdebug.Open(password.c_str());
00119 jvmdebug.Attach();
00120
00121
00122 jvmdebug.Unknown01();
00123 jvmdebug.Unknown02();
00124 jvmdebug.Unknown03();
00125 jvmdebug.Unknown04();
00126 jvmdebug.Unknown05();
00127
00128 {
00129 cout << "Java Modules List :" << endl;
00130 JVMModulesList list;
00131 jvmdebug.GetModulesList(list);
00132 cout << list;
00133 }
00134
00135 {
00136 cout << "Java Threads currently running :" << endl;
00137 JVMThreadsList list;
00138 jvmdebug.GetThreadsList(list);
00139 cout << list;
00140 }
00141
00142 jvmdebug.Unknown06();
00143 jvmdebug.Unknown07();
00144 jvmdebug.Unknown08();
00145 jvmdebug.Unknown09();
00146 jvmdebug.Unknown10();
00147
00148 jvmdebug.Go();
00149
00150 for (int i=0; i<20; i++) {
00151 int ret;
00152 string msg;
00153 ret = jvmdebug.GetConsoleMessage(msg);
00154
00155 if (ret < 0) {
00156 int status;
00157 jvmdebug.GetStatus(status);
00158 }
00159 else {
00160 cout << "JVM message : " << msg << endl;
00161 }
00162 }
00163
00164
00165 jvmdebug.Detach();
00166 }
00167 catch( Usb::Error &ue) {
00168 std::cout << endl;
00169 std::cerr << "Usb::Error caught: " << ue.what() << endl;
00170 return 1;
00171 }
00172 catch( Barry::Error &se ) {
00173 std::cout << endl;
00174 std::cerr << "Barry::Error caught: " << se.what() << endl;
00175 return 1;
00176 }
00177 catch( std::exception &e ) {
00178 std::cout << endl;
00179 std::cerr << "std::exception caught: " << e.what() << endl;
00180 return 1;
00181 }
00182
00183 return 0;
00184 }
00185