aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java47
1 files changed, 18 insertions, 29 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java b/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java
index 74574ecc..f07528ad 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/ContentTypeDetector.java
@@ -1,13 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
+ * This program and the accompanying materials are made available under
+ * the terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Marc R. Hoffmann - initial API and implementation
- *
+ *
*******************************************************************************/
package org.jacoco.core.internal;
@@ -15,8 +16,6 @@ import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
-import org.objectweb.asm.Opcodes;
-
/**
* Detector for content types of binary streams based on a magic headers.
*/
@@ -47,7 +46,7 @@ public class ContentTypeDetector {
* Creates a new detector based on the given input. To process the complete
* original input afterwards use the stream returned by
* {@link #getInputStream()}.
- *
+ *
* @param in
* input to read the header from
* @throws IOException
@@ -72,24 +71,14 @@ public class ContentTypeDetector {
case PACK200FILE:
return PACK200FILE;
case CLASSFILE:
- // also verify version to distinguish from Mach Object files:
- switch (readInt(in)) {
- case Opcodes.V1_1:
- case Opcodes.V1_2:
- case Opcodes.V1_3:
- case Opcodes.V1_4:
- case Opcodes.V1_5:
- case Opcodes.V1_6:
- case Opcodes.V1_7:
- case Opcodes.V1_8:
- case Opcodes.V9:
- case Opcodes.V10:
- case Opcodes.V11:
- case Opcodes.V11 | Opcodes.V_PREVIEW:
- case Opcodes.V12:
- case Opcodes.V12 | Opcodes.V_PREVIEW:
- case (Opcodes.V12 + 1):
- case (Opcodes.V12 + 1) | Opcodes.V_PREVIEW:
+ // Mach-O fat/universal binaries have the same magic header as Java
+ // class files, number of architectures is stored in unsigned 4
+ // bytes in the same place and in the same big-endian order as major
+ // and minor version of class file. Hopefully on practice number of
+ // architectures in single executable is less than 45, which is
+ // major version of Java 1.1 class files:
+ final int majorVersion = readInt(in) & 0xFFFF;
+ if (majorVersion >= 45) {
return CLASSFILE;
}
}
@@ -106,7 +95,7 @@ public class ContentTypeDetector {
/**
* Returns an input stream instance to read the complete content (including
* the header) of the underlying stream.
- *
+ *
* @return input stream containing the complete content
*/
public InputStream getInputStream() {
@@ -115,7 +104,7 @@ public class ContentTypeDetector {
/**
* Returns the detected file type.
- *
+ *
* @return file type
*/
public int getType() {