-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,816 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Swiddler.Common; | ||
using Swiddler.DataChunks; | ||
using Swiddler.Utils.RtfWriter; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace Swiddler.IO | ||
{ | ||
public interface IDataTransferTarget | ||
{ | ||
void Write(IDataChunk chunk, byte[] data); | ||
void Flush(); | ||
} | ||
|
||
public class StreamTransferTarget : IDataTransferTarget | ||
{ | ||
readonly Stream _stream; | ||
public StreamTransferTarget(Stream stream) => _stream = stream; | ||
public void Write(IDataChunk chunk, byte[] data) => _stream.Write(data, 0, data.Length); | ||
public void Flush() => _stream.Flush(); | ||
} | ||
|
||
public class RtfTransferTarget : IDataTransferTarget | ||
{ | ||
RtfDocument _doc; | ||
ColorDescriptor _inFg, _inBg, _outFg, _outBg; | ||
Encoding _encoding { get; set; } | ||
|
||
public RtfTransferTarget(RtfDocument doc, Encoding encoding) | ||
{ | ||
_doc = doc; | ||
_encoding = encoding; | ||
|
||
doc.DefaultCharFormat.FontSize = 10; | ||
|
||
_inFg = doc.createColor(new RtfColor(App.Current.Res.InboundFlowTextBrush.Color)); | ||
_inBg = doc.createColor(new RtfColor(App.Current.Res.InboundFlowBrush.Color)); | ||
_outFg = doc.createColor(new RtfColor(App.Current.Res.OutboundFlowTextBrush.Color)); | ||
_outBg = doc.createColor(new RtfColor(App.Current.Res.OutboundFlowBrush.Color)); | ||
} | ||
|
||
public void Write(IDataChunk chunk, byte[] data) | ||
{ | ||
var par = _doc.addParagraph(); | ||
|
||
par.setText(_encoding.GetString(data)); | ||
|
||
if (chunk is Packet packet) | ||
{ | ||
if (packet.Flow == TrafficFlow.Inbound) | ||
{ | ||
par.DefaultCharFormat.FgColor = _inFg; | ||
par.DefaultCharFormat.BgColor = _inBg; | ||
} | ||
if (packet.Flow == TrafficFlow.Outbound) | ||
{ | ||
par.DefaultCharFormat.FgColor = _outFg; | ||
par.DefaultCharFormat.BgColor = _outBg; | ||
} | ||
} | ||
} | ||
|
||
public void Flush() | ||
{ | ||
} | ||
} | ||
|
||
public class CompositeTransferTarget : IDataTransferTarget | ||
{ | ||
IDataTransferTarget[] _targets; | ||
public CompositeTransferTarget(params IDataTransferTarget[] targets) => _targets = targets; | ||
public void Write(IDataChunk chunk, byte[] data) | ||
{ | ||
foreach (var t in _targets) t.Write(chunk, data); | ||
} | ||
public void Flush() | ||
{ | ||
foreach (var t in _targets) t.Flush(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace Swiddler.Utils.RtfWriter | ||
{ | ||
/// <summary> | ||
/// Internal use only. | ||
/// Objects that are renderable can emit RTF code. | ||
/// </summary> | ||
abstract public class RtfRenderable | ||
{ | ||
/// <summary> | ||
/// Internal use only. | ||
/// Emit RTF code. | ||
/// </summary> | ||
/// <returns>RTF code</returns> | ||
abstract public string render(); | ||
} | ||
|
||
/// <summary> | ||
/// Internal use only. | ||
/// RtfBlock is a content block that cannot contain other blocks. | ||
/// For example, an image is an RtfBlock because it cannot contain | ||
/// other content block such as another image, a paragraph, a table, | ||
/// etc. | ||
/// </summary> | ||
abstract public class RtfBlock : RtfRenderable | ||
{ | ||
/// <summary> | ||
/// How this block is aligned in its containing block. | ||
/// </summary> | ||
abstract public Align Alignment { get; set; } | ||
/// <summary> | ||
/// Default character formats. | ||
/// </summary> | ||
abstract public RtfCharFormat DefaultCharFormat { get; } | ||
/// <summary> | ||
/// When set to true, this block will be arranged in the beginning | ||
/// of a new page. | ||
/// </summary> | ||
abstract public bool StartNewPage { get; set; } | ||
|
||
protected string AlignmentCode() | ||
{ | ||
switch (Alignment) | ||
{ | ||
case Align.Left: | ||
return @"\ql"; | ||
case Align.Right: | ||
return @"\qr"; | ||
case Align.Center: | ||
return @"\qc"; | ||
case Align.FullyJustify: | ||
return @"\qj"; | ||
default: | ||
return @"\qd"; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.