A static byte array containing 0 elements. Use to avoid having many copies of an empty byte[] floating around.
Declaration
public static readonly byte[] emptyByteArray
public const string sCommonRequestHeaders = "Cache-Control,If-None-Match,If-Modified-Since,Pragma,If-Unmodified-Since,If-Range,If-Match,Content-Length,Content-Type,Referer,Origin,SOAPAction,Expect,Content-Encoding,TE,Transfer-Encoding,Proxy-Connection,Connection,Accept,Accept-Charset,Accept-Encoding,Accept-Language,User-Agent,UA-Color,UA-CPU,UA-OS,UA-Pixels,Cookie,Cookie2,DNT,Authorization,Proxy-Authorization,X-Requested-With,X-Download-Initiator"
public const string sCommonResponseHeaders = "Age,Cache-Control,Date,Expires,Pragma,Vary,Content-Length,ETag,Last-Modified,Content-Type,Content-Disposition,Content-Encoding,Transfer-encoding,Via,Keep-Alive,Location,Proxy-Connection,Connection,Set-Cookie,WWW-Authenticate,Proxy-Authenticate,P3P,X-UA-Compatible,X-Frame-options,X-Content-Type-Options,X-XSS-Protection,Strict-Transport-Security,Content-Security-Policy,Access-Control-Allow-Origin"
public static bool areOriginsEquivalent(string sOrigin1, string sOrigin2, int iDefaultPort)
Parameters
System.String
sOrigin1
The first ORIGIN
[CodeDescription("Returns a string representing a Hex view of a byte array. Slow.")]
public static string ByteArrayToHexView(byte[] inArr, int iBytesPerLine)
Parameters
System.Byte
[]
inArr
The byte array
[CodeDescription("Returns a string representing a Hex view of a byte array. PERF: Slow.")]
public static string ByteArrayToHexView(byte[] inArr, int iBytesPerLine, int iMaxByteCount)
Parameters
System.Byte
[]
inArr
The byte array
[CodeDescription("Returns a string representing a Hex view of a byte array. PERF: Slow.")]
public static string ByteArrayToHexView(byte[] inArr, int iBytesPerLine, int iMaxByteCount, bool bShowASCII)
Parameters
System.Byte
[]
inArr
The byte array
[CodeDescription("Returns a string representing a Hex view of a byte array. PERF: Slow.")]
public static string ByteArrayToHexView(byte[] inArr, int iStartAt, int iBytesPerLine, int iMaxByteCount, bool bShowASCII)
Parameters
System.Byte
[]
inArr
[CodeDescription("Returns a string representing a Hex stream of a byte array. Slow.")]
public static string ByteArrayToString(byte[] inArr)
Parameters
System.Byte
[]
inArr
Byte array
[CodeDescription("Returns a byte[] representing the bzip2'd representation of writeData[]")]
public static byte[] bzip2Compress(byte[] writeData)
Parameters
System.Byte
[]
writeData
Array to compress
Typically, a version number is displayed as "major number.minor number.build number.private part number".
Declaration
public static int CompareVersions(string sRequiredVersion, Version verTest)
Parameters
System.String
sRequiredVersion
Version required
[CodeDescription("This function cracks the Host/Port combo, removing IPV6 brackets if needed.")]
public static void CrackHostAndPort(string sHostPort, out string sHostname, ref int iPort)
Parameters
System.String
sHostPort
Hostname/port combo, like www.foo.com or www.example.com:8888 or [::1]:80
[CodeDescription("Returns a byte[] containing a DEFLATE'd copy of writeData[]")]
public static byte[] DeflaterCompress(byte[] writeData)
Parameters
System.Byte
[]
writeData
Array to compress
[CodeDescription("Returns a byte[] representing the INFLATE'd representation of compressedData[]")]
public static byte[] DeflaterExpand(byte[] compressedData)
Parameters
System.Byte
[]
compressedData
Array to decompress
Removes HTTP chunked encoding from the data in writeData and returns the resulting array.
Declaration
public static byte[] doUnchunk(byte[] writeData)
Parameters
System.Byte
[]
writeData
Some chunked data
Duplicate a byte array, replacing null with byte[0].
Doing this instead of .Clone() because it better handles nulls and it may be faster.
Declaration
public static byte[] Dupe(byte[] bIn)
Parameters
System.Byte
[]
The array to copy
Ensures that the target string is iMaxLength or fewer characters, appending ... if truncation occurred
Declaration
public static string EllipsizeIfNeeded(string sString, int iMaxLength)
Parameters
System.String
sString
The string to trim from
Ensure that the target path exists and if a file exists there, it is not readonly or hidden.
WARNING: Can throw if target "Filename" calls for a parent directoryname that is already used as a filename by a non-directory.
E.g. EnsureOverwriteable(C:\io.sys\filename.txt); would throw.
Declaration
public static void EnsureOverwritable(string sFilename)
Parameters
System.String
sFilename
The candidate filename
Ensure that a given path is absolute, if not, applying the root path.
WARNING: This function only works as well as Path.IsPathRooted, which returns "True" for things like "/NoDriveSpecified/fuzzle.txt"
A better approach would be to look at the internal Path.IsRelative method
Declaration
public static string EnsurePathIsAbsolute(string sRootPath, string sFilename)
Parameters
System.String
sRootPath
Ensure that the target file does not yet exist. If it does, generates a new filename with an embedded identifier, e.g. out[1].txt instead.
Attempts to ensure filename is creatable; e.g. if a path component needs to be a directory but is a file already, injects [#] into that
path component.
Declaration
public static string EnsureUniqueFilename(string sFilename)
Parameters
System.String
sFilename
Candidate filename
Address the problem where the target "PATH" calls for a directoryname is already a filename
Declaration
public static string EnsureValidAsPath(string sTargetFolder)
Parameters
System.String
sTargetFolder
Returns the Value from a (case-insensitive) token in the header string. Correctly handles double-quoted strings.
Allows comma and semicolon as delimiter. Trailing whitespace may be present.
Declaration
public static string GetCommaTokenValue(string sString, string sTokenName)
Parameters
System.String
sString
Name of the header
WARNING: Potentially slow.
WARNING: Does not decode the HTTP Response body; if compressed, embedded META or
charset
will not be checked
Gets (via Headers or Sniff) the provided body's text Encoding. If not found, returns CONFIG.oHeaderEncoding (usually UTF-8).
Declaration
[CodeDescription("Gets (via Headers or Sniff) the provided body's text Encoding. Returns CONFIG.oHeaderEncoding (usually UTF-8) if unknown. Potentially slow.")]
public static Encoding getEntityBodyEncoding(HTTPHeaders oHeaders, byte[] oBody)
Parameters
HTTPHeaders
oHeaders
HTTP Headers, ideally containing a Content-Type header with a charset attribute.
Run an executable, wait for it to exit, and return its output as a string.
NOTE: Uses CreateProcess, so you cannot launch applications which require Elevation.
Declaration
[CodeDescription("Run an executable, wait for it to exit, and return its output as a string.")]
public static string GetExecutableOutput(string sExecute, string sParams, out int iExitCode)
Parameters
System.String
sExecute
Fully-qualified filename of file to Execute
[CodeDescription("Returns an bool from the registry, or bDefault if the registry key is missing or cannot be used as an bool.")]
public static bool GetRegistryBool(RegistryKey oReg, string sName, bool bDefault)
Parameters
Microsoft.Win32.RegistryKey
The RegistryKey
[CodeDescription("Returns an float from the registry, or flDefault if the registry key is missing or cannot be used as an float.")]
public static float GetRegistryFloat(RegistryKey oReg, string sName, float flDefault)
Parameters
Microsoft.Win32.RegistryKey
Registry key in which to find the value.
[CodeDescription("Returns an integer from the registry, or iDefault if the registry key is missing or cannot be used as an integer.")]
public static int GetRegistryInt(RegistryKey oReg, string sName, int iDefault)
Parameters
Microsoft.Win32.RegistryKey
The Registry key in which to find the value.
Gets (via Headers or Sniff) the Response Text Encoding. Returns CONFIG.oHeaderEncoding (usually UTF-8) if unknown.
Perf: May be quite slow; cache the response
Declaration
[CodeDescription("Gets (via Headers or Sniff) the Response Text Encoding. Returns CONFIG.oHeaderEncoding (usually UTF-8) if unknown. Potentially slow.")]
public static Encoding getResponseBodyEncoding(Session oSession)
Parameters
Session
oSession
The session
[CodeDescription("Gets a string from a byte-array, stripping a BOM if present.")]
public static string GetStringFromArrayRemovingBOM(byte[] arrInput, Encoding oDefaultEncoding)
Parameters
System.Byte
[]
arrInput
The byte array
WARNING: May throw.
Gets an encoding, with proper respect for "utf8" as an alias for "utf-8"; Microsoft products don't support
this prior to 2015-era, but it turns out to be common. We do have a linter elsewhere that reports a warning
if it sees the dashless form.
https://github.com/telerik/fiddler/issues/38
Declaration
public static Encoding GetTextEncoding(string sEncoding)
Parameters
System.String
sEncoding
Textual name of the encoding
Get a TickCount (milliseconds since system start) as an unsigned 64bit value. On Windows Vista+, uses the GetTickCount64 API that
won't rollover, but on any other platform, this unsigned wrapper moves the rollover point to 49 days of uptime.
Declaration
public static ulong GetTickCount()
Returns
System.UInt64
Number of ms since the system started
[CodeDescription("Returns a byte[] containing a gzip-compressed copy of writeData[]")]
public static byte[] GzipCompress(byte[] writeData)
Parameters
System.Byte
[]
writeData
Input byte array
[CodeDescription("Returns a byte[] containing an un-gzipped copy of compressedData[]")]
public static byte[] GzipExpand(byte[] compressedData)
Parameters
System.Byte
[]
compressedData
The array to decompress
Determines whether the arrData array STARTS WITH with the supplied arrMagics bytes. Used for Content-Type sniffing.
Declaration
public static bool HasMagicBytes(byte[] arrData, byte[] arrMagics)
Parameters
System.Byte
[]
arrData
The data, or null
Determines whether the arrData array begins with the supplied sMagics ASCII text. Used for Content-Type sniffing.
Declaration
public static bool HasMagicBytes(byte[] arrData, string sMagics)
Parameters
System.Byte
[]
arrData
The data, or null
HtmlEncode a string.
In Fiddler itself, this is a simple wrapper for the System.Web.HtmlEncode function.
The .NET3.5/4.0 Client Profile doesn't include System.Web, so we must provide our
own implementation of HtmlEncode for FiddlerCore's use.
Declaration
public static string HtmlEncode(string sInput)
Parameters
System.String
sInput
String to encode
[CodeDescription("Returns TRUE if the HTTP Method MAY have a body.")]
public static bool HTTPMethodAllowsBody(string sMethod)
Parameters
System.String
sMethod
The Method/Verb
Determines true if a request with the specified HTTP Method/Verb MUST contain a entity body
Declaration
[CodeDescription("Returns TRUE if the HTTP Method MUST have a body.")]
public static bool HTTPMethodRequiresBody(string sMethod)
Parameters
System.String
sMethod
The Method/Verb
[CodeDescription("Returns TRUE if a response body is allowed for this responseCode.")]
public static bool HTTPStatusAllowsBody(int iResponseCode)
Parameters
System.Int32
iResponseCode
Given a string/list in the form HOSTNAME:PORT#;HOSTNAME2:PORT2#, this function returns the FIRST IPEndPoint. Defaults to port 80 if not specified.
Warning: DNS resolution is slow, so use this function wisely.
Declaration
public static IPEndPoint IPEndPointFromHostPortString(string sHostAndPort)
Parameters
System.String
sHostAndPort
HOSTNAME:PORT#;OPTHOST2:PORT2#
Given a string/list in the form HOSTNAME:PORT#;HOSTNAME2:PORT2#, this function returns all IPEndPoints for ALL listed hosts. Defaults to port 80 if not specified.
Warning: DNS resolution is slow, so use this function wisely.
Declaration
public static IPEndPoint[] IPEndPointListFromHostPortString(string sAllHostAndPorts)
Parameters
System.String
sAllHostAndPorts
HOSTNAME:PORT#;OPTHOST2:PORT2#
This function attempts to be a ~fast~ way to return an IP from a hoststring that contains an IPv4/6-Literal.
Declaration
[CodeDescription("This function attempts to be a ~fast~ way to return an IP from a hoststring that contains an IP-Literal. ")]
public static IPAddress IPFromString(string sHost)
Parameters
System.String
sHost
Hostname
For a given process name, returns a bool indicating whether this is a known browser process name.
Declaration
public static bool IsBrowserProcessName(string sProcessName)
Parameters
System.String
sProcessName
The Process name (e.g. "abrowser.exe")
Returns TRUE if the string is non-empty and not of the pattern "[#123]"
Necessary because SAZ-saving logic autogenerates comments of that form
Declaration
public static bool IsCommentUserSupplied(string strComment)
Parameters
System.String
strComment
This function cracks a sHostPort string to determine if the address
refers to the local computer
Declaration
[CodeDescription("Returns true if True if the sHostAndPort's host is 127.0.0.1, 'localhost', or ::1. Note that list is not complete.")]
public static bool isLocalhost(string sHostAndPort)
Parameters
System.String
sHostAndPort
The string to evaluate, potentially containing a port
Determines if the specified Hostname is a either 'localhost' or an IPv4 or IPv6 loopback literal
Declaration
[CodeDescription("Returns true if True if the sHostname is 127.0.0.1, 'localhost', or ::1. Note that list is not complete.")]
public static bool isLocalhostname(string sHostname)
Parameters
System.String
sHostname
Hostname (no port)
This function cracks a sHostPort string to determine if the address
refers to a "local" site
Declaration
[CodeDescription("Returns false if Hostname contains any dots or colons.")]
public static bool isPlainHostName(string sHostAndPort)
Parameters
System.String
sHostAndPort
The string to evaluate, potentially containing a port
Implements a BlockList for "unknown" encodings that the utilDecode* functions cannot handle
Declaration
public static bool isUnsupportedEncoding(string sTE, string sCE)
Parameters
System.String
Transfer-Encoding
Launch the user's browser to a hyperlink. This function traps exceptions and notifies the user via UI dialog.
Declaration
[CodeDescription("ShellExecutes the sURL.")]
public static bool LaunchHyperlink(string sURL)
Parameters
System.String
The URL to ShellExecute.
[CodeDescription("Tokenize a string into tokens. Delimits on whitespace; \" marks are dropped unless preceded by \\ characters.")]
public static string[] Parameterize(string sInput)
Parameters
System.String
sInput
Tokenize a string into tokens. Delimits on unquoted whitespace ; quote marks are dropped unless preceded by \ characters.
Some special hackery to allow trailing slash not escape the final character of the entire input, so that:
prefs set fiddler.config.path.vsplugins "F:\users\ericlaw\VSWebTest"
...doesn't end up with a trailing quote.
Declaration
[CodeDescription("Tokenize a string into tokens. Delimits on whitespace; \" marks are dropped unless preceded by \\ characters.")]
public static string[] Parameterize(string sInput, bool bAllowSQuote)
Parameters
System.String
sInput
The string to tokenize
Fills an array completely using the provided stream. Unlike a normal .Read(), this one will always fully fill the array unless the Stream throws.
Declaration
[CodeDescription("Reads oStream until arrBytes is filled.")]
public static int ReadEntireStream(Stream oStream, byte[] arrBytes)
Parameters
System.IO.Stream
oStream
The stream from which to read.
[CodeDescription("Load the specified .SAZ or .ZIP session archive")]
public static Session[] ReadSessionArchive(string sFilename, string sContext, GetPasswordDelegate fnPasswordCallback)
Parameters
System.String
sFilename
Filename to load
[CodeDescription("Run an executable and wait for it to exit.")]
public static bool RunExecutableAndWait(string sExecute, string sParams)
Parameters
System.String
sExecute
Fully-qualified filename of file to execute.
[CodeDescription("Save a string to the registry. Correctly handles null Value, saving as String.Empty.")]
public static void SetRegistryString(RegistryKey oReg, string sName, string sValue)
Parameters
Microsoft.Win32.RegistryKey
The registry key into which the value will be written.
Returns the "Head" of a string, before and not including the first instance of specified delimiter.
Declaration
[CodeDescription("Returns the part of a string up to (but NOT including) the first instance of specified delimiter. If delim not found, returns entire string.")]
public static string TrimAfter(string sString, char chDelim)
Parameters
System.String
sString
The string to trim from.
[CodeDescription("Returns the part of a string up to (but NOT including) the first instance of specified substring. If delim not found, returns entire string.")]
public static string TrimAfter(string sString, string sDelim)
Parameters
System.String
sString
The string to trim from
Returns the "Tail" of a string, after (but NOT including) the First instance of specified delimiter.
See also
TrimBeforeLast(String, Char)
Declaration
[CodeDescription("Returns the part of a string after (but NOT including) the first instance of specified delimiter. If delim not found, returns entire string.")]
public static string TrimBefore(string sString, char chDelim)
Parameters
System.String
sString
The string to trim from.
Returns the "Tail" of a string, after (but NOT including) the First instance of specified search string.
TrimBeforeLast(String, String)
Declaration
[CodeDescription("Returns the part of a string after (but NOT including) the first instance of specified substring. If delim not found, returns entire string.")]
public static string TrimBefore(string sString, string sDelim)
Parameters
System.String
sString
The string to trim from.
Returns the "Tail" of a string, after (but not including) the Last instance of specified delimiter.
TrimBefore(String, Char)
Declaration
[CodeDescription("Returns the part of a string after (but not including) the last instance of specified delimiter. If delim not found, returns entire string.")]
public static string TrimBeforeLast(string sString, char chDelim)
Parameters
System.String
sString
The string to trim from.
Returns the "Tail" of a string, after (but not including) the Last instance of specified substring.
TrimBefore(String, String)
Declaration
[CodeDescription("Returns the part of a string after (but not including) the last instance of specified substring. If delim not found, returns entire string.")]
public static string TrimBeforeLast(string sString, string sDelim)
Parameters
System.String
sString
The string to trim from.
[CodeDescription("Returns the first iMaxLength or fewer characters from the target string.")]
public static string TrimTo(string sString, int iMaxLength)
Parameters
System.String
sString
The string to trim from
Returns the "Tail" of a string, after (and including) the first instance of specified search string.
Declaration
[CodeDescription("Returns the part of a string after (and including) the first instance of specified substring. If delim not found, returns entire string.")]
public static string TrimUpTo(string sString, string sDelim)
Parameters
System.String
sString
The string to trim from.
Try parsing the string for a Hex-formatted int. If it fails, return false and 0 in iOutput.
Declaration
[CodeDescription("Try parsing the string for a Hex-formatted int. If it fails, return false and 0 in iOutput.")]
public static bool TryHexParse(string sInput, out int iOutput)
Parameters
System.String
sInput
The hex number
Convert the %-encoded string into a string, interpreting %-escape sequences as UTF-8 characters
Declaration
public static string UrlDecode(string sInput)
Parameters
System.String
sInput
%-encoded string
Remove all encodings from arrBody, based on those specified in the supplied HTTP headers; DOES NOT MODIFY HEADERS.
Throws on errors.
Declaration
public static void utilDecodeHTTPBody(HTTPHeaders oHeaders, ref byte[] arrBody)
Parameters
HTTPHeaders
oHeaders
Readonly
headers specifying what encodings are applied
Remove all encodings from arrBody, based on those specified in the supplied HTTP headers;
DOES NOT MODIFY HEADERS. DOES NOT HANDLE UNSUPPORTED ENCODINGS WELL.
Throws on errors.
Declaration
public static void utilDecodeHTTPBody(HTTPHeaders oHeaders, ref byte[] arrBody, bool bSilent)
Parameters
HTTPHeaders
oHeaders
Readonly
headers specifying what encodings are applied
Writes arrBytes to a file, creating the target directory and overwriting if the file exists.
Declaration
[CodeDescription("Writes arrBytes to a file, creating the target directory and overwriting if the file exists.")]
public static void WriteArrayToFile(string sFilename, byte[] arrBytes)
Parameters
System.String
sFilename
Path to File to write.
[CodeDescription("Save the specified .SAZ session archive")]
public static bool WriteSessionArchive(string sFilename, Session[] arrSessions, string sPassword)
Parameters
System.String
sFilename
The filename of the SAZ file to store
Decompress a byte array that was compressed using Microsoft's Xpress Raw format.
Available only on Windows 8+
Declaration
public static byte[] XpressExpand(byte[] arrBlock)
Parameters
System.Byte
[]
arrBlock
Array to decompress
Decompress an array compressed using an Zlib DEFLATE stream. Not a HTTP Encoding; it's used internally in the PNG format.
Declaration
public static byte[] ZLibExpand(byte[] compressedData)
Parameters
System.Byte
[]
compressedData
The array to expand
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See
Trademarks
for appropriate markings.