From ce8a6fde0a1b5c4c46eacee64d69306b8ac80125 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Tue, 14 May 2019 15:25:36 +0200 Subject: [PATCH] Fix status screen current password query --- include/backend.h | 2 ++ src/backend.c | 77 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/include/backend.h b/include/backend.h index e2ea51fb7..c74faa84d 100644 --- a/include/backend.h +++ b/include/backend.h @@ -71,6 +71,8 @@ int hc_cuModuleUnload (hashcat_ctx_t *hashcat_ctx, CUmodule hmod); int hc_cuStreamCreate (hashcat_ctx_t *hashcat_ctx, CUstream *phStream, unsigned int Flags); int hc_cuStreamDestroy (hashcat_ctx_t *hashcat_ctx, CUstream hStream); int hc_cuStreamSynchronize (hashcat_ctx_t *hashcat_ctx, CUstream hStream); +int hc_cuCtxPushCurrent (hashcat_ctx_t *hashcat_ctx, CUcontext ctx); +int hc_cuCtxPopCurrent (hashcat_ctx_t *hashcat_ctx, CUcontext *pctx); int hc_clBuildProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data); int hc_clCreateBuffer (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_mem *mem); diff --git a/src/backend.c b/src/backend.c index 4417167ca..2b4604ac3 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1922,6 +1922,59 @@ int hc_cuCtxSetCacheConfig (hashcat_ctx_t *hashcat_ctx, CUfunc_cache config) return 0; } +int hc_cuCtxPushCurrent (hashcat_ctx_t *hashcat_ctx, CUcontext ctx) +{ + backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx; + + CUDA_PTR *cuda = backend_ctx->cuda; + + const CUresult CU_err = cuda->cuCtxPushCurrent (ctx); + + if (CU_err != CUDA_SUCCESS) + { + const char *pStr = NULL; + + if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS) + { + event_log_error (hashcat_ctx, "cuCtxPushCurrent(): %s", pStr); + } + else + { + event_log_error (hashcat_ctx, "cuCtxPushCurrent(): %d", CU_err); + } + + return -1; + } + + return 0; +} + +int hc_cuCtxPopCurrent (hashcat_ctx_t *hashcat_ctx, CUcontext *pctx) +{ + backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx; + + CUDA_PTR *cuda = backend_ctx->cuda; + + const CUresult CU_err = cuda->cuCtxPopCurrent (pctx); + + if (CU_err != CUDA_SUCCESS) + { + const char *pStr = NULL; + + if (cuda->cuGetErrorString (CU_err, &pStr) == CUDA_SUCCESS) + { + event_log_error (hashcat_ctx, "cuCtxPopCurrent(): %s", pStr); + } + else + { + event_log_error (hashcat_ctx, "cuCtxPopCurrent(): %d", CU_err); + } + + return -1; + } + + return 0; +} // OpenCL @@ -2607,7 +2660,17 @@ int gidd_to_pw_t (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, c if (device_param->is_cuda == true) { - const int CU_rc = hc_cuMemcpyDtoH (hashcat_ctx, &pw_idx, device_param->cuda_d_pws_idx + (gidd * sizeof (pw_idx_t)), sizeof (pw_idx_t)); + int CU_rc; + + CU_rc = hc_cuCtxPushCurrent (hashcat_ctx, device_param->cuda_context); + + if (CU_rc == -1) return -1; + + CU_rc = hc_cuMemcpyDtoH (hashcat_ctx, &pw_idx, device_param->cuda_d_pws_idx + (gidd * sizeof (pw_idx_t)), sizeof (pw_idx_t)); + + if (CU_rc == -1) return -1; + + CU_rc = hc_cuCtxPopCurrent (hashcat_ctx, &device_param->cuda_context); if (CU_rc == -1) return -1; } @@ -2627,7 +2690,17 @@ int gidd_to_pw_t (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, c { if (cnt > 0) { - const int CU_rc = hc_cuMemcpyDtoH (hashcat_ctx,pw->i, device_param->cuda_d_pws_comp_buf + (off * sizeof (u32)), cnt * sizeof (u32)); + int CU_rc; + + CU_rc = hc_cuCtxPushCurrent (hashcat_ctx, device_param->cuda_context); + + if (CU_rc == -1) return -1; + + CU_rc = hc_cuMemcpyDtoH (hashcat_ctx,pw->i, device_param->cuda_d_pws_comp_buf + (off * sizeof (u32)), cnt * sizeof (u32)); + + if (CU_rc == -1) return -1; + + CU_rc = hc_cuCtxPopCurrent (hashcat_ctx, &device_param->cuda_context); if (CU_rc == -1) return -1; }