public void TaskDumpRecord(string args) { String[] taskArgs = args.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (taskArgs.Length != 1) { Console.WriteLine("Invalid number of arguments: ({0})", taskArgs.Length); return; } else { MMemoryLoader.DumpMMRecord(taskArgs[0]); } }
public void TaskLocal(string args) { List <String> lTypes = new List <String>() { "py", "cs", "dll", "zip" }; List <String> lAccess = new List <String>() { "file", "anon" }; String[] taskArgs = args.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (taskArgs.Length != 3) { Console.WriteLine("Invalid number of arguments: ({0})", taskArgs.Length); return; } String type = taskArgs[0]; String location = taskArgs[1]; // Does not handle \s or \t in path name, as args is a string. String access = taskArgs[2]; if (lTypes.Exists(t => t == type)) { if (lAccess.Exists(a => a == access)) { if (System.IO.File.Exists(location)) { Console.WriteLine("Passing type:{0} location:{1} access:{2}", type, location, access); MMemoryLoader.LoadMMRecordFromFile(location, type); } else { Console.WriteLine("Invalid argument <{0}>", location); } } else { Console.WriteLine("Invalid argument <{0}>", access); } } else { Console.WriteLine("Invalid argument <{0}>", type); } }
public void TaskPrintMap(string args) { MMemoryLoader.PrintMemoryMap(); }
/// <summary> /// Run Cs extension ora Py Script /// </summary> /// <param name="mmLocation"></param> public static void RunMMRecord(String mmLocation) { Dictionary <String, MMRecord> mmfRepo = MMemoryLoader.GetMMFRepo(); Console.WriteLine("In RunMMRecord"); if (mmfRepo.ContainsKey(mmLocation)) { MMRecord mmr; if (mmfRepo.TryGetValue(mmLocation, out mmr)) { Console.WriteLine("After TryGetValue"); Console.WriteLine("Found {0}, {1}, {2}", mmr.ResourceSize, mmr.ResourceType, mmr.ResourceMMFile); switch (mmr.ResourceType.ToLower()) { case "py": try { dynamic pengine = IPythonUtil.GetPyEngine(); dynamic pscope = IPythonUtil.GetNewScope(); String pyCodeContent = MMemoryLoader.MMRecordContentString(mmLocation); if (ConfigUtil.DEBUG) { Console.WriteLine("Python Code: \n\n__BEGIN__\n\n{0}\n\n__END__\n\n", pyCodeContent); } dynamic pythonScript = IPythonUtil.GetPyEngine().CreateScriptSourceFromString(pyCodeContent); Console.WriteLine("Execute Python script ({0}) contents from memory", mmLocation); pythonScript.Execute(pscope); } catch (Exception ae) { Console.WriteLine("Iron Python Scope/Execution not created: {0}", ae.Message); } break; case "cs": Console.WriteLine("ResourceType {0}", mmr.ResourceType); String csCodeContent = MMemoryLoader.MMRecordContentString(mmLocation); Console.WriteLine("csCodeContent {0}", csCodeContent); // Load CS Source Code of the extension, MMRecord's name is the name of the TypeToRun param // when MMemoryLoader loads resource it might contain extension on the file, strip it when passing to TypeToRun // Name of the MMRecord is the name of the TypeToRun minus extension. Name your extension file accordingly // Example: If Memory File is WmiQuery.cs then TypeToRun is `WmiQuery` DynCSharpRunner.CompileRunXSource(csCodeContent, String.Join(".", new String[2] { "Typhoon.Extensions", mmLocation.Replace( String.Concat(new String[] { ".", mmr.ResourceType }), String.Empty) })); break; default: Console.WriteLine("Unknown ResourceType {0}", mmr.ResourceType); break; } } else { Console.WriteLine("Unable to get {0}. Valid value?", mmLocation); } } else { Console.WriteLine("Unable to find {0}. Valid value?", mmLocation); } }