Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

U/sgriffin/export #81

Merged
merged 17 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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