From 58affff114b06b37e0c4ee8c897569a40d7da774 Mon Sep 17 00:00:00 2001 From: Remco Poelstra Date: Thu, 4 Jun 2026 09:52:49 +0200 Subject: [PATCH 1/3] Make sure error messages are always shown --- .../leechcore_device_devmem.c | 4 +- .../leechcore_device_hvsavedstate.c | 6 +-- leechcore_ft601_driver_linux/fpga_libusb.c | 46 +++++++++---------- .../fpga_ft601.c | 22 ++++----- leechcore_ft601_driver_macos/fpga_ft601.c | 22 ++++----- 5 files changed, 48 insertions(+), 52 deletions(-) diff --git a/leechcore_device_devmem/leechcore_device_devmem.c b/leechcore_device_devmem/leechcore_device_devmem.c index b70ed9e..ad1849f 100644 --- a/leechcore_device_devmem/leechcore_device_devmem.c +++ b/leechcore_device_devmem/leechcore_device_devmem.c @@ -17,7 +17,7 @@ static VOID DeviceDevmem_ReadContigious(PLC_READ_CONTIGIOUS_CONTEXT ctxRC) { lseek(fd, ctxRC->paBase, SEEK_SET); if ((bytes_read = read(fd, ctxRC->pb, ctxRC->cb)) < 0) { - lcprintfvvv(ctxRC->ctxLC, "Failed to read physical memory at 0x%llx (error %d)\n", + lcprintf(ctxRC->ctxLC, "Failed to read physical memory at 0x%llx (error %d)\n", ctxRC->paBase, bytes_read); } ctxRC->cbRead = (DWORD)bytes_read; @@ -30,7 +30,7 @@ static BOOL DeviceDevmem_WriteContigious(_In_ PLC_CONTEXT ctxLC, int fd = (intptr_t)ctxLC->hDevice; lseek(fd, qwAddr, SEEK_SET); if ((bytes_written = write(fd, pb, cb)) < 0) { - lcprintfvvv(ctxLC, "Failed to write physical memory at 0x%llx (error %d)\n", + lcprintf(ctxLC, "Failed to write physical memory at 0x%llx (error %d)\n", qwAddr, bytes_written); return false; } diff --git a/leechcore_device_hvsavedstate/leechcore_device_hvsavedstate.c b/leechcore_device_hvsavedstate/leechcore_device_hvsavedstate.c index 548e80c..41d331e 100644 --- a/leechcore_device_hvsavedstate/leechcore_device_hvsavedstate.c +++ b/leechcore_device_hvsavedstate/leechcore_device_hvsavedstate.c @@ -387,7 +387,7 @@ BOOL DeviceHvSavedState_Init(_In_ PLC_CONTEXT ctxLC, _Inout_ PHVSAVEDSTATE_CONTE UINT32 vpId = 0; if(ctx->fn.GetArchitecture(ctx->hVmSavedStateDumpHandle, vpId, &ctx->architecture) != S_OK) { - lcprintfvv_fn(ctxLC, "ERROR: GetPagingMode() failed.\n"); + lcprintf_fn(ctxLC, "ERROR: GetPagingMode() failed.\n"); return FALSE; } @@ -396,7 +396,7 @@ BOOL DeviceHvSavedState_Init(_In_ PLC_CONTEXT ctxLC, _Inout_ PHVSAVEDSTATE_CONTE if(ctx->fn.GetRegisterValue(ctx->hVmSavedStateDumpHandle, vpId, ®) == S_OK) { ctx->regCr3 = reg.RegisterValue; } else { - lcprintfvv_fn(ctxLC, "ERROR: GetPagingMode(Cr3) failed.\n"); + lcprintf_fn(ctxLC, "ERROR: GetPagingMode(Cr3) failed.\n"); } reg.Architecture = ctx->architecture; @@ -404,7 +404,7 @@ BOOL DeviceHvSavedState_Init(_In_ PLC_CONTEXT ctxLC, _Inout_ PHVSAVEDSTATE_CONTE if(ctx->fn.GetRegisterValue(ctx->hVmSavedStateDumpHandle, vpId, ®) != S_OK) { ctx->regRip = reg.RegisterValue; } else { - lcprintfvv_fn(ctxLC, "ERROR: GetPagingMode() failed.\n"); + lcprintf_fn(ctxLC, "ERROR: GetPagingMode() failed.\n"); } lcprintfv(ctxLC, "[%d] VP Architecture %s\n", vpId, ctx->architecture == Arch_x64 ? "x64" : "x86"); diff --git a/leechcore_ft601_driver_linux/fpga_libusb.c b/leechcore_ft601_driver_linux/fpga_libusb.c index 1a0c065..97e3a71 100644 --- a/leechcore_ft601_driver_linux/fpga_libusb.c +++ b/leechcore_ft601_driver_linux/fpga_libusb.c @@ -146,7 +146,7 @@ int fpga_get_chip_configuration(struct fpga_context *ctx, void *config) err = ftdi_GetChipConfiguration(ctx, config); if(err != sizeof(struct FT_60XCONFIGURATION)) { - vprintfv("[-] cannot get chip config: %s\n", libusb_strerror(err)); + vprintf("[-] cannot get chip config: %s\n", libusb_strerror(err)); rc = -1; } @@ -184,13 +184,13 @@ struct fpga_context* fpga_open(int device_index) err = libusb_init(&ctx->usb_ctx); if(err) { - vprintfv("[-] libusb_init failed: %s\n", libusb_strerror(err)); + vprintf("[-] libusb_init failed: %s\n", libusb_strerror(err)); goto fail; } device_count = libusb_get_device_list(ctx->usb_ctx, &device_list); if(device_count < 0) { - vprintfv("[-] Cannot get device list: %s\n", libusb_strerror(device_count)); + vprintf("[-] Cannot get device list: %s\n", libusb_strerror(device_count)); goto fail; } @@ -200,7 +200,7 @@ struct fpga_context* fpga_open(int device_index) err = libusb_get_device_descriptor(device, &desc); if(err) { - vprintfv("[-] Cannot get device descriptor: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot get device descriptor: %s\n", libusb_strerror(err)); goto fail; } @@ -225,7 +225,7 @@ struct fpga_context* fpga_open(int device_index) err = libusb_open(device, &ctx->device_handle); if(err) { - vprintfv("[-] Cannot open device: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot open device: %s\n", libusb_strerror(err)); goto fail; } @@ -252,7 +252,7 @@ struct fpga_context* fpga_open(int device_index) err = ftdi_GetChipConfiguration(ctx, &chip_configuration); if(err != sizeof(chip_configuration)) { - vprintfv("[-] Cannot get chip configuration: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot get chip configuration: %s\n", libusb_strerror(err)); goto fail; } @@ -269,7 +269,7 @@ struct fpga_context* fpga_open(int device_index) err = ftdi_SetChipConfiguration(ctx, &chip_configuration); if(err != sizeof(chip_configuration)) { - vprintfv("[-] Cannot set chip configuration: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot set chip configuration: %s\n", libusb_strerror(err)); goto fail; } @@ -277,33 +277,33 @@ struct fpga_context* fpga_open(int device_index) err = libusb_kernel_driver_active(ctx->device_handle, FTDI_COMMUNICATION_INTERFACE); if(err < 0) { - vprintfv("[-] Cannot get kernel driver status for FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot get kernel driver status for FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } if(err) { - vprintfv("[-] driver is active on FTDI_COMMUNICATION_INTERFACE = %d\n", err); + vprintf("[-] driver is active on FTDI_COMMUNICATION_INTERFACE = %d\n", err); goto fail; } err = libusb_kernel_driver_active(ctx->device_handle, FTDI_DATA_INTERFACE); if(err < 0) { - vprintfv("[-] Cannot get kernel driver status for FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot get kernel driver status for FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } if(err) { - vprintfv("[-] driver is active on FTDI_DATA_INTERFACE = %d\n", err); + vprintf("[-] driver is active on FTDI_DATA_INTERFACE = %d\n", err); goto fail; } err = libusb_claim_interface(ctx->device_handle, FTDI_COMMUNICATION_INTERFACE); if(err != 0) { - vprintfv("[-] Cannot claim interface FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot claim interface FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } err = libusb_claim_interface(ctx->device_handle, FTDI_DATA_INTERFACE); if(err != 0) { - vprintfv("[-] Cannot claim interface FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); + vprintf("[-] Cannot claim interface FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } return ctx; @@ -332,14 +332,14 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran err = ftdi_SendCmdRead(ctx, size); if(err) { - vprintfv("[-] cannot send CmdRead ftdi: %s", libusb_strerror(err)); + vprintf("[-] cannot send CmdRead ftdi: %s", libusb_strerror(err)); return -1; } *transferred = 0; err = libusb_bulk_transfer(ctx->device_handle, FTDI_ENDPOINT_IN, data, size, transferred, 0); if(err < 0) { - vprintfv("[-] bulk transfer error: %s", libusb_strerror(err)); + vprintf("[-] bulk transfer error: %s", libusb_strerror(err)); return -1; } @@ -349,7 +349,7 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran int fpga_read(struct fpga_context *ctx, void *data, int size, int *transferred) { if(ctx->async.is_thread_read) { - vprintfv("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } return fpga_read_internal(ctx, data, size, transferred); @@ -363,12 +363,12 @@ int fpga_write(struct fpga_context *ctx, void *data, int size, int *transferred) err = libusb_bulk_transfer(ctx->device_handle, FTDI_ENDPOINT_OUT, data, size, transferred, 1000); if(err < 0) { - vprintfv("[-] bulk transfer error: %s", libusb_strerror(err)); + vprintf("[-] bulk transfer error: %s", libusb_strerror(err)); return -1; } if(*transferred != size) { - vprintfv("[-] only %d bytes transferred\n", *transferred); + vprintf("[-] only %d bytes transferred\n", *transferred); return -1; } @@ -401,7 +401,7 @@ void* fpga_async_thread(void* thread_ctx) int fpga_async_init(struct fpga_context *ctx) { if(ctx->async.is_valid) { - vprintfv("[-] only one async overlapped supported. close previous one before open new!\n"); + vprintf("[-] only one async overlapped supported. close previous one before open new!\n"); return -1; } @@ -412,7 +412,7 @@ int fpga_async_init(struct fpga_context *ctx) pthread_create(&ctx->async.tid, NULL, fpga_async_thread, ctx); if(!ctx->async.tid) { - vprintfv("[-] failed creating thread.\n"); + vprintf("[-] failed creating thread.\n"); memset(&ctx->async, 0, sizeof(ctx->async)); return -1; } @@ -434,11 +434,11 @@ int fpga_async_close(struct fpga_context *ctx) int fpga_async_read(struct fpga_context *ctx, void *data, int size) { if(!ctx->async.is_valid) { - vprintfv("[-] invalid context!\n"); + vprintf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { - vprintfv("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } ctx->async.data = data; @@ -453,7 +453,7 @@ int fpga_async_read(struct fpga_context *ctx, void *data, int size) int fpga_async_result(struct fpga_context *ctx, uint32_t *transferred) { if(!ctx->async.is_valid) { - vprintfv("[-] invalid context!\n"); + vprintf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { diff --git a/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c b/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c index 2bd92c8..11df683 100644 --- a/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c +++ b/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c @@ -100,8 +100,6 @@ VOID ReleaseSRWLockExclusive(_Inout_ PSRWLOCK pSRWLock) // FPGA driver defines: // ---------------------------------------------------------------------------- -#define vprintfv(format, ...) { printf(format, ##__VA_ARGS__); } - struct fpga_context { void *lib; HANDLE ftHandle; @@ -155,7 +153,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // load lib: ctx->lib = dlopen("libftd3xx.so", RTLD_NOW); if(!ctx->lib) { - vprintfv("[-] Unable to open library: 'libftd3xx.so'\n"); + vprintf("[-] Unable to open library: 'libftd3xx.so'\n"); goto fail; } @@ -168,7 +166,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) ctx->pfn.pfnFT_WritePipe = (PFN_FT_WritePipe)dlsym(ctx->lib, "FT_WritePipe"); ctx->pfn.pfnFT_ReadPipe = (PFN_FT_ReadPipe)dlsym(ctx->lib, "FT_ReadPipe"); if(!ctx->pfn.pfnFT_AbortPipe || !ctx->pfn.pfnFT_Close || !ctx->pfn.pfnFT_Create || !ctx->pfn.pfnFT_GetChipConfiguration || !ctx->pfn.pfnFT_SetChipConfiguration || !ctx->pfn.pfnFT_WritePipe || !ctx->pfn.pfnFT_ReadPipe) { - vprintfv("[-] Unable to find function in library\n"); + vprintf("[-] Unable to find function in library\n"); goto fail; } @@ -178,7 +176,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // ft601 initialize handle: rc = ctx->pfn.pfnFT_Create(pvArg, dwFlags, &ctx->ftHandle); if(rc) { - vprintfv("[-] Unable to create device (rc = %i)\n", rc); + vprintf("[-] Unable to create device (rc = %i)\n", rc); goto fail; } @@ -219,7 +217,7 @@ uint32_t fpga_read(struct fpga_context *ctx, void *data, uint32_t size, uint32_t { uint32_t rc; if(ctx->async.is_thread_read) { - vprintfv("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return FT_OTHER_ERROR; } if(ctx->is_safe_mode) { @@ -270,7 +268,7 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran ReleaseSRWLockExclusive(&ctx->lock); } if(rc) { - vprintfv("[-] bulk transfer error: %i \n", rc); + vprintf("[-] bulk transfer error: %i \n", rc); return -1; } return 0; @@ -296,7 +294,7 @@ void* fpga_async_thread(void* thread_ctx) int fpga_async_init(struct fpga_context *ctx) { if(ctx->async.is_valid) { - vprintfv("[-] only one async overlapped supported. close previous one before open new!\n"); + vprintf("[-] only one async overlapped supported. close previous one before open new!\n"); return -1; } ctx->async.is_result = 1; @@ -305,7 +303,7 @@ int fpga_async_init(struct fpga_context *ctx) AcquireSRWLockExclusive(&ctx->async.lock_thread_read); pthread_create(&ctx->async.tid, NULL, fpga_async_thread, ctx); if(!ctx->async.tid) { - vprintfv("[-] failed creating thread.\n"); + vprintf("[-] failed creating thread.\n"); memset(&ctx->async, 0, sizeof(ctx->async)); return -1; } @@ -326,11 +324,11 @@ int fpga_async_close(struct fpga_context *ctx) int fpga_async_read(struct fpga_context *ctx, void *data, int size) { if(!ctx->async.is_valid) { - vprintfv("[-] invalid context!\n"); + vprintf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { - vprintfv("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } ctx->async.data = data; @@ -345,7 +343,7 @@ int fpga_async_read(struct fpga_context *ctx, void *data, int size) int fpga_async_result(struct fpga_context *ctx, uint32_t *transferred) { if(!ctx->async.is_valid) { - vprintfv("[-] invalid context!\n"); + vprintf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { diff --git a/leechcore_ft601_driver_macos/fpga_ft601.c b/leechcore_ft601_driver_macos/fpga_ft601.c index d5e1ffd..2305c94 100644 --- a/leechcore_ft601_driver_macos/fpga_ft601.c +++ b/leechcore_ft601_driver_macos/fpga_ft601.c @@ -71,8 +71,6 @@ VOID ReleaseSRWLockExclusive(_Inout_ PSRWLOCK pSRWLock) // FPGA driver defines: // ---------------------------------------------------------------------------- -#define vprintfv(format, ...) { printf(format, ##__VA_ARGS__); } - struct fpga_context { void *lib; HANDLE ftHandle; @@ -126,7 +124,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // load lib: ctx->lib = dlopen("libftd3xx.dylib", RTLD_NOW); if(!ctx->lib) { - vprintfv("[-] Unable to open library: 'libftd3xx.dylib'\n"); + vprintf("[-] Unable to open library: 'libftd3xx.dylib'\n"); goto fail; } @@ -139,7 +137,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) ctx->pfn.pfnFT_WritePipe = (PFN_FT_WritePipe)dlsym(ctx->lib, "FT_WritePipe"); ctx->pfn.pfnFT_ReadPipe = (PFN_FT_ReadPipe)dlsym(ctx->lib, "FT_ReadPipe"); if(!ctx->pfn.pfnFT_AbortPipe || !ctx->pfn.pfnFT_Close || !ctx->pfn.pfnFT_Create || !ctx->pfn.pfnFT_GetChipConfiguration || !ctx->pfn.pfnFT_SetChipConfiguration || !ctx->pfn.pfnFT_WritePipe || !ctx->pfn.pfnFT_ReadPipe) { - vprintfv("[-] Unable to find function in library\n"); + vprintf("[-] Unable to find function in library\n"); goto fail; } @@ -149,7 +147,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // ft601 initialize handle: rc = ctx->pfn.pfnFT_Create(pvArg, dwFlags, &ctx->ftHandle); if(rc) { - vprintfv("[-] Unable to create device (rc = %i)\n", rc); + vprintf("[-] Unable to create device (rc = %i)\n", rc); goto fail; } @@ -190,7 +188,7 @@ uint32_t fpga_read(struct fpga_context *ctx, void *data, uint32_t size, uint32_t { uint32_t rc; if(ctx->async.is_thread_read) { - vprintfv("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return FT_OTHER_ERROR; } if(ctx->is_safe_mode) { @@ -241,7 +239,7 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran ReleaseSRWLockExclusive(&ctx->lock); } if(rc) { - vprintfv("[-] bulk transfer error: %i \n", rc); + vprintf("[-] bulk transfer error: %i \n", rc); return -1; } return 0; @@ -267,7 +265,7 @@ void* fpga_async_thread(void* thread_ctx) int fpga_async_init(struct fpga_context *ctx) { if(ctx->async.is_valid) { - vprintfv("[-] only one async overlapped supported. close previous one before open new!\n"); + vprintf("[-] only one async overlapped supported. close previous one before open new!\n"); return -1; } ctx->async.is_result = 1; @@ -276,7 +274,7 @@ int fpga_async_init(struct fpga_context *ctx) AcquireSRWLockExclusive(&ctx->async.lock_thread_read); pthread_create(&ctx->async.tid, NULL, fpga_async_thread, ctx); if(!ctx->async.tid) { - vprintfv("[-] failed creating thread.\n"); + vprintf("[-] failed creating thread.\n"); memset(&ctx->async, 0, sizeof(ctx->async)); return -1; } @@ -297,11 +295,11 @@ int fpga_async_close(struct fpga_context *ctx) int fpga_async_read(struct fpga_context *ctx, void *data, int size) { if(!ctx->async.is_valid) { - vprintfv("[-] invalid context!\n"); + vprintf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { - vprintfv("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } ctx->async.data = data; @@ -316,7 +314,7 @@ int fpga_async_read(struct fpga_context *ctx, void *data, int size) int fpga_async_result(struct fpga_context *ctx, uint32_t *transferred) { if(!ctx->async.is_valid) { - vprintfv("[-] invalid context!\n"); + vprintf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { From c9ff1eb01598b36350f04af457f9bf007b07969c Mon Sep 17 00:00:00 2001 From: Remco Poelstra Date: Thu, 4 Jun 2026 10:22:44 +0200 Subject: [PATCH 2/3] Use constants --- includes/leechcore_device.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/leechcore_device.h b/includes/leechcore_device.h index 3fccf11..3889df3 100644 --- a/includes/leechcore_device.h +++ b/includes/leechcore_device.h @@ -139,14 +139,14 @@ EXPORTED_FUNCTION PLC_DEVICE_PARAMETER_ENTRY LcDeviceParameterGet(_In_ PLC_CONTE */ EXPORTED_FUNCTION QWORD LcDeviceParameterGetNumeric(_In_ PLC_CONTEXT ctxLC, _In_ LPSTR szName); -#define lcprintf(ctxLC, _Format, ...) { if(ctxLC->fPrintf[0]) { ctxLC->Config.pfn_printf_opt ? ctxLC->Config.pfn_printf_opt(_Format, ##__VA_ARGS__) : printf(_Format, ##__VA_ARGS__); } } -#define lcprintfv(ctxLC, _Format, ...) { if(ctxLC->fPrintf[1]) { lcprintf(ctxLC, _Format, ##__VA_ARGS__); } } -#define lcprintfvv(ctxLC, _Format, ...) { if(ctxLC->fPrintf[2]) { lcprintf(ctxLC, _Format, ##__VA_ARGS__); } } -#define lcprintfvvv(ctxLC, _Format, ...) { if(ctxLC->fPrintf[3]) { lcprintf(ctxLC, _Format, ##__VA_ARGS__); } } -#define lcprintf_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[0]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } -#define lcprintfv_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[1]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } -#define lcprintfvv_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[2]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } -#define lcprintfvvv_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[3]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } +#define lcprintf(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_ENABLE]) { ctxLC->Config.pfn_printf_opt ? ctxLC->Config.pfn_printf_opt(_Format, ##__VA_ARGS__) : printf(_Format, ##__VA_ARGS__); } } +#define lcprintfv(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_V]) { lcprintf(ctxLC, _Format, ##__VA_ARGS__); } } +#define lcprintfvv(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_VV]) { lcprintf(ctxLC, _Format, ##__VA_ARGS__); } } +#define lcprintfvvv(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_VVV]) { lcprintf(ctxLC, _Format, ##__VA_ARGS__); } } +#define lcprintf_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_ENABLE]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } +#define lcprintfv_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_V]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } +#define lcprintfvv_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_VV]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } +#define lcprintfvvv_fn(ctxLC, _Format, ...) { if(ctxLC->fPrintf[LC_PRINTF_VVV]) { lcprintf(ctxLC, "%s: "_Format, __func__, ##__VA_ARGS__); } } /* * Check whether the memory map is initialized or not. From 6fe25df87138d8e76cf989fbd0eb38eb6b951439 Mon Sep 17 00:00:00 2001 From: Remco Poelstra Date: Thu, 4 Jun 2026 12:46:57 +0200 Subject: [PATCH 3/3] Use correct printf function --- leechcore_ft601_driver_linux/fpga_libusb.c | 46 +++++++++---------- .../fpga_ft601.c | 20 ++++---- leechcore_ft601_driver_macos/fpga_ft601.c | 20 ++++---- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/leechcore_ft601_driver_linux/fpga_libusb.c b/leechcore_ft601_driver_linux/fpga_libusb.c index 97e3a71..f1de7b9 100644 --- a/leechcore_ft601_driver_linux/fpga_libusb.c +++ b/leechcore_ft601_driver_linux/fpga_libusb.c @@ -146,7 +146,7 @@ int fpga_get_chip_configuration(struct fpga_context *ctx, void *config) err = ftdi_GetChipConfiguration(ctx, config); if(err != sizeof(struct FT_60XCONFIGURATION)) { - vprintf("[-] cannot get chip config: %s\n", libusb_strerror(err)); + printf("[-] cannot get chip config: %s\n", libusb_strerror(err)); rc = -1; } @@ -184,13 +184,13 @@ struct fpga_context* fpga_open(int device_index) err = libusb_init(&ctx->usb_ctx); if(err) { - vprintf("[-] libusb_init failed: %s\n", libusb_strerror(err)); + printf("[-] libusb_init failed: %s\n", libusb_strerror(err)); goto fail; } device_count = libusb_get_device_list(ctx->usb_ctx, &device_list); if(device_count < 0) { - vprintf("[-] Cannot get device list: %s\n", libusb_strerror(device_count)); + printf("[-] Cannot get device list: %s\n", libusb_strerror(device_count)); goto fail; } @@ -200,7 +200,7 @@ struct fpga_context* fpga_open(int device_index) err = libusb_get_device_descriptor(device, &desc); if(err) { - vprintf("[-] Cannot get device descriptor: %s\n", libusb_strerror(err)); + printf("[-] Cannot get device descriptor: %s\n", libusb_strerror(err)); goto fail; } @@ -225,7 +225,7 @@ struct fpga_context* fpga_open(int device_index) err = libusb_open(device, &ctx->device_handle); if(err) { - vprintf("[-] Cannot open device: %s\n", libusb_strerror(err)); + printf("[-] Cannot open device: %s\n", libusb_strerror(err)); goto fail; } @@ -252,7 +252,7 @@ struct fpga_context* fpga_open(int device_index) err = ftdi_GetChipConfiguration(ctx, &chip_configuration); if(err != sizeof(chip_configuration)) { - vprintf("[-] Cannot get chip configuration: %s\n", libusb_strerror(err)); + printf("[-] Cannot get chip configuration: %s\n", libusb_strerror(err)); goto fail; } @@ -269,7 +269,7 @@ struct fpga_context* fpga_open(int device_index) err = ftdi_SetChipConfiguration(ctx, &chip_configuration); if(err != sizeof(chip_configuration)) { - vprintf("[-] Cannot set chip configuration: %s\n", libusb_strerror(err)); + printf("[-] Cannot set chip configuration: %s\n", libusb_strerror(err)); goto fail; } @@ -277,33 +277,33 @@ struct fpga_context* fpga_open(int device_index) err = libusb_kernel_driver_active(ctx->device_handle, FTDI_COMMUNICATION_INTERFACE); if(err < 0) { - vprintf("[-] Cannot get kernel driver status for FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); + printf("[-] Cannot get kernel driver status for FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } if(err) { - vprintf("[-] driver is active on FTDI_COMMUNICATION_INTERFACE = %d\n", err); + printf("[-] driver is active on FTDI_COMMUNICATION_INTERFACE = %d\n", err); goto fail; } err = libusb_kernel_driver_active(ctx->device_handle, FTDI_DATA_INTERFACE); if(err < 0) { - vprintf("[-] Cannot get kernel driver status for FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); + printf("[-] Cannot get kernel driver status for FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } if(err) { - vprintf("[-] driver is active on FTDI_DATA_INTERFACE = %d\n", err); + printf("[-] driver is active on FTDI_DATA_INTERFACE = %d\n", err); goto fail; } err = libusb_claim_interface(ctx->device_handle, FTDI_COMMUNICATION_INTERFACE); if(err != 0) { - vprintf("[-] Cannot claim interface FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); + printf("[-] Cannot claim interface FTDI_COMMUNICATION_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } err = libusb_claim_interface(ctx->device_handle, FTDI_DATA_INTERFACE); if(err != 0) { - vprintf("[-] Cannot claim interface FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); + printf("[-] Cannot claim interface FTDI_DATA_INTERFACE: %s\n", libusb_strerror(err)); goto fail; } return ctx; @@ -332,14 +332,14 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran err = ftdi_SendCmdRead(ctx, size); if(err) { - vprintf("[-] cannot send CmdRead ftdi: %s", libusb_strerror(err)); + printf("[-] cannot send CmdRead ftdi: %s", libusb_strerror(err)); return -1; } *transferred = 0; err = libusb_bulk_transfer(ctx->device_handle, FTDI_ENDPOINT_IN, data, size, transferred, 0); if(err < 0) { - vprintf("[-] bulk transfer error: %s", libusb_strerror(err)); + printf("[-] bulk transfer error: %s", libusb_strerror(err)); return -1; } @@ -349,7 +349,7 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran int fpga_read(struct fpga_context *ctx, void *data, int size, int *transferred) { if(ctx->async.is_thread_read) { - vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } return fpga_read_internal(ctx, data, size, transferred); @@ -363,12 +363,12 @@ int fpga_write(struct fpga_context *ctx, void *data, int size, int *transferred) err = libusb_bulk_transfer(ctx->device_handle, FTDI_ENDPOINT_OUT, data, size, transferred, 1000); if(err < 0) { - vprintf("[-] bulk transfer error: %s", libusb_strerror(err)); + printf("[-] bulk transfer error: %s", libusb_strerror(err)); return -1; } if(*transferred != size) { - vprintf("[-] only %d bytes transferred\n", *transferred); + printf("[-] only %d bytes transferred\n", *transferred); return -1; } @@ -401,7 +401,7 @@ void* fpga_async_thread(void* thread_ctx) int fpga_async_init(struct fpga_context *ctx) { if(ctx->async.is_valid) { - vprintf("[-] only one async overlapped supported. close previous one before open new!\n"); + printf("[-] only one async overlapped supported. close previous one before open new!\n"); return -1; } @@ -412,7 +412,7 @@ int fpga_async_init(struct fpga_context *ctx) pthread_create(&ctx->async.tid, NULL, fpga_async_thread, ctx); if(!ctx->async.tid) { - vprintf("[-] failed creating thread.\n"); + printf("[-] failed creating thread.\n"); memset(&ctx->async, 0, sizeof(ctx->async)); return -1; } @@ -434,11 +434,11 @@ int fpga_async_close(struct fpga_context *ctx) int fpga_async_read(struct fpga_context *ctx, void *data, int size) { if(!ctx->async.is_valid) { - vprintf("[-] invalid context!\n"); + printf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { - vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } ctx->async.data = data; @@ -453,7 +453,7 @@ int fpga_async_read(struct fpga_context *ctx, void *data, int size) int fpga_async_result(struct fpga_context *ctx, uint32_t *transferred) { if(!ctx->async.is_valid) { - vprintf("[-] invalid context!\n"); + printf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { diff --git a/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c b/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c index 11df683..c8c96c7 100644 --- a/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c +++ b/leechcore_ft601_driver_linux_ftdi/fpga_ft601.c @@ -153,7 +153,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // load lib: ctx->lib = dlopen("libftd3xx.so", RTLD_NOW); if(!ctx->lib) { - vprintf("[-] Unable to open library: 'libftd3xx.so'\n"); + printf("[-] Unable to open library: 'libftd3xx.so'\n"); goto fail; } @@ -166,7 +166,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) ctx->pfn.pfnFT_WritePipe = (PFN_FT_WritePipe)dlsym(ctx->lib, "FT_WritePipe"); ctx->pfn.pfnFT_ReadPipe = (PFN_FT_ReadPipe)dlsym(ctx->lib, "FT_ReadPipe"); if(!ctx->pfn.pfnFT_AbortPipe || !ctx->pfn.pfnFT_Close || !ctx->pfn.pfnFT_Create || !ctx->pfn.pfnFT_GetChipConfiguration || !ctx->pfn.pfnFT_SetChipConfiguration || !ctx->pfn.pfnFT_WritePipe || !ctx->pfn.pfnFT_ReadPipe) { - vprintf("[-] Unable to find function in library\n"); + printf("[-] Unable to find function in library\n"); goto fail; } @@ -176,7 +176,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // ft601 initialize handle: rc = ctx->pfn.pfnFT_Create(pvArg, dwFlags, &ctx->ftHandle); if(rc) { - vprintf("[-] Unable to create device (rc = %i)\n", rc); + printf("[-] Unable to create device (rc = %i)\n", rc); goto fail; } @@ -217,7 +217,7 @@ uint32_t fpga_read(struct fpga_context *ctx, void *data, uint32_t size, uint32_t { uint32_t rc; if(ctx->async.is_thread_read) { - vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return FT_OTHER_ERROR; } if(ctx->is_safe_mode) { @@ -268,7 +268,7 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran ReleaseSRWLockExclusive(&ctx->lock); } if(rc) { - vprintf("[-] bulk transfer error: %i \n", rc); + printf("[-] bulk transfer error: %i \n", rc); return -1; } return 0; @@ -294,7 +294,7 @@ void* fpga_async_thread(void* thread_ctx) int fpga_async_init(struct fpga_context *ctx) { if(ctx->async.is_valid) { - vprintf("[-] only one async overlapped supported. close previous one before open new!\n"); + printf("[-] only one async overlapped supported. close previous one before open new!\n"); return -1; } ctx->async.is_result = 1; @@ -303,7 +303,7 @@ int fpga_async_init(struct fpga_context *ctx) AcquireSRWLockExclusive(&ctx->async.lock_thread_read); pthread_create(&ctx->async.tid, NULL, fpga_async_thread, ctx); if(!ctx->async.tid) { - vprintf("[-] failed creating thread.\n"); + printf("[-] failed creating thread.\n"); memset(&ctx->async, 0, sizeof(ctx->async)); return -1; } @@ -324,11 +324,11 @@ int fpga_async_close(struct fpga_context *ctx) int fpga_async_read(struct fpga_context *ctx, void *data, int size) { if(!ctx->async.is_valid) { - vprintf("[-] invalid context!\n"); + printf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { - vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } ctx->async.data = data; @@ -343,7 +343,7 @@ int fpga_async_read(struct fpga_context *ctx, void *data, int size) int fpga_async_result(struct fpga_context *ctx, uint32_t *transferred) { if(!ctx->async.is_valid) { - vprintf("[-] invalid context!\n"); + printf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { diff --git a/leechcore_ft601_driver_macos/fpga_ft601.c b/leechcore_ft601_driver_macos/fpga_ft601.c index 2305c94..5d5eb77 100644 --- a/leechcore_ft601_driver_macos/fpga_ft601.c +++ b/leechcore_ft601_driver_macos/fpga_ft601.c @@ -124,7 +124,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // load lib: ctx->lib = dlopen("libftd3xx.dylib", RTLD_NOW); if(!ctx->lib) { - vprintf("[-] Unable to open library: 'libftd3xx.dylib'\n"); + printf("[-] Unable to open library: 'libftd3xx.dylib'\n"); goto fail; } @@ -137,7 +137,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) ctx->pfn.pfnFT_WritePipe = (PFN_FT_WritePipe)dlsym(ctx->lib, "FT_WritePipe"); ctx->pfn.pfnFT_ReadPipe = (PFN_FT_ReadPipe)dlsym(ctx->lib, "FT_ReadPipe"); if(!ctx->pfn.pfnFT_AbortPipe || !ctx->pfn.pfnFT_Close || !ctx->pfn.pfnFT_Create || !ctx->pfn.pfnFT_GetChipConfiguration || !ctx->pfn.pfnFT_SetChipConfiguration || !ctx->pfn.pfnFT_WritePipe || !ctx->pfn.pfnFT_ReadPipe) { - vprintf("[-] Unable to find function in library\n"); + printf("[-] Unable to find function in library\n"); goto fail; } @@ -147,7 +147,7 @@ struct fpga_context *fpga_open(void *pvArg, uint32_t dwFlags) // ft601 initialize handle: rc = ctx->pfn.pfnFT_Create(pvArg, dwFlags, &ctx->ftHandle); if(rc) { - vprintf("[-] Unable to create device (rc = %i)\n", rc); + printf("[-] Unable to create device (rc = %i)\n", rc); goto fail; } @@ -188,7 +188,7 @@ uint32_t fpga_read(struct fpga_context *ctx, void *data, uint32_t size, uint32_t { uint32_t rc; if(ctx->async.is_thread_read) { - vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return FT_OTHER_ERROR; } if(ctx->is_safe_mode) { @@ -239,7 +239,7 @@ int fpga_read_internal(struct fpga_context *ctx, void *data, int size, int *tran ReleaseSRWLockExclusive(&ctx->lock); } if(rc) { - vprintf("[-] bulk transfer error: %i \n", rc); + printf("[-] bulk transfer error: %i \n", rc); return -1; } return 0; @@ -265,7 +265,7 @@ void* fpga_async_thread(void* thread_ctx) int fpga_async_init(struct fpga_context *ctx) { if(ctx->async.is_valid) { - vprintf("[-] only one async overlapped supported. close previous one before open new!\n"); + printf("[-] only one async overlapped supported. close previous one before open new!\n"); return -1; } ctx->async.is_result = 1; @@ -274,7 +274,7 @@ int fpga_async_init(struct fpga_context *ctx) AcquireSRWLockExclusive(&ctx->async.lock_thread_read); pthread_create(&ctx->async.tid, NULL, fpga_async_thread, ctx); if(!ctx->async.tid) { - vprintf("[-] failed creating thread.\n"); + printf("[-] failed creating thread.\n"); memset(&ctx->async, 0, sizeof(ctx->async)); return -1; } @@ -295,11 +295,11 @@ int fpga_async_close(struct fpga_context *ctx) int fpga_async_read(struct fpga_context *ctx, void *data, int size) { if(!ctx->async.is_valid) { - vprintf("[-] invalid context!\n"); + printf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) { - vprintf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); + printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n"); return -1; } ctx->async.data = data; @@ -314,7 +314,7 @@ int fpga_async_read(struct fpga_context *ctx, void *data, int size) int fpga_async_result(struct fpga_context *ctx, uint32_t *transferred) { if(!ctx->async.is_valid) { - vprintf("[-] invalid context!\n"); + printf("[-] invalid context!\n"); return -1; } if(ctx->async.is_thread_read) {