line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl -w |
2
|
|
|
|
|
|
|
################################################################################ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright (c) 2002-2020 Marcus Holland-Moritz. All rights reserved. |
5
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
6
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
################################################################################ |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#=============================================================================== |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Print a simple memory map of a structure. |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
#=============================================================================== |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
943
|
use Convert::Binary::C; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
53
|
|
17
|
1
|
|
|
1
|
|
766
|
use Data::Dumper; |
|
1
|
|
|
|
|
7439
|
|
|
1
|
|
|
|
|
63
|
|
18
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1596
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#----------------------------------------------------- |
21
|
|
|
|
|
|
|
# Create an object, configure it, and parse some code. |
22
|
|
|
|
|
|
|
#----------------------------------------------------- |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
648
|
my $c = Convert::Binary::C->new( PointerSize => 4, |
25
|
|
|
|
|
|
|
LongSize => 4, |
26
|
|
|
|
|
|
|
ShortSize => 2, |
27
|
|
|
|
|
|
|
Alignment => 4 ) |
28
|
|
|
|
|
|
|
->parse( <<'ENDC' ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
typedef unsigned long u_32; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
typedef struct _LinkedList * LinkedList; |
33
|
|
|
|
|
|
|
typedef struct _HashTable * HashTable; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
typedef struct { |
36
|
|
|
|
|
|
|
enum { |
37
|
|
|
|
|
|
|
BO_BIG_ENDIAN, |
38
|
|
|
|
|
|
|
BO_LITTLE_ENDIAN |
39
|
|
|
|
|
|
|
} bo; |
40
|
|
|
|
|
|
|
} ArchSpecs; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
typedef struct { |
43
|
|
|
|
|
|
|
char *buffer; |
44
|
|
|
|
|
|
|
long pos, length; |
45
|
|
|
|
|
|
|
} Buffer; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
typedef struct { |
48
|
|
|
|
|
|
|
unsigned alignment; |
49
|
|
|
|
|
|
|
unsigned int_size; |
50
|
|
|
|
|
|
|
unsigned short_size; |
51
|
|
|
|
|
|
|
unsigned long_size; |
52
|
|
|
|
|
|
|
unsigned long_long_size; |
53
|
|
|
|
|
|
|
int enum_size; |
54
|
|
|
|
|
|
|
unsigned ptr_size; |
55
|
|
|
|
|
|
|
unsigned float_size; |
56
|
|
|
|
|
|
|
unsigned double_size; |
57
|
|
|
|
|
|
|
unsigned long_double_size; |
58
|
|
|
|
|
|
|
u_32 flags; |
59
|
|
|
|
|
|
|
u_32 keywords; |
60
|
|
|
|
|
|
|
LinkedList disabled_keywords; |
61
|
|
|
|
|
|
|
LinkedList includes; |
62
|
|
|
|
|
|
|
LinkedList defines; |
63
|
|
|
|
|
|
|
LinkedList assertions; |
64
|
|
|
|
|
|
|
HashTable keyword_map; |
65
|
|
|
|
|
|
|
} CParseConfig; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
typedef struct { |
68
|
|
|
|
|
|
|
LinkedList enums; |
69
|
|
|
|
|
|
|
LinkedList structs; |
70
|
|
|
|
|
|
|
LinkedList typedef_lists; |
71
|
|
|
|
|
|
|
HashTable htEnumerators; |
72
|
|
|
|
|
|
|
HashTable htEnums; |
73
|
|
|
|
|
|
|
HashTable htStructs; |
74
|
|
|
|
|
|
|
HashTable htTypedefs; |
75
|
|
|
|
|
|
|
HashTable htFiles; |
76
|
|
|
|
|
|
|
char *errstr; |
77
|
|
|
|
|
|
|
} CParseInfo; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
typedef struct { |
80
|
|
|
|
|
|
|
char *bufptr; |
81
|
|
|
|
|
|
|
unsigned alignment; |
82
|
|
|
|
|
|
|
unsigned align_base; |
83
|
|
|
|
|
|
|
int dataTooShortFlag; |
84
|
|
|
|
|
|
|
Buffer buf; |
85
|
|
|
|
|
|
|
CParseConfig cfg; |
86
|
|
|
|
|
|
|
CParseInfo cpi; |
87
|
|
|
|
|
|
|
ArchSpecs as; |
88
|
|
|
|
|
|
|
enum { |
89
|
|
|
|
|
|
|
ET_INTEGER, ET_STRING, ET_BOTH |
90
|
|
|
|
|
|
|
} enumType; |
91
|
|
|
|
|
|
|
} CBC; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
ENDC |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#------------------------------------------------- |
96
|
|
|
|
|
|
|
# Print the memory map for type 'CBC' with a base |
97
|
|
|
|
|
|
|
# address of 0x01500000. |
98
|
|
|
|
|
|
|
#------------------------------------------------- |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
7
|
memmap( $c, 'CBC', 0x01500000 ); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#========================================================== |
103
|
|
|
|
|
|
|
# SUBROUTINES |
104
|
|
|
|
|
|
|
#========================================================== |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub memmap |
107
|
|
|
|
|
|
|
{ |
108
|
1
|
|
|
1
|
|
5
|
my($c, $type, $start) = @_; |
109
|
1
|
|
50
|
|
|
4
|
$start ||= 0; |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
21
|
my $afmt = '%0' . 2*$c->PointerSize . 'X'; |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
48
|
for my $offset ( 0 .. $c->sizeof( $type ) - 1 ) { |
114
|
140
|
|
|
|
|
602
|
my $m = $c->member( $type, $offset ); |
115
|
140
|
100
|
|
|
|
282
|
rindex( $m, '+' ) < 0 or next; |
116
|
35
|
|
|
|
|
155
|
my $t = $c->typeof( $type.$m ); |
117
|
35
|
|
|
|
|
145
|
printf "$afmt %-16s %s\n", $start+$offset, $t, $m; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |