Skip to content

Commit a58b8f2

Browse files
committed
Use LIEF to check for the appropriate exe, for launching and linking
1 parent 483a0ed commit a58b8f2

File tree

16 files changed

+512
-197
lines changed

16 files changed

+512
-197
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ This project is my passion for Tomb Raider classics combined with learning C++,
1717
## Installation
1818

1919
### Dependencies
20+
On Arch this should be enough, you get the rest probably when you install the base, curl + openssl
2021
Ensure the following are installed on your Linux desktop:
2122
- `curl` (7.71.0 or newer)
22-
- Boost
23-
- OpenSSL
24-
- Qt5
25-
On Arch this should be enough, you get the rest probably when you install the base, curl + openssl
23+
- `Boost`
24+
- `OpenSSL`
25+
- `Qt5`
2626

2727
```shell
2828
sudo pacman -S qt5-wayland qt5-webengine qt5-imageformats boost

database/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ trle.tar.gz
66
trle
77
trle.sanitized.tar.gz
88
trle.sanitized
9+
.env

database/https.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Get a request response for https only with curl"""
1+
"""Get a request response for https only with curl."""
22
import os
33
import sys
44
import time
@@ -38,8 +38,9 @@ class AcquireLock:
3838
lock (socket.socket): The TCP socket used to enforce the single instance.
3939
To protect the server from user error.
4040
"""
41+
4142
def __init__(self):
42-
# Create a TCP socket
43+
"""Set the lock, so that it don't accidentally span too many requests."""
4344
self.lock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4445
try:
4546
# Bind to localhost and a specific port
@@ -63,13 +64,15 @@ class RequestHandler:
6364
"""Handle HTTPS requests with retry and certificate handling."""
6465

6566
def __init__(self):
67+
"""Set default values."""
6668
self.misconfigured_server = False
6769
self.leaf_cert = None
6870

6971
def validate_url(self, url):
7072
"""Limit to used domains."""
7173
allowed_domains = (
7274
"https://www.trle.net/",
75+
"https://trle.net/",
7376
"https://trcustoms.org/",
7477
"https://data.trcustoms.org/"
7578
)
@@ -127,7 +130,7 @@ def validate_data_type(self, content_type):
127130
sys.exit(1)
128131

129132
def set_leaf(self, curl):
130-
"""Write the certificate to a temporary file manually"""
133+
"""Write the certificate to a temporary file manually."""
131134
if self.leaf_cert is None:
132135
raise ValueError("Leaf certificate is None and cannot be written to a file.")
133136

@@ -142,7 +145,7 @@ def set_leaf(self, curl):
142145
return temp_cert_path
143146

144147
def get_leaf(self, url):
145-
"""Check if we need to grab the first certificate"""
148+
"""Check if we need to grab the first certificate."""
146149
if not self.misconfigured_server:
147150
self.leaf_cert = get_leaf_cert.run(url)
148151
if not isinstance(self.leaf_cert, bytes):
@@ -156,15 +159,15 @@ def get_leaf(self, url):
156159
sys.exit(1)
157160

158161
def setup_before_get_response(self, url, content_type):
159-
"""validate known url and content type"""
162+
"""Validate known URL and content type."""
160163
self.validate_url(url)
161164
self.validate_data_type(content_type)
162165

163166
if url.startswith("https://www.trle.net/") and not self.misconfigured_server:
164167
self.get_leaf(url)
165168

166169
def get_response(self, url, content_type):
167-
"""Handle all https requests"""
170+
"""Handle all https requests."""
168171
self.setup_before_get_response(url, content_type)
169172

170173
if content_type == 'application/zip':
@@ -228,7 +231,7 @@ def get_response(self, url, content_type):
228231
return self.close_response(curl, headers, response_buffer, content_type)
229232

230233
def close_response(self, curl, headers, response_buffer, content_type):
231-
"""Pack response and close curl"""
234+
"""Pack response and close curl."""
232235
if curl is None:
233236
logging.error("No curl instance")
234237
sys.exit(1)
@@ -252,7 +255,7 @@ def close_response(self, curl, headers, response_buffer, content_type):
252255
sys.exit(1)
253256

254257
def pack_response_buffer(self, content_type, response_buffer):
255-
"""Validate and return the response based on content type"""
258+
"""Validate and return the response based on content type."""
256259
if content_type == 'text/html':
257260
raw_data = response_buffer.getvalue()
258261
for encoding in ['utf-8', 'windows-1252', 'utf-16', 'utf-32']:
@@ -272,8 +275,7 @@ def pack_response_buffer(self, content_type, response_buffer):
272275
return None
273276

274277
def extract_content_type(self, headers):
275-
"""Read the header lines to look for content-type"""
276-
278+
"""Read the header lines to look for content-type."""
277279
for header in headers.splitlines():
278280
if header.lower().startswith('content-type:'):
279281
return header.split(':', 1)[1].split(';')[0].strip()
@@ -282,19 +284,21 @@ def extract_content_type(self, headers):
282284

283285

284286
class Downloader:
285-
"""Zip file downloader to be used in RequestHandler"""
287+
"""Zip file downloader to be used in RequestHandler."""
288+
286289
def __init__(self):
290+
"""Set default values."""
287291
self.buffer = BytesIO()
288292
self.status = 0
289293
self.progress_bar = None
290294

291295
def write_callback(self, data):
292-
"""Callback function for writing downloaded data."""
296+
"""Write the downloaded data."""
293297
self.buffer.write(data)
294298
return len(data)
295299

296300
def progress_callback(self, total_to_download, downloaded, total_to_upload, uploaded):
297-
"""Callback function for reporting download progress.
301+
"""Report download progress.
298302
299303
Args:
300304
total_to_download (int): Total size of the file to download.
@@ -319,7 +323,7 @@ def progress_callback(self, total_to_download, downloaded, total_to_upload, uplo
319323

320324
def download_file(self, url):
321325
"""
322-
Downloads a file from the specified URL and stores its contents in a buffer.
326+
Download a file from the specified URL and stores its contents in a buffer.
323327
324328
This method utilizes the `pycurl` library to perform the download, providing
325329
a progress bar for user feedback. It handles server misconfigurations,
@@ -434,7 +438,7 @@ def download_file(self, url):
434438

435439
def get(url, content_type):
436440
"""
437-
Get server response from TRLE or Trcustom hosts
441+
Get server response from TRLE or Trcustom hosts.
438442
439443
content_type:
440444
'application/json'
@@ -454,10 +458,10 @@ def get(url, content_type):
454458

455459

456460
def release_lock():
457-
"""Release lock for this instance"""
461+
"""Release lock for this instance."""
458462
ACQUIRE_LOCK.release_lock()
459463

460464

461465
def is_locked():
462-
"""Lock this instance"""
466+
"""Lock this instance."""
463467
ACQUIRE_LOCK.is_locked()

database/ideas.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,6 @@ still the app should support rar also at some point
289289

290290
we need to support this kind of download link also
291291
https://www.trle.net/levels/levels/2020/0620/BtB
292+
293+
we have typechecking lint, so we need to install like this:
294+
pip install types-tqdm

database/setup_env.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
rm -fr .env
3+
python3 -m venv .env
4+
source .env/bin/activate
5+
pip install pycurl types-pycurl tqdm types-tqdm cryptography beautifulsoup4 pillow

fixes/raw_ps4/controller.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@
216216
ui.write(e.EV_KEY, e.KEY_ESC, 0) # Deactivate ESC
217217
ui.syn()
218218

219+
if event.code == e.BTN_MODE: # PS button
220+
if event.value == 1:
221+
ui.write(e.EV_KEY, e.KEY_P, 1) # Activate P
222+
ui.syn()
223+
else:
224+
ui.write(e.EV_KEY, e.KEY_P, 0) # Deactivate P
225+
ui.syn()
219226

220227
# This function implements an analog-to-digital conversion with angular thresholding,
221228
# where the joystick angle determines whether to send a full digital press or a pulsed key press.

libs/LIEF

Submodule LIEF updated 595 files

src/Data.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,11 @@ ZipData Data::getDownload(const int id) {
172172
ZipData result;
173173

174174
status = query.prepare(
175-
"SELECT Zip.* "
175+
"SELECT Zip.*, Info.type "
176176
"FROM Level "
177177
"JOIN ZipList ON Level.LevelID = ZipList.levelID "
178178
"JOIN Zip ON ZipList.zipID = Zip.ZipID "
179+
"JOIN Info ON Level.infoID = Info.InfoID "
179180
"WHERE Level.LevelID = :id");
180181
query.bindValue(":id", id);
181182

@@ -188,6 +189,7 @@ ZipData Data::getDownload(const int id) {
188189
query.value("Zip.md5sum").toString(),
189190
query.value("Zip.url").toString(),
190191
query.value("Zip.version").toInt(),
192+
query.value("Info.type").toInt(),
191193
query.value("Zip.release").toString());
192194
} else {
193195
qDebug() << "No results found for Level ID:" << id;

src/Data.hpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ struct FolderNames {
4848
};
4949
};
5050

51+
struct ExecutableNames {
52+
QMap<int, QString> data = {
53+
{0, "null"},
54+
{1, "tomb.exe"},
55+
{2, "Tomb2.exe"},
56+
{3, "tomb3.exe"},
57+
{4, "tomb4.exe"},
58+
{5, "PCTOMB5.EXE"},
59+
{6, "TombEngine.exe"},
60+
};
61+
};
62+
5163
struct ZipData {
5264
/**
5365
* @struct ZipData
@@ -57,15 +69,26 @@ struct ZipData {
5769
*/
5870
ZipData() {}
5971
ZipData(
60-
const QString& zipName, float zipSize, const QString& md5sum,
61-
const QString& url, int version, const QString& release) :
62-
name(zipName), megabyteSize(zipSize), md5sum(md5sum),
63-
url(url), version(version), release(release) {}
72+
const QString& zipName,
73+
float zipSize,
74+
const QString& md5sum,
75+
const QString& url,
76+
int version,
77+
int type,
78+
const QString& release) :
79+
name(zipName),
80+
megabyteSize(zipSize),
81+
md5sum(md5sum),
82+
url(url),
83+
version(version),
84+
type(type),
85+
release(release) {}
6486
QString name;
6587
float megabyteSize;
6688
QString md5sum;
6789
QString url;
6890
int version;
91+
int type;
6992
QString release;
7093
};
7194

0 commit comments

Comments
 (0)