Skip to content

Commit

Permalink
Added support for Write-Host
Browse files Browse the repository at this point in the history
Added raw interface to support write-host
Still need to do read-host and implement other parts, but this is the
basis.
Also cleaned up empty new lines that were not necessary.
Improved logging with new lines.
  • Loading branch information
Ben0xA committed May 21, 2014
1 parent 4513050 commit 61e20fc
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 18 deletions.
6 changes: 3 additions & 3 deletions poshsecframework/Interface/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,12 +1132,12 @@ public void DisplayOutput(String output, ListViewItem lvw, bool clicked, bool ca
}
else
{
if ((txtPShellOutput.Text.Length + output.Length + (Environment.NewLine + StringValue.psf).Length) > txtPShellOutput.MaxLength)
if ((txtPShellOutput.Text.Length + output.Length + StringValue.psf.Length) > txtPShellOutput.MaxLength)
{
txtPShellOutput.Text = txtPShellOutput.Text.Substring(output.Length + 500, txtPShellOutput.Text.Length - (output.Length + 500));
}
txtPShellOutput.AppendText(output);
txtPShellOutput.AppendText(Environment.NewLine + StringValue.psf);
txtPShellOutput.AppendText(StringValue.psf);
mincurpos = txtPShellOutput.Text.Length;
txtPShellOutput.SelectionStart = mincurpos;
if (clicked || cancelled || scroll)
Expand All @@ -1153,7 +1153,7 @@ public void DisplayOutput(String output, ListViewItem lvw, bool clicked, bool ca
tcMain.SelectedTab = tbpPowerShell;
}
RemoveActiveScript(lvw);
LogOutput(output + Environment.NewLine + StringValue.psf);
LogOutput(Environment.NewLine + output + StringValue.psf);
}
}

Expand Down
18 changes: 9 additions & 9 deletions poshsecframework/Interface/frmMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbW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ASgDAAFA
AwABIAMAAQEBAAEgBgABIP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AQgADJgE4AxYBHjgA
AyYBOAMWAR44AAMmATgDFgEeOAADJgE4AxYBHjQAAyYBOANiAfYDtgH/AxgBITAAAyYBOANiAfYDtgH/
AxgBITAAAyYBOANiAfYDtgH/AxgBITAAAyYBOANiAfYDtgH/AxgBISwAAyYBOANiAfYD4AH/A9gB/wO2
Expand Down Expand Up @@ -422,7 +422,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAe
GAAAAk1TRnQBSQFMAgEBBQEAAdgBDAHYAQwBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
GAAAAk1TRnQBSQFMAgEBBQEAAegBDAHoAQwBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
AwABIAMAAQEBAAEgBgABIP8AIwADGQEjA0UBfQJaAV8B2wJMAV8B8wJMAV8B8wJaAV8B2wNFAX0DGQEj
3AADMwFTAlgBYQHmAgAB1AH/AYQBkAHnAf8BlQGgAe4B/wGVAZ8B7QH/AYMBjgHlAf8CAAHOAf8CWAFh
AeYDMwFT1AADMwFTAlIBZQH0AQABhAHjAf8BoQGsAfQB/wEAAYsB7AH/AgAB5AH/AgAB4wH/AQABhwHq
Expand Down
2 changes: 1 addition & 1 deletion poshsecframework/PShell/pscript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void RunScript()
rslts.AppendLine(scriptcommand + cmdparams);
}
pline.Commands.AddScript(cmdscript);
pline.Commands.Add(StringValue.OutString);
//pline.Commands.Add(StringValue.OutString);
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions poshsecframework/PShell/psfhost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public psfhost()

public override void EnterNestedPrompt()
{
throw new NotImplementedException();
System.Windows.Forms.MessageBox.Show("Enter nested prompt");
//throw new NotImplementedException();
}

public override void ExitNestedPrompt()
{
throw new NotImplementedException();
System.Windows.Forms.MessageBox.Show("Exit nested prompt");
//throw new NotImplementedException();
}

