00001 /** 00002 * vim: set ts=4 : 00003 * ============================================================================= 00004 * SourcePawn 00005 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. 00006 * ============================================================================= 00007 * 00008 * This program is free software; you can redistribute it and/or modify it under 00009 * the terms of the GNU General Public License, version 3.0, as published by the 00010 * Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU General Public License along with 00018 * this program. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 * As a special exception, AlliedModders LLC gives you permission to link the 00021 * code of this program (as well as its derivative works) to "Half-Life 2," the 00022 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software 00023 * by the Valve Corporation. You must obey the GNU General Public License in 00024 * all respects for all other code used. Additionally, AlliedModders LLC grants 00025 * this exception to all derivative works. AlliedModders LLC defines further 00026 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), 00027 * or <http://www.sourcemod.net/license.php>. 00028 * 00029 * Version: $Id$ 00030 */ 00031 00032 #ifndef _INCLUDE_SPFILE_HEADERS_H 00033 #define _INCLUDE_SPFILE_HEADERS_H 00034 00035 /** 00036 * @file sp_file_headers.h 00037 * @brief Defines the structure present in a SourcePawn compiled binary. 00038 * 00039 * Note: These structures should be 1-byte packed to match the file format. 00040 */ 00041 00042 #include <stddef.h> 00043 #if defined __GNUC__ || defined HAVE_STDINT_ 00044 #include <stdint.h> 00045 #else 00046 #if !defined HAVE_STDINT_H 00047 typedef unsigned __int64 uint64_t; /**< 64bit unsigned integer */ 00048 typedef __int64 int64_t; /**< 64bit signed integer */ 00049 typedef unsigned __int32 uint32_t; /**< 32bit unsigned integer */ 00050 typedef __int32 int32_t; /**< 32bit signed integer */ 00051 typedef unsigned __int16 uint16_t; /**< 16bit unsigned integer */ 00052 typedef __int16 int16_t; /**< 16bit signed integer */ 00053 typedef unsigned __int8 uint8_t; /**< 8bit unsigned integer */ 00054 typedef __int8 int8_t; /**< 8bit signed integer */ 00055 #define HAVE_STDINT_H 00056 #endif 00057 #endif 00058 00059 #define SPFILE_MAGIC 0x53504646 /**< Source Pawn File Format (SPFF) */ 00060 #define SPFILE_VERSION 0x0102 /**< File format version */ 00061 00062 //:TODO: better compiler/nix support 00063 #if defined __GNUC__ 00064 #pragma pack(1) /* structures must be packed (byte-aligned) */ 00065 #else 00066 #pragma pack(push) 00067 #pragma pack(1) /* structures must be packed (byte-aligned) */ 00068 #endif 00069 00070 #define SPFILE_COMPRESSION_NONE 0 /**< No compression in file */ 00071 #define SPFILE_COMPRESSION_GZ 1 /**< GZ compression */ 00072 00073 /** 00074 * @brief File section header format. 00075 */ 00076 typedef struct sp_file_section_s 00077 { 00078 uint32_t nameoffs; /**< Relative offset into global string table */ 00079 uint32_t dataoffs; /**< Offset into the data section of the file */ 00080 uint32_t size; /**< Size of the section's entry in the data section */ 00081 } sp_file_section_t; 00082 00083 /** 00084 * @brief File header format. If compression is 0, then disksize may be 0 00085 * to mean that only the imagesize is needed. 00086 */ 00087 typedef struct sp_file_hdr_s 00088 { 00089 uint32_t magic; /**< Magic number */ 00090 uint16_t version; /**< Version code */ 00091 uint8_t compression;/**< Compression algorithm */ 00092 uint32_t disksize; /**< Size on disk */ 00093 uint32_t imagesize; /**< Size in memory */ 00094 uint8_t sections; /**< Number of sections */ 00095 uint32_t stringtab; /**< Offset to string table */ 00096 uint32_t dataoffs; /**< Offset to file proper (any compression starts here) */ 00097 } sp_file_hdr_t; 00098 00099 #define SP_FLAG_DEBUG (1<<0) /**< Debug information is present in the file */ 00100 00101 #define SP_CODEVERS_JIT1 9 /**< Code version for JIT1 */ 00102 #define SP_CODEVERS_JIT2 10 /**< Code version for JIT2 */ 00103 00104 /** 00105 * @brief File-encoded format of the ".code" section. 00106 */ 00107 typedef struct sp_file_code_s 00108 { 00109 uint32_t codesize; /**< Codesize in bytes */ 00110 uint8_t cellsize; /**< Cellsize in bytes */ 00111 uint8_t codeversion; /**< Version of opcodes supported */ 00112 uint16_t flags; /**< Flags */ 00113 uint32_t main; /**< Address to "main," if any */ 00114 uint32_t code; /**< Relative offset to code */ 00115 } sp_file_code_t; 00116 00117 /** 00118 * @brief File-encoded format of the ".data" section. 00119 */ 00120 typedef struct sp_file_data_s 00121 { 00122 uint32_t datasize; /**< Size of data section in memory */ 00123 uint32_t memsize; /**< Total mem required (includes data) */ 00124 uint32_t data; /**< File offset to data (helper) */ 00125 } sp_file_data_t; 00126 00127 /** 00128 * @brief File-encoded format of the ".publics" section. 00129 */ 00130 typedef struct sp_file_publics_s 00131 { 00132 uint32_t address; /**< Address relative to code section */ 00133 uint32_t name; /**< Index into nametable */ 00134 } sp_file_publics_t; 00135 00136 /** 00137 * @brief File-encoded format of the ".natives" section. 00138 */ 00139 typedef struct sp_file_natives_s 00140 { 00141 uint32_t name; /**< Index into nametable */ 00142 } sp_file_natives_t; 00143 00144 /** 00145 * @brief File-encoded format of the ".pubvars" section. 00146 */ 00147 typedef struct sp_file_pubvars_s 00148 { 00149 uint32_t address; /**< Address relative to the DAT section */ 00150 uint32_t name; /**< Index into nametable */ 00151 } sp_file_pubvars_t; 00152 00153 /** 00154 * @brief File-encoded tag info. 00155 */ 00156 typedef struct sp_file_tag_s 00157 { 00158 uint32_t tag_id; /**< Tag ID from compiler */ 00159 uint32_t name; /**< Index into nametable */ 00160 } sp_file_tag_t; 00161 00162 /** 00163 * @brief File-encoded debug information table. 00164 */ 00165 typedef struct sp_fdbg_info_s 00166 { 00167 uint32_t num_files; /**< number of files */ 00168 uint32_t num_lines; /**< number of lines */ 00169 uint32_t num_syms; /**< number of symbols */ 00170 uint32_t num_arrays; /**< number of symbols which are arrays */ 00171 } sp_fdbg_info_t; 00172 00173 /** 00174 * @brief File-encoded debug file table. 00175 */ 00176 typedef struct sp_fdbg_file_s 00177 { 00178 uint32_t addr; /**< Address into code */ 00179 uint32_t name; /**< Offset into debug nametable */ 00180 } sp_fdbg_file_t; 00181 00182 /** 00183 * @brief File-encoded debug line table. 00184 */ 00185 typedef struct sp_fdbg_line_s 00186 { 00187 uint32_t addr; /**< Address into code */ 00188 uint32_t line; /**< Line number */ 00189 } sp_fdbg_line_t; 00190 00191 #define SP_SYM_VARIABLE 1 /**< Cell that has an address and that can be fetched directly (lvalue) */ 00192 #define SP_SYM_REFERENCE 2 /**< VARIABLE, but must be dereferenced */ 00193 #define SP_SYM_ARRAY 3 /**< Symbol is an array */ 00194 #define SP_SYM_REFARRAY 4 /**< An array passed by reference (i.e. a pointer) */ 00195 #define SP_SYM_FUNCTION 9 /**< Symbol is a function */ 00196 #define SP_SYM_VARARGS 11 /**< Variadic argument start. */ 00197 00198 /** 00199 * @brief File-encoded debug symbol information. 00200 */ 00201 typedef struct sp_fdbg_symbol_s 00202 { 00203 int32_t addr; /**< Address rel to DAT or stack frame */ 00204 int16_t tagid; /**< Tag id */ 00205 uint32_t codestart; /**< Start scope validity in code */ 00206 uint32_t codeend; /**< End scope validity in code */ 00207 uint8_t ident; /**< Variable type */ 00208 uint8_t vclass; /**< Scope class (local vs global) */ 00209 uint16_t dimcount; /**< Dimension count (for arrays) */ 00210 uint32_t name; /**< Offset into debug nametable */ 00211 } sp_fdbg_symbol_t; 00212 00213 /** 00214 * @brief File-encoded debug symbol array dimension info. 00215 */ 00216 typedef struct sp_fdbg_arraydim_s 00217 { 00218 int16_t tagid; /**< Tag id */ 00219 uint32_t size; /**< Size of dimension */ 00220 } sp_fdbg_arraydim_t; 00221 00222 /** Typedef for .names table */ 00223 typedef char * sp_file_nametab_t; 00224 00225 /** 00226 * @brief File encoding for the dbg.natives table. 00227 * 00228 * This header is followed by variable length entries of sp_fdbg_native. 00229 */ 00230 typedef struct sp_fdbg_ntvtab_s 00231 { 00232 uint32_t num_entries; /**< Number of entries. */ 00233 } sp_fdbg_ntvtab_t; 00234 00235 #define SP_NTVDBG_VARARGS (1<<0) /**< Formal args are followed by '...' */ 00236 00237 /** 00238 * @brief File encoding of native debug info. 00239 * 00240 * Each entry is followed by an sp_fdbg_ntvarg_t for each narg. 00241 */ 00242 typedef struct sp_fdbg_native_s 00243 { 00244 uint32_t index; /**< Native index in the plugin. */ 00245 uint32_t name; /**< Offset into debug nametable. */ 00246 int16_t tagid; /**< Return tag. */ 00247 uint16_t nargs; /**< Number of formal arguments. */ 00248 } sp_fdbg_native_t; 00249 00250 /** 00251 * @brief File encoding of native arguments. 00252 * 00253 * Each entry is followed by an sp_fdbg_arraydim_t for each dimcount. 00254 */ 00255 typedef struct fp_fdbg_ntvarg_s 00256 { 00257 uint8_t ident; /**< Variable type */ 00258 int16_t tagid; /**< Tag id */ 00259 uint16_t dimcount; /**< Dimension count (for arrays) */ 00260 uint32_t name; /**< Offset into debug nametable */ 00261 } sp_fdbg_ntvarg_t; 00262 00263 #if defined __linux__ 00264 #pragma pack() /* reset default packing */ 00265 #else 00266 #pragma pack(pop) /* reset previous packing */ 00267 #endif 00268 00269 /** 00270 * Okay, my mistake here. I apologize. I changed the packing by accident and there is no 00271 * version bump aside from the presence of the native debug table. Cat's out of the bag 00272 * for SourceMod and we have no choice but to shim compat for the old version. For people 00273 * parsing plugins on their own, use the presence of the native debug table to decide this. 00274 * If there are no natives (really, there is a very very low chance of this), heuristics 00275 * might be necessary. I've bumped the version to 0x0102 but there may have been plugins 00276 * in the 0x0101 window with no natives. 00277 */ 00278 00279 /** 00280 * @brief Unpacked file-encoded debug symbol array dimension info. 00281 */ 00282 typedef struct sp_u_fdbg_arraydim_s 00283 { 00284 int16_t tagid; /**< Tag id */ 00285 uint32_t size; /**< Size of dimension */ 00286 } sp_u_fdbg_arraydim_t; 00287 00288 /** 00289 * @brief Unpacked file-encoded debug symbol information. 00290 */ 00291 typedef struct sp_u_fdbg_symbol_s 00292 { 00293 int32_t addr; /**< Address rel to DAT or stack frame */ 00294 int16_t tagid; /**< Tag id */ 00295 uint32_t codestart; /**< Start scope validity in code */ 00296 uint32_t codeend; /**< End scope validity in code */ 00297 uint8_t ident; /**< Variable type */ 00298 uint8_t vclass; /**< Scope class (local vs global) */ 00299 uint16_t dimcount; /**< Dimension count (for arrays) */ 00300 uint32_t name; /**< Offset into debug nametable */ 00301 } sp_u_fdbg_symbol_t; 00302 00303 00304 #endif //_INCLUDE_SPFILE_HEADERS_H 00305
1.5.1