sift_writer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef __SIFT_WRITER_H
  2. #define __SIFT_WRITER_H
  3. #include "sift.h"
  4. #include "sift_format.h"
  5. #include <unordered_map>
  6. #include <fstream>
  7. #include <assert.h>
  8. class vistream;
  9. class vostream;
  10. namespace Sift
  11. {
  12. class Writer
  13. {
  14. typedef void (*GetCodeFunc)(uint8_t *dst, const uint8_t *src, uint32_t size);
  15. typedef void (*HandleAccessMemoryFunc)(void *arg, MemoryLockType lock_signal, MemoryOpType mem_op, uint64_t d_addr, uint8_t *data_buffer, uint32_t data_size);
  16. private:
  17. vostream *output;
  18. vistream *response;
  19. GetCodeFunc getCodeFunc;
  20. HandleAccessMemoryFunc handleAccessMemoryFunc;
  21. void *handleAccessMemoryArg;
  22. uint64_t ninstrs, hsize[16], haddr[MAX_DYNAMIC_ADDRESSES+1], nbranch, npredicate, ninstrsmall, ninstrext;
  23. uint64_t last_address;
  24. std::unordered_map<uint64_t, bool> icache;
  25. int fd_va;
  26. std::unordered_map<intptr_t, bool> m_va2pa;
  27. char *m_response_filename;
  28. uint32_t m_id;
  29. bool m_requires_icache_per_insn;
  30. bool m_send_va2pa_mapping;
  31. void initResponse();
  32. void handleMemoryRequest(Record &respRec);
  33. void send_va2pa(uint64_t va);
  34. uint64_t va2pa_lookup(uint64_t va);
  35. public:
  36. Writer(const char *filename, GetCodeFunc getCodeFunc, bool useCompression = false, const char *response_filename = "", uint32_t id = 0, bool arch32 = false, bool requires_icache_per_insn = false, bool send_va2pa_mapping = false);
  37. ~Writer();
  38. void End();
  39. void Instruction(uint64_t addr, uint8_t size, uint8_t num_addresses, uint64_t addresses[], bool is_branch, bool taken, bool is_predicate, bool executed);
  40. Mode InstructionCount(uint32_t icount);
  41. void CacheOnly(uint8_t icount, CacheOnlyType type, uint64_t eip, uint64_t address);
  42. void Output(uint8_t fd, const char *data, uint32_t size);
  43. uint64_t Syscall(uint16_t syscall_number, const char *data, uint32_t size);
  44. int32_t NewThread();
  45. int32_t Join(int32_t);
  46. Mode Sync();
  47. uint64_t Magic(uint64_t a, uint64_t b, uint64_t c);
  48. bool Emulate(Sift::EmuType type, Sift::EmuRequest &req, Sift::EmuReply &res);
  49. int32_t Fork();
  50. void RoutineChange(Sift::RoutineOpType event, uint64_t eip, uint64_t esp, uint64_t callEip = 0);
  51. void RoutineAnnounce(uint64_t eip, const char *name, const char *imgname, uint64_t offset, uint32_t line, uint32_t column, const char *filename);
  52. void setHandleAccessMemoryFunc(HandleAccessMemoryFunc func, void* arg = NULL) { assert(func); handleAccessMemoryFunc = func; handleAccessMemoryArg = arg; }
  53. };
  54. };
  55. #endif // __SIFT_WRITER_H