Skip to content
Browse files

Major refactoring of Win32_Handle_Hijack class which improved the gui…

… of Util - Win32 Window Handle Hijack (simple).h2

Minor fix on IVMK
Couple new Win32 apis
Added installer for Gource and SublimeText
Added PoC for Karma and Angular use
  • Loading branch information...
1 parent 68c1c07 commit a9901bc6db47adc0b66c9b66cfe46f95cbcf2376 @DinisCruz DinisCruz committed Jun 20, 2013
View
43 3rdParty/_Installers/Gource_Installer.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Diagnostics;
+using O2.Kernel;
+using O2.Kernel.ExtensionMethods;
+using O2.DotNetWrappers.ExtensionMethods;
+using O2.XRules.Database.Utils;
+using O2.XRules.Database.APIs;
+
+//O2File:Tool_API.cs
+
+namespace O2.XRules.Database.APIs
+{
+ public class Launcher
+ {
+ public static void launch()
+ {
+ new Gource_Installer().start();
+ }
+ }
+ public class Gource_Installer : Tool_API
+ {
+
+ public Gource_Installer()
+ {
+ config("gource",
+ "https://gource.googlecode.com/files/gource-0.40.win32.zip".uri(),
+ "gource.exe");
+
+ installFromZip_Web();
+ }
+
+ public Process start()
+ {
+ if (isInstalled())
+ {
+ var path = "What is the path of the repo to view".askUser();
+ if (path.dirExists())
+ return this.Executable.startProcess(path);
+ }
+ return null;
+ }
+ }
+}
View
41 3rdParty/_Installers/SublimeText.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Diagnostics;
+using O2.Kernel;
+using O2.Kernel.ExtensionMethods;
+using O2.DotNetWrappers.ExtensionMethods;
+using O2.XRules.Database.Utils;
+using O2.XRules.Database.APIs;
+
+//O2File:Tool_API.cs
+
+namespace O2.XRules.Database.APIs
+{
+ public class Launcher
+ {
+ public static void launch()
+ {
+ new SublimeText_Installer().start();
+ }
+ }
+ public class SublimeText_Installer : Tool_API
+ {
+
+ public SublimeText_Installer()
+ {
+ config("SublimeText",
+ "http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1%20x64.zip".uri(),
+ "sublime_text.exe");
+
+ installFromZip_Web();
+ }
+
+ public Process start()
+ {
+ if (isInstalled())
+ {
+ this.Executable.startProcess();
+ }
+ return null;
+ }
+ }
+}
View
3 APIs/IKVM/API_IKVMC.cs
@@ -52,7 +52,8 @@ public API_IKVMC()
public void setup()
{
- IkvmcAssembly = "ikvmc.exe".assembly();
+ //IkvmcAssembly = "ikvmc.exe".assembly();
+ IkvmcAssembly = @"IKVM\ikvm-7.1.4532.2\bin\ikvmc.exe".assembly();
StaticCompiler = IkvmcAssembly.type("StaticCompiler");
//IkvmRuntime = StaticCompiler.invokeStatic("LoadFile",Environment.CurrentDirectory.pathCombine("IKVM.Runtime.dll"));
IkvmRuntime = StaticCompiler.invokeStatic("LoadFile","IKVM.Runtime.dll".assembly().Location);
View
1 APIs/Windows/Win32_DLL_Imports/DLL_User32.cs
@@ -15,6 +15,7 @@ public partial class WinAPI
[DllImport("user32.dll")] public static extern IntPtr ChildWindowFromPoint (IntPtr hWndParent, POINT Point);
[DllImport("user32.dll")] public static extern bool CloseWindow (IntPtr hWnd);
+ [DllImport("user32.dll")] public static extern bool ClientToScreen (IntPtr hWnd, ref POINT lpPoint);
[DllImport("user32.dll")] public static extern bool DestroyWindow (IntPtr hwnd);
View
1 APIs/Windows/Win32_DLL_Imports/Dll_User32.cs
@@ -15,6 +15,7 @@ public partial class WinAPI
[DllImport("user32.dll")] public static extern IntPtr ChildWindowFromPoint (IntPtr hWndParent, POINT Point);
[DllImport("user32.dll")] public static extern bool CloseWindow (IntPtr hWnd);
+ [DllImport("user32.dll")] public static extern bool ClientToScreen (IntPtr hWnd, ref POINT lpPoint);
[DllImport("user32.dll")] public static extern bool DestroyWindow (IntPtr hwnd);
View
1 APIs/Windows/Win32_DLL_Imports/Win32_Structs.cs
@@ -12,6 +12,7 @@ public struct RECT
public int Top;
public int Right;
public int Bottom;
+
public int Height
{
get
View
247 APIs/Windows/Windows_Messages/API_Win32_Handle_Hijack.cs
@@ -7,6 +7,8 @@
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using O2.DotNetWrappers.Windows;
+using O2.DotNetWrappers.DotNet;
using O2.DotNetWrappers.ExtensionMethods;
@@ -31,96 +33,151 @@ public class API_Win32_Handle_Hijack
public class Win32_Handle_Hijack : Control
{
- public Panel topPanel;
- public WindowFinder windowFinder;
- public TextBox targetHandle;
- public TextBox parentHandle;
- public Panel hijackedWindow;
- public PictureBox pictureBox;
- public Label className;
- public IntPtr hijackedHandle;
- public IntPtr hijackedParent;
- public TextBox test;
-
+ public WindowFinder WindowFinder { get; set; }
+ public ToolStrip ToolStrip { get; set; }
+ public Panel TopPanel { get; set; }
+ public ToolStripTextBox TargetHandle { get; set; }
+ public ToolStripTextBox ParentHandle { get; set; }
+ public Panel HijackedWindow { get; set; }
+ public CheckBox AutoResize ;//{ get; set; }
+
+ public IntPtr HijackedHandle { get; set; }
+ public IntPtr HijackedParent { get; set; }
+
+ public WinAPI.RECT HijackedHandleRECT;
+
+ //public PictureBox PictureBox ;//{ get; set; }
+ //public Label ClassName ;//{ get; set; }
+
public Win32_Handle_Hijack()
{
this.width(400);
this.height(400);
buildGui();
}
+ public void setTarget(IntPtr handle)
+ {
+ TargetHandle.set_Text(handle.str());
+ //ClassName.set_Text(handle.className());
+ //PictureBox.show(handle.window_ScreenShot());
+ }
+
+ public void updateParentValue()
+ {
+ var target = TargetHandle.get_Text().toInt().intPtr();
+ var targetParent = target.parent().str();
+ ParentHandle.set_Text(targetParent);
+ }
+
+ public void setTargetValueToItsParent()
+ {
+ if(ParentHandle.get_Text().isInt())
+ if (ParentHandle.get_Text().toInt() > 0)
+ TargetHandle.set_Text(ParentHandle.get_Text());
+ }
+
+ public void restore()
+ {
+ if (HijackedHandle != IntPtr.Zero)
+ {
+ "restoring {0} to parent {1}".info(HijackedHandle, HijackedParent);
+ HijackedHandle.setParent(HijackedParent);
+ if(HijackedHandleRECT.Width >0 && HijackedHandleRECT.Width > 0)
+ {
+ HijackedHandle.window_Move(HijackedHandleRECT.Left,HijackedHandleRECT.Top, HijackedHandleRECT.Width,HijackedHandleRECT.Height);
+ HijackedHandleRECT = default(WinAPI.RECT);
+ }
+ HijackedParent.window_Redraw();
+ HijackedHandle.window_Redraw();
+ HijackedHandle = IntPtr.Zero;
+ }
+ }
+
+ public void hijack()
+ {
+ restore();
+ var handle = TargetHandle.get_Text().toInt().intPtr();
+ var newParent = HijackedWindow.clear().handle();
+ "Hijacking {0} into window {1}".info(handle, newParent);
+ HijackedHandle = handle;
+
+ WinAPI.GetWindowRect(handle, ref HijackedHandleRECT);
+ HijackedParent = ParentHandle.get_Text().toInt().intPtr();
+ handle.setParent(newParent);
+
+ adjustHandleSizeToTargetWindow();
+ }
+ public void screenShot()
+ {
+ restore();
+ try
+ {
+ var handle = TargetHandle.get_Text().toInt().intPtr();
+ var bitmap = handle.window_ScreenShot();
+ HijackedWindow.clear().add_PictureBox().layout_Zoom().show(bitmap);
+ }
+ catch(Exception ex)
+ {
+ ex.log();
+ }
+ }
+
+ public void adjustHandleSizeToTargetWindow()
+ {
+ if (AutoResize.@checked())
+ HijackedHandle.window_Move(0,0, HijackedWindow.width(), HijackedWindow.height());
+ }
+ public Process startProcessAndHijackMainWindow(string processToStart, string processParams)
+ {
+ return hijackProcessMainWindow(processToStart.startProcess(processParams));
+ }
+ public Process hijackProcessMainWindow(Process process)
+ {
+ var mainHandle = process.waitFor_MainWindowHandle().MainWindowHandle;
+ O2Thread.mtaThread(
+ ()=>{
+ setTarget(mainHandle);
+ hijack();
+ adjustHandleSizeToTargetWindow();
+ });
+ return process;
+ }
+
public Win32_Handle_Hijack buildGui()
{
- Action restore =
- ()=>{
- if (hijackedHandle != IntPtr.Zero)
- {
- "restoring {0} to parent {1}".info(hijackedHandle, hijackedParent);
- hijackedHandle.setParent(hijackedParent);
- hijackedParent.window_Redraw();
- hijackedHandle.window_Redraw();
- }
- };
-
- Action hijack =
- ()=>{
- restore();
- var handle = targetHandle.get_Text().toInt().intPtr();
- var newParent = hijackedWindow.clear().handle();
- "Hijacking {0} into window {1}".info(handle, newParent);
- hijackedHandle = handle;
- hijackedParent = parentHandle.get_Text().toInt().intPtr();
- handle.setParent(newParent);
- };
- Action screenShot =
- ()=>{
- restore();
- try
- {
- var handle = targetHandle.get_Text().toInt().intPtr();
- var bitmap = handle.window_ScreenShot();
- hijackedWindow.clear().add_PictureBox().layout_Zoom().show(bitmap);
- }
- catch(Exception ex)
- {
- ex.log();
- }
- };
- Action<IntPtr> setTarget =
- (handle)=>{
- targetHandle.set_Text(handle.str());
- className.set_Text(handle.className());
- pictureBox.show(handle.window_ScreenShot());
- //pictureBox
- };
- topPanel = this.add_Panel();
- topPanel.insert_Above(35).splitContainerFixed()
- .add_WindowFinder(ref windowFinder)
- .append_Label("Handle:").top(10).append_TextBox(ref targetHandle)
- .append_Label("Parent:").top(10).append_TextBox(ref parentHandle)
+ TopPanel = this.add_Panel();
+ createToolStrip();
+ /*
+ TopPanel.insert_Above(35).splitContainerFixed()
+// .add_WindowFinder(ref WindowFinder)
+//.add_WindowFinder()
+ //.add_Label("Handle:").top(10).append_TextBox(ref TargetHandle).width(60)
+ //.append_Label("Parent:").top(10).append_TextBox(ref ParentHandle).width(60)
.append_Link("Hijack", ()=> hijack()).top(10)
.append_Link("Restore", ()=> restore())
.append_Link("Screenshot", ()=> screenShot())
- .append_PictureBox(ref pictureBox)
- .append_TextBox(ref test).set_Text("Hijack me").top(10)
- .append_Label(ref className).topAdd(2);
+ .append_CheckBox("Auto Size", (value)=> AutoResize = value)
+ .append_PictureBox(ref PictureBox)
+ .append_TextBox(ref Test).set_Text("Hijack me").top(10)
+ .append_Label(ref ClassName).topAdd(2);
-
-
- hijackedWindow = topPanel.add_GroupBox("Hijacked Window/Control").add_Panel();
+ */
+ HijackedWindow = TopPanel.add_GroupBox("(click here to hide tool bar)").add_Panel();
- targetHandle.onTextChange((text)=> parentHandle.set_Text(text.toInt().intPtr().parent().str()));
- windowFinder.Window_Changed = setTarget;
+ //TargetHandle.onTextChange((value)=> ParentHandle.set_Text(value.toInt().intPtr().parent().str()));
+ //TargetHandle.TextChanged+= (sender,e)=> updateParentValue();
+ //WindowFinder.Window_Changed = setTarget;
// setTarget(test.handle());
- pictureBox.layout_Zoom();
+ //PictureBox.layout_Zoom();
this.onClosed(
()=>{
"On Closed".info();
restore();
});
- var groupBox = hijackedWindow.parent();;
+ var groupBox = HijackedWindow.parent();;
var originalText = groupBox.get_Text();
var splitcontainer = groupBox.splitContainer();
@@ -138,8 +195,62 @@ public Win32_Handle_Hijack buildGui()
groupBox.set_Text(".");
}
};
+
return this;
}
+
+ public void createToolStrip()
+ {
+ ToolStrip = TopPanel.insert_Above_ToolStrip();
+
+ WindowFinder = ToolStrip.insert_Left(30).add_WindowFinder();
+
+ WindowFinder.Window_Changed = setTarget;
+
+ ToolStrip.add_Button("Hijack","btExecuteOnExternalEngine_Image".formImage(), hijack)
+ .add_Button("Restore","edit_undo".formImage(),restore)
+ .add_Button("Screenshot","camera_photo".formImage(),screenShot)
+ .toolStrip()
+ .add_CheckBox("Size", ref AutoResize);
+
+ TargetHandle = ToolStrip.add_Label("Handle").add_TextBox("");
+ ParentHandle = ToolStrip.add_Label("Parent").add_TextBox("").width(40);
+ TargetHandle.width(40); // didn't work if set above
+
+ TargetHandle.TextChanged += (sender,e)=> updateParentValue();
+ ParentHandle.DoubleClick += (sender,e)=> setTargetValueToItsParent();
+
+ addExamples();
+
+
+ ToolStrip.add_DropDown("REPL")
+ .add_Button("Hijacked Handle","ViewCode".formImage(),()=> HijackedHandle.script_Me("handle").set_Code("return handle;\n\n//"+"O2File:Api_WinApi.cs"))
+ .add_Button("Hijack UI","ViewCode".formImage(),()=> this.script_Me("hijackUI"))
+ .add_Button("Parent Form","ViewCode".formImage(),()=> TopPanel.parentForm().script_Me("form"));
+
+ AutoResize.check();
+ TopPanel.Resize+= (sender,e)=> adjustHandleSizeToTargetWindow();
+ }
+
+ public void addExamples()
+ {
+ var examples = ToolStrip.add_DropDown("Hijack Processes");
+
+ examples.add_Button("---- (start new process and Hijack) ----", ()=>{})
+ .add_Button("Notepad",()=> startProcessAndHijackMainWindow("notepad",""))
+ .add_Button("Calculator",()=> startProcessAndHijackMainWindow("calc",""))
+ .add_Button("Cmd",()=> startProcessAndHijackMainWindow("cmd",""));
+
+ examples.add_Button("---- (Hijack existing processes) --", ()=>{});
+
+ // .add_Button("Chrome (Web Browser)",()=> startProcessAndHijackMainWindow("chrome","--chrome-frame"));
+ var targetProcesses = Processes.getProcesses().where((process)=>process.MainWindowHandle != IntPtr.Zero);
+ foreach(var targetProcess in targetProcesses)
+ {
+ var process = targetProcess; // need to pin it
+ examples.add_Button(targetProcess.MainWindowTitle, ()=> hijackProcessMainWindow(process));
+ }
+ }
}
public static class API_Win32_Handle_Hijack_ExtensionMethods
View
16 APIs/Windows/Windows_Messages/Util - Win32 Window Handle Hijack (simple).h2
@@ -1,12 +1,6 @@
-<?xml version="1.0"?>
-<H2>
- <SourceCode>
-//var topPanel = panel.add_Panel(true);
-
+//var topPanel = panel.add_Panel(true);
var topPanel = "Util - Win32 Window Handle Hijack (simple)".popupWindow();
-
-return topPanel.add_Handle_HijackGui();
-
-//O2File:API_Win32_Handle_Hijack.cs</SourceCode>
- <ReferencedAssemblies />
-</H2>
+var hijackGui = topPanel.add_Handle_HijackGui();
+return hijackGui;
+
+//O2File:API_Win32_Handle_Hijack.cs
View
51 APIs/_Javascript_Libraries/Karma/PoC - Karma and Angular run.h2
@@ -0,0 +1,51 @@
+var topPanel = "PoC - Karma and Angular run".popupWindow(1200,700);
+//var topPanel = panel.clear().add_Panel();
+//var textBox = topPanel.clear().add_RichTextBox();
+var codeDir = @"E:\_Code_Tests\AngularJS\angular-scenario";
+var karma = @"C:\Users\o2\AppData\Roaming\npm\node_modules\karma\bin\karma";
+
+var testPage = "http://localhost:8000/index.html";
+var testRunner = "http://localhost:9876/__karma/";
+
+var karmaConfig = codeDir.pathCombine("karma.conf.js");
+var serverConfig = codeDir.pathCombine("server.js");
+var unitTestFile = codeDir.pathCombine("e2eSpec.js");
+
+Process karmaProcess = null;
+
+Action startWebServer =
+ ()=>{
+ Processes.startProcessAndRedirectIO("node", serverConfig,codeDir,(line)=>line.info());
+ };
+
+Action runKarma =
+ ()=>{
+ Action<string> consoleOut =
+ (consoleLine)=> consoleLine.info(); //textBox.append_Line(consoleLine);
+
+ var command = "start \"{0}\" ".format(karmaConfig);
+ karmaProcess = "node".startProcess("\"" + karma + "\" " + command, consoleOut);
+ };
+
+if (testPage.GET().notValid())
+{
+ "Staring WebServer".info();
+ startWebServer();
+ 1000.wait();
+}
+var toolStrip = topPanel.insert_Above_ToolStrip();
+var codeEditor_Test = topPanel.add_SourceCodeEditor();
+var ie_UnitTestRunner = codeEditor_Test.insert_Right().add_WebBrowser_with_NavigationBar();
+var ie_Site = ie_UnitTestRunner.insert_Below().add_WebBrowser_with_NavigationBar();
+var codeEditor_Config = codeEditor_Test.insert_Below().add_SourceCodeEditor();
+
+codeEditor_Test.open(unitTestFile);
+codeEditor_Config.open(karmaConfig);
+ie_Site.open(testPage);
+ie_UnitTestRunner.open(testRunner);
+toolStrip.add_Button("Run","btExecuteSelectedMethod_Image".formImage(),()=>runKarma());
+
+
+runKarma();
+
+//using System.Diagnostics
View
22 Utils/ExtensionMethods/_Extra_methods_To_Add_to_Main_CodeBase.cs
@@ -71,8 +71,28 @@ public static class Extra_Misc
}
}
+ public static class Extra_WinForm_Controls_ToolStrip
+ {
+ public static ToolStripDropDown add_DropDown_Menu(this ToolStrip toolStrip, string menuTitle)
+ {
+ return toolStrip.add_DropDown(menuTitle);
+
+// check if existing on looks like this (below)
+ /*return toolStrip.invokeOnThread(
+ ()=>{
+ var dropDownButton = new ToolStripDropDownButton(menuTitle);
+ var toolStripDropDown = new ToolStripDropDown();
+ dropDownButton.DropDown = toolStripDropDown;
+ toolStrip.Items.Add(dropDownButton);
+ return toolStripDropDown;
+ });*/
+ }
+
+ }
+
public static class Extra_WinForm_Controls_TreeView
- {
+ {
+
}
public static class Extra_WinForm_Controls_Control

0 comments on commit a9901bc

Please sign in to comment.
Something went wrong with that request. Please try again.