LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ResourceAccelerator.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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#ifndef LIEF_PE_RESOURCE_ACCELERATOR_H
17#define LIEF_PE_RESOURCE_ACCELERATOR_H
18
19#include <string>
20#include <ostream>
21#include <vector>
22
23#include "LIEF/visibility.h"
24
25#include "LIEF/Object.hpp"
26
28#include "LIEF/enums.hpp"
29
30namespace LIEF {
31namespace PE {
33
34namespace details {
35struct pe_resource_acceltableentry;
36}
37
38class LIEF_API ResourceAccelerator : public Object {
39 friend class ResourcesManager;
40 public:
41 enum class FLAGS : uint32_t { VIRTKEY = 0x01,
47 NOINVERT = 0x02,
52 SHIFT = 0x04,
56 CONTROL = 0x08,
60 ALT = 0x10,
64 END = 0x80,
67 };
68
70 explicit ResourceAccelerator(const details::pe_resource_acceltableentry&);
71
72 ResourceAccelerator(const ResourceAccelerator&) = default;
73 ResourceAccelerator& operator=(const ResourceAccelerator&) = default;
74
75 ResourceAccelerator(ResourceAccelerator&&) = default;
76 ResourceAccelerator& operator=(ResourceAccelerator&&) = default;
77
78 ~ResourceAccelerator() override = default;
79
80 std::vector<FLAGS> flags_list() const;
81
82 const char* ansi_str() const {
83 return to_string((ACCELERATOR_CODES)ansi());
84 }
85 int16_t flags() const {
88 return flags_;
89 }
90 int16_t ansi() const {
94 return ansi_;
95 }
96 uint16_t id() const {
99 return id_;
100 }
101 int16_t padding() const {
105 return padding_;
106 }
107 bool has(FLAGS flag) const {
110 return (flags_ & (int16_t)flag) != 0;
111 }
112
113 ResourceAccelerator& add(FLAGS flag) {
114 flags_ |= (int16_t)flag;
115 return *this;
116 }
117
118 ResourceAccelerator& remove(FLAGS flag) {
119 flags_ &= ~(int16_t)flag;
120 return *this;
121 }
122
123 void accept(Visitor& visitor) const override;
124
125 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ResourceAccelerator& acc);
126
127 private:
128 int16_t flags_ = 0;
129 int16_t ansi_ = 0;
130 uint16_t id_ = 0;
131 int16_t padding_ = 0;
132};
133
134LIEF_API const char* to_string(ResourceAccelerator::FLAGS e);
135
136}
137}
138
139ENABLE_BITMASK_OPERATORS(LIEF::PE::ResourceAccelerator::FLAGS)
140#endif
AcceleratorCodes.hpp
Object.hpp
LIEF::PE::ResourceAccelerator
Definition ResourceAccelerator.hpp:38
LIEF::PE::ResourceAccelerator::ResourceAccelerator
ResourceAccelerator(const details::pe_resource_acceltableentry &)
LIEF::PE::ResourceAccelerator::ansi_str
const char * ansi_str() const
Definition ResourceAccelerator.hpp:82
LIEF::PE::ResourceAccelerator::ansi
int16_t ansi() const
An ANSI character value or a virtual-key code that identifies the accelerator key.
Definition ResourceAccelerator.hpp:93
LIEF::PE::ResourceAccelerator::add
ResourceAccelerator & add(FLAGS flag)
Definition ResourceAccelerator.hpp:113
LIEF::PE::ResourceAccelerator::operator=
ResourceAccelerator & operator=(ResourceAccelerator &&)=default
LIEF::PE::ResourceAccelerator::operator=
ResourceAccelerator & operator=(const ResourceAccelerator &)=default
LIEF::PE::ResourceAccelerator::remove
ResourceAccelerator & remove(FLAGS flag)
Definition ResourceAccelerator.hpp:118
LIEF::PE::ResourceAccelerator::ResourceAccelerator
ResourceAccelerator(ResourceAccelerator &&)=default
LIEF::PE::ResourceAccelerator::id
uint16_t id() const
An identifier for the keyboard accelerator.
Definition ResourceAccelerator.hpp:98
LIEF::PE::ResourceAccelerator::ResourceAccelerator
ResourceAccelerator()=default
LIEF::PE::ResourceAccelerator::flags_list
std::vector< FLAGS > flags_list() const
LIEF::PE::ResourceAccelerator::~ResourceAccelerator
~ResourceAccelerator() override=default
LIEF::PE::ResourceAccelerator::flags
int16_t flags() const
Describe the keyboard accelerator characteristics.
Definition ResourceAccelerator.hpp:87
LIEF::PE::ResourceAccelerator::FLAGS
FLAGS
From: https://docs.microsoft.com/en-us/windows/win32/menurc/acceltableentry.
Definition ResourceAccelerator.hpp:43
LIEF::PE::ResourceAccelerator::ResourceAccelerator
ResourceAccelerator(const ResourceAccelerator &)=default
LIEF::PE::ResourceAccelerator::accept
void accept(Visitor &visitor) const override
LIEF::PE::ResourceAccelerator::has
bool has(FLAGS flag) const
Whether the entry has the given flag.
Definition ResourceAccelerator.hpp:109
LIEF::PE::ResourceAccelerator::padding
int16_t padding() const
The number of bytes inserted to ensure that the structure is aligned on a DWORD boundary.
Definition ResourceAccelerator.hpp:104
LIEF::PE::ResourceAccelerator::operator<<
friend std::ostream & operator<<(std::ostream &os, const ResourceAccelerator &acc)
LIEF::PE::ResourcesManager
The Resource Manager provides an enhanced API to manipulate the resource tree.
Definition ResourcesManager.hpp:38
enums.hpp
ENABLE_BITMASK_OPERATORS
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
to_string
const char * to_string(lief_errors err)
LIEF::PE::details
Definition DataDirectory.hpp:37
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::ACCELERATOR_CODES
ACCELERATOR_CODES
From https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes.
Definition AcceleratorCodes.hpp:25
LIEF::PE::ACCELERATOR_CODES::SHIFT
@ SHIFT
Definition AcceleratorCodes.hpp:36
LIEF::PE::ACCELERATOR_CODES::CONTROL
@ CONTROL
Definition AcceleratorCodes.hpp:37
LIEF::PE::to_string
const char * to_string(AuxiliaryWeakExternal::CHARACTERISTICS e)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41