text: #include "utils.h"
  
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  
  uint8_t *hex_string_to_bin(const char *hex_string) {
      size_t   i, len = strlen(hex_string) / 2;
      uint8_t *ret = (uint8_t *)malloc(len);
      if (!ret) {
          return NULL;
      }
  
      const char *pos = hex_string;
  
      for (i = 0; i < len; ++i, pos += 2) {
          sscanf(pos, "%2hhx", &ret[i]);
      }
  
      return ret;
  }
  
  off_t get_file_size(char *file) {
      off_t size = 0;
  
      FILE *fp = fopen(file, "r");
      if (fp == NULL) {
          return size;
      }
  
      fseek(fp, 0, SEEK_END);
      size = ftell(fp);
      fseek(fp, 0, SEEK_SET);
      fclose(fp);
  
      return size;
  }
  
  void to_hex(char *out, uint8_t *in, int size) {
      while (size--) {
          if (*in >> 4 < 0xA) {
              *out++ = '0' + (*in >> 4);
          } else {
              *out++ = 'A' + (*in >> 4) - 0xA;
          }
  
          if ((*in & 0xf) < 0xA) {
              *out++ = '0' + (*in & 0xF);
          } else {
              *out++ = 'A' + (*in & 0xF) - 0xA;
          }
          in++;
      }
  }
  