CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_project.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, an unpublished work by CodeSecure, Inc.
3  * ALL RIGHTS RESERVED
4  *
5  * Copyright (c) 2013-2023, an unpublished work by GrammaTech, Inc.
6  * ALL RIGHTS RESERVED
7  *
8  * This software is furnished under a license and may be used and
9  * copied only in accordance with the terms of such license and the
10  * inclusion of the above copyright notice. This software or any
11  * other copies thereof may not be provided or otherwise made
12  * available to any other person. Title to and ownership of the
13  * software is retained by CodeSecure, Inc.
14  */
15 
16 #ifndef CS_PROJECT_HPP
17 #define CS_PROJECT_HPP
18 
19 #include "cs_sdg.h"
20 #include "cs_interest_sets.h"
21 #include "cs_binaries.h"
22 #include "cs_procedure_decl.hpp"
23 #include "cs_directory_fwd.hpp"
24 #include "cs_scratchpad.hpp"
25 #include "cs_xref.hpp"
26 #include "cs_ir_factory.hpp"
27 #include "cs_amc_analysis.hpp"
28 #include "cs_sfileinst_decl.hpp"
29 
32 namespace cs{
33 
34  template<>
35  class cglue<interest_set>
36  {
37  cglue();
38  friend class scratchpad<interest_set>;
39  public:
40  typedef interest_set type;
41  typedef cs_string_pdgvs_pair ctype;
42  CS_CXX_API_CGLUE_ACCESS_MODIFIER:
43  static type wrap(const ctype &c)
44  {
45  return interest_set(
46  c.string,
47  cglue<point_set>::wrap(c.pdg_vertex_set, false) );
48  }
49  };
50 
51  template<>
52  class cglue<std::vector<procedure> >
53  {
54  cglue();
55  friend class scratchpad<std::vector<procedure> >;
56  public:
57  typedef std::vector<procedure> type;
58  typedef cs_pdglist_pair ctype;
59  CS_CXX_API_CGLUE_ACCESS_MODIFIER:
60  static type wrap(const ctype &c)
61  {
62  std::vector<procedure> rv;
63  rv.reserve(c.n_sublist_elements);
64  for( size_t i = 0; i < c.n_sublist_elements; i++ )
65  rv.push_back(cglue<procedure>::wrap(c.pdglst_ptr[i]));
66  return rv;
67  }
68  };
69 
70  class symbol_universe_iterator_policy{
71  public:
72  typedef cs_abs_loc_for_each_iter iterator_impl;
73  typedef symbol key;
74  typedef char ctype;
75 
76  static cs_result iter_first(
77  ctype container,
78  cglue<key>::ctype *val,
79  iterator_impl *it)
80  { return cs_abs_loc_for_each_first( val, it ); }
81  static cs_result iter_next(
82  ctype container,
83  cglue<key>::ctype *val,
84  iterator_impl *it)
85  { return cs_abs_loc_for_each_next( val, it ); }
86  static cs_result iter_close(iterator_impl *it)
87  { return cs_abs_loc_for_each_close( it ); }
88  static const char *name()
89  { return "symbol_universe_iterator"; }
90  };
91 
92  class project_procedures_iterator_policy{
93  public:
94  typedef cs_sdg_pdgs_iter iterator_impl;
95  typedef procedure key;
96  typedef char ctype;
97 
98  static cs_result iter_first(
99  ctype container,
100  cglue<key>::ctype *val,
101  iterator_impl *it)
102  { return cs_sdg_pdgs_iter_first( val, it ); }
103  static cs_result iter_next(
104  ctype container,
105  cglue<key>::ctype *val,
106  iterator_impl *it)
107  { return cs_sdg_pdgs_iter_next( val, it ); }
108  static cs_result iter_close(iterator_impl *it)
109  { return cs_sdg_pdgs_iter_close( it ); }
110  static const char *name()
111  { return "project_procedures_iterator"; }
112  };
113 
114  class project_compunits_iterator_policy{
115  public:
116  typedef cs_sdg_uids_iter iterator_impl;
117  typedef compunit key;
118  typedef empty_class ctype;
119 
120  static cs_result iter_first(
121  ctype container,
122  cglue<key>::ctype *val,
123  iterator_impl *it)
124  { return cs_sdg_uids_iter_first( val, it ); }
125  static cs_result iter_next(
126  ctype container,
127  cglue<key>::ctype *val,
128  iterator_impl *it)
129  { return cs_sdg_uids_iter_next( val, it ); }
130  static cs_result iter_close(iterator_impl *it)
131  { return cs_sdg_uids_iter_close( it ); }
132  static const char *name()
133  { return "project_compunits_iterator"; }
134  };
135 
136  class project_sfiles_iterator_policy{
137  public:
138  typedef cs_sdg_sfs_iter iterator_impl;
139  typedef sfile key;
140  typedef empty_class ctype;
141 
142  static cs_result iter_first(
143  ctype container,
144  cglue<key>::ctype *val,
145  iterator_impl *it)
146  { return cs_sdg_sfs_iter_first( val, it ); }
147  static cs_result iter_next(
148  ctype container,
149  cglue<key>::ctype *val,
150  iterator_impl *it)
151  { return cs_sdg_sfs_iter_next( val, it ); }
152  static cs_result iter_close(iterator_impl *it)
153  { return cs_sdg_sfs_iter_close( it ); }
154  static const char *name()
155  { return "project_sfiles_iterator"; }
156  };
157 
158  class project_root_directories_iterator_policy{
159  public:
160  typedef cs_directory_root_directory_iter iterator_impl;
161  typedef directory key;
162  typedef empty_class ctype;
163 
164  static cs_result iter_first(
165  ctype container,
166  cglue<key>::ctype *val,
167  iterator_impl *it)
168  { return cs_directory_root_directory_iter_first( val, it ); }
169  static cs_result iter_next(
170  ctype container,
171  cglue<key>::ctype *val,
172  iterator_impl *it)
173  { return cs_directory_root_directory_iter_next( val, it ); }
174  static cs_result iter_close(iterator_impl *it)
175  { return cs_directory_root_directory_iter_close( it ); }
176  static const char *name()
177  { return "project_root_directories_iterator"; }
178  };
179 
189  typedef csuint32 xtype_render_style_helper;
190  CS_FLAGS_BOILERPLATE(
191  xtype_render_style, xtype_render_style_helper,
192  cs_xtype_all,
193  "int_as_intnn_t",
194  "int_as_dword",
195  "int_as_std32",
196  "int_as_csintnn",
197  "(unused)",
198  "(unused)",
199  "(unused)",
200  "(unused)",
201  "unknown_as_intnn_t",
202  "unknown_as_dword",
203  "unknown_as_std32",
204  "unknown_as_csintnn",
205  "(unused)",
206  "(unused)",
207  "(unused)",
208  "(unused)",
209  "float_as_floatnn_t",
210  "float_as_dword",
211  "float_as_std32",
212  "(unused)",
213  "(unused)",
214  "(unused)",
215  "(unused)",
216  "(unused)",
217  "skip_typedef",
218  "ptr_to_array",
219  "inout_ptrs",
220  "single_line"
221  );
224  static const xtype_render_style INT_MASK;
225 
228  static const xtype_render_style INT_AS_INTNN_T;
229 
234 
239 
244  static const xtype_render_style INT_AS_CSINTNN;
245 
250 
255 
260  static const xtype_render_style UNK_AS_DWORD;
261 
266  static const xtype_render_style UNK_AS_STD32;
267 
272 
277 
282 
287  static const xtype_render_style FLT_AS_DWORD;
288 
293  static const xtype_render_style FLT_AS_STD32;
294 
299 
305  static const xtype_render_style SKIP_TYPEDEF;
306 
311  static const xtype_render_style PTR_TO_ARRAY;
312 
318  static const xtype_render_style INOUT_PTRS;
319 
324 
329 
334  static const xtype_render_style STD32;
335 
340  static const xtype_render_style STDINT32;
341 
346  static const xtype_render_style BWDQ;
347  };
348  CS_FLAGS_BOILERPLATE_FRIENDS(xtype_render_style,
349  friend class xtype_to_c_decl_helper;
350  friend class project;,
352  )
353 #ifdef CS_CPP_IMPL
377 #endif
378 
387  class project{
388  project(){};
389  public:
390 
412  static void load(const std::string &file_path, bool read_only)
413  { check(cs_s_read_sdg(file_path.c_str(), read_only)); }
426  static void unload()
427  { check(cs_s_unload_sdg()); }
442  static project current()
443  {
444  static project rv;
445  if( !cs_sdg_is_loaded() )
446  check(CS_ERROR_SDG_NOT_PRESENT);
447  return rv;
448  }
449 
457  { return symbol_universe_iterator(/* iterator interface demands an argument */42); }
458 
459 
475  symbol param_symbol( size_t num ) const
476  {
477  cs_abs_loc rv;
478  check( cs_abs_loc_get_param( num, &rv ) );
479  return symbol::;
480  }
481 
482 
494  symbol lookup_symbol( const std::string &symname ) const
495  {
496  cs_abs_loc rv;
497  check(cs_abs_loc_lookup(symname.c_str(), &rv));
498  return symbol::;
499  }
500 
501 
533  symbol lookup_register_symbol( const std::string &regname ) const
534  {
535  cs_abs_loc rv;
536  check(cs_abs_loc_lookup_register(regname.c_str(), &rv));
537  return symbol::;
538  }
539 
540 
552  std::vector<interest_set> interest_sets() const
553  {
554  typedef scratchpad<interest_set> sp;
555  sp::to_vector_functor0_card<cs_get_interest_sets> functor;
556  return sp::to_vector(functor);
557  }
574  void set_interest_sets(const std::vector<interest_set> &sets)
575  {
576  size_t count = sets.size();
577  cs_string_const_pdgvs_pair *lst = new cs_string_const_pdgvs_pair[count];
578  cs_result r;
579  for( size_t i = 0; i < count; i++ )
580  {
581  lst[i].string = const_cast<char*>(sets[i].first.c_str());
582  lst[i].pdg_vertex_set = cglue<point_set>::unwrap(sets[i].second);
583  }
584  r = cs_set_interest_sets(lst, count);
585  delete[] lst;
586  check(r);
587  }
601  std::vector<std::string> interest_set_names() const
602  {
603  // This and the interest set functions below will be a
604  // little slower than necessary, but is clearer than
605  // messing with C API directly and doesn't require adding
606  // to the C API. Unlikely to be important anyway.
607  std::vector<interest_set> isets = interest_sets();
608  std::vector<std::string> iset_names(isets.size());
609  for( size_t i = 0; i < isets.size(); ++i )
610  iset_names[i] = isets[i].first;
611  return iset_names;
612  }
628  point_set get_interest_set(const std::string &setname) const
629  {
630  std::vector<interest_set> isets = interest_sets();
631  for( size_t i = 0; i < isets.size(); ++i )
632  if( isets[i].first == setname )
633  return isets[i].second;
634  check(CS_ELEMENT_NOT_PRESENT);
635  return point_set();
636  }
655  void set_interest_set(const std::string &setname,
656  const point_set &set)
657  {
658  std::vector<interest_set> isets = interest_sets();
659  bool found = false;
660  for( size_t i = 0; i < isets.size(); ++i )
661  {
662  if( isets[i].first == setname )
663  {
664  isets[i].second = set;
665  found = true;
666  break;
667  }
668  }
669  if (!found)
670  isets.push_back(interest_set(setname, set));
671  set_interest_sets(isets);
672  }
689  size_t erase_interest_set(const std::string & setname)
690  {
691  std::vector<interest_set> isets = interest_sets();
692  for( size_t i = 0; i < isets.size(); ++i )
693  {
694  if( isets[i].first == setname )
695  {
696  isets.erase(isets.begin() + i);
697  set_interest_sets(isets);
698  return 1;
699  }
700  }
701  return 0;
702  }
730  compunit lookup_compunit_handle(const std::string &compunit_handle) const
731  {
732  cs_uid rv;
733  check(cs_uid_lookup_handle(compunit_handle.c_str(), &rv));
734  return compunit::;
735  }
736 
767  procedure lookup_procedure_handle(const std::string &proc_handle) const
768  {
769  cs_pdg rv;
770  check(cs_pdg_lookup_handle(proc_handle.c_str(), &rv));
771  return procedure::;
772  }
773 
798  sfile lookup_sfile_handle(const std::string &sfile_handle) const
799  {
800  cs_sf rv;
801  check(cs_sf_lookup_handle(sfile_handle.c_str(), &rv));
802  return sfile::;
803  }
804 
835  sfileinst lookup_sfileinst_handle(const std::string &sfileinst_handle) const
836  {
837  cs_sfid rv;
838  check(cs_sfid_lookup_handle(sfileinst_handle.c_str(), &rv));
839  return sfileinst::;
840  }
841 
872  symbol lookup_symbol_handle(const std::string &symbol_handle) const
873  {
874  cs_abs_loc rv;
875  check(cs_abs_loc_lookup_handle(symbol_handle.c_str(), &rv));
876  return symbol::;
877  }
878 
908  point lookup_point_handle(const std::string &point_handle) const
909  {
910  cs_pdg_vertex rv;
911  check(cs_pdg_vertex_lookup_handle(point_handle.c_str(), &rv));
912  return point::;
913  }
914 
945  basic_block lookup_basic_block_handle(const std::string &basic_block_handle) const
946  {
947  cs_basic_block rv;
948  check(cs_basic_block_lookup_handle(basic_block_handle.c_str(), &rv));
949  return basic_block::;
950  }
969  std::string handle() const
970  {
971  return "";
972  }
973 
994  static project lookup_project_handle(const std::string &project_handle)
995  {
996  if( project_handle != "" )
997  check(CS_ELEMENT_NOT_PRESENT);
998  return current();
999  }
1000 
1001 
1019  procedure find_procedure(const std::string &procname) const
1020  {
1021  cs_pdg rv;
1022  check(cs_pdg_find(procname.c_str(), &rv));
1023  return procedure::;
1024  }
1025 
1026 
1037  procedure find_procedure(csint64 id) const
1038  {
1039  cs_pdg rv;
1040  check(cs_sdg_retrieve_pdg(id, &rv));
1041  return procedure::;
1042  }
1043 
1044 
1051  { return project_procedures_iterator(42); }
1052 
1053 
1054 
1061  std::vector<procedure> procedures_vector() const
1062  {
1063  typedef scratchpad<procedure> sp;
1064  sp::to_vector_functor0<cs_sdg_pdgs> functor;
1065  return sp::to_vector(functor);
1066  }
1067 
1068 
1082  std::vector<std::vector<procedure> > sccs() const
1083  {
1084  typedef scratchpad<std::vector<procedure> > sp;
1085  sp::to_vector_functor0_card<cs_sdg_sccs> functor;
1086  return sp::to_vector(functor);
1087  }
1102  compunit find_compunit(csuint32 id) const
1103  {
1104  cs_uid uid = id;
1105  if( !cs_uid_is_valid(uid) )
1106  check(CS_ERROR_UID_NOT_FOUND);
1107  return compunit::;
1108  }
1109 
1110 
1117  std::vector<compunit> compunits_vector() const
1118  {
1119  typedef scratchpad<compunit> sp;
1120  sp::to_vector_functor0<cs_sdg_uids> functor;
1121  return sp::to_vector(functor);
1122  }
1123 
1124 
1131  { return project_compunits_iterator(
1132  project_compunits_iterator_policy::ctype()); }
1133 
1134 
1140  project_sfiles_iterator sfiles() const
1141  { return project_sfiles_iterator(
1142  project_sfiles_iterator_policy::ctype()); }
1143 
1144 
1152  std::vector<compunit> ignored_compunits() const
1153  {
1154  typedef scratchpad<compunit> sp;
1155  sp::to_vector_functor0<cs_sdg_ignored_uids> functor;
1156  return sp::to_vector(functor);
1157  }
1158 
1159 
1167  {
1169  project_root_directories_iterator_policy::ctype());
1170  }
1172 
1177  size_t root_directory_count() const
1178  {
1179  size_t rv;
1180  check(cs_directory_root_directory_count(&rv));
1181  return rv;
1182  }
1183 
1184 
1190  std::string name() const
1191  {
1192  string_scratchpad::
1193  to_string_functor0_limit<cs_project_name>
1194  functor(-1);
1195  return string_scratchpad::to_string(functor);
1196  }
1197 
1198 
1220  std::string prj_files_directory() const
1221  {
1222  string_scratchpad::
1223  to_string_functor0_limit<cs_prj_files_directory>
1224  functor(-1);
1225  return string_scratchpad::to_string(functor);
1226  }
1227 
1228 #if 0
1229  /* This method is redundant; use [x.name() for x in p.compunits()] */
1230  private:
1231  static cs_result compilation_units_helper(
1232  const char **lst,
1233  cs_size_t capacity_bytes,
1234  cs_size_t *bytes_needed,
1235  cs_size_t *result_cardinality)
1236  {
1237  return cs_sdg_compilation_units(
1238  const_cast<char**>(lst), capacity_bytes,
1239  bytes_needed, result_cardinality);
1240  }
1241  public:
1242 
1248  std::vector<std::string> compilation_units() const
1249  {
1250  typedef scratchpad<std::string> sp;
1251  sp::to_vector_functor0_card<compilation_units_helper> functor;
1252  return sp::to_vector(functor);
1253  }
1254 #endif
1255 
1256 
1275  size_t error_count(bool including_ignored = false) const
1276  {
1277  size_t rv;
1278  check(cs_sdg_error_count(including_ignored, &rv));
1279  return rv;
1280  }
1281 
1282 
1306  size_t warning_count(bool including_ignored = false) const
1307  {
1308  size_t rv;
1309  check(cs_sdg_warning_count(including_ignored, &rv));
1310  return rv;
1311  }
1312 
1313 
1319  static bool is_loaded()
1320  { return !!cs_sdg_is_loaded(); }
1321 
1322 
1328  bool is_read_only() const
1329  { return !!cs_sdg_is_read_only(); };
1330 
1331 
1341  bool file_is_newer(const std::string &fn) const
1342  {
1343  cs_boolean rv;
1344  check(cs_sdg_file_is_newer_than_build(fn.c_str(), &rv));
1345  return !!rv;
1346  }
1347 
1348 
1370  bool has_unnormalized_c_asts() const
1371  {
1372  cs_boolean rv;
1373  check(cs_sdg_retain_unnormalized_c_ast(&rv));
1374  return !!rv;
1375  }
1376 
1377 
1406  bool incremental_capable() const
1407  {
1408  cs_boolean rv;
1409  check(cs_sdg_incremental_capable(&rv));
1410  return !!rv;
1411  }
1412 
1423  xr_query_iterator token_search(const xr_query &q) const
1424  {
1425  return xr_query_iterator(
1426  xr_query_iterator_policy_container(
1427  q));
1428  }
1429 
1435  ir_factory get_ir_factory() const
1436  { return ir_factory(); }
1440  std::string as_string() const
1441  { return name(); }
1442 
1443 
1445  std::string as_repr() const
1446  { return name(); }
1448 
1449 
1463  amc_analysis
1464  get_vsa_results() {
1465  cs_amc_analysis out;
1466  check(cs_get_vsa_results(&out));
1467  return amc_analysis::;
1468  }
1469 
1503  amc_analysis
1505  {
1506  cs_amc_analysis out;
1507  const char* (*c_fn_to_model_str)[2] = new const char*[fn_to_model_str.size() + 1][2];
1508  for (size_t i=0; i<fn_to_model_str.size(); ++i) {
1509  c_fn_to_model_str[i][0] = fn_to_model_str[i].first.c_str();
1510  c_fn_to_model_str[i][1] = fn_to_model_str[i].second.c_str();
1511  }
1512  c_fn_to_model_str[fn_to_model_str.size()][0] = NULL;
1513  c_fn_to_model_str[fn_to_model_str.size()][1] = NULL;
1514  cs_result r = cs_run_multiinterval_analysis(c_fn_to_model_str, &out);
1515  delete[] c_fn_to_model_str;
1516  check(r);
1517  return amc_analysis::;
1518  }
1519 
1520 
1544  std::string
1545  get_data_bytes_by_address(effective_address ea, size_t num_bytes) {
1546  // Quick fix for fuzzer. Better would be to be able to ask
1547  // how much is available and pin to that.
1548  if (num_bytes > (1L << 20))
1549  check(CS_ERROR_PARAMETER_TOO_LARGE);
1550  std::string out_string;
1551  out_string.resize(num_bytes);
1552  size_t bytes_read = 0;
1553 
1554  check(cs_ea_to_data_bytes(ea, &(out_string[0]), num_bytes,
1555  &bytes_read));
1556 
1557  out_string.resize(bytes_read);
1558  return out_string;
1559  }
1560 
1575  csuint8
1577  csuint8 result;
1578  check(cs_ea_to_uint8(ea, &result));
1579  return result;
1580  }
1581 
1598  csuint16
1600  csuint16 result;
1601  check(cs_ea_to_uint16(ea, &result));
1602  return result;
1603  }
1604 
1621  csuint32
1623  csuint32 result;
1624  check(cs_ea_to_uint32(ea, &result));
1625  return result;
1626  }
1627 
1644  csuint64
1646  csuint64 result;
1647  check(cs_ea_to_uint64(ea, &result));
1648  return result;
1649  }
1650 
1651 
1672  symbol_set
1674  cs_abs_loc_set set;
1675  check(cs_ea_to_abs_loc_set(ea, &set));
1676  return cglue<symbol_set>::wrap(set, false);
1677  }
1678 
1679 
1701  symbol_set
1703  cs_abs_loc_set set;
1704  check(cs_ea_to_containing_abs_loc_set(ea, &set));
1705  return cglue<symbol_set>::wrap(set, false);
1706  }
1707 
1708 
1729  point_set
1731  cs_pdg_vertex_set set;
1732  check(cs_ea_to_pdg_vertex_set(ea, &set));
1733  return cglue<point_set>::wrap(set, false);
1734  }
1735 
1736 
1760  procedure
1762  cs_pdg pdg;
1763  check(cs_ea_to_pdg(ea, &pdg));
1764  return procedure::;
1765  }
1766 
1767 
1788  ast
1790  cs_ast the_ast;
1791  check(cs_ea_to_ast(ea, &the_ast));
1792  return ast::AST;
1793  }
1794 
1795 
1824  cs_sfid s;
1825  cs_line ln;
1826  check(cs_ea_to_file_line(ea, &s, &ln));
1827  return sfileinst_line_pair(cglue<cs::sfileinst>::wrap(s), ln);
1828  }
1829 
1830 
1840  void
1841  decompiler_main(const std::vector<cs::procedure> & pdgs) const {
1842  size_t count = pdgs.size();
1843  cs_pdg *pdgs_ = new cs_pdg[count];
1844  for(size_t i=0;i<count;i++)
1845  pdgs_[i] = cglue<cs::procedure>::unwrap(pdgs[i]);
1846  cs_result r = cs_decompiler_main(count, pdgs_);
1847  delete[] pdgs_;
1848  check(r);
1849  }
1852 #ifndef SWIG
1853  private:
1854  // Wrapper for all the arguments to cs_xtype_to_c_decl.
1855  class xtype_to_c_decl_helper
1856  {
1857  public:
1858  typedef class xtype_to_c_decl_helper * ctype;
1859  xtype_to_c_decl_helper( ast & _xtype_ast,
1860  const std::string & _id,
1861  csuint32 _struct_depth,
1862  xtype_render_style _style,
1863  const std::string & _prefix,
1864  const std::string & _indent)
1865  : xtype_ast(_xtype_ast),
1866  id(_id),
1867  struct_depth(_struct_depth),
1868  style(_style),
1869  prefix(_prefix),
1870  indent(_indent) {};
1871  static cs_result xtype_to_c_decl(xtype_to_c_decl_helper * p,
1872  cs_string out_decl,
1873  size_t capacity_bytes,
1874  size_t * bytes_needed)
1875  {
1876  return cs_xtype_to_c_decl(
1877  cglue<ast>::unwrap(p->xtype_ast),
1878  p->id.c_str(),
1879  p->struct_depth,
1880  static_cast<cs_xtype_render_style>(cglue<xtype_render_style>::unwrap(p->style)),
1881  p->prefix.c_str(),
1882  p->indent.c_str(),
1883  out_decl,
1884  capacity_bytes,
1885  bytes_needed);
1886  }
1887  private:
1888  const ast & xtype_ast;
1889  const std::string & id;
1890  csuint32 struct_depth;
1891  xtype_render_style style;
1892  const std::string & prefix;
1893  const std::string & indent;
1894  };
1895 #endif /* SWIG */
1896 
1897  public:
1898 
1927  std::string
1929  ast xtype_ast,
1930  const std::string id,
1931  csuint32 struct_depth,
1932  xtype_render_style style,
1933  const std::string prefix,
1934  const std::string indent) const
1935  {
1936  xtype_to_c_decl_helper helper(xtype_ast, id, struct_depth,
1937  style, prefix, indent);
1938  string_scratchpad::
1939  to_string_functor1_limit<xtype_to_c_decl_helper,
1940  xtype_to_c_decl_helper::xtype_to_c_decl>
1941  functor(&helper, -1);
1942  return string_scratchpad::to_string(functor);
1943  }
1944 
1946  std::string blocks_as_smtlib(const std::vector<basic_block>& blocks) const
1947  {
1948 
1949  string_scratchpad::
1950  to_string_functor2_limit_no_ctype<const cs_basic_block *, cs_size_t, cs_basic_blocks_to_smt>
1951  functor(reinterpret_cast<const cs_basic_block*>(&blocks[0]), blocks.size(), -1);
1952  return string_scratchpad::to_string(functor);
1953  }
1966  int cmp(const project &other) const
1967  {
1968  return 0; /* cs::project is a singleton, at least for now. */
1969  }
1970 
1975  CS_BOILERPLATE_HASH_TYPE hash() const
1976  {
1977  return 42; /* cs::project is a singleton, at least for now. */
1978  }
1979 
1980  CS_CMP_COMPARATORS(project)
1981  };
1982  CS_IR_BOILERPLATE_FRIENDS(project)
1983 }
1984 
1985 #endif /* CS_PROJECT_HPP */
int cmp(const project &other) const
Comparison function for project, with respect to a stable overall ordering.
Definition: cs_project.hpp:1976
ast find_ast_by_address(effective_address ea) const
[Binary analyses only] Get the AST with the specified effective address.
Definition: cs_project.hpp:1799
sfile lookup_sfile_handle(const std::string &sfile_handle) const
Get a sfile from a handle.
Definition: cs_project.hpp:803
cs::project_root_directories_iterator_policy
Definition: cs_project.hpp:158
std::string handle() const
Get a handle for this project.
Definition: cs_project.hpp:974
csuint16 get_uint16_by_address(effective_address ea)
[Binary analysis only] Read an endian-correct 16 bit unsigned integer value from the specified effect...
Definition: cs_project.hpp:1609
std::string prj_files_directory() const
Get the absolute file system path for the project analysis directory (pfilesname.prj_files) for a pro...
Definition: cs_project.hpp:1225
Namespace for CodeSonar/CodeSurfer API.
Definition: cs_ast.hpp:33
static const xtype_render_style OPTION_MASK
Mask for additional rendering options.
Definition: cs_project.hpp:303
point_set find_points_by_address(effective_address ea) const
[Binary analyses only] Get the points with the specified effective address.
Definition: cs_project.hpp:1740
static const xtype_render_style INTNN_T
Combination: use intNN_t and floatNN_t styles.
Definition: cs_project.hpp:333
symbol_set find_containing_symbols_by_address(effective_address ea) const
[Binary analyses only] Get the symbols that contain the specified effective address.
Definition: cs_project.hpp:1712
std::pair< cs::sfileinst, cs::line_number > sfileinst_line_pair
A std::pair (sfi, line) where:
Definition: cs_tplt_instantiations.hpp:107
csuint8 get_uint8_by_address(effective_address ea)
[Binary analysis only] Read an 8-bit unsigned integer value from the specified effective address...
Definition: cs_project.hpp:1586
static const xtype_render_style SKIP_TYPEDEF
Use the intNN_t style for types for which none of the above formats apply (otherwise, generated "typedef" names are used).
Definition: cs_project.hpp:310
std::string get_data_bytes_by_address(effective_address ea, size_t num_bytes)
[Binary analyses only] Get the underlying data bytes for the specified effective address.
Definition: cs_project.hpp:1555
A CodeSonar or CodeSurfer project.
Definition: cs_project.hpp:392
size_t warning_count(bool including_ignored=false) const
Get the number of compiler warnings encountered in compiling the files in a project.
Definition: cs_project.hpp:1311
static const xtype_render_style UNK_AS_CSINTNN
Render unknown types as csintNN, depending on size.
Definition: cs_project.hpp:276
bool is_read_only() const
Check: is the project read-only?
Definition: cs_project.hpp:1333
A function or variable.
Definition: cs_symbol_decl.hpp:243
size_t error_count(bool including_ignored=false) const
Get the number of errors encountered in compiling the files in a project.
Definition: cs_project.hpp:1280
symbol lookup_symbol(const std::string &symname) const
Retrieve a symbol by verbose name.
Definition: cs_project.hpp:499
cs::project_compunits_iterator_policy
Definition: cs_project.hpp:114
static const xtype_render_style UNK_AS_INTNN_T
Render unknown types as intNN_t, depending on size.
Definition: cs_project.hpp:259
std
Definition: cs_ast_decl.hpp:67
A single program point.
Definition: cs_point_decl.hpp:66
project_root_directories_iterator root_directories() const
Get an iterator over the set of root directories (directory) deduced by inspecting all source file pa...
Definition: cs_project.hpp:1171
cs::project_sfiles_iterator_policy
Definition: cs_project.hpp:136
A directory.
Definition: cs_directory_decl.hpp:91
static const xtype_render_style FLT_AS_FLOATNN_T
Render floating types as floatNN_t, depending on size.
Definition: cs_project.hpp:286
std::vector< compunit > ignored_compunits() const
Get a std::vector of the compilation units that are dropped from the build.
Definition: cs_project.hpp:1157
std::string xtype_to_c_decl(ast xtype_ast, const std::string id, csuint32 struct_depth, xtype_render_style style, const std::string prefix, const std::string indent) const
[Binary analyses only] Given an ast which is an xtype abstract type, render the type as a C declarati...
Definition: cs_project.hpp:1938
static bool is_loaded()
Check: is a project currently loaded?
Definition: cs_project.hpp:1324
Iterator over all the compilation units (compunit) in a project.
Definition: cs_tplt_instantiations.hpp:864
static const xtype_render_style STDINT32
Combination: use "standard" names for integer and floating types, and convert unknown types to intege...
Definition: cs_project.hpp:345
static const xtype_render_style INT_AS_STD32
Render integer types as signed/unsigned bool/char/short/int/long long, depending on size...
Definition: cs_project.hpp:243
A single procedure/function/method.
Definition: cs_procedure_decl.hpp:173
procedure find_procedure(const std::string &procname) const
Retrieve the procedure with the specified verbose name.
Definition: cs_project.hpp:1024
static const xtype_render_style BWDQ
Combination: use byte/word/dword/qword (etc.) for all types.
Definition: cs_project.hpp:351
static const xtype_render_style SINGLE_LINE
Use a single line for the representation.
Definition: cs_project.hpp:328
sfileinst lookup_sfileinst_handle(const std::string &sfileinst_handle) const
Get a sfileinst from a handle.
Definition: cs_project.hpp:840
project_procedures_iterator procedures() const
Get an iterator over all the procedures (procedure) in a project.
Definition: cs_project.hpp:1055
static const xtype_render_style UNK_AS_DWORD
Render unknown types as byte/word/dword/qword/tbyte/oword, depending on size.
Definition: cs_project.hpp:265
point lookup_point_handle(const std::string &point_handle) const
Get a point from a handle.
Definition: cs_project.hpp:913
std::string name() const
Get the name of a project.
Definition: cs_project.hpp:1195
static const xtype_render_style FLT_MASK
Mask for floating type rendering styles.
Definition: cs_project.hpp:281
sfileinst_line_pair find_file_line_by_address(effective_address ea) const
[Binary analyses only] Get the file instance and line for the specified effective address...
Definition: cs_project.hpp:1833
symbol lookup_symbol_handle(const std::string &symbol_handle) const
Get a symbol from a handle.
Definition: cs_project.hpp:877
static const xtype_render_style INT_AS_DWORD
Render integer types as byte/word/dwod/qword/tbyte/oword, depending on size.
Definition: cs_project.hpp:238
symbol param_symbol(size_t num) const
Retrieve $param_NUM: the symbol representing the NUM&#39;th formal parameter.
Definition: cs_project.hpp:480
symbol_universe_iterator symbols() const
Get an iterator over the symbols (symbol) in a project.
Definition: cs_project.hpp:461
Flag class for selecting type rendering styles.
Definition: cs_project.hpp:188
static const xtype_render_style UNK_AS_STD32
Render unknown types as bool/char/short/int/long long, depending on size.
Definition: cs_project.hpp:271
static const xtype_render_style UNK_MASK
Mask for unknown type rendering styles.
Definition: cs_project.hpp:254
Iterator over the results (xr_tuple) of an xr_query.
Definition: cs_tplt_instantiations.hpp:1281
size_t root_directory_count() const
Get the number of root directories in the project.
Definition: cs_project.hpp:1182
csuint32 get_uint32_by_address(effective_address ea)
[Binary analysis only] Read an endian-correct 32-bit unsigned integer value from the specified effect...
Definition: cs_project.hpp:1632
std::string as_string() const
Get a simple string representation of a project object.
Definition: cs_project.hpp:1447
static const xtype_render_style INT_MASK
Mask for integer type rendering styles.
Definition: cs_project.hpp:226
project_compunits_iterator compunits() const
Get an iterator over all the compilation units (compunit) in a project.
Definition: cs_project.hpp:1135
static const xtype_render_style FLT_AS_DWORD
Render floating types as byte/word/dwod/qword/tbyte/oword, depending on size.
Definition: cs_project.hpp:292
bool file_is_newer(const std::string &fn) const
Check: is a file newer than the rest of the project?
Definition: cs_project.hpp:1346
static const xtype_render_style INT_AS_CSINTNN
Render integer types as csintNN/csuintNN, depending on size.
Definition: cs_project.hpp:249
project_sfiles_iterator sfiles() const
Get an iterator over all the source files (sfile) in a project.
Definition: cs_project.hpp:1145
amc_analysis get_vsa_results()
[Binary analyses only] Get the results of Value Set Analysis (VSA).
Definition: cs_project.hpp:1474
bool incremental_capable() const
Check: was INCREMENTAL_BUILD=Yes specified in the configuration file?
Definition: cs_project.hpp:1411
static const xtype_render_style STD32
Combination: use "standard" names for integer and floating types, and dword-style for unknown types...
Definition: cs_project.hpp:339
A source file.
Definition: cs_sfile_decl.hpp:98
The result of an API operation.
Definition: cs_result.hpp:50
std::vector< compunit > compunits_vector() const
Get the compilation units contributing to a project.
Definition: cs_project.hpp:1122
cs::project_procedures_iterator_policy
Definition: cs_project.hpp:92
static project lookup_project_handle(const std::string &project_handle)
Get a project from a handle.
Definition: cs_project.hpp:999
compunit lookup_compunit_handle(const std::string &compunit_handle) const
Get a compunit from a handle.
Definition: cs_project.hpp:735
procedure find_procedure_by_address(effective_address ea) const
[Binary analyses only] Get the procedure with the specified effective address.
Definition: cs_project.hpp:1771
std::vector< procedure > procedures_vector() const
Get the procedures defined in a project.
Definition: cs_project.hpp:1066
Fully specifies a cross-referencing query over the tokens in an analyzed project. ...
Definition: cs_xref.hpp:1158
cs::symbol_universe_iterator_policy
Definition: cs_project.hpp:70
std::string as_repr() const
Get a representation of a project object that includes information useful for debugging.
Definition: cs_project.hpp:1455
Iterator over all the procedures (procedure) in a project.
Definition: cs_tplt_instantiations.hpp:898
A source file instance.
Definition: cs_sfileinst_decl.hpp:302
std::vector< cs::string_pair > procedure_name_to_model_vector
A std::vector of string_pair, representing a map from a function name or call address to the way that fu...
Definition: cs_tplt_instantiations.hpp:546
static const xtype_render_style INT_AS_INTNN_T
Render integer types as intNN_t, depending on size.
Definition: cs_project.hpp:233
csuint64 get_uint64_by_address(effective_address ea)
[Binary analysis only] Read an endian-correct 64-bit unsigned integer value from the specified effect...
Definition: cs_project.hpp:1655
procedure lookup_procedure_handle(const std::string &proc_handle) const
Get a procedure from a handle.
Definition: cs_project.hpp:772
static const xtype_render_style FLT_AS_STD32
Render floating types as float/double/long double, depending on size.
Definition: cs_project.hpp:298
amc_analysis run_multiinterval_analysis(procedure_name_to_model_vector const &fn_to_model_str)
[Binary analyses only] Run multiinterval analysis.
Definition: cs_project.hpp:1514
Iterator over all the symbols (symbol) in a project.
Definition: cs_tplt_instantiations.hpp:1107
static project current()
Get the currently-loaded project.
Definition: cs_project.hpp:447
A compilation unit.
Definition: cs_compunit_decl.hpp:70
compunit find_compunit(csuint32 id) const
Retrieve the compilation unit with the specified unique ID.
Definition: cs_project.hpp:1107
Iterator over the set of root directories(directory) in a project (deduced by inspecting all source f...
Definition: cs_tplt_instantiations.hpp:933
symbol_set find_symbols_by_address(effective_address ea) const
[Binary analyses only] Get the symbols with the specified effective address.
Definition: cs_project.hpp:1683
static const xtype_render_style PTR_TO_ARRAY
Fully render arrays of pointers (otherwise, drop the array component).
Definition: cs_project.hpp:316
static const xtype_render_style INOUT_PTRS
Mark parameter pointer type with "_In_", "_Out", or "_Inout_" depending on whether they are input par...
Definition: cs_project.hpp:323
cs_ea effective_address
An effective address: used for binary analyses to hold the address of an entity such as a point or sy...
Definition: cs_types.hpp:392
symbol lookup_register_symbol(const std::string &regname) const
[Binary analyses only] Retrieve a register (including flag) symbol by name.
Definition: cs_project.hpp:538
bool has_unnormalized_c_asts() const
Check: was the project built to retain unnormalized C/C++ ASTs?
Definition: cs_project.hpp:1375
cs_hash_t hash() const
Hash function for project.
Definition: cs_project.hpp:1985