diff -Nru libjna-java-4.5.0/ant-elfanalyser-src/com/sun/jna/BuildArmSoftFloatDetector.java libjna-java-4.5.1/ant-elfanalyser-src/com/sun/jna/BuildArmSoftFloatDetector.java --- libjna-java-4.5.0/ant-elfanalyser-src/com/sun/jna/BuildArmSoftFloatDetector.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/ant-elfanalyser-src/com/sun/jna/BuildArmSoftFloatDetector.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,53 +0,0 @@ - -package com.sun.jna; - -import java.io.File; -import java.io.IOException; -import org.apache.tools.ant.Project; - -/** - * Ant task to expose the arm soft-/hardfloat detection routines of the JNA core - * for the build script. - * - *

The build script is expected to build a minimal set of classes that are - * required to execute this. At the time of writing these are:

- * - * - */ -public class BuildArmSoftFloatDetector { - - private String targetProperty; - private Project project; - - public void setProject(Project proj) { - project = proj; - } - - /** - * targetProperty receives the name of the property, that should take the - * new property - * - * @param targetProperty - */ - public void setTargetProperty(String targetProperty) { - this.targetProperty = targetProperty; - } - - public void execute() throws IOException { - boolean result = false; - // On linux /proc/self/exe is a symblink to the currently executing - // binary (the JVM) - File self = new File("/proc/self/exe"); - try { - // The self.getCanonicalPath() resolves the symblink to the backing - // realfile and passes that to the detection routines - ELFAnalyser ahfd = ELFAnalyser.analyse(self.getCanonicalPath()); - result = ahfd.isArmSoftFloat(); - } catch (IOException ex) { - result = false; - } - project.setNewProperty(targetProperty, Boolean.toString(result)); - } -} diff -Nru libjna-java-4.5.0/ant-tools-src/com/sun/jna/BuildArmSoftFloatDetector.java libjna-java-4.5.1/ant-tools-src/com/sun/jna/BuildArmSoftFloatDetector.java --- libjna-java-4.5.0/ant-tools-src/com/sun/jna/BuildArmSoftFloatDetector.java 1970-01-01 00:00:00.000000000 +0000 +++ libjna-java-4.5.1/ant-tools-src/com/sun/jna/BuildArmSoftFloatDetector.java 2017-12-27 19:27:16.000000000 +0000 @@ -0,0 +1,69 @@ +/* Copyright (c) 2016 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ + +package com.sun.jna; + +import java.io.File; +import java.io.IOException; +import org.apache.tools.ant.Project; + +/** + * Ant task to expose the arm soft-/hardfloat detection routines of the JNA core + * for the build script. + */ +public class BuildArmSoftFloatDetector { + + private String targetProperty; + private Project project; + + public void setProject(Project proj) { + project = proj; + } + + /** + * targetProperty receives the name of the property, that should take the + * new property + * + * @param targetProperty + */ + public void setTargetProperty(String targetProperty) { + this.targetProperty = targetProperty; + } + + public void execute() throws IOException { + boolean result = false; + // On linux /proc/self/exe is a symblink to the currently executing + // binary (the JVM) + File self = new File("/proc/self/exe"); + try { + // The self.getCanonicalPath() resolves the symblink to the backing + // realfile and passes that to the detection routines + ELFAnalyser ahfd = ELFAnalyser.analyse(self.getCanonicalPath()); + result = ahfd.isArmSoftFloat(); + } catch (IOException ex) { + result = false; + } + project.setNewProperty(targetProperty, Boolean.toString(result)); + } +} diff -Nru libjna-java-4.5.0/ant-tools-src/com/sun/jna/CalcAndroidVersion.java libjna-java-4.5.1/ant-tools-src/com/sun/jna/CalcAndroidVersion.java --- libjna-java-4.5.0/ant-tools-src/com/sun/jna/CalcAndroidVersion.java 1970-01-01 00:00:00.000000000 +0000 +++ libjna-java-4.5.1/ant-tools-src/com/sun/jna/CalcAndroidVersion.java 2017-12-27 19:27:16.000000000 +0000 @@ -0,0 +1,102 @@ +/* Copyright (c) 2017 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ + +package com.sun.jna; + +import java.io.IOException; +import org.apache.tools.ant.Project; + +/** + * Calculate the androidVersion code based on the major, minor, patchlevel. + * + *

This is inspired by the AndroidGradleExample implemented here: + * + * https://github.com/jayway/AndroidGradleExample/blob/master/versioning.gradle + * + *

+ * + *

The androidVersion is calculated from the major/minor/revision/buildNumber + * quarted as:

+ * + *
+ * androidVersion = 1000000 * major
+ *                +   10000 * minor
+ *                +     100 * revision
+ *                + (isRelease) ? 99 : 0
+ * 
+ */ +public class CalcAndroidVersion { + + private String targetProperty; + private Integer major; + private Integer minor; + private Integer revision; + private String releaseProperty; + private Project project; + + public void setProject(Project proj) { + project = proj; + } + + /** + * targetProperty receives the name of the property, that should take the + * new property + * + * @param targetProperty + */ + public void setTargetProperty(String targetProperty) { + this.targetProperty = targetProperty; + } + + public void setMajor(Integer major) { + this.major = major; + } + + public void setMinor(Integer minor) { + this.minor = minor; + } + + public void setRevision(Integer revision) { + this.revision = revision; + } + + /** + * Name of property, that is set, if a release is done + * + * @param releaseProperty + */ + public void setReleaseProperty(String releaseProperty) { + this.releaseProperty = releaseProperty; + } + + public void execute() throws IOException { + int androidVersion = 1000000 * major + + 10000 * minor + + 100 * revision; + if(project.getProperties().containsKey(releaseProperty)) { + androidVersion += 99; + } + project.setNewProperty(targetProperty, Integer.toString(androidVersion)); + } +} diff -Nru libjna-java-4.5.0/ant-tools-src/com/sun/jna/package-info.java libjna-java-4.5.1/ant-tools-src/com/sun/jna/package-info.java --- libjna-java-4.5.0/ant-tools-src/com/sun/jna/package-info.java 1970-01-01 00:00:00.000000000 +0000 +++ libjna-java-4.5.1/ant-tools-src/com/sun/jna/package-info.java 2017-12-27 19:27:16.000000000 +0000 @@ -0,0 +1,10 @@ +/** + *

The build script is expected to build a minimal set of classes that are + * required to execute this. At the time of writing these are:

+ * + * + */ +package com.sun.jna; diff -Nru libjna-java-4.5.0/build.xml libjna-java-4.5.1/build.xml --- libjna-java-4.5.0/build.xml 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/build.xml 2017-12-27 19:27:16.000000000 +0000 @@ -54,11 +54,10 @@ value="Copyright &copy; 2007-${year} Timothy Wall. All Rights Reserved."/> - - + @@ -128,6 +127,7 @@ + @@ -136,8 +136,26 @@ - + + + + + + + + + + + + + @@ -204,29 +222,21 @@ - + - - - - - - - - - + - + @@ -311,7 +321,7 @@ - + diff -Nru libjna-java-4.5.0/CHANGES.md libjna-java-4.5.1/CHANGES.md --- libjna-java-4.5.0/CHANGES.md 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/CHANGES.md 2017-12-27 19:27:16.000000000 +0000 @@ -2,6 +2,22 @@ NOTE: JNI native support is typically incompatible between minor versions, and almost always incompatible between major versions. +Release 4.5.1 +============= + +Features +-------- + +Bug Fixes +--------- +* [#863](https://github.com/java-native-access/jna/pull/863): Fix ARM softfloat/hardfloat detection by modifying armSoftFloat condition in ELFAnalyser. Before this fix a softfloat binary could be misdetected as hardfloat. - [@kunkun26](https://github.com/kunkun26). +* [#867](https://github.com/java-native-access/jna/issues/867): Fix memory leak in `COMLateBindingObject#getStringProperty` - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#871](https://github.com/java-native-access/jna/issues/871): Fix mapping of libc function `gethostname`, `sethostname`, `getdomainname` and `setdomainname` and bind `com.sun.jna.platform.win32.Winsock2.gethostname(byte[], int)` - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#876](https://github.com/java-native-access/jna/pull/876): Restore java 6 compatibility - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#882](https://github.com/java-native-access/jna/pull/882): Correctly close file in `ELFAnalyser#runDetection`, fix suggested by [@Sylvyrfysh](https://github.com/Sylvyrfysh) in [#880](https://github.com/java-native-access/jna/pull/880) - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#887](https://github.com/java-native-access/jna/issues/887): MacFileUtils.moveToTrash() doesn't work in a sandboxed app fix suggested by [@sobakasu](https://github.com/sobakasu) - [@matthiasblaesing](https://github.com/matthiasblaesing). +* [#894](https://github.com/java-native-access/jna/issues/894): NullPointerException can be caused by calling `com.sun.jna.platform.win32.COM.util.ProxyObject#dispose` multiple times - [@matthiasblaesing](https://github.com/matthiasblaesing). + Release 4.5.0 ============= diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/mac/MacFileUtils.java 2017-12-27 19:27:16.000000000 +0000 @@ -74,14 +74,8 @@ @Override public void moveToTrash(File[] files) throws IOException { - File home = new File(System.getProperty("user.home")); - File trash = new File(home, ".Trash"); - if (!trash.exists()) { - throw new IOException("The Trash was not found in its expected location (" + trash + ")"); - } List failed = new ArrayList(); - for (int i=0;i < files.length;i++) { - File src = files[i]; + for (File src: files) { FileManager.FSRef fsref = new FileManager.FSRef(); int status = FileManager.INSTANCE.FSPathMakeRefWithOptions(src.getAbsolutePath(), FileManager.kFSPathMakeRefDoNotFollowLeafSymlink, diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/unix/LibCAPI.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/unix/LibCAPI.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/unix/LibCAPI.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/unix/LibCAPI.java 2017-12-27 19:27:16.000000000 +0000 @@ -43,12 +43,32 @@ // see man(2) get/set hostname int HOST_NAME_MAX = 255; // not including the '\0' + /** + * @deprecated use com.sun.jna.platform.unix.LibCAPI.gethostname(byte[], int) + */ + @Deprecated int gethostname(char[] name, int len); + /** + * @deprecated use com.sun.jna.platform.unix.LibCAPI.sethostname(String, int) + */ + @Deprecated int sethostname(char[] name, int len); + int gethostname(byte[] name, int len); + int sethostname(String name, int len); // see man(2) get/set domainname + /** + * @deprecated use com.sun.jna.platform.unix.LibCAPI.getdomainname(byte[], int) + */ + @Deprecated int getdomainname(char[] name, int len); + /** + * @deprecated use com.sun.jna.platform.unix.LibCAPI.setdomainname(String, int) + */ + @Deprecated int setdomainname(char[] name, int len); + int getdomainname(byte[] name, int len); + int setdomainname(String name, int len); /** * @param name Environment variable name diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java 2017-12-27 19:27:16.000000000 +0000 @@ -544,7 +544,7 @@ if (err == null) { err = e; } else { - err.addSuppressed(e); + err.addSuppressedReflected(e); } } } @@ -2443,7 +2443,7 @@ if (err == null) { err = e; } else { - err.addSuppressed(e); + err.addSuppressedReflected(e); } } diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/COM/COMLateBindingObject.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/COM/COMLateBindingObject.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/COM/COMLateBindingObject.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/COM/COMLateBindingObject.java 2017-12-27 19:27:16.000000000 +0000 @@ -217,7 +217,11 @@ this.oleMethod(OleAuto.DISPATCH_PROPERTYGET, result, this.getIDispatch(), propertyName); - return result.stringValue(); + String res = result.stringValue(); + + OleAuto.INSTANCE.VariantClear(result); + + return res; } /** diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java 2017-12-27 19:27:16.000000000 +0000 @@ -34,7 +34,6 @@ import com.sun.jna.platform.win32.Guid; import com.sun.jna.platform.win32.Guid.IID; import com.sun.jna.platform.win32.Guid.REFIID; -import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.Kernel32Util; import com.sun.jna.platform.win32.OaIdl; import com.sun.jna.platform.win32.OaIdl.DISPID; @@ -46,7 +45,6 @@ import com.sun.jna.platform.win32.Variant.VARIANT; import com.sun.jna.platform.win32.WinDef; import com.sun.jna.platform.win32.WinDef.DWORDByReference; -import com.sun.jna.platform.win32.WinDef.LCID; import com.sun.jna.platform.win32.WinNT; import com.sun.jna.platform.win32.WinNT.HRESULT; import com.sun.jna.platform.win32.COM.COMException; @@ -134,7 +132,7 @@ } public synchronized void dispose() { - if (! ((Dispatch) this.rawDispatch).getPointer().equals(Pointer.NULL)) { + if (((Dispatch) this.rawDispatch).getPointer() != Pointer.NULL) { this.rawDispatch.Release(); ((Dispatch) this.rawDispatch).setPointer(Pointer.NULL); factory.unregister(this); diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Crypt32Util.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Crypt32Util.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Crypt32Util.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Crypt32Util.java 2017-12-27 19:27:16.000000000 +0000 @@ -150,7 +150,7 @@ if (err == null) { err = e; } else { - err.addSuppressed(e); + err.addSuppressedReflected(e); } } } @@ -162,7 +162,7 @@ if (err == null) { err = e; } else { - err.addSuppressed(e); + err.addSuppressedReflected(e); } } } diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/GDI32Util.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/GDI32Util.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/GDI32Util.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/GDI32Util.java 2017-12-27 19:27:16.000000000 +0000 @@ -153,7 +153,7 @@ if (result == null || WinGDI.HGDI_ERROR.equals(result)) { Win32Exception ex = new Win32Exception(Native.getLastError()); if (we != null) { - ex.addSuppressed(we); + ex.addSuppressedReflected(we); } we = ex; } @@ -163,7 +163,7 @@ if (!GDI32.INSTANCE.DeleteObject(hBitmap)) { Win32Exception ex = new Win32Exception(Native.getLastError()); if (we != null) { - ex.addSuppressed(we); + ex.addSuppressedReflected(we); } we = ex; } @@ -174,7 +174,7 @@ if (!GDI32.INSTANCE.DeleteDC(hdcTargetMem)) { Win32Exception ex = new Win32Exception(Native.getLastError()); if (we != null) { - ex.addSuppressed(we); + ex.addSuppressedReflected(we); } we = ex; } diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java 2017-12-27 19:27:16.000000000 +0000 @@ -110,7 +110,7 @@ if (err == null) { err = e; } else { - err.addSuppressed(e); + err.addSuppressedReflected(e); } } } @@ -148,7 +148,7 @@ if (err == null) { err = e; } else { - err.addSuppressed(e); + err.addSuppressedReflected(e); } } } @@ -351,7 +351,7 @@ if (err == null) { err = e; } else { - err.addSuppressed(e); + err.addSuppressedReflected(e); } } @@ -915,7 +915,7 @@ if (!Kernel32.INSTANCE.FreeLibrary(target)) { Win32Exception we = new Win32Exception(Kernel32.INSTANCE.GetLastError()); if (err != null) { - we.addSuppressed(err); + we.addSuppressedReflected(err); } throw we; } @@ -1023,7 +1023,7 @@ if (!Kernel32.INSTANCE.FreeLibrary(target)) { Win32Exception we = new Win32Exception(Kernel32.INSTANCE.GetLastError()); if (err != null) { - we.addSuppressed(err); + we.addSuppressedReflected(err); } throw we; } @@ -1085,7 +1085,7 @@ if (we == null) { we = e; } else { - we.addSuppressed(e); + we.addSuppressedReflected(e); } } diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Win32Exception.java 2017-12-27 19:27:16.000000000 +0000 @@ -25,6 +25,10 @@ import com.sun.jna.LastErrorException; import com.sun.jna.platform.win32.WinNT.HRESULT; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Win32 exception. @@ -69,4 +73,31 @@ super(code, msg); _hr = hr; } + + private static Method addSuppressedMethod = null; + static { + try { + addSuppressedMethod = Throwable.class.getMethod("addSuppressed", Throwable.class); + } catch (NoSuchMethodException ex) { + // This is the case for JDK < 7 + } catch (SecurityException ex) { + Logger.getLogger(Win32Exception.class.getName()).log(Level.SEVERE, "Failed to initialize 'addSuppressed' method", ex); + } + } + + void addSuppressedReflected(Throwable exception) { + if(addSuppressedMethod == null) { + // Make this a NOOP on an unsupported JDK + return; + } + try { + addSuppressedMethod.invoke(this, exception); + } catch (IllegalAccessException ex) { + throw new RuntimeException("Failed to call addSuppressedMethod", ex); + } catch (IllegalArgumentException ex) { + throw new RuntimeException("Failed to call addSuppressedMethod", ex); + } catch (InvocationTargetException ex) { + throw new RuntimeException("Failed to call addSuppressedMethod", ex); + } + } } diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/WininetUtil.java 2017-12-27 19:27:16.000000000 +0000 @@ -123,7 +123,7 @@ if (!Wininet.INSTANCE.FindCloseUrlCache(cacheHandle)) { if (we != null) { Win32Exception e = new Win32Exception(Native.getLastError()); - e.addSuppressed(we); + e.addSuppressedReflected(we); we = e; } } diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Winsock2.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Winsock2.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/Winsock2.java 1970-01-01 00:00:00.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/Winsock2.java 2017-12-27 19:27:16.000000000 +0000 @@ -0,0 +1,81 @@ +/* Copyright (c) 2017 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ +package com.sun.jna.platform.win32; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.win32.W32APIOptions; + +public interface Winsock2 extends Library { + + Winsock2 INSTANCE = (Winsock2) Native.loadLibrary("ws2_32", Winsock2.class, W32APIOptions.ASCII_OPTIONS); + + /** + * The gethostname function retrieves the standard host name for the local + * computer. + * + *

+ * Remarks

+ * + *

+ * The gethostname function returns the name of the local host into the + * buffer specified by the name parameter. The host name is returned as a + * null-terminated string. The form of the host name is dependent on the + * Windows Sockets provider—it can be a simple host name, or it can be a + * fully qualified domain name. However, it is guaranteed that the name + * returned will be successfully parsed by gethostbyname and + * WSAAsyncGetHostByName.

+ * + *

+ * The maximum length of the name returned in the buffer pointed to by the + * name parameter is dependent on the namespace provider.

+ * + *

+ * If the gethostname function is used on a cluster resource on Windows + * Server 2008, Windows Server 2003, or Windows 2000 Server and the + * _CLUSTER_NETWORK_NAME_ environment variable is defined, then the value in + * this environment variable overrides the actual hostname and is returned. + * On a cluster resource, the _CLUSTER_NETWORK_NAME_ environment variable + * contains the name of the cluster.

+ * + *

+ * The gethostname function queries namespace providers to determine the + * local host name using the SVCID_HOSTNAME GUID defined in the Svgguid.h + * header file. If no namespace provider responds, then the gethostname + * function returns the NetBIOS name of the local computer.

+ * + *

+ * The maximum length, in bytes, of the string returned in the buffer + * pointed to by the name parameter is dependent on the namespace provider, + * but this string must be 256 bytes or less. So if a buffer of 256 bytes is + * passed in the name parameter and the namelen parameter is set to 256, the + * buffer size will always be adequate.

+ * + * @param name A bytearray that receives the local host name. + * @param namelen The length, in bytes, of the buffer pointed to by the name parameter. + * @return If no error occurs, gethostname returns zero. Otherwise, it returns SOCKET_ERROR and a specific error code can be retrieved by calling WSAGetLastError. + */ + public int gethostname(byte[] name, int namelen); + +} diff -Nru libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java --- libjna-java-4.5.0/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/src/com/sun/jna/platform/win32/WinspoolUtil.java 2017-12-27 19:27:16.000000000 +0000 @@ -118,7 +118,7 @@ if (!Winspool.INSTANCE.ClosePrinter(pHandle.getValue())) { Win32Exception ex = new Win32Exception(Kernel32.INSTANCE.GetLastError()); if (we != null) { - ex.addSuppressed(we); + ex.addSuppressedReflected(we); } } } diff -Nru libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/unix/LibCTest.java libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/unix/LibCTest.java --- libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/unix/LibCTest.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/unix/LibCTest.java 2017-12-27 19:27:16.000000000 +0000 @@ -1,17 +1,29 @@ /* Copyright (c) 2015 Goldstein Lyor, All Rights Reserved * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". */ package com.sun.jna.platform.unix; +import com.sun.jna.Native; import java.sql.Date; import java.util.Map; @@ -21,6 +33,7 @@ * @author Lyor Goldstein */ public class LibCTest extends AbstractUnixTestSupport { + public LibCTest() { super(); } @@ -48,7 +61,7 @@ LibC.INSTANCE.unsetenv(name); } } - + @Test public void testGetLoadAvg() { double[] loadavg = new double[3]; @@ -58,4 +71,18 @@ assertTrue(loadavg[1] >= 0); assertTrue(loadavg[2] >= 0); } + + @Test + public void testGethostnameGetdomainname() { + // This needs visual inspection ... + byte[] buffer = new byte[256]; + LibC.INSTANCE.gethostname(buffer, buffer.length); + String hostname = Native.toString(buffer); + System.out.println("Hostname: " + hostname); + assertTrue(hostname.length() > 0); + LibC.INSTANCE.getdomainname(buffer, buffer.length); + String domainname = Native.toString(buffer); + System.out.println("Domainname: " + domainname); + assertTrue(domainname.length() > 0); + } } diff -Nru libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java --- libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectFactory_Test.java 2017-12-27 19:27:16.000000000 +0000 @@ -12,7 +12,6 @@ */ package com.sun.jna.platform.win32.COM.util; -import com.sun.jna.Pointer; import static org.junit.Assert.*; import java.io.File; @@ -25,7 +24,6 @@ import com.sun.jna.platform.win32.COM.util.annotation.ComObject; import com.sun.jna.platform.win32.COM.util.annotation.ComMethod; import com.sun.jna.platform.win32.COM.util.annotation.ComProperty; -import com.sun.jna.platform.win32.Ole32; public class ProxyObjectFactory_Test { diff -Nru libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java --- libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/COM/util/ProxyObjectObjectFactory_Test.java 2017-12-27 19:27:16.000000000 +0000 @@ -15,6 +15,8 @@ import com.sun.jna.Pointer; import static org.junit.Assert.*; +import java.lang.reflect.Proxy; + import java.io.File; import org.junit.After; @@ -156,7 +158,8 @@ @Test public void accessWhilstDisposing() { MsWordApp comObj1 = this.factory.createObject(MsWordApp.class); - + comObj1.Quit(); + //TODO: how to test this? this.factory.disposeAll(); @@ -186,4 +189,13 @@ boolean wasDeleted = new File("abcdefg.pdf").delete(); assertTrue(wasDeleted); } + + + @Test + public void testDisposeMustBeCallableMultipleTimes() { + MsWordApp comObj = this.factory.createObject(MsWordApp.class); + comObj.Quit(); + ((ProxyObject) Proxy.getInvocationHandler(comObj)).dispose(); + ((ProxyObject) Proxy.getInvocationHandler(comObj)).dispose(); + } } diff -Nru libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java --- libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java 2017-12-27 19:27:16.000000000 +0000 @@ -1552,7 +1552,7 @@ if (we == null) { we = e; } else { - we.addSuppressed(e); + we.addSuppressedReflected(e); } } @@ -1589,7 +1589,7 @@ if (we == null) { we = e; } else { - we.addSuppressed(e); + we.addSuppressedReflected(e); } } diff -Nru libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java --- libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/PsapiTest.java 2017-12-27 19:27:16.000000000 +0000 @@ -135,7 +135,7 @@ if (we == null) { we = e; } else { - we.addSuppressed(e); + we.addSuppressedReflected(e); } } if (we != null) { @@ -186,7 +186,7 @@ if (we == null) { we = e; } else { - we.addSuppressed(e); + we.addSuppressedReflected(e); } } if (we != null) { @@ -218,7 +218,7 @@ if (we == null) { we = e; } else { - we.addSuppressed(e); + we.addSuppressedReflected(e); } } if (we != null) { diff -Nru libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/Win32ExceptionTest.java libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/Win32ExceptionTest.java --- libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/Win32ExceptionTest.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/Win32ExceptionTest.java 2017-12-27 19:27:16.000000000 +0000 @@ -15,6 +15,7 @@ import com.sun.jna.LastErrorException; import junit.framework.TestCase; +import org.junit.Assume; /** * @author dblock[at]dblock[dot]org @@ -50,8 +51,27 @@ } } + public void testAddSuppressed() { + Assume.assumeTrue(isMethodPresent(Win32Exception.class, "addSuppressed", Throwable.class)); + + Win32Exception demoException = new Win32Exception(WinError.E_FAIL); + demoException.addSuppressed(new RuntimeException("Demo")); + + assertEquals(1, demoException.getSuppressed().length); + assertEquals("Demo", demoException.getSuppressed()[0].getMessage()); + } + private void assertLastErrorValue(LastErrorException e, int code, String msg) { assertEquals("Mismatched error code", code, e.getErrorCode()); assertEquals("Mismatched error message", msg, e.getMessage()); } + + private boolean isMethodPresent(Class baseClass, String methodName, Class... parameters) throws SecurityException { + try { + baseClass.getMethod(methodName, parameters); + return true; + } catch (NoSuchMethodException ex) { + return false; + } + } } diff -Nru libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/Winsock2Test.java libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/Winsock2Test.java --- libjna-java-4.5.0/contrib/platform/test/com/sun/jna/platform/win32/Winsock2Test.java 1970-01-01 00:00:00.000000000 +0000 +++ libjna-java-4.5.1/contrib/platform/test/com/sun/jna/platform/win32/Winsock2Test.java 2017-12-27 19:27:16.000000000 +0000 @@ -0,0 +1,41 @@ +/* Copyright (c) 2017 Matthias Bläsing, All Rights Reserved + * + * The contents of this file is dual-licensed under 2 + * alternative Open Source/Free licenses: LGPL 2.1 or later and + * Apache License 2.0. (starting with JNA version 4.0.0). + * + * You can freely decide which license you want to apply to + * the project. + * + * You may obtain a copy of the LGPL License at: + * + * http://www.gnu.org/licenses/licenses.html + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "LGPL2.1". + * + * You may obtain a copy of the Apache License at: + * + * http://www.apache.org/licenses/ + * + * A copy is also included in the downloadable source code package + * containing JNA, in file "AL2.0". + */ +package com.sun.jna.platform.win32; + +import com.sun.jna.Native; +import org.junit.Test; +import static org.junit.Assert.*; + +public class Winsock2Test { + @Test + public void testGethostname() { + // This needs visual inspection ... + byte[] buffer = new byte[256]; + Winsock2.INSTANCE.gethostname(buffer, buffer.length); + String hostname = Native.toString(buffer); + System.out.println("Hostname: " + hostname); + assertTrue(hostname.length() > 0); + } + +} diff -Nru libjna-java-4.5.0/debian/changelog libjna-java-4.5.1/debian/changelog --- libjna-java-4.5.0/debian/changelog 2017-11-29 16:20:25.000000000 +0000 +++ libjna-java-4.5.1/debian/changelog 2018-01-09 23:32:50.000000000 +0000 @@ -1,3 +1,13 @@ +libjna-java (4.5.1-1) unstable; urgency=medium + + * Team upload. + * New upstream release + - Refreshed the patches + * Removed the contradicting javadoc patches + * Standards-Version updated to 4.1.3 + + -- Emmanuel Bourg Wed, 10 Jan 2018 00:32:50 +0100 + libjna-java (4.5.0-2) unstable; urgency=medium * Team upload. diff -Nru libjna-java-4.5.0/debian/control libjna-java-4.5.1/debian/control --- libjna-java-4.5.0/debian/control 2017-11-29 16:19:23.000000000 +0000 +++ libjna-java-4.5.1/debian/control 2018-01-09 23:22:34.000000000 +0000 @@ -16,7 +16,7 @@ libxt-dev, maven-repo-helper (>= 1.5~), pkg-config -Standards-Version: 4.1.1 +Standards-Version: 4.1.3 Vcs-Git: https://anonscm.debian.org/git/pkg-java/libjna-java.git Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/libjna-java.git Homepage: https://github.com/twall/jna diff -Nru libjna-java-4.5.0/debian/patches/03-dynlink-and-cflags.patch libjna-java-4.5.1/debian/patches/03-dynlink-and-cflags.patch --- libjna-java-4.5.0/debian/patches/03-dynlink-and-cflags.patch 2017-09-15 12:40:41.000000000 +0000 +++ libjna-java-4.5.1/debian/patches/03-dynlink-and-cflags.patch 2018-01-09 23:23:39.000000000 +0000 @@ -3,7 +3,7 @@ --- a/build.xml +++ b/build.xml -@@ -936,6 +936,19 @@ +@@ -946,6 +946,19 @@ @@ -23,7 +23,7 @@ diff -Nru libjna-java-4.5.0/debian/patches/06-remove-gjdoc-inexistent-options.patch libjna-java-4.5.1/debian/patches/06-remove-gjdoc-inexistent-options.patch --- libjna-java-4.5.0/debian/patches/06-remove-gjdoc-inexistent-options.patch 2017-09-15 12:40:44.000000000 +0000 +++ libjna-java-4.5.1/debian/patches/06-remove-gjdoc-inexistent-options.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,14 +0,0 @@ -Author: Jan Dittberner -Subject: disable javadoc options that are not supported by gjdoc - ---- a/build.xml -+++ b/build.xml -@@ -1225,7 +1225,7 @@ - - - -- -+ - - - diff -Nru libjna-java-4.5.0/debian/patches/09-javadoc.patch libjna-java-4.5.1/debian/patches/09-javadoc.patch --- libjna-java-4.5.0/debian/patches/09-javadoc.patch 2017-09-15 12:40:46.000000000 +0000 +++ libjna-java-4.5.1/debian/patches/09-javadoc.patch 2018-01-09 23:23:45.000000000 +0000 @@ -2,7 +2,7 @@ --- a/build.xml +++ b/build.xml -@@ -1208,7 +1208,7 @@ +@@ -1218,7 +1218,7 @@ JNA API Documentation
${header}
${footer} diff -Nru libjna-java-4.5.0/debian/patches/10-disable-full-jar.patch libjna-java-4.5.1/debian/patches/10-disable-full-jar.patch --- libjna-java-4.5.0/debian/patches/10-disable-full-jar.patch 2017-09-15 12:40:47.000000000 +0000 +++ libjna-java-4.5.1/debian/patches/10-disable-full-jar.patch 2018-01-09 23:23:47.000000000 +0000 @@ -3,7 +3,7 @@ Forwarded: not-needed --- a/build.xml +++ b/build.xml -@@ -414,6 +414,7 @@ +@@ -424,6 +424,7 @@ @@ -11,7 +11,7 @@ @@ -24,7 +24,7 @@ -@@ -560,6 +563,7 @@ +@@ -570,6 +573,7 @@ diff -Nru libjna-java-4.5.0/debian/patches/13-reproducible-javadoc.patch libjna-java-4.5.1/debian/patches/13-reproducible-javadoc.patch --- libjna-java-4.5.0/debian/patches/13-reproducible-javadoc.patch 2017-09-15 12:40:50.000000000 +0000 +++ libjna-java-4.5.1/debian/patches/13-reproducible-javadoc.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -Description: Set the locale and remove the timestamps when generating the javadoc to make it reproducible -Author: Emmanuel Bourg -Forwarded: no ---- a/build.xml -+++ b/build.xml -@@ -1206,7 +1206,8 @@ - maxmemory="256m" - packagenames="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.platform,com.sun.jna.platform.win32" - overview="${src}/com/sun/jna/overview.html" -- additionalparam="${javadoc.opts}" -+ additionalparam="${javadoc.opts} -notimestamp" -+ locale="en" - destdir="${javadoc}"> - - JNA API Documentation diff -Nru libjna-java-4.5.0/debian/patches/series libjna-java-4.5.1/debian/patches/series --- libjna-java-4.5.0/debian/patches/series 2017-11-29 16:09:48.000000000 +0000 +++ libjna-java-4.5.1/debian/patches/series 2018-01-09 23:30:21.000000000 +0000 @@ -1,10 +1,8 @@ #01-nbproject.patch 03-dynlink-and-cflags.patch 04-load-native-code-from-fs.patch -06-remove-gjdoc-inexistent-options.patch 09-javadoc.patch 10-disable-full-jar.patch 12-structure-backward-compatibility.patch -13-reproducible-javadoc.patch 14-rename-native-library.patch 15-java9-compatibility.patch diff -Nru libjna-java-4.5.0/nbproject/project.xml libjna-java-4.5.1/nbproject/project.xml --- libjna-java-4.5.0/nbproject/project.xml 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/nbproject/project.xml 2017-12-27 19:27:16.000000000 +0000 @@ -33,9 +33,9 @@ UTF-8 - + java - ant-elfanalyser-src + ant-tools-src UTF-8 @@ -68,8 +68,8 @@ test - - ant-elfanalyser-src + + ant-tools-src build.xml @@ -98,7 +98,7 @@ 1.5 - ant-elfanalyser-src + ant-tools-src src:lib/ant.jar 1.5 diff -Nru libjna-java-4.5.0/README.md libjna-java-4.5.1/README.md --- libjna-java-4.5.0/README.md 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/README.md 2017-12-27 19:27:16.000000000 +0000 @@ -5,7 +5,7 @@ Java Native Access (JNA) ======================== -The definitive JNA reference (including an overview and usage details) is in the [JavaDoc](http://java-native-access.github.io/jna/4.5.0/javadoc/). Please read the [overview](http://java-native-access.github.io/jna/4.5.0/javadoc/overview-summary.html#overview_description). Questions, comments, or exploratory conversations should begin on the [mailing list](http://groups.google.com/group/jna-users), although you may find it easier to find answers to already-solved problems on [StackOverflow](http://stackoverflow.com/questions/tagged/jna). +The definitive JNA reference (including an overview and usage details) is in the [JavaDoc](http://java-native-access.github.io/jna/4.5.1/javadoc/). Please read the [overview](http://java-native-access.github.io/jna/4.5.1/javadoc/overview-summary.html#overview_description). Questions, comments, or exploratory conversations should begin on the [mailing list](http://groups.google.com/group/jna-users), although you may find it easier to find answers to already-solved problems on [StackOverflow](http://stackoverflow.com/questions/tagged/jna). JNA provides Java programs easy access to native shared libraries without writing anything but Java code - no JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes. @@ -58,13 +58,13 @@ Download ======== -Version 4.5.0 +Version 4.5.1 * [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.java.dev.jna/jna/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.java.dev.jna/jna)   - [jna.jar](http://repo1.maven.org/maven2/net/java/dev/jna/jna/4.5.0/jna-4.5.0.jar) + [jna.jar](http://repo1.maven.org/maven2/net/java/dev/jna/jna/4.5.1/jna-4.5.1.jar) * [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.java.dev.jna/jna-platform/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.java.dev.jna/jna-platform)   - [jna-platform.jar](http://repo1.maven.org/maven2/net/java/dev/jna/jna-platform/4.5.0/jna-platform-4.5.0.jar) + [jna-platform.jar](http://repo1.maven.org/maven2/net/java/dev/jna/jna-platform/4.5.1/jna-platform-4.5.1.jar) Features ======== @@ -125,12 +125,12 @@ * [Platform Library](https://github.com/java-native-access/jna/blob/master/www/PlatformLibrary.md) * [Direct Method Mapping](https://github.com/java-native-access/jna/blob/master/www/DirectMapping.md) (Optimization) * [Frequently Asked Questions (FAQ)](https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md) -* [Avoiding Crashes](http://java-native-access.github.io/jna/4.5.0/javadoc/overview-summary.html#crash-protection) +* [Avoiding Crashes](http://java-native-access.github.io/jna/4.5.1/javadoc/overview-summary.html#crash-protection) Primary Documentation (JavaDoc) =============================== -The definitive JNA reference is in the [JavaDoc](http://java-native-access.github.io/jna/4.5.0/javadoc/). +The definitive JNA reference is in the [JavaDoc](http://java-native-access.github.io/jna/4.5.1/javadoc/). Developers ========== diff -Nru libjna-java-4.5.0/src/com/sun/jna/ELFAnalyser.java libjna-java-4.5.1/src/com/sun/jna/ELFAnalyser.java --- libjna-java-4.5.0/src/com/sun/jna/ELFAnalyser.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/src/com/sun/jna/ELFAnalyser.java 2017-12-27 19:27:16.000000000 +0000 @@ -104,37 +104,45 @@ } private void runDetection() throws IOException { - // run precheck - only of if the file at least hold an ELF header parsing - // runs further. RandomAccessFile raf = new RandomAccessFile(filename, "r"); - if (raf.length() > 4) { - byte[] magic = new byte[4]; - raf.seek(0); - raf.read(magic); - if (Arrays.equals(magic, ELF_MAGIC)) { - ELF = true; + try { + // run precheck - only of if the file at least hold an ELF header parsing + // runs further. + if (raf.length() > 4) { + byte[] magic = new byte[4]; + raf.seek(0); + raf.read(magic); + if (Arrays.equals(magic, ELF_MAGIC)) { + ELF = true; + } } - } - if (!ELF) { - return; - } - raf.seek(4); - // The total header size depends on the pointer size of the platform - // so before the header is loaded the pointer size has to be determined - byte sizeIndicator = raf.readByte(); - _64Bit = sizeIndicator == EI_CLASS_64BIT; - raf.seek(0); - ByteBuffer headerData = ByteBuffer.allocate(_64Bit ? 64 : 52); - raf.getChannel().read(headerData, 0); - bigEndian = headerData.get(5) == EI_DATA_BIG_ENDIAN; - headerData.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); + if (!ELF) { + return; + } + raf.seek(4); + // The total header size depends on the pointer size of the platform + // so before the header is loaded the pointer size has to be determined + byte sizeIndicator = raf.readByte(); + _64Bit = sizeIndicator == EI_CLASS_64BIT; + raf.seek(0); + ByteBuffer headerData = ByteBuffer.allocate(_64Bit ? 64 : 52); + raf.getChannel().read(headerData, 0); + bigEndian = headerData.get(5) == EI_DATA_BIG_ENDIAN; + headerData.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); + + arm = headerData.get(0x12) == E_MACHINE_ARM; - arm = headerData.get(0x12) == E_MACHINE_ARM; - - if(arm) { - int flags = headerData.getInt(_64Bit ? 0x30 : 0x24); - armSoftFloat = (flags & EF_ARM_ABI_FLOAT_SOFT) == EF_ARM_ABI_FLOAT_SOFT; - armHardFloat = (flags & EF_ARM_ABI_FLOAT_HARD) == EF_ARM_ABI_FLOAT_HARD; + if(arm) { + int flags = headerData.getInt(_64Bit ? 0x30 : 0x24); + armHardFloat = (flags & EF_ARM_ABI_FLOAT_HARD) == EF_ARM_ABI_FLOAT_HARD; + armSoftFloat = !armHardFloat; + } + } finally { + try { + raf.close(); + } catch (IOException ex) { + // Swallow - closing + } } } } diff -Nru libjna-java-4.5.0/src/com/sun/jna/Platform.java libjna-java-4.5.1/src/com/sun/jna/Platform.java --- libjna-java-4.5.0/src/com/sun/jna/Platform.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/src/com/sun/jna/Platform.java 2017-12-27 19:27:16.000000000 +0000 @@ -130,7 +130,7 @@ C_LIBRARY_NAME = osType == WINDOWS ? "msvcrt" : osType == WINDOWSCE ? "coredll" : "c"; MATH_LIBRARY_NAME = osType == WINDOWS ? "msvcrt" : osType == WINDOWSCE ? "coredll" : "m"; HAS_DLL_CALLBACKS = osType == WINDOWS; - ARCH = getCanonicalArchitecture(System.getProperty("os.arch")); + ARCH = getCanonicalArchitecture(System.getProperty("os.arch"), osType); RESOURCE_PREFIX = getNativeLibraryResourcePrefix(); } private Platform() { } @@ -236,7 +236,7 @@ return false; } - static String getCanonicalArchitecture(String arch) { + static String getCanonicalArchitecture(String arch, int platform) { arch = arch.toLowerCase().trim(); if ("powerpc".equals(arch)) { arch = "ppc"; @@ -256,7 +256,7 @@ arch = "ppc64le"; } // Map arm to armel if the binary is running as softfloat build - if("arm".equals(arch) && isSoftFloat()) { + if("arm".equals(arch) && platform == Platform.LINUX && isSoftFloat()) { arch = "armel"; } @@ -300,7 +300,7 @@ */ static String getNativeLibraryResourcePrefix(int osType, String arch, String name) { String osPrefix; - arch = getCanonicalArchitecture(arch); + arch = getCanonicalArchitecture(arch, osType); switch(osType) { case Platform.ANDROID: if (arch.startsWith("arm")) { diff -Nru libjna-java-4.5.0/test/com/sun/jna/ELFAnalyserTest.java libjna-java-4.5.1/test/com/sun/jna/ELFAnalyserTest.java --- libjna-java-4.5.0/test/com/sun/jna/ELFAnalyserTest.java 2017-09-13 20:12:57.000000000 +0000 +++ libjna-java-4.5.1/test/com/sun/jna/ELFAnalyserTest.java 2017-12-27 19:27:16.000000000 +0000 @@ -1,11 +1,7 @@ package com.sun.jna; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.junit.AfterClass; @@ -16,13 +12,13 @@ public class ELFAnalyserTest { - - private static File testResources = new File("build/test-resources"); - private static File win32Lib = new File(testResources, "win32-x86-64.dll"); - private static File linuxArmelLib = new File(testResources, "linux-armel.so"); - private static File linuxArmhfLib = new File(testResources, "linux-armhf.so"); - private static File linuxAmd64Lib = new File(testResources, "linux-amd64.so"); + private static final File TEST_RESOURCES = new File("build/test-resources"); + private static final File WIN32_LIB = new File(TEST_RESOURCES, "win32-x86-64.dll"); + private static final File LINUX_ARMEL_LIB = new File(TEST_RESOURCES, "linux-armel.so"); + private static final File LINUX_ARMEL_NOFLAG_LIG = new File(TEST_RESOURCES, "linux-armel-noflag.so"); + private static final File LINUX_ARMHF_LIB = new File(TEST_RESOURCES, "linux-armhf.so"); + private static final File LINUX_AMD64_LIB = new File(TEST_RESOURCES, "linux-amd64.so"); @BeforeClass public static void initClass() throws IOException { @@ -31,23 +27,24 @@ File linuxArmhfZip = new File("dist/linux-arm.jar"); File linuxAmd64Zip = new File("dist/linux-x86-64.jar"); - testResources.mkdirs(); + TEST_RESOURCES.mkdirs(); - extractFileFromZip(win32Zip, "jnidispatch.dll", win32Lib); - extractFileFromZip(linuxArmelZip, "libjnidispatch.so", linuxArmelLib); - extractFileFromZip(linuxArmhfZip, "libjnidispatch.so", linuxArmhfLib); - extractFileFromZip(linuxAmd64Zip, "libjnidispatch.so", linuxAmd64Lib); + extractFileFromZip(win32Zip, "jnidispatch.dll", WIN32_LIB); + extractFileFromZip(linuxArmelZip, "libjnidispatch.so", LINUX_ARMEL_LIB); + extractFileFromZip(linuxArmhfZip, "libjnidispatch.so", LINUX_ARMHF_LIB); + extractFileFromZip(linuxAmd64Zip, "libjnidispatch.so", LINUX_AMD64_LIB); + makeLinuxArmelNoflagLib(LINUX_ARMEL_LIB, LINUX_ARMEL_NOFLAG_LIG); } @Test public void testNonELF() throws IOException { - ELFAnalyser ahfd = ELFAnalyser.analyse(win32Lib.getAbsolutePath()); + ELFAnalyser ahfd = ELFAnalyser.analyse(WIN32_LIB.getAbsolutePath()); assertFalse(ahfd.isELF()); } @Test public void testNonArm() throws IOException { - ELFAnalyser ahfd = ELFAnalyser.analyse(linuxAmd64Lib.getAbsolutePath()); + ELFAnalyser ahfd = ELFAnalyser.analyse(LINUX_AMD64_LIB.getAbsolutePath()); assertTrue(ahfd.isELF()); assertFalse(ahfd.isArm()); assertTrue(ahfd.is64Bit()); @@ -55,7 +52,7 @@ @Test public void testArmhf() throws IOException { - ELFAnalyser ahfd = ELFAnalyser.analyse(linuxArmhfLib.getAbsolutePath()); + ELFAnalyser ahfd = ELFAnalyser.analyse(LINUX_ARMHF_LIB.getAbsolutePath()); assertTrue(ahfd.isELF()); assertTrue(ahfd.isArm()); assertFalse(ahfd.is64Bit()); @@ -65,7 +62,17 @@ @Test public void testArmel() throws IOException { - ELFAnalyser ahfd = ELFAnalyser.analyse(linuxArmelLib.getAbsolutePath()); + ELFAnalyser ahfd = ELFAnalyser.analyse(LINUX_ARMEL_LIB.getAbsolutePath()); + assertTrue(ahfd.isELF()); + assertTrue(ahfd.isArm()); + assertFalse(ahfd.is64Bit()); + assertTrue(ahfd.isArmSoftFloat()); + assertFalse(ahfd.isArmHardFloat()); + } + + @Test + public void testArmelNoflag() throws IOException { + ELFAnalyser ahfd = ELFAnalyser.analyse(LINUX_ARMEL_NOFLAG_LIG.getAbsolutePath()); assertTrue(ahfd.isELF()); assertTrue(ahfd.isArm()); assertFalse(ahfd.is64Bit()); @@ -75,11 +82,12 @@ @AfterClass public static void afterClass() throws IOException { - linuxAmd64Lib.delete(); - linuxArmhfLib.delete(); - linuxArmelLib.delete(); - win32Lib.delete(); - testResources.delete(); + LINUX_AMD64_LIB.delete(); + LINUX_ARMHF_LIB.delete(); + LINUX_ARMEL_LIB.delete(); + WIN32_LIB.delete(); + LINUX_ARMEL_NOFLAG_LIG.delete(); + TEST_RESOURCES.delete(); } private static void extractFileFromZip(File zipTarget, String zipEntryName, File outputFile) throws IOException { @@ -92,11 +100,7 @@ InputStream is = zip.getInputStream(entry); // Implicitly closed by closing ZipFile OutputStream os = new FileOutputStream(outputFile); try { - int read; - byte[] buffer = new byte[1024 * 1024]; - while((read = is.read(buffer)) > 0) { - os.write(buffer, 0, read); - } + copyStream(is, os); } finally { os.close(); } @@ -104,5 +108,49 @@ zip.close(); } } + + // The e_flags for elf arm binaries begin at an offset of 0x24 bytes. + // The procedure call standard is coded on the second byte. + private static void makeLinuxArmelNoflagLib(File sourceFile, File outputFile) throws IOException { + final int POS_ABI_FLOAT_BIT = (byte) 0x25; + copyFile(sourceFile, outputFile); + + RandomAccessFile out = new RandomAccessFile(outputFile, "rw"); + + out.seek(POS_ABI_FLOAT_BIT); + out.write(0); + + out.close(); + } + + private static void copyFile(File sourceFile, File outputFile) throws IOException { + InputStream inputStream = null; + OutputStream outputStream = null; + try { + inputStream = new FileInputStream(sourceFile); + outputStream = new FileOutputStream(outputFile); + copyStream(inputStream, outputStream); + } finally { + closeSilently(inputStream); + closeSilently(outputStream); + } + } + + private static void copyStream(InputStream is, OutputStream os) throws IOException { + int read; + byte[] buffer = new byte[1024 * 1024]; + while ((read = is.read(buffer)) > 0) { + os.write(buffer, 0, read); + } + } + + private static void closeSilently(Closeable closeable) { + if(closeable == null) { + return; + } + try { + closeable.close(); + } catch (IOException ex) {} + } }