Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 3 | * |
| 4 | * jdwpspy common stuff. |
| 5 | */ |
| 6 | #ifndef _JDWPSPY_COMMON |
| 7 | #define _JDWPSPY_COMMON |
| 8 | |
Elliott Hughes | 6d8dd47 | 2012-01-17 18:27:41 -0800 | [diff] [blame^] | 9 | #include <stdint.h> |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <sys/types.h> |
| 12 | |
Elliott Hughes | 6d8dd47 | 2012-01-17 18:27:41 -0800 | [diff] [blame^] | 13 | typedef uint8_t u1; |
| 14 | typedef uint16_t u2; |
| 15 | typedef uint32_t u4; |
| 16 | typedef uint64_t u8; |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 17 | |
| 18 | #define NELEM(x) (sizeof(x) / sizeof((x)[0])) |
| 19 | |
| 20 | #ifndef _JDWP_MISC_INLINE |
| 21 | # define INLINE extern inline |
| 22 | #else |
| 23 | # define INLINE |
| 24 | #endif |
| 25 | |
| 26 | /* |
| 27 | * Get 1 byte. (Included to make the code more legible.) |
| 28 | */ |
| 29 | INLINE u1 get1(unsigned const char* pSrc) |
| 30 | { |
| 31 | return *pSrc; |
| 32 | } |
| 33 | |
| 34 | /* |
| 35 | * Get 2 big-endian bytes. |
| 36 | */ |
| 37 | INLINE u2 get2BE(unsigned char const* pSrc) |
| 38 | { |
| 39 | u2 result; |
| 40 | |
| 41 | result = *pSrc++ << 8; |
| 42 | result |= *pSrc++; |
| 43 | |
| 44 | return result; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * Get 4 big-endian bytes. |
| 49 | */ |
| 50 | INLINE u4 get4BE(unsigned char const* pSrc) |
| 51 | { |
| 52 | u4 result; |
| 53 | |
| 54 | result = *pSrc++ << 24; |
| 55 | result |= *pSrc++ << 16; |
| 56 | result |= *pSrc++ << 8; |
| 57 | result |= *pSrc++; |
| 58 | |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Get 8 big-endian bytes. |
| 64 | */ |
| 65 | INLINE u8 get8BE(unsigned char const* pSrc) |
| 66 | { |
| 67 | u8 result; |
| 68 | |
| 69 | result = (u8) *pSrc++ << 56; |
| 70 | result |= (u8) *pSrc++ << 48; |
| 71 | result |= (u8) *pSrc++ << 40; |
| 72 | result |= (u8) *pSrc++ << 32; |
| 73 | result |= (u8) *pSrc++ << 24; |
| 74 | result |= (u8) *pSrc++ << 16; |
| 75 | result |= (u8) *pSrc++ << 8; |
| 76 | result |= (u8) *pSrc++; |
| 77 | |
| 78 | return result; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /* |
| 83 | * Start here. |
| 84 | */ |
| 85 | int run(const char* connectHost, int connectPort, int listenPort); |
| 86 | |
| 87 | /* |
| 88 | * Print a hex dump to the specified file pointer. |
| 89 | * |
| 90 | * "local" mode prints a hex dump starting from offset 0 (roughly equivalent |
| 91 | * to "xxd -g1"). |
| 92 | * |
| 93 | * "mem" mode shows the actual memory address, and will offset the start |
| 94 | * so that the low nibble of the address is always zero. |
| 95 | */ |
| 96 | typedef enum { kHexDumpLocal, kHexDumpMem } HexDumpMode; |
| 97 | void printHexDump(const void* vaddr, size_t length); |
| 98 | void printHexDump2(const void* vaddr, size_t length, const char* prefix); |
| 99 | void printHexDumpEx(FILE* fp, const void* vaddr, size_t length, |
| 100 | HexDumpMode mode, const char* prefix); |
| 101 | |
| 102 | #endif /*_JDWPSPY_COMMON*/ |