PatternCollector.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef PATTERNCOLLECTOR
  2. #define PATTERNCOLLECTOR
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. #include <stdlib.h>
  6. #include <vector>
  7. #define SYMLEN 16 /* Number of chars in the symbol name, incl null */
  8. #define PATLEN 23 /* Number of bytes in the pattern part */
  9. struct HASHENTRY
  10. {
  11. char name[SYMLEN]; /* The symbol name */
  12. uint8_t pat [PATLEN]; /* The pattern */
  13. uint16_t offset; /* Offset (needed temporarily) */
  14. };
  15. struct PatternCollector {
  16. uint8_t buf[100], bufSave[7]; /* Temp buffer for reading the file */
  17. uint16_t readShort(FILE *f)
  18. {
  19. uint8_t b1, b2;
  20. if (fread(&b1, 1, 1, f) != 1)
  21. {
  22. printf("Could not read\n");
  23. exit(11);
  24. }
  25. if (fread(&b2, 1, 1, f) != 1)
  26. {
  27. printf("Could not read\n");
  28. exit(11);
  29. }
  30. return (b2 << 8) + b1;
  31. }
  32. void grab(FILE *f,int n)
  33. {
  34. if (fread(buf, 1, n, f) != (size_t)n)
  35. {
  36. printf("Could not read\n");
  37. exit(11);
  38. }
  39. }
  40. uint8_t readByte(FILE *f)
  41. {
  42. uint8_t b;
  43. if (fread(&b, 1, 1, f) != 1)
  44. {
  45. printf("Could not read\n");
  46. exit(11);
  47. }
  48. return b;
  49. }
  50. uint16_t readWord(FILE *fl)
  51. {
  52. uint8_t b1, b2;
  53. b1 = readByte(fl);
  54. b2 = readByte(fl);
  55. return b1 + (b2 << 8);
  56. }
  57. /* Called by map(). Return the i+1th key in *pKeys */
  58. uint8_t *getKey(int i)
  59. {
  60. return keys[i].pat;
  61. }
  62. /* Display key i */
  63. void dispKey(int i)
  64. {
  65. printf("%s", keys[i].name);
  66. }
  67. std::vector<HASHENTRY> keys; /* array of keys */
  68. virtual int readSyms(FILE *f)=0;
  69. };
  70. #endif // PATTERNCOLLECTOR