Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypt32 bindings #851

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/notes/3.3.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This build includes the following changes:
* FreeType interop can be enabled by making HarfBuzz use FreeType's shared library (see `Configuration.HARFBUZZ_LIBRARY_NAME`).
- Added [hwloc](https://www.open-mpi.org/projects/hwloc/) bindings. (#98)
- Added [KTX (Khronos Texture)](https://www.khronos.org/ktx/) bindings. (#660)
- Windows: Added bindings to `dpapi.h`. (#851)
- Assimp: Updated to 5.2.5 (up from 5.2.2)
* `KHR_draco_mesh_compression` is now supported via the bundled [Draco](https://github.com/google/draco) library. (#773)
- bgfx: Updated to API version 118 (up from 115)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,12 @@ class NativeClass internal constructor(
staticImports.add("org.lwjgl.system.APIUtil.*")
if ((binding != null && binding.apiCapabilities.ordinal >= 2) || functions.any { func ->
func.hasParam { param ->
param.nativeType is PointerType<*> && func.getReferenceParam<AutoSize>(param.name).let {
param.nativeType is PointerType<*> && (param.has<Check>() || func.getReferenceParam<AutoSize>(param.name).let {
if (it == null)
!param.has<Nullable>() && param.nativeType.elementType !is StructType
(!param.has<Nullable>() || param.nativeType is CharSequenceType) && param.nativeType.elementType !is StructType
else
it.get<AutoSize>().reference != param.name // dependent auto-size
}
})
} || (module.arrayOverloads && func.hasArrayOverloads) || (func.has<IgnoreMissing>() && binding?.apiCapabilities != APICapabilities.JNI_CAPABILITIES)
})
staticImports.add("org.lwjgl.system.Checks.*")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
#include "common_tools.h"
#include "WindowsLWJGL.h"

typedef jint (APIENTRY *CryptProtectDataPROC) (uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, jint, uintptr_t);
typedef jint (APIENTRY *CryptProtectMemoryPROC) (uintptr_t, jint, jint);
typedef jint (APIENTRY *CryptUnprotectDataPROC) (uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, jint, uintptr_t);
typedef jint (APIENTRY *CryptUnprotectMemoryPROC) (uintptr_t, jint, jint);

EXTERN_C_ENTER

JNIEXPORT jint JNICALL Java_org_lwjgl_system_windows_Crypt32_nCryptProtectData(JNIEnv *__env, jclass clazz, jlong pDataInAddress, jlong szDataDescrAddress, jlong pOptionalEntropyAddress, jlong pvReservedAddress, jlong pPromptStructAddress, jint dwFlags, jlong pDataOutAddress, jlong __functionAddress) {
CryptProtectDataPROC CryptProtectData = (CryptProtectDataPROC)(uintptr_t)__functionAddress;
uintptr_t pDataIn = (uintptr_t)pDataInAddress;
uintptr_t szDataDescr = (uintptr_t)szDataDescrAddress;
uintptr_t pOptionalEntropy = (uintptr_t)pOptionalEntropyAddress;
uintptr_t pvReserved = (uintptr_t)pvReservedAddress;
uintptr_t pPromptStruct = (uintptr_t)pPromptStructAddress;
uintptr_t pDataOut = (uintptr_t)pDataOutAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = CryptProtectData(pDataIn, szDataDescr, pOptionalEntropy, pvReserved, pPromptStruct, dwFlags, pDataOut);
saveLastError();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_windows_Crypt32_nCryptProtectMemory(JNIEnv *__env, jclass clazz, jlong pDataInAddress, jint cbDataIn, jint dwFlags, jlong __functionAddress) {
CryptProtectMemoryPROC CryptProtectMemory = (CryptProtectMemoryPROC)(uintptr_t)__functionAddress;
uintptr_t pDataIn = (uintptr_t)pDataInAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = CryptProtectMemory(pDataIn, cbDataIn, dwFlags);
saveLastError();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_windows_Crypt32_nCryptUnprotectData(JNIEnv *__env, jclass clazz, jlong pDataInAddress, jlong ppszDataDescrAddress, jlong pOptionalEntropyAddress, jlong pvReservedAddress, jlong pPromptStructAddress, jint dwFlags, jlong pDataOutAddress, jlong __functionAddress) {
CryptUnprotectDataPROC CryptUnprotectData = (CryptUnprotectDataPROC)(uintptr_t)__functionAddress;
uintptr_t pDataIn = (uintptr_t)pDataInAddress;
uintptr_t ppszDataDescr = (uintptr_t)ppszDataDescrAddress;
uintptr_t pOptionalEntropy = (uintptr_t)pOptionalEntropyAddress;
uintptr_t pvReserved = (uintptr_t)pvReservedAddress;
uintptr_t pPromptStruct = (uintptr_t)pPromptStructAddress;
uintptr_t pDataOut = (uintptr_t)pDataOutAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = CryptUnprotectData(pDataIn, ppszDataDescr, pOptionalEntropy, pvReserved, pPromptStruct, dwFlags, pDataOut);
saveLastError();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_windows_Crypt32_nCryptUnprotectMemory(JNIEnv *__env, jclass clazz, jlong pDataInAddress, jint cbDataIn, jint dwFlags, jlong __functionAddress) {
CryptUnprotectMemoryPROC CryptUnprotectMemory = (CryptUnprotectMemoryPROC)(uintptr_t)__functionAddress;
uintptr_t pDataIn = (uintptr_t)pDataInAddress;
jint __result;
UNUSED_PARAMS(__env, clazz)
__result = CryptUnprotectMemory(pDataIn, cbDataIn, dwFlags);
saveLastError();
return __result;
}

EXTERN_C_EXIT
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

EXTERN_C_ENTER

JNIEXPORT jlong JNICALL Java_org_lwjgl_system_windows_WinBase_nLocalFree(JNIEnv *__env, jclass clazz, jlong hMemAddress) {
HLOCAL hMem = (HLOCAL)(uintptr_t)hMemAddress;
jlong __result;
UNUSED_PARAMS(__env, clazz)
__result = (jlong)(uintptr_t)LocalFree(hMem);
saveLastError();
return __result;
}

JNIEXPORT jint JNICALL Java_org_lwjgl_system_windows_WinBase_GetLastError(JNIEnv *__env, jclass clazz) {
UNUSED_PARAMS(__env, clazz)
return (jint)GetLastError();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
package org.lwjgl.system.windows;

import javax.annotation.*;

import java.nio.*;

import org.lwjgl.*;
import org.lwjgl.system.*;

import static org.lwjgl.system.Checks.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.MemoryStack.*;

/**
* Provides the text of a prompt and information about when and where that prompt is to be displayed when using the {@link Crypt32#CryptProtectData} and
* {@link Crypt32#CryptUnprotectData} functions.
*
* <h3>Layout</h3>
*
* <pre><code>
* struct CRYPTPROTECT_PROMPTSTRUCT {
* DWORD {@link #cbSize};
* DWORD {@link #dwPromptFlags};
* HWND {@link #hwndApp};
* LPCWSTR {@link #szPrompt};
* }</code></pre>
*/
public class CRYPTPROTECT_PROMPTSTRUCT extends Struct implements NativeResource {

/** The struct size in bytes. */
public static final int SIZEOF;

/** The struct alignment in bytes. */
public static final int ALIGNOF;

/** The struct member offsets. */
public static final int
CBSIZE,
DWPROMPTFLAGS,
HWNDAPP,
SZPROMPT;

static {
Layout layout = __struct(
__member(4),
__member(4),
__member(POINTER_SIZE),
__member(POINTER_SIZE)
);

SIZEOF = layout.getSize();
ALIGNOF = layout.getAlignment();

CBSIZE = layout.offsetof(0);
DWPROMPTFLAGS = layout.offsetof(1);
HWNDAPP = layout.offsetof(2);
SZPROMPT = layout.offsetof(3);
}

/**
* Creates a {@code CRYPTPROTECT_PROMPTSTRUCT} instance at the current position of the specified {@link ByteBuffer} container. Changes to the buffer's content will be
* visible to the struct instance and vice versa.
*
* <p>The created instance holds a strong reference to the container object.</p>
*/
public CRYPTPROTECT_PROMPTSTRUCT(ByteBuffer container) {
super(memAddress(container), __checkContainer(container, SIZEOF));
}

@Override
public int sizeof() { return SIZEOF; }

/** the size, in bytes, of this structure */
@NativeType("DWORD")
public int cbSize() { return ncbSize(address()); }
/** flags that indicate when prompts to the user are to be displayed. One or more of:<br><table><tr><td>{@link Crypt32#CRYPTPROTECT_PROMPT_ON_UNPROTECT}</td><td>{@link Crypt32#CRYPTPROTECT_PROMPT_ON_PROTECT}</td></tr></table> */
@NativeType("DWORD")
public int dwPromptFlags() { return ndwPromptFlags(address()); }
/** window handle to the parent window */
@NativeType("HWND")
public long hwndApp() { return nhwndApp(address()); }
/** a string containing the text of a prompt to be displayed */
@NativeType("LPCWSTR")
public ByteBuffer szPrompt() { return nszPrompt(address()); }
/** a string containing the text of a prompt to be displayed */
@NativeType("LPCWSTR")
public String szPromptString() { return nszPromptString(address()); }

/** Sets the specified value to the {@link #cbSize} field. */
public CRYPTPROTECT_PROMPTSTRUCT cbSize(@NativeType("DWORD") int value) { ncbSize(address(), value); return this; }
/** Sets the default value to the {@link #cbSize} field. */
public CRYPTPROTECT_PROMPTSTRUCT cbSize$Default() { return cbSize(SIZEOF); }
/** Sets the specified value to the {@link #dwPromptFlags} field. */
public CRYPTPROTECT_PROMPTSTRUCT dwPromptFlags(@NativeType("DWORD") int value) { ndwPromptFlags(address(), value); return this; }
/** Sets the specified value to the {@link #hwndApp} field. */
public CRYPTPROTECT_PROMPTSTRUCT hwndApp(@NativeType("HWND") long value) { nhwndApp(address(), value); return this; }
/** Sets the address of the specified encoded string to the {@link #szPrompt} field. */
public CRYPTPROTECT_PROMPTSTRUCT szPrompt(@NativeType("LPCWSTR") ByteBuffer value) { nszPrompt(address(), value); return this; }

/** Initializes this struct with the specified values. */
public CRYPTPROTECT_PROMPTSTRUCT set(
int cbSize,
int dwPromptFlags,
long hwndApp,
ByteBuffer szPrompt
) {
cbSize(cbSize);
dwPromptFlags(dwPromptFlags);
hwndApp(hwndApp);
szPrompt(szPrompt);

return this;
}

/**
* Copies the specified struct data to this struct.
*
* @param src the source struct
*
* @return this struct
*/
public CRYPTPROTECT_PROMPTSTRUCT set(CRYPTPROTECT_PROMPTSTRUCT src) {
memCopy(src.address(), address(), SIZEOF);
return this;
}

// -----------------------------------

/** Returns a new {@code CRYPTPROTECT_PROMPTSTRUCT} instance allocated with {@link MemoryUtil#memAlloc memAlloc}. The instance must be explicitly freed. */
public static CRYPTPROTECT_PROMPTSTRUCT malloc() {
return wrap(CRYPTPROTECT_PROMPTSTRUCT.class, nmemAllocChecked(SIZEOF));
}

/** Returns a new {@code CRYPTPROTECT_PROMPTSTRUCT} instance allocated with {@link MemoryUtil#memCalloc memCalloc}. The instance must be explicitly freed. */
public static CRYPTPROTECT_PROMPTSTRUCT calloc() {
return wrap(CRYPTPROTECT_PROMPTSTRUCT.class, nmemCallocChecked(1, SIZEOF));
}

/** Returns a new {@code CRYPTPROTECT_PROMPTSTRUCT} instance allocated with {@link BufferUtils}. */
public static CRYPTPROTECT_PROMPTSTRUCT create() {
ByteBuffer container = BufferUtils.createByteBuffer(SIZEOF);
return wrap(CRYPTPROTECT_PROMPTSTRUCT.class, memAddress(container), container);
}

/** Returns a new {@code CRYPTPROTECT_PROMPTSTRUCT} instance for the specified memory address. */
public static CRYPTPROTECT_PROMPTSTRUCT create(long address) {
return wrap(CRYPTPROTECT_PROMPTSTRUCT.class, address);
}

/** Like {@link #create(long) create}, but returns {@code null} if {@code address} is {@code NULL}. */
@Nullable
public static CRYPTPROTECT_PROMPTSTRUCT createSafe(long address) {
return address == NULL ? null : wrap(CRYPTPROTECT_PROMPTSTRUCT.class, address);
}

/**
* Returns a new {@code CRYPTPROTECT_PROMPTSTRUCT} instance allocated on the specified {@link MemoryStack}.
*
* @param stack the stack from which to allocate
*/
public static CRYPTPROTECT_PROMPTSTRUCT malloc(MemoryStack stack) {
return wrap(CRYPTPROTECT_PROMPTSTRUCT.class, stack.nmalloc(ALIGNOF, SIZEOF));
}

/**
* Returns a new {@code CRYPTPROTECT_PROMPTSTRUCT} instance allocated on the specified {@link MemoryStack} and initializes all its bits to zero.
*
* @param stack the stack from which to allocate
*/
public static CRYPTPROTECT_PROMPTSTRUCT calloc(MemoryStack stack) {
return wrap(CRYPTPROTECT_PROMPTSTRUCT.class, stack.ncalloc(ALIGNOF, 1, SIZEOF));
}

// -----------------------------------

/** Unsafe version of {@link #cbSize}. */
public static int ncbSize(long struct) { return UNSAFE.getInt(null, struct + CRYPTPROTECT_PROMPTSTRUCT.CBSIZE); }
/** Unsafe version of {@link #dwPromptFlags}. */
public static int ndwPromptFlags(long struct) { return UNSAFE.getInt(null, struct + CRYPTPROTECT_PROMPTSTRUCT.DWPROMPTFLAGS); }
/** Unsafe version of {@link #hwndApp}. */
public static long nhwndApp(long struct) { return memGetAddress(struct + CRYPTPROTECT_PROMPTSTRUCT.HWNDAPP); }
/** Unsafe version of {@link #szPrompt}. */
public static ByteBuffer nszPrompt(long struct) { return memByteBufferNT2(memGetAddress(struct + CRYPTPROTECT_PROMPTSTRUCT.SZPROMPT)); }
/** Unsafe version of {@link #szPromptString}. */
public static String nszPromptString(long struct) { return memUTF16(memGetAddress(struct + CRYPTPROTECT_PROMPTSTRUCT.SZPROMPT)); }

/** Unsafe version of {@link #cbSize(int) cbSize}. */
public static void ncbSize(long struct, int value) { UNSAFE.putInt(null, struct + CRYPTPROTECT_PROMPTSTRUCT.CBSIZE, value); }
/** Unsafe version of {@link #dwPromptFlags(int) dwPromptFlags}. */
public static void ndwPromptFlags(long struct, int value) { UNSAFE.putInt(null, struct + CRYPTPROTECT_PROMPTSTRUCT.DWPROMPTFLAGS, value); }
/** Unsafe version of {@link #hwndApp(long) hwndApp}. */
public static void nhwndApp(long struct, long value) { memPutAddress(struct + CRYPTPROTECT_PROMPTSTRUCT.HWNDAPP, check(value)); }
/** Unsafe version of {@link #szPrompt(ByteBuffer) szPrompt}. */
public static void nszPrompt(long struct, ByteBuffer value) {
if (CHECKS) { checkNT2(value); }
memPutAddress(struct + CRYPTPROTECT_PROMPTSTRUCT.SZPROMPT, memAddress(value));
}

/**
* Validates pointer members that should not be {@code NULL}.
*
* @param struct the struct to validate
*/
public static void validate(long struct) {
check(memGetAddress(struct + CRYPTPROTECT_PROMPTSTRUCT.HWNDAPP));
check(memGetAddress(struct + CRYPTPROTECT_PROMPTSTRUCT.SZPROMPT));
}

}
Loading