Skip to content

Commit 19adb81

Browse files
committed
update pinned cert and python runner
1 parent ded87bb commit 19adb81

File tree

10 files changed

+118
-57
lines changed

10 files changed

+118
-57
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ find_package(Boost REQUIRED COMPONENTS system filesystem)
2525

2626
find_package(OpenSSL REQUIRED)
2727

28+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
29+
2830
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/miniz/CMakeLists.txt")
2931
message(STATUS "Submodule 'libs/miniz' not found. Updating submodules...")
3032
execute_process(
@@ -122,6 +124,7 @@ set(LINK_COMMON
122124
OpenSSL::SSL
123125
Boost::system
124126
Boost::filesystem
127+
Python3::Python
125128
)
126129

127130
set(LINK_GUI
@@ -131,6 +134,7 @@ set(LINK_GUI
131134
set(INCLUDE_DIR
132135
${CURL_INCLUDE_DIR}
133136
${Boost_INCLUDE_DIRS}
137+
${Python3_INCLUDE_DIRS}
134138
libs/miniz
135139
libs/LIEF/include
136140
src

database/https.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def get_response(self, url, content_type):
208208
temp_cert_path = self.set_leaf(curl)
209209
curl.setopt(pycurl.SSL_VERIFYPEER, 1)
210210
curl.setopt(pycurl.SSL_VERIFYHOST, 2)
211-
pinned_key = "sha256//7WRPcNY2QpOjWiQSLbiBu/9Og69JmzccPAdfj2RT5Vw="
211+
pinned_key = "sha256//87UOkLPD3rxuss0AWbDbdDI0NPZvT6xpQHkQGxHpWE8="
212212
curl.setopt(pycurl.PINNEDPUBLICKEY, pinned_key)
213213

214214
headers_list = [

src/Controller.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ const QString Controller::getWalkthrough(int id) {
114114
return model.getWalkthrough(id);
115115
}
116116

117+
bool Controller::updateLevel(int id) {
118+
return model.updateLevel(id);
119+
}
120+
117121
bool Controller::link(int id) {
118122
return model.setLink(id);
119123
}
@@ -122,3 +126,5 @@ int Controller::getItemState(int id) {
122126
return model.getItemState(id);
123127
}
124128

129+
130+

src/Controller.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Controller : public QObject {
4242
const InfoData getInfo(int id);
4343
const QString getWalkthrough(int id);
4444
bool link(int id);
45+
bool updateLevel(int id);
4546
int getItemState(int id);
4647

4748
signals:

src/Model.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ bool Model::setupDirectories(const QString& level, const QString& game) {
2020
bool status = false;
2121
if (fileManager.setUpCamp(level, game) &&
2222
downloader.setUpCamp(level) &&
23-
data.initializeDatabase(level)) {
23+
data.initializeDatabase(level) &&
24+
m_pyRunner.setUpCamp(level.toStdString())) {
2425
status = true;
2526
}
2627
return status;
@@ -205,6 +206,10 @@ void Model::setupGame(int id) {
205206
}
206207
}
207208

209+
bool Model::updateLevel(const int id) {
210+
return m_pyRunner.updateLevel(id);
211+
}
212+
208213
bool Model::unpackLevel(const int id, const QString& name, const QString& exe) {
209214
bool status = false;
210215
const QString directory = QString("%1.TRLE").arg(id);

src/Model.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "../src/FileManager.hpp"
2828
#include "../src/Network.hpp"
2929
#include "../src/Runner.hpp"
30+
#include "../src/PyRunner.hpp"
3031

3132
class InstructionManager : public QObject {
3233
Q_OBJECT
@@ -76,6 +77,7 @@ class Model : public QObject {
7677
const QString getWalkthrough(int id);
7778
bool setupDirectories(const QString& level, const QString& game);
7879
void setup(const QString& level, const QString& game);
80+
bool updateLevel(const int id);
7981

8082
signals:
8183
void generateListSignal(QList<int> availableGames);
@@ -90,6 +92,7 @@ class Model : public QObject {
9092
bool unpackLevel(const int id, const QString& name, const QString& exe);
9193

9294
Runner m_wineRunner = Runner("/usr/bin/wine");
95+
PyRunner m_pyRunner;
9396
Data& data = Data::getInstance();
9497
FileManager& fileManager = FileManager::getInstance();
9598
Downloader& downloader = Downloader::getInstance();

src/Network.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void Downloader::connect(QFile *file, const std::string& url) {
175175
if (status == CURLE_OK) {
176176
if (url.compare(0, trle_domain.size(), trle_domain) == 0) {
177177
status = curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY,
178-
"sha256//7WRPcNY2QpOjWiQSLbiBu/9Og69JmzccPAdfj2RT5Vw=");
178+
"sha256//87UOkLPD3rxuss0AWbDbdDI0NPZvT6xpQHkQGxHpWE8=");
179179
} else if (url.compare(
180180
0, trcustoms_domain.size(), trcustoms_domain) == 0) {
181181
qDebug() << "trcustoms dont pinn key.";

src/PyRunner.cpp

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,95 @@
1111
* GNU General Public License for more details.
1212
*/
1313

14-
1514
#include "../src/PyRunner.hpp"
16-
#include <QFileInfo>
17-
18-
PyRunner::PyRunner(const QString& cwd)
19-
: m_env(QProcessEnvironment::systemEnvironment()) {
20-
m_status = 0;
21-
if (QFileInfo("/usr/bin/python3").exists()) {
22-
m_command = "/usr/bin/python3";
23-
} else if (QFileInfo("/usr/bin/python").exists()) {
24-
m_command = "/usr/bin/python";
25-
}
26-
m_process.setWorkingDirectory(cwd);
27-
m_process.setProcessEnvironment(m_env);
15+
#include <Python.h>
16+
#include <vector>
17+
#include <string>
18+
#include <iostream>
19+
#include <filesystem>
20+
#include <cstdio>
21+
22+
namespace fs = std::filesystem;
23+
24+
PyRunner::PyRunner() : m_status(0) {
25+
Py_Initialize();
26+
}
27+
28+
PyRunner::PyRunner(const std::string& cwd) : m_cwd(cwd), m_status(0) {
29+
Py_Initialize();
2830
}
2931

30-
void PyRunner::run(const QStringList& arguments) {
31-
m_process.setProgram(m_command);
32-
m_process.setArguments(arguments);
33-
qDebug() << m_command << arguments;
34-
m_process.start();
35-
36-
if (m_process.waitForStarted() == true) {
37-
m_process.waitForFinished();
38-
qDebug().noquote() << "\n"
39-
<< m_process.readAllStandardOutput();
40-
qDebug().noquote()
41-
<< m_process.readAllStandardError();
42-
qDebug().noquote() << "\nExit status :" << m_process.exitStatus();
43-
m_status = m_process.exitCode();
32+
PyRunner::~PyRunner() {
33+
Py_Finalize();
34+
}
35+
36+
bool PyRunner::setUpCamp(const std::string& level) {
37+
if (!fs::exists(level)) return false;
38+
m_cwd = level;
39+
return true;
40+
}
41+
42+
void PyRunner::run(const std::string& script,
43+
const std::vector<std::string>& args) {
44+
if (!Py_IsInitialized()) {
45+
std::cerr << "Python not initialized!" << std::endl;
46+
m_status = 1;
47+
return;
48+
}
49+
50+
std::cerr << "[PyRunner] Executing script file: " << script << std::endl;
51+
52+
// Add working dir to sys.path
53+
if (!m_cwd.empty()) {
54+
PyObject *sysPath = PySys_GetObject("path");
55+
PyObject *cwdPath = PyUnicode_FromString(m_cwd.c_str());
56+
PyList_Insert(sysPath, 0, cwdPath);
57+
Py_DECREF(cwdPath);
58+
}
59+
60+
// Set sys.argv
61+
PyObject *argvList = PyList_New(args.size());
62+
for (size_t i = 0; i < args.size(); ++i) {
63+
PyObject *arg = PyUnicode_FromString(args[i].c_str());
64+
PyList_SET_ITEM(argvList, i, arg); // steals ref
65+
}
66+
PySys_SetObject("argv", argvList);
67+
Py_DECREF(argvList);
68+
69+
std::string fullpath =
70+
m_cwd.empty() ? script : (m_cwd + "/" + script + ".py");
71+
FILE* fp = fopen(fullpath.c_str(), "r");
72+
if (!fp) {
73+
std::cerr << "[PyRunner] Failed to open script file: "
74+
<< fullpath << std::endl;
75+
m_status = 1;
76+
return;
77+
}
78+
79+
int result = PyRun_SimpleFile(fp, fullpath.c_str());
80+
fclose(fp);
81+
82+
if (result != 0) {
83+
std::cerr << "[PyRunner] Python script returned error.\n";
84+
m_status = 1;
4485
} else {
45-
qWarning() << "Failed to start python process!";
86+
std::cerr << "[PyRunner] Script executed successfully.\n";
87+
m_status = 0;
4688
}
4789
}
4890

49-
qint64 PyRunner::updateLevel(qint64 lid) {
50-
QStringList arguments;
51-
arguments << "tombll_manage_data.py" << "-u" << QString::number(lid);
52-
run(arguments);
53-
return getStatus();
91+
int64_t PyRunner::updateLevel(int64_t lid) {
92+
run("tombll_manage_data",
93+
{"tombll_manage_data.py", "-u", std::to_string(lid)});
94+
return m_status;
5495
}
5596

56-
qint64 PyRunner::syncCards(qint64 lid ) {
57-
QStringList arguments;
58-
arguments << "tombll_manage_data.py" << "-sc";
59-
run(arguments);
60-
return getStatus();
97+
int64_t PyRunner::syncCards(int64_t lid) {
98+
run("tombll_manage_data", {"tombll_manage_data.py", "-sc"});
99+
return m_status;
61100
}
62101

63-
qint64 PyRunner::getStatus() {
102+
int64_t PyRunner::getStatus() const {
64103
return m_status;
65104
}
105+

src/PyRunner.hpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,24 @@
1414
#ifndef SRC_PYRUNNER_HPP_
1515
#define SRC_PYRUNNER_HPP_
1616

17-
#include <QProcess>
18-
#include <QProcessEnvironment>
19-
#include <QDebug>
20-
21-
class PyRunner : public QObject {
22-
Q_OBJECT
17+
#include <string>
18+
#include <vector>
2319

20+
class PyRunner {
2421
public:
2522
PyRunner();
26-
explicit PyRunner(const QString& cwd);
27-
qint64 updateLevel(qint64 lid);
28-
qint64 syncCards(qint64 lid);
23+
explicit PyRunner(const std::string& cwd);
24+
~PyRunner();
25+
26+
bool setUpCamp(const std::string& level);
27+
void run(const std::string& script, const std::vector<std::string>& args);
28+
int64_t updateLevel(int64_t lid);
29+
int64_t syncCards(int64_t lid);
30+
int64_t getStatus() const;
2931

3032
private:
31-
void run(const QStringList& arguments);
32-
qint64 getStatus();
33-
QProcessEnvironment m_env;
34-
QProcess m_process;
35-
QString m_command;
36-
qint64 m_status;
33+
std::string m_cwd;
34+
int64_t m_status;
3735
};
3836

3937
#endif // SRC_PYRUNNER_HPP_

src/TombRaiderLinuxLauncher.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ void TombRaiderLinuxLauncher::infoClicked() {
373373
qint64 id = levelListModel->getLid(current);
374374
if (id != 0) {
375375
InfoData info = controller.getInfo(id);
376+
if (info.m_body == "" && info.m_imageList.size() == 0) {
377+
controller.updateLevel(id);
378+
}
379+
376380
ui->infoWebEngineView->setHtml(info.m_body);
377381

378382
// Get the vertical scrollbar size

0 commit comments

Comments
 (0)