-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
SignatureDB.h
87 lines (67 loc) · 2.19 KB
/
SignatureDB.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <map>
#include <memory>
#include <string>
#include "Common/CommonTypes.h"
// You're not meant to keep around SignatureDB objects persistently. Use 'em, throw them away.
class PPCSymbolDB;
class SignatureDBFormatHandler;
class SignatureDB
{
public:
enum class HandlerType
{
DSY,
CSV,
MEGA
};
explicit SignatureDB(HandlerType handler);
explicit SignatureDB(const std::string& file_path);
void Clear();
// Does not clear. Remember to clear first if that's what you want.
bool Load(const std::string& file_path);
bool Save(const std::string& file_path) const;
void List() const;
void Populate(const PPCSymbolDB* func_db, const std::string& filter = "");
void Apply(PPCSymbolDB* func_db) const;
bool Add(u32 start_addr, u32 size, const std::string& name);
private:
std::unique_ptr<SignatureDBFormatHandler> m_handler;
};
class SignatureDBFormatHandler
{
public:
virtual ~SignatureDBFormatHandler();
virtual void Clear() = 0;
virtual bool Load(const std::string& file_path) = 0;
virtual bool Save(const std::string& file_path) const = 0;
virtual void List() const = 0;
virtual void Populate(const PPCSymbolDB* func_db, const std::string& filter = "") = 0;
virtual void Apply(PPCSymbolDB* func_db) const = 0;
virtual bool Add(u32 startAddr, u32 size, const std::string& name) = 0;
};
class HashSignatureDB : public SignatureDBFormatHandler
{
public:
struct DBFunc
{
u32 size = 0;
std::string name;
std::string object_name;
std::string object_location;
};
using FuncDB = std::map<u32, DBFunc>;
static u32 ComputeCodeChecksum(u32 offsetStart, u32 offsetEnd);
void Clear() override;
void List() const override;
void Populate(const PPCSymbolDB* func_db, const std::string& filter = "") override;
void Apply(PPCSymbolDB* func_db) const override;
bool Add(u32 startAddr, u32 size, const std::string& name) override;
protected:
// Map from signature to function. We store the DB in this map because it optimizes the
// most common operation - lookup. We don't care about ordering anyway.
FuncDB m_database;
};