1 /* Sysprof -- Sampling, systemwide CPU profiler
2 * Copyright 2006, 2007, Soeren Sandmann
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 typedef struct BinParser BinParser
;
21 typedef struct BinRecord BinRecord
;
22 typedef struct BinField BinField
;
26 * BinParser has an offset associated with it. This offset can be
27 * manipulated with methods
29 * goto - go to absolute position from file start
30 * goto_rel - go to relative positio
31 * goto_record_rel - skip the given number of records
32 * align - move forward until aligned to given width
33 * save/restore - save/restore the current offset (stack)
37 * get_offset - return current offset in bytes from start
39 * data can be retrieved with
41 * get_uint - return a uint of given width, and skip
42 * get_string - return a null terminated stringm, and skip
43 * get_pstring - return a 'pascal' string with given length
45 * get_uint_field - return the named field
47 * formats should probably be definable as static data.
49 * A bin parser also has an associated "status" with it. This can be
50 * OK, or error. It is ok to use a parser with an error status, but
51 * the data returned will not be meaningfull.
56 #define BIN_MAX_NAME 52
67 /* More types can (and probably will) be added in the future */
73 const char name
[BIN_MAX_NAME
];
75 char n_bytes
; /* number of bytes in the type */
78 BinParser
* bin_parser_new (const guchar
*data
,
80 void bin_parser_free (BinParser
*parser
);
81 const guchar
*bin_parser_get_data (BinParser
*parser
);
82 gsize
bin_parser_get_length (BinParser
*parser
);
83 void bin_parser_set_endian (BinParser
*parser
,
85 gboolean
bin_parser_error (BinParser
*parser
);
86 void bin_parser_clear_error (BinParser
*parser
);
87 const gchar
* bin_parser_get_error_msg (BinParser
*parser
);
88 BinRecord
* bin_parser_create_record (BinParser
*parser
,
89 const BinField
*fields
);
90 gsize
bin_record_get_size (BinRecord
*record
);
91 guint64
bin_parser_get_uint_field (BinParser
*parser
,
95 /* Move current offset */
96 gsize
bin_parser_get_offset (BinParser
*parser
);
97 void bin_parser_set_offset (BinParser
*parser
,
99 void bin_parser_align (BinParser
*parser
,
101 void bin_parser_seek_record (BinParser
*parser
,
104 void bin_parser_save (BinParser
*parser
);
105 void bin_parser_restore (BinParser
*parser
);
108 guint64
bin_parser_get_uint (BinParser
*parser
,
110 const char * bin_parser_get_string (BinParser
*parser
);