Didier Stevens

FileGen

FileGen is a command-line program to create test files of different lengths.

FileGen takes 2 or 3 parameters: filegen file size [byte]

  • filegen test 1000
    this will create a file named test and 1000 bytes long, the bytes are random
  • filegen test 1000 0
    this will create a file named test and 1000 bytes long, and all the bytes will be zero

 

The size and byte can be specified in hexadecimal notation, like this:

    filegen test 0x100 0xA0

 

When you create a random byte sequence, C’s pseudo random number generation function rand is seeded with the current time (srand(time(NULL))). This means that the generated byte sequence is different each time you run the command.

 

The algorithm is not optimized for speed.

FileGen doesn’t test if the generated file already exists, it will be overwritten without warning. And it will not test if you have the required disk space to create the file.

 

Generating a 1.000.000.000 bytes long random file takes 95 seconds on my 2GHz machine.

 

Compiled with Borland’s free C++ 5.5 compiler.

Download:

FileGen_V1_0_0.zip (https)

MD5: 6AAAB254D4BB10AC6320C7106C04FA79

SHA-256: D7BE1E64BAD8DE33EDAD6A218E0B8E4BC53E011E3B1175F05E384A63C4BF24D7

 

12 Comments »

  1. Neat. But you are probably doing more work than necessary. I usually just do:

    cat /dev/urandom | head -c 1000 > test

    It gives you a 1MB file filled with random bytes. It works on windows too if you install Cygwin.

    Comment by Luke — Monday 22 January 2007 @ 21:43

  2. I needed this tool for a Windows machine, installing Cygwin was not an option.

    2 remarks about your example:
    – it will create a 1000 bytes file, not a 1MB file
    – you don’t need the cat: head -c 1000 /dev/urandom > test

    Comment by Didier Stevens — Tuesday 23 January 2007 @ 9:58

  3. I just checked, there is no /dev directory on my Windows XP PC with Cygwin.

    Comment by Didier Stevens — Tuesday 23 January 2007 @ 14:07

  4. Hehe… This is what happens when you post in a hurry. You are right of course in both cases. Color me embarrassed.

    Either way it’s a cool tool for easily doing this under windows. I actually bookmarked this in case I need it in the future.

    Btw, my cygwin installation on XP did have a /dev directory – or at least it did have /dev/random and /dev/null cause I used them in the past without any problems. Maybe it depends on which components are installed.

    Comment by Luke — Tuesday 23 January 2007 @ 14:41

  5. cygwin 이 머하는 거요 ??

    Comment by cygwin — Sunday 11 March 2007 @ 23:54

  6. Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\user_1>cat /dev/urandom | head -c 1000 > test
    ‘cat’은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는
    배치 파일이 아닙니다.

    C:\Documents and Settings\user_1>

    Comment by cygwin — Sunday 11 March 2007 @ 23:57

  7. Awesome….Ill use this to lock up hard disk space and prevent fragmentation :)
    Could be used to overwrite free space previously written to :)

    Comment by Mehdi S — Friday 8 February 2008 @ 4:54

  8. There is no guarantee that your plan will work. Filegen is written in standard C and is not OS specific. You can compile it for Linux too. And it is slow, because I use the function fputc to write byte per byte to the file.

    There is no guarantee that the space used by a file generated with filegen will be consecutive. If you want to program with this kind of control, use the Windows Defragmentation API:

    http://technet.microsoft.com/en-us/sysinternals/bb897427.aspx

    If you’re looking for tool that do the job, take a look at Sysinternals:

    http://technet.microsoft.com/en-us/sysinternals/bb545046.aspx

    In particular, the tools contig and sdelete.

    Comment by Didier Stevens — Friday 8 February 2008 @ 9:46

  9. This alternative is somewhat faster, and has feedback;

    http://www.bertel.de/software/rdfc/index-en.html

    Comment by Drewfus — Wednesday 3 February 2010 @ 14:24

  10. @Drewfus: it’s faster because it is designed for Windows. I choose another design goal. My code is open source and written in standard C, hence usable on many platforms.

    Comment by Didier Stevens — Wednesday 3 February 2010 @ 19:20

  11. Comprehendo!

    Comment by Drewfus — Friday 5 February 2010 @ 14:20

  12. Hi Didier,

    Windows (since 2000): fsutil file createnew file.txt 1000000000
    less than 0,1 second but it’s empty.

    Best regards

    Comment by pat — Friday 15 July 2011 @ 13:48


RSS feed for comments on this post. TrackBack URI

Leave a Reply (comments are moderated)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 244 other followers

%d bloggers like this: