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