project.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <string>
  3. #include <stdint.h>
  4. #include <cassert>
  5. #include <list>
  6. #include <llvm/ADT/ilist.h>
  7. #include "symtab.h"
  8. #include "BinaryImage.h"
  9. #include "Procedure.h"
  10. class SourceMachine;
  11. struct CALL_GRAPH;
  12. class IProject
  13. {
  14. virtual PROG *binary()=0;
  15. virtual const std::string & project_name() const =0;
  16. virtual const std::string & binary_path() const =0;
  17. };
  18. class Project : public IProject
  19. {
  20. static Project *s_instance;
  21. std::string m_fname;
  22. std::string m_project_name;
  23. public:
  24. typedef llvm::iplist<Function> FunctionListType;
  25. typedef FunctionListType lFunction;
  26. typedef FunctionListType::iterator ilFunction;
  27. SYMTAB symtab; /* Global symbol table */
  28. FunctionListType pProcList;
  29. CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  30. PROG prog; /* Loaded program image parameters */
  31. // no copies
  32. Project(const Project&) = delete;
  33. const Project &operator=(const Project & l) =delete;
  34. // only moves
  35. Project(); // default constructor,
  36. public:
  37. void create(const std::string & a);
  38. const std::string &project_name() const {return m_project_name;}
  39. const std::string &binary_path() const {return m_fname;}
  40. ilFunction funcIter(Function *to_find);
  41. ilFunction findByEntry(uint32_t entry);
  42. ilFunction createFunction();
  43. bool valid(ilFunction iter);
  44. int getSymIdxByAdd(uint32_t adr);
  45. bool validSymIdx(size_t idx);
  46. size_t symbolSize(size_t idx);
  47. hlType symbolType(size_t idx);
  48. const std::string &symbolName(size_t idx);
  49. const SYM &getSymByIdx(size_t idx) const;
  50. static Project *get();
  51. PROG * binary() {return &prog;}
  52. SourceMachine *machine();
  53. protected:
  54. void initialize();
  55. void writeGlobSymTable();
  56. };
  57. //extern Project g_proj;