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