1

I'm trying to write a program that simply uses all available physical memory (i.e. so that Task Manager shows 100% RAM utilization). I wrote the following but although it allocates outrageous amounts of memory (about 58GB on my system), all of that seems to go to the swap file or something, and Task Manager still reports plenty of available physical memory.

    class Program
    {
        static void Main(string[] args)
        {
            var memoryBlocks = new List<byte[]>();
            var chunk = 10000000;
            while (chunk > 100)
            {
                try
                {
                    memoryBlocks.Add(new byte[chunk]);
                    Console.WriteLine("Using {0}MB", memoryBlocks.Sum(b => (float)b.Length) / 1000000);
                }
                catch (OutOfMemoryException)
                {
                    chunk /= 10;
                }
            }
            Console.ReadKey();
        }
    }
Asik
  • 21,506
  • 6
  • 72
  • 131

3 Answers3

1

If you're running on 64bit system you can use AllocateUserPhysicalPages function which allocates physical memory

From the documentation:

The AllocateUserPhysicalPages function is used to allocate physical memory that can later be mapped within the virtual address space of the process. The SeLockMemoryPrivilege privilege must be enabled in the caller's token or the function will fail with ERROR_PRIVILEGE_NOT_HELD. For more information, see Privilege Constants. Memory allocated by this function must be physically present in the system. After the memory is allocated, it is locked down and unavailable to the rest of the virtual memory management system.

For more information see: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366528%28v=vs.85%29.aspx

yakiro
  • 718
  • 4
  • 9
0

Well... Here's a script I made for MD5 brute forcing that maxes out the RAM in an hour or so...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace csharp
{
    class Program
    {
        public static string[] letters = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };

        static void Main(string[] args)
        {
            //string mg = MD5Hash("john");
            bool inp = false;
            string hash;
            while (!inp) {
                Console.WriteLine("Please input the hash you're trying to bruteforce...");
                hash = Console.ReadLine();
                if (hash.Length == 32) {
                    inp = true;
                    Console.WriteLine("Cracked! There you go: " + startProcess(hash));
                    Console.ReadLine();
                }
            }
        }
        public static string startProcess(string hsh) {
            bool solved = false;
            string track = letters[0];
            string ltrack = letters[letters.Length - 1];
            while (!solved) {
                //Console.WriteLine(track); // remove this line for debug
                track = setLCharPos(track, ltrack);
                if (MD5Hash(track) == hsh) {
                    solved = true;
                    return track;
                }
            } return track;
        }
        public static string setLCharPos(string ttr, string ltr) {

            if (ttr == "") return letters[0];

            if (ttr[ttr.Length - 1].ToString() != ltr) {
                return ttr.Substring(0, ttr.Length - 1) + letters[Array.IndexOf(letters, ttr[ttr.Length - 1].ToString()) + 1];
            } else {
                return setLCharPos(ttr.Substring(0, ttr.Length - 1), ltr) + letters[0];
            }
        }
        public static string MD5Hash(string text)
        {
            MD5 md5 = new MD5CryptoServiceProvider();

            //compute hash from the bytes of text
            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));

            //get hash result after compute it
            byte[] result = md5.Hash;

            StringBuilder strBuilder = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                //change it into 2 hexadecimal digits
                //for each byte
                strBuilder.Append(result[i].ToString("x2"));
            }

            return strBuilder.ToString();
        }
    }
}

Just insert any 32 character string and it will loop forever. Unless you actually are trying to bruteforce, I take no responsibility for this.

Johnaudi
  • 257
  • 1
  • 23
-1

The System manages the ram for you. This means, whenever your Application will exceed the boundaries of available ram, the system will deal with it. (Moving it to the harddisk, etc..)

Therefore you can not fill up the ram to 100%.

And it would be BAD if a single app COULD fill up the ram ;)

dognose
  • 20,360
  • 9
  • 61
  • 107