summaryrefslogtreecommitdiff
path: root/hacking.h
blob: 2684b6cadeef6562481addebf61b1c8dc2f0ce31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdlib.h>

void fatal(char *message)
{
  char error_message[100];
  strcpy(error_message, "[!!] Fatal Error ");
  strncat(error_message, message, 83);
  perror(error_message);
  exit(-1);
}

void *ec_malloc(unsigned int size)
{
  void *ptr;
  ptr = malloc(size);
  if (ptr == NULL)
    fatal("in ec_malloc() on memory allocation");
  return ptr;
}

void dump(const char *data_buffer, const unsigned int length) {
  unsigned char byte;
  unsigned int i, j;

  for (int i = 0; i < length; i++) {
    byte = data_buffer[i];
    printf("%02x ", data_buffer[i]);
    if ( ((i%16) == 15) || (i==length-1) ) {
      for (int j = 0; j < 15 - (i%16); j++) {
        printf("   ");
      }
      printf("| ");
      for (j=(i-(i%16)); j <= i; j++) {
        byte = data_buffer[j];
        if ((byte > 31) && (byte < 127)) {
          printf("%c", byte);
        } else {
          printf(".");
        }
      }
      printf("\n");
    }
  }
}