/** Return the native size of the given Java type, from the perspective of * this Structure. * @param nativeType field type to examine * @param value instance of the field type * @return native size (in bytes) of the requested field type */ protected int getNativeSize(Class<?> nativeType, Object value) { return Native.getNativeSize(nativeType, value); }
/** * @param cls The Java class * @return {@code true} whether the given class is supported as a native argument type. */ public static boolean isSupportedNativeType(Class<?> cls) { if (Structure.class.isAssignableFrom(cls)) { return true; } try { return getNativeSize(cls) != 0; } catch(IllegalArgumentException e) { return false; } }
public NativeMappedArray(NativeMapped[] arg) { super(Native.getNativeSize(arg.getClass(), arg)); this.original = arg; setValue(0, original, original.getClass()); } @Override
/** * @param type The Java class for which the native size is to be determined * @param value an instance of said class (if available) * @return the native size of the given class, in bytes. * For use with arrays. */ public static int getNativeSize(Class<?> type, Object value) { if (type.isArray()) { int len = Array.getLength(value); if (len > 0) { Object o = Array.get(value, 0); return len * getNativeSize(type.getComponentType(), o); } // Don't process zero-length arrays throw new IllegalArgumentException("Arrays of length zero not allowed: " + type); } if (Structure.class.isAssignableFrom(type) && !Structure.ByReference.class.isAssignableFrom(type)) { return Structure.size((Class<Structure>) type, (Structure)value); } try { return getNativeSize(type); } catch(IllegalArgumentException e) { throw new IllegalArgumentException("The type \"" + type.getName() + "\" is not supported: " + e.getMessage()); } }
/** Override this to handle any custom class mappings. * @param cls Java class of a parameter * @return number of native bytes used for this class on the stack */ protected int getArgumentNativeStackSize(Class<?> cls) { if (NativeMapped.class.isAssignableFrom(cls)) { cls = NativeMappedConverter.getInstance(cls).nativeType(); } if (cls.isArray()) { return Native.POINTER_SIZE; } try { return Native.getNativeSize(cls); } catch(IllegalArgumentException e) { throw new IllegalArgumentException("Unknown native stack allocation size for " + cls); } }
value = tc.toNative(value, new ToNativeContext()); int size = Native.getNativeSize(type, value); if (type.isPrimitive() || Long.class == type || Integer.class == type || Short.class == type || Character.class == type
public static int sizeOf() { return Native.getNativeSize(FILE_COMPRESSION_INFO.class, null); }
/** * Helper function to calculate the size of an ACE for a given PSID size * @param sidLength length of the sid * @return size of the ACE */ public static int getAceSize(int sidLength) { return Native.getNativeSize(ACCESS_ALLOWED_ACE.class, null) + sidLength - DWORD.SIZE; }
/** Return the native size of the given Java type, from the perspective of * this Structure. * @param nativeType field type to examine * @param value instance of the field type * @return native size (in bytes) of the requested field type */ protected int getNativeSize(Class<?> nativeType, Object value) { return Native.getNativeSize(nativeType, value); }
public static final int size(@SuppressWarnings("rawtypes") final Class cls) { return Native.getNativeSize(cls); } }
public static int sizeOf() { return Native.getNativeSize(FILE_ATTRIBUTE_TAG_INFO.class, null); }
public static int sizeOf() { return Native.getNativeSize(FILE_DISPOSITION_INFO.class, null); }
public static int sizeOf() { return Native.getNativeSize(FILE_BASIC_INFO.class, null); }
public static int sizeOf() { return Native.getNativeSize(FILE_STANDARD_INFO.class, null); }
public static int sizeOf() { return Native.getNativeSize(FILE_ID_INFO.class, null); }
public static int sizeOf() { return Native.getNativeSize(WIN32_FIND_DATA.class, null); }
NativeMapped[] array = (NativeMapped[])result; NativeMappedConverter tc = NativeMappedConverter.getInstance(cls); int size = Native.getNativeSize(result.getClass(), result) / array.length; for (int i=0;i < array.length;i++) { Object value = getValue(offset + size*i, tc.nativeType(), array[i]);
NativeMappedConverter tc = NativeMappedConverter.getInstance(cls); Class<?> nativeType = tc.nativeType(); int size = Native.getNativeSize(value.getClass(), value) / buf.length; for (int i=0;i < buf.length;i++) { Object element = tc.toNative(buf[i], new ToNativeContext());
public NativeMappedArray(NativeMapped[] arg) { super(Native.getNativeSize(arg.getClass(), arg)); this.original = arg; setValue(0, original, original.getClass()); } @Override
public Pointer call( Pointer jsContextRef, Pointer jsFunction, Pointer thisObject, int argumentCount, PointerByReference ref, Pointer exception ) throws Exception { JSC jsc = shell.jsc(); int size = Native.getNativeSize(Pointer.class); Object[] args = new Object[argumentCount]; for (int i = 0, offset = 0; i < argumentCount; i++, offset += size) { args[i] = convertToJava(jsc, method.getParameterTypes()[i], ref.getPointer().getPointer(offset)); } return convertFromJava(method.invoke(vm, args))[0]; } }