Skip to content

Commit

Permalink
Merge pull request #43 from stephenegriffin/fixparser
Browse files Browse the repository at this point in the history
MAPIInspector.Partial Throws when VirtualID not present
  • Loading branch information
IamWenboZhang committed Jul 24, 2019
2 parents bbc2b48 + e53629c commit 1cd6f84
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions MAPIInspector/Source/MAPIInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ public static uint ParseResponseMessageSimplely(Session currentSession, int outp
if (IsMapihttpSession(currentSession, TrafficDirection.Out))
{
byte[] bytesForHexView;
object mapiResponse;
mapiResponse = ParseHTTPExecuteResponsePayload(currentSession.ResponseHeaders, currentSession, currentSession.responseBodyBytes, TrafficDirection.Out, out bytesForHexView);
object mapiResponse;
mapiResponse = ParseHTTPExecuteResponsePayload(currentSession.ResponseHeaders, currentSession, currentSession.responseBodyBytes, TrafficDirection.Out, out bytesForHexView);
int rgbOutputBufferCount = (mapiResponse as ExecuteResponseBody).RopBuffer.RgbOutputBuffers.Length;

for (int i = 0; i < rgbOutputBufferCount; i++)
Expand Down Expand Up @@ -464,13 +464,13 @@ public static object ParseHTTPExecuteResponsePayload(HTTPHeaders headers, Sessio
{
if (direction == TrafficDirection.Out && MapiInspector.MAPIInspector.IsFromFiddlerCore(currentSession))
{
if(currentSession["Transfer-Encoding"] != null && currentSession["Transfer-Encoding"] == "chunked")
if (currentSession["Transfer-Encoding"] != null && currentSession["Transfer-Encoding"] == "chunked")
{
bytesFromHTTP = Utilities.GetPaylodFromChunkedBody(bytesFromHTTP);
bytes = bytesFromHTTP;
}
}
else if(direction == TrafficDirection.Out && headers.Exists("Transfer-Encoding") && headers["Transfer-Encoding"] == "chunked")
else if (direction == TrafficDirection.Out && headers.Exists("Transfer-Encoding") && headers["Transfer-Encoding"] == "chunked")
{
bytesFromHTTP = Utilities.GetPaylodFromChunkedBody(bytesFromHTTP);
bytes = bytesFromHTTP;
Expand Down Expand Up @@ -529,9 +529,9 @@ public static bool IsMapihttpSession(Session currentSession, TrafficDirection di
}
}
}
else if(direction == TrafficDirection.Out && currentSession["X-ResponseCode"] != null)
else if (direction == TrafficDirection.Out && currentSession["X-ResponseCode"] != null)
{
string responseCode = currentSession["X-ResponseCode"];
string responseCode = currentSession["X-ResponseCode"];
if (responseCode == "0")
{
return currentSession["Content-Type"] != null && currentSession["Content-Type"] == "application/mapi-http";
Expand All @@ -540,7 +540,7 @@ public static bool IsMapihttpSession(Session currentSession, TrafficDirection di
{
return currentSession["Content-Type"] != null && currentSession["Content-Type"] == "text/html";
}
}
}
}

return false;
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public void HandleContextInformation(ushort sourceRopID, out object obj, out byt
}
else
{
currentSession = AllSessions[Convert.ToInt32(thisSession["Number"]) - 1];
currentSession = AllSessions[Convert.ToInt32(thisSession["Number"]) - 1];
if (MapiInspector.MAPIInspector.IsFromFiddlerCore(currentSession))
{
currentSessionID = int.Parse(currentSession["VirtualID"]);
Expand Down Expand Up @@ -1353,7 +1353,7 @@ public object Partial(RopIdType ropID, uint parameters, out byte[] bytes)
if (MapiInspector.MAPIInspector.IsFromFiddlerCore(thisSession))
{
thisSessionID = int.Parse(thisSession["VirtualID"]);
}
}

if (ropID == RopIdType.RopFastTransferSourceGetBuffer)
{
Expand Down Expand Up @@ -1467,7 +1467,8 @@ public object Partial(RopIdType ropID, uint parameters, out byte[] bytes)
}

currentSession = AllSessions[Convert.ToInt32(currentSession["Number"]) + 1];
if (currentSessionID == currentSession.id || currentSessionID == int.Parse(currentSession["VirtualID"])) break;
if (currentSessionID == currentSession.id ||
(currentSession["VirtualID"] != null && currentSessionID == int.Parse(currentSession["VirtualID"]))) break;
if (MapiInspector.MAPIInspector.IsFromFiddlerCore(currentSession))
{
currentSessionID = int.Parse(currentSession["VirtualID"]);
Expand Down Expand Up @@ -1533,7 +1534,7 @@ public object Partial(RopIdType ropID, uint parameters, out byte[] bytes)
if (MapiInspector.MAPIInspector.IsFromFiddlerCore(currentSession))
{
currentSessionID = int.Parse(currentSession["VirtualID"]);
}
}
if (ropID == RopIdType.RopFastTransferDestinationPutBuffer)
{
int sessionPutContextCount = HandleWithSessionPutContextInformation.Count;
Expand Down Expand Up @@ -1787,7 +1788,7 @@ public object ParseResponseMessage(Session currentSession, out byte[] hexViewByt
{
object mapiResponse = null;
hexViewBytes = new byte[0];
if(!MapiInspector.MAPIInspector.IsFromFiddlerCore(currentSession))
if (!MapiInspector.MAPIInspector.IsFromFiddlerCore(currentSession))
{
if (IsMapihttpSession(currentSession, TrafficDirection.Out) && currentSession.ResponseHeaders["X-ResponseCode"] == "0")
{
Expand Down Expand Up @@ -1869,7 +1870,7 @@ public object ParseResponseMessage(Session currentSession, out byte[] hexViewByt
}
}
}


if (isLooper)
{
Expand Down Expand Up @@ -1942,7 +1943,7 @@ public object ParseHTTPPayload(HTTPHeaders headers, Session currentSession, byte
bytes = bytesFromHTTP;
}
}
else if (direction == TrafficDirection.Out && headers.Exists("Transfer-Encoding") && headers["Transfer-Encoding"] == "chunked")
else if (direction == TrafficDirection.Out && headers.Exists("Transfer-Encoding") && headers["Transfer-Encoding"] == "chunked")
{
bytesFromHTTP = Utilities.GetPaylodFromChunkedBody(bytesFromHTTP);
bytes = bytesFromHTTP;
Expand Down Expand Up @@ -2507,7 +2508,7 @@ private void UpdateView()
Session session0 = new Session(new byte[0], new byte[0]);
Session[] sessionsInFiddler = FiddlerApplication.UI.GetAllSessions();
allSessionsList.AddRange(sessionsInFiddler);
FiddlerApplication.OnLoadSAZ += this.AfterCallDoImport;
FiddlerApplication.OnLoadSAZ += this.AfterCallDoImport;
allSessionsList.Sort(delegate (Session p1, Session p2)
{
return p1.id.CompareTo(p2.id);
Expand Down Expand Up @@ -2540,7 +2541,7 @@ private void UpdateView()

this.DisplayObject(parserResult, bytesForHexView);
}
catch(Exception e)
catch (Exception e)
{
parserResult = e.ToString();
}
Expand All @@ -2567,7 +2568,7 @@ private void UpdateView()
public static bool IsFromFiddlerCore(Session session)
{
bool result = false;
if(session.id == 0)
if (session.id == 0)
{
result = true;
}
Expand Down

0 comments on commit 1cd6f84

Please sign in to comment.