private static void DoCloseOpenFileDialog(NktRemoteBridge remoteBridge, Process proc) { IntPtr hWnd; try { hWnd = remoteBridge.FindWindow(proc.Id, IntPtr.Zero, "Open", "#32770", false); if (hWnd == IntPtr.Zero) hWnd = remoteBridge.FindWindow(proc.Id, IntPtr.Zero, "Abrir", "#32770", false); if (hWnd == IntPtr.Zero) { Console.WriteLine("Cannot find OpenFileDialog window"); return; } //we can try sending a WM_COMMAND with IDOK but we will try to find the ok button and send //fake lbuttondown/up to test more methods instead. hWnd = remoteBridge.GetChildWindowFromId(proc.Id, hWnd, 1); if (hWnd == IntPtr.Zero) { Console.WriteLine("Cannot find OpenFileDialog's OK button"); return; } remoteBridge.PostMessage(proc.Id, hWnd, 0x0201, IntPtr.Zero, IntPtr.Zero); //WM_LBUTTONDOWN remoteBridge.PostMessage(proc.Id, hWnd, 0x0202, IntPtr.Zero, IntPtr.Zero); //WM_LBUTTONUP } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } return; }
private static void DoGetOpenFileDialogFilename(NktRemoteBridge remoteBridge, Process proc) { IFileOpenDialog dlg = null; object obj = null; IntPtr hWnd; string s; try { hWnd = remoteBridge.FindWindow(proc.Id, IntPtr.Zero, "Open", "#32770", false); if (hWnd == IntPtr.Zero) hWnd = remoteBridge.FindWindow(proc.Id, IntPtr.Zero, "Abrir", "#32770", false); if (hWnd == IntPtr.Zero) { Console.WriteLine("Cannot find OpenFileDialog window"); return; } obj = remoteBridge.GetComInterfaceFromHwnd(proc.Id, hWnd, ShellIIDGuid.IFileDialog); if (obj == null) { Console.WriteLine("Cannot find retrieve IFileOpenDialog interface"); return; } dlg = obj as IFileOpenDialog; dlg.GetFileName(out s); Console.WriteLine("Filename: [" + s + "]"); } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } finally { //if (dlg != null) // Marshal.ReleaseComObject(dlg); if (obj != null) Marshal.ReleaseComObject(obj); } return; }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //date<->date test Console.Write(" Date single value test... "); try { DateTime sBaseDate = new DateTime(2013, 10, 13, 16, 00, 00); object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test", sBaseDate); if (res.GetType() != typeof(DateTime)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((DateTime)res != sBaseDate.AddYears(1)) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //date<->date array test Console.Write(" Date array test... "); try { DateTime[, ,] arrayDate = new DateTime[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayDate[i, j, k] = new DateTime(2013, 10, 13, i, j, k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test3D", new object[] { arrayDate }); if (res.GetType() != typeof(DateTime[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } DateTime[, ,] arrayDateRes = (DateTime[, , ])res; if (arrayDateRes.GetLength(0) != 4 || arrayDateRes.GetLength(1) != 6 || arrayDateRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayDateRes[i, j, k] != arrayDate[i, j, k].AddYears(1)) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); return(true); }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //bool<->bool test Console.Write(" Boolean single value test... "); try { bool bBaseBool = true; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test", bBaseBool); if (res.GetType() != typeof(bool)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((bool)res != (!bBaseBool)) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //bool<->bool array test Console.Write(" Boolean array test... "); try { bool[, ,] arrayBool = new bool[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayBool[i, j, k] = (((i+j+k) & 1) != 0) ? true : false; } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test3D", new object[] { arrayBool }); if (res.GetType() != typeof(bool[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } bool[, ,] arrayBoolRes = (bool[, ,])res; if (arrayBoolRes.GetLength(0) != 4 || arrayBoolRes.GetLength(1) != 6 || arrayBoolRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayBoolRes[i, j, k] != (!arrayBool[i, j, k])) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); return true; }
static void Main(string[] args) { object continueEv; INktJavaObject topLevelFrame; int verMajor, verMinor; Console.WriteLine("This example launches the Java Development Kit Notepad demo application and..."); Console.WriteLine(" a) Changes the main frame caption."); Console.WriteLine(" b) Creates a JTextArea with a text and inserts it at the bottom."); Console.WriteLine(" c) Sends System.exit() on exit to gracefully close Notepad if still running."); remoteBridge = new NktRemoteBridge(); if (remoteBridge == null) { Console.Write("Error: NktRemoteBridge not registered."); return; } try { String s; int pid; Console.Write("Launching NOTEPAD.JAR... "); s = FindJavaLauncher(args); if (s == "") { Console.WriteLine("Cannot locate a registered jarfile launcher."); return; } //create command line s = "\"" + s + "\" "; if (DoVerboseJNI(args) != false) s += "-Xcheck:jni -verbose:jni "; s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); s += "\\..\\Samples\\Demos4Test\\Java\\Notepad\\notepad.jar\""; //create process pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv); if (pid == 0) { Console.WriteLine("failed."); return; } procNotepad = Process.GetProcessById(pid); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return; } //---------------- INJECT try { Console.Write("Injecting... "); remoteBridge.Hook(procNotepad.Id, eNktHookFlags.flgDebugPrintInterfaces); if (continueEv != null) remoteBridge.ResumeProcess(procNotepad.Id, continueEv); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return; } //---------------- WAIT UNTIL JVM INITIALIZATION Console.Write("Waiting for JVM initialization... "); try { while (remoteBridge.IsJVMAttached(procNotepad.Id, out verMajor, out verMinor) == false) { if (procNotepad.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java notepad if still open QuitJavaApp(true); return; } } else { System.Threading.Thread.Sleep(10); } } Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); //close java notepad if still open QuitJavaApp(true); return; } //---------------- PERFORM TASKS Console.Write("Obtaining main JFrame... "); topLevelFrame = null; while (topLevelFrame == null) { object frames; if (procNotepad.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java notepad if still open QuitJavaApp(true); return; } } //get top level frame try { frames = remoteBridge.InvokeJavaStaticMethod(procNotepad.Id, "javax.swing.JFrame", "getFrames", null); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } if (frames is Array) { if (((object[])frames).Length > 0) topLevelFrame = ((object[])frames)[0] as INktJavaObject; } if (topLevelFrame == null) System.Threading.Thread.Sleep(100); } Console.WriteLine("OK"); Console.Write("Waiting until visible... "); while ((bool)(topLevelFrame.InvokeMethod("isVisible", null)) == false) { System.Threading.Thread.Sleep(10); } Console.WriteLine("OK"); //set new caption topLevelFrame.InvokeMethod("setTitle", "Nektra - Notepad"); //get main frame content pane INktJavaObject cntPane = topLevelFrame.InvokeMethod("getContentPane", null) as INktJavaObject; //add a new JTextArea at the bottom INktJavaObject newTxArea = remoteBridge.CreateJavaObject(procNotepad.Id, "javax.swing.JTextArea", "Nektra Demo"); cntPane.InvokeMethod("add", new object[] { "South", newTxArea }); //resize window in order to force a re-layout topLevelFrame.InvokeMethod("setSize", new object[] { 500, 601 }); //free resources Marshal.ReleaseComObject(cntPane); Marshal.ReleaseComObject(newTxArea); Marshal.ReleaseComObject(topLevelFrame); //---------------- WAIT FOR EXIT Console.WriteLine("Press 'ESC' key to quit"); while (true) { if (procNotepad.HasExited != false) { Console.WriteLine("Hooked process has ended. Quitting."); break; } if (Console.KeyAvailable == false) { System.Threading.Thread.Sleep(10); continue; } Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) break; } //---------------- CLOSE JAVA APP IF STILL RUNNING QuitJavaApp(false); }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //float<->float test Console.Write(" Float single value test... "); try { float nBaseFloat = 10.0F; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseFloat); if (res.GetType() != typeof(float)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((float)res != 255.0F - nBaseFloat) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //float<->float array test Console.Write(" Float array test... "); try { float[, ,] arrayFloat = new float[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayFloat[i, j, k] = (float)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayFloat }); if (res.GetType() != typeof(float[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } float[, ,] arrayFloatRes = (float[, ,])res; if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayFloatRes[i, j, k] != 255.0 - arrayFloat[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //double<->float test Console.Write(" Float single value test using doubles... "); try { double nBaseDouble = 10.0; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDouble); if (res.GetType() != typeof(float)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((double)(float)res != 255.0 - nBaseDouble) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //double<->float array test Console.Write(" Float array test using doubles... "); try { double[, ,] arrayDouble = new double[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayDouble[i, j, k] = (double)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDouble }); if (res.GetType() != typeof(float[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } float[, ,] arrayFloatRes = (float[, ,])res; if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if ((double)arrayFloatRes[i, j, k] != 255.0 - arrayDouble[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //decimal<->float test Console.Write(" Float single value test using BigDecimal... "); try { Decimal nBaseDecimal = 10.0M; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDecimal); if (res.GetType() != typeof(float)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((Decimal)(float)(res) != 255.0M - nBaseDecimal) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //decimal<->float array test Console.Write(" Float array test using BigDecimal... "); try { Decimal[, ,] arrayDecimal = new Decimal[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayDecimal[i, j, k] = new Decimal(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDecimal }); if (res.GetType() != typeof(float[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } float[, ,] arrayFloatRes = (float[, ,])res; if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if ((Decimal)arrayFloatRes[i, j, k] != 255.0M - arrayDecimal[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); return true; }
static void Main(string[] args) { object continueEvent; //Console.Write("Press any key to continue... "); //Console.ReadKey(true); //Console.WriteLine("OK"); processesList = new SortedList<Int32, string>(); remoteBridge = new NktRemoteBridge(); if (remoteBridge == null) { Console.Write("Error: NktRemoteBridge not registered."); return; } remoteBridge.OnCreateProcessCall += new DNktRemoteBridgeEvents_OnCreateProcessCallEventHandler(OnCreateProcessCall); remoteBridge.OnComInterfaceCreated += new DNktRemoteBridgeEvents_OnComInterfaceCreatedEventHandler(OnComInterfaceCreated); remoteBridge.OnProcessUnhooked += new DNktRemoteBridgeEvents_OnProcessUnhookedEventHandler(OnProcessUnhooked); try { string s; s = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE", "", null) as string; if (s == null) { Console.WriteLine("failed."); return; } Console.Write("Launching & hooking IEXPLORE.EXE... "); s = "\"" + s + "\" http://www.bbc.co.uk"; iePid = remoteBridge.CreateProcess(s, true, out continueEvent); if (iePid == 0) { Console.WriteLine("failed."); return; } lock (processesList) { processesList.Add(iePid, ""); } remoteBridge.Hook(iePid, eNktHookFlags.flgDebugPrintInterfaces); remoteBridge.WatchComInterface(iePid, CLSID_HTMLDocument, IID_IUnknown); remoteBridge.ResumeProcess(iePid, continueEvent); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("ERROR"); Console.WriteLine(ex.ToString()); return; } while (true) { bool b; lock (processesList) { b = (processesList.Count > 0); } if (b == false) { Console.WriteLine("Hooked process has ended. Quitting."); break; } if (Console.KeyAvailable == false) { System.Threading.Thread.Sleep(10); continue; } Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) break; } return; }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //bool<->bool test Console.Write(" String single value test... "); try { string szBaseString = "this is a test string"; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test", szBaseString); if (res.GetType() != typeof(string)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((string)res != "[" + szBaseString + "]") { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //string<->string array test Console.Write(" String array test... "); try { string szBaseString = "this is a test string"; string[, ,] arrayStr = new string[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayStr[i, j, k] = szBaseString + " " + i.ToString() + "/" + j.ToString() + "/" + k.ToString(); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test3D", new object[] { arrayStr }); if (res.GetType() != typeof(string[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } string[, ,] arrayStrRes = (string[, ,])res; if (arrayStrRes.GetLength(0) != 4 || arrayStrRes.GetLength(1) != 6 || arrayStrRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayStrRes[i, j, k] != "[" + arrayStr[i, j, k] + "]") { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); return true; }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //short<->char test Console.Write(" Char single value test using shorts... "); try { char nBaseChar = (char)10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test", nBaseChar); if (res.GetType() != typeof(short)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((short)res != 255 - (short)nBaseChar) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //short<->char array test Console.Write(" Char array test using shorts... "); try { char[, ,] arrayChar = new char[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayChar[i, j, k] = (char)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test3D", new object[] { arrayChar }); if (res.GetType() != typeof(short[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } short[, ,] arrayCharRes = (short[, , ])res; if (arrayCharRes.GetLength(0) != 4 || arrayCharRes.GetLength(1) != 6 || arrayCharRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayCharRes[i, j, k] != 255 - (short)arrayChar[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); return(true); }
//static string IID_IUnknown = "{00000000-0000-0000-C000-000000000046}"; static void Main(string[] args) { NktRemoteBridge remoteBridge; object continueEv; Process procNotepad; if (Environment.OSVersion.Version.Major < 6) { Console.Write("Error: This application requires Windows Vista or later to work."); return; } remoteBridge = new NktRemoteBridge(); if (remoteBridge == null) { Console.Write("Error: NktRemoteBridge not registered."); return; } try { int pid; Console.Write("Launching NOTEPAD.EXE... "); pid = remoteBridge.CreateProcess("notepad.exe", (DoDelayedHook(args) != false) ? false : true, out continueEv); if (pid == 0) { Console.WriteLine("failed."); return; } procNotepad = Process.GetProcessById(pid); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return; } //---------------- try { Console.Write("Injecting... "); remoteBridge.Hook(procNotepad.Id, eNktHookFlags.flgDebugPrintInterfaces); if (continueEv != null) remoteBridge.ResumeProcess(procNotepad.Id, continueEv); remoteBridge.WatchComInterface(procNotepad.Id, ShellCLSIDGuid.FileOpenDialog, ShellIIDGuid.IFileDialog); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return; } //---------------- Console.WriteLine("Ready."); Console.WriteLine("Usage:"); Console.WriteLine(" This demo launches a Windows' Notepad application and scans 'File Open' dialog boxes."); Console.WriteLine(" When a file open dialog box is created, you can take the following actions:"); Console.WriteLine(" 1) Press the 'F' key to retrieve the typed file name in the dialog box."); Console.WriteLine(" 2) Press the 'C' key to close the dialog box window using the OK button."); Console.WriteLine(" 3) Press 'ESC' key to quit this demo!"); while (true) { if (procNotepad.HasExited != false) { Console.WriteLine("Hooked process has ended. Quitting."); break; } if (Console.KeyAvailable == false) { System.Threading.Thread.Sleep(10); continue; } Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) break; switch (ch) { case 'f': case 'F': DoGetOpenFileDialogFilename(remoteBridge, procNotepad); break; case 'c': case 'C': DoCloseOpenFileDialog(remoteBridge, procNotepad); break; } } return; }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { NktJavaObject testObj; Console.Write(" EventCallbackTests[DefineClass] test... "); try { byte[] byteCode; string s; s = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); s += "\\..\\Samples\\Demos4Test\\Java\\Test\\InjectTestWithCallbacks.class"; byteCode = System.IO.File.ReadAllBytes(s); remoteBridge.DefineJavaClass(pid, "InjectTestWithCallbacks", byteCode); } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[Instatiate] test... "); try { testObj = remoteBridge.CreateJavaObject(pid, "InjectTestWithCallbacks", null); if (testObj == null) { Console.WriteLine("Error: Cannot create object"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[NoParametersReturningInt] test... "); try { object res; res = testObj.InvokeMethod("Test_NoParametersReturningInt", null); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((int)res != 10) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[NoParametersReturningJavaLangDoubleObject] test... "); try { object res; NktJavaObject javaObj; res = testObj.InvokeMethod("Test_NoParametersReturningJavaLangDoubleObject", null); javaObj = res as NktJavaObject; if (javaObj == null) { Console.WriteLine("Error: Invalid returned type"); return(false); } res = javaObj.get_Field("value"); //accessing private field if (res.GetType() != typeof(double)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((double)res != 10.0) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[WithParametersReturningInt] test... "); try { object res; res = testObj.InvokeMethod("Test_WithParametersReturningInt", null); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((int)res != 124) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[WithParametersReturningJavaLangDoubleObject] test... "); try { object res; NktJavaObject javaObj; res = testObj.InvokeMethod("Test_WithParametersReturningJavaLangDoubleObject", null); javaObj = res as NktJavaObject; if (javaObj == null) { Console.WriteLine("Error: Invalid returned type"); return(false); } res = javaObj.get_Field("value"); //accessing private field if (res.GetType() != typeof(double)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((double)res != 124.0) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine("OK"); return(true); }
static void Main(string[] args) { object continueEv; INktJavaObject topLevelFrame; int verMajor, verMinor; Console.WriteLine("This example performs some tests on RemoteBridge's Java functionality."); remoteBridge = new NktRemoteBridge(); if (remoteBridge == null) { Console.Write("Error: NktRemoteBridge not registered."); QuitJavaApp(true); return; } try { String s; int pid; Console.Write("Launching JAVATEST.JAR... "); s = FindJavaLauncher(args); if (s == "") { Console.WriteLine("Cannot locate a registered jarfile launcher."); return; } //create command line s = "\"" + s + "\" "; if (DoVerboseJNI(args) != false) { s += "-Xcheck:jni -verbose:jni "; } s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); s += "\\..\\Samples\\Demos4Test\\Java\\Test\\JavaTest.jar\""; //create process pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv); if (pid == 0) { Console.WriteLine("failed."); return; } procJavaTest = Process.GetProcessById(pid); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } //---------------- INJECT try { Console.Write("Injecting... "); remoteBridge.Hook(procJavaTest.Id, eNktHookFlags.flgDebugPrintInterfaces); if (continueEv != null) { remoteBridge.ResumeProcess(procJavaTest.Id, continueEv); } Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } //---------------- WAIT UNTIL JVM INITIALIZATION Console.Write("Waiting for JVM initialization... "); try { while (remoteBridge.IsJVMAttached(procJavaTest.Id, out verMajor, out verMinor) == false) { if (procJavaTest.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java test if still open QuitJavaApp(false); return; } } else { System.Threading.Thread.Sleep(10); } } Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } //---------------- FIND TOPLEVEL WINDOW Console.Write("Obtaining main Window... "); topLevelFrame = null; while (topLevelFrame == null) { object frames; if (procJavaTest.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java test if still open QuitJavaApp(false); return; } } //get top level frame try { frames = remoteBridge.InvokeJavaStaticMethod(procJavaTest.Id, "javax.swing.JFrame", "getFrames", null); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } if (frames is Array) { if (((object[])frames).Length > 0) { topLevelFrame = ((object[])frames)[0] as INktJavaObject; } } if (topLevelFrame == null) { System.Threading.Thread.Sleep(10); } } Console.WriteLine("OK"); //---------------- RUN TESTS Console.Write("Running tests..."); for (int testNo = 1; testNo <= 12; testNo++) { if (procJavaTest.HasExited != false) { Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine("Exiting by user request."); //close java test if still open QuitJavaApp(false); return; } } //run test bool b = false; switch (testNo) { case 1: b = BooleanTests.RunTests(procJavaTest.Id, remoteBridge); break; case 2: b = ByteTests.RunTests(procJavaTest.Id, remoteBridge); break; case 3: b = ShortTests.RunTests(procJavaTest.Id, remoteBridge); break; case 4: b = CharTests.RunTests(procJavaTest.Id, remoteBridge); break; case 5: b = IntTests.RunTests(procJavaTest.Id, remoteBridge); break; case 6: b = LongTests.RunTests(procJavaTest.Id, remoteBridge); break; case 7: b = FloatTests.RunTests(procJavaTest.Id, remoteBridge); break; case 8: b = DoubleTests.RunTests(procJavaTest.Id, remoteBridge); break; case 9: b = DateTests.RunTests(procJavaTest.Id, remoteBridge); break; case 10: b = BigDecimalTests.RunTests(procJavaTest.Id, remoteBridge); break; case 11: b = StringTests.RunTests(procJavaTest.Id, remoteBridge); break; case 12: remoteBridge.OnJavaCustomNativeCall += Test_OnJavaCustomNativeCall; b = EventCallbackTests.RunTests(procJavaTest.Id, remoteBridge); remoteBridge.OnJavaCustomNativeCall -= Test_OnJavaCustomNativeCall; break; } if (b == false) { QuitJavaApp(true); return; } } //---------------- CLOSE JAVA APP IF STILL RUNNING QuitJavaApp(true); }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //date<->date test Console.Write(" Date single value test... "); try { DateTime sBaseDate = new DateTime(2013, 10, 13, 16, 00, 00); object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test", sBaseDate); if (res.GetType() != typeof(DateTime)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((DateTime)res != sBaseDate.AddYears(1)) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //date<->date array test Console.Write(" Date array test... "); try { DateTime[, ,] arrayDate = new DateTime[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayDate[i, j, k] = new DateTime(2013, 10, 13, i, j, k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test3D", new object[] { arrayDate }); if (res.GetType() != typeof(DateTime[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } DateTime[, ,] arrayDateRes = (DateTime[, ,])res; if (arrayDateRes.GetLength(0) != 4 || arrayDateRes.GetLength(1) != 6 || arrayDateRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayDateRes[i, j, k] != arrayDate[i, j, k].AddYears(1)) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); return true; }
static void Main(string[] args) { object continueEv; INktJavaObject topLevelFrame; int verMajor, verMinor; Console.WriteLine("This example launches the Java Development Kit Notepad demo application and..."); Console.WriteLine(" a) Changes the main frame caption."); Console.WriteLine(" b) Creates a JTextArea with a text and inserts it at the bottom."); Console.WriteLine(" c) Sends System.exit() on exit to gracefully close Notepad if still running."); remoteBridge = new NktRemoteBridge(); if (remoteBridge == null) { Console.Write("Error: NktRemoteBridge not registered."); return; } try { String s; int pid; Console.Write("Launching NOTEPAD.JAR... "); s = FindJavaLauncher(args); if (s == "") { Console.WriteLine("Cannot locate a registered jarfile launcher."); return; } //create command line s = "\"" + s + "\" "; if (DoVerboseJNI(args) != false) { s += "-Xcheck:jni -verbose:jni "; } s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); s += "\\..\\Samples\\Demos4Test\\Java\\Notepad\\notepad.jar\""; //create process pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv); if (pid == 0) { Console.WriteLine("failed."); return; } procNotepad = Process.GetProcessById(pid); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return; } //---------------- INJECT try { Console.Write("Injecting... "); remoteBridge.Hook(procNotepad.Id, eNktHookFlags.flgDebugPrintInterfaces); if (continueEv != null) { remoteBridge.ResumeProcess(procNotepad.Id, continueEv); } Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return; } //---------------- WAIT UNTIL JVM INITIALIZATION Console.Write("Waiting for JVM initialization... "); try { while (remoteBridge.IsJVMAttached(procNotepad.Id, out verMajor, out verMinor) == false) { if (procNotepad.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java notepad if still open QuitJavaApp(true); return; } } else { System.Threading.Thread.Sleep(10); } } Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); //close java notepad if still open QuitJavaApp(true); return; } //---------------- PERFORM TASKS Console.Write("Obtaining main JFrame... "); topLevelFrame = null; while (topLevelFrame == null) { object frames; if (procNotepad.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java notepad if still open QuitJavaApp(true); return; } } //get top level frame try { frames = remoteBridge.InvokeJavaStaticMethod(procNotepad.Id, "javax.swing.JFrame", "getFrames", null); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } if (frames is Array) { if (((object[])frames).Length > 0) { topLevelFrame = ((object[])frames)[0] as INktJavaObject; } } if (topLevelFrame == null) { System.Threading.Thread.Sleep(100); } } Console.WriteLine("OK"); Console.Write("Waiting until visible... "); while ((bool)(topLevelFrame.InvokeMethod("isVisible", null)) == false) { System.Threading.Thread.Sleep(10); } Console.WriteLine("OK"); //set new caption topLevelFrame.InvokeMethod("setTitle", "Nektra - Notepad"); //get main frame content pane INktJavaObject cntPane = topLevelFrame.InvokeMethod("getContentPane", null) as INktJavaObject; //add a new JTextArea at the bottom INktJavaObject newTxArea = remoteBridge.CreateJavaObject(procNotepad.Id, "javax.swing.JTextArea", "Nektra Demo"); cntPane.InvokeMethod("add", new object[] { "South", newTxArea }); //resize window in order to force a re-layout topLevelFrame.InvokeMethod("setSize", new object[] { 500, 601 }); //free resources Marshal.ReleaseComObject(cntPane); Marshal.ReleaseComObject(newTxArea); Marshal.ReleaseComObject(topLevelFrame); //---------------- WAIT FOR EXIT Console.WriteLine("Press 'ESC' key to quit"); while (true) { if (procNotepad.HasExited != false) { Console.WriteLine("Hooked process has ended. Quitting."); break; } if (Console.KeyAvailable == false) { System.Threading.Thread.Sleep(10); continue; } Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { break; } } //---------------- CLOSE JAVA APP IF STILL RUNNING QuitJavaApp(false); }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //int<->int test Console.Write(" Integer single value test... "); try { int nBaseInt = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseInt); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((int)res != 255 - nBaseInt) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //int<->int array test Console.Write(" Integer array test... "); try { int[, ,] arrayInt = new int[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayInt[i, j, k] = (int)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayInt }); if (res.GetType() != typeof(int[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } int[, ,] arrayIntRes = (int[, , ])res; if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayIntRes[i, j, k] != 255 - arrayInt[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //byte<->int test Console.Write(" Integer single value test using bytes... "); try { byte nBaseByte = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseByte); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((byte)(int)res != 255 - nBaseByte) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //byte<->int array test Console.Write(" Integer array test using bytes... "); try { byte[, ,] arrayByte = new byte[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayByte[i, j, k] = (byte)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayByte }); if (res.GetType() != typeof(int[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } int[, ,] arrayIntRes = (int[, , ])res; if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayIntRes[i, j, k] != 255 - (int)arrayByte[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //short<->int test Console.Write(" Integer single value test using shorts... "); try { short nBaseShort = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseShort); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((short)(int)res != 255 - nBaseShort) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //short<->int array test Console.Write(" Integer array test using shorts... "); try { short[, ,] arrayShort = new short[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayShort[i, j, k] = (short)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayShort }); if (res.GetType() != typeof(int[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } int[, ,] arrayIntRes = (int[, , ])res; if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayIntRes[i, j, k] != 255 - (int)arrayShort[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //long<->int test Console.Write(" Integer single value test using longs... "); try { long nBaseLong = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseLong); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((long)(int)res != 255 - nBaseLong) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //long<->int array test Console.Write(" Integer array test using longs... "); try { long[, ,] arrayLong = new long[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayLong[i, j, k] = (long)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayLong }); if (res.GetType() != typeof(int[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } int[, ,] arrayIntRes = (int[, , ])res; if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if ((long)arrayIntRes[i, j, k] != 255 - arrayLong[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); return(true); }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { NktJavaObject testObj; Console.Write(" EventCallbackTests[DefineClass] test... "); try { byte[] byteCode; string s; s = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); s += "\\..\\Samples\\Demos4Test\\Java\\Test\\InjectTestWithCallbacks.class"; byteCode = System.IO.File.ReadAllBytes(s); remoteBridge.DefineJavaClass(pid, "InjectTestWithCallbacks", byteCode); } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[Instatiate] test... "); try { testObj = remoteBridge.CreateJavaObject(pid, "InjectTestWithCallbacks", null); if (testObj == null) { Console.WriteLine("Error: Cannot create object"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[NoParametersReturningInt] test... "); try { object res; res = testObj.InvokeMethod("Test_NoParametersReturningInt", null); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((int)res != 10) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[NoParametersReturningJavaLangDoubleObject] test... "); try { object res; NktJavaObject javaObj; res = testObj.InvokeMethod("Test_NoParametersReturningJavaLangDoubleObject", null); javaObj = res as NktJavaObject; if (javaObj == null) { Console.WriteLine("Error: Invalid returned type"); return false; } res = javaObj.get_Field("value"); //accessing private field if (res.GetType() != typeof(double)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((double)res != 10.0) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[WithParametersReturningInt] test... "); try { object res; res = testObj.InvokeMethod("Test_WithParametersReturningInt", null); if (res.GetType() != typeof(int)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((int)res != 124) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine("OK"); Console.Write(" EventCallbackTests[WithParametersReturningJavaLangDoubleObject] test... "); try { object res; NktJavaObject javaObj; res = testObj.InvokeMethod("Test_WithParametersReturningJavaLangDoubleObject", null); javaObj = res as NktJavaObject; if (javaObj == null) { Console.WriteLine("Error: Invalid returned type"); return false; } res = javaObj.get_Field("value"); //accessing private field if (res.GetType() != typeof(double)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((double)res != 124.0) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine("OK"); return true; }
static void Main(string[] args) { object continueEv; INktJavaObject topLevelFrame; int verMajor, verMinor; Console.WriteLine("This example performs some tests on RemoteBridge's Java functionality."); remoteBridge = new NktRemoteBridge(); if (remoteBridge == null) { Console.Write("Error: NktRemoteBridge not registered."); QuitJavaApp(true); return; } try { String s; int pid; Console.Write("Launching JAVATEST.JAR... "); s = FindJavaLauncher(args); if (s == "") { Console.WriteLine("Cannot locate a registered jarfile launcher."); return; } //create command line s = "\"" + s + "\" "; if (DoVerboseJNI(args) != false) s += "-Xcheck:jni -verbose:jni "; s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); s += "\\..\\Samples\\Demos4Test\\Java\\Test\\JavaTest.jar\""; //create process pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv); if (pid == 0) { Console.WriteLine("failed."); return; } procJavaTest = Process.GetProcessById(pid); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } //---------------- INJECT try { Console.Write("Injecting... "); remoteBridge.Hook(procJavaTest.Id, eNktHookFlags.flgDebugPrintInterfaces); if (continueEv != null) remoteBridge.ResumeProcess(procJavaTest.Id, continueEv); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } //---------------- WAIT UNTIL JVM INITIALIZATION Console.Write("Waiting for JVM initialization... "); try { while (remoteBridge.IsJVMAttached(procJavaTest.Id, out verMajor, out verMinor) == false) { if (procJavaTest.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java test if still open QuitJavaApp(false); return; } } else { System.Threading.Thread.Sleep(10); } } Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } //---------------- FIND TOPLEVEL WINDOW Console.Write("Obtaining main Window... "); topLevelFrame = null; while (topLevelFrame == null) { object frames; if (procJavaTest.HasExited != false) { Console.WriteLine(""); Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine(""); Console.WriteLine("Exiting by user request."); //close java test if still open QuitJavaApp(false); return; } } //get top level frame try { frames = remoteBridge.InvokeJavaStaticMethod(procJavaTest.Id, "javax.swing.JFrame", "getFrames", null); } catch (Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); QuitJavaApp(true); return; } if (frames is Array) { if (((object[])frames).Length > 0) topLevelFrame = ((object[])frames)[0] as INktJavaObject; } if (topLevelFrame == null) System.Threading.Thread.Sleep(10); } Console.WriteLine("OK"); //---------------- RUN TESTS Console.Write("Running tests..."); for (int testNo=1; testNo<=12; testNo++) { if (procJavaTest.HasExited != false) { Console.WriteLine("Hooked process has ended. Quitting."); return; } if (Console.KeyAvailable != false) { Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { Console.WriteLine("Exiting by user request."); //close java test if still open QuitJavaApp(false); return; } } //run test bool b = false; switch (testNo) { case 1: b = BooleanTests.RunTests(procJavaTest.Id, remoteBridge); break; case 2: b = ByteTests.RunTests(procJavaTest.Id, remoteBridge); break; case 3: b = ShortTests.RunTests(procJavaTest.Id, remoteBridge); break; case 4: b = CharTests.RunTests(procJavaTest.Id, remoteBridge); break; case 5: b = IntTests.RunTests(procJavaTest.Id, remoteBridge); break; case 6: b = LongTests.RunTests(procJavaTest.Id, remoteBridge); break; case 7: b = FloatTests.RunTests(procJavaTest.Id, remoteBridge); break; case 8: b = DoubleTests.RunTests(procJavaTest.Id, remoteBridge); break; case 9: b = DateTests.RunTests(procJavaTest.Id, remoteBridge); break; case 10: b = BigDecimalTests.RunTests(procJavaTest.Id, remoteBridge); break; case 11: b = StringTests.RunTests(procJavaTest.Id, remoteBridge); break; case 12: remoteBridge.OnJavaCustomNativeCall += Test_OnJavaCustomNativeCall; b = EventCallbackTests.RunTests(procJavaTest.Id, remoteBridge); remoteBridge.OnJavaCustomNativeCall -= Test_OnJavaCustomNativeCall; break; } if (b == false) { QuitJavaApp(true); return; } } //---------------- CLOSE JAVA APP IF STILL RUNNING QuitJavaApp(true); }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //bool<->bool test Console.Write(" Boolean single value test... "); try { bool bBaseBool = true; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test", bBaseBool); if (res.GetType() != typeof(bool)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((bool)res != (!bBaseBool)) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //bool<->bool array test Console.Write(" Boolean array test... "); try { bool[, ,] arrayBool = new bool[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayBool[i, j, k] = (((i + j + k) & 1) != 0) ? true : false; } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test3D", new object[] { arrayBool }); if (res.GetType() != typeof(bool[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } bool[, ,] arrayBoolRes = (bool[, , ])res; if (arrayBoolRes.GetLength(0) != 4 || arrayBoolRes.GetLength(1) != 6 || arrayBoolRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayBoolRes[i, j, k] != (!arrayBool[i, j, k])) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); return(true); }
static void Main(string[] args) { object continueEvent; //Console.Write("Press any key to continue... "); //Console.ReadKey(true); //Console.WriteLine("OK"); processesList = new SortedList <Int32, string>(); remoteBridge = new NktRemoteBridge(); if (remoteBridge == null) { Console.Write("Error: NktRemoteBridge not registered."); return; } remoteBridge.OnCreateProcessCall += new DNktRemoteBridgeEvents_OnCreateProcessCallEventHandler(OnCreateProcessCall); remoteBridge.OnComInterfaceCreated += new DNktRemoteBridgeEvents_OnComInterfaceCreatedEventHandler(OnComInterfaceCreated); remoteBridge.OnProcessUnhooked += new DNktRemoteBridgeEvents_OnProcessUnhookedEventHandler(OnProcessUnhooked); try { string s; s = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE", "", null) as string; if (s == null) { Console.WriteLine("failed."); return; } Console.Write("Launching & hooking IEXPLORE.EXE... "); s = "\"" + s + "\" http://www.bbc.co.uk"; iePid = remoteBridge.CreateProcess(s, true, out continueEvent); if (iePid == 0) { Console.WriteLine("failed."); return; } lock (processesList) { processesList.Add(iePid, ""); } remoteBridge.Hook(iePid, eNktHookFlags.flgDebugPrintInterfaces); remoteBridge.WatchComInterface(iePid, CLSID_HTMLDocument, IID_IUnknown); remoteBridge.ResumeProcess(iePid, continueEvent); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine("ERROR"); Console.WriteLine(ex.ToString()); return; } while (true) { bool b; lock (processesList) { b = (processesList.Count > 0); } if (b == false) { Console.WriteLine("Hooked process has ended. Quitting."); break; } if (Console.KeyAvailable == false) { System.Threading.Thread.Sleep(10); continue; } Char ch = Console.ReadKey(true).KeyChar; if (ch == 27) { break; } } return; }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //short<->char test Console.Write(" Char single value test using shorts... "); try { char nBaseChar = (char)10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test", nBaseChar); if (res.GetType() != typeof(short)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((short)res != 255 - (short)nBaseChar) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //short<->char array test Console.Write(" Char array test using shorts... "); try { char[, ,] arrayChar = new char[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayChar[i, j, k] = (char)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test3D", new object[] { arrayChar }); if (res.GetType() != typeof(short[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } short[, ,] arrayCharRes = (short[, ,])res; if (arrayCharRes.GetLength(0) != 4 || arrayCharRes.GetLength(1) != 6 || arrayCharRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayCharRes[i, j, k] != 255 - (short)arrayChar[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); return true; }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //long<->long test Console.Write(" Long single value test... "); try { long nBaseLong = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseLong); if (res.GetType() != typeof(long)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((long)res != 255 - nBaseLong) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //long<->long array test Console.Write(" Long array test... "); try { long[, ,] arrayLong = new long[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayLong[i, j, k] = (long)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayLong }); if (res.GetType() != typeof(long[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } long[, ,] arrayLongRes = (long[, ,])res; if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayLongRes[i, j, k] != 255 - arrayLong[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //byte<->long test Console.Write(" Long single value test using bytes... "); try { byte nBaseByte = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseByte); if (res.GetType() != typeof(long)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((byte)(long)res != 255 - nBaseByte) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //byte<->long array test Console.Write(" Long array test using bytes... "); try { byte[, ,] arrayByte = new byte[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayByte[i, j, k] = (byte)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayByte }); if (res.GetType() != typeof(long[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } long[, ,] arrayLongRes = (long[, ,])res; if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayLongRes[i, j, k] != 255 - (long)arrayByte[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //short<->long test Console.Write(" Long single value test using shorts... "); try { short nBaseShort = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseShort); if (res.GetType() != typeof(long)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((short)(long)res != 255 - nBaseShort) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //short<->long array test Console.Write(" Long array test using shorts... "); try { short[, ,] arrayShort = new short[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayShort[i, j, k] = (short)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayShort }); if (res.GetType() != typeof(long[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } long[, ,] arrayLongRes = (long[, ,])res; if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayLongRes[i, j, k] != 255 - (long)arrayShort[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //int<->long test Console.Write(" Long single value test using ints... "); try { int nBaseInt = 10; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseInt); if (res.GetType() != typeof(long)) { Console.WriteLine("Error: Invalid returned type"); return false; } if ((int)(long)res != 255 - nBaseInt) { Console.WriteLine("Error: Returned data mismatch"); return false; } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); //int<->long array test Console.Write(" Long array test using ints... "); try { int[, ,] arrayInt = new int[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayInt[i, j, k] = (int)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayInt }); if (res.GetType() != typeof(long[, ,])) { Console.WriteLine("Error: Invalid returned type"); return false; } long[, ,] arrayLongRes = (long[, ,])res; if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return false; } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayLongRes[i, j, k] != 255 - (long)arrayInt[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return false; } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return false; } Console.WriteLine(" OK"); return true; }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //float<->float test Console.Write(" Float single value test... "); try { float nBaseFloat = 10.0F; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseFloat); if (res.GetType() != typeof(float)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((float)res != 255.0F - nBaseFloat) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //float<->float array test Console.Write(" Float array test... "); try { float[, ,] arrayFloat = new float[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayFloat[i, j, k] = (float)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayFloat }); if (res.GetType() != typeof(float[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } float[, ,] arrayFloatRes = (float[, , ])res; if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayFloatRes[i, j, k] != 255.0 - arrayFloat[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //double<->float test Console.Write(" Float single value test using doubles... "); try { double nBaseDouble = 10.0; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDouble); if (res.GetType() != typeof(float)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((double)(float)res != 255.0 - nBaseDouble) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //double<->float array test Console.Write(" Float array test using doubles... "); try { double[, ,] arrayDouble = new double[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayDouble[i, j, k] = (double)(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDouble }); if (res.GetType() != typeof(float[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } float[, ,] arrayFloatRes = (float[, , ])res; if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if ((double)arrayFloatRes[i, j, k] != 255.0 - arrayDouble[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //decimal<->float test Console.Write(" Float single value test using BigDecimal... "); try { Decimal nBaseDecimal = 10.0M; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDecimal); if (res.GetType() != typeof(float)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((Decimal)(float)(res) != 255.0M - nBaseDecimal) { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //decimal<->float array test Console.Write(" Float array test using BigDecimal... "); try { Decimal[, ,] arrayDecimal = new Decimal[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayDecimal[i, j, k] = new Decimal(i + j + k); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDecimal }); if (res.GetType() != typeof(float[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } float[, ,] arrayFloatRes = (float[, , ])res; if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if ((Decimal)arrayFloatRes[i, j, k] != 255.0M - arrayDecimal[i, j, k]) { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); return(true); }
public static bool RunTests(int pid, NktRemoteBridge remoteBridge) { //bool<->bool test Console.Write(" String single value test... "); try { string szBaseString = "this is a test string"; object res; res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test", szBaseString); if (res.GetType() != typeof(string)) { Console.WriteLine("Error: Invalid returned type"); return(false); } if ((string)res != "[" + szBaseString + "]") { Console.WriteLine("Error: Returned data mismatch"); return(false); } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); //string<->string array test Console.Write(" String array test... "); try { string szBaseString = "this is a test string"; string[, ,] arrayStr = new string[4, 6, 5]; object res; int i, j, k; for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { arrayStr[i, j, k] = szBaseString + " " + i.ToString() + "/" + j.ToString() + "/" + k.ToString(); } } } res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test3D", new object[] { arrayStr }); if (res.GetType() != typeof(string[, , ])) { Console.WriteLine("Error: Invalid returned type"); return(false); } string[, ,] arrayStrRes = (string[, , ])res; if (arrayStrRes.GetLength(0) != 4 || arrayStrRes.GetLength(1) != 6 || arrayStrRes.GetLength(2) != 5) { Console.WriteLine("Error: Returned array size mismatch"); return(false); } for (i = 0; i < 4; i++) { for (j = 0; j < 6; j++) { for (k = 0; k < 5; k++) { if (arrayStrRes[i, j, k] != "[" + arrayStr[i, j, k] + "]") { Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")"); return(false); } } } } } catch (System.Exception ex) { Console.WriteLine("failed."); Console.WriteLine(ex.ToString()); return(false); } Console.WriteLine(" OK"); return(true); }