diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-02-28 00:17:43 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-03-04 18:50:25 +0100 |
commit | b6a5cc00018fcc42ee306cff7cd8bcdda01916a3 (patch) | |
tree | 453ebdb0a1aeb0c5b349eba88ba69d53ced0935c /contrib/examples/extract-handshakes/offset-finder.c | |
parent | wg-quick: if resolvconf/run/iface exists, use it (diff) | |
download | wireguard-monolithic-historical-b6a5cc00018fcc42ee306cff7cd8bcdda01916a3.tar.xz wireguard-monolithic-historical-b6a5cc00018fcc42ee306cff7cd8bcdda01916a3.zip |
contrib: add extract-handshakes kprobe example
Diffstat (limited to '')
-rw-r--r-- | contrib/examples/extract-handshakes/offset-finder.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/contrib/examples/extract-handshakes/offset-finder.c b/contrib/examples/extract-handshakes/offset-finder.c new file mode 100644 index 0000000..d0bc69c --- /dev/null +++ b/contrib/examples/extract-handshakes/offset-finder.c @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + */ + +struct def { + const char *name; + unsigned long offset; + unsigned long indirection_offset; +}; +extern const struct def defs[]; + +#ifdef __KERNEL__ +#include "../../../src/noise.h" + +const struct def defs[] = { + { "LOCAL_STATIC_PRIVATE_KEY", offsetof(struct noise_static_identity, static_private), offsetof(struct noise_handshake, static_identity) }, + { "LOCAL_EPHEMERAL_PRIVATE_KEY", offsetof(struct noise_handshake, ephemeral_private), -1 }, + { "REMOTE_STATIC_PUBLIC_KEY", offsetof(struct noise_handshake, remote_static), -1 }, + { "PRESHARED_KEY", offsetof(struct noise_handshake, preshared_key), -1 }, + { NULL, 0 } +}; +#else +#include <stdio.h> +int main(int argc, char *argv[]) +{ + puts("declare -A OFFSETS=("); + for (const struct def *def = defs; def->name; ++def) { + printf("\t[%s]=%ld", def->name, def->offset); + if (def->indirection_offset != -1) + printf(",%ld", def->indirection_offset); + putchar('\n'); + } + puts(")"); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + puts("ENDIAN=big"); +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + puts("ENDIAN=little"); +#else +#error "Unsupported endianness" +#endif + return 0; +} +#endif |