Skip to content
Open
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
16 changes: 8 additions & 8 deletions includes/leechcore_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions leechcore_device_devmem/leechcore_device_devmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions leechcore_device_hvsavedstate/leechcore_device_hvsavedstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -396,15 +396,15 @@ BOOL DeviceHvSavedState_Init(_In_ PLC_CONTEXT ctxLC, _Inout_ PHVSAVEDSTATE_CONTE
if(ctx->fn.GetRegisterValue(ctx->hVmSavedStateDumpHandle, vpId, &reg) == 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;
reg.RegisterId = ctx->architecture == Arch_x64 ? X64_RegisterRip : X86_RegisterEip;
if(ctx->fn.GetRegisterValue(ctx->hVmSavedStateDumpHandle, vpId, &reg) != 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");
Expand Down
46 changes: 23 additions & 23 deletions leechcore_ft601_driver_linux/fpga_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
printf("[-] cannot get chip config: %s\n", libusb_strerror(err));
rc = -1;
}

Expand Down Expand Up @@ -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));
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) {
vprintfv("[-] Cannot get device list: %s\n", libusb_strerror(device_count));
printf("[-] Cannot get device list: %s\n", libusb_strerror(device_count));
goto fail;
}

Expand All @@ -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));
printf("[-] Cannot get device descriptor: %s\n", libusb_strerror(err));
goto fail;
}

Expand All @@ -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));
printf("[-] Cannot open device: %s\n", libusb_strerror(err));
goto fail;
}

Expand All @@ -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));
printf("[-] Cannot get chip configuration: %s\n", libusb_strerror(err));
goto fail;
}

Expand All @@ -269,41 +269,41 @@ 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));
printf("[-] Cannot set chip configuration: %s\n", libusb_strerror(err));
goto fail;
}

}

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));
printf("[-] 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);
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) {
vprintfv("[-] 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) {
vprintfv("[-] 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) {
vprintfv("[-] 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) {
vprintfv("[-] 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;
Expand Down Expand Up @@ -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));
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) {
vprintfv("[-] bulk transfer error: %s", libusb_strerror(err));
printf("[-] bulk transfer error: %s", libusb_strerror(err));
return -1;
}

Expand All @@ -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");
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);
Expand All @@ -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));
printf("[-] bulk transfer error: %s", libusb_strerror(err));
return -1;
}

if(*transferred != size) {
vprintfv("[-] only %d bytes transferred\n", *transferred);
printf("[-] only %d bytes transferred\n", *transferred);
return -1;
}

Expand Down Expand Up @@ -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");
printf("[-] only one async overlapped supported. close previous one before open new!\n");
return -1;
}

Expand All @@ -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");
printf("[-] failed creating thread.\n");
memset(&ctx->async, 0, sizeof(ctx->async));
return -1;
}
Expand All @@ -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");
printf("[-] 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");
printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n");
return -1;
}
ctx->async.data = data;
Expand All @@ -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");
printf("[-] invalid context!\n");
return -1;
}
if(ctx->async.is_thread_read) {
Expand Down
22 changes: 10 additions & 12 deletions leechcore_ft601_driver_linux_ftdi/fpga_ft601.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
printf("[-] Unable to open library: 'libftd3xx.so'\n");
goto fail;
}

Expand All @@ -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");
printf("[-] Unable to find function in library\n");
goto fail;
}

Expand All @@ -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);
printf("[-] Unable to create device (rc = %i)\n", rc);
goto fail;
}

Expand Down Expand Up @@ -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");
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) {
Expand Down Expand Up @@ -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);
printf("[-] bulk transfer error: %i \n", rc);
return -1;
}
return 0;
Expand All @@ -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");
printf("[-] only one async overlapped supported. close previous one before open new!\n");
return -1;
}
ctx->async.is_result = 1;
Expand All @@ -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");
printf("[-] failed creating thread.\n");
memset(&ctx->async, 0, sizeof(ctx->async));
return -1;
}
Expand All @@ -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");
printf("[-] 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");
printf("[-] previous async read is not yet completed. complete by reading results before initiating new read!\n");
return -1;
}
ctx->async.data = data;
Expand All @@ -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");
printf("[-] invalid context!\n");
return -1;
}
if(ctx->async.is_thread_read) {
Expand Down
Loading
Loading