mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Add Decompiler and Compiler tools
This commit is contained in:
parent
0da6a4dc43
commit
5db7bc2d4c
@ -98,7 +98,9 @@ group ""
|
|||||||
-- Projects
|
-- Projects
|
||||||
-- ========================
|
-- ========================
|
||||||
include "src/Common.lua"
|
include "src/Common.lua"
|
||||||
|
include "src/Compiler.lua"
|
||||||
include "src/Crypto.lua"
|
include "src/Crypto.lua"
|
||||||
|
include "src/Decompiler.lua"
|
||||||
include "src/Linker.lua"
|
include "src/Linker.lua"
|
||||||
include "src/Parser.lua"
|
include "src/Parser.lua"
|
||||||
include "src/RawTemplater.lua"
|
include "src/RawTemplater.lua"
|
||||||
@ -140,6 +142,8 @@ group ""
|
|||||||
|
|
||||||
-- Tools group: All projects that compile into the final tools
|
-- Tools group: All projects that compile into the final tools
|
||||||
group "Tools"
|
group "Tools"
|
||||||
|
Compiler:project()
|
||||||
|
Decompiler:project()
|
||||||
Linker:project()
|
Linker:project()
|
||||||
Unlinker:project()
|
Unlinker:project()
|
||||||
group ""
|
group ""
|
||||||
|
46
src/Compiler.lua
Normal file
46
src/Compiler.lua
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
Compiler = {}
|
||||||
|
|
||||||
|
function Compiler:include(includes)
|
||||||
|
if includes:handle(self:name()) then
|
||||||
|
includedirs {
|
||||||
|
path.join(ProjectFolder(), "Compiler")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Compiler:link(links)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Compiler:use()
|
||||||
|
dependson(self:name())
|
||||||
|
end
|
||||||
|
|
||||||
|
function Compiler:name()
|
||||||
|
return "Compiler"
|
||||||
|
end
|
||||||
|
|
||||||
|
function Compiler:project()
|
||||||
|
local folder = ProjectFolder()
|
||||||
|
local includes = Includes:create()
|
||||||
|
local links = Links:create()
|
||||||
|
|
||||||
|
project(self:name())
|
||||||
|
targetdir(TargetDirectoryBin)
|
||||||
|
location "%{wks.location}/src/%{prj.name}"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
language "C++"
|
||||||
|
|
||||||
|
files {
|
||||||
|
path.join(folder, "Compiler/**.h"),
|
||||||
|
path.join(folder, "Compiler/**.cpp")
|
||||||
|
}
|
||||||
|
|
||||||
|
self:include(includes)
|
||||||
|
Utils:include(includes)
|
||||||
|
|
||||||
|
Raw:use()
|
||||||
|
|
||||||
|
links:linkto(Utils)
|
||||||
|
links:linkall()
|
||||||
|
end
|
22
src/Compiler/Compiler.cpp
Normal file
22
src/Compiler/Compiler.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "Compiler.h"
|
||||||
|
|
||||||
|
#include "CompilerArgs.h"
|
||||||
|
|
||||||
|
class CompilerImpl final : public Compiler
|
||||||
|
{
|
||||||
|
CompilerArgs m_args;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool Start(const int argc, const char** argv) override
|
||||||
|
{
|
||||||
|
if (!m_args.ParseArgs(argc, argv))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<Compiler> Compiler::Create()
|
||||||
|
{
|
||||||
|
return std::make_unique<CompilerImpl>();
|
||||||
|
}
|
25
src/Compiler/Compiler.h
Normal file
25
src/Compiler/Compiler.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class Compiler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Compiler() = default;
|
||||||
|
virtual ~Compiler() = default;
|
||||||
|
|
||||||
|
Compiler(const Compiler& other) = default;
|
||||||
|
Compiler(Compiler&& other) noexcept = default;
|
||||||
|
Compiler& operator=(const Compiler& other) = default;
|
||||||
|
Compiler& operator=(Compiler&& other) noexcept = default;
|
||||||
|
|
||||||
|
static std::unique_ptr<Compiler> Create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Starts the Compiler application logic.
|
||||||
|
* \param argc The amount of command line arguments specified.
|
||||||
|
* \param argv The command line arguments.
|
||||||
|
* \return \c true if the application was successful or \c false if an error occurred.
|
||||||
|
*/
|
||||||
|
virtual bool Start(int argc, const char** argv) = 0;
|
||||||
|
};
|
68
src/Compiler/CompilerArgs.cpp
Normal file
68
src/Compiler/CompilerArgs.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "CompilerArgs.h"
|
||||||
|
|
||||||
|
#include "Utils/Arguments/UsageInformation.h"
|
||||||
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
|
const CommandLineOption* const OPTION_HELP =
|
||||||
|
CommandLineOption::Builder::Create()
|
||||||
|
.WithShortName("?")
|
||||||
|
.WithLongName("help")
|
||||||
|
.WithDescription("Displays usage information.")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
const CommandLineOption* const OPTION_VERBOSE =
|
||||||
|
CommandLineOption::Builder::Create()
|
||||||
|
.WithShortName("v")
|
||||||
|
.WithLongName("verbose")
|
||||||
|
.WithDescription("Outputs a lot more and more detailed messages.")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
const CommandLineOption* const COMMAND_LINE_OPTIONS[]
|
||||||
|
{
|
||||||
|
OPTION_HELP,
|
||||||
|
OPTION_VERBOSE
|
||||||
|
};
|
||||||
|
|
||||||
|
CompilerArgs::CompilerArgs()
|
||||||
|
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
||||||
|
m_verbose(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompilerArgs::PrintUsage()
|
||||||
|
{
|
||||||
|
UsageInformation usage("Compiler.exe");
|
||||||
|
|
||||||
|
for (const auto* commandLineOption : COMMAND_LINE_OPTIONS)
|
||||||
|
{
|
||||||
|
usage.AddCommandLineOption(commandLineOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompilerArgs::SetVerbose(const bool isVerbose)
|
||||||
|
{
|
||||||
|
m_verbose = isVerbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CompilerArgs::ParseArgs(const int argc, const char** argv)
|
||||||
|
{
|
||||||
|
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
|
||||||
|
{
|
||||||
|
PrintUsage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the user requested help
|
||||||
|
if (m_argument_parser.IsOptionSpecified(OPTION_HELP))
|
||||||
|
{
|
||||||
|
PrintUsage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -v; --verbose
|
||||||
|
SetVerbose(m_argument_parser.IsOptionSpecified(OPTION_VERBOSE));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
21
src/Compiler/CompilerArgs.h
Normal file
21
src/Compiler/CompilerArgs.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Utils/Arguments/ArgumentParser.h"
|
||||||
|
|
||||||
|
class CompilerArgs
|
||||||
|
{
|
||||||
|
ArgumentParser m_argument_parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Prints a command line usage help text for the Compiler tool to stdout.
|
||||||
|
*/
|
||||||
|
static void PrintUsage();
|
||||||
|
|
||||||
|
void SetVerbose(bool isVerbose);
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool m_verbose;
|
||||||
|
|
||||||
|
CompilerArgs();
|
||||||
|
bool ParseArgs(int argc, const char** argv);
|
||||||
|
};
|
8
src/Compiler/main.cpp
Normal file
8
src/Compiler/main.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "Compiler.h"
|
||||||
|
|
||||||
|
int main(const int argc, const char** argv)
|
||||||
|
{
|
||||||
|
const auto compiler = Compiler::Create();
|
||||||
|
|
||||||
|
return compiler->Start(argc, argv) ? 0 : 1;
|
||||||
|
}
|
46
src/Decompiler.lua
Normal file
46
src/Decompiler.lua
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
Decompiler = {}
|
||||||
|
|
||||||
|
function Decompiler:include(includes)
|
||||||
|
if includes:handle(self:name()) then
|
||||||
|
includedirs {
|
||||||
|
path.join(ProjectFolder(), "Decompiler")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Decompiler:link(links)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function Decompiler:use()
|
||||||
|
dependson(self:name())
|
||||||
|
end
|
||||||
|
|
||||||
|
function Decompiler:name()
|
||||||
|
return "Decompiler"
|
||||||
|
end
|
||||||
|
|
||||||
|
function Decompiler:project()
|
||||||
|
local folder = ProjectFolder()
|
||||||
|
local includes = Includes:create()
|
||||||
|
local links = Links:create()
|
||||||
|
|
||||||
|
project(self:name())
|
||||||
|
targetdir(TargetDirectoryBin)
|
||||||
|
location "%{wks.location}/src/%{prj.name}"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
language "C++"
|
||||||
|
|
||||||
|
files {
|
||||||
|
path.join(folder, "Decompiler/**.h"),
|
||||||
|
path.join(folder, "Decompiler/**.cpp")
|
||||||
|
}
|
||||||
|
|
||||||
|
self:include(includes)
|
||||||
|
Utils:include(includes)
|
||||||
|
|
||||||
|
Raw:use()
|
||||||
|
|
||||||
|
links:linkto(Utils)
|
||||||
|
links:linkall()
|
||||||
|
end
|
22
src/Decompiler/Decompiler.cpp
Normal file
22
src/Decompiler/Decompiler.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "Decompiler.h"
|
||||||
|
|
||||||
|
#include "DecompilerArgs.h"
|
||||||
|
|
||||||
|
class DecompilerImpl final : public Decompiler
|
||||||
|
{
|
||||||
|
DecompilerArgs m_args;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool Start(const int argc, const char** argv) override
|
||||||
|
{
|
||||||
|
if (!m_args.ParseArgs(argc, argv))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<Decompiler> Decompiler::Create()
|
||||||
|
{
|
||||||
|
return std::make_unique<DecompilerImpl>();
|
||||||
|
}
|
25
src/Decompiler/Decompiler.h
Normal file
25
src/Decompiler/Decompiler.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class Decompiler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Decompiler() = default;
|
||||||
|
virtual ~Decompiler() = default;
|
||||||
|
|
||||||
|
Decompiler(const Decompiler& other) = default;
|
||||||
|
Decompiler(Decompiler&& other) noexcept = default;
|
||||||
|
Decompiler& operator=(const Decompiler& other) = default;
|
||||||
|
Decompiler& operator=(Decompiler&& other) noexcept = default;
|
||||||
|
|
||||||
|
static std::unique_ptr<Decompiler> Create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Starts the Decompiler application logic.
|
||||||
|
* \param argc The amount of command line arguments specified.
|
||||||
|
* \param argv The command line arguments.
|
||||||
|
* \return \c true if the application was successful or \c false if an error occurred.
|
||||||
|
*/
|
||||||
|
virtual bool Start(int argc, const char** argv) = 0;
|
||||||
|
};
|
68
src/Decompiler/DecompilerArgs.cpp
Normal file
68
src/Decompiler/DecompilerArgs.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "DecompilerArgs.h"
|
||||||
|
|
||||||
|
#include "Utils/Arguments/UsageInformation.h"
|
||||||
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
|
const CommandLineOption* const OPTION_HELP =
|
||||||
|
CommandLineOption::Builder::Create()
|
||||||
|
.WithShortName("?")
|
||||||
|
.WithLongName("help")
|
||||||
|
.WithDescription("Displays usage information.")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
const CommandLineOption* const OPTION_VERBOSE =
|
||||||
|
CommandLineOption::Builder::Create()
|
||||||
|
.WithShortName("v")
|
||||||
|
.WithLongName("verbose")
|
||||||
|
.WithDescription("Outputs a lot more and more detailed messages.")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
const CommandLineOption* const COMMAND_LINE_OPTIONS[]
|
||||||
|
{
|
||||||
|
OPTION_HELP,
|
||||||
|
OPTION_VERBOSE
|
||||||
|
};
|
||||||
|
|
||||||
|
DecompilerArgs::DecompilerArgs()
|
||||||
|
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
||||||
|
m_verbose(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecompilerArgs::PrintUsage()
|
||||||
|
{
|
||||||
|
UsageInformation usage("Decompiler.exe");
|
||||||
|
|
||||||
|
for (const auto* commandLineOption : COMMAND_LINE_OPTIONS)
|
||||||
|
{
|
||||||
|
usage.AddCommandLineOption(commandLineOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
usage.Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecompilerArgs::SetVerbose(const bool isVerbose)
|
||||||
|
{
|
||||||
|
m_verbose = isVerbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DecompilerArgs::ParseArgs(const int argc, const char** argv)
|
||||||
|
{
|
||||||
|
if (!m_argument_parser.ParseArguments(argc - 1, &argv[1]))
|
||||||
|
{
|
||||||
|
PrintUsage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the user requested help
|
||||||
|
if (m_argument_parser.IsOptionSpecified(OPTION_HELP))
|
||||||
|
{
|
||||||
|
PrintUsage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -v; --verbose
|
||||||
|
SetVerbose(m_argument_parser.IsOptionSpecified(OPTION_VERBOSE));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
21
src/Decompiler/DecompilerArgs.h
Normal file
21
src/Decompiler/DecompilerArgs.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Utils/Arguments/ArgumentParser.h"
|
||||||
|
|
||||||
|
class DecompilerArgs
|
||||||
|
{
|
||||||
|
ArgumentParser m_argument_parser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Prints a command line usage help text for the Decompiler tool to stdout.
|
||||||
|
*/
|
||||||
|
static void PrintUsage();
|
||||||
|
|
||||||
|
void SetVerbose(bool isVerbose);
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool m_verbose;
|
||||||
|
|
||||||
|
DecompilerArgs();
|
||||||
|
bool ParseArgs(int argc, const char** argv);
|
||||||
|
};
|
8
src/Decompiler/main.cpp
Normal file
8
src/Decompiler/main.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "Decompiler.h"
|
||||||
|
|
||||||
|
int main(const int argc, const char** argv)
|
||||||
|
{
|
||||||
|
const auto decompiler = Decompiler::Create();
|
||||||
|
|
||||||
|
return decompiler->Start(argc, argv) ? 0 : 1;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user