blob: c42d183cb3cea2d1c301a9197c8002b15b34088a [file] [log] [blame]
The Android Open Source Project52d4c302009-03-03 19:29:09 -08001/*
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
12typedef unsigned char u1;
13typedef unsigned short u2;
14typedef unsigned int u4;
15typedef unsigned long long u8;
16
17#ifndef __bool_true_false_are_defined
18typedef 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 */
33INLINE u1 get1(unsigned const char* pSrc)
34{
35 return *pSrc;
36}
37
38/*
39 * Get 2 big-endian bytes.
40 */
41INLINE 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 */
54INLINE 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 */
69INLINE 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 */
89int 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 */
100typedef enum { kHexDumpLocal, kHexDumpMem } HexDumpMode;
101void printHexDump(const void* vaddr, size_t length);
102void printHexDump2(const void* vaddr, size_t length, const char* prefix);
103void printHexDumpEx(FILE* fp, const void* vaddr, size_t length,
104 HexDumpMode mode, const char* prefix);
105
106#endif /*_JDWPSPY_COMMON*/