Asm::C - Extract macro values and structure details from C programs.
Given:
struct S {int a; int b; int c; } s; void main() {}
Get:
is_deeply extractCStructure($input), { S => bless({ fields => { a => bless({field => "a", loc => 0, size => 4, type => "int"}, "field"), b => bless({field => "b", loc => 4, size => 4, type => "int"}, "field"), c => bless({field => "c", loc => 8, size => 4, type => "int"}, "field"), }, size => 12, }, "structure")};
Find the value of a macro definition in a C header file:
my $m = extractMacroDefinitionsFromCHeaderFile("linux/mman.h"); is_deeply $$m{MAP_ANONYMOUS}, "0x20";
Extract macro values and structure details from C programs.
Version "20210328".
The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.
Extract structure details from C programs.
Extract the details of a structure
Parameter Description 1 $input Input C file - a temporary one is ok
Example:
is_deeply extractCStructure($input), # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲
Extract the details of a field in a structure in a C file
Parameter Description 1 $input Input file 2 $structure Structure name 3 $field Field within structure
if (1) {my $input = writeTempFile <<END; struct S {int a; int b; int c; } s;
Extract the offset to the location of a field in a structure in a C file
Extract the size of a field in a structure in a C file
Extract the type of a field in a structure in a C file
Extract the names of the fields in a C structure
Parameter Description 1 $input Input file 2 $structure Structure name
Extract the size of a C structure
Extract macro values from C header files
Extract the macro definitions found in a C header file using gcc
Parameter Description 1 $includeFile C Header file name as it would be entered in a C program
if (1) {my $h = "linux/mman.h"; my $m = extractMacroDefinitionsFromCHeaderFile("linux/mman.h"); # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 is_deeply $$m{MAP_ANONYMOUS}, "0x20"; ok extractMacroDefinitionFromCHeaderFile("linux/mman.h", q(PROT_WRITE)) eq "0x2"; }
Extract a macro definitions found in a C header file using gcc
Parameter Description 1 $includeFile C Header file name as it would be entered in a C program 2 $macro Macro name
if (1) {my $h = "linux/mman.h"; my $m = extractMacroDefinitionsFromCHeaderFile("linux/mman.h"); is_deeply $$m{MAP_ANONYMOUS}, "0x20"; ok extractMacroDefinitionFromCHeaderFile("linux/mman.h", q(PROT_WRITE)) eq "0x2"; # 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 }
1 extractCField - Extract the details of a field in a structure in a C file
2 extractCFieldLoc - Extract the offset to the location of a field in a structure in a C file
3 extractCFieldSize - Extract the size of a field in a structure in a C file
4 extractCFieldType - Extract the type of a field in a structure in a C file
5 extractCStructure - Extract the details of a structure
6 extractCStructureFields - Extract the names of the fields in a C structure
7 extractCStructureSize - Extract the size of a C structure
8 extractMacroDefinitionFromCHeaderFile - Extract a macro definitions found in a C header file using gcc
9 extractMacroDefinitionsFromCHeaderFile - Extract the macro definitions found in a C header file using gcc
This module is written in 100% Pure Perl and, thus, it is easy to read, comprehend, use, modify and install via cpan:
sudo cpan install Asm::C
philiprbrenan@gmail.com
http://www.appaapps.com
Copyright (c) 2016-2021 Philip R Brenan.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
To install Asm::C, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Asm::C
CPAN shell
perl -MCPAN -e shell install Asm::C
For more information on module installation, please visit the detailed CPAN module installation guide.