Skip to content

Commit 6ca847b

Browse files
fix(lib,gui): forgot FPX files can't be signed
1 parent bfca8b4 commit 6ca847b

File tree

7 files changed

+6
-113
lines changed

7 files changed

+6
-113
lines changed

include/vpkedit/format/FPX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class FPX : public VPK {
1919
[[nodiscard]] static std::unique_ptr<PackFile> openInternal(const std::string& path, PackFileOptions options = {}, const Callback& callback = nullptr);
2020

2121
private:
22+
using VPK::generateKeyPairFiles;
23+
using VPK::sign;
2224
using VPK::getVersion;
2325
using VPK::setVersion;
2426

include/vpkeditc/format/FPX.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,3 @@
55
VPKEDIT_API VPKEdit_PackFileHandle_t vpkedit_fpx_open(const char* path);
66

77
VPKEDIT_API VPKEdit_PackFileHandle_t vpkedit_fpx_open_with_options(const char* path, VPKEdit_PackFileOptions_t options);
8-
9-
VPKEDIT_API bool vpkedit_fpx_generate_keypair_files(const char* path);
10-
11-
VPKEDIT_API bool vpkedit_fpx_sign_from_file(VPKEdit_PackFileHandle_t handle, const char* filename);
12-
13-
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);

src/gui/Window.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,6 @@ Window::Window(QWidget* parent)
299299
});
300300
this->toolsGeneralMenu->setDisabled(true);
301301

