Artifact C-1: Cdump Utility (Command Prompt)

Description

The following description of the cdump program is based on the documentation of the hexdump utility:

NAME
cdump – ascii, hexadecimal, octal dump
SYNOPSIS
cdump [-bcC] [-nlength] [-soffset] [file]
DESCRIPTION
The cdump utility is a filter which displays the specified file, or the standard input, if no file is specified, in a user specified format.The options are as follows:

-b
One-byte octal display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, zero-filled, bytes of input data, in octal, per line.
-c
One-byte character display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space-filled, characters of input data per line.
-C
Canonical hex+ASCII display. Display the input offset in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes in “character” format enclosed in ‘|’ characters.
-nlength
Interpret only length bytes of input. Note that there is no space between -n and length.
-soffset
Skip offset bytes from the beginning of the input. Note that there is no space between -s and offset.

The default is to interpret length & offset as decimal numbers. If they start with 0x (zero x) or 0X (zero X), they are interpreted as hexadecimal numbers; otherwise, if they start with 0 (zero), they are interpreted as octal numbers.

The default format, when neither -b, -c nor -C is specified, is to use one-byte hexadecimal display — the input offset is displayed in hexadecimal, followed by sixteen space-separated, two column, zero-filled, bytes of input data, in hexadecimal, per line.

Technical Knowledge

I learned and applied my knowledge of:

  • procedural programming in C
  • command line argument validation
  • basic I/O.

Skills Applied

I developed these skills while making this artifact:

  • programming with C
  • working with octal and hexadecimal number systems
  • managing complex user requirements.

Notes

I wrote this for BCIT’s COMP 2510, Procedural Programming in C, in July 2008.

We were required to write logic accommodating complex requirements including special cases like:

  • if the file to dump has size 0, there should be no output
  • if the number of bytes to skip is more than the number of bytes in the file, there should be no output
  • if the number of bytes to dump exceeds the number of bytes available, dumping stops at the end of the file

The following shows the -C option. The output format is somewhat different from the other cases.

$ cdump -C hello.o
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF…………|
00000010 01 00 03 00 01 00 00 00 00 00 00 00 00 00 00 00 |…………….|
00000020 c0 00 00 00 00 00 00 00 34 00 00 00 00 00 28 00 |……..4…..(.|
00000030 0a 00 07 00 55 89 e5 83 ec 08 83 e4 f0 b8 00 00 |….U………..|
00000040 00 00 29 c4 83 ec 0c 68 00 00 00 00 e8 fc ff ff |..)….h……..|
… (40 lines omitted) …
000002d0 0e 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 |…………….|
000002e0 00 68 65 6c 6c 6f 2e 63 00 6d 61 69 6e 00 70 72 |.hello.c.main.pr|
000002f0 69 6e 74 66 00 00 00 00 14 00 00 00 01 05 00 00 |intf…………|
00000300 19 00 00 00 02 08 00 00 |……..|
00000308

Demonstration

Download a ZIP file containing the C source code here [4 KB]
Alternatively, you can download the Win Executable [16 KB] or Linux Executable [12 KB]

  • Share/Bookmark

Tags: , , , , ,

Leave a Comment

Spam Protection by WP-SpamFree