Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
- /*
- * File: symbols.h
- * ----------------
- * This is where you declare any exported features of the symbols.c
- * module. As is good header file practice, you should take care to
- * set the header up to work correctly even if included more than once.
- */
- #ifndef _symbols_h
- #define _symbols_h
- #include <stdbool.h> // this header defines the C99 bool type
- /*
- * The <elf.h> header already declares structs for the file header, section header,
- * symbols, etc. but the naming conventions are cryptic and multi-layered, which
- * makes it a hassle to try to figure out what a particular field/type boils down
- * to, so we declare our own version of these structures with simpler names
- * to keep things cleaner for you. We do directly use the #define-d ELF constants
- * such as SHT_SYMTAB, SHT_STRTAB, STT_FUNC which come from <elf.h>
- */
- /* Type: Elf_File_Header
- * ---------------------
- * A struct that describes the data found in first few bytes of Elf file.
- */
- typedef struct {
- char identity[16]; // ELF specification information
- int other_ints[4]; // you can ignore these fields
- int offset_to_section_header_table; // offset in bytes from start of file to section headers
- short other_shorts[6]; // you can ignore these fields
- short number_of_section_headers; // count of section headers in table
- } Elf_File_Header;
- /* Type: Elf_Section_Header
- * ------------------------
- * A struct that describes the data for each section header. The section
- * header table is a contiguous array of section header structs.
- */
- typedef struct {
- int name;
- int type; // type of section: SHT_SYMTAB, SHT_STRTAB, SHT_REL, etc.
- int flags;
- int addr;
- int offset; // offset in bytes from file begin to where sectn data starts
- int size; // number of bytes of data in the section
- int strtab_index; // index into section header table for associated string table section
- int other_ints[3];
- } Elf_Section_Header;
- /* Type: Elf_Symbol
- * ----------------
- * A struct that describes the data for each symbol. The symtab
- * section is a contiguous array of symbol structs.
- */
- typedef struct {
- int name; // offset into string table for symbol name
- int address; // symbol address
- int size; // symbol size in bytes
- char type_and_binding; // low-order 4 bits are type (STT_FUNC, STT_OBJECT)
- // high-order 4 bits are binding (STB_LOCAL, STB_GLOBAL)
- char reserved;
- char section_tag; // will be SHN_UNDEF if symbol is undefined
- } Elf_Symbol;
- /* Type: Symbol
- * ----------------
- * A struct that describes the data for each symbol, and is what is returned to the client.
- */
- typedef struct {
- char* name;
- int address;
- int size;
- } Func_Symbol;
- /* Type: Function_Table
- * --------------------
- * A struct that manages the table of symbols
- */
- typedef struct {
- Func_Symbol* table;
- int count;
- } Client_Symbol_Table;
- /* Function: GetFunctionSymbolsTable
- * ---------------------------------
- * The main function exported by symbol.c. This function, given a string filename, checks for formatting mistakes,
- * parses the ELF file, builds a symbol table, and returns a pointer to the table.
- */
- void *GetFunctionTable(const char *filename, int* count);
- /* Function: FreeFunctionSymbolsTable
- * ----------------------------------
- * Frees memory associated with a table of function symbols
- */
- void FreeFunctionSymbolsTable(char *func_table);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement