(C) Relatively high density file backups on paper. Cross-platform CLI port of Ollydbg's Paperback from Windows and Borland C.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Global.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * =====================================================================================
  3. *
  4. * Filename: Global.h
  5. *
  6. * Description: As paperback was designed around global memory management, some
  7. * must remain global until serious refactoring
  8. *
  9. * Version: 1.2
  10. * Created: 07/25/2017 09:23:02 AM
  11. * Revision: none
  12. * Compiler: gcc
  13. *
  14. * Author: Oleh Yuschuk
  15. * Modified By: suhrke@teknik.io
  16. *
  17. * =====================================================================================
  18. */
  19. #include <ctime>
  20. #include <string>
  21. #ifdef __WIN32
  22. #include <windows.h>
  23. #endif
  24. ////////////////////////////////////////////////////////////////////////////////
  25. ///////////////////////////// GENERAL DEFINITIONS //////////////////////////////
  26. typedef unsigned char uchar;
  27. typedef unsigned short ushort;
  28. typedef unsigned int uint;
  29. typedef unsigned long ulong;
  30. #define TEXTLEN 256 // Maximal length of strings
  31. #ifdef __WIN32
  32. #define MAXPATH 247 // max file path characters
  33. #define MAXFILE 255 // max file name characters
  34. #define MAXEXT 245 // max characters of file extension
  35. // Assuming smaller capacity FAT32, not NTFS
  36. #define MAXDIR 65534 // max files in a directory
  37. #define MAXDRIVE 268173300
  38. #elif __linux__
  39. #define MAXPATH 4096 // max file path characters
  40. #define MAXFILE 255 // max file name characters
  41. #define MAXEXT 4094 // max characters of file extension
  42. // Performance issues in ext2 beyond 10000 files
  43. #define MAXDIR 10000 // max files in a directory
  44. // 10^18 in ext2 and more in later filesystems
  45. // using max value of 32-bit int for compatibility
  46. #define MAXDRIVE 2147483647
  47. #endif
  48. ////////////////////////////////////////////////////////////////////////////////
  49. /////////////////////////////// DATA PROPERTIES ////////////////////////////////
  50. // Don't change the definitions below! Program may crash if any modified!
  51. #define NDOT 32 // Block X and Y size, dots
  52. #define NDATA 90 // Number of data bytes in a block
  53. #define MAXSIZE 0x0FFFFF80 // Maximal (theoretical) length of file
  54. #define SUPERBLOCK 0xFFFFFFFF // Address of superblock
  55. #define NGROUP 5 // For NGROUP blocks (1..15), 1 recovery
  56. #define NGROUPMIN 2
  57. #define NGROUPMAX 10
  58. typedef struct t_data { // Block on paper
  59. ulong addr; // Offset of the block or special code
  60. uchar data[NDATA]; // Useful data
  61. ushort crc; // Cyclic redundancy of addr and data
  62. uchar ecc[32]; // Reed-Solomon's error correction code
  63. } t_data;
  64. //static_assert(sizeof(t_data)==128);
  65. #define PBM_COMPRESSED 0x01 // Paper backup is compressed
  66. #define PBM_ENCRYPTED 0x02 // Paper backup is encrypted
  67. // FILETIME is 64-bit data type, time_t typically 64-bit, but was 32-bit in
  68. // older *NIX versions. long and pointers are 64-bit in *NIX while only
  69. // 32-bit in Windows. Depending on implementation, alignment issues possible
  70. typedef struct t_superdata { // Identification block on paper
  71. ulong addr; // Expecting SUPERBLOCK
  72. ulong datasize; // Size of (compressed) data
  73. ulong pagesize; // Size of (compressed) data on page
  74. ulong origsize; // Size of original (uncompressed) data
  75. uchar mode; // Special mode bits, set of PBM_xxx
  76. uchar attributes; // Basic file attributes
  77. ushort page; // Actual page (1-based)
  78. #ifdef _WIN32
  79. FILETIME modified; // Time of last file modification
  80. #elif __linux__
  81. time_t modified;
  82. #endif
  83. ushort filecrc; // CRC of compressed decrypted file
  84. char name[64]; // File name - may have all 64 chars
  85. ushort crc; // Cyclic redundancy of previous fields
  86. uchar ecc[32]; // Reed-Solomon's error correction code
  87. } t_superdata;
  88. //static_assert(sizeof(t_superdata)==sizeof(t_data));
  89. typedef struct t_block { // Block in memory
  90. ulong addr; // Offset of the block
  91. ulong recsize; // 0 for data, or length of covered data
  92. uchar data[NDATA]; // Useful data
  93. } t_block;
  94. typedef struct t_superblock { // Identification block in memory
  95. ulong addr; // Expecting SUPERBLOCK
  96. ulong datasize; // Size of (compressed) data
  97. ulong pagesize; // Size of (compressed) data on page
  98. ulong origsize; // Size of original (uncompressed) data
  99. ulong mode; // Special mode bits, set of PBM_xxx
  100. ushort page; // Actual page (1-based)
  101. #ifdef _WIN32
  102. FILETIME modified; // Time of last file modification
  103. #elif __linux__
  104. time_t modified;
  105. #endif
  106. ulong attributes; // Basic file attributes
  107. ulong filecrc; // 16-bit CRC of decrypted packed file
  108. char name[64]; // File name - may have all 64 chars
  109. int ngroup; // Actual NGROUP on the page
  110. } t_superblock;
  111. ////////////////////////////////////////////////////////////////////////////////
  112. //////////////////////////////// OPTIONS ///////////////////////////////
  113. // All unique
  114. char infile[MAXPATH]; // Last selected file to read
  115. char outbmp[MAXPATH]; // Last selected bitmap to save
  116. char inbmp[MAXPATH]; // Last selected bitmap to read
  117. char outfile[MAXPATH]; // Last selected data file to save
  118. // All unique
  119. int dpi; // Dot raster, dots per inch
  120. int dotpercent; // Dot size, percent of dpi
  121. int redundancy; // Redundancy (NGROUPMIN..NGROUPMAX)
  122. int printheader; // Print header and footer
  123. int printborder; // Border around bitmap
  124. int autosave; // Autosave completed files
  125. int bestquality; // Determine best quality
  126. // All unique
  127. int marginunits; // 0:undef, 1:inches, 2:millimeters
  128. int marginleft; // Left printer page margin
  129. int marginright; // Right printer page margin
  130. int margintop; // Top printer page margin
  131. int marginbottom; // Bottom printer page margin
  132. void Options(void);
  133. void Reporterror (std::string);
  134. void Message (std::string, int);