From 219cfb58d9f6c69a7e609ecadb685b826b25cc06 Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Sun, 31 Dec 2006 00:24:30 +0000 Subject: [PATCH] Fix bug 166268. --- .../org/eclipse/cdt/utils/macho/MachO.java | 53 ++++++++++++++++++- .../cdt/utils/macho/parser/MachOParser.java | 2 +- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachO.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachO.java index 7e664d9570a..b7dc37ed4ed 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachO.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/MachO.java @@ -53,6 +53,7 @@ public class MachO { /* values of magic */ public final static int MH_MAGIC = 0xfeedface; /* the mach magic number */ public final static int MH_CIGAM = 0xcefaedfe; + public final static int MH_UNIVERSAL = 0xcafebabe; /* values of cputype */ public final static int CPU_TYPE_ANY = -1; @@ -167,6 +168,31 @@ public class MachO { magic = efile.readIntE(); if ( magic == MH_CIGAM ) efile.setEndian(true); + else + if ( magic == MH_UNIVERSAL) + { + String arch = System.getProperty("os.arch"); + int numArchives = efile.readIntE(); + while (numArchives-- > 0) + { + int cpuType = efile.readIntE(); + int cpuSubType = efile.readIntE(); + int archiveOffset = efile.readIntE(); + int archiveSize = efile.readIntE(); + int archiveAlignment = efile.readIntE(); + if ((cpuType == MachO.MachOhdr.CPU_TYPE_I386 && arch.equalsIgnoreCase("i386")) || + (cpuType == MachO.MachOhdr.CPU_TYPE_POWERPC && arch.equalsIgnoreCase("ppc"))) + { + efile.seek(archiveOffset); + magic = efile.readIntE(); + if ( magic == MH_CIGAM ) + efile.setEndian(true); + else if ( magic != MH_MAGIC ) + throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$ + break; + } + } + } else if ( magic != MH_MAGIC ) throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$ cputype = efile.readIntE(); @@ -183,6 +209,31 @@ public class MachO { magic = makeInt(bytes, offset, isle); offset += 4; if ( magic == MH_CIGAM ) isle = true; + else + if ( magic == MH_UNIVERSAL) + { + String arch = System.getProperty("os.arch"); + int numArchives = makeInt(bytes, offset, isle); offset += 4; + while (numArchives-- > 0) + { + int cpuType = makeInt(bytes, offset, isle); offset += 4; + int cpuSubType = makeInt(bytes, offset, isle); offset += 4; + int archiveOffset = makeInt(bytes, offset, isle); offset += 4; + int archiveSize = makeInt(bytes, offset, isle); offset += 4; + int archiveAlignment = makeInt(bytes, offset, isle); offset += 4; + if ((cpuType == MachO.MachOhdr.CPU_TYPE_I386 && arch.equalsIgnoreCase("i386")) || + (cpuType == MachO.MachOhdr.CPU_TYPE_POWERPC && arch.equalsIgnoreCase("ppc"))) + { + offset = archiveOffset; + magic = makeInt(bytes, offset, isle); offset += 4; + if ( magic == MH_CIGAM ) + isle = true; + else if ( magic != MH_MAGIC ) + throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$ + break; + } + } + } else if ( magic != MH_MAGIC ) throw new IOException(CCorePlugin.getResourceString("Util.exception.notMACHO")); //$NON-NLS-1$ cputype = makeInt(bytes, offset, isle); offset += 4; @@ -1043,7 +1094,7 @@ public class MachO { public static boolean isMachOHeader(byte[] bytes) { try { int magic = makeInt(bytes, 0, false); - return (magic == MachO.MachOhdr.MH_MAGIC || magic == MachO.MachOhdr.MH_CIGAM); + return (magic == MachO.MachOhdr.MH_MAGIC || magic == MachO.MachOhdr.MH_CIGAM || magic == MachO.MachOhdr.MH_UNIVERSAL); } catch (IOException e) { return false; } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java index b92ff945b6c..fb02d552d81 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/macho/parser/MachOParser.java @@ -47,7 +47,7 @@ public class MachOParser extends AbstractCExtension implements IBinaryParser { if (hints != null && hints.length > 0) { try { attribute = MachO.getAttributes(hints); - } catch (EOFException eof) { + } catch (IOException eof) { // continue, the array was to small. } }