aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2021-01-20 19:12:52 +0100
committerGitHub <noreply@github.com>2021-01-20 19:12:52 +0100
commit068bef5eab942df0a133c92522f2ab81b28ac636 (patch)
tree4689cb46e0d543af889609e260b1ff03455a2701 /utils
parent271116f8705e08d1b4f924cda6c6cae1b0b5de2b (diff)
parentb9e855b7b5ef3d7f367b32ee03459a9f5b21360f (diff)
downloadafl++-068bef5eab942df0a133c92522f2ab81b28ac636.tar.gz
Merge pull request #691 from AFLplusplus/dev
push to stable
Diffstat (limited to 'utils')
-rw-r--r--utils/afl_frida/afl-frida.c201
-rw-r--r--utils/afl_frida/android/README.md1
-rw-r--r--utils/afl_frida/android/frida-gum-example.c130
-rw-r--r--utils/afl_network_proxy/afl-network-server.c4
-rw-r--r--utils/aflpp_driver/aflpp_driver.c65
-rw-r--r--utils/defork/defork.c2
-rw-r--r--utils/libdislocator/README.md2
-rw-r--r--utils/libdislocator/libdislocator.so.c8
-rw-r--r--utils/libtokencap/README.md7
-rw-r--r--utils/persistent_mode/Makefile8
-rw-r--r--utils/qemu_persistent_hook/test.c2
11 files changed, 273 insertions, 157 deletions
diff --git a/utils/afl_frida/afl-frida.c b/utils/afl_frida/afl-frida.c
index b5b8196d..087f18e8 100644
--- a/utils/afl_frida/afl-frida.c
+++ b/utils/afl_frida/afl-frida.c
@@ -153,7 +153,7 @@ static int enumerate_ranges(const GumRangeDetails *details,
}
-int main() {
+int main(int argc, char** argv) {
#ifndef __APPLE__
(void)personality(ADDR_NO_RANDOMIZE); // disable ASLR
@@ -164,105 +164,140 @@ int main() {
// If there is just one function, then there is nothing to change
// or add here.
- void *dl = dlopen(TARGET_LIBRARY, RTLD_LAZY);
+ void *dl = NULL;
+ if (argc > 2) {
+ dl = dlopen(argv[1], RTLD_LAZY);
+ } else {
+ dl = dlopen(TARGET_LIBRARY, RTLD_LAZY);
+ }
if (!dl) {
- fprintf(stderr, "Could not load %s\n", TARGET_LIBRARY);
+ if (argc > 2)
+ fprintf(stderr, "Could not load %s\n", argv[1]);
+ else
+ fprintf(stderr, "Could not load %s\n", TARGET_LIBRARY);
exit(-1);
}
- if (!(o_function = dlsym(dl, TARGET_FUNCTION))) {
+ if (argc > 2)
+ o_function = dlsym(dl, argv[2]);
+ else
+ o_function = dlsym(dl, TARGET_FUNCTION);
+ if (!o_function) {
- fprintf(stderr, "Could not find function %s\n", TARGET_FUNCTION);
+ if (argc > 2)
+ fprintf(stderr, "Could not find function %s\n", argv[2]);
+ else
+ fprintf(stderr, "Could not find function %s\n", TARGET_FUNCTION);
exit(-1);
}
// END STEP 2
- gum_init_embedded();
- if (!gum_stalker_is_supported()) {
-
- gum_deinit_embedded();
- return 1;
-
- }
-
- GumStalker *stalker = gum_stalker_new();
-
- GumAddress base_address = gum_module_find_base_address(TARGET_LIBRARY);
- GumMemoryRange code_range;
- gum_module_enumerate_ranges(TARGET_LIBRARY, GUM_PAGE_RX, enumerate_ranges,
- &code_range);
-
- guint64 code_start = code_range.base_address;
- guint64 code_end = code_range.base_address + code_range.size;
- range_t instr_range = {0, code_start, code_end};
-
- printf("Frida instrumentation: base=0x%lx instrumenting=0x%lx-%lx\n",
- base_address, code_start, code_end);
- if (!code_start || !code_end) {
-
- fprintf(stderr, "Error: no valid memory address found for %s\n",
- TARGET_LIBRARY);
- exit(-1);
-
- }
-
- GumStalkerTransformer *transformer =
- gum_stalker_transformer_make_from_callback(instr_basic_block,
- &instr_range, NULL);
-
- // to ensure that the signatures are not optimized out
- memcpy(__afl_area_ptr, (void *)AFL_PERSISTENT, sizeof(AFL_PERSISTENT) + 1);
- memcpy(__afl_area_ptr + 32, (void *)AFL_DEFER_FORKSVR,
- sizeof(AFL_DEFER_FORKSVR) + 1);
- __afl_manual_init();
-
- //
- // any expensive target library initialization that has to be done just once
- // - put that here
- //
-
- gum_stalker_follow_me(stalker, transformer, NULL);
-
- while (__afl_persistent_loop(UINT32_MAX) != 0) {
-
- previous_pc = 0; // Required!
-
-#ifdef _DEBUG
- fprintf(stderr, "CLIENT crc: %016llx len: %u\n",
- hash64(__afl_fuzz_ptr, *__afl_fuzz_len), *__afl_fuzz_len);
- fprintf(stderr, "RECV:");
- for (int i = 0; i < *__afl_fuzz_len; i++)
- fprintf(stderr, "%02x", __afl_fuzz_ptr[i]);
- fprintf(stderr, "\n");
-#endif
-
- // STEP 3: ensure the minimum length is present and setup the target
- // function to fuzz.
-
- if (*__afl_fuzz_len > 0) {
-
- __afl_fuzz_ptr[*__afl_fuzz_len] = 0; // if you need to null terminate
- (*o_function)(__afl_fuzz_ptr, *__afl_fuzz_len);
-
+ if (!getenv("AFL_FRIDA_TEST_INPUT")) {
+ gum_init_embedded();
+ if (!gum_stalker_is_supported()) {
+
+ gum_deinit_embedded();
+ return 1;
+
}
+
+ GumStalker *stalker = gum_stalker_new();
+
+ GumAddress base_address;
+ if (argc > 2)
+ base_address = gum_module_find_base_address(argv[1]);
+ else
+ base_address = gum_module_find_base_address(TARGET_LIBRARY);
+ GumMemoryRange code_range;
+ if (argc > 2)
+ gum_module_enumerate_ranges(argv[1], GUM_PAGE_RX, enumerate_ranges,
+ &code_range);
+ else
+ gum_module_enumerate_ranges(TARGET_LIBRARY, GUM_PAGE_RX, enumerate_ranges,
+ &code_range);
+
+ guint64 code_start = code_range.base_address;
+ guint64 code_end = code_range.base_address + code_range.size;
+ range_t instr_range = {0, code_start, code_end};
+
+ printf("Frida instrumentation: base=0x%lx instrumenting=0x%lx-%lx\n",
+ base_address, code_start, code_end);
+ if (!code_start || !code_end) {
+
+ if (argc > 2)
+ fprintf(stderr, "Error: no valid memory address found for %s\n",
+ argv[1]);
+ else
+ fprintf(stderr, "Error: no valid memory address found for %s\n",
+ TARGET_LIBRARY);
+ exit(-1);
+
+ }
+
+ GumStalkerTransformer *transformer =
+ gum_stalker_transformer_make_from_callback(instr_basic_block,
+ &instr_range, NULL);
+
+ // to ensure that the signatures are not optimized out
+ memcpy(__afl_area_ptr, (void *)AFL_PERSISTENT, sizeof(AFL_PERSISTENT) + 1);
+ memcpy(__afl_area_ptr + 32, (void *)AFL_DEFER_FORKSVR,
+ sizeof(AFL_DEFER_FORKSVR) + 1);
+ __afl_manual_init();
+
+ //
+ // any expensive target library initialization that has to be done just once
+ // - put that here
+ //
+
+ gum_stalker_follow_me(stalker, transformer, NULL);
+
+ while (__afl_persistent_loop(UINT32_MAX) != 0) {
+
+ previous_pc = 0; // Required!
+
+ #ifdef _DEBUG
+ fprintf(stderr, "CLIENT crc: %016llx len: %u\n",
+ hash64(__afl_fuzz_ptr, *__afl_fuzz_len), *__afl_fuzz_len);
+ fprintf(stderr, "RECV:");
+ for (int i = 0; i < *__afl_fuzz_len; i++)
+ fprintf(stderr, "%02x", __afl_fuzz_ptr[i]);
+ fprintf(stderr, "\n");
+ #endif
+
+ // STEP 3: ensure the minimum length is present and setup the target
+ // function to fuzz.
+
+ if (*__afl_fuzz_len > 0) {
+
+ __afl_fuzz_ptr[*__afl_fuzz_len] = 0; // if you need to null terminate
+ (*o_function)(__afl_fuzz_ptr, *__afl_fuzz_len);
+
+ }
+
+ // END STEP 3
+
+ }
+
+ gum_stalker_unfollow_me(stalker);
+
+ while (gum_stalker_garbage_collect(stalker))
+ g_usleep(10000);
+
+ g_object_unref(stalker);
+ g_object_unref(transformer);
+ gum_deinit_embedded();
- // END STEP 3
-
+ } else {
+ char buf[8*1024] = {0};
+ int count = read(0, buf, sizeof(buf));
+ buf[8*1024-1] = '\0';
+ (*o_function)(buf, count);
}
- gum_stalker_unfollow_me(stalker);
-
- while (gum_stalker_garbage_collect(stalker))
- g_usleep(10000);
-
- g_object_unref(stalker);
- g_object_unref(transformer);
- gum_deinit_embedded();
-
return 0;
}
diff --git a/utils/afl_frida/android/README.md b/utils/afl_frida/android/README.md
new file mode 100644
index 00000000..044b48a1
--- /dev/null
+++ b/utils/afl_frida/android/README.md
@@ -0,0 +1 @@
+For android, frida-gum package (ex. https://github.com/frida/frida/releases/download/14.2.6/frida-gum-devkit-14.2.6-android-arm64.tar.xz) is needed to be extracted in the directory.
diff --git a/utils/afl_frida/android/frida-gum-example.c b/utils/afl_frida/android/frida-gum-example.c
new file mode 100644
index 00000000..14d98248
--- /dev/null
+++ b/utils/afl_frida/android/frida-gum-example.c
@@ -0,0 +1,130 @@
+/*
+ * Compile with:
+ *
+ * clang -fPIC -DANDROID -ffunction-sections -fdata-sections -Os -pipe -g3 frida-gum-example.c -o frida-gum-example -L. -lfrida-gum -llog -ldl -lm -pthread -Wl,--gc-sections,-z,noexecstack,-z,relro,-z,now -fuse-ld=gold -fuse-ld=gold -Wl,--icf=all
+ *
+ * Visit https://frida.re to learn more about Frida.
+ */
+
+#include "frida-gum.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+typedef struct _ExampleListener ExampleListener;
+typedef enum _ExampleHookId ExampleHookId;
+
+struct _ExampleListener
+{
+ GObject parent;
+
+ guint num_calls;
+};
+
+enum _ExampleHookId
+{
+ EXAMPLE_HOOK_OPEN,
+ EXAMPLE_HOOK_CLOSE
+};
+
+static void example_listener_iface_init (gpointer g_iface, gpointer iface_data);
+
+#define EXAMPLE_TYPE_LISTENER (example_listener_get_type ())
+G_DECLARE_FINAL_TYPE (ExampleListener, example_listener, EXAMPLE, LISTENER, GObject)
+G_DEFINE_TYPE_EXTENDED (ExampleListener,
+ example_listener,
+ G_TYPE_OBJECT,
+ 0,
+ G_IMPLEMENT_INTERFACE (GUM_TYPE_INVOCATION_LISTENER,
+ example_listener_iface_init))
+
+int
+main (int argc,
+ char * argv[])
+{
+ GumInterceptor * interceptor;
+ GumInvocationListener * listener;
+
+ gum_init_embedded ();
+
+ interceptor = gum_interceptor_obtain ();
+ listener = g_object_new (EXAMPLE_TYPE_LISTENER, NULL);
+
+ gum_interceptor_begin_transaction (interceptor);
+ gum_interceptor_attach (interceptor,
+ GSIZE_TO_POINTER (gum_module_find_export_by_name (NULL, "open")),
+ listener,
+ GSIZE_TO_POINTER (EXAMPLE_HOOK_OPEN));
+ gum_interceptor_attach (interceptor,
+ GSIZE_TO_POINTER (gum_module_find_export_by_name (NULL, "close")),
+ listener,
+ GSIZE_TO_POINTER (EXAMPLE_HOOK_CLOSE));
+ gum_interceptor_end_transaction (interceptor);
+
+ close (open ("/etc/hosts", O_RDONLY));
+ close (open ("/etc/fstab", O_RDONLY));
+
+ g_print ("[*] listener got %u calls\n", EXAMPLE_LISTENER (listener)->num_calls);
+
+ gum_interceptor_detach (interceptor, listener);
+
+ close (open ("/etc/hosts", O_RDONLY));
+ close (open ("/etc/fstab", O_RDONLY));
+
+ g_print ("[*] listener still has %u calls\n", EXAMPLE_LISTENER (listener)->num_calls);
+
+ g_object_unref (listener);
+ g_object_unref (interceptor);
+
+ gum_deinit_embedded ();
+
+ return 0;
+}
+
+static void
+example_listener_on_enter (GumInvocationListener * listener,
+ GumInvocationContext * ic)
+{
+ ExampleListener * self = EXAMPLE_LISTENER (listener);
+ ExampleHookId hook_id = GUM_IC_GET_FUNC_DATA (ic, ExampleHookId);
+
+ switch (hook_id)
+ {
+ case EXAMPLE_HOOK_OPEN:
+ g_print ("[*] open(\"%s\")\n", (const gchar *) gum_invocation_context_get_nth_argument (ic, 0));
+ break;
+ case EXAMPLE_HOOK_CLOSE:
+ g_print ("[*] close(%d)\n", GPOINTER_TO_INT (gum_invocation_context_get_nth_argument (ic, 0)));
+ break;
+ }
+
+ self->num_calls++;
+}
+
+static void
+example_listener_on_leave (GumInvocationListener * listener,
+ GumInvocationContext * ic)
+{
+}
+
+static void
+example_listener_class_init (ExampleListenerClass * klass)
+{
+ (void) EXAMPLE_IS_LISTENER;
+ (void) glib_autoptr_cleanup_ExampleListener;
+}
+
+static void
+example_listener_iface_init (gpointer g_iface,
+ gpointer iface_data)
+{
+ GumInvocationListenerInterface * iface = g_iface;
+
+ iface->on_enter = example_listener_on_enter;
+ iface->on_leave = example_listener_on_leave;
+}
+
+static void
+example_listener_init (ExampleListener * self)
+{
+}
diff --git a/utils/afl_network_proxy/afl-network-server.c b/utils/afl_network_proxy/afl-network-server.c
index 513dc8f2..fe225416 100644
--- a/utils/afl_network_proxy/afl-network-server.c
+++ b/utils/afl_network_proxy/afl-network-server.c
@@ -24,10 +24,6 @@
#define AFL_MAIN
-#ifdef __ANDROID__
- #include "android-ashmem.h"
-#endif
-
#include "config.h"
#include "types.h"
#include "debug.h"
diff --git a/utils/aflpp_driver/aflpp_driver.c b/utils/aflpp_driver/aflpp_driver.c
index c6f5a76c..30e6ebb9 100644
--- a/utils/aflpp_driver/aflpp_driver.c
+++ b/utils/aflpp_driver/aflpp_driver.c
@@ -1,12 +1,8 @@
-//===- afl_driver.cpp - a glue between AFL and libFuzzer --------*- C++ -* ===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//===- afl_driver.cpp - a glue between AFL++ and libFuzzer ------*- C++ -* ===//
//===----------------------------------------------------------------------===//
/* This file allows to fuzz libFuzzer-style target functions
- (LLVMFuzzerTestOneInput) with AFL using AFL's persistent (in-process) mode.
+ (LLVMFuzzerTestOneInput) with AFL++ using persistent in-memory fuzzing.
Usage:
################################################################################
@@ -25,25 +21,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
EOF
# Build your target with -fsanitize-coverage=trace-pc-guard using fresh clang.
-clang -g -fsanitize-coverage=trace-pc-guard test_fuzzer.cc -c
+clang -c aflpp_driver.c
# Build afl-compiler-rt.o.c from the AFL distribution.
-clang -c -w $AFL_HOME/instrumentation/afl-compiler-rt.o.c
+clang -c $AFL_HOME/instrumentation/afl-compiler-rt.o.c
# Build this file, link it with afl-compiler-rt.o.o and the target code.
-clang++ afl_driver.cpp test_fuzzer.o afl-compiler-rt.o.o
+afl-clang-fast -o test_fuzzer test_fuzzer.cc afl-compiler-rt.o aflpp_driver.o
# Run AFL:
rm -rf IN OUT; mkdir IN OUT; echo z > IN/z;
$AFL_HOME/afl-fuzz -i IN -o OUT ./a.out
################################################################################
-AFL_DRIVER_STDERR_DUPLICATE_FILENAME: Setting this *appends* stderr to the file
-specified. If the file does not exist, it is created. This is useful for getting
-stack traces (when using ASAN for example) or original error messages on hard
-to reproduce bugs. Note that any content written to stderr will be written to
-this file instead of stderr's usual location.
-
-AFL_DRIVER_CLOSE_FD_MASK: Similar to libFuzzer's -close_fd_mask behavior option.
-If 1, close stdout at startup. If 2 close stderr; if 3 close both.
-
*/
+
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
@@ -65,47 +53,6 @@ If 1, close stdout at startup. If 2 close stderr; if 3 close both.
#include "hash.h"
#endif
-#ifndef MAP_FIXED_NOREPLACE
- #define MAP_FIXED_NOREPLACE 0x100000
-#endif
-
-#define MAX_DUMMY_SIZE 256000
-
-// Platform detection. Copied from FuzzerInternal.h
-#ifdef __linux__
- #define LIBFUZZER_LINUX 1
- #define LIBFUZZER_APPLE 0
- #define LIBFUZZER_NETBSD 0
- #define LIBFUZZER_FREEBSD 0
- #define LIBFUZZER_OPENBSD 0
-#elif __APPLE__
- #define LIBFUZZER_LINUX 0
- #define LIBFUZZER_APPLE 1
- #define LIBFUZZER_NETBSD 0
- #define LIBFUZZER_FREEBSD 0
- #define LIBFUZZER_OPENBSD 0
-#elif __NetBSD__
- #define LIBFUZZER_LINUX 0
- #define LIBFUZZER_APPLE 0
- #define LIBFUZZER_NETBSD 1
- #define LIBFUZZER_FREEBSD 0
- #define LIBFUZZER_OPENBSD 0
-#elif __FreeBSD__
- #define LIBFUZZER_LINUX 0
- #define LIBFUZZER_APPLE 0
- #define LIBFUZZER_NETBSD 0
- #define LIBFUZZER_FREEBSD 1
- #define LIBFUZZER_OPENBSD 0
-#elif __OpenBSD__
- #define LIBFUZZER_LINUX 0
- #define LIBFUZZER_APPLE 0
- #define LIBFUZZER_NETBSD 0
- #define LIBFUZZER_FREEBSD 0
- #define LIBFUZZER_OPENBSD 1
-#else
- #error "Support for your platform has not been implemented"
-#endif
-
int __afl_sharedmem_fuzzing = 1;
extern unsigned int * __afl_fuzz_len;
extern unsigned char *__afl_fuzz_ptr;
diff --git a/utils/defork/defork.c b/utils/defork/defork.c
index f71d1124..f50b9a4b 100644
--- a/utils/defork/defork.c
+++ b/utils/defork/defork.c
@@ -1,4 +1,4 @@
-#define __GNU_SOURCE
+#define _GNU_SOURCE
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
diff --git a/utils/libdislocator/README.md b/utils/libdislocator/README.md
index 1785463e..d0340af0 100644
--- a/utils/libdislocator/README.md
+++ b/utils/libdislocator/README.md
@@ -1,6 +1,6 @@
# libdislocator, an abusive allocator
- (See ../README.md for the general instruction manual.)
+ (See ../../README.md for the general instruction manual.)
This is a companion library that can be used as a drop-in replacement for the
libc allocator in the fuzzed binaries. It improves the odds of bumping into
diff --git a/utils/libdislocator/libdislocator.so.c b/utils/libdislocator/libdislocator.so.c
index 2324e390..c041fec6 100644
--- a/utils/libdislocator/libdislocator.so.c
+++ b/utils/libdislocator/libdislocator.so.c
@@ -345,10 +345,10 @@ void free(void *ptr) {
len = PTR_L(ptr);
total_mem -= len;
+ u8 *ptr_ = ptr;
if (align_allocations && (len & (ALLOC_ALIGN_SIZE - 1))) {
- u8 * ptr_ = ptr;
size_t rlen = (len & ~(ALLOC_ALIGN_SIZE - 1)) + ALLOC_ALIGN_SIZE;
for (; len < rlen; ++len)
if (ptr_[len] != TAIL_ALLOC_CANARY)
@@ -359,11 +359,13 @@ void free(void *ptr) {
/* Protect everything. Note that the extra page at the end is already
set as PROT_NONE, so we don't need to touch that. */
- ptr -= PAGE_SIZE * PG_COUNT(len + 8) - len - 8;
+ ptr_ -= PAGE_SIZE * PG_COUNT(len + 8) - len - 8;
- if (mprotect(ptr - 8, PG_COUNT(len + 8) * PAGE_SIZE, PROT_NONE))
+ if (mprotect(ptr_ - 8, PG_COUNT(len + 8) * PAGE_SIZE, PROT_NONE))
FATAL("mprotect() failed when freeing memory");
+ ptr = ptr_;
+
/* Keep the mapping; this is wasteful, but prevents ptr reuse. */
}
diff --git a/utils/libtokencap/README.md b/utils/libtokencap/README.md
index 13a440da..a39ed3a5 100644
--- a/utils/libtokencap/README.md
+++ b/utils/libtokencap/README.md
@@ -1,6 +1,11 @@
# strcmp() / memcmp() token capture library
- (See ../README.md for the general instruction manual.)
+ NOTE: libtokencap is only recommended for binary-only targets or targets that
+ do not compile with afl-clang-fast/afl-clang-lto.
+ The afl-clang-fast AFL_LLVM_DICT2FILE feature is much better, afl-clang-lto
+ has that feature automatically integrated.
+
+ (See ../../README.md for the general instruction manual.)
This companion library allows you to instrument `strcmp()`, `memcmp()`,
and related functions to automatically extract syntax tokens passed to any of
diff --git a/utils/persistent_mode/Makefile b/utils/persistent_mode/Makefile
index 6fa1c30e..e348c46c 100644
--- a/utils/persistent_mode/Makefile
+++ b/utils/persistent_mode/Makefile
@@ -1,10 +1,10 @@
all:
- afl-clang-fast -o persistent_demo persistent_demo.c
- afl-clang-fast -o persistent_demo_new persistent_demo_new.c
- AFL_DONT_OPTIMIZE=1 afl-clang-fast -o test-instr test-instr.c
+ ../../afl-clang-fast -o persistent_demo persistent_demo.c
+ ../../afl-clang-fast -o persistent_demo_new persistent_demo_new.c
+ AFL_DONT_OPTIMIZE=1 ../../afl-clang-fast -o test-instr test-instr.c
document:
- AFL_DONT_OPTIMIZE=1 afl-clang-fast -D_AFL_DOCUMENT_MUTATIONS -o test-instr test-instr.c
+ AFL_DONT_OPTIMIZE=1 ../../afl-clang-fast -D_AFL_DOCUMENT_MUTATIONS -o test-instr test-instr.c
clean:
rm -f persistent_demo persistent_demo_new test-instr
diff --git a/utils/qemu_persistent_hook/test.c b/utils/qemu_persistent_hook/test.c
index afeff202..a0e815dc 100644
--- a/utils/qemu_persistent_hook/test.c
+++ b/utils/qemu_persistent_hook/test.c
@@ -2,7 +2,7 @@
int target_func(unsigned char *buf, int size) {
- printf("buffer:%p, size:%p\n", buf, size);
+ printf("buffer:%p, size:%d\n", buf, size);
switch (buf[0]) {
case 1: