fix: Blood setup crash caused by Windows NE executable
Build & Deploy / build-and-deploy (push) Failing after 31s
Build & Deploy / build-and-deploy (push) Failing after 31s
Two bugs: 1. PlatformDetector buffer was 512 bytes — too small to read the NE header at offset 0x0E00 in Blood's SETUP.EXE. Increased to 4096 bytes (0x1000), covering headers up to ~4KB. 2. findSetup() had no platform awareness — it picked SETUP.EXE (Windows 3.x NE executable) over SETMAIN.EXE (actual DOS4GW setup). Added platform detection to the sort, preferring DOS executables over Windows ones. Also added "setmain" to pattern list so Build engine games' DOS setup utilities are detected.
This commit is contained in:
@@ -82,9 +82,9 @@ public class ExecutableDetector {
|
||||
}
|
||||
|
||||
public String findSetup(Path dir) throws IOException {
|
||||
record Candidate(int depth, long size, String path) {}
|
||||
record Candidate(int depth, boolean isWindows, long size, String path) {}
|
||||
List<Candidate> candidates = new ArrayList<>();
|
||||
List<String> patterns = List.of("setup", "install", "config", "custom");
|
||||
List<String> patterns = List.of("setup", "setmain", "install", "config", "custom");
|
||||
|
||||
Files.walkFileTree(dir, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
@@ -95,8 +95,9 @@ public class ExecutableDetector {
|
||||
return FileVisitResult.CONTINUE;
|
||||
for (String pat : patterns) {
|
||||
if (stem.equals(pat) || stem.startsWith(pat + ".") || stem.startsWith(pat + "-")) {
|
||||
boolean isWin = "windows".equals(platform.detect(f));
|
||||
candidates.add(new Candidate(
|
||||
f.getNameCount() - dir.getNameCount(), a.size(), f.toString()));
|
||||
f.getNameCount() - dir.getNameCount(), isWin, a.size(), f.toString()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -105,7 +106,10 @@ public class ExecutableDetector {
|
||||
});
|
||||
|
||||
if (candidates.isEmpty()) return null;
|
||||
candidates.sort(Comparator.comparingInt(Candidate::depth).thenComparingLong(Candidate::size));
|
||||
candidates.sort(Comparator
|
||||
.<Candidate, Integer>comparingInt(c -> c.isWindows() ? 1 : 0) // prefer DOS over Windows
|
||||
.thenComparingInt(Candidate::depth)
|
||||
.thenComparingLong(Candidate::size));
|
||||
return candidates.getFirst().path();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PlatformDetector {
|
||||
|
||||
/** Read enough PE header bytes from any InputStream (shared by Path and ZIP callers). */
|
||||
static byte[] readHeaderBytes(InputStream is) throws IOException {
|
||||
byte[] buf = new byte[0x200];
|
||||
byte[] buf = new byte[0x1000];
|
||||
int read = is.readNBytes(buf, 0, buf.length);
|
||||
return read < buf.length ? java.util.Arrays.copyOf(buf, read) : buf;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user