feat: upload.

This commit is contained in:
2025-01-12 23:49:54 +08:00
parent 698b50316a
commit b57c7e30a1
13 changed files with 312 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "dumpsym"]
path = dumpsym
url = https://github.com/Redbeanw44602/dumpsym.git

1
README.md Normal file
View File

@@ -0,0 +1 @@
# DebugInfo

46
askrva/.clang-format Normal file
View File

@@ -0,0 +1,46 @@
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: Left
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: true
PadOperators: true
AlignConsecutiveMacros:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllArgumentsOnNextLine: false
AlignOperands: AlignAfterOperator
AlignConsecutiveBitFields:
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AllowShortLambdasOnASingleLine: All
AllowShortBlocksOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakTemplateDeclarations: 'Yes'
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BreakBeforeBinaryOperators: NonAssignment
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerIndentWidth: 0
IndentWidth: 4
Language: Cpp
MaxEmptyLinesToKeep: 2
PackConstructorInitializers: CurrentLine
PointerAlignment: Left
TabWidth: 4
UseTab: Never
SortIncludes: CaseSensitive

9
askrva/.gitignore vendored Normal file
View File

@@ -0,0 +1,9 @@
# VSCode
.vscode
# XMake
.xmake
build
# ClangD
.cache

1
askrva/README.md Normal file
View File

@@ -0,0 +1 @@
# cxx-project-template

97
askrva/src/main.cpp Normal file
View File

@@ -0,0 +1,97 @@
#include "pl/SymbolProvider.h"
#include <exception>
#include <fstream>
#include <print>
#include <string>
#include <argparse/argparse.hpp>
#include <nlohmann/json.hpp>
int main(int argc, char** argv) try {
argparse::ArgumentParser program("askrva");
// clang-format off
program.add_argument("path")
.help("Path to the symbol list file.")
.required();
program.add_argument("--output", "-o")
.help("Path to output.")
.required();
program.add_argument("--output-failed", "-of")
.help("Path to output failed entries.");
program.add_argument("--output-format")
.help("Specify output format.")
.choices("auto", "text", "fakepdb")
.default_value("auto");
// clang-format on
program.parse_args(argc, argv);
enum OutputFormat { Text, FakePDB } outputFormat;
std::string outputFormat_s = program.get<std::string>("--output-format");
std::string inputPath_s = program.get<std::string>("path");
std::string outputPath_s = program.get<std::string>("--output");
std::optional<std::string> outputFailedPath_s;
if (program.is_used("--output-failed")) {
outputFailedPath_s = program.get<std::string>("--output-failed");
}
if (outputFormat_s == "text") {
outputFormat = Text;
} else if (outputFormat_s == "fakepdb") {
outputFormat = FakePDB;
} else {
if (outputPath_s.ends_with(".json")) {
outputFormat = FakePDB;
} else {
outputFormat = Text;
}
}
std::ifstream input(inputPath_s);
std::string symbol;
std::ofstream output(outputPath_s);
std::ofstream output_failed;
if (outputFailedPath_s) {
output_failed.open(*outputFailedPath_s);
}
nlohmann::json json;
while (std::getline(input, symbol)) {
if (symbol.empty()) continue;
if (auto rva = reinterpret_cast<uintptr_t>(
pl::symbol_provider::pl_resolve_symbol_silent_n(symbol.data(), symbol.size())
)) {
if (outputFormat == FakePDB) {
json[symbol] = std::format("{:#x}", rva);
} else {
output << std::format("[{:#x}] {}\n", rva, symbol);
}
} else if (output_failed.is_open()) {
output_failed << symbol << "\n";
}
}
if (outputFormat == FakePDB) {
output << json.dump(4);
}
std::println("Everything is OK.");
return 0;
} catch (const std::exception& e) {
std::println("E: {}", e.what());
return -1;
}

30
askrva/xmake.lua Normal file
View File

