feat: support makepdb format.

This commit is contained in:
2025-01-20 00:44:40 +08:00
parent 235afe9b9b
commit a66f97714b
3 changed files with 51 additions and 1 deletions

View File

@@ -17,7 +17,8 @@ known as magicblob), PreLoader no longer handles PDB. The source code in the cur
- Just execute `xmake` to complete the build.
### Usage
- --output-format can be `auto` / `txt` / `fakepdb`
- --output-format can be `auto` / `txt` / `fakepdb` / `makepdb`
```
Usage: askrva [--help] [--version] --output VAR [--output-failed VAR] [--output-format VAR] path

View File

@@ -0,0 +1,33 @@
#include "format/output/makepdb.h"
#include <nlohmann/json.hpp>
namespace format::output {
void OutputMakePDBFile::record(std::string_view symbol, uint64_t rva, bool is_function) {
m_records.emplace(std::string(symbol), rva, is_function);
}
void OutputMakePDBFile::save(std::string_view path) const {
std::ofstream ofs(path.data());
if (!ofs) {
throw std::runtime_error("Failed to open save file.");
}
nlohmann::json data;
// MakePDB - Format V1
data["version"] = 1;
for (const auto& [symbol, rva, is_fun] : m_records) {
data["data"].emplace_back(nlohmann::json{
{"symbol", symbol},
{"rva", rva },
{"is_function", is_fun}
});
}
ofs << data.dump(4);
}
} // namespace format::output

View File

@@ -0,0 +1,16 @@
#pragma once
#include "format/output/all.h"
namespace format::output {
class OutputMakePDBFile : public DefaultOutputFile {
public:
void record(std::string_view symbol, uint64_t rva, bool is_function) override;
void save(std::string_view path) const override;
private:
std::unordered_set<std::tuple<std::string, uint64_t, bool>> m_records;
};
} // namespace format::output