Search code examples
.netwebsocketfiddlerpacket-snifferssniffing

Debug Websocket with Fiddler


I'm trying to debugging a websocket frame with fiddler, I use the next code to achieve that

class Handlers
{
    // ...

    static function OnWebSocketMessage(oMsg: WebSocketMessage)
    {
        // Modify a message's content
        var sPayload = oMsg.PayloadAsString();
        var pattern = "Hello, \([a-zA-Z]+\)!";
        var match = Regex.Match(sPayload, pattern);

        if (match.Success) {
            var pattern = "Hello, \([a-zA-Z]+\)!";
            var match = Regex.Match(sPayload, pattern);
            var who = match.Groups[1].ToString();

            var forgedWho = String.Format("FORGED-{0}", who);
            var changedPayload = sPayload.Replace(who, forgedWho);
            FiddlerApplication.Log.LogString(String.Format("Changing {0} to {1}", who, forgedWho));
            oMsg.SetPayload(changedPayload);
        }
    }
}

I'm triyng to add "FORGED" to the Web Socket Message but when i try to save the script the next error displays

Error

The error says "The variable 'Regex' has not been declared" but regex is a function, could you help me.

I extract this code from here http://www.mopsled.com/2016/debug-websocket-connections/


Solution

  • Add import System.Text.RegularExpressions or use directly System.Text.RegularExpressions.Regex.Match(sPayload, pattern)