diff options
author | comex | 2015-01-20 21:48:38 -0500 |
---|---|---|
committer | comex | 2015-01-20 21:58:52 -0500 |
commit | c2728b5b3416d3bb2dedb62366a8e87e05d8629a (patch) | |
tree | 2b9bc6f8c365237ceeac980498d6b24df80b6fa3 /lib/darwin/read.c | |
parent | revert THAT WHOLE THING because we can't actually use it for inject (diff) | |
download | substitute-c2728b5b3416d3bb2dedb62366a8e87e05d8629a.tar.gz |
...
Diffstat (limited to 'lib/darwin/read.c')
-rw-r--r-- | lib/darwin/read.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/darwin/read.c b/lib/darwin/read.c new file mode 100644 index 0000000..2e5b746 --- /dev/null +++ b/lib/darwin/read.c @@ -0,0 +1,22 @@ +#include "darwin/read.h" +bool read_leb128(void **ptr, void *end, bool is_signed, uint64_t *out) { + uint64_t result = 0; + uint8_t *p = *ptr; + uint8_t bit; + unsigned int shift = 0; + do { + if (p >= (uint8_t *) end) + return false; + bit = *p++; + uint64_t k = bit & 0x7f; + if (shift < sizeof(uint64_t) * 8) + result |= k << shift; + shift += 7; + } while (bit & 0x80); + if (is_signed && (bit & 0x40)) + result |= ~((uint64_t) 0) << shift; + *ptr = p; + if (out) + *out = result; + return true; +} |