Jump to content

Make Big Files Full Of Junk


Recommended Posts

Dont enjoy yourself too much eh?

 

What does it do? It makes a file and fills it up with jibberish. User specifies the size of the file (in MB) and the filename to write to.

 

I needed to write this... because I have a 200GB drive in my computer not being used AT ALL, sooo... :) KB might find some fiendishly evil use for it or something :rolleyes:

 

main.c

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

#include "junkfile.h"

int main(char **argv, int argc) {
       char filename[500];
       char filesize[10];
       unsigned long iFilesize = 0;
       int ret = 0;

       memset(filename, 0, 500 * sizeof(char));
       memset(filesize, 0, 10 * sizeof(char));

       // ask for file name (no length checking here)
       printf("Filename> ");
       fgets(filename, 500, stdin);
       filename[strlen(filename) - 1] = '\0';

// ask for size in bytes (no length checking here either)
       do {
              printf("Size (Bytes)> ");
              fgets(filesize, 10, stdin);
              iFilesize = atol(filesize);
       } while (iFilesize < 1);

       if ((ret = CreateJunkFile(filename, iFilesize, NULL)) == 0) {
              printf("Done writing %d bytes\n", iFilesize);
       } else {
              switch(ret) {
                      case -1: {
                             // generic nastyness error because ... not checking errors properly
                            // (too tired thanks)
                           printf("fopen error, aborting...\n");
                           break;
                      }
              }
       }

       printf("Press any key to exit...\n");
       getch();
       return 0;
}

 

junkfile.c

#include "junkfile.h"

int CreateJunkFile(char *filename, unsigned long sizeInBytes, char *charToWrite) {
      char bChar = 'a';
      unsigned long i = 0;
      FILE *fp;
      short writeRandom = 0;

      if (charToWrite == NULL) {
            srand(time(NULL));
            writeRandom = 1;
      } else {
            bChar = *charToWrite;
      }

      fp = fopen(filename, "w");
      if (fp != NULL) {
              // write each byte
              for (i = 0; i < sizeInBytes; i++) {
                     if (writeRandom == 1) {
                           bChar = rand() % 255;
                     }

                     fwrite(&bChar, sizeof(char), 1, fp);
             }
             fclose(fp);
 	} else {
             // fopen error (check properly)
        return -1;
       }

       return 0;
}

 

junkfile.h

#ifndef JUNKFILE_H
#define JUNKFILE_H

#include <stdio.h>
#include <string.h>
#include <time.h>

int CreateJunkFile(char *, unsigned long, char *);
#endif

Share this post


Link to post
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

MS already has this in the Resource kit - it's called "creatfil.exe"

 

It's nice to see how to do it though...

485049[/snapback]

 

Didn't know that :)

 

Evil as in shove the junk file through TKC and see what happens? You could just change the output from [filename] to stdin right?

485059[/snapback]

 

..... don't think so, no, but I know how to "simulate" key/mouse events, that'd probly do it.

Share this post


Link to post
Share on other sites

Thats what I ment. I know how to do this with a loop that just repats a letter or number a bunch of times. But to random junk.

 

Dim ReturnValue, I
ReturnValue = Shell("CALC.EXE", 1)    ' Run Calculator.
AppActivate ReturnValue     ' Activate the Calculator.
For I = 1 To 100    ' Set up counting loop.
   SendKeys I & "{+}", True    ' Send keystrokes to Calculator
Next I    ' to add each value of I.
SendKeys "=", True    ' Get grand total.
SendKeys "%{F4}", True    ' Send ALT+F4 to close Calculator.

Share this post


Link to post
Share on other sites

is that Java or C++

485198[/snapback]

 

What, ijagwalaafq's bit of code? That's neither Java or C/++! It's VB lol

 

Mine actually appears to pass through a C compiler alright. I've no idea why I named them cpp, since I aint using any of that complex C++ template/classes stuff. *renames them .c*

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...