From 00069ce2eed58bf1ca5dda3b272cad99be9e278d Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 08 2020 01:00:10 +0000 Subject: driver & daemon: create a service object directory, link the current instance. --- diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index d3b56ad..1f3e571 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -24,6 +24,8 @@ extern "C" { 0x440f, \ {0x92,0xbe,0xc3,0x53,0x61,0x7b,0xbc,0x96}} +#define TOKS_PORT_NAME_PREFIX {'t','o','k','s','v','c'} + /* status codes */ #define TOKS_OK 0x00 #define TOKS_USAGE 0x01 diff --git a/src/daemon/toks_daemon_init.c b/src/daemon/toks_daemon_init.c index 0914a6d..d500854 100644 --- a/src/daemon/toks_daemon_init.c +++ b/src/daemon/toks_daemon_init.c @@ -21,6 +21,7 @@ static int32_t toks_daemon_init_impl( nt_daemon_params dparams; wchar16_t * port_name; nt_port_name_keys * port_name_keys; + void * hsvclink; /* daemon attributes */ dctx->daemon_attr.type = NT_PORT_TYPE_DAEMON; @@ -70,6 +71,18 @@ static int32_t toks_daemon_init_impl( if ((status = ntapi->dsr_init(&dparams))) return status; + if ((status = ntapi->tt_create_dev_object_directory_entry( + &hsvclink, + NT_SYMBOLIC_LINK_ALL_ACCESS, + toks_get_driver_hsvcdir(dctx->driver_ctx), + dparams.hport_daemon,0, + svcguid))) + return status; + + toks_set_driver_hsvclink( + dctx->driver_ctx, + hsvclink); + /* todo: check driver flags or defer to driver */ return ntapi->tty_request_peer( htty, diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index b6a3c65..a214c71 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -35,6 +35,7 @@ const ntapi_vtbl * toks_ntapi; /* daemon */ static struct toks_daemon_ctx toks_daemon_ctx; static const nt_guid toks_daemon_default_guid = TOKS_PORT_GUID_DAEMON; +static const wchar16_t toks_service_name[6] = TOKS_PORT_NAME_PREFIX; /* package info */ static const struct toks_source_version toks_src_version = { @@ -280,6 +281,13 @@ int toks_get_driver_ctx( NT_EVENT_NOT_SIGNALED))) return toks_get_driver_ctx_fail(meta); + if ((ntapi->tt_open_dev_object_directory( + &ctx->hsvcdir, + NT_DIRECTORY_ALL_ACCESS, + toks_service_name, + &toks_daemon_default_guid))) + return toks_get_driver_ctx_fail(meta); + if ((hkernel32 = pe_get_kernel32_module_handle())) if ((ctx->ticks.qpc = pe_get_procedure_address( hkernel32,"QueryPerformanceCounter"))) @@ -306,6 +314,12 @@ static void toks_free_driver_ctx_impl(struct toks_driver_ctx_alloc * ictx) if (ictx->ctx.hevent) ntapi->zw_close(ictx->ctx.hevent); + if (ictx->ctx.hsvcdir) + ntapi->zw_close(ictx->ctx.hsvcdir); + + if (ictx->ctx.hsvclink) + ntapi->zw_close(ictx->ctx.hsvclink); + argv_free(ictx->meta); free(ictx); } diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 2c41eb0..7ceada2 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -44,6 +44,8 @@ struct toks_driver_ctx_impl { struct toks_driver_ctx ctx; struct toks_ticks ticks; void * hevent; + void * hsvcdir; + void * hsvclink; nt_guid uuid; }; @@ -73,6 +75,34 @@ static inline void * toks_get_driver_hevent(const struct toks_driver_ctx * dctx) return ictx->hevent; } +static inline void * toks_get_driver_hsvcdir(const struct toks_driver_ctx * dctx) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + return ictx->hsvcdir; +} + +static inline void toks_set_driver_hsvcdir(const struct toks_driver_ctx * dctx, void * hsvcdir) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + ictx->hsvcdir = hsvcdir; +} + +static inline void * toks_get_driver_hsvclink(const struct toks_driver_ctx * dctx) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + return ictx->hsvclink; +} + +static inline void toks_set_driver_hsvclink(const struct toks_driver_ctx * dctx, void * hsvclink) +{ + struct toks_driver_ctx_impl * ictx; + ictx = toks_get_driver_ictx(dctx); + ictx->hsvclink = hsvclink; +} + static inline const nt_guid * toks_get_driver_uuid(const struct toks_driver_ctx * dctx) { struct toks_driver_ctx_impl * ictx;