diff --git a/include/vpkedit/format/FPX.h b/include/vpkedit/format/FPX.h index 4b6f16fe..d7e25180 100644 --- a/include/vpkedit/format/FPX.h +++ b/include/vpkedit/format/FPX.h @@ -19,6 +19,8 @@ class FPX : public VPK { [[nodiscard]] static std::unique_ptr openInternal(const std::string& path, PackFileOptions options = {}, const Callback& callback = nullptr); private: + using VPK::generateKeyPairFiles; + using VPK::sign; using VPK::getVersion; using VPK::setVersion; diff --git a/include/vpkeditc/format/FPX.h b/include/vpkeditc/format/FPX.h index 789e8bd9..c8dbaef0 100644 --- a/include/vpkeditc/format/FPX.h +++ b/include/vpkeditc/format/FPX.h @@ -5,9 +5,3 @@ VPKEDIT_API VPKEdit_PackFileHandle_t vpkedit_fpx_open(const char* path); VPKEDIT_API VPKEdit_PackFileHandle_t vpkedit_fpx_open_with_options(const char* path, VPKEdit_PackFileOptions_t options); - -VPKEDIT_API bool vpkedit_fpx_generate_keypair_files(const char* path); - -VPKEDIT_API bool vpkedit_fpx_sign_from_file(VPKEdit_PackFileHandle_t handle, const char* filename); - -VPKEDIT_API bool vpkedit_fpx_sign_from_mem(VPKEdit_PackFileHandle_t handle, const unsigned char* privateKeyBuffer, size_t privateKeyLen, const unsigned char* publicKeyBuffer, size_t publicKeyLen); diff --git a/src/gui/Window.cpp b/src/gui/Window.cpp index 1d670c81..05c34f09 100644 --- a/src/gui/Window.cpp +++ b/src/gui/Window.cpp @@ -299,15 +299,6 @@ Window::Window(QWidget* parent) }); this->toolsGeneralMenu->setDisabled(true); - this->toolsFPXMenu = toolsMenu->addMenu(this->style()->standardIcon(QStyle::SP_FileIcon), "FPX"); - this->toolsFPXMenu->addAction(this->style()->standardIcon(QStyle::SP_FileIcon), tr("Generate Public/Private Key Files..."), [this] { - this->generateKeyPairFiles(); - }); - this->toolsFPXMenu->addAction(this->style()->standardIcon(QStyle::SP_FileIcon), tr("Sign File..."), [this] { - this->signPackFile(); - }); - this->toolsFPXMenu->setDisabled(true); - this->toolsVPKMenu = toolsMenu->addMenu(this->style()->standardIcon(QStyle::SP_FileIcon), "VPK"); this->toolsVPKMenu->addAction(this->style()->standardIcon(QStyle::SP_FileIcon), tr("Generate Public/Private Key Files..."), [this] { this->generateKeyPairFiles(); @@ -918,8 +909,7 @@ void Window::signPackFile(const QString& privateKeyLocation) { if (privateKeyPath.isEmpty()) { return; } - if ((this->packFile->getType() == PackFileType::FPX && dynamic_cast(*this->packFile).sign(privateKeyPath.toStdString())) || - (this->packFile->getType() == PackFileType::VPK && dynamic_cast(*this->packFile).sign(privateKeyPath.toStdString()))) { + if (this->packFile->getType() == PackFileType::VPK && dynamic_cast(*this->packFile).sign(privateKeyPath.toStdString())) { QMessageBox::information(this, tr("Success"), tr("Successfully signed the pack file.")); } else { QMessageBox::information(this, tr("Error"), tr("Failed to sign the pack file! Check the file contains both the private key and public key.")); @@ -1234,7 +1224,6 @@ void Window::freezeActions(bool freeze, bool freezeCreationActions) const { this->addDirAction->setDisabled(freeze); this->setPropertiesAction->setDisabled(freeze); this->toolsGeneralMenu->setDisabled(freeze); - this->toolsFPXMenu->setDisabled(freeze || (!this->packFile || this->packFile->getType() != PackFileType::FPX)); this->toolsVPKMenu->setDisabled(freeze || (!this->packFile || this->packFile->getType() != PackFileType::VPK)); this->searchBar->setDisabled(freeze); diff --git a/src/gui/Window.h b/src/gui/Window.h index e2c017f2..a1dc4300 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -133,7 +133,6 @@ class Window : public QMainWindow { QAction* addDirAction; QAction* setPropertiesAction; QMenu* toolsGeneralMenu; - QMenu* toolsFPXMenu; QMenu* toolsVPKMenu; QNetworkAccessManager* checkForNewUpdateNetworkManager; diff --git a/src/lib/format/VPK.cpp b/src/lib/format/VPK.cpp index 4b21f4f6..b697ca00 100644 --- a/src/lib/format/VPK.cpp +++ b/src/lib/format/VPK.cpp @@ -759,7 +759,7 @@ bool VPK::generateKeyPairFiles(const std::string& name) { } bool VPK::sign(const std::string& filename_) { - if (this->header1.version == 1 || !std::filesystem::exists(filename_) || std::filesystem::is_directory(filename_)) { + if (this->header1.version != 2 || !std::filesystem::exists(filename_) || std::filesystem::is_directory(filename_)) { return false; } @@ -778,7 +778,7 @@ bool VPK::sign(const std::string& filename_) { } bool VPK::sign(const std::vector& privateKey, const std::vector& publicKey) { - if (this->header1.version == 1) { + if (this->header1.version != 2) { return false; } diff --git a/src/lib/lang/c/format/FPX.cpp b/src/lib/lang/c/format/FPX.cpp index 5f066f0c..6da38aa6 100644 --- a/src/lib/lang/c/format/FPX.cpp +++ b/src/lib/lang/c/format/FPX.cpp @@ -25,36 +25,3 @@ VPKEDIT_API VPKEdit_PackFileHandle_t vpkedit_fpx_open_with_options(const char* p } return packFile.release(); } - -VPKEDIT_API bool vpkedit_fpx_generate_keypair_files(const char* path) { - VPKEDIT_EARLY_RETURN_VALUE(path, false); - - return FPX::generateKeyPairFiles(path); -} - -VPKEDIT_API bool vpkedit_fpx_sign_from_file(VPKEdit_PackFileHandle_t handle, const char* filename) { - VPKEDIT_EARLY_RETURN_VALUE(handle, false); - VPKEDIT_EARLY_RETURN_VALUE(filename, false); - - auto* fpx = ::getPackFile(handle); - if (fpx->getType() != PackFileType::FPX) { - return false; - } - return dynamic_cast(fpx)->sign(filename); -} - -VPKEDIT_API bool vpkedit_fpx_sign_from_mem(VPKEdit_PackFileHandle_t handle, const unsigned char* privateKeyBuffer, size_t privateKeyLen, const unsigned char* publicKeyBuffer, size_t publicKeyLen) { - VPKEDIT_EARLY_RETURN_VALUE(handle, false); - VPKEDIT_EARLY_RETURN_VALUE(privateKeyBuffer, false); - VPKEDIT_EARLY_RETURN_VALUE(privateKeyLen, false); - VPKEDIT_EARLY_RETURN_VALUE(publicKeyBuffer, false); - VPKEDIT_EARLY_RETURN_VALUE(publicKeyLen, false); - - auto* fpx = ::getPackFile(handle); - if (fpx->getType() != PackFileType::FPX) { - return false; - } - return dynamic_cast(fpx)->sign( - {reinterpret_cast(privateKeyBuffer), reinterpret_cast(privateKeyBuffer + privateKeyLen)}, - {reinterpret_cast(publicKeyBuffer), reinterpret_cast(publicKeyBuffer + publicKeyLen)}); -} diff --git a/src/lib/lang/csharp/libvpkedit/Format/FPX.cs b/src/lib/lang/csharp/libvpkedit/Format/FPX.cs index 2b579108..94faacb7 100644 --- a/src/lib/lang/csharp/libvpkedit/Format/FPX.cs +++ b/src/lib/lang/csharp/libvpkedit/Format/FPX.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace libvpkedit.Format { @@ -12,15 +9,6 @@ internal static unsafe partial class Extern [DllImport("libvpkeditc")] public static extern void* vpkedit_fpx_open_with_options([MarshalAs(UnmanagedType.LPStr)] string path, PackFileOptions options); - - [DllImport("libvpkeditc")] - public static extern byte vpkedit_fpx_generate_keypair_files([MarshalAs(UnmanagedType.LPStr)] string path); - - [DllImport("libvpkeditc")] - public static extern byte vpkedit_fpx_sign_from_file(void* handle, [MarshalAs(UnmanagedType.LPStr)] string filepath); - - [DllImport("libvpkeditc")] - public static extern byte vpkedit_fpx_sign_from_mem(void* handle, byte* privateKeyBuffer, ulong privateKeyLen, byte* publicKeyBuffer, ulong publicKeyLen); } public class FPX : PackFile @@ -44,51 +32,5 @@ private protected unsafe FPX(void* handle) : base(handle) {} return handle == null ? null : new FPX(handle); } } - - public static bool GenerateKeyPairFiles(string path) - { - unsafe - { - return Convert.ToBoolean(Extern.vpkedit_vpk_generate_keypair_files(path)); - } - } - - public bool Sign(string filepath) - { - unsafe - { - return Convert.ToBoolean(Extern.vpkedit_fpx_sign_from_file(Handle, filepath)); - } - } - - public bool Sign(byte[] privateKey, byte[] publicKey) - { - unsafe - { - fixed (byte* privateKeyBufferPtr = privateKey) - { - fixed (byte* publicKeyBufferPtr = publicKey) - { - return Convert.ToBoolean(Extern.vpkedit_fpx_sign_from_mem(Handle, privateKeyBufferPtr, (ulong)privateKey.LongLength, publicKeyBufferPtr, (ulong)publicKey.LongLength)); - } - } - } - } - - public bool Sign(IEnumerable privateKey, IEnumerable publicKey) - { - var privateKeyData = privateKey.ToArray(); - var publicKeyData = publicKey.ToArray(); - unsafe - { - fixed (byte* privateKeyBufferPtr = privateKeyData) - { - fixed (byte* publicKeyBufferPtr = publicKeyData) - { - return Convert.ToBoolean(Extern.vpkedit_fpx_sign_from_mem(Handle, privateKeyBufferPtr, (ulong)privateKeyData.LongLength, publicKeyBufferPtr, (ulong)publicKeyData.LongLength)); - } - } - } - } } }