ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Home
Upgrade
Credits
Help
Search
Awards
Achievements
 2641

WPF Exploit | Monaco Error

by LordKenny - 02-23-2020 - 01:38 PM
#1
Hello guys!

I don't know if this is the correct section to post this in, please correct me if it's not and I will remove it right away.
I am currently developing an exploit in WPF (Visual Studio 2019). I have a basic UI, and I have programmed most of the exploit, including the DLL. Now I just need Monaco, which I have almost finished but I keep getting an error that I cannot quite seem to fix. Could somebody please look through the code and see if they can figure out the issue?

FULL EXCEPTION:

System.Exception
HResult=0x80131500
Message=Unable to execute javascript at this time, scripts can only be executed within a V8Context. Use the IWebBrowser.CanExecuteJavascriptInMainFrame property to guard against this exception. See https://github.com/cefsharp/CefSharp/wik...javascript for more details on when you can execute javascript. For frames that do not contain Javascript then no V8Context will be created. Executing a script once the frame has loaded it's possible to create a V8Context. You can use browser.GetMainFrame().ExecuteJavaScriptAsync(script) or browser.GetMainFrame().EvaluateScriptAsync to bypass these checks (advanced users only).
Source=CefSharp
StackTrace:
at CefSharp.WebBrowserExtensions.ExecuteScriptAsync(IWebBrowser browser, String script)
at RoSlasher_UI_WPF.Monaco.SetTheme(MonacoTheme theme)
at RoSlasher_UI_WPF.MainWindow.<Browser_MonacoReady>d__5.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

This exception was originally thrown at this call stack:
CefSharp.WebBrowserExtensions.ExecuteScriptAsync(CefSharp.IWebBrowser, string)
RoSlasher_UI_WPF.Monaco.SetTheme(RoSlasher_UI_WPF.MonacoTheme)
RoSlasher_UI_WPF.MainWindow.Browser_MonacoReady()
System.Runtime.CompilerServices.AsyncMethodBuilderCore.ThrowAsync.AnonymousMethod__6_1(object)
System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object)
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, object, bool)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, object, bool)
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
System.Threading.ThreadPoolWorkQueue.Dispatch()
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()


MONACO.CS:

using System;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using CefSharp;
using CefSharp.Wpf;
using CefSharp.Wpf.Internals;

