Yun Peng | 09dd8c0 | 2017-07-21 15:57:05 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef BAZEL_SRC_TOOLS_LAUNCHER_UTIL_DATA_PARSER_H_ |
| 16 | #define BAZEL_SRC_TOOLS_LAUNCHER_UTIL_DATA_PARSER_H_ |
| 17 | |
| 18 | #include <fstream> |
| 19 | #include <memory> |
| 20 | #include <string> |
| 21 | #include <unordered_map> |
| 22 | |
| 23 | namespace bazel { |
| 24 | namespace launcher { |
| 25 | |
| 26 | class LaunchDataParser { |
| 27 | public: |
Yun Peng | 40f5a77 | 2018-06-25 05:35:50 -0700 | [diff] [blame] | 28 | typedef std::unordered_map<std::string, std::wstring> LaunchInfo; |
Yun Peng | 09dd8c0 | 2017-07-21 15:57:05 +0200 | [diff] [blame] | 29 | LaunchDataParser() = delete; |
| 30 | ~LaunchDataParser() = delete; |
Yun Peng | 40f5a77 | 2018-06-25 05:35:50 -0700 | [diff] [blame] | 31 | static bool GetLaunchInfo(const std::wstring& binary_path, |
Yun Peng | 09dd8c0 | 2017-07-21 15:57:05 +0200 | [diff] [blame] | 32 | LaunchInfo* launch_info); |
| 33 | |
| 34 | private: |
| 35 | // Read the last 64 bit from the given binary to get the data size |
| 36 | static int64_t ReadDataSize(std::ifstream* binary); |
| 37 | |
| 38 | // Read launch data at the end of the given binary into a buffer |
| 39 | static void ReadLaunchData(std::ifstream* binary, char* launch_data, |
| 40 | int64_t data_size); |
| 41 | |
| 42 | // Parse the launch data into a map |
| 43 | static bool ParseLaunchData(LaunchInfo* launch_info, const char* launch_data, |
| 44 | int64_t data_size); |
| 45 | }; |
| 46 | |
| 47 | } // namespace launcher |
| 48 | } // namespace bazel |
| 49 | |
| 50 | #endif // BAZEL_SRC_TOOLS_LAUNCHER_UTIL_DATA_PARSER_H_ |