302-
this->toolsFPXMenu = toolsMenu->addMenu(this->style()->standardIcon(QStyle::SP_FileIcon), "FPX");
303-
this->toolsFPXMenu->addAction(this->style()->standardIcon(QStyle::SP_FileIcon), tr("Generate Public/Private Key Files..."), [this] {
304-
this->generateKeyPairFiles();
305-
});
306-
this->toolsFPXMenu->addAction(this->style()->standardIcon(QStyle::SP_FileIcon), tr("Sign File..."), [this] {
307-
this->signPackFile();
308-
});
309-
this->toolsFPXMenu->setDisabled(true);
310-
311302
this->toolsVPKMenu = toolsMenu->addMenu(this->style()->standardIcon(QStyle::SP_FileIcon), "VPK");
312303
this->toolsVPKMenu->addAction(this->style()->standardIcon(QStyle::SP_FileIcon), tr("Generate Public/Private Key Files..."), [this] {
313304
this->generateKeyPairFiles();
@@ -918,8 +909,7 @@ void Window::signPackFile(const QString& privateKeyLocation) {
918909
if (privateKeyPath.isEmpty()) {
919910
return;
920911
}
921-
if ((this->packFile->getType() == PackFileType::FPX && dynamic_cast<FPX&>(*this->packFile).sign(privateKeyPath.toStdString())) ||
922-
(this->packFile->getType() == PackFileType::VPK && dynamic_cast<VPK&>(*this->packFile).sign(privateKeyPath.toStdString()))) {
912+
if (this->packFile->getType() == PackFileType::VPK && dynamic_cast<VPK&>(*this->packFile).sign(privateKeyPath.toStdString())) {
923913
QMessageBox::information(this, tr("Success"), tr("Successfully signed the pack file."));
924914
} else {
925915
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 {
12341224
this->addDirAction->setDisabled(freeze);
12351225
this->setPropertiesAction->setDisabled(freeze);
12361226
this->toolsGeneralMenu->setDisabled(freeze);
1237-
this->toolsFPXMenu->setDisabled(freeze || (!this->packFile || this->packFile->getType() != PackFileType::FPX));
12381227
this->toolsVPKMenu->setDisabled(freeze || (!this->packFile || this->packFile->getType() != PackFileType::VPK));
12391228

12401229
this->searchBar->setDisabled(freeze);

src/gui/Window.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ class Window : public QMainWindow {
133133
QAction* addDirAction;
134134
QAction* setPropertiesAction;
135135
QMenu* toolsGeneralMenu;
136-
QMenu* toolsFPXMenu;
137136
QMenu* toolsVPKMenu;
138137

139138
QNetworkAccessManager* checkForNewUpdateNetworkManager;

src/lib/format/VPK.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ bool VPK::generateKeyPairFiles(const std::string& name) {
759759
}
760760

761761
bool VPK::sign(const std::string& filename_) {
762-
if (this->header1.version == 1 || !std::filesystem::exists(filename_) || std::filesystem::is_directory(filename_)) {
762+
if (this->header1.version != 2 || !std::filesystem::exists(filename_) || std::filesystem::is_directory(filename_)) {
763763
return false;
764764
}
765765

@@ -778,7 +778,7 @@ bool VPK::sign(const std::string& filename_) {
778778
}
779779

780780
bool VPK::sign(const std::vector<std::byte>& privateKey, const std::vector<std::byte>& publicKey) {
781-
if (this->header1.version == 1) {
781+
if (this->header1.version != 2) {
782782
return false;
783783
}
784784

src/lib/lang/c/format/FPX.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,3 @@ VPKEDIT_API VPKEdit_PackFileHandle_t vpkedit_fpx_open_with_options(const char* p
2525
}
2626
return packFile.release();
2727
}
28-
29-
VPKEDIT_API bool vpkedit_fpx_generate_keypair_files(const char* path) {
30-
VPKEDIT_EARLY_RETURN_VALUE(path, false);
31-
32-
return FPX::generateKeyPairFiles(path);
33-
}
34-
35-
VPKEDIT_API bool vpkedit_fpx_sign_from_file(VPKEdit_PackFileHandle_t handle, const char* filename) {
36-
VPKEDIT_EARLY_RETURN_VALUE(handle, false);
37-
VPKEDIT_EARLY_RETURN_VALUE(filename, false);
38-
39-
auto* fpx = ::getPackFile(handle);
40-
if (fpx->getType() != PackFileType::FPX) {
41-
return false;
42-
}
43-
return dynamic_cast<FPX*>(fpx)->sign(filename);
44-
}
45-
46-
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) {
47-
VPKEDIT_EARLY_RETURN_VALUE(handle, false);
48-
VPKEDIT_EARLY_RETURN_VALUE(privateKeyBuffer, false);
49-
VPKEDIT_EARLY_RETURN_VALUE(privateKeyLen, false);
50-
VPKEDIT_EARLY_RETURN_VALUE(publicKeyBuffer, false);
51-
VPKEDIT_EARLY_RETURN_VALUE(publicKeyLen, false);
52-
53-
auto* fpx = ::getPackFile(handle);
54-
if (fpx->getType() != PackFileType::FPX) {
55-
return false;
56-
}
57-
return dynamic_cast<FPX*>(fpx)->sign(
58-
{reinterpret_cast<const std::byte*>(privateKeyBuffer), reinterpret_cast<const std::byte*>(privateKeyBuffer + privateKeyLen)},
59-
{reinterpret_cast<const std::byte*>(publicKeyBuffer), reinterpret_cast<const std::byte*>(publicKeyBuffer + publicKeyLen)});
60-
}
Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
52

63
namespace libvpkedit.Format
74
{
@@ -12,15 +9,6 @@ internal static unsafe partial class Extern
129

1310
[DllImport("libvpkeditc")]
1411
public static extern void* vpkedit_fpx_open_with_options([MarshalAs(UnmanagedType.LPStr)] string path, PackFileOptions options);
15-
16-
[DllImport("libvpkeditc")]
17-
public static extern byte vpkedit_fpx_generate_keypair_files([MarshalAs(UnmanagedType.LPStr)] string path);
18-
19-
[DllImport("libvpkeditc")]
20-
public static extern byte vpkedit_fpx_sign_from_file(void* handle, [MarshalAs(UnmanagedType.LPStr)] string filepath);
21-
22-
[DllImport("libvpkeditc")]
23-
public static extern byte vpkedit_fpx_sign_from_mem(void* handle, byte* privateKeyBuffer, ulong privateKeyLen, byte* publicKeyBuffer, ulong publicKeyLen);
2412
}
2513

2614
public class FPX : PackFile
@@ -44,51 +32,5 @@ private protected unsafe FPX(void* handle) : base(handle) {}
4432
return handle == null ? null : new FPX(handle);
4533
}
4634
}
47-
48-
public static bool GenerateKeyPairFiles(string path)
49-
{
50-
unsafe
51-
{
52-
return Convert.ToBoolean(Extern.vpkedit_vpk_generate_keypair_files(path));
53-
}
54-
}
55-
56-
public bool Sign(string filepath)
57-
{
58-
unsafe
59-
{
60-
return Convert.ToBoolean(Extern.vpkedit_fpx_sign_from_file(Handle, filepath));
61-
}
62-
}
63-
64-
public bool Sign(byte[] privateKey, byte[] publicKey)
65-
{
66-
unsafe
67-
{
68-
fixed (byte* privateKeyBufferPtr = privateKey)
69-
{
70-
fixed (byte* publicKeyBufferPtr = publicKey)
71-
{
72-
return Convert.ToBoolean(Extern.vpkedit_fpx_sign_from_mem(Handle, privateKeyBufferPtr, (ulong)privateKey.LongLength, publicKeyBufferPtr, (ulong)publicKey.LongLength));
73-
}
74-
}
75-
}
76-
}
77-
78-
public bool Sign(IEnumerable<byte> privateKey, IEnumerable<byte> publicKey)
79-
{
80-
var privateKeyData = privateKey.ToArray();
81-
var publicKeyData = publicKey.ToArray();
82-
unsafe
83-
{
84-
fixed (byte* privateKeyBufferPtr = privateKeyData)
85-
{
86-
fixed (byte* publicKeyBufferPtr = publicKeyData)
87-
{
88-
return Convert.ToBoolean(Extern.vpkedit_fpx_sign_from_mem(Handle, privateKeyBufferPtr, (ulong)privateKeyData.LongLength, publicKeyBufferPtr, (ulong)publicKeyData.LongLength));
89-
}
90-
}
91-
}
92-
}
9335
}
9436
}

0 commit comments

Comments
 (0)