public override void NotifyBeginApplication()
Expand Down
22 changes: 19 additions & 3 deletions poshsecframework/PShell/psfhostinterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace poshsecframework.PShell
class psfhostinterface : PSHostUserInterface
{
private Collection<String> warnings = new Collection<string>();
private psfhostrawinterface rawinterface = new psfhostrawinterface();
public EventHandler<Events.WriteProgressEventArgs> WriteProgressUpdate;
public EventHandler<Events.WriteEventArgs> WriteUpdate;

Expand All @@ -31,6 +32,7 @@ public override void WriteDebugLine(string message)

public override void WriteLine()
{
System.Windows.Forms.MessageBox.Show("Writeline");
base.WriteLine();
}

Expand All @@ -41,12 +43,13 @@ public override void Write(string value)

public override void WriteErrorLine(string value)
{
System.Windows.Forms.MessageBox.Show("Writeerrorline");
return;
}

public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
{
base.WriteLine(foregroundColor, backgroundColor, value);
return; //base.WriteLine(foregroundColor, backgroundColor, value);
}

public override void WriteLine(string value)
Expand Down Expand Up @@ -89,27 +92,40 @@ public override void WriteWarningLine(string message)

public override Dictionary<string, System.Management.Automation.PSObject> Prompt(string caption, string message, System.Collections.ObjectModel.Collection<FieldDescription> descriptions)
{
return null;
Dictionary<string, System.Management.Automation.PSObject> rtn = new Dictionary<string, System.Management.Automation.PSObject>();
string msg = message;
if (descriptions != null)
{
foreach (FieldDescription descr in descriptions)
{
msg += descr.Name + "\n";
}
}
System.Windows.Forms.MessageBox.Show(msg, caption);
return rtn;
}

public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice)
{
System.Windows.Forms.MessageBox.Show("Caption = " + caption);
return -1;
}

public override System.Management.Automation.PSCredential PromptForCredential(string caption, string message, string userName, string targetName)
{
System.Windows.Forms.MessageBox.Show("promptforcreds");
return null;
}

public override System.Management.Automation.PSCredential PromptForCredential(string caption, string message, string userName, string targetName, System.Management.Automation.PSCredentialTypes allowedCredentialTypes, System.Management.Automation.PSCredentialUIOptions options)
{
System.Windows.Forms.MessageBox.Show("promptforcreds2");
return null;
}

public override PSHostRawUserInterface RawUI
{
get { return null; }
get { return rawinterface; }
}

public override string ReadLine()
Expand Down
153 changes: 153 additions & 0 deletions poshsecframework/PShell/psfhostrawinterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation.Host;
using System.Text;
using System.Threading.Tasks;

namespace poshsecframework.PShell
{
class psfhostrawinterface : PSHostRawUserInterface
{
public override ConsoleColor BackgroundColor
{
get
{
return System.ConsoleColor.Blue;
}
set
{
throw new NotImplementedException();
}
}

public override Size BufferSize
{
get
{
return new System.Management.Automation.Host.Size(80, 80);
}
set
{
throw new NotImplementedException();
}
}

public override Coordinates CursorPosition
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public override int CursorSize
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public override void FlushInputBuffer()
{
throw new NotImplementedException();
}

public override ConsoleColor ForegroundColor
{
get
{
return ConsoleColor.Black;
}
set
{
throw new NotImplementedException();
}
}

public override BufferCell[,] GetBufferContents(Rectangle rectangle)
{
throw new NotImplementedException();
}

public override bool KeyAvailable
{
get { throw new NotImplementedException(); }
}

public override Size MaxPhysicalWindowSize
{
get { throw new NotImplementedException(); }
}

public override Size MaxWindowSize
{
get { throw new NotImplementedException(); }
}

public override KeyInfo ReadKey(ReadKeyOptions options)
{
throw new NotImplementedException();
}

public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill)
{
throw new NotImplementedException();
}

public override void SetBufferContents(Rectangle rectangle, BufferCell fill)
{
throw new NotImplementedException();
}

public override void SetBufferContents(Coordinates origin, BufferCell[,] contents)
{
throw new NotImplementedException();
}

public override Coordinates WindowPosition
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public override Size WindowSize
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}

public override string WindowTitle
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
}
}
1 change: 1 addition & 0 deletions poshsecframework/poshsecframework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PShell\psfhost.cs" />
<Compile Include="PShell\psfhostinterface.cs" />
<Compile Include="PShell\psfhostrawinterface.cs" />
<Compile Include="PShell\psfilenameeditor.cs" />
<Compile Include="PShell\pshosteditor.cs" />
<Compile Include="Strings\StringValue.cs" />
Expand Down

0 comments on commit 61e20fc

Please sign in to comment.