Question: Write a C program to dump sections of memory in hexadecimal format. Specifically, you are required to print a memory map for all memory areas

Write a C program to dump sections of memory in hexadecimal format. Specifically, you are required to print a memory map for all memory areas that correspond to the command-line arguments argc and argv.

You may use a 32-bit system, or a 64-bit system. In addition, the output should reflect the native endianness of the system you are using. Two output samples (32-bit, and 64-bit) are provided.

They were both generated using the following command line with little-endian byte order:

$ printMemoryMap A hippopotamus got on the bus where printMemoryMap is the name of the executable file.

Your program must work correctly with any number of command-line arguments. In addition, your program must produce the exact same format as given in the 32-bit or 64-bit examples. Of course, even if you use the same command-line as illustrated, the addresses in your output will be different than the ones shown in the sample output. In addition, the option system in use will impact the way argv[0] is constructed (e.g., it may or may not include the full path).

Note that the memory locations where the command-line arguments are stored may not follow the same order in which the command-line arguments are stored in argv. For example, notice how in the sample output the string pointed to by argv[0] is stored at a higher memory location than the string pointed to by argv[1].

Hints

The printf() C library function supports the %p specifier to print pointer address. For example, you canuse:printf("%p", q)toprinttheaddressstoredinq,foranypointerq.Alternatively,youcan alsousethe%Xspecifierasfollows:printf("%08X", q)toprintanyintegertypeinhexadecimalleft- padded with zeroes (0) up to a width of 8 characters.

To chop an address into its byte components (4 bytes or 8 bytes, depending on whether you are using a 32-bit or 64-bit system, respectively) you can use either bit-wise operators or convert the address to a hexadecimal string first and then perform string manipulation. If you decide to use the latter approach, you may find the itoa C Standard library function handy.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!