C headers parser and “Binary Data Conversion using C Types” Yossi Itzkovich Feb 2013.

Slides:



Advertisements
Similar presentations
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
THE PREPROCESSOR. Preprocessing is (apparently) done before actual compilation begins. The preprocessor doesnt know (very much) C. Major kinds of preprocessor.
Compilation and Debugging 101. Compilation in C/C++ hello.c Preprocessor Compiler stdio.h tmpXQ.i (C code) hello.o (object file)
C Language.
Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
Bit Field.
C Intro.
Union, bitfield, typedef, enum union nama_u{ }; union nama_u{ struct nama_s byte; }; enum{ }; Tipedef var BYTE.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
Introduction Computer program: an ordered sequence of instructions whose objective is to accomplish a task. Programming: process of planning and creating.
Cs4411 – Operating Systems Practicum October 14, 2011 Zhiyuan Teo Supplementary lecture 3.
Data Types in the Kernel Sarah Diesburg COP 5641.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
Lecture 16 CIS 208 Friday March 18 th, Last bit on structs, I swear Structs in Debugger It’s your friend.
System definition file (defsystem foo :components … :depends-on … ) FIND-SYSTEM Function Request for system Configuration.
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
Engineering Computing I Chapter 6 Structures. Sgtructures  A structure is a collection of one or more variables, possibly of different types, grouped.
C Tokens Identifiers Keywords Constants Operators Special symbols.
1 Homework HW6 due class 22 K&R 6.6 K&R 5.7 – 5.9 (skipped earlier) Finishing up K&R Chapter 6.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Programming in C Structs and Unions. Java vs C Suppose you were assigned a write an application about points and straight lines in a coordinate plane.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
 2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
Homework Finishing up K&R Chapter 6 today Also, K&R 5.7 – 5.9 (skipped earlier)
1 Review. 2 Creating a Runnable Program  What is the function of the compiler?  What is the function of the linker?  Java doesn't have a linker. If.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
Structures and Unions in C Alan L. Cox
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
Weekly C-minar Week 0. Today: Steps of the compile Basic inclusion/syntax rules Low-cost containment Debugging.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 12 – C: structs, linked lists, and casts.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
Presented by: © 2015 Jacob Beningo All Rights Reserved Writing Portable and Robust Firmware in C September 2, 2015 Jacob Beningo, CSDP Class 3: Uart Driver.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Basic Data Types & Memory & Representation. Basic data types Primitive data types are similar to JAVA: char int short long float double Unlike in JAVA,
C++ Functions A bit of review (things we’ve covered so far)
1 Building a program in C: Preprocessor, Compilation and Linkage.
Numbers in ‘C’ Two general categories: Integers Floats
Basic Data Types & Memory & Representation
C++ Lesson 1.
Introduction to C Programming
PHP (PHP: Hypertext Preprocessor)
CSE 374 Programming Concepts & Tools
C Basics.
Choice of Programming Language
Methods and Parameters
C Structures, Unions, Bit Manipulations and Enumerations
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
פרטים נוספים בסילבוס של הקורס
פרטים נוספים בסילבוס של הקורס
Govt. Polytechnic,Dhangar
C Structures, Unions, Bit Manipulations and Enumerations
WEEK-2.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
INTRODUCTION TO C.
Presentation transcript:

C headers parser and “Binary Data Conversion using C Types” Yossi Itzkovich Feb 2013

 A lot of convenience methods to retrieve information about the C types that have been parse.  A C Preprocessor  A Parser for C type definitions  Using pack() and unpack() with C types instead of a string representation of the data structure for conversion of binary data from and to Perl's complex data structures

 struct foo { char ary[3]; unsigned short baz; int bar; };  Perl code: = (1, 2, 3); my $baz = 40000; my $bar = -4711; my $binary = pack ('c3 S $baz, $bar) ;  What are the disadvantages with the above coding ?

 The disadvantages are:  Maintaining 2 sources (C, Perl)  Not practical for complicated C structures  Alignment issues

use Convert::Binary::C my $c = new Convert::Binary::C (optional_configuration) $c->parse_file(file_name)

my $data = { ary => [1, 2, 3], baz => 40000, bar => -4711, }; $binary = $c->pack('foo', $data);

my $binary = get_data_from_memory(); my $data = $c->unpack('foo', $binary); say "foo.ary[1] = $data->{ary}[1]"; Or use Data::Dumper: say Dumper($data);

 As there are over 20 different configuration options, setting all of them correctly can be a lengthy and tedious task.  The ccconfig script, which is bundled with this module, aims at automatically determining the correct compiler configuration by testing the compiler executable. It works for both, native and cross compilers.ccconfig

 Important methods:  sizeof  member, offsetof  typeof  def, defined  enum_names, enum  struct_names, struct  union_names, union  typedf_names, typedef  macro_names, macro  compound_names, compound

 In ECI Telecom, in the EMS-XDM project we use it:  Parse embedded header files that define the protocol.  Endian conversion  Backward compatibility

 'Define' => [ 'DEBUGGING', 'FOO=123' ],  'StdCVersion' => ,  'ByteOrder' => 'LittleEndian',  'LongSize' => 4, 'IntSize' => 4, 'DoubleSize' => 8, 'CharSize' => 1,  'PointerSize' => 4, 'EnumSize' => 4, 'ShortSize' => 2,, 'LongLongSize' => 8, 'LongDoubleSize' => 12, 'FloatSize' => 4,  'HostedC' => 1,  'HasMacroVAARGS' => 1,  'Assert' => [],  'UnsignedChars' => 0, , 'EnumType' => 'Integer‘, DisabledKeywords' => [], 'Alignment' => 1, 'KeywordMap' => {}, 'Include' => [ '/usr/include' ], 'HasCPPComments' => 1, 'Bitfields' => { 'Engine' => 'Generic' }, 'UnsignedBitfields' => 0, 'Warnings' => 0, 'CompoundAlignment' => 1, 'OrderMembers' => 0