namespace RoSlasher_UI_WPF
{
public enum MonacoTheme
{
Light = 0,
Dark = 1
}

public class MonacoSettings
{
public bool ReadOnly; // The ability to edit text.
public bool AutoIndent; // Enables auto indentation & adjustment
public bool Folding; // Enables code folding.
public bool FontLigatures; // Enables font ligatures.
public bool Links; // Enables whether links are clickable & detectible.
public bool MinimapEnabled; // Enables whether code minimap is enabled.
public int LineHeight; // Set's the line height.
public double FontSize; // Determine's the font size of the text.
public string FontFamily; // Set's the font family for the editor.
public string RenderWhitespace; // "none" | "boundary" | "all"
}

public class Monaco : ChromiumWebBrowser
{
public bool MonacoLoaded;
public delegate void MonacoReadyDelegate();

public event MonacoReadyDelegate MonacoReady;

public Monaco()
{
Opacity = 0;
Address = $"file:///{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).Replace("\\", "/")}/Monaco.html";

LoadingStateChanged += (sender, args) =>
{
if (args.IsLoading) return;

MonacoLoaded = true;
MonacoReady?.Invoke();
};
}

protected override void OnMouseLeave(MouseEventArgs e)
{
e.Handled = true;

var browser = GetBrowser();
var modifiers = e.GetModifiers();
var point = e.GetPosition(this);

if (e.LeftButton == MouseButtonState.Pressed)
{
browser.GetHost().SendMouseClickEvent((int)point.X, (int)point.Y, MouseButtonType.Left, mouseUp: true, clickCount: 1, modifiers: modifiers);
}

browser.GetHost().SendMouseMoveEvent((int)point.X, (int)point.Y, true, modifiers);

base.OnMouseLeave(e);
}

/// <summary>
/// Set's Monaco editor's theme to the selected Choice.
/// </summary>
/// <param name="theme"></param>
public void SetTheme(MonacoTheme theme)
{
if (!MonacoLoaded) return;

switch (theme)
{
case MonacoTheme.Dark:
this.ExecuteScriptAsync("SetTheme", "Dark");
break;
case MonacoTheme.Light:
this.ExecuteScriptAsync("SetTheme", "Light");
break;
default:
throw new ArgumentOutOfRangeException(nameof(theme), theme, null);
}
}

/// <summary>
/// Set's the text of Monaco to the parameter text.
/// </summary>
/// <param name="text"></param>
public void SetText(string text)
{
if (MonacoLoaded)
this.ExecuteScriptAsync("SetText", text);
}

private object EvaluateScript(string script)
{
var Task = this.EvaluateScriptAsync(script);
Task.Wait();
var Resp = Task.Result;
return Resp.Success ? Resp.Result ?? "" : Resp.Message;
}

/// <summary>
/// Get's the text of Monaco and returns it.
/// </summary>
/// <returns></returns>
public string GetText()
{
if (!MonacoLoaded) return "";

return (string)EvaluateScript("GetText();");
}

/// <summary>
/// Appends the text of Monaco with the parameter text.
/// </summary>
/// <param name="text"></param>
public void AppendText(string text)
{
if (MonacoLoaded)
SetText(GetText() + text);
}

public void GoToLine(int lineNumber)
{
if (MonacoLoaded)
this.ExecuteScriptAsync("SetScroll", lineNumber);
}

/// <summary>
/// Refreshes the Monaco editor.
/// </summary>
public void EditorRefresh()
{
if (MonacoLoaded)
this.ExecuteScriptAsync("Refresh");
}

/// <summary>
/// Updates Monaco editor's settings with it's parameter structure.
/// </summary>
/// <param name="settings"></param>
public void UpdateSettings(MonacoSettings settings)
{
if (!MonacoLoaded) return;

this.ExecuteScriptAsync("SwitchMinimap", settings.MinimapEnabled);
this.ExecuteScriptAsync("SwitchReadonly", settings.ReadOnly);
this.ExecuteScriptAsync("SwitchRenderWhitespace", settings.RenderWhitespace);
this.ExecuteScriptAsync("SwitchLinks", settings.Links);
this.ExecuteScriptAsync("SwitchLineHeight", settings.LineHeight);
this.ExecuteScriptAsync("SwitchFontSize", settings.FontSize);
this.ExecuteScriptAsync("SwitchFolding", settings.Folding);
this.ExecuteScriptAsync("SwitchAutoIndent", settings.AutoIndent);
this.ExecuteScriptAsync("SwitchFontFamily", settings.FontFamily);
this.ExecuteScriptAsync("SwitchFontLigatures", settings.FontLigatures);
}

/// <summary>
/// Adds intellisense for the specified type.
/// </summary>
/// <param name="label"></param>
/// <param name="type"></param>
/// <param name="description"></param>
/// <param name="insert"></param>
public void AddIntellisense(string label, string type, string description, string insert)
{
if (MonacoLoaded)
this.ExecuteScriptAsync("AddIntellisense", label, type, description, insert);
}

/// <summary>
/// Creates a syntax error symbol (squiggly red line) on the specific parameters in the editor.
/// </summary>
/// <param name="line"></param>
/// <param name="column"></param>
/// <param name="endLine"></param>
/// <param name="endColumn"></param>
/// <param name="message"></param>
public void ShowSyntaxError(int line, int column, int endLine, int endColumn, string message)
{
if (MonacoLoaded)
this.ExecuteScriptAsync("ShowErr", line, column, endLine, endColumn, message);
}
}
}


MAINWINDOW.XAML.CS:

