LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
PE/utils.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
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 LIEF_PE_UTILS_H
16#define LIEF_PE_UTILS_H
17#include <string_view>
18#include <string>
19#include <vector>
20
21#include "LIEF/PE/enums.hpp"
22#include "LIEF/errors.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
26class BinaryStream;
27
28namespace PE {
29class Binary;
30class Import;
31
33enum class IMPHASH_MODE {
36
39
42
45
46};
47
50
52LIEF_API bool is_pe(std::string_view file);
53
55LIEF_API bool is_pe(const std::vector<uint8_t>& raw);
56
58LIEF_API result<PE_TYPE> get_type(std::string_view file);
59
61LIEF_API result<PE_TYPE> get_type(const std::vector<uint8_t>& raw);
62
63// In this case we assume that stream contains a valid PE stream
65
81LIEF_API std::string get_imphash(const Binary& binary,
83
98LIEF_API result<Import> resolve_ordinals(const Import& import, bool strict = false,
99 bool use_std = false);
100
101LIEF_API ALGORITHMS algo_from_oid(std::string_view oid);
102
105LIEF_API bool check_layout(const Binary& bin, std::string* error_info = nullptr);
106
107}
108}
109#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:58
Class that represents a PE import.
Definition Import.hpp:40
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:78
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
ALGORITHMS
Cryptography algorithms.
Definition PE/enums.hpp:28
result< PE_TYPE > get_type_from_stream(BinaryStream &stream)
ALGORITHMS algo_from_oid(std::string_view oid)
std::string get_imphash(const Binary &binary, IMPHASH_MODE mode=IMPHASH_MODE::DEFAULT)
Compute the hash of imported functions.
bool check_layout(const Binary &bin, std::string *error_info=nullptr)
Check that the layout of the given Binary is correct from the Windows loader perspective.
result< Import > resolve_ordinals(const Import &import, bool strict=false, bool use_std=false)
Take a PE::Import as entry and try to resolve imports by ordinal.
result< PE_TYPE > get_type(std::string_view file)
if the input file is a PE one, return PE32 or PE32+
bool is_pe(BinaryStream &stream)
Check if the given stream wraps a PE binary.
IMPHASH_MODE
Enum to define the behavior of LIEF::PE::get_imphash.
Definition PE/utils.hpp:33
@ VT
Same as IMPHASH_MODE::PEFILE since Virus Total is using pefile.
Definition PE/utils.hpp:44
@ DEFAULT
Default implementation.
Definition PE/utils.hpp:35
@ PEFILE
Use pefile algorithm.
Definition PE/utils.hpp:41
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:44
#define LIEF_LOCAL
Definition visibility.h:45