Random file size

Discussion in 'Mixed Languages' started by Alphawaves, Dec 5, 2012.

  1. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,906
    20,439
    180
    #1 Alphawaves, Dec 5, 2012
    Last edited by a moderator: Apr 20, 2017
    Ok i made a function a long time ago to add random file byte size (white space) to a file and its been doing nothing, so if it will help anyone here it is:

    Code:
    public bool ByteToFile(string FileName)
            {
                try
                {
                    byte[] Buffer1 = null;
                    byte[] ByteArray = null;
                    int RandSize = 322024; //size
                    Random rand = new Random();
                    byte[] nullArray = new byte[rand.Next(RandSize) + 1];
                    Buffer1 = File.ReadAllBytes(FileName);
                    ByteArray = new byte[Buffer1.Length + nullArray.Length + 1];
                    Buffer.BlockCopy(Buffer1, 0, ByteArray, 0, Buffer1.Length);
                    Buffer.BlockCopy(nullArray, 0, ByteArray, Buffer1.Length, nullArray.Length);
                    FileStream FileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write);
                    FileStream.Write(ByteArray, 0, ByteArray.Length);
                    FileStream.Close();
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                return false;
            }
    Usage:
    Code:
    ByteToFile(Your file);
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,112
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...