@@ -0,0 +1,30 @@
add_rules('mode.debug', 'mode.release')
set_allowedplats('windows')
set_allowedarchs('x64')
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
-- from xmake-repo
add_requires('argparse 3.1')
add_requires('nlohmann_json 3.11.3')
-- from liteldev-repo
add_requires('preloader 1.12.0')
target('askrva')
set_kind('binary')
add_files('src/**.cpp')
add_includedirs('src')
set_warnings('all')
set_languages('c23', 'c++23')
add_packages(
'argparse',
'nlohmann_json',
'preloader'
)
if is_mode('debug') then
add_defines('DEBUG')
end

5
dethunk/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
# Python
.venv
# VSCode
.vscode

1
dethunk/README.md Normal file
View File

@@ -0,0 +1 @@
# DeThunk

0
dethunk/requirements.txt Normal file
View File

17
dethunk/ruff.toml Normal file
View File

@@ -0,0 +1,17 @@
# Same as Black.
line-length = 100
indent-width = 4
# Assume Python 3.12
target-version = "py312"
[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E", "F", "W"]
ignore = ["E501"]
[format]
# Like Black, use double quotes for strings.
quote-style = "single"

101
dethunk/src/main.py Normal file
View File

@@ -0,0 +1,101 @@
import sys
import os
def remove_thunks(path_to_file: str):
if not os.path.isfile(path_to_file):
print('invalid file.')
return
with open(path_to_file, 'r', encoding='utf-8') as file:
# states
is_modified = False
in_useless_thunk = False
in_static_variable = False
# tmp
content = ''
for line in file.readlines():
# restore static member variable thunk:
if '// static variables' in line:
in_static_variable = True
is_modified = True
if in_static_variable:
tmpline = line.strip()
if tmpline.endswith(';'):
if not tmpline.startswith('MCAPI'): # declaration may not be on one line
begin_pos = content.rfind('MCAPI')
tmpline = content[begin_pos:] + tmpline
content = content[:begin_pos]
tmpline = tmpline.strip()
# remove parameter list (convert to static variable)
call_spec_pos = tmpline.rfind('()')
if call_spec_pos == -1:
print(path_to_file)
assert False
tmpline = tmpline[:call_spec_pos] + tmpline[call_spec_pos + 2 :]
# remove reference
refsym_pos = tmpline.rfind('&') # T&
tlpsym_pos = tmpline.rfind('>') # ::std::add_lvalue_reference_t<T>
assert refsym_pos != -1 or tlpsym_pos != -1
if tlpsym_pos == -1 or refsym_pos > tlpsym_pos:
tmpline = tmpline[:refsym_pos] + tmpline[refsym_pos + 1 :]
elif refsym_pos == -1 or tlpsym_pos > refsym_pos:
# C-style arrays must have '[]' written after the variable name
tmpline = tmpline[:tlpsym_pos] + '>' + tmpline[tlpsym_pos:]
tmpline = tmpline.replace(
'::std::add_lvalue_reference_t<',
'::std::remove_reference_t<::std::add_lvalue_reference_t<',
)
content += f'\t{tmpline}\n'
continue
# remove useless thunks.
if '// NOLINTEND' in line and (in_useless_thunk or in_static_variable):
in_useless_thunk = False
in_static_variable = False
continue # don't add this line.
for token in [
'// virtual function thunks',
'// constructor thunks',
'// vftables',
'// destructor thunk',
]:
if token in line:
in_useless_thunk = True
is_modified = True
# remove previous access specifier.
content = content[: content.rfind('public:')]
content = content[: content.rfind('\n')] # for nested classes
if not in_useless_thunk:
content += line
if is_modified:
with open(path_to_file, 'w', encoding='utf-8') as wfile:
wfile.write(content)
def iterate_headers(target_path: str):
if not os.path.isdir(target_path):
print('invalid path.')
return
for root, dirs, files in os.walk(target_path):
for file in files:
remove_thunks(os.path.join(root, file))
def main():
if len(sys.argv) < 2:
print('usage: main.py <PATH>')
return
iterate_headers(sys.argv[1])
print('done.')
if __name__ == '__main__':
main()

1
dumpsym Submodule

Submodule dumpsym added at 911158677e