private async void Browser_MonacoReady()
{
Browser.SetTheme(MonacoTheme.Dark);
Browser.SetText("");

/* Intellisense */

var KeywordsControlFlow = new List<string>
{
"and", "do", "elseif",
"for", "function", "if",
"in", "local", "not", "or",
"then", "until", "while"
};

var KeywordsValue = new List<string>
{
"_G", "shared", "true", "false", "nil", "end",
"break", "else", "repeat", "then", "return"
};

var IntellisenseNoDocs = new List<string>
{
"error", "getfenv", "getmetatable",
"newproxy", "next", "pairs",
"pcall", "print", "rawequal", "rawget", "rawset", "select", "setfenv",
"tonumber", "tostring", "type", "unpack", "xpcall", "_G",
"shared", "delay", "require", "spawn", "tick", "typeof", "wait", "warn",
"game", "Enum", "script", "workspace"
};

foreach (var Key in KeywordsControlFlow)
{
Browser.AddIntellisense(Key, "Keyword", "", Key + " ");
}

foreach (var Key in KeywordsValue)
{
Browser.AddIntellisense(Key, "Keyword", "", Key);
}

foreach (var Key in IntellisenseNoDocs)
{
Browser.AddIntellisense(Key, "Method", "", Key);
}

Browser.AddIntellisense("hookfunction(<function> old, <function> hook)", "Method",
"Hooks function 'old', replacing it with the function 'hook'. The old function is returned, you must use it to call the function further.",
"hookfunction");
Browser.AddIntellisense("getgenv(<void>)", "Method",
"Returns the environment that will be applied to each script ran by RoSlasher.",
"getgenv");
Browser.AddIntellisense("keyrelease(<int> key)", "Method",
"Releases 'key' on the keyboard. You can access the int key values on MSDN.",
"keyrelease");
Browser.AddIntellisense("setclipboard(<string> value)", "Method",
"Sets 'value' to the clipboard.",
"setclipboard");
Browser.AddIntellisense("mouse2press(<void>)", "Method",
"Clicks down on the right mouse button.",
"mouse2press");
Browser.AddIntellisense("getsenv(<LocalScript, ModuleScript> Script)", "Method",
"Returns the environment of Script. Returns nil if the script is not running.",
"getsenv");
Browser.AddIntellisense("checkcaller(<void>)", "Method",
"Returns true if the current thread was made by RoSlasher. Useful for metatable hooks.",
"checkcaller");

Browser.AddIntellisense("bit", "Class", "Bit Library", "bit");
Browser.AddIntellisense("bit.bdiv(<uint> dividend, <uint> divisor)", "Method",
"Divides 'dividend' by 'divisor', remainder is not returned.",
"bit.bdiv");
Browser.AddIntellisense("bit.badd(<uint> a, <uint> b)", "Method",
"Adds 'a' with 'b', allows overflows (unlike normal Lua).",
"bit.badd");
Browser.AddIntellisense("bit.bsub(<uint> a, <uint> b)", "Method",
"Subtracts 'a' with 'b', allows overflows (unlike normal Lua).",
"bit.badd");
Browser.AddIntellisense("bit.rshift(<uint> val, <uint> by)", "Method",
"Does a right shift on 'val' using 'by'.",
"bit.rshift");
Browser.AddIntellisense("bit.band(<uint> val, <uint> by)", "Method",
"Does a logical AND (&) on 'val' using 'by'.",
"bit.band");
Browser.AddIntellisense("bit.bor(<uint> val, <uint> by)", "Method",
"Does a logical OR (|) on 'val' using 'by'.",
"bit.bor");
Browser.AddIntellisense("bit.bxor(<uint> val, <uint> by)", "Method",
"Does a logical XOR (^) on 'val' using 'by'.",
"bit.bxor");
Browser.AddIntellisense("bit.bnot(<uint> val)", "Method",
"Does a logical NOT on 'val'.",
"bit.bnot");
Browser.AddIntellisense("bit.bmul(<uint> val, <uint> by)", "Method",
"Multiplies 'val' using 'by', allows overflows (unlike normal Lua)",
"bit.bmul");
Browser.AddIntellisense("bit.bswap(<uint> val)", "Method",
"Does a bitwise swap on 'val'.",
"bit.bswap");
Browser.AddIntellisense("bit.tobit(<uint> val)", "Method",
"Converts 'val' into proper form for bitwise operations.",
"bit.tobit");
Browser.AddIntellisense("bit.ror(<uint> val, <uint> by)", "Method",
"Rotates right 'val' using 'by'.",
"bit.ror");
Browser.AddIntellisense("bit.lshift(<uint> val, <uint> by)", "Method",
"Does a left shift on 'val' using 'by'.",
"bit.lshift");
Browser.AddIntellisense("bit.tohex(<uint> val)", "Method",
"Converts 'val' to a hex string.",
"bit.tohex");

Browser.AddIntellisense("debug", "Class", "Debug Library", "debug");
Browser.AddIntellisense("debug.getconstant(<function, int> fi, <int> idx)", "Method", "Returns the constant at index 'idx' in function 'fi' or level 'fi'.", "debug.getconstant");
Browser.AddIntellisense("debug.profilebegin(<string> label>", "Method", "Opens a microprofiler label.", "debug.profilebegin");
Browser.AddIntellisense("debug.profileend(<void>)", "Method", "Closes the top microprofiler label.", "debug.profileend");
Browser.AddIntellisense("debug.traceback(<void>)", "Method", "Returns a traceback of the current stack as a string.", "debug.traceback");
Browser.AddIntellisense("debug.getfenv(<T> o)", "Method", "Returns the environment of object 'o'.", "debug.getfenv");
Browser.AddIntellisense("debug.getupvalue(<function, int> fi, <string> upval)", "Method", "Returns the upvalue with name 'upval' in function or level 'fi'.", "debug.getupvalue");
Browser.AddIntellisense("debug.getlocals(<int> lvl)", "Method", "Returns a table containing the upvalues at level 'lvl'.", "debug.getlocals");
Browser.AddIntellisense("debug.setmetatable(<T> o, <table> mt)", "Method", "Set the metatable of 'o' to 'mt'.", "debug.setmetatable");
Browser.AddIntellisense("debug.getconstants(<function, int> fi)", "Method", "Retrieve the constants in function 'fi' or at level 'fi'.", "debug.getconstants");
Browser.AddIntellisense("debug.getupvalues(<function, int> fi)", "Method", "Retrieve the upvalues in function 'fi' or at level 'fi'.", "debug.getupvalues");
Browser.AddIntellisense("debug.setlocal(<int> lvl, <string> localname, <T> value)", "Method", "Set local 'localname' to value 'value' at level 'lvl'.", "debug.setlocal");
Browser.AddIntellisense("debug.setupvalue(<function, int> fi, <string> upvname, <T> value)", "Method", "Set upvalue 'upvname' to value 'value' at level or function 'fi'.", "debug.setupvalue");
Browser.AddIntellisense("debug.setconstant(<function, int> fi, <string> consname, <int, bool, nil, string> value)", "Method", "Set constant 'consname' to tuple 'value' at level or function 'fi'.", "debug.setupvalue");
Browser.AddIntellisense("debug.getregistry(<void>)", "Method", "Returns the registry", "debug.getregistry");
Browser.AddIntellisense("debug.getinfo(<function, int> fi, <string> w)", "Method", "Returns a table of info pertaining to the Lua function 'fi'.", "debug.getinfo");
Browser.AddIntellisense("debug.getlocal(<int> lvl, <string> localname)", "Method", "Returns the local with name 'localname' in level 'lvl'.", "debug.getlocal");

Browser.AddIntellisense("loadfile(<string> path)", "Method", "Loads in the contents of a file as a chunk and returns it if compilation is successful. Otherwise, if an error has occured during compilation, nil followed by the error message will be returned.", "loadfile");
Browser.AddIntellisense("loadstring(<string> chunk, [<string> chunkname])", "Method", "Loads 'chunk' as a Lua function and returns it if compilation is succesful. Otherwise, if an error has occured during compilation, nil followed by the error message will be returned.", "loadstring");
Browser.AddIntellisense("writefile(<string> filepath, <string> contents)", "Method", "Writes 'contents' to the supplied filepath.", "writefile");
Browser.AddIntellisense("mousescroll(<signed int> px)", "Method", "Scrolls the mouse wheel virtually by 'px' pixels.", "mousescroll");
Browser.AddIntellisense("mouse2click(<void>)", "Method", "Virtually presses the right mouse button.", "mouse2click");
Browser.AddIntellisense("islclosure(<function> f)", "Method", "Returns true if 'f' is an LClosure", "islclosure");
Browser.AddIntellisense("mouse1press(<void>)", "Method", "Simulates a left mouse button press without releasing it.", "mouse1press");
Browser.AddIntellisense("mouse1release(<void>)", "Method", "Simulates a left mouse button release.", "mouse1release");
Browser.AddIntellisense("keypress(<int> keycode)", "Method", "Simulates a key press for the specified keycode. For more information: https://docs.microsoft.com/en-us/windows...-key-codes", "keypress");
Browser.AddIntellisense("mouse2release(<void>)", "Method", "Simulates a right mouse button release.", "mouse2release");
Browser.AddIntellisense("newcclosure(<function> f)", "Method", "Pushes a new c closure that invokes function 'f' upon call. Used for metatable hooks.", "newcclosure");
Browser.AddIntellisense("getinstances(<void>)", "Method", "Returns a list of all instances within the game.", "getinstances");
Browser.AddIntellisense("getnilinstances(<void>)", "Method", "Returns a list of all instances parented to nil within the game.", "getnilinstances");
Browser.AddIntellisense("readfile(<string> path)", "Method", "Reads the contents of the file located at 'path' and returns it. If the file does not exist, it errors.", "readfile");
Browser.AddIntellisense("getscripts(<void>)", "Method", "Returns a list of all scripts within the game.", "getscripts");
Browser.AddIntellisense("getrunningscripts(<void>)", "Method", "Returns a list of all scripts currently running.", "getrunningscripts");
Browser.AddIntellisense("appendfile(<string> path, <string> content)", "Method", "Appends 'content' to the file contents at 'path'. If the file does not exist, it errors", "appendfile");
Browser.AddIntellisense("listfiles(<string> folder)", "Method", "Returns a table of files in 'folder'.", "listfiles");
Browser.AddIntellisense("isfile(<string> path)", "Method", "Returns if 'path' is a file or not.", "isfile");
Browser.AddIntellisense("isfolder(<string> path)", "Method", "Returns if 'path' is a folder or not.", "isfolder");
Browser.AddIntellisense("delfolder(<string> path)", "Method", "Deletes 'folder' in the workspace directory.", "delfolder");
Browser.AddIntellisense("delfile(<string> path)", "Method", "Deletes 'file' from the workspace directory.", "delfile");
Browser.AddIntellisense("getreg(<void>)", "Method", "Returns the Lua registry.", "getreg");
Browser.AddIntellisense("getgc(<void>)", "Method", "Returns a copy of the Lua GC list.", "getgc");
Browser.AddIntellisense("mouse1click(<void>)", "Method", "Simulates a full left mouse button press.", "mouse1click");
Browser.AddIntellisense("getrawmetatable(<T> value)", "Method", "Retrieve the metatable of value irregardless of value's metatable's __metatable field. Returns nil if it doesn't exist.", "getrawmetatable");
Browser.AddIntellisense("setreadonly(<table> table, <bool> ro)", "Method", "Sets table's read-only value to ro", "setreadonly");
Browser.AddIntellisense("isreadonly(<table> table)", "Method", "Returns table's read-only condition.", "isreadonly");
Browser.AddIntellisense("getrenv(<void>)", "Method", "Returns the global Roblox environment for the LocalScript state.", "getrenv");
Browser.AddIntellisense("decompile(<LocalScript, ModuleScript, function> Script, bool Bytecode = false)", "Method", "Decompiles Script and returns the decompiled script. If the decompilation fails, then the return value will be an error message.", "decompile");
Browser.AddIntellisense("dumpstring(<string> Script)", "Method", "Returns the Roblox formatted bytecode for source string 'Script'.", "dumpstring");
Browser.AddIntellisense("getloadedmodules(<void>)", "Method", "Returns all ModuleScripts loaded in the game.", "getloadedmodules");
Browser.AddIntellisense("isrbxactive(<void>)", "Method", "Returns if the Roblox window is in focus.", "getloadedmodules");
Browser.AddIntellisense("getcallingscript(<void>)", "Method", "Gets the script that is calling this function.", "getcallingscript");
Browser.AddIntellisense("setnonreplicatedproperty(<Instance> obj, <string> prop, <T> value)", "Method", "Sets the prop property of obj, not replicating to the server. Useful for anticheat bypasses.", "setnonreplicatedproperty");
Browser.AddIntellisense("getconnections(<Signal> obj)", "Method", "Gets a list of connections to the specified signal. You can then use :Disable and :Enable on the connections to disable/enable them.", "getconnections");
Browser.AddIntellisense("getspecialinfo(<Instance> obj)", "Method", "Gets a list of special properties for MeshParts, UnionOperations, and Terrain.", "getspecialinfo");
Browser.AddIntellisense("messagebox(<string> message, <string> title, <int> options)", "Method", "Makes a MessageBox with 'message', 'title', and 'options' as options. See https://docs.microsoft.com/en-us/windows...messagebox for more information.", "messagebox");
Browser.AddIntellisense("messageboxasync(<string> message, <string> title, <int> options)", "Method", "Makes a MessageBox with 'message', 'title', and 'options' as options. See https://docs.microsoft.com/en-us/windows...messagebox for more information.", "messageboxasync");
Browser.AddIntellisense("rconsolename(<string> title)", "Method", "Sets the currently allocated console title to 'title'.", "rconsolename");
Browser.AddIntellisense("rconsoleinput(<void>)", "Method", "Yields until the user inputs information into ther console. Returns the input the put in.", "rconsoleinput");
Browser.AddIntellisense("rconsoleinputasync(<void>)", "Method", "Yields until the user inputs information into ther console. Returns the input the put in.", "rconsoleinputasync");
Browser.AddIntellisense("rconsoleprint(<string> message)", "Method", "Prints 'message' into the console.", "rconsoleprint");
Browser.AddIntellisense("rconsoleinfo(<string> message)", "Method", "Prints 'message' into the console, with a info text before it.", "rconsoleinfo");
Browser.AddIntellisense("rconsolewarn(<string> message)", "Method", "Prints 'message' into the console, with a warning text before it.", "rconsolewarn");
Browser.AddIntellisense("rconsoleerr(<string> message)", "Method", "Prints 'message' into the console, with a error text before it.", "rconsoleerr");
Browser.AddIntellisense("fireclickdetector(<ClickDetector> detector, <number, nil> distance)", "Method", "Fires click detector 'detector' with 'distance'. If a distance is not provided, it will be 0.", "fireclickdetector");
Browser.AddIntellisense("firetouchinterest(<Part> part, <TouchTransmitter> transmitter, <number> toggle)", "Method", "Fires touch 'transmitter' with 'part'. Use 0 to toggle it being touched, 1 for it not being toggled.", "firetouchinterest");
Browser.AddIntellisense("saveinstance(<table> t)", "Method", "Saves the Roblox game into your workspace folder.", "saveinstance");

await Task.Delay(250);
Dispatcher.Invoke(() => { Browser.Opacity = 1; });
}


If you figure out why this may be happening, please let me know!

Thank you so much for the taking the time to read this thread! (:
Reply

Users browsing: 2 Guest(s)