|
| 1 | +/* Copyright 2017 R. Thomas |
| 2 | + * Copyright 2017 Quarkslab |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#include "pyPE.hpp" |
| 17 | + |
| 18 | +#include "LIEF/visitors/Hash.hpp" |
| 19 | +#include "LIEF/PE/LoadConfigurations.hpp" |
| 20 | + |
| 21 | +#include <string> |
| 22 | +#include <sstream> |
| 23 | + |
| 24 | +template<class T> |
| 25 | +using getter_t = T (LoadConfiguration::*)(void) const; |
| 26 | + |
| 27 | +template<class T> |
| 28 | +using setter_t = void (LoadConfiguration::*)(T); |
| 29 | + |
| 30 | +void init_PE_LoadConfiguration_class(py::module& m) { |
| 31 | + py::class_<LoadConfiguration>(m, "LoadConfiguration", |
| 32 | + "Class modeling the default PE's ``LoadConfiguration``\n\n" |
| 33 | + "It's the base class for any future version of the structure" |
| 34 | + ) |
| 35 | + .def(py::init<>()) |
| 36 | + |
| 37 | + .def_property_readonly("version", |
| 38 | + &LoadConfiguration::version, |
| 39 | + "(SDK) Version of the structure. (" RST_CLASS_REF(lief.PE.WIN_VERSION) ")") |
| 40 | + |
| 41 | + .def_property("characteristics", |
| 42 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::characteristics), |
| 43 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::characteristics), |
| 44 | + "Characteristics of the structure.") |
| 45 | + |
| 46 | + .def_property("timedatestamp", |
| 47 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::timedatestamp), |
| 48 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::timedatestamp), |
| 49 | + "Date and time stamp value") |
| 50 | + |
| 51 | + .def_property("major_version", |
| 52 | + static_cast<getter_t<uint16_t>>(&LoadConfiguration::major_version), |
| 53 | + static_cast<setter_t<uint16_t>>(&LoadConfiguration::major_version), |
| 54 | + "Major Version") |
| 55 | + |
| 56 | + .def_property("minor_version", |
| 57 | + static_cast<getter_t<uint16_t>>(&LoadConfiguration::minor_version), |
| 58 | + static_cast<setter_t<uint16_t>>(&LoadConfiguration::minor_version), |
| 59 | + "Minor version") |
| 60 | + |
| 61 | + .def_property("global_flags_clear", |
| 62 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::global_flags_clear), |
| 63 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::global_flags_clear), |
| 64 | + "The global loader flags to clear for this process as the loader start the process.") |
| 65 | + |
| 66 | + .def_property("global_flags_set", |
| 67 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::global_flags_set), |
| 68 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::global_flags_set), |
| 69 | + "The global loader flags to set for this process as the loader starts the process.") |
| 70 | + |
| 71 | + .def_property("critical_section_default_timeout", |
| 72 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::critical_section_default_timeout), |
| 73 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::critical_section_default_timeout), |
| 74 | + "The default timeout value to use for is process’s critical sections that are abandoned.") |
| 75 | + |
| 76 | + .def_property("decommit_free_block_threshold", |
| 77 | + static_cast<getter_t<uint64_t>>(&LoadConfiguration::decommit_free_block_threshold), |
| 78 | + static_cast<setter_t<uint64_t>>(&LoadConfiguration::decommit_free_block_threshold), |
| 79 | + "Memory that must be freed before it is returned to the system, in bytes.") |
| 80 | + |
| 81 | + .def_property("decommit_total_free_threshold", |
| 82 | + static_cast<getter_t<uint64_t>>(&LoadConfiguration::decommit_total_free_threshold), |
| 83 | + static_cast<setter_t<uint64_t>>(&LoadConfiguration::decommit_total_free_threshold), |
| 84 | + "Total amount of free memory, in bytes") |
| 85 | + |
| 86 | + .def_property("lock_prefix_table", |
| 87 | + static_cast<getter_t<uint64_t>>(&LoadConfiguration::lock_prefix_table), |
| 88 | + static_cast<setter_t<uint64_t>>(&LoadConfiguration::lock_prefix_table), |
| 89 | + "The **VA** of a list of addresses where the ``LOCK`` prefix " |
| 90 | + "is used so that they can be replaced with ``NOP`` on single processor machines.") |
| 91 | + |
| 92 | + .def_property("maximum_allocation_size", |
| 93 | + static_cast<getter_t<uint64_t>>(&LoadConfiguration::maximum_allocation_size), |
| 94 | + static_cast<setter_t<uint64_t>>(&LoadConfiguration::maximum_allocation_size), |
| 95 | + "Maximum allocation size, in bytes.") |
| 96 | + |
| 97 | + .def_property("virtual_memory_threshold", |
| 98 | + static_cast<getter_t<uint64_t>>(&LoadConfiguration::virtual_memory_threshold), |
| 99 | + static_cast<setter_t<uint64_t>>(&LoadConfiguration::virtual_memory_threshold), |
| 100 | + "Maximum virtual memory size, in bytes.") |
| 101 | + |
| 102 | + .def_property("process_affinity_mask", |
| 103 | + static_cast<getter_t<uint64_t>>(&LoadConfiguration::process_affinity_mask), |
| 104 | + static_cast<setter_t<uint64_t>>(&LoadConfiguration::process_affinity_mask), |
| 105 | + "Setting this field to a non-zero value is equivalent to calling " |
| 106 | + "``SetProcessAffinityMask`` with this value during process startup (.exe only)") |
| 107 | + |
| 108 | + .def_property("process_heap_flags", |
| 109 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::process_heap_flags), |
| 110 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::process_heap_flags), |
| 111 | + "Process heap flags that correspond to the first argument of the " |
| 112 | + "``HeapCreate`` function. These flags apply to the process heap that is " |
| 113 | + "created during process startup.") |
| 114 | + |
| 115 | + .def_property("csd_version", |
| 116 | + static_cast<getter_t<uint16_t>>(&LoadConfiguration::csd_version), |
| 117 | + static_cast<setter_t<uint16_t>>(&LoadConfiguration::csd_version), |
| 118 | + "The service pack version identifier.") |
| 119 | + |
| 120 | + .def_property("reserved1", |
| 121 | + static_cast<getter_t<uint16_t>>(&LoadConfiguration::reserved1), |
| 122 | + static_cast<setter_t<uint16_t>>(&LoadConfiguration::reserved1), |
| 123 | + "Must be zero.") |
| 124 | + |
| 125 | + .def_property("editlist", |
| 126 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::editlist), |
| 127 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::editlist), |
| 128 | + "Reserved for use by the system.") |
| 129 | + |
| 130 | + .def_property("security_cookie", |
| 131 | + static_cast<getter_t<uint32_t>>(&LoadConfiguration::security_cookie), |
| 132 | + static_cast<setter_t<uint32_t>>(&LoadConfiguration::security_cookie), |
| 133 | + "A pointer to a cookie that is used by Visual C++ or GS implementation.") |
| 134 | + |
| 135 | + .def("__eq__", &LoadConfiguration::operator==) |
| 136 | + .def("__ne__", &LoadConfiguration::operator!=) |
| 137 | + .def("__hash__", |
| 138 | + [] (const LoadConfiguration& config) { |
| 139 | + return LIEF::Hash::hash(config); |
| 140 | + }) |
| 141 | + |
| 142 | + |
| 143 | + .def("__str__", [] (const LoadConfiguration& config) |
| 144 | + { |
| 145 | + std::ostringstream stream; |
| 146 | + stream << config; |
| 147 | + std::string str = stream.str(); |
| 148 | + return str; |
| 149 | + }); |
| 150 | + |
| 151 | + |
| 152 | +} |
0 commit comments