Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * [hacking.h]
- *
- * General purpose (error handler/utility) functions.
- */
- #ifndef HACKING_H
- #define HACKING_H
- #include <stdio.h> /* for perror() */
- #include <stdlib.h> /* for malloc() */
- #include <string.h> /* for strcpy() and strncat() */
- /**
- * The fatal() function:
- *
- * A function to display an error message and then exit.
- */
- void fatal(char *message)
- {
- char error_message[100];
- strcpy(error_message, "[!!] Fatal Error ");
- strncat(error_message, message, 83);
- perror(error_message);
- exit(-1);
- }
- /**
- * The ec_malloc() function:
- *
- * An error-checked malloc() wrapper function.
- */
- void *ec_malloc(unsigned int size)
- {
- void *ptr;
- ptr = malloc(size);
- if(ptr == NULL)
- fatal("in ec_malloc() on memory allocation");
- return ptr;
- }
- /**
- * The dump() function:
- *
- * A function that dumps raw memory in hex byte and printable split format.
- */
- void dump(const unsigned char *data_buffer, const unsigned int length)
- {
- unsigned char byte;
- unsigned int i;
- unsigned int j;
- for(i = 0; i < length; i++)
- {
- byte = data_buffer[i];
- printf("%02x ", data_buffer[i]); /* Display byte in hex format. */
- if(((i % 16) == 15) || (i == (length - 1)))
- {
- for(j = 0; j < (15 - (i % 16)); j++)
- printf(" ");
- printf("| ");
- for(j = (i - (i % 16)); j <= i; j++) /* Display printable bytes from line... */
- {
- byte = data_buffer[j];
- if((byte > 31) && (byte < 127)) /* ...outside printable char range. */
- printf("%c", byte);
- else
- printf(".");
- }
- printf("\n"); /* End of the dump line (each line 16 bytes). */
- }
- }
- }
- #endif
Add Comment
Please, Sign In to add comment