### Get PawnIOLib Version (C) Source: https://context7.com/namazso/pawniolib/llms.txt Retrieves and prints the version of the PawnIOLib library. It requires the `` header and uses the `pawnio_version` function. The output is formatted as major.minor.patch. ```c #include #include int main() { ULONG version = 0; HRESULT hr = pawnio_version(&version); if (SUCCEEDED(hr)) { ULONG major = (version >> 16) & 0xFF; ULONG minor = (version >> 8) & 0xFF; ULONG patch = version & 0xFF; printf("PawnIOLib version: %lu.%lu.%lu\n", major, minor, patch); // Output: PawnIOLib version: 2.0.0 } else { fprintf(stderr, "Failed to get version: 0x%lx\n", hr); return 1; } return 0; } ``` -------------------------------- ### Get Library Version Source: https://context7.com/namazso/pawniolib/llms.txt Retrieves the current version of the PawnIOLib library. The version is returned as a packed ULONG value that can be unpacked into major, minor, and patch components. ```APIDOC ## GET /pawnio/version ### Description Retrieves the current version of the PawnIOLib library. ### Method GET ### Endpoint /pawnio/version ### Parameters #### Query Parameters None #### Path Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **version** (ULONG) - The packed library version. Major, minor, and patch can be extracted using bitwise operations. #### Response Example ```json { "version": 33554432 } ``` #### Error Response (e.g., 500) - **error** (string) - Description of the error. ``` -------------------------------- ### Test AMX Binary Loading using Bash Source: https://context7.com/namazso/pawniolib/llms.txt This bash script shows how to test AMX binary loading with the PawnIOUtil tool. It covers testing an unsigned binary and testing a binary that is first signed using a provided private key. Successful loading results in no output and an exit code of 0, while failure indicates an error loading the PawnIO module with an exit code of 1. ```bash # Test unsigned binary PawnIOUtil.exe test myprogram.amx # Test with signing (will sign and then test) PawnIOUtil.exe test myprogram.amx private.pem # Success output: # (no output, exit code 0) # Failure output: # failed loading PawnIO module: 0xXXXXXXXX # (exit code 1) ``` -------------------------------- ### Execute Function Synchronously with PawnIOLib Source: https://context7.com/namazso/pawniolib/llms.txt This C code snippet demonstrates how to execute a named function synchronously from a loaded AMX binary using PawnIOLib. It includes opening the device, preparing input and output buffers, executing the function, and handling potential errors. Dependencies include PawnIOLib, stdio, and string.h. ```c #include #include #include int main() { HANDLE handle = NULL; HRESULT hr = pawnio_open(&handle); if (FAILED(hr)) { fprintf(stderr, "Failed to open device: 0x%lx\n", hr); return 1; } // Load binary (blob loading code omitted for brevity) // UCHAR* blob = ...; SIZE_T blob_size = ...; // hr = pawnio_load(handle, blob, blob_size); // Prepare input parameters (example: two 64-bit integers) ULONG64 input_params[2] = { 42, 100 }; SIZE_T input_count = 2; // Prepare output buffer (expecting 1 return value) ULONG64 output_buffer[1] = { 0 }; SIZE_T output_count = 1; SIZE_T returned_count = 0; // Execute function named "calculate" hr = pawnio_execute( handle, "calculate", input_params, input_count, output_buffer, output_count, &returned_count ); if (SUCCEEDED(hr)) { printf("Function executed successfully\n"); printf("Returned %zu values:\n", returned_count); for (SIZE_T i = 0; i < returned_count; i++) { printf(" [%zu] = 0x%016llX (%lld)\n", i, output_buffer[i], output_buffer[i]); } // Example output: // Returned 1 values: // [0] = 0x000000000000008E (142) } else { fprintf(stderr, "Execution failed: 0x%lx\n", hr); fprintf(stderr, "Function name may not exist in binary\n"); } pawnio_close(handle); return FAILED(hr) ? 1 : 0; } ``` -------------------------------- ### Sign AMX Binary with RSA Key using Bash Source: https://context7.com/namazso/pawniolib/llms.txt This bash script demonstrates how to generate an RSA key pair using OpenSSL and then sign an AMX binary using the PawnIOUtil tool with the generated private key. The signed binary includes the signature length, the signature itself, and the original AMX data. ```bash # Generate RSA key pair (using OpenSSL) openssl genrsa -out private.pem 2048 openssl rsa -in private.pem -pubout -out public.pem # Sign AMX binary with private key PawnIOUtil.exe sign input.amx signed_output.amx private.pem # The signed binary contains: # - 4 bytes: signature length (little-endian) # - N bytes: RSA signature (SHA256 hash of AMX data) # - Remaining: original AMX binary data ``` -------------------------------- ### Execute Function Asynchronously with PawnIOLib Source: https://context7.com/namazso/pawniolib/llms.txt This C code demonstrates asynchronous function execution using Windows OVERLAPPED I/O with PawnIOLib. It shows how to open the device, create an event for tracking completion, initiate the asynchronous operation, and wait for its result. This method allows for non-blocking execution. Dependencies include PawnIOLib, stdio, and Windows.h functions like CreateEvent and WaitForSingleObject. ```c #include #include int main() { HANDLE handle = NULL; HRESULT hr = pawnio_open(&handle); if (FAILED(hr)) { fprintf(stderr, "Failed to open device: 0x%lx\n", hr); return 1; } // Load binary (omitted for brevity) // Create event for async operation OVERLAPPED overlapped = { 0 }; overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!overlapped.hEvent) { fprintf(stderr, "Failed to create event\n"); pawnio_close(handle); return 1; } ULONG64 input[1] = { 123 }; ULONG64 output[10] = { 0 }; // Start async execution hr = pawnio_execute_async( handle, "process_async", input, 1, output, 10, &overlapped ); if (hr == S_OK) { printf("Operation completed synchronously\n"); } else if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING)) { printf("Operation pending, waiting...\n"); // Wait for completion DWORD wait_result = WaitForSingleObject(overlapped.hEvent, 5000); if (wait_result == WAIT_OBJECT_0) { SIZE_T bytes_returned = overlapped.InternalHigh; SIZE_T cells_returned = bytes_returned / sizeof(ULONG64); printf("Async operation completed, %zu cells returned\n", cells_returned); for (SIZE_T i = 0; i < cells_returned; i++) { printf(" output[%zu] = %lld\n", i, output[i]); } } else { fprintf(stderr, "Wait failed or timed out\n"); } } else { fprintf(stderr, "Async execute failed: 0x%lx\n", hr); } CloseHandle(overlapped.hEvent); pawnio_close(handle); return 0; } ``` -------------------------------- ### Execute Function with NT APIs in C Source: https://context7.com/namazso/pawniolib/llms.txt This C code demonstrates how to execute a native function asynchronously using NT APIs, including event creation for synchronization and IO status blocks for results. It requires the PawnIOLib and standard Windows headers. ```c #include #include #include #include typedef enum _EVENT_TYPE { NotificationEvent, SynchronizationEvent } EVENT_TYPE; EXTERN_C NTSYSCALLAPI NTSTATUS NTAPI NtCreateEvent( PHANDLE EventHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, EVENT_TYPE EventType, BOOLEAN InitialState ); int main() { HANDLE handle = NULL; NTSTATUS status = pawnio_open_nt(&handle); if (!NT_SUCCESS(status)) { fprintf(stderr, "Failed to open device: 0x%lx\n", status); return 1; } // Load binary (omitted) // Create event for NT async operation HANDLE event = NULL; status = NtCreateEvent(&event, EVENT_ALL_ACCESS, NULL, NotificationEvent, FALSE); if (!NT_SUCCESS(status)) { fprintf(stderr, "Failed to create event: 0x%lx\n", status); pawnio_close_nt(handle); return 1; } IO_STATUS_BLOCK iosb = { 0 }; ULONG64 input[2] = { 10, 20 }; ULONG64 output[5] = { 0 }; status = pawnio_execute_async_nt( handle, "nt_function", event, NULL, // No APC routine NULL, // No APC context &iosb, input, 2, output, 5 ); if (status == STATUS_PENDING) { printf("Operation pending, waiting on event...\n"); NtWaitForSingleObject(event, FALSE, NULL); status = iosb.Status; } if (NT_SUCCESS(status)) { SIZE_T cells_returned = iosb.Information / sizeof(ULONG64); printf("NT execution completed: %zu cells returned\n", cells_returned); for (SIZE_T i = 0; i < cells_returned; i++) { printf(" output[%zu] = 0x%llX\n", i, output[i]); } } else { fprintf(stderr, "NT execution failed: 0x%lx\n", status); } NtClose(event); pawnio_close_nt(handle); return NT_SUCCESS(status) ? 0 : 1; } ``` -------------------------------- ### Load AMX Binary Blob (C) Source: https://context7.com/namazso/pawniolib/llms.txt Loads a compiled Pawn binary (AMX format) into the PawnIO executor. This function requires a valid handle obtained from `pawnio_open` and the binary data along with its size. The binary can optionally be signed. Error handling for file reading and driver operations is included. ```c #include #include #include // Helper function to read binary file UCHAR* read_file(const char* path, SIZE_T* size) { FILE* f = fopen(path, "rb"); if (!f) return NULL; fseek(f, 0, SEEK_END); *size = ftell(f); fseek(f, 0, SEEK_SET); UCHAR* data = (UCHAR*)malloc(*size); if (data) { fread(data, 1, *size, f); } fclose(f); return data; } int main(int argc, char* argv[]) { if (argc < 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } SIZE_T blob_size = 0; UCHAR* blob = read_file(argv[1], &blob_size); if (!blob) { fprintf(stderr, "Failed to read AMX file\n"); return 1; } HANDLE handle = NULL; HRESULT hr = pawnio_open(&handle); if (FAILED(hr)) { fprintf(stderr, "Failed to open device: 0x%lx\n", hr); free(blob); return 1; } hr = pawnio_load(handle, blob, blob_size); if (SUCCEEDED(hr)) { printf("Successfully loaded AMX binary (%zu bytes)\n", blob_size); } else { fprintf(stderr, "Failed to load binary: 0x%lx\n", hr); fprintf(stderr, "Binary may be corrupted or signature invalid\n"); } pawnio_close(handle); free(blob); return FAILED(hr) ? 1 : 0; } ``` -------------------------------- ### Load AMX Binary Blob Source: https://context7.com/namazso/pawniolib/llms.txt Loads a compiled Pawn binary (AMX format) into the PawnIO executor. The binary can optionally include a signature for verification. ```APIDOC ## POST /pawnio/load ### Description Loads a compiled Pawn binary (AMX format with optional signature) into the PawnIO executor. ### Method POST ### Endpoint /pawnio/load ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **handle** (HANDLE) - Required - The handle obtained from `pawnio_open`. - **blob** (UCHAR[]) - Required - The binary data of the AMX file. - **size** (SIZE_T) - Required - The size of the binary data in bytes. ### Request Example ```json { "handle": "0x1234567890ABCDEF", "blob": "AAABAAIAAAABAAAABgAAAAQAAAAOAAAADAAAAAUAAAABAAAAAQAAAAIAAQAAAAEAAAAQAAAAEAAAAAAAAAAFAAAACAAAAAAAAAAFAAAA\/wAAAAAAAAA=", "size": 100 } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating successful loading. #### Response Example ```json { "message": "Successfully loaded AMX binary (100 bytes)" } ``` #### Error Response (e.g., 500) - **error** (string) - Description of the error, e.g., 'Failed to load binary: 0x80070057', 'Binary may be corrupted or signature invalid'. ``` -------------------------------- ### Interactive Function Execution using Bash Source: https://context7.com/namazso/pawniolib/llms.txt This bash script launches an interactive REPL (Read-Eval-Print Loop) using PawnIOUtil. It allows users to execute functions, specifying the number of output cells and input parameters in hexadecimal format. The results are displayed with hex, ASCII, decimal, and floating-point interpretations. The 'quit' command exits the session. ```bash # Start interactive mode PawnIOUtil.exe interactive myprogram.amx private.pem # Interactive session example: > add 2 10 20 received 2 cells: 000000000000001E ........ 30 0.000000 (0.000000 0.000000) 0000000000000000 ........ 0 0.000000 (0.000000 0.000000) > multiply 1 5 7 received 1 cells: 0000000000000023 #....... 35 0.000000 (0.000000 0.000000) > quit # Exits interactive mode # Format: # Each result shows: hex value, ASCII chars, decimal, double, float interpretations ``` -------------------------------- ### Open PawnIO Device Handle (C) Source: https://context7.com/namazso/pawniolib/llms.txt Opens a handle to the PawnIO kernel driver device using `pawnio_open`. This handle is necessary for subsequent operations. The function requires `` and returns an `HRESULT`. The handle must be closed with `pawnio_close` when no longer needed. ```c #include #include int main() { HANDLE handle = NULL; HRESULT hr = pawnio_open(&handle); if (SUCCEEDED(hr)) { printf("Successfully opened PawnIO device, handle: %p\n", handle); // Perform operations with handle... // Always close when done hr = pawnio_close(handle); if (FAILED(hr)) { fprintf(stderr, "Failed to close handle: 0x%lx\n", hr); return 1; } } else { fprintf(stderr, "Failed to open PawnIO device: 0x%lx\n", hr); fprintf(stderr, "Ensure the PawnIO driver is installed and running\n"); return 1; } return 0; } ``` -------------------------------- ### Execute Function Synchronously Source: https://context7.com/namazso/pawniolib/llms.txt This function executes a named function from the loaded AMX binary with specified input and output buffers. It provides a direct, blocking call to the function. ```APIDOC ## pawnio_execute ### Description Executes a named function from the loaded AMX binary with input/output buffers. ### Method `pawnio_execute` ### Parameters #### Function Parameters - **handle** (`HANDLE`) - Handle to the pawnio device. - **function_name** (`const char*`) - The name of the function to execute. - **input_params** (`const ULONG64*`) - Pointer to an array of input parameters. - **input_count** (`SIZE_T`) - The number of input parameters. - **output_buffer** (`ULONG64*`) - Pointer to a buffer for output values. - **output_count** (`SIZE_T`) - The maximum number of output values to retrieve. - **returned_count** (`SIZE_T*`) - Pointer to a variable that will receive the actual number of returned values. ### Request Example ```c #include #include #include int main() { HANDLE handle = NULL; HRESULT hr = pawnio_open(&handle); if (FAILED(hr)) { fprintf(stderr, "Failed to open device: 0x%lx\n", hr); return 1; } // Load binary (blob loading code omitted for brevity) // UCHAR* blob = ...; SIZE_T blob_size = ...; // hr = pawnio_load(handle, blob, blob_size); // Prepare input parameters (example: two 64-bit integers) ULONG64 input_params[2] = { 42, 100 }; SIZE_T input_count = 2; // Prepare output buffer (expecting 1 return value) ULONG64 output_buffer[1] = { 0 }; SIZE_T output_count = 1; SIZE_T returned_count = 0; // Execute function named "calculate" hr = pawnio_execute( handle, "calculate", input_params, input_count, output_buffer, output_count, &returned_count ); if (SUCCEEDED(hr)) { printf("Function executed successfully\n"); printf("Returned %zu values:\n", returned_count); for (SIZE_T i = 0; i < returned_count; i++) { printf(" [%%zu] = 0x%%016llX (%%lld)\n", i, output_buffer[i], output_buffer[i]); } } else { fprintf(stderr, "Execution failed: 0x%lx\n", hr); fprintf(stderr, "Function name may not exist in binary\n"); } pawnio_close(handle); return FAILED(hr) ? 1 : 0; } ``` ### Response #### Success Response (0 or S_OK) - **returned_count** (`SIZE_T`) - The actual number of values returned by the function. - **output_buffer** (`ULONG64*`) - Contains the output values from the function. #### Response Example ```json { "returned_count": 1, "output_buffer": [142] } ``` #### Error Response - **HRESULT** - An error code indicating the failure reason (e.g., function not found, invalid parameters). #### Error Example ``` Execution failed: 0x80070057 Function name may not exist in binary ``` ``` -------------------------------- ### Open PawnIO Device Handle Source: https://context7.com/namazso/pawniolib/llms.txt Opens a handle to the PawnIO kernel driver device. This handle is required for all subsequent operations with the PawnIO driver. ```APIDOC ## POST /pawnio/open ### Description Opens a handle to the PawnIO kernel driver device for subsequent operations. ### Method POST ### Endpoint /pawnio/open ### Parameters #### Query Parameters None #### Path Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **handle** (HANDLE) - A handle to the PawnIO device. This handle must be closed when no longer needed. #### Response Example ```json { "handle": "0x1234567890ABCDEF" } ``` #### Error Response (e.g., 500) - **error** (string) - Description of the error, e.g., 'Driver not installed or running'. ``` -------------------------------- ### RSA Signature Calculation in C++ Source: https://context7.com/namazso/pawniolib/llms.txt This C++ code snippet illustrates the internal API usage for calculating an RSA signature with SHA256 hashing. It involves reading a PEM private key, providing binary data to sign, and receiving the resulting signature. The process uses the BCrypt API for hashing and RSA-PKCS1 padding for the signature. ```c++ #include #include // Function prototype (internal to PawnIOUtil) DWORD sign(const char* pem, const uint8_t* data, size_t len, std::vector& signature); int example_usage() { // Read PEM private key const char* pem_key = "-----BEGIN RSA PRIVATE KEY-----\\n" "MIIEpAIBAAKCAQEA...\\n" "-----END RSA PRIVATE KEY-----\\n"; // Binary data to sign uint8_t amx_data[] = { 0xE1, 0xF1, /* ... AMX binary ... */ }; size_t amx_size = sizeof(amx_data); // Generate signature std::vector signature; DWORD result = sign(pem_key, amx_data, amx_size, signature); if (result == ERROR_SUCCESS) { printf("Signature generated: %zu bytes\n", signature.size()); printf("SHA256 hash computed using BCrypt API\n"); printf("RSA-PKCS1 signature with SHA256 padding\n"); // Signature can now be prepended to AMX binary // Format: [sig_len(4)] [signature] [amx_data] } else { fprintf(stderr, "Signature generation failed: %lu\n", result); return 1; } return 0; } ``` -------------------------------- ### Execute Function Asynchronously Source: https://context7.com/namazso/pawniolib/llms.txt This function executes a function asynchronously, utilizing Windows OVERLAPPED I/O for non-blocking operations. This allows your application to continue processing while the function executes. ```APIDOC ## pawnio_execute_async ### Description Executes a function asynchronously using Windows OVERLAPPED I/O for non-blocking operation. ### Method `pawnio_execute_async` ### Parameters #### Function Parameters - **handle** (`HANDLE`) - Handle to the pawnio device. - **function_name** (`const char*`) - The name of the function to execute. - **input_params** (`const ULONG64*`) - Pointer to an array of input parameters. - **input_count** (`SIZE_T`) - The number of input parameters. - **output_buffer** (`ULONG64*`) - Pointer to a buffer for output values. - **output_count** (`SIZE_T`) - The maximum number of output values to retrieve. - **overlapped** (`OVERLAPPED*`) - Pointer to an OVERLAPPED structure used for asynchronous operation. ### Request Example ```c #include #include int main() { HANDLE handle = NULL; HRESULT hr = pawnio_open(&handle); if (FAILED(hr)) { fprintf(stderr, "Failed to open device: 0x%lx\n", hr); return 1; } // Load binary (omitted for brevity) // Create event for async operation OVERLAPPED overlapped = { 0 }; overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!overlapped.hEvent) { fprintf(stderr, "Failed to create event\n"); pawnio_close(handle); return 1; } ULONG64 input[1] = { 123 }; ULONG64 output[10] = { 0 }; // Start async execution hr = pawnio_execute_async( handle, "process_async", input, 1, output, 10, &overlapped ); if (hr == S_OK) { printf("Operation completed synchronously\n"); } else if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING)) { printf("Operation pending, waiting...\n"); // Wait for completion DWORD wait_result = WaitForSingleObject(overlapped.hEvent, 5000); if (wait_result == WAIT_OBJECT_0) { SIZE_T bytes_returned = overlapped.InternalHigh; SIZE_T cells_returned = bytes_returned / sizeof(ULONG64); printf("Async operation completed, %zu cells returned\n", cells_returned); for (SIZE_T i = 0; i < cells_returned; i++) { printf(" output[%%zu] = %%lld\n", i, output[i]); } } else { fprintf(stderr, "Wait failed or timed out\n"); } } else { fprintf(stderr, "Async execute failed: 0x%lx\n", hr); } CloseHandle(overlapped.hEvent); pawnio_close(handle); return 0; } ``` ### Response #### Success Response (S_OK or ERROR_IO_PENDING) - **S_OK**: Indicates the operation completed synchronously. - **ERROR_IO_PENDING**: Indicates the operation is pending and will complete asynchronously. #### Response Example (if ERROR_IO_PENDING) ```json { "status": "pending", "message": "Operation pending, waiting..." } ``` #### Response Example (after waiting for completion) ```json { "status": "completed", "cells_returned": 3, "output_buffer": [10, 20, 30] } ``` #### Error Response - **HRESULT** - An error code indicating the failure reason (e.g., device not open, invalid parameters). #### Error Example ``` Async execute failed: 0x80070005 ``` ``` -------------------------------- ### Close PawnIO Device Handle Source: https://context7.com/namazso/pawniolib/llms.txt Closes the handle to the PawnIO kernel driver device, releasing associated resources. ```APIDOC ## POST /pawnio/close ### Description Closes the handle to the PawnIO kernel driver device. ### Method POST ### Endpoint /pawnio/close ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **handle** (HANDLE) - Required - The handle to be closed, obtained from `pawnio_open`. ### Request Example ```json { "handle": "0x1234567890ABCDEF" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating successful closure. #### Response Example ```json { "message": "PawnIO device handle closed successfully." } ``` #### Error Response (e.g., 500) - **error** (string) - Description of the error. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.