HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
saleae_directory.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include <string>
29 #include <vector>
30 #include <unordered_map>
31 #include <cstdint>
32 
33 // unfortunately std::filesystem::path is not available for all platforms
34 #ifdef _WIN32
35 const char folderSeparator = '\\';
36 #else
37 const char folderSeparator = '/';
38 #endif
39 
40 namespace hal
41 {
42  class SaleaeDirectory;
43 
44 #ifndef STANDALONE_PARSER
53  {
54  private:
55  SaleaeDirectory* mSaleaeDirectory;
56  SaleaeDirectoryStoreRequest(const SaleaeDirectoryStoreRequest&) {;} // disable copy constructor
57  public:
63 
68 
69  static bool sWriteDisabled;
70  };
71 #endif
72 
78  {
79  int mIndex;
80  uint64_t mBeginTime;
81  uint64_t mEndTime;
82  uint64_t mNumberValues;
83  public:
85  SaleaeDirectoryFileIndex(int inx, uint64_t tBeg=0, uint64_t tEnd=0, uint64_t nval=0)
86  : mIndex(inx), mBeginTime(tBeg), mEndTime(tEnd), mNumberValues(nval) {;}
87 
89  int index() const { return mIndex; }
90 
92  uint64_t beginTime() const { return mBeginTime; }
93 
95  uint64_t endTime() const { return mEndTime; }
96 
98  uint64_t numberValues() const { return mNumberValues; }
99  };
100 
110  {
111  friend class SaleaeDirectory;
112  public:
114  protected:
115  uint32_t mId;
116  std::string mName;
118  std::vector<SaleaeDirectoryFileIndex> mFileIndexes;
119  public:
121  SaleaeDirectoryNetEntry(const std::string nam, uint32_t id_=0, Type tp=None)
122  : mId(id_), mName(nam), mType(tp) {;}
123 
125 
127  uint32_t id() const { return mId; }
128 
130  std::string name() const { return mName; }
131 
133  Type type() const { return mType; }
134 
136  const std::vector<SaleaeDirectoryFileIndex>& indexes() const { return mFileIndexes; }
137 
139  void addIndex(const SaleaeDirectoryFileIndex& sdfe) { mFileIndexes.push_back(sdfe); }
140 
142  void rename(const std::string nam) { mName = nam; }
143 
145  int dataFileIndex() const; // TODO : time as argument
146 
148  int uniqueKey() const;
149 
150  static const int sComposedBaseKey = 1 << 16;
151  };
152 
160  {
161  friend class SaleaeDirectory;
162  private:
163  std::vector<int> mChildKeys;
164  std::vector<int> mData;
165  int mFilterEntry;
166  public:
167  SaleaeDirectoryComposedEntry(const std::string nam=std::string(), uint32_t id_=0, Type tp=None)
168  : SaleaeDirectoryNetEntry(nam,id_,tp), mFilterEntry(0) {;}
171 
173  void add_child(int key) { mChildKeys.push_back(key); }
174 
176  void remove_child(int key);
177 
179  const std::vector<int>& get_children() const {return mChildKeys; }
180 
182  const std::vector<int>& get_data() const { return mData; }
183 
185  void set_data(const std::vector<int>& dat);
186 
188  int get_filter_entry() const { return mFilterEntry; }
189 
191  void set_filter_entry(int filt) { mFilterEntry = filt; }
192 
194  bool isNull() const { return !mId || !mType; }
195 
197  void dump() const;
198  };
199 
208  {
210  public:
214  struct ListEntry
215  {
216  uint32_t id;
217  std::string name;
219  uint64_t size;
220  };
221  private:
222  std::string mDirectoryFile;
223  std::vector<SaleaeDirectoryNetEntry> mNetEntries;
224  std::unordered_map<int,SaleaeDirectoryComposedEntry> mComposedEntryMap;
225 
226  std::unordered_map<uint32_t,int> mById;
227  std::unordered_map<std::string, int> mByName;
228 
229  int getIndex(const SaleaeDirectoryNetEntry& sdnep) const;
230  int mNextAvailableIndex;
231  int mStoreRequest;
232 #ifndef STANDALONE_PARSER
233  bool write_json() const;
234 #endif
235  public:
237  SaleaeDirectory(const std::string& path, bool create=false);
238 
240  bool parse_json();
241 
244 
246  void clearAll();
247 
249  std::vector<SaleaeDirectoryNetEntry> dump() const;
250 
252  void update_file_indexes(std::unordered_map<int, SaleaeDirectoryFileIndex>& fileIndexes);
253 
255  void rename_net(uint32_t id, const std::string& nam);
256 
258  std::string get_datafile_name(int index) const;
259 
261  std::string get_datafile_path(int index) const;
262 
264  std::string get_datafile_path(const std::string& nam, uint32_t id) const;
265 
267  int get_datafile_index(const std::string& nam, uint32_t id) const;
268 
270  int get_next_available_index() const { return mNextAvailableIndex; }
271 
273  uint64_t get_max_time() const;
274 
276  std::string get_directory() const;
277 
279  std::string get_filename() const;
280 
282  std::vector<ListEntry> get_net_list() const;
283 
286 
288  void remove_composed(uint32_t id, SaleaeDirectoryNetEntry::Type tp);
289 
292 
294  std::vector<SaleaeDirectoryComposedEntry> get_composed_list() const;
295  };
296 }
The SaleaeDirectoryComposedEntry class represents a composed waveform. There are currently three type...
void add_child(int key)
Add an additional child key to composed.
SaleaeDirectoryComposedEntry(const std::string nam=std::string(), uint32_t id_=0, Type tp=None)
void dump() const
Dump to stdout.
~SaleaeDirectoryComposedEntry()
void set_data(const std::vector< int > &dat)
Setter for data list described above.
const std::vector< int > & get_data() const
Getter for data list which is used a) Boolean: list of accepted(=true) net combinations b) Trigger: t...
int get_filter_entry() const
Only used for trigger: Pointer to filter (suppress trigger unless value 1), null if no filter used.
void set_filter_entry(int filt)
Setter for filter pointer described above.
bool isNull() const
Test for null.
void remove_child(int key)
Remove child key from composed.
const std::vector< int > & get_children() const
Access to child keys.
The SaleaeDirectoryFileIndex class represents a single SALEAE data file. The class comprises the inde...
uint64_t beginTime() const
Getter for first time value in SALEAE file.
SaleaeDirectoryFileIndex(int inx, uint64_t tBeg=0, uint64_t tEnd=0, uint64_t nval=0)
Constructor.
int index() const
Getter for SALEAE data file index.
uint64_t endTime() const
Getter for last time value in SALEAE file.
uint64_t numberValues() const
Getter for number of transitions + 1 (start value)
The SaleaeDirectory class provides the API for the SALEAE directory file. The SALEAE directory file w...
void rename_net(uint32_t id, const std::string &nam)
Change waveform name entry for net identified by id.
int get_datafile_index(const std::string &nam, uint32_t id) const
Get waveform datafile index for net identified by name and id.
void clearAll()
Remove all files and reset internal variables.
void add_or_replace_net(SaleaeDirectoryNetEntry &sdne)
Add net entry if not yet existing, replace existing entry otherwise.
bool parse_json()
Parse .json file into class instance.
std::string get_directory() const
Get path to SALEAE directory without filename.
std::vector< SaleaeDirectoryNetEntry > dump() const
Dump content of class instance to console for debugging purpose.
std::string get_datafile_name(int index) const
Get waveform datafile name without path (digital_XXX.bin)
SaleaeDirectory(const std::string &path, bool create=false)
constructor
std::vector< SaleaeDirectoryComposedEntry > get_composed_list() const
Getter to list of all composed waveform entries.
void add_or_replace_composed(SaleaeDirectoryComposedEntry sdce)
Add composed waveform entry (Group, Boolean, Trigger)
int get_next_available_index() const
Getter for next available file index ('digital_XXX.bin' with lowest number XXX not in use)
void remove_composed(uint32_t id, SaleaeDirectoryNetEntry::Type tp)
Remove composed waveform entry identified by id an type.
void update_file_indexes(std::unordered_map< int, SaleaeDirectoryFileIndex > &fileIndexes)
Update file index information (like number of transitions, end time ...) after writing SALEAE files.
SaleaeDirectoryComposedEntry get_composed(uint32_t id, SaleaeDirectoryNetEntry::Type tp) const
Getter for pointer to composed waveform entry allowing modifications.
std::vector< ListEntry > get_net_list() const
Getter for all net entries.
std::string get_datafile_path(int index) const
Get full path to waveform data file.
std::string get_filename() const
Get full path to saleae directory file including filename (/.../saleae.json)
uint64_t get_max_time() const
Getter for maximum time.
The SaleaeDirectoryNetEntry class represents a regular waveform for a single simulated net....
int dataFileIndex() const
Return last data file index (currently there should be no more than one)
void rename(const std::string nam)
Rename waveform.
Type mType
Type
@ Boolean
@ Trigger
@ None
@ Group
int uniqueKey() const
Unique key as reference (used e.g. in mComposedEntryMap)
uint32_t id() const
Getter for waveform ID = simulated net ID.
virtual ~SaleaeDirectoryNetEntry()
std::string mName
const std::vector< SaleaeDirectoryFileIndex > & indexes() const
Getter for list of associated binary files indexes.
std::vector< SaleaeDirectoryFileIndex > mFileIndexes
uint32_t mId
SaleaeDirectoryNetEntry(const std::string nam, uint32_t id_=0, Type tp=None)
Constructor.
Type type() const
Getter for composed type, None for regular waveform.
static const int sComposedBaseKey
void addIndex(const SaleaeDirectoryFileIndex &sdfe)
Add index for binary file to net entry instance.
std::string name() const
Getter for waveform name.
The SaleaeDirectoryStoreRequest class is useful to bundle requests for updating SALEAE directory....
Definition: defines.h:45
const char folderSeparator
int fileIndex
uint32_t id
uint64_t size
std::string name