aboutsummaryrefslogtreecommitdiff
path: root/zenserver/frontend/frontend.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2022-03-02 10:18:20 +0100
committerMartin Ridgers <[email protected]>2022-03-15 13:45:20 +0100
commit27b351c2bac99d06f020f60fd859ecc93d4fd140 (patch)
treed6703c0c12e476ecbb7cce69263960f6dadbf6a4 /zenserver/frontend/frontend.cpp
parentFunction to find .zip appended to a IoBuffer-wrapped executable file (diff)
downloadzen-27b351c2bac99d06f020f60fd859ecc93d4fd140.tar.xz
zen-27b351c2bac99d06f020f60fd859ecc93d4fd140.zip
Implemented zip file locating for fat Mach-o binaries
Diffstat (limited to 'zenserver/frontend/frontend.cpp')
-rw-r--r--zenserver/frontend/frontend.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/zenserver/frontend/frontend.cpp b/zenserver/frontend/frontend.cpp
index 0611f068c..17614f163 100644
--- a/zenserver/frontend/frontend.cpp
+++ b/zenserver/frontend/frontend.cpp
@@ -2,6 +2,7 @@
#include "frontend.h"
+#include <zencore/endian.h>
#include <zencore/filesystem.h>
#include <zencore/string.h>
@@ -93,7 +94,38 @@ static IoBuffer FindZipFsInBinary(const IoBuffer& BinBuffer)
}
}
#elif ZEN_PLATFORM_MAC
-# error "needs to be implemented!"
+ if (Magic == 0xbebafeca)
+ {
+ struct MachInt32
+ {
+ operator uint32_t () const { return ByteSwap(Value); }
+ uint32_t Value;
+ };
+
+ struct MachFatArch
+ {
+ MachInt32 CpuType;
+ MachInt32 SubType;
+ MachInt32 Offset;
+ MachInt32 Size;
+ MachInt32 Alignment;
+ };
+
+ struct MachFatHeader
+ {
+ uint32_t Magic;
+ MachInt32 NumArchs;
+ MachFatArch Archs[];
+ };
+
+ const auto* Header = (MachFatHeader*)Cursor;
+ for (int i = 0, n = Header->NumArchs; i < n; ++i)
+ {
+ const MachFatArch* Arch = Header->Archs + i;
+ uint32_t ArchEnd = Arch->Offset + Arch->Size;
+ BinSize = (ArchEnd > BinSize) ? ArchEnd : BinSize;
+ }
+ }
#endif // win/linux/mac
if (!BinSize || BinSize > BinBuffer.GetSize())