Skip to content

Commit 965125b

Browse files
committed
feat: check if is valid exe
1 parent bacf755 commit 965125b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

spt_fuyu_patcher.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace build {
3131
static constexpr std::string_view kFilename = "SPT.Launcher.exe";
3232

33+
static constexpr std::string_view kExpectedProductName = "SPT.Launcher";
3334
// 要搜索的字节序列 Pattern to search for
3435
static constexpr std::array<unsigned char, 10> kPattern = {
3536
0x26, 0x15, 0x0B, 0xDE, 0x00, 0x07, 0x16, 0xFE, 0x01, 0x2A
@@ -47,7 +48,8 @@ enum class FileError {
4748
ReadError,
4849
WriteError,
4950
PatternNotFound,
50-
PatchedPatternFound
51+
PatchedPatternFound,
52+
NotExecutable
5153
};
5254

5355
std::expected<std::vector<unsigned char>, FileError>
@@ -112,6 +114,10 @@ std::expected<void, FileError> ModifyFile(const std::string& filename) {
112114
return std::unexpected(buffer.error());
113115
}
114116

117+
if (buffer->size() < 2 || (*buffer)[0] != 0x4D || (*buffer)[1] != 0x5A) {
118+
return std::unexpected(FileError::NotExecutable);
119+
}
120+
115121
auto data_span = std::span{*buffer};
116122
const auto it =
117123
std::search(std::execution::par_unseq,
@@ -212,6 +218,12 @@ int main(int argc, char* argv[]) {
212218
"You might have already patched the launcher. \n");
213219
break;
214220
}
221+
case FileError::NotExecutable: {
222+
std::cout << (isChinese
223+
? "错误: 目标文件不是有效的可执行文件 \n"
224+
: "Error: Target file is not a valid executable \n");
225+
break;
226+
}
215227
default: {
216228
std::cout << (isChinese
217229
? "错误: 未知错误发生 \n"

0 commit comments

Comments
 (0)