/// <summary> /// ProcessRecord - core powershell function /// </summary> protected override void ProcessRecord() { byte[] buffer = Rando.GetBytes(this.Width * this.Height); var bmp = BitmapHelper.CreateBitmap(this.Width, this.Height, buffer); WriteObject(bmp); }
private static String GetUnicodeString(ulong length) { StringBuilder str = new StringBuilder(); while (((ulong)str.Length) < length) { str.Append(BitConverter.ToChar(Rando.GetBytes(2), 0)); } return(str.ToString()); }
/// <summary> /// ProcessRecord - primary Cmdlet func /// </summary> protected override void ProcessRecord() { switch (this.StringType) { case StringType.AaZz: case StringType.AlphaNumeric: case StringType.ASCII: case StringType.ANSI: case StringType.Hex: case StringType.LowerCase: case StringType.UpperCase: case StringType.Unicode: case StringType.Digits: System.IO.File.WriteAllText(this.OutputFile, StringGenerator.GetString(this.StringType, this.Size)); break; case StringType.Name: case StringType.Word: case StringType.Sentence: case StringType.Email: case StringType.EmailSimple: case StringType.Domain: case StringType.TLD: case StringType.Uri: UInt64 writtenSize = 0; while (writtenSize < this.Size) { String data = StringGenerator.GetString(this.StringType) + this.Seperator; writtenSize += (UInt64)data.Length; System.IO.File.AppendAllText(this.OutputFile, data); } break; case StringType.Random: default: System.IO.File.WriteAllBytes(this.OutputFile, Rando.GetBytes(this.Size)); break; } WriteObject(new FileInfo(this.OutputFile)); }
protected override void ProcessRecord() { this.repeteIndex = 0; UInt64 writtenSize = 0; using (var writer = new FileStream(this.OutputFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) { while (writtenSize < this.Size) { Byte[] data; ulong bsize = this.BlockSize; if (writtenSize + BlockSize > this.Size) { bsize = this.Size - writtenSize; } switch (this.ParameterSetName.ToLowerInvariant()) { case "repeatstr": case "repeat": { data = this.extractpattern((int)bsize); } break; case "random": default: { data = Rando.GetBytes(bsize); } break; } writtenSize += (UInt64)data.Length; writer.Write(data, 0, data.Length); } } WriteObject(new FileInfo(this.OutputFile)); }
/// <summary> /// ProcessRecord - primary powershell cmdlet entrance /// </summary> protected override void ProcessRecord() { Bitmap bmp = null; switch (this.Type) { case TypedImage.SimpleShape: { bmp = new Bitmap(this.Width, this.Height); var unit = GraphicsUnit.Pixel; var rect = bmp.GetBounds(ref unit); using (var gfx = Graphics.FromImage(bmp)) { for (int i = 0; i < this.ShapeCount; i++) { ShapesArtist.DrawShape(gfx, rect, this.Shape, true, this.IsFilled); } } } break; case TypedImage.Pixel: { byte[] data = new byte[this.Width * this.Height]; byte[] c = null; for (int y = 0; y < this.Height; y++) { if (y % this.PixelSize == 0) { c = Rando.GetBytes(this.Width / this.PixelSize); } for (int x = 0; x < this.Width; x++) { int idx = (y * this.Width) + x; data[idx] = c[x / this.PixelSize]; } } bmp = BitmapHelper.CreateBitmap(this.Width, this.Height, data); // Alternate method to do the same thing //bmp = new Bitmap(this.Width, this.Height); //List<RectangleF> gridBlocks = getGridBlocks(); //using (var gfx = Graphics.FromImage(bmp)) //{ // foreach (var grid in gridBlocks) // { // using (var brush = new SolidBrush(Rando.RandomColor())) // { // ShapesArtist.DrawRectangle(gfx, brush, null, grid, true); // } // } //} } break; case TypedImage.GridShapes: { bmp = new Bitmap(this.Width, this.Height); List <RectangleF> gridBlocks = GetGridBlocks(this.Width, this.Height, this.PixelSize); //create images for each grid rectangle using (var gfx = Graphics.FromImage(bmp)) { foreach (var grid in gridBlocks) { ShapesArtist.DrawShape(gfx, grid, this.Shape, false, this.IsFilled); } } } break; default: { byte[] buffer = Rando.GetBytes(this.Width * this.Height); bmp = BitmapHelper.CreateBitmap(this.Width, this.Height, buffer); } break; } WriteObject(bmp); }