Skip to content

Commit

Permalink
U/sgriffin/export (#81)
Browse files Browse the repository at this point in the history
* Stub in exporter

* remove x86

* Fix typo

* remove x86 build

* start converting to static

* convert more to static

* more static

* break out parser from UI (maybe more to move later)

* fix binary copy path

* Rough hookup of ParseCaptureFile to export code

* better json formatting

* Add more detail to exported frames

* convert enums as strings

* Add byte array converter

* Add ClientRequestId

* Add response request-id

* Restore some code only used for test automation
  • Loading branch information
stephenegriffin authored Dec 6, 2023
1 parent 5308cb7 commit e0cb1b9
Show file tree
Hide file tree
Showing 17 changed files with 3,104 additions and 2,839 deletions.
59 changes: 59 additions & 0 deletions MAPIInspector/Source/ByteArrayConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace MAPIInspector
{
public class ByteArrayConverter : JsonConverter
{
public override void WriteJson(
JsonWriter writer,
object value,
JsonSerializer serializer)
{
if (value == null)
{
writer.WriteNull();
return;
}

byte[] data = (byte[])value;

writer.WriteValue(BitConverter.ToString(data).Replace("-", ""));
}

public override object ReadJson(
JsonReader reader,
Type objectType,
object existingValue,
JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String)
{
// Parse the hex string into a byte array
string hexString = (string)reader.Value;
byte[] byteData = new byte[hexString.Length / 2];

for (int i = 0; i < byteData.Length; i++)
{
byteData[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}

return byteData;
}
else
{
throw new Exception(
string.Format(
"Unexpected token parsing binary. "
+ "Expected String, got {0}.",
reader.TokenType));
}
}

public override bool CanConvert(Type objectType)
{
return objectType == typeof(byte[]);
}
}
}
6 changes: 6 additions & 0 deletions MAPIInspector/Source/CopyBinaries.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set PathToBinaries=%1
set FiddlerPath=%2

xcopy "%PathToBinaries%*.*" %FiddlerPath%\Inspectors\ /Q /Y
xcopy "%PathToBinaries%*.*" %FiddlerPath%\ImportExport\ /Q /Y
exit
40 changes: 40 additions & 0 deletions MAPIInspector/Source/MAPIExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Windows.Forms;
using Fiddler;
using System.Collections.Generic;
using MapiInspector;

[ProfferFormat("MAPI", "Parsed MAPI frames")]
public class MAPIExporter : ISessionExporter
{
public bool ExportSessions(string sFormat, Session[] oSessions, Dictionary<string, object> dictOptions,
EventHandler<ProgressCallbackEventArgs> evtProgressNotifications)
{
bool result;

string filePath = null;
if (null != dictOptions && dictOptions.ContainsKey("FilePath"))
{
filePath = dictOptions["FilePath"] as string;
}

if (string.IsNullOrEmpty(filePath)) filePath = Fiddler.Utilities.ObtainSaveFilename("Export As " + sFormat, "JSON File (*.json)|*.json");

if (string.IsNullOrEmpty(filePath)) return false;

try
{
MAPIParser.ParseCaptureFile(oSessions, filePath);
result = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Failed to export");
result = false;
}

return result;
}

public void Dispose() { }
}
Loading

0 comments on commit e0cb1b9

Please sign in to comment.