1 #ifndef ___BIN_RECORD_H__ 2 #define ___BIN_RECORD_H__ 3 4 #include <stddef.h> 5 #include <stdint.h> 6 7 #include <list> 8 #include <map> 9 #include <unordered_map> 10 #include <vector> 11 12 #define MAX_IQBIN_SIZE 2048000 13 14 typedef struct __map_index { 15 void *dst_offset; 16 void *ptr_offset; 17 size_t len; 18 } map_index_t; 19 20 class BinMapLoader { 21 public: BinMapLoader()22 explicit BinMapLoader() 23 : struct_buffer(NULL), buffer_size(0), same_block(0){}; 24 BinMapLoader(uint8_t * data,size_t len)25 explicit BinMapLoader(uint8_t *data, size_t len) 26 : struct_buffer(data), buffer_size(len), same_block(0){}; 27 28 ~BinMapLoader() = default; 29 30 static int suqeezBinMap(const char *fpath, uint8_t *buffer, 31 size_t buffer_len); 32 33 int saveFile(const char *fpath, void *buf, size_t file_size); 34 int genBinary(void *buffer, size_t buffer_size); 35 int collectBinMap(); 36 int suqeezBinMapOne(); 37 int findDuplicate(map_index_t *map_item, size_t map_index, 38 map_index_t *ori_item); 39 int removeBlock(map_index_t *map_item, size_t map_index, 40 map_index_t *same_item); 41 int removeMap(map_index_t *map_item, size_t map_index); 42 void info(); 43 44 int parseBinStructMap(uint8_t *data, size_t len); 45 int compareBinStruct(map_index_t *binstruct1, map_index_t *binstruct2); 46 int dumpMap(); 47 48 void *loadWholeFile(const char *fpath, size_t *fsize); 49 int loadFile(const char *filename); 50 51 private: 52 uint8_t *struct_buffer; 53 size_t buffer_size; 54 size_t same_block; 55 size_t block_count; 56 std::unordered_map<uint64_t, void *> buffer_map; 57 std::unordered_map<uint64_t, void *> dst_map; 58 std::vector<uint8_t> block_vec; 59 std::vector<uint8_t> map_vec; 60 }; 61 62 #endif /*___BIN_RECORD_H__*/ 63 64