2020-04-29 18:02:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2018 Maschell
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-02-04 16:25:44 +01:00
|
|
|
#include "FunctionData.h"
|
|
|
|
#include "FunctionSymbolData.h"
|
|
|
|
#include "HookData.h"
|
|
|
|
#include "PluginMetaInformation.h"
|
|
|
|
#include "RelocationData.h"
|
|
|
|
#include "SectionInfo.h"
|
2023-11-04 15:32:45 +01:00
|
|
|
#include "utils/HeapMemoryFixedSize.h"
|
|
|
|
#include "utils/utils.h"
|
2020-04-29 18:02:36 +02:00
|
|
|
#include <map>
|
2022-02-04 16:25:44 +01:00
|
|
|
#include <memory>
|
2020-04-29 18:02:36 +02:00
|
|
|
#include <optional>
|
2022-05-14 14:00:20 +02:00
|
|
|
#include <ranges>
|
2022-02-04 16:25:44 +01:00
|
|
|
#include <set>
|
2020-04-29 18:02:36 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-12-15 17:09:30 +01:00
|
|
|
struct FunctionSymbolDataComparator {
|
2024-03-24 07:40:58 +01:00
|
|
|
bool operator()(const FunctionSymbolData &lhs,
|
|
|
|
const FunctionSymbolData &rhs) const {
|
|
|
|
return lhs < rhs;
|
2021-12-15 17:09:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-29 18:02:36 +02:00
|
|
|
class PluginInformation {
|
|
|
|
public:
|
2024-03-24 07:40:58 +01:00
|
|
|
PluginInformation(const PluginInformation &) = delete;
|
|
|
|
|
|
|
|
|
|
|
|
PluginInformation(PluginInformation &&src) : mHookDataList(std::move(src.mHookDataList)),
|
|
|
|
mFunctionDataList(std::move(src.mFunctionDataList)),
|
|
|
|
mRelocationDataList(std::move(src.mRelocationDataList)),
|
|
|
|
mSymbolDataList(std::move(src.mSymbolDataList)),
|
|
|
|
mSectionInfoList(std::move(src.mSectionInfoList)),
|
|
|
|
mTrampolineId(src.mTrampolineId),
|
|
|
|
mAllocatedTextMemoryAddress(std::move(src.mAllocatedTextMemoryAddress)),
|
|
|
|
mAllocatedDataMemoryAddress(std::move(src.mAllocatedDataMemoryAddress))
|
|
|
|
|
|
|
|
{
|
|
|
|
src.mTrampolineId = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginInformation &operator=(PluginInformation &&src) {
|
|
|
|
if (this != &src) {
|
|
|
|
this->mHookDataList = std::move(src.mHookDataList);
|
|
|
|
this->mFunctionDataList = std::move(src.mFunctionDataList);
|
|
|
|
this->mRelocationDataList = std::move(src.mRelocationDataList);
|
|
|
|
this->mSymbolDataList = std::move(src.mSymbolDataList);
|
|
|
|
this->mSectionInfoList = std::move(src.mSectionInfoList);
|
|
|
|
this->mTrampolineId = src.mTrampolineId;
|
|
|
|
this->mAllocatedTextMemoryAddress = std::move(src.mAllocatedTextMemoryAddress);
|
|
|
|
this->mAllocatedDataMemoryAddress = std::move(src.mAllocatedDataMemoryAddress);
|
|
|
|
src.mTrampolineId = {};
|
|
|
|
}
|
|
|
|
return *this;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
|
|
|
|
void addHookData(HookData hook_data) {
|
|
|
|
mHookDataList.push_back(hook_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const std::vector<HookData> &getHookDataList() const {
|
2023-11-04 15:32:45 +01:00
|
|
|
return mHookDataList;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
void addFunctionData(FunctionData function_data) {
|
2023-11-04 15:32:45 +01:00
|
|
|
mFunctionDataList.push_back(std::move(function_data));
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
[[nodiscard]] const std::vector<FunctionData> &getFunctionDataList() const {
|
2023-11-04 15:32:45 +01:00
|
|
|
return mFunctionDataList;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
[[nodiscard]] std::vector<FunctionData> &getFunctionDataList() {
|
|
|
|
return mFunctionDataList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addRelocationData(RelocationData relocation_data) {
|
2023-11-04 15:32:45 +01:00
|
|
|
mRelocationDataList.push_back(std::move(relocation_data));
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
[[nodiscard]] const std::vector<RelocationData> &getRelocationDataList() const {
|
2023-11-04 15:32:45 +01:00
|
|
|
return mRelocationDataList;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
void addFunctionSymbolData(const FunctionSymbolData &symbol_data) {
|
|
|
|
mSymbolDataList.insert(symbol_data);
|
2021-12-15 17:04:30 +01:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
void addSectionInfo(const SectionInfo §ionInfo) {
|
|
|
|
mSectionInfoList.insert(std::pair(sectionInfo.getName(), sectionInfo));
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
[[nodiscard]] const std::map<std::string, SectionInfo> &getSectionInfoList() const {
|
2023-11-04 15:32:45 +01:00
|
|
|
return mSectionInfoList;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2023-11-05 13:31:22 +01:00
|
|
|
[[nodiscard]] std::optional<SectionInfo> getSectionInfo(const std::string §ionName) const {
|
2022-05-14 14:00:20 +02:00
|
|
|
if (getSectionInfoList().contains(sectionName)) {
|
2024-03-24 07:40:58 +01:00
|
|
|
return mSectionInfoList.at(sectionName);
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
2023-11-05 13:31:22 +01:00
|
|
|
return std::nullopt;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2023-11-04 15:32:45 +01:00
|
|
|
void setTrampolineId(uint8_t trampolineId) {
|
|
|
|
this->mTrampolineId = trampolineId;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
|
|
|
|
2022-01-27 12:47:33 +01:00
|
|
|
[[nodiscard]] uint8_t getTrampolineId() const {
|
2023-11-04 15:32:45 +01:00
|
|
|
return mTrampolineId;
|
2020-04-29 18:02:36 +02:00
|
|
|
}
|
2020-05-03 12:23:50 +02:00
|
|
|
|
2024-03-24 07:40:58 +01:00
|
|
|
[[nodiscard]] const FunctionSymbolData *getNearestFunctionSymbolData(uint32_t address) const {
|
|
|
|
const FunctionSymbolData *result = nullptr;
|
2022-05-14 14:00:20 +02:00
|
|
|
|
|
|
|
bool foundHit = false;
|
2023-11-04 15:32:45 +01:00
|
|
|
for (auto &cur : mSymbolDataList) {
|
2024-03-24 07:40:58 +01:00
|
|
|
if (foundHit && address < (uint32_t) cur.getAddress()) {
|
2022-05-14 14:00:20 +02:00
|
|
|
break;
|
|
|
|
}
|
2024-03-24 07:40:58 +01:00
|
|
|
if (address >= (uint32_t) cur.getAddress()) {
|
|
|
|
result = &cur;
|
2022-05-14 14:00:20 +02:00
|
|
|
foundHit = true;
|
|
|
|
}
|
|
|
|
}
|
2023-11-05 13:31:22 +01:00
|
|
|
if (!foundHit) {
|
2023-11-27 17:45:56 +01:00
|
|
|
return nullptr;
|
2023-11-05 13:31:22 +01:00
|
|
|
}
|
2022-05-14 14:00:20 +02:00
|
|
|
|
2023-11-27 17:45:56 +01:00
|
|
|
return result;
|
2022-05-14 14:00:20 +02:00
|
|
|
}
|
|
|
|
|
2023-11-04 15:32:45 +01:00
|
|
|
[[nodiscard]] const HeapMemoryFixedSize &getTextMemory() const {
|
|
|
|
return mAllocatedTextMemoryAddress;
|
2023-02-17 17:30:28 +01:00
|
|
|
}
|
|
|
|
|
2023-11-04 15:32:45 +01:00
|
|
|
[[nodiscard]] const HeapMemoryFixedSize &getDataMemory() const {
|
|
|
|
return mAllocatedDataMemoryAddress;
|
2023-02-17 17:30:28 +01:00
|
|
|
}
|
|
|
|
|
2020-04-29 18:02:36 +02:00
|
|
|
private:
|
2024-03-24 07:40:58 +01:00
|
|
|
PluginInformation(){
|
|
|
|
|
|
|
|
}
|
|
|
|
std::vector<HookData> mHookDataList;
|
|
|
|
std::vector<FunctionData> mFunctionDataList;
|
|
|
|
std::vector<RelocationData> mRelocationDataList;
|
|
|
|
std::set<FunctionSymbolData, FunctionSymbolDataComparator> mSymbolDataList;
|
|
|
|
std::map<std::string, SectionInfo> mSectionInfoList;
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2023-11-04 15:32:45 +01:00
|
|
|
uint8_t mTrampolineId = 0;
|
2020-04-29 18:02:36 +02:00
|
|
|
|
2023-11-04 15:32:45 +01:00
|
|
|
HeapMemoryFixedSize mAllocatedTextMemoryAddress;
|
|
|
|
HeapMemoryFixedSize mAllocatedDataMemoryAddress;
|
2020-05-03 12:23:50 +02:00
|
|
|
|
2020-04-29 18:02:36 +02:00
|
|
|
friend class PluginInformationFactory;
|
|
|
|
};
|