Skip to content
Browse files

Improved Process Injection API and Jni4Net PoCs

  • Loading branch information...
1 parent 5f5799e commit 31adc75014327e360fda4177d066787051be7e7d @DinisCruz DinisCruz committed Nov 13, 2012
View
17 3rdParty/HawkEye/Ctrl_ProcessFinder.cs
@@ -30,13 +30,15 @@ public Ctrl_ProcessFinder()
public Ctrl_ProcessFinder onProcessSelect(Action<Process> callback)
{
- this.ActiveWindowSelected += (sender, e)=> callback.invoke(this.TargetProcess);
+ if(callback.notNull())
+ this.ActiveWindowSelected += (sender, e)=> callback.invoke(this.TargetProcess);
return this;
}
public Ctrl_ProcessFinder onProcessChange(Action<Process> callback)
{
- this.ActiveWindowChanged += (sender, e)=> callback.invoke(this.TargetProcess);
+ if(callback.notNull())
+ this.ActiveWindowChanged += (sender, e)=> callback.invoke(this.TargetProcess);
return this;
}
}
@@ -48,5 +50,16 @@ public static Ctrl_ProcessFinder insert_Above_ProcessFinder(this Control control
return control.insert_Above(30).add_Control<Ctrl_ProcessFinder>().width(30).fill(false);
}
+ public static Ctrl_ProcessFinder add_ProcessFinder(this Control control, Action<Process> onProcessSelect)
+ {
+ return control.add_ProcessFinder(onProcessSelect, null);
+ }
+ public static Ctrl_ProcessFinder add_ProcessFinder(this Control control, Action<Process> onProcessSelect, Action<Process> onProcessChange )
+ {
+ return control.add_Control<Ctrl_ProcessFinder>().width(30).fill(false)
+ .onProcessSelect(onProcessSelect)
+ .onProcessChange(onProcessChange);
+ }
+
}
}
View
24 3rdParty/JAD/API_Jad.cs
@@ -10,10 +10,11 @@ namespace O2.XRules.Database.APIs
public class API_Jad
{
public string Executable { get; set;}
-
+ public string JadDecompilations { get; set; }
public API_Jad()
{
this.Executable = PublicDI.config.ToolsOrApis.pathCombine(@"jad/jad.exe");
+ this.JadDecompilations = "..\\_Jad".tempDir(false).fullPath();
}
public string execute(string commands)
{
@@ -33,5 +34,26 @@ public static string decompile(this API_Jad jad, string classFile)
return jad.execute("-p \"{0}\"".format(classFile));
}
}
+
+ public static class API_Jad_ExtensionMethods_JarFiles
+ {
+ public static string extractJarIntoTempFolder(this API_Jad jad, string jarFile)
+ {
+ if (jarFile.extension(".jar"))
+ {
+ var targetFolder = jad.JadDecompilations;
+ var extractFolder = targetFolder.pathCombine(jarFile.fileName().safeFileName().replace(".","_")).createDir();
+ if (extractFolder.folderExists().isFalse() || extractFolder.files(true).empty())
+ {
+ "Extracting Classes from Jar: {0}".info(jarFile);
+ jarFile.unzip(extractFolder);
+ }
+ return extractFolder;
+ }
+ return null;
+
+ }
+
+ }
}
View
2 3rdParty/JAD/Util - Java Decompiler (JAD based).h2
@@ -34,7 +34,7 @@ files.afterSelect&lt;string&gt;(
var javaCode = jad.decompile(file);
codeViewer.set_Text(javaCode,".java");
});
-files.onDrop(extractClassesFromJar);
+files.onDrop(extractClassesFromJar);
//O2File:API_Jad.cs
//O2EmbedTool:Jad
View
189 3rdParty/Jni4Net/API_Jni4Net_Active.cs
@@ -0,0 +1,189 @@
+// This file is part of the OWASP O2 Platform (http://www.owasp.org/index.php/OWASP_O2_Platform) and is released under the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0)
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using System.Collections.Generic;
+using O2.Kernel;
+using O2.DotNetWrappers.ExtensionMethods;
+using java.lang;
+using net.sf.jni4net;
+using net.sf.jni4net.jni;
+//Installer:Jni4Net_Installer.cs!Jni4Net/bin/proxygen.exe
+//O2Ref:Jni4Net/lib/jni4net.n-0.8.6.0.dll
+
+//O2File:_Extra_methods_To_Add_to_Main_CodeBase.cs
+
+namespace O2.XRules.Database.APIs
+{
+ public class API_Jni4Net_Active
+ {
+
+ }
+
+ public static class API_Jni4Net_Active_ExtensionMethods
+ {
+ public static bool isJVMAvaiable(this API_Jni4Net_Active jni4Net)
+ {
+ try
+ {
+ var env = JNIEnv.ThreadEnv;
+ var br = env.FindClass("java/lang/Object");
+ return true;
+ }
+ catch(System.Exception ex)
+ {
+ ex.log();
+ return false;
+ }
+
+ }
+
+ public static Class java_Find_Class(this string className)
+ {
+ try
+ {
+ return JNIEnv.ThreadEnv.FindClass(className.replace(".", "/"));
+ }
+ catch(System.Exception ex)
+ {
+ ex.log();
+ return null;
+ }
+ }
+
+ public static java.lang.Object java_Invoke(this java.lang.Object liveObject, string method, string signature, params java.lang.Object[] methodParameters)
+ {
+ try
+ {
+ var result = liveObject.getClass().GetMethod(method,signature,false)
+ .invoke(liveObject, methodParameters);
+ return result;
+ }
+ catch(System.Exception ex)
+ {
+ ex.log();
+ return null;
+ }
+ }
+
+ public static string java_Get_Class_Jar_File_Location(this Class targetClass)
+ {
+ try
+ {
+ var protectionDomain = targetClass.getProtectionDomain();
+ var protectionDomain_Class = protectionDomain.getClass();
+
+ var getCodeSource = protectionDomain_Class.GetMethod("getCodeSource", "()Ljava/security/CodeSource;", false);
+ var codeSource = getCodeSource.invoke(protectionDomain, new java.lang.Object[] {});
+ var getLocation = codeSource.getClass().GetMethod("getLocation","()Ljava/net/URL;",false);
+ var location = getLocation.invoke(codeSource, new java.lang.Object[] {});
+
+ var toString = location.getClass().GetMethod("toString", "()Ljava/lang/String;",false)
+ .invoke(location, new java.lang.Object[] {});
+ var path = toString.str().urlDecode().subString(6);
+ return path;
+ }
+ catch(System.Exception ex)
+ {
+ ex.log("in getClassJarFileLocation");
+ return null;
+ }
+ }
+
+ public static List<Class> java_From_ClassLoader_get_Loaded_Classes(this API_Jni4Net_Active jni4Net)
+ {
+ var classes = new List<Class>();
+ var classLoader = ClassLoader.getSystemClassLoader();
+ var clClass = classLoader.getClass();
+ while(clClass != java.lang.ClassLoader._class)
+ {
+ "{0} - {1}".info(clClass.str(), clClass.getSuperclass().str());
+ clClass = clClass.getSuperclass();
+ }
+
+ var classes_Field = clClass.getDeclaredField("classes");
+ var classes_Value = classes_Field.get(classLoader);
+
+ var elements_Method = classes_Value.getClass().getMethod("elements",null);
+ var elements = elements_Method.invoke(classes_Value,null);
+
+
+ while (elements.Invoke<bool>("hasMoreElements","()Z"))
+ classes.add(elements.Invoke<java.lang.Class>("nextElement", "()Ljava/lang/Object;"));
+
+ return classes;
+ }
+ }
+
+
+ public static class API_Jni4Net_Active_ExtensionMethods_GUI_Helpers
+ {
+ public static TreeView java_SetTreeView_To_Show_Jni4Net_Reflection_Data(this TreeView treeView)
+ {
+ treeView.beforeExpand<java.lang.Class>(
+ (treeNode, @class)=>{
+ var ctors = @class.getDeclaredConstructors();
+ var methods = @class.getDeclaredMethods();
+ var fields = @class.getDeclaredFields();
+ var superClass = @class.getSuperclass();
+ //var annotations = @class.getDeclaredAnnotations();
+ if (superClass.notNull()) treeNode.add_Node("SuperClass")
+ .add_Node(superClass.getName(), superClass, true).foreColor(Color.Orange);;
+
+ if (ctors.size() > 0)
+ treeNode.add_Node("ctors ({0})".format(ctors.size()), ctors,true);
+ if (methods.size() > 0)
+ treeNode.add_Node("methods ({0})".format(methods.size()), methods,true);
+ if (fields.size() > 0)
+ treeNode.add_Node("fields ({0})".format(fields.size()), fields,true);
+ });
+
+ treeView.beforeExpand<java.lang.reflect.Method[]>(
+ (treeNode,methods)=>{
+ treeNode.add_Nodes(methods, (method)=>"{0} {1}".format(method.getName(),method.GetSignature()), true);
+ treeNode.nodes().colorNodes(Color.Blue);
+ });
+ treeView.beforeExpand<java.lang.reflect.Constructor[]>(
+ (treeNode,ctors) => {
+ treeNode.add_Nodes(ctors, (ctor)=>"{0} {1}".format(ctor.getName(),ctor.GetSignature()), true);
+ treeNode.nodes().colorNodes(Color.Blue);
+ });
+
+ treeView.beforeExpand<java.lang.reflect.Field[]>(
+ (treeNode,fields) => {
+ treeNode.add_Nodes(fields, (field)=>"{0} {1}".format(field.getName(),field.GetSignature()), true);
+ treeNode.nodes().colorNodes( Color.Blue);
+ });
+
+ treeView.beforeExpand<java.lang.reflect.Method>(
+ (treeNode,method)=>{
+ treeNode.add_Node("ToString: {0}".format(method.toGenericString()), method).foreColor(Color.DarkGray);
+ treeNode.add_Node("Java Signature: {0}".format(method.GetSignature()), method).foreColor(Color.DarkGray);;
+ var parameterNode = treeNode.add_Node("_Parameters");
+ parameterNode.add_Nodes(method.getParameterTypes(), (@class)=>@class.getName(),true);
+ parameterNode.nodes().colorNodes( Color.DarkOrange);
+ treeNode.add_Node("_ReturnType").add_Node(method.getReturnType().getName(), method.getReturnType(),true)
+ .foreColor(Color.DarkOrange);
+ });
+
+ treeView.beforeExpand<java.lang.reflect.Constructor>(
+ (treeNode,ctor)=>{
+ treeNode.add_Node("ToString: {0}".format(ctor.toGenericString()), ctor).foreColor(Color.DarkGray);
+ treeNode.add_Node("Java Signature: {0}".format(ctor.GetSignature()), ctor).foreColor(Color.DarkGray);;
+ var parameterNode = treeNode.add_Node("_Parameters");
+ parameterNode.add_Nodes(ctor.getParameterTypes(), (@class)=>@class.getName(),true);
+ parameterNode.nodes().colorNodes( Color.DarkOrange);
+
+ });
+
+ treeView.beforeExpand<java.lang.reflect.Field>(
+ (treeNode,field)=>{
+ treeNode.add_Node("ToString: {0}".format(field.toGenericString()), field).foreColor(Color.DarkGray);
+ treeNode.add_Node("Java Signature: {0}".format(field.GetSignature()), field).foreColor(Color.DarkGray);;
+ });
+ return treeView;
+ }
+
+
+ }
+}
View
34 3rdParty/Jni4Net/Jni4Net_Installer.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Diagnostics;
+using O2.DotNetWrappers.ExtensionMethods;
+//O2File:Tool_API.cs
+
+namespace O2.XRules.Database.APIs
+{
+ public class testInstall
+ {
+ public static void test()
+ {
+ new Jni4Net_Installer().start();
+ }
+ }
+
+ public class Jni4Net_Installer : Tool_API
+ {
+ public Jni4Net_Installer()
+ {
+ config("Jni4Net",
+ "http://switch.dl.sourceforge.net/project/jni4net/0.8.6/jni4net-0.8.6.0-bin.zip".uri(),
+ @"bin/proxygen.exe");
+ installFromZip_Web();
+ }
+ //
+
+ public Process start()
+ {
+ if (this.isInstalled())
+ return this.Executable.startProcess();
+ return null;
+ }
+ }
+}
View
163 3rdParty/Jni4Net/PoC - Jni4Net - Classes, Methods, Fields in target.h2
@@ -1,88 +1,25 @@
<?xml version="1.0"?>
<H2>
- <SourceCode>Bridge.CreateJVM( new BridgeSetup(){Verbose=true}); //only needs to be called once
-
-var topPanel = "PoC - Jni4Net - Classes, Methods, Fields in target".popupWindow();
-//var topPanel = panel.add_Panel(true);
+ <SourceCode>Bridge.CreateJVM(new BridgeSetup(){Verbose=true}); //only needs to be called once
+var topPanel = "PoC - Jni4Net - Classes, Methods, Fields in target".popupWindow(1000,400);
+//var topPanel = panel.add_Panel(true);
+
var actionPanel = topPanel.insert_ActionPanel();
-
-var treeView = topPanel.add_Panel(true).add_TreeView_with_PropertyGrid(false).sort();
+var decompileClasses = false;
+//var treeView = topPanel.insert_Left().add_TreeView_with_PropertyGrid().sort();
+var treeView = topPanel.insert_Left().add_TreeView().sort();
+var codeViewer = topPanel.title("Decompiled Java code of selected class").add_SourceCodeEditor();
actionPanel.add_Link("REPL selectedNode", ()=&gt; treeView.selected().Tag.script_Me())
- .append_Link("Copy selectedNode text to clipboard", ()=&gt; treeView.selected().str().clipboardText_Set());
-
-Action&lt;List&lt;TreeNode&gt;, Color&gt; colorNodes =
- (nodes, color)=&gt;{
- treeView.beginUpdate();
- foreach(var node in nodes)
- node.foreColor(color);
- treeView.endUpdate();
- };
-
-treeView.beforeExpand&lt;java.lang.Class&gt;(
- (treeNode, @class)=&gt;{
- var ctors = @class.getDeclaredConstructors();
- var methods = @class.getDeclaredMethods();
- var fields = @class.getDeclaredFields();
- var superClass = @class.getSuperclass();
- //var annotations = @class.getDeclaredAnnotations();
- if (superClass.notNull()) treeNode.add_Node("SuperClass")
- .add_Node(superClass.getName(), superClass, true).foreColor(Color.Orange);;
-
- if (ctors.size() &gt; 0)
- treeNode.add_Node("ctors ({0})".format(ctors.size()), ctors,true);
- if (methods.size() &gt; 0)
- treeNode.add_Node("methods ({0})".format(methods.size()), methods,true);
- if (fields.size() &gt; 0)
- treeNode.add_Node("fields ({0})".format(fields.size()), fields,true);
- });
-
-treeView.beforeExpand&lt;java.lang.reflect.Method[]&gt;(
- (treeNode,methods)=&gt;{
- treeNode.add_Nodes(methods, (method)=&gt;"{0} {1}".format(method.getName(),method.GetSignature()), true);
- colorNodes(treeNode.nodes(), Color.Blue);
- });
-treeView.beforeExpand&lt;java.lang.reflect.Constructor[]&gt;(
- (treeNode,ctors) =&gt; {
- treeNode.add_Nodes(ctors, (ctor)=&gt;"{0} {1}".format(ctor.getName(),ctor.GetSignature()), true);
- colorNodes(treeNode.nodes(), Color.Blue);
- });
-
-treeView.beforeExpand&lt;java.lang.reflect.Field[]&gt;(
- (treeNode,fields) =&gt; {
- treeNode.add_Nodes(fields, (field)=&gt;"{0} {1}".format(field.getName(),field.GetSignature()), true);
- colorNodes(treeNode.nodes(), Color.Blue);
- });
-
-treeView.beforeExpand&lt;java.lang.reflect.Method&gt;(
- (treeNode,method)=&gt;{
- treeNode.add_Node("ToString: {0}".format(method.toGenericString()), method).foreColor(Color.DarkGray);
- treeNode.add_Node("Java Signature: {0}".format(method.GetSignature()), method).foreColor(Color.DarkGray);;
- var parameterNode = treeNode.add_Node("_Parameters");
- parameterNode.add_Nodes(method.getParameterTypes(), (@class)=&gt;@class.getName(),true);
- colorNodes(parameterNode.nodes(), Color.DarkOrange);
- treeNode.add_Node("_ReturnType").add_Node(method.getReturnType().getName(), method.getReturnType(),true)
- .foreColor(Color.DarkOrange);
- });
+ .append_Link("Copy selectedNode text to clipboard", ()=&gt; treeView.selected().str().clipboardText_Set())
+ .append_CheckBox("Decompile Classes", (value)=&gt; decompileClasses = value).autoSize().tick();
+
+treeView.java_SetTreeView_To_Show_Jni4Net_Reflection_Data();
-treeView.beforeExpand&lt;java.lang.reflect.Constructor&gt;(
- (treeNode,ctor)=&gt;{
- treeNode.add_Node("ToString: {0}".format(ctor.toGenericString()), ctor).foreColor(Color.DarkGray);
- treeNode.add_Node("Java Signature: {0}".format(ctor.GetSignature()), ctor).foreColor(Color.DarkGray);;
- var parameterNode = treeNode.add_Node("_Parameters");
- parameterNode.add_Nodes(ctor.getParameterTypes(), (@class)=&gt;@class.getName(),true);
- colorNodes(parameterNode.nodes(), Color.DarkOrange);
-
- });
+var jni4Net_Active = new API_Jni4Net_Active();
-treeView.beforeExpand&lt;java.lang.reflect.Field&gt;(
- (treeNode,field)=&gt;{
- treeNode.add_Node("ToString: {0}".format(field.toGenericString()), field).foreColor(Color.DarkGray);
- treeNode.add_Node("Java Signature: {0}".format(field.GetSignature()), field).foreColor(Color.DarkGray);;
- });
-
-var classes = new List&lt;java.lang.Class&gt;();
+var classes = jni4Net_Active.java_From_ClassLoader_get_Loaded_Classes();
Action&lt;string&gt; showClasses =
(filter)=&gt;{
@@ -91,46 +28,64 @@ Action&lt;string&gt; showClasses =
: classes.Where((@class)=&gt;@class.getName().str().regEx(filter));
treeView.beginUpdate()
.clear()
- .add_Nodes(classesToShow, (@class)=&gt;@class.getName(), true)
+ .add_Nodes(classesToShow, (@class)=&gt;@class.getName(), true)
.endUpdate();
- colorNodes(treeView.nodes(), Color.DarkOrange);
+ treeView.nodes().colorNodes(Color.DarkRed);
+ treeView.selectFirst();
};
treeView.insert_Above(40,"Filter (RegEx applied on text change)")
.add_TextBox().fill().onTextChange(showClasses);
-
-var classLoader = ClassLoader.getSystemClassLoader();
-var clClass = classLoader.getClass();
-while(clClass != java.lang.ClassLoader._class)
-{
- "{0} - {1}".info(clClass.str(), clClass.getSuperclass().str());
- clClass = clClass.getSuperclass();
-}
-
-var classes_Field = clClass.getDeclaredField("classes");
-var classes_Value = classes_Field.get(classLoader);
-
-var elements_Method = classes_Value.getClass().getMethod("elements",null);
-var elements = elements_Method.invoke(classes_Value,null);
-
-
-while (elements.Invoke&lt;bool&gt;("hasMoreElements","()Z"))
-{
- classes.add(elements.Invoke&lt;java.lang.Class&gt;("nextElement", "()Ljava/lang/Object;"));
-}
-
-
-showClasses("zap");
+Action&lt;Class&gt; showClassSourceCode =
+ (@class)=&gt;{
+ codeViewer.enabled(false);
+ O2Thread.mtaThread(
+ ()=&gt;{
+ var jad = new API_Jad();
+ if (decompileClasses)
+ {
+ var pathToJar = @class.java_Get_Class_Jar_File_Location();
+ if (pathToJar.valid())
+ {
+ var extractedFiles = jad.extractJarIntoTempFolder(pathToJar);
+ var classFile = extractedFiles.pathCombine(@class.FullName.replace(".","\\") + ".class");
+ var javaCode = jad.decompile(classFile);
+ codeViewer.set_Text(javaCode, ".java");
+ }
+ else
+ {
+ codeViewer.set_Text("Error: Could not get location for class: {0}".format(@class.FullName));
+ }
+
+ }
+ codeViewer.enabled(true);
+ });
+ };
+
+treeView.afterSelect&lt;Class&gt;(
+ (@class) =&gt; {
+ showClassSourceCode (@class);
+ });
+treeView.afterSelect&lt;Field&gt;(
+ (field)=&gt;{
+ showClassSourceCode(field.getDeclaringClass());
+ });
+showClasses("");
+//showClasses("zap");
return "done";
-//using java.lang
+//using java.lang
//using net.sf.jni4net;
//using net.sf.jni4net.jni
+//using java.lang.reflect
//using net.sf.jni4net.adaptors
-//O2Ref:C:\__Tests\JNI_4_net\jni4net-0.8.6.0-bin\lib\jni4net.n-0.8.6.0.dll</SourceCode>
+//O2Ref:Jni4Net/lib/jni4net.n-0.8.6.0.dll
+
+//O2File:API_Jni4Net_Active.cs
+//O2File:API_Jad.cs</SourceCode>
<ReferencedAssemblies />
</H2>
View
36 3rdParty/Jni4Net/PoC - Jni4Net - List JavaProperties.h2
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<H2>
+ <SourceCode>O2Setup.extractEmbededConfigZips();
+var topPanel = "PoC - Jni4Net - List JavaProperties: {0}".format(clr.details()).popupWindow().insert_LogViewer();
+var tableList = topPanel.clear().add_TableList("Java Properties").add_Columns("Key", "Value");
+tableList.insert_Below().add_ConsoleOut();
+var bridgeSetup = new BridgeSetup(){Verbose=true};
+try
+{
+ Bridge.CreateJVM(bridgeSetup);
+}
+catch(System.Exception ex)
+{
+ ex.log();
+ return "error";
+}
+java.lang.System.@out.println("Hello Java world!");
+
+
+Properties javaSystemProperties = java.lang.System.getProperties();
+foreach (java.lang.String key in Adapt.Enumeration(javaSystemProperties.keys()))
+ tableList.add_Row(key, java.lang.System.getProperty(key));
+
+
+return "ok";
+//using java.io;
+//using java.lang;
+//using java.util;
+//using net.sf.jni4net;
+//using net.sf.jni4net.adaptors;
+//O2Ref:Jni4Net/lib/jni4net.n-0.8.6.0.dll
+//O2File:API_ConsoleOut.cs
+//O2EmbedTool:Jni4Net
+</SourceCode>
+ <ReferencedAssemblies />
+</H2>
View
84 3rdParty/Snoop/Process Injection Tests/API_O2_Injector.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
+using System.Windows.Forms;
using O2.Kernel;
using O2.Kernel.ExtensionMethods;
using O2.DotNetWrappers.ExtensionMethods;
@@ -8,14 +9,19 @@
using O2.XRules.Database.Utils;
using O2.External.SharpDevelop.ExtensionMethods;
using System.Runtime.InteropServices;
+
//O2File:API_CLR.cs
//O2Ref:Snoop\Snoop\Snoop.exe
//Installer:Snoop_Installer.cs!Snoop\Snoop\Snoop.exe
+//O2File:_Extra_methods_To_Add_to_Main_CodeBase.cs
+
namespace O2.XRules.Database.APIs
{
public class API_O2_Injector
{
+ public string targetFile = "SimpleCSharpREPL.cs".local();
+ //"SimpleCSharpREPL.cs".local()
public bool injectIntoProcess(int processId)
{
@@ -34,12 +40,13 @@ public bool injectIntoProcess(Process process, bool x64, bool runtime40)
{
var codeFile = "Injected_Dll.cs".local();
var fixedCourceCode = codeFile.fileContents() //ensure that we are pointing to the current locations of O2 folders
- .replace(@"E:\O2_V4\O2.Platform.Projects\binaries",PublicDI.config.CurrentExecutableDirectory)
- .replace(@"E:\O2_V4\O2.Platform.Scripts", PublicDI.config.LocalScriptsFolder);
+ .replace(@"%CurrentExecutableDirectory%",PublicDI.config.CurrentExecutableDirectory)
+ .replace(@"%scriptToExecute%",targetFile );
//fixedCourceCode.showInCodeViewer();
- var compiledAssembly = new CompileEngine().compileSourceCode(fixedCourceCode);
+ var compileEngine = new CompileEngine(runtime40 ? "v4.0" : "v3.5") { UseCachedAssemblyIfAvailable = false };
+ var compiledAssembly = compileEngine.compileSourceCode(fixedCourceCode);
if (compiledAssembly.notNull())
- {
+ {
var className = "O2.Script.Test"; //"Snoop.SnoopUI";
var methodName = "GoBabyGo";
return injectIntoProcess(process, compiledAssembly.Location, className, methodName, x64, runtime40);
@@ -61,14 +68,11 @@ public bool injectIntoProcess(Process process,string assemblyToInject, string cl
}
"Injecting into process {0}:{1} dll {1}".info(process.Id,process.ProcessName, assemblyToInject);
-
-
+
var suffix = (x64) ? "64-" : "32-";
suffix += (runtime40) ? "4.0" : "3.5";
- //var process = Processes.getProcess(12168);
+
var hwnd = process.MainWindowHandle;
-// var hwnd = process.Handle;
- //var hwnd = new IntPtr(398680);
if (hwnd == IntPtr.Zero)
{
"Could not get MainWindow handle".error();
@@ -79,14 +83,9 @@ public bool injectIntoProcess(Process process,string assemblyToInject, string cl
var snoopAssembly = @"Snoop\Snoop\Snoop.exe".assembly();
var directoryName = snoopAssembly.Location.directoryName();
- //return process.MainModule;
-// var suffix = snoopAssembly.type("Injector")
-// .invokeStatic("Suffix", hwnd);
-// suffix = "64-4.0";
var fileName = directoryName.pathCombine("ManagedInjectorLauncher" + suffix+ ".exe");
-
- var windowHandle= hwnd;
+ var windowHandle= hwnd;
var arguments = string.Concat(new object[]
{
@@ -103,40 +102,31 @@ public bool injectIntoProcess(Process process,string assemblyToInject, string cl
}
}
}
-
- public static class API_O2_Injector_ExtensionMethods
+
+
+ public static class API_O2_Injector_GUI_Helpers
{
- public static Process process_MainWindow_BringToFront(this Process process)
+ public static FlowLayoutPanel add_FlowLayoutPanel_with_DetectedModules(this Control targetControl, Process process)
{
- if (process.MainWindowHandle != IntPtr.Zero)
- "WindowsBase.dll".assembly()
- .type("UnsafeNativeMethods")
- .invokeStatic("SetForegroundWindow",new HandleRef(null, process.MainWindowHandle)) ;
- else
- "[process_MainWindow_BringToFront] provided process has no main Window".error();
- return process;
+ targetControl.clear();
+
+ var modules_byModuleName = process.modules_Indexed_by_ModuleName();
+ var modules_byFileName = process.modules_Indexed_by_FileName();
+
+ var flowPanel = targetControl.add_FlowLayoutPanel();
+ Func<string,string, Button> add_Mapping =
+ (key, text)=>{
+ if (modules_byModuleName.hasKey(key) || modules_byFileName.hasKey(key))
+ return flowPanel.add_Button(text);
+ return null;
+ };
+
+
+ add_Mapping("mscoree.dll" , "CLR").green();
+ add_Mapping(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll" , "CLR 4.0 32bit").blue();
+ add_Mapping(@"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll" , "CLR 4.0 64bit").blue();
+ add_Mapping("java.dll", "JVM").green();
+ return flowPanel;
}
-
- public static bool is64BitProcess(this Process process )
- {
- if (process.isNull())
- {
- "in process.is64BitProcess provided process value was null!".error();
- return false;
- }
- bool lIs64BitProcess = false;
- if ( System.Environment.Is64BitOperatingSystem ) {
- IsWow64Process( process.Handle, out lIs64BitProcess );
- }
- "[Is Target Process 64Bit = {0}]".debug(lIs64BitProcess);
- return lIs64BitProcess;
- }
-
- [DllImport( "kernel32.dll" )]
- static extern bool IsWow64Process( System.IntPtr aProcessHandle, out bool lpSystemInfo );
}
-
-
-
-
}
View
28 3rdParty/Snoop/Process Injection Tests/Injected_Dll.cs
@@ -1,5 +1,6 @@
// This file is part of the OWASP O2 Platform (http://www.owasp.org/index.php/OWASP_O2_Platform) and is released under the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0)
using System;
+using System.IO;
using System.Diagnostics;
using System.Reflection;
using System.Linq;
@@ -13,7 +14,7 @@ namespace O2.Script
public class Test
{
static Process CurrentProcess = System.Diagnostics.Process.GetCurrentProcess();
- static string assemblyLocation = @"E:\O2_V4\O2.Platform.Projects\binaries\O2_FluentSharp_CoreLib.dll";
+ static string assemblyLocation = @"%CurrentExecutableDirectory%\O2_FluentSharp_CoreLib.dll";
static Assembly assembly = Assembly.LoadFrom(assemblyLocation);
@@ -107,21 +108,24 @@ public static void executeFirstMethod(Assembly _assembly)
}
}
- public static void injectO2Script()
+ public static void executeDefaultO2Script()
{
//var file = @"E:\O2_V4\O2.Platform.Scripts\Utils\O2\ascx_Quick_Development_GUI.cs.o2";
//var file = @"E:\O2_V4\O2.Platform.Scripts\Utils\O2\Util - C# REPL Script.h2";
//var file = @"E:\O2_V4\O2.Platform.Scripts\APIs\C# REPL\Util - Text Based C# REPL.h2";
//var file = @"E:\O2_V4\O2.Platform.Scripts\Utils\Web\SimpleTextEditor.cs";
- var file = @"E:\O2_V4\O2.Platform.Scripts\Utils\Web\SimpleCSharpREPL.cs";
- info("Injecting O2 REPL editor by compiling file: " + file);
- var compiledAssembly = compileFile(file);
- if (compiledAssembly == null)
- info("Error: in injectO2Script, failed to compile: " + file);
- else
+ var file = @"%scriptToExecute%";
+ if (File.Exists(file))
{
- executeFirstMethod(compiledAssembly);
- info("Injected O2 REPL editor");
+ info("compiling Default O2 Script: " + file);
+ var compiledAssembly = compileFile(file);
+ if (compiledAssembly == null)
+ info("Error: in injectO2Script, failed to compile: " + file);
+ else
+ {
+ info("executing first method from: " + compiledAssembly.Location);
+ executeFirstMethod(compiledAssembly);
+ }
}
}
@@ -133,14 +137,14 @@ public static string GoBabyGo()
//System.Windows.Forms.MessageBox.Show("About to Inject script");
try
{
- Assembly bcl = Assembly.LoadFrom(@"E:\O2_V4\O2.Platform.Projects\binaries\O2_FluentSharp_BCL.dll");
+ //Assembly bcl = Assembly.LoadFrom(@"E:\O2_V4\O2.Platform.Projects\binaries\O2_FluentSharp_BCL.dll");
//Assembly repl = Assembly.LoadFrom(@"E:\O2_V4\O2.Platform.Projects\binaries\O2_FluentSharp_REPL.dll");
}
catch(Exception ex)
{
info("Error: loading assemblies " + ex.Message);
}
- injectO2Script();
+ executeDefaultO2Script();
//listLoadedAssemblies();
//info("Starting nodepad");
// startProcess("notepad.exe");
View
135 3rdParty/Snoop/Process Injection Tests/Util - Inject O2 into other processes.h2
@@ -1,43 +1,67 @@
<?xml version="1.0"?>
<H2>
- <SourceCode>//var topPanel = panel.clear().add_Panel();
-var topPanel = "Util - Inject O2 into Other processes".popupWindow(600,600);
-topPanel.insert_LogViewer();
-var actionsPanel = topPanel.insert_Above(40,"Actions");
-var processesTreeView = topPanel.title("Current Processes (with MainWindowHandle != 0)").add_TreeView_with_PropertyGrid().sort();
-var modulesTreeView = topPanel.insert_Right("Selected Process Modules List").add_TreeView_with_PropertyGrid().sort();
-processesTreeView.splitContainer().splitterDistance(300);
-modulesTreeView.splitContainer().splitterDistance(300);
-Process selectedProcess = null;
-CheckBox x64_CheckBox = null;
-CheckBox runtime40_ChexkBox = null;
+ <SourceCode>//var topPanel = panel.clear().add_Panel();
+
+var topPanel = "Util - Inject O2 into Other processes v2.0".popupWindow(1200,600);
+topPanel.insert_LogViewer();
+
+
+var processesTreeView = topPanel.title("Current Processes (with MainWindowHandle != 0)").add_TreeView().sort();
+var tabPanel = topPanel.insert_Right().add_TabControl();
+var selectedProcessTab = tabPanel.add_Tab("Selected Process details").add_Panel();
+//var modulesTreeView = tabPanel.add_Tab("Selected Process Modules List").add_TreeView_with_PropertyGrid().sort();
-bool x64 = false;
-bool runtime40 = false;
+var modulesTreeView = selectedProcessTab.insert_Below("Selected Process Modules List").add_TreeView_with_PropertyGrid(false).sort();
+var processScreenshot = modulesTreeView.insert_Left(100).add_PictureBox();
+//processesTreeView.splitContainer().splitterDistance(300);
+//modulesTreeView.splitContainer().splitterDistance(300);
+Process selectedProcess = null;
+CheckBox x64_CheckBox = null;
+CheckBox runtime40_CheckBox = null;
+
+Action&lt;Process&gt; selectProcess =
+ (process)=&gt; {
+ "select process: {0}".info(process.Id);
+ foreach(var treeNode in processesTreeView.nodes())
+ if (treeNode.tag&lt;Process&gt;().Id == process.Id)
+ {
+ treeNode.selected();
+ return;
+ }
+
+ };
processesTreeView.afterSelect&lt;Process&gt;(
(process)=&gt; {
- selectedProcess = process;
- modulesTreeView.clear();
- modulesTreeView.parent&lt;GroupBox&gt;().set_Text("Showing Modules for process: {0} (id: {1})".format(process.ProcessName, process.Id));
-
+ selectedProcess = Processes.getProcess(process.Id); //to refresh the values
+ modulesTreeView.clear();
+ selectedProcessTab.parent&lt;TabPage&gt;().set_Text("Selected process: {0} (id: {1})".format(process.ProcessName, process.Id));
+ //modulesTreeView.parent&lt;GroupBox&gt;()
+ O2Thread.mtaThread(
+ ()=&gt;{
+ processScreenshot.load(selectedProcess.screenshot_MainWindow() as Image);
+ selectedProcessTab.add_FlowLayoutPanel_with_DetectedModules(process);
+ });
try
{
foreach(ProcessModule module in process.Modules)
modulesTreeView.add_Node(module.ModuleName, module);
- modulesTreeView.selectFirst();
-
- x64_CheckBox.@checked(process.is64BitProcess());
- runtime40_ChexkBox.@checked(process.isRuntime_V4());
+ modulesTreeView.selectFirst();
+
+ x64_CheckBox.@checked(process.is64BitProcess());
+ runtime40_CheckBox.@checked(process.isRuntime_V4());
modulesTreeView.white();
- }
+ }
catch(Exception ex)
{
- ex.log();
- x64_CheckBox.@checked(false);
- runtime40_ChexkBox.@checked(false);
- modulesTreeView.pink();
- }
+ ex.log();
+ x64_CheckBox.@checked(ex.Message == "A 32 bit processes cannot access modules of a 64 bit process.");
+ runtime40_CheckBox.@checked(false);
+ modulesTreeView.pink()
+ .add_Node("Can't access Module list").treeView()
+ .add_Node("Exception: {0}".format(ex.Message.info()));
+ }
+
});
Action refreshProcessList =
@@ -57,31 +81,52 @@ Action refreshProcessList_in_1Second =
Action injectO2IntoProcess =
()=&gt;{
"Injecting O2 into process '{0}' with id {1}".info(selectedProcess.ProcessName, selectedProcess.Id);
- var o2Injector = new API_O2_Injector();
- o2Injector.injectIntoProcess(selectedProcess, x64, runtime40);
- };
+ var o2Injector = new API_O2_Injector();
+ o2Injector.injectIntoProcess(selectedProcess, x64_CheckBox.value(), runtime40_CheckBox.value());
+ };
+
+processesTreeView.insert_Below_ToolStrip()
+ .add_Button("Refresh", "view_refresh".formImage(), ()=&gt; refreshProcessList())
+ .add_Button("Process Properties", "btSettings_Image".formImage(), ()=&gt; processesTreeView.selected().Tag.showInfo())
+ .add_Button("Bring to front", "preferences_desktop_locale".formImage(), ()=&gt; selectedProcess.process_MainWindow_BringToFront())
+ .add_Button("Stop Process", "process_stop".formImage(), () =&gt; { selectedProcess.stop(); refreshProcessList();});
+
+
+selectedProcessTab.insert_ToolStrip()
+ .add_Button("Inject O2 into Process","btExecuteSelectedMethod_Image".formImage(), ()=&gt;injectO2IntoProcess())
+ .add_CheckBox("x64",ref x64_CheckBox)
+ .add_CheckBox(".Net 40 runtime",ref runtime40_CheckBox);
+
+var toolStrip = topPanel.insert_Above(30).add_ToolStrip();
+toolStrip.add_DropDown("REPL", "document_save_as".formImage())
+ .add_DropDown_Button("REPL this Form ", ()=&gt; topPanel.parentForm().script_Me("form"))
+ .add_DropDown_Button("REPL selected Process and API_O2_Injector ",
+ ()=&gt; new API_O2_Injector().script_Me().add_InvocationParameter("process", selectedProcess).code_Insert("//return process;"))
+ //.add_DropDown_Button("REPL selected Process", ()=&gt; selectedProcess.script_Me())
+ ;
+
+toolStrip.add_DropDown("Open Demo Apps", "face_glasses".formImage())
+ .add_DropDown_Button("Open LinqPad (C#) " , ()=&gt; { "LinqPad_Installer.cs".executeFirstMethod() ; refreshProcessList_in_1Second(); })
+ .add_DropDown_Button("Open Calc (C++) " , ()=&gt; { "calc.exe".startProcess() ; refreshProcessList_in_1Second(); });
+toolStrip.add_Button("Open DbgViewer.exe (SysInternals)", "btDebugMethod_Image".formImage(), ()=&gt; "DebugView.cs".executeFirstMethod());
+
+toolStrip.insert_Right(160).add_ProcessFinder(selectProcess, selectProcess).append_Label("Click to select process").top(10);
-processesTreeView.add_ContextMenu()
- .add_MenuItem("Bring this process MainWindow to Front", true,()=&gt; selectedProcess.process_MainWindow_BringToFront())
- .add_MenuItem("Inject O2 Into this process", true,()=&gt; injectO2IntoProcess())
- .add_MenuItem("Refresh Process List", true,()=&gt; refreshProcessList())
- ;
+//toolStrip.insert_Left(30).add_ProcessFindings((process)=&gt;{});
+//&lt;Ctrl_ProcessFinder&gt;
+//O2File:Ctrl_ProcessFinder.cs
-var lastLink = actionsPanel.add_Link("Inject O2 into Process", ()=&gt;injectO2IntoProcess())
- .append_Label("(and open C# REPL Editor)").autoSize()
- .append_Link("Open LinqPad (C#)", ()=&gt; { "LinqPad.cs".executeFirstMethod() ; refreshProcessList_in_1Second(); })
- .append_Link("Open Calc (C++)", ()=&gt; { "calc.exe".startProcess() ; refreshProcessList_in_1Second(); })
- .append_Link("Open DebugView", ()=&gt; { "DebugView.cs".executeFirstMethod() ; });
-
-x64_CheckBox = lastLink.append_CheckBox("x64", (value)=&gt;x64= value);
-runtime40_ChexkBox = x64_CheckBox.append_CheckBox(".Net 40 runtime", (value)=&gt; runtime40 = value);
+//x64_CheckBox = lastLink.append_CheckBox("x64", (value)=&gt;x64= value);
+//runtime40_ChexkBox = x64_CheckBox.append_CheckBox(".Net 40 runtime", (value)=&gt; runtime40 = value);
refreshProcessList();
+
//injectO2IntoProcess();
//using System.Diagnostics
-//O2File:API_O2_Injector.cs
-//O2Tag_DontAddExtraO2Files
+//O2File:API_O2_Injector.cs
+
+//O2File:_Extra_methods_To_Add_to_Main_CodeBase.cs
</SourceCode>
<ReferencedAssemblies />
</H2>
View
358 Utils/ExtensionMethods/_Extra_methods_To_Add_to_Main_CodeBase.cs
@@ -34,10 +34,11 @@
using O2.Views.ASCX.CoreControls;
using O2.Views.ASCX.classes.MainGUI;
using O2.Views.ASCX.ExtensionMethods;
+using O2.Platform.BCL.O2_Views_ASCX;
using O2.External.SharpDevelop.AST;
using O2.External.SharpDevelop.ExtensionMethods;
using O2.External.SharpDevelop.Ascx;
-
+using O2.XRules.Database.Utils;
using ICSharpCode.TextEditor;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Ast;
@@ -51,34 +52,365 @@
using System.Security.Cryptography;
-//O2File:_Extra_methods_Browser.cs
-namespace O2.XRules.Database.Utils
+namespace O2.XRules.Database.APIs
{
- public static class Extra_Object
+ public static class Extra_TreeView
{
-
+ public static List<TreeNode> colorNodes(this List<TreeNode> nodes, Color color)
+ {
+ if (nodes.notNull() && nodes.size()>0)
+ {
+ var treeView = nodes.first().treeView();
+ treeView.beginUpdate();
+ foreach(var node in nodes)
+ node.foreColor(color);
+ treeView.endUpdate();
+ }
+ return nodes;
+ }
+ }
+ public static class Extra_WinForm_Controls_Forms
+ {
+ public static Image formImage(this string imageKey)
+ {
+ return (Image)typeof(FormImages).prop(imageKey);
+ }
}
- public static class Extra_WinForm_Controls_ToolStripLayout
+ public class ToolStripCheckBox : ToolStripControlHost
+ {
+ public ToolStripCheckBox()
+ : base(new CheckBox())
+ {
+ this.BackColor = Color.Transparent;
+ this.Margin = new Padding(1,3,1,1);
+ }
+ }
+
+ public static class Extra_WinForm_Controls_ToolStrip
{
+ public static ToolStrip insert_ToolStrip(this Control control)
+ {
+ var panel = control.insert_Above(30);
+ panel.splitContainer().fixedPanel1().@fixed(true);;
+ return panel.add_ToolStrip();
+ }
+ public static ToolStrip insert_Below_ToolStrip(this Control control)
+ {
+ var panel = control.insert_Below(30);
+ panel.splitContainer().fixedPanel2().@fixed(true);;
+ return panel.add_ToolStrip();
+ }
+ public static ToolStrip add_CheckBox(this ToolStrip toolStrip, string text, Action<bool> onValueChange)
+ {
+ CheckBox checkBox_Ref = null;
+ return toolStrip.add_CheckBox(text, ref checkBox_Ref, onValueChange);
+ }
+ public static ToolStrip add_CheckBox(this ToolStrip toolStrip, string text, ref CheckBox checkBox_Ref)
+ {
+ return toolStrip.add_CheckBox(text, ref checkBox_Ref, (value)=> {});
+ }
+ public static ToolStrip add_CheckBox(this ToolStrip toolStrip, string text, ref CheckBox checkBox_Ref, Action<bool> onValueChange)
+ {
+ return toolStrip.add_CheckBox(text, null, ref checkBox_Ref, onValueChange);
+ }
+ public static ToolStrip add_CheckBox(this ToolStrip toolStrip, string text, Image image, ref CheckBox checkBox_Ref, Action<bool> onValueChange)
+ {
+ var checkBox = toolStrip.add_Control<ToolStripCheckBox>().Control as CheckBox;
+ checkBox_Ref = checkBox; // need to do this because we can't use the ref object inside the lambda method below
+ return toolStrip.invokeOnThread(
+ ()=>{
+ checkBox.Text = text;
+ checkBox.Image = image;
+ checkBox.CheckedChanged += (sender,e)=>
+ O2Thread.mtaThread(()=> onValueChange(checkBox.value()));
+ return toolStrip;
+ });
+
+ }
+ //merge with current one add_Button (without the image)
+ public static ToolStrip add_Button(this ToolStrip toolStrip, string text, Image image, Action onClick)
+ {
+ return toolStrip.invokeOnThread(
+ ()=>{
+ var newButton = new ToolStripButton(text);
+ newButton.Image = image;
+ newButton.Click += (sender,e)=> O2Thread.mtaThread(()=> onClick());
+ toolStrip.Items.Add(newButton);
+ return toolStrip;
+ });
+ }
+
+ public static ToolStripDropDown add_DropDown(this ToolStrip toolStrip, string text)
+ {
+ return toolStrip.add_DropDown(text,null);
+ }
+ public static ToolStripDropDown add_DropDown(this ToolStrip toolStrip, string text, Image image)
+ {
+ return toolStrip.invokeOnThread(
+ ()=>{
+ var dropDown = new ToolStripDropDown();
+ var menuButton = new ToolStripDropDownButton(text);
+ menuButton.Image = image;
+ menuButton.DropDown = dropDown;
+ toolStrip.Items.Add(menuButton);
+ return dropDown;
+ });
+ }
+ public static ToolStripDropDown add_DropDown_Button(this ToolStripDropDown dropDown, string text, Action onClick)
+ {
+ return dropDown.add_DropDown_Button(text, null, onClick);
+ }
+
+ public static ToolStripDropDown add_DropDown_Button(this ToolStripDropDown dropDown, string text, Image image, Action onClick)
+ {
+ return dropDown.invokeOnThread(
+ ()=>{
+ var newButton = new ToolStripButton(text);
+ newButton.Click += (sender,e)=> O2Thread.mtaThread(()=> onClick());
+ dropDown.Items.Add(newButton);
+ return dropDown;
+ });
+ }
}
- public static class Extra_Items
- {
+ public static class Extra_Processes
+ {
+ public static List<ProcessModule> modules(this Process process)
+ {
+ var modules = new List<ProcessModule>();
+ try
+ {
+ foreach(ProcessModule module in process.Modules)
+ modules.Add(module);
+ }
+ catch(Exception ex)
+ {
+ ex.log();
+ }
+ return modules;
+ }
+ public static List<string> names(this List<ProcessModule> modules)
+ {
+ return modules.Select((module)=> module.ModuleName).toList();
+ }
+ public static Dictionary<string,ProcessModule> modules_Indexed_by_ModuleName(this Process process)
+ {
+ //return process.modules().ToDictionary((module)=> module.ModuleName.lower());; //doesn't handle duplicate names
+ var modulesIndexed = new Dictionary<string,ProcessModule>();
+ foreach(var module in process.modules())
+ modulesIndexed.add(module.ModuleName.lower(), module);
+ return modulesIndexed;
+ }
+
+ public static Dictionary<string,ProcessModule> modules_Indexed_by_FileName(this Process process)
+ {
+ var modulesIndexed = new Dictionary<string,ProcessModule>();
+ foreach(var module in process.modules())
+ modulesIndexed.add(module.FileName.lower(), module);
+ return modulesIndexed;
+ }
+ public static Process process_WithId(this int id)
+ {
+ return Processes.getProcess(id);
+ }
+ public static Process process_WithName(this string name)
+ {
+ return Processes.getProcessCalled(name);
+ }
+ public static Process process_MainWindow_BringToFront(this Process process)
+ {
+ if (process.MainWindowHandle != IntPtr.Zero)
+ "WindowsBase.dll".assembly()
+ .type("UnsafeNativeMethods")
+ .invokeStatic("SetForegroundWindow",new HandleRef(null, process.MainWindowHandle)) ;
+ else
+ "[process_MainWindow_BringToFront] provided process has no main Window".error();
+ return process;
+ }
+
+ public static bool is64BitProcess(this Process process )
+ {
+ if (process.isNull())
+ {
+ "in process.is64BitProcess provided process value was null!".error();
+ return false;
+ }
+ bool lIs64BitProcess = false;
+ //if ( System.Environment.Is64BitOperatingSystem )
+ //{
+ IsWow64Process( process.Handle, out lIs64BitProcess );
+ return ! lIs64BitProcess; // weirdly the value is reversed
+ //}
+ //"[Is Target Process 64Bit = {0}]".debug(lIs64BitProcess);
+ //return lIs64BitProcess;
+ }
+
+ [DllImport( "kernel32.dll" )]
+ public static extern bool IsWow64Process( System.IntPtr aProcessHandle, out bool lpSystemInfo );
}
- public static class Extra_Controls
+ public static class Extra_ascx_Simple_Script_Editor
{
-
-
+ public static ascx_Simple_Script_Editor add_InvocationParameter(this ascx_Simple_Script_Editor scriptEditor, string parameterName, object parameterObject)
+ {
+ scriptEditor.InvocationParameters.add(parameterName,parameterObject);
+ return scriptEditor;
+ }
+ public static ascx_Simple_Script_Editor code_Insert(this ascx_Simple_Script_Editor scriptEditor, string textToInsert)
+ {
+ scriptEditor.Code = textToInsert.line() + scriptEditor.Code;
+ return scriptEditor;
+ }
+ public static ascx_Simple_Script_Editor code_Append(this ascx_Simple_Script_Editor scriptEditor, string textToInsert)
+ {
+ scriptEditor.Code = scriptEditor.Code.line() + scriptEditor.Code;
+ return scriptEditor;
+ }
}
- public static class Extra_String
+ public static class Extra_Screenshot
{
+ //based on code from http://stackoverflow.com/a/911225
+ public static Bitmap screenshot_MainWindow(this Process process)
+ {
+ return PrintWindow(process.MainWindowHandle);
+ }
+
+
+ [DllImport("user32.dll")]
+ public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
+ [DllImport("user32.dll")]
+ public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags);
+
+ public static Bitmap PrintWindow(IntPtr hwnd)
+ {
+ RECT rc;
+ GetWindowRect(hwnd, out rc);
-
+ Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
+ Graphics gfxBmp = Graphics.FromImage(bmp);
+ IntPtr hdcBitmap = gfxBmp.GetHdc();
+
+ PrintWindow(hwnd, hdcBitmap, 0);
+
+ gfxBmp.ReleaseHdc(hdcBitmap);
+ gfxBmp.Dispose();
+
+ return bmp;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct RECT
+ {
+ private int _Left;
+ private int _Top;
+ private int _Right;
+ private int _Bottom;
+
+ public RECT(RECT Rectangle) : this(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom)
+ {
+ }
+ public RECT(int Left, int Top, int Right, int Bottom)
+ {
+ _Left = Left;
+ _Top = Top;
+ _Right = Right;
+ _Bottom = Bottom;
+ }
+
+ public int X {
+ get { return _Left; }
+ set { _Left = value; }
+ }
+ public int Y {
+ get { return _Top; }
+ set { _Top = value; }
+ }
+ public int Left {
+ get { return _Left; }
+ set { _Left = value; }
+ }
+ public int Top {
+ get { return _Top; }
+ set { _Top = value; }
+ }
+ public int Right {
+ get { return _Right; }
+ set { _Right = value; }
+ }
+ public int Bottom {
+ get { return _Bottom; }
+ set { _Bottom = value; }
+ }
+ public int Height {
+ get { return _Bottom - _Top; }
+ set { _Bottom = value + _Top; }
+ }
+ public int Width {
+ get { return _Right - _Left; }
+ set { _Right = value + _Left; }
+ }
+ public Point Location {
+ get { return new Point(Left, Top); }
+ set {
+ _Left = value.X;
+ _Top = value.Y;
+ }
+ }
+ public Size Size {
+ get { return new Size(Width, Height); }
+ set {
+ _Right = value.Width + _Left;
+ _Bottom = value.Height + _Top;
+ }
+ }
+
+ public static implicit operator Rectangle(RECT Rectangle)
+ {
+ return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
+ }
+ public static implicit operator RECT(Rectangle Rectangle)
+ {
+ return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
+ }
+ public static bool operator ==(RECT Rectangle1, RECT Rectangle2)
+ {
+ return Rectangle1.Equals(Rectangle2);
+ }
+ public static bool operator !=(RECT Rectangle1, RECT Rectangle2)
+ {
+ return !Rectangle1.Equals(Rectangle2);
+ }
+
+ public override string ToString()
+ {
+ return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}";
+ }
+
+ public override int GetHashCode()
+ {
+ return ToString().GetHashCode();
+ }
+
+ public bool Equals(RECT Rectangle)
+ {
+ return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom;
+ }
+
+ public override bool Equals(object Object)
+ {
+ if (Object is RECT) {
+ return Equals((RECT)Object);
+ } else if (Object is Rectangle) {
+ return Equals(new RECT((Rectangle)Object));
+ }
+
+ return false;
+ }
+ }
}
View
35 Utils/Web/SimpleCSharpREPL.cs
@@ -1,41 +1,18 @@
// This file is part of the OWASP O2 Platform (http://www.owasp.org/index.php/OWASP_O2_Platform) and is released under the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0)
using System;
using System.Windows.Forms;
+using O2.Kernel;
using O2.DotNetWrappers.Windows;
using O2.DotNetWrappers.ExtensionMethods;
-//O2Ref:O2_FluentSharp_BCL.dll
+//O2Ref:O2_FluentSharp_REPL.dll
namespace O2.XRules.Database.Utils
{
- public class SimpleCSharpREPL
+ public class CSharpREPL
{
- public static Panel launch()
- {
- var topPanel = "Util - Text Based C# REPL".popupWindow(800,400).insert_LogViewer();
-
- var replGui = topPanel.add_REPL_Gui();
-
- var codeText = replGui.Code_Panel.add_TextArea().allowTabs();
-
-
- Action execute =
- ()=>{
- var compilationOk = false;
- var code = codeText.get_Text();
- var result = code.compileAndExecuteCodeSnippet(
- (okMsg)=> { replGui.showOutput(okMsg); compilationOk = true;},
- (failMsg)=> { replGui.showErrorMessage(failMsg); });
- if(compilationOk)
- replGui.showOutput(result);
- //replGui.Output_RichTextBox.set_Text(code);
- };
-
- replGui.On_ExecuteCode = execute;
-
- codeText.set_Text("return \"Hello World\";");
-
- replGui.Execute_Button.click();
- return topPanel;
+ public static ascx_Panel_With_Inspector launch()
+ {
+ return open.scriptEditor();
}
}
}
View
16 _Custom_O2s/v4.1/Main O2 Gui.h2
@@ -95,15 +95,19 @@ menu.add_MenuItem("Main")
menu.add_MenuItem("Debug")
.add_MenuItem("Restart O2 (will kill current process)", ()=&gt; { Application.ExecutablePath.startProcess(); Processes.getCurrentProcess().stop();})
.add_MenuItem("View O2 Config Object", ()=&gt; PublicDI.config.showInfo())
- .add_MenuItem("Clear Compilation Cache and Downloads",()=&gt; { CompileEngine.clearAllCompilationRelatedDownloadsAndCaches();})
.add_MenuItem("Compile All Scripts",()=&gt; executeH2Script("Compile All Local O2 Scripts.h2"))
.add_MenuItem("REPL this GUI",()=&gt; topPanel.parentForm().script_Me("form"))
- .add_MenuItem("Folders",false)
+ .add_MenuItem("Folders",false)
.add_MenuItem("TempDir",()=&gt; PublicDI.config.O2TempDir.startProcess())
- .add_MenuItem("References Downloaded",()=&gt; PublicDI.config.ReferencesDownloadLocation.startProcess())
- .add_MenuItem("Embedded Assemblies",()=&gt; PublicDI.config.EmbeddedAssemblies.startProcess())
- .add_MenuItem("Tools or APIs",()=&gt; PublicDI.config.ToolsOrApis.startProcess())
- .add_MenuItem("of current Executable",()=&gt; PublicDI.config.CurrentExecutableDirectory.startProcess());
+ .add_MenuItem("References Downloaded",()=&gt; PublicDI.config.ReferencesDownloadLocation.startProcess())
+ .add_MenuItem("Embedded Assemblies",()=&gt; PublicDI.config.EmbeddedAssemblies.startProcess())
+ .add_MenuItem("Tools or APIs",()=&gt; PublicDI.config.ToolsOrApis.startProcess())
+ .add_MenuItem("of current Executable",()=&gt; PublicDI.config.CurrentExecutableDirectory.startProcess());
+
+menu.add_MenuItem("Compilation Cache(s)")
+ .add_MenuItem("Clear LocalScript mappings",()=&gt; { CompileEngine.clearLocalScriptFileMappings();})
+ .add_MenuItem("Clear Compilation Cache",()=&gt; { CompileEngine.clearCompilationCache();})
+ .add_MenuItem("Clear Compilation Cache and Downloads",()=&gt; { CompileEngine.clearAllCompilationRelatedDownloadsAndCaches();});
menu.add_MenuItem("Help")
.add_MenuItem("Report bug",()=&gt; ReportBug.showGui(topPanel))

0 comments on commit 31adc75

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