├── .travis.yml ├── ELFDump.xcodeproj ├── xcuserdata │ └── macmade.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcuserdata │ │ └── macmade.xcuserdatad │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ │ └── ELFDump.xccheckout ├── xcshareddata │ └── xcschemes │ │ └── ELFDump.xcscheme └── project.pbxproj ├── README.md └── ELFDump ├── main.c ├── elf.h └── elf.c /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | xcode_project: ELFDump.xcodeproj 3 | xcode_scheme: ELFDump 4 | -------------------------------------------------------------------------------- /ELFDump.xcodeproj/xcuserdata/macmade.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /ELFDump.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ELFDump.xcodeproj/project.xcworkspace/xcuserdata/macmade.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/macmade/ELFDump/HEAD/ELFDump.xcodeproj/project.xcworkspace/xcuserdata/macmade.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ELFDump.xcodeproj/project.xcworkspace/xcuserdata/macmade.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ELFDump.xcodeproj/xcuserdata/macmade.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ELFDump.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 05946C4B18A6246900D2FD40 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ELFDump 2 | ======= 3 | 4 | [![Build Status](https://img.shields.io/travis/macmade/ELFDump.svg?branch=master&style=flat)](https://travis-ci.org/macmade/ELFDump) 5 | [![Issues](http://img.shields.io/github/issues/macmade/ELFDump.svg?style=flat)](https://github.com/macmade/ELFDump/issues) 6 | ![Status](https://img.shields.io/badge/status-inactive-lightgray.svg?style=flat) 7 | ![License](https://img.shields.io/badge/license-xeos-brightgreen.svg?style=flat) 8 | [![Contact](https://img.shields.io/badge/contact-@macmade-blue.svg?style=flat)](https://twitter.com/macmade) 9 | [![Donate-Patreon](https://img.shields.io/badge/donate-patreon-yellow.svg?style=flat)](https://patreon.com/macmade) 10 | [![Donate-Gratipay](https://img.shields.io/badge/donate-gratipay-yellow.svg?style=flat)](https://www.gratipay.com/macmade) 11 | [![Donate-Paypal](https://img.shields.io/badge/donate-paypal-yellow.svg?style=flat)](https://paypal.me/xslabs) 12 | 13 | About 14 | ----- 15 | 16 | ELFDump is a C parser for ELF64 object files. 17 | 18 | License 19 | ------- 20 | 21 | ELFDump is released under the terms of the XEOS Software License. 22 | 23 | Repository Infos 24 | ---------------- 25 | 26 | Owner: Jean-David Gadina - XS-Labs 27 | Web: www.xs-labs.com 28 | Blog: www.noxeos.com 29 | Twitter: @macmade 30 | GitHub: github.com/macmade 31 | LinkedIn: ch.linkedin.com/in/macmade/ 32 | StackOverflow: stackoverflow.com/users/182676/macmade 33 | -------------------------------------------------------------------------------- /ELFDump.xcodeproj/project.xcworkspace/xcshareddata/ELFDump.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 5CB0F919-2D58-40C7-A45D-D27DB4861868 9 | IDESourceControlProjectName 10 | ELFDump 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 65DF393D-87FB-4388-BA5C-F5B8F4160BB3 14 | ssh://github.com/macmade/ELFReader.git 15 | 16 | IDESourceControlProjectPath 17 | ELFDump.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 65DF393D-87FB-4388-BA5C-F5B8F4160BB3 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | ssh://github.com/macmade/ELFReader.git 25 | IDESourceControlProjectVersion 26 | 110 27 | IDESourceControlProjectWCCIdentifier 28 | 65DF393D-87FB-4388-BA5C-F5B8F4160BB3 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 65DF393D-87FB-4388-BA5C-F5B8F4160BB3 36 | IDESourceControlWCCName 37 | ELFReader 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ELFDump.xcodeproj/xcshareddata/xcschemes/ELFDump.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 68 | 69 | 72 | 73 | 76 | 77 | 78 | 79 | 80 | 81 | 87 | 89 | 95 | 96 | 97 | 98 | 100 | 101 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /ELFDump.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 05946C9218A7A0E100D2FD40 /* elf.c in Sources */ = {isa = PBXBuildFile; fileRef = 05946C8F18A7A0E100D2FD40 /* elf.c */; }; 11 | 05946C9318A7A0E100D2FD40 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 05946C9118A7A0E100D2FD40 /* main.c */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXCopyFilesBuildPhase section */ 15 | 05946C4A18A6246900D2FD40 /* CopyFiles */ = { 16 | isa = PBXCopyFilesBuildPhase; 17 | buildActionMask = 2147483647; 18 | dstPath = /usr/share/man/man1/; 19 | dstSubfolderSpec = 0; 20 | files = ( 21 | ); 22 | runOnlyForDeploymentPostprocessing = 1; 23 | }; 24 | /* End PBXCopyFilesBuildPhase section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 05946C4C18A6246900D2FD40 /* ELFDump */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ELFDump; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 05946C8F18A7A0E100D2FD40 /* elf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = elf.c; sourceTree = ""; }; 29 | 05946C9018A7A0E100D2FD40 /* elf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = elf.h; sourceTree = ""; }; 30 | 05946C9118A7A0E100D2FD40 /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 05946C4918A6246900D2FD40 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 05946C4318A6246900D2FD40 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 05946C8E18A7A0E100D2FD40 /* ELFDump */, 48 | 05946C4D18A6246900D2FD40 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | 05946C4D18A6246900D2FD40 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 05946C4C18A6246900D2FD40 /* ELFDump */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | 05946C8E18A7A0E100D2FD40 /* ELFDump */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 05946C9018A7A0E100D2FD40 /* elf.h */, 64 | 05946C8F18A7A0E100D2FD40 /* elf.c */, 65 | 05946C9118A7A0E100D2FD40 /* main.c */, 66 | ); 67 | path = ELFDump; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | 05946C4B18A6246900D2FD40 /* ELFDump */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = 05946C5518A6246900D2FD40 /* Build configuration list for PBXNativeTarget "ELFDump" */; 76 | buildPhases = ( 77 | 05946C4818A6246900D2FD40 /* Sources */, 78 | 05946C4918A6246900D2FD40 /* Frameworks */, 79 | 05946C4A18A6246900D2FD40 /* CopyFiles */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = ELFDump; 86 | productName = ELF; 87 | productReference = 05946C4C18A6246900D2FD40 /* ELFDump */; 88 | productType = "com.apple.product-type.tool"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | 05946C4418A6246900D2FD40 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastUpgradeCheck = 0820; 97 | ORGANIZATIONNAME = "XS-Labs"; 98 | }; 99 | buildConfigurationList = 05946C4718A6246900D2FD40 /* Build configuration list for PBXProject "ELFDump" */; 100 | compatibilityVersion = "Xcode 3.2"; 101 | developmentRegion = English; 102 | hasScannedForEncodings = 0; 103 | knownRegions = ( 104 | en, 105 | ); 106 | mainGroup = 05946C4318A6246900D2FD40; 107 | productRefGroup = 05946C4D18A6246900D2FD40 /* Products */; 108 | projectDirPath = ""; 109 | projectRoot = ""; 110 | targets = ( 111 | 05946C4B18A6246900D2FD40 /* ELFDump */, 112 | ); 113 | }; 114 | /* End PBXProject section */ 115 | 116 | /* Begin PBXSourcesBuildPhase section */ 117 | 05946C4818A6246900D2FD40 /* Sources */ = { 118 | isa = PBXSourcesBuildPhase; 119 | buildActionMask = 2147483647; 120 | files = ( 121 | 05946C9318A7A0E100D2FD40 /* main.c in Sources */, 122 | 05946C9218A7A0E100D2FD40 /* elf.c in Sources */, 123 | ); 124 | runOnlyForDeploymentPostprocessing = 0; 125 | }; 126 | /* End PBXSourcesBuildPhase section */ 127 | 128 | /* Begin XCBuildConfiguration section */ 129 | 05946C5318A6246900D2FD40 /* Debug */ = { 130 | isa = XCBuildConfiguration; 131 | buildSettings = { 132 | ALWAYS_SEARCH_USER_PATHS = NO; 133 | CLANG_ANALYZER_DEADCODE_DEADSTORES = YES; 134 | CLANG_ANALYZER_GCD = YES; 135 | CLANG_ANALYZER_MEMORY_MANAGEMENT = YES; 136 | CLANG_ANALYZER_OBJC_ATSYNC = YES; 137 | CLANG_ANALYZER_OBJC_COLLECTIONS = YES; 138 | CLANG_ANALYZER_OBJC_INCOMP_METHOD_TYPES = YES; 139 | CLANG_ANALYZER_OBJC_NSCFERROR = YES; 140 | CLANG_ANALYZER_OBJC_RETAIN_COUNT = YES; 141 | CLANG_ANALYZER_OBJC_SELF_INIT = YES; 142 | CLANG_ANALYZER_OBJC_UNUSED_IVARS = YES; 143 | CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; 144 | CLANG_ANALYZER_SECURITY_INSECUREAPI_GETPW_GETS = YES; 145 | CLANG_ANALYZER_SECURITY_INSECUREAPI_MKSTEMP = YES; 146 | CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; 147 | CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES; 148 | CLANG_ANALYZER_SECURITY_INSECUREAPI_UNCHECKEDRETURN = YES; 149 | CLANG_ANALYZER_SECURITY_KEYCHAIN_API = YES; 150 | CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; 151 | CLANG_CXX_LIBRARY = "libc++"; 152 | CLANG_ENABLE_MODULES = YES; 153 | CLANG_ENABLE_OBJC_ARC = YES; 154 | CLANG_STATIC_ANALYZER_MODE = deep; 155 | CLANG_STATIC_ANALYZER_MODE_ON_ANALYZE_ACTION = deep; 156 | CLANG_WARN_BOOL_CONVERSION = YES; 157 | CLANG_WARN_CONSTANT_CONVERSION = YES; 158 | CLANG_WARN_CXX0X_EXTENSIONS = YES; 159 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 160 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 161 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 162 | CLANG_WARN_EMPTY_BODY = YES; 163 | CLANG_WARN_ENUM_CONVERSION = YES; 164 | CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; 165 | CLANG_WARN_INFINITE_RECURSION = YES; 166 | CLANG_WARN_INT_CONVERSION = YES; 167 | CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; 168 | CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; 169 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 170 | CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; 171 | CLANG_WARN_OBJC_RECEIVER_WEAK = YES; 172 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; 173 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 174 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; 175 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 176 | CLANG_WARN_UNREACHABLE_CODE = YES; 177 | CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES; 178 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 179 | CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES; 180 | COPY_PHASE_STRIP = NO; 181 | ENABLE_STRICT_OBJC_MSGSEND = YES; 182 | ENABLE_TESTABILITY = YES; 183 | GCC_C_LANGUAGE_STANDARD = c99; 184 | GCC_DYNAMIC_NO_PIC = NO; 185 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 186 | GCC_NO_COMMON_BLOCKS = YES; 187 | GCC_OPTIMIZATION_LEVEL = 0; 188 | GCC_PREPROCESSOR_DEFINITIONS = ( 189 | "DEBUG=1", 190 | "$(inherited)", 191 | ); 192 | GCC_STRICT_ALIASING = NO; 193 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 194 | GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; 195 | GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; 196 | GCC_TREAT_WARNINGS_AS_ERRORS = YES; 197 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 198 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES; 199 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES; 200 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; 201 | GCC_WARN_ABOUT_MISSING_NEWLINE = YES; 202 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 203 | GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES; 204 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 205 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES; 206 | GCC_WARN_CHECK_SWITCH_STATEMENTS = YES; 207 | GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; 208 | GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; 209 | GCC_WARN_INHIBIT_ALL_WARNINGS = NO; 210 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; 211 | GCC_WARN_MISSING_PARENTHESES = YES; 212 | GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES; 213 | GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; 214 | GCC_WARN_PEDANTIC = YES; 215 | GCC_WARN_SHADOW = YES; 216 | GCC_WARN_SIGN_COMPARE = YES; 217 | GCC_WARN_STRICT_SELECTOR_MATCH = YES; 218 | GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNKNOWN_PRAGMAS = YES; 222 | GCC_WARN_UNUSED_FUNCTION = YES; 223 | GCC_WARN_UNUSED_LABEL = YES; 224 | GCC_WARN_UNUSED_PARAMETER = YES; 225 | GCC_WARN_UNUSED_VALUE = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | MACOSX_DEPLOYMENT_TARGET = 10.9; 228 | ONLY_ACTIVE_ARCH = YES; 229 | OTHER_CFLAGS = "-Weverything"; 230 | RUN_CLANG_STATIC_ANALYZER = YES; 231 | SDKROOT = macosx; 232 | }; 233 | name = Debug; 234 | }; 235 | 05946C5418A6246900D2FD40 /* Release */ = { 236 | isa = XCBuildConfiguration; 237 | buildSettings = { 238 | ALWAYS_SEARCH_USER_PATHS = NO; 239 | CLANG_ANALYZER_DEADCODE_DEADSTORES = YES; 240 | CLANG_ANALYZER_GCD = YES; 241 | CLANG_ANALYZER_MEMORY_MANAGEMENT = YES; 242 | CLANG_ANALYZER_OBJC_ATSYNC = YES; 243 | CLANG_ANALYZER_OBJC_COLLECTIONS = YES; 244 | CLANG_ANALYZER_OBJC_INCOMP_METHOD_TYPES = YES; 245 | CLANG_ANALYZER_OBJC_NSCFERROR = YES; 246 | CLANG_ANALYZER_OBJC_RETAIN_COUNT = YES; 247 | CLANG_ANALYZER_OBJC_SELF_INIT = YES; 248 | CLANG_ANALYZER_OBJC_UNUSED_IVARS = YES; 249 | CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; 250 | CLANG_ANALYZER_SECURITY_INSECUREAPI_GETPW_GETS = YES; 251 | CLANG_ANALYZER_SECURITY_INSECUREAPI_MKSTEMP = YES; 252 | CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; 253 | CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES; 254 | CLANG_ANALYZER_SECURITY_INSECUREAPI_UNCHECKEDRETURN = YES; 255 | CLANG_ANALYZER_SECURITY_KEYCHAIN_API = YES; 256 | CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; 257 | CLANG_CXX_LIBRARY = "libc++"; 258 | CLANG_ENABLE_MODULES = YES; 259 | CLANG_ENABLE_OBJC_ARC = YES; 260 | CLANG_STATIC_ANALYZER_MODE = deep; 261 | CLANG_STATIC_ANALYZER_MODE_ON_ANALYZE_ACTION = deep; 262 | CLANG_WARN_BOOL_CONVERSION = YES; 263 | CLANG_WARN_CONSTANT_CONVERSION = YES; 264 | CLANG_WARN_CXX0X_EXTENSIONS = YES; 265 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 268 | CLANG_WARN_EMPTY_BODY = YES; 269 | CLANG_WARN_ENUM_CONVERSION = YES; 270 | CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES; 271 | CLANG_WARN_INFINITE_RECURSION = YES; 272 | CLANG_WARN_INT_CONVERSION = YES; 273 | CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES; 274 | CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; 275 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 276 | CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; 277 | CLANG_WARN_OBJC_RECEIVER_WEAK = YES; 278 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES; 281 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 282 | CLANG_WARN_UNREACHABLE_CODE = YES; 283 | CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES; 286 | COPY_PHASE_STRIP = YES; 287 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 288 | ENABLE_NS_ASSERTIONS = NO; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | GCC_C_LANGUAGE_STANDARD = c99; 291 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 292 | GCC_NO_COMMON_BLOCKS = YES; 293 | GCC_OPTIMIZATION_LEVEL = s; 294 | GCC_STRICT_ALIASING = NO; 295 | GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; 296 | GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; 297 | GCC_TREAT_WARNINGS_AS_ERRORS = YES; 298 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 299 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES; 300 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES; 301 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; 302 | GCC_WARN_ABOUT_MISSING_NEWLINE = YES; 303 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 304 | GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES; 305 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 306 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES; 307 | GCC_WARN_CHECK_SWITCH_STATEMENTS = YES; 308 | GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; 309 | GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES; 310 | GCC_WARN_INHIBIT_ALL_WARNINGS = NO; 311 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; 312 | GCC_WARN_MISSING_PARENTHESES = YES; 313 | GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES; 314 | GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; 315 | GCC_WARN_PEDANTIC = YES; 316 | GCC_WARN_SHADOW = YES; 317 | GCC_WARN_SIGN_COMPARE = YES; 318 | GCC_WARN_STRICT_SELECTOR_MATCH = YES; 319 | GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; 320 | GCC_WARN_UNDECLARED_SELECTOR = YES; 321 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 322 | GCC_WARN_UNKNOWN_PRAGMAS = YES; 323 | GCC_WARN_UNUSED_FUNCTION = YES; 324 | GCC_WARN_UNUSED_LABEL = YES; 325 | GCC_WARN_UNUSED_PARAMETER = YES; 326 | GCC_WARN_UNUSED_VALUE = YES; 327 | GCC_WARN_UNUSED_VARIABLE = YES; 328 | MACOSX_DEPLOYMENT_TARGET = 10.9; 329 | OTHER_CFLAGS = "-Weverything"; 330 | RUN_CLANG_STATIC_ANALYZER = YES; 331 | SDKROOT = macosx; 332 | }; 333 | name = Release; 334 | }; 335 | 05946C5618A6246900D2FD40 /* Debug */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | PRODUCT_NAME = ELFDump; 339 | }; 340 | name = Debug; 341 | }; 342 | 05946C5718A6246900D2FD40 /* Release */ = { 343 | isa = XCBuildConfiguration; 344 | buildSettings = { 345 | PRODUCT_NAME = ELFDump; 346 | }; 347 | name = Release; 348 | }; 349 | /* End XCBuildConfiguration section */ 350 | 351 | /* Begin XCConfigurationList section */ 352 | 05946C4718A6246900D2FD40 /* Build configuration list for PBXProject "ELFDump" */ = { 353 | isa = XCConfigurationList; 354 | buildConfigurations = ( 355 | 05946C5318A6246900D2FD40 /* Debug */, 356 | 05946C5418A6246900D2FD40 /* Release */, 357 | ); 358 | defaultConfigurationIsVisible = 0; 359 | defaultConfigurationName = Release; 360 | }; 361 | 05946C5518A6246900D2FD40 /* Build configuration list for PBXNativeTarget "ELFDump" */ = { 362 | isa = XCConfigurationList; 363 | buildConfigurations = ( 364 | 05946C5618A6246900D2FD40 /* Debug */, 365 | 05946C5718A6246900D2FD40 /* Release */, 366 | ); 367 | defaultConfigurationIsVisible = 0; 368 | defaultConfigurationName = Release; 369 | }; 370 | /* End XCConfigurationList section */ 371 | }; 372 | rootObject = 05946C4418A6246900D2FD40 /* Project object */; 373 | } 374 | -------------------------------------------------------------------------------- /ELFDump/main.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * XEOS - X86 Experimental Operating System 3 | * 4 | * Copyright (c) 2010-2013, Jean-David Gadina - www.xs-labs.com 5 | * All rights reserved. 6 | * 7 | * XEOS Software License - Version 1.0 - December 21, 2012 8 | * 9 | * Permission is hereby granted, free of charge, to any person or organisation 10 | * obtaining a copy of the software and accompanying documentation covered by 11 | * this license (the "Software") to deal in the Software, with or without 12 | * modification, without restriction, including without limitation the rights 13 | * to use, execute, display, copy, reproduce, transmit, publish, distribute, 14 | * modify, merge, prepare derivative works of the Software, and to permit 15 | * third-parties to whom the Software is furnished to do so, all subject to the 16 | * following conditions: 17 | * 18 | * 1. Redistributions of source code, in whole or in part, must retain the 19 | * above copyright notice and this entire statement, including the 20 | * above license grant, this restriction and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice and this entire statement, including the above license grant, 24 | * this restriction and the following disclaimer in the documentation 25 | * and/or other materials provided with the distribution, unless the 26 | * Software is distributed by the copyright owner as a library. 27 | * A "library" means a collection of software functions and/or data 28 | * prepared so as to be conveniently linked with application programs 29 | * (which use some of those functions and data) to form executables. 30 | * 31 | * 3. The Software, or any substancial portion of the Software shall not 32 | * be combined, included, derived, or linked (statically or 33 | * dynamically) with software or libraries licensed under the terms 34 | * of any GNU software license, including, but not limited to, the GNU 35 | * General Public License (GNU/GPL) or the GNU Lesser General Public 36 | * License (GNU/LGPL). 37 | * 38 | * 4. All advertising materials mentioning features or use of this 39 | * software must display an acknowledgement stating that the product 40 | * includes software developed by the copyright owner. 41 | * 42 | * 5. Neither the name of the copyright owner nor the names of its 43 | * contributors may be used to endorse or promote products derived from 44 | * this software without specific prior written permission. 45 | * 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS "AS IS" 47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 48 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 49 | * PURPOSE, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED. 50 | * 51 | * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR ANYONE DISTRIBUTING 52 | * THE SOFTWARE BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 53 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 54 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 55 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 56 | * WHETHER IN ACTION OF CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 57 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF OR IN CONNECTION WITH 58 | * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE, EVEN IF ADVISED 59 | * OF THE POSSIBILITY OF SUCH DAMAGE. 60 | ******************************************************************************/ 61 | 62 | /* $Id$ */ 63 | 64 | #include "elf.h" 65 | #include 66 | #include 67 | #include 68 | 69 | int main( int argc, char * argv[] ) 70 | { 71 | FILE * fh; 72 | char * data; 73 | char * buf; 74 | size_t size; 75 | size_t alloc; 76 | bool showStrings; 77 | bool showSymbols; 78 | 79 | fh = NULL; 80 | data = NULL; 81 | 82 | if( argc < 2 ) 83 | { 84 | { 85 | char * exec; 86 | 87 | exec = strrchr( argv[ 0 ], '/' ); 88 | 89 | if( exec != argv[ 0 ] ) 90 | { 91 | exec++; 92 | } 93 | 94 | printf 95 | ( 96 | "Usage: %s [OPTIONS] \n" 97 | "\n" 98 | "Options:\n" 99 | "\n" 100 | " --all Displays everything\n" 101 | " --strings Displays the content of string tables\n" 102 | " --symbols Displays the content of symbol tables\n", 103 | exec 104 | ); 105 | } 106 | 107 | return EXIT_SUCCESS; 108 | } 109 | 110 | showStrings = false; 111 | showSymbols = false; 112 | 113 | { 114 | int arg; 115 | 116 | for( arg = 1; arg < argc; arg++ ) 117 | { 118 | if( strcmp( argv[ arg ], "--strings" ) == 0 ) 119 | { 120 | showStrings = true; 121 | } 122 | 123 | if( strcmp( argv[ arg ], "--symbols" ) == 0 ) 124 | { 125 | showSymbols = true; 126 | } 127 | 128 | if( strcmp( argv[ arg ], "--all" ) == 0 ) 129 | { 130 | showStrings = true; 131 | showSymbols = true; 132 | } 133 | } 134 | } 135 | 136 | if( ( fh = fopen( argv[ argc - 1 ], "r" ) ) == NULL ) 137 | { 138 | goto error; 139 | } 140 | 141 | if( ( data = malloc( 4096 ) ) == NULL ) 142 | { 143 | goto error; 144 | } 145 | 146 | buf = data; 147 | alloc = 1; 148 | size = alloc; 149 | 150 | while( fread( buf, 1, alloc, fh ) ) 151 | { 152 | size += alloc; 153 | 154 | if( ( data = realloc( data, size ) ) == NULL ) 155 | { 156 | goto error; 157 | } 158 | 159 | buf = data + ( size - alloc ); 160 | } 161 | 162 | { 163 | ELF64_FileRef file; 164 | ELF64_HeaderRef header; 165 | ELF64_ProgramHeaderEntryRef pHeader; 166 | ELF64_SectionHeaderEntryRef sHeader; 167 | ELF64_Half i; 168 | 169 | file = ELF64_ReadFromData( data ); 170 | header = ELF64_FileGetHeader( file ); 171 | 172 | if( ELF64_FileIsValid( file ) == false ) 173 | { 174 | printf( "Invalid ELF64 file...\n" ); 175 | 176 | goto end; 177 | } 178 | 179 | printf 180 | ( 181 | "ELF64 File:\n" 182 | "===========\n" 183 | "\n" 184 | "Header infos:\n" 185 | "-------------\n" 186 | "\n" 187 | " - Object file class: %s\n" 188 | " - Data encoding: %s\n" 189 | " - File version: %u\n" 190 | " - OS ABI: %s\n" 191 | " - Object file type: %s\n" 192 | " - Version: %u\n" 193 | " - Machine: %s\n" 194 | " - Entry point address: 0x%016llX\n" 195 | " - Program header offset: %lu\n" 196 | " - Section header offset: %lu\n" 197 | " - Processor-specific flags: %lu\n" 198 | " - ELF header size: %lu\n" 199 | " - Size of program header entry: %lu\n" 200 | " - Number of program header entries: %lu\n" 201 | " - Size of section header entry: %lu\n" 202 | " - Number of section header entries: %lu\n" 203 | " - Section name string table index: %lu\n", 204 | 205 | ELF64_HeaderGetObjectFileClassString( header ), 206 | ELF64_HeaderGetDataEncodingString( header ), 207 | ELF64_HeaderGetFileVersion( header ), 208 | ELF64_HeaderGetOSABIString( header ), 209 | ELF64_HeaderGetObjectFileTypeString( header ), 210 | ELF64_HeaderGetVersion( header ), 211 | ELF64_HeaderGetMachineTypeString( header ), 212 | ELF64_HeaderGetEntryPointAddress( header ), 213 | ( unsigned long )ELF64_HeaderGetProgramHeaderOffset( header ), 214 | ( unsigned long )ELF64_HeaderGetSectionHeaderOffset( header ), 215 | ( unsigned long )ELF64_HeaderGetProcessorSpecificFlags( header ), 216 | ( unsigned long )ELF64_HeaderGetHeaderSize( header ), 217 | ( unsigned long )ELF64_HeaderGetProgramHeaderEntrySize( header ), 218 | ( unsigned long )ELF64_HeaderGetProgramHeaderEntryCount( header ), 219 | ( unsigned long )ELF64_HeaderGetSectionHeaderEntrySize( header ), 220 | ( unsigned long )ELF64_HeaderGetSectionHeaderEntryCount( header ), 221 | ( unsigned long )ELF64_HeaderGetSectionNameStringTableIndex( header ) 222 | ); 223 | 224 | printf 225 | ( 226 | "\n" 227 | "Program header entries:\n" 228 | "-----------------------\n" 229 | "\n" 230 | ); 231 | 232 | for( i = 0; i < ELF64_HeaderGetProgramHeaderEntryCount( header ); i++ ) 233 | { 234 | pHeader = ELF64_FileGetProgramHeaderEntry( file, i ); 235 | 236 | printf 237 | ( 238 | " ### Program header entry (%lu):\n" 239 | " \n" 240 | " - Segment type: %s\n" 241 | " - Segment attributes: %lu (%s)\n" 242 | " - Offset in file: 0x%016llX\n" 243 | " - Virtual address in memory: 0x%016llX\n" 244 | " - Size of segment in file: %lu\n" 245 | " - Size of segment in memory: %lu\n" 246 | " - Alignment of segment: %lu\n" 247 | " \n", 248 | ( unsigned long )i, 249 | ELF64_ProgramHeaderEntryGetTypeString( pHeader ), 250 | ( unsigned long )ELF64_ProgramHeaderEntryGetAttributes( pHeader ), 251 | ELF64_ProgramHeaderEntryGetAttributesString( pHeader ), 252 | ELF64_ProgramHeaderEntryGetFileOffset( pHeader ), 253 | ELF64_ProgramHeaderEntryGetMemoryVirtualAddress( pHeader ), 254 | ( unsigned long )ELF64_ProgramHeaderEntryGetFileSize( pHeader ), 255 | ( unsigned long )ELF64_ProgramHeaderEntryGetMemorySize( pHeader ), 256 | ( unsigned long )ELF64_ProgramHeaderEntryGetAlignment( pHeader ) 257 | ); 258 | } 259 | 260 | printf 261 | ( 262 | "Section header entries:\n" 263 | "-----------------------\n" 264 | "\n" 265 | ); 266 | 267 | for( i = 0; i < ELF64_HeaderGetSectionHeaderEntryCount( header ); i++ ) 268 | { 269 | sHeader = ELF64_FileGetSectionHeaderEntry( file, i ); 270 | 271 | printf 272 | ( 273 | " ### Section header entry (%lu):\n" 274 | " \n" 275 | " - Section name: %s\n" 276 | " - Section type: %s\n" 277 | " - Section attributes: %lu (%s)\n" 278 | " - Virtual address in memory: 0x%016llX\n" 279 | " - Offset in file: %lu\n" 280 | " - Size of section: %lu\n" 281 | " - Link to other section: %lu\n" 282 | " - Miscellaneous information: %lu\n" 283 | " - Address alignment boundary: %lu\n" 284 | " - Size of entries, if section has table: %lu\n" 285 | " \n", 286 | ( unsigned long )i, 287 | ELF64_FileGetNameOfSection( file, sHeader ), 288 | ELF64_SectionHeaderEntryGetTypeString( sHeader ), 289 | ( unsigned long )ELF64_SectionHeaderEntryGetAttributes( sHeader ), 290 | ELF64_SectionHeaderEntryGetAttributesString( sHeader ), 291 | ELF64_SectionHeaderEntryGetMemoryVirtualAddress( sHeader ), 292 | ( unsigned long )ELF64_SectionHeaderEntryGetFileOffset( sHeader ), 293 | ( unsigned long )ELF64_SectionHeaderEntryGetSectionSize( sHeader ), 294 | ( unsigned long )ELF64_SectionHeaderEntryGetLinkedSectionIndex( sHeader ), 295 | ( unsigned long )ELF64_SectionHeaderEntryGetMiscInfo( sHeader ), 296 | ( unsigned long )ELF64_SectionHeaderEntryGetAddressAlignmentBoundary( sHeader ), 297 | ( unsigned long )ELF64_SectionHeaderEntryGetEntrySize( sHeader ) 298 | ); 299 | } 300 | 301 | for( i = 0; i < ELF64_HeaderGetSectionHeaderEntryCount( header ) && showStrings == true; i++ ) 302 | { 303 | sHeader = ELF64_FileGetSectionHeaderEntry( file, i ); 304 | 305 | if( ELF64_SectionHeaderEntryGetType( sHeader ) != ELF64_SectionTypeStringTable ) 306 | { 307 | continue; 308 | } 309 | 310 | printf 311 | ( 312 | "String table:\n" 313 | "-------------\n" 314 | "\n" 315 | " - Section number: %lu\n" 316 | " - Section name: %s\n" 317 | "\n", 318 | ( unsigned long )i, 319 | ELF64_FileGetNameOfSection( file, sHeader ) 320 | ); 321 | 322 | { 323 | ELF64_XWord j; 324 | ELF64_XWord totalLength; 325 | ELF64_XWord stringLength; 326 | ELF64_XWord sectionSize; 327 | ELF64_UChar * sectionData; 328 | 329 | sectionSize = ELF64_SectionHeaderEntryGetSectionSize( sHeader ); 330 | sectionData = ELF64_FileGetDataForSection( file, sHeader ); 331 | totalLength = 0; 332 | j = 0; 333 | 334 | printf 335 | ( 336 | " ### Strings:\n" 337 | " \n" 338 | ); 339 | 340 | while( totalLength < sectionSize ) 341 | { 342 | stringLength = strlen( ( const char * )sectionData ); 343 | 344 | if( stringLength > 0 ) 345 | { 346 | printf 347 | ( 348 | " - %010lu (%010lu): %s\n", 349 | ( unsigned long )j, 350 | ( unsigned long )totalLength, 351 | sectionData 352 | ); 353 | } 354 | 355 | sectionData += stringLength + 1; 356 | totalLength += stringLength + 1; 357 | 358 | j++; 359 | } 360 | 361 | printf( "\n" ); 362 | } 363 | } 364 | 365 | for( i = 0; i < ELF64_HeaderGetSectionHeaderEntryCount( header ) && showSymbols == true; i++ ) 366 | { 367 | sHeader = ELF64_FileGetSectionHeaderEntry( file, i ); 368 | 369 | if( ELF64_SectionHeaderEntryGetType( sHeader ) != ELF64_SectionTypeLinkerSymbolTable ) 370 | { 371 | continue; 372 | } 373 | 374 | printf 375 | ( 376 | "Linker symbol table:\n" 377 | "--------------------\n" 378 | "\n" 379 | " - Section number: %lu\n" 380 | " - Section name: %s\n" 381 | "\n", 382 | ( unsigned long )i, 383 | ELF64_FileGetNameOfSection( file, sHeader ) 384 | ); 385 | 386 | { 387 | unsigned int symCount; 388 | unsigned int j; 389 | ELF64_SymbolTableEntryRef sym; 390 | 391 | symCount = ELF64_SectionHeaderEntryGetSymbolTableEntryCount( sHeader ); 392 | 393 | for( j = 0; j < symCount; j++ ) 394 | { 395 | sym = ELF64_FileGetSymbolTableEntryForSection( file, sHeader, j ); 396 | 397 | printf 398 | ( 399 | " ### Symbol (%lu):\n" 400 | " \n" 401 | " - Symbol name: %s\n" 402 | " - Symbol type: %s\n" 403 | " - Symbol bindings: %s\n" 404 | " - Section table index: %lu\n" 405 | " - Symbol value: 0x%016llX\n" 406 | " - Size of object: %lu\n" 407 | " \n", 408 | ( unsigned long )j, 409 | ELF64_FileGetSymbolTableEntryNameForSection( file, sym, sHeader ), 410 | ELF64_SymbolTableEntryGetTypeString( sym ), 411 | ELF64_SymbolTableEntryGetBindingString( sym ), 412 | ( unsigned long )ELF64_SymbolTableEntryGetSectionTableIndex( sym ), 413 | ELF64_SymbolTableEntryGetSymbolValue( sym ), 414 | ( unsigned long )ELF64_SymbolTableEntryGetObjectSize( sym ) 415 | ); 416 | } 417 | } 418 | } 419 | } 420 | 421 | goto end; 422 | 423 | error: 424 | 425 | printf( "Error reading ELF file: %s\n", argv[ argc - 1 ] ); 426 | 427 | end: 428 | 429 | free( data ); 430 | fclose( fh ); 431 | 432 | return EXIT_SUCCESS; 433 | } 434 | 435 | -------------------------------------------------------------------------------- /ELFDump/elf.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * XEOS - X86 Experimental Operating System 3 | * 4 | * Copyright (c) 2010-2013, Jean-David Gadina - www.xs-labs.com 5 | * All rights reserved. 6 | * 7 | * XEOS Software License - Version 1.0 - December 21, 2012 8 | * 9 | * Permission is hereby granted, free of charge, to any person or organisation 10 | * obtaining a copy of the software and accompanying documentation covered by 11 | * this license (the "Software") to deal in the Software, with or without 12 | * modification, without restriction, including without limitation the rights 13 | * to use, execute, display, copy, reproduce, transmit, publish, distribute, 14 | * modify, merge, prepare derivative works of the Software, and to permit 15 | * third-parties to whom the Software is furnished to do so, all subject to the 16 | * following conditions: 17 | * 18 | * 1. Redistributions of source code, in whole or in part, must retain the 19 | * above copyright notice and this entire statement, including the 20 | * above license grant, this restriction and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice and this entire statement, including the above license grant, 24 | * this restriction and the following disclaimer in the documentation 25 | * and/or other materials provided with the distribution, unless the 26 | * Software is distributed by the copyright owner as a library. 27 | * A "library" means a collection of software functions and/or data 28 | * prepared so as to be conveniently linked with application programs 29 | * (which use some of those functions and data) to form executables. 30 | * 31 | * 3. The Software, or any substancial portion of the Software shall not 32 | * be combined, included, derived, or linked (statically or 33 | * dynamically) with software or libraries licensed under the terms 34 | * of any GNU software license, including, but not limited to, the GNU 35 | * General Public License (GNU/GPL) or the GNU Lesser General Public 36 | * License (GNU/LGPL). 37 | * 38 | * 4. All advertising materials mentioning features or use of this 39 | * software must display an acknowledgement stating that the product 40 | * includes software developed by the copyright owner. 41 | * 42 | * 5. Neither the name of the copyright owner nor the names of its 43 | * contributors may be used to endorse or promote products derived from 44 | * this software without specific prior written permission. 45 | * 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS "AS IS" 47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 48 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 49 | * PURPOSE, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED. 50 | * 51 | * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR ANYONE DISTRIBUTING 52 | * THE SOFTWARE BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 53 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 54 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 55 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 56 | * WHETHER IN ACTION OF CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 57 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF OR IN CONNECTION WITH 58 | * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE, EVEN IF ADVISED 59 | * OF THE POSSIBILITY OF SUCH DAMAGE. 60 | ******************************************************************************/ 61 | 62 | /* $Id$ */ 63 | 64 | #include 65 | #include 66 | #include 67 | 68 | typedef struct __ELF64_File * ELF64_FileRef; 69 | typedef struct __ELF64_Header * ELF64_HeaderRef; 70 | typedef struct __ELF64_ProgramHeaderEntry * ELF64_ProgramHeaderEntryRef; 71 | typedef struct __ELF64_SectionHeaderEntry * ELF64_SectionHeaderEntryRef; 72 | typedef struct __ELF64_SymbolTableEntry * ELF64_SymbolTableEntryRef; 73 | 74 | typedef uint64_t ELF64_Addr; 75 | typedef uint64_t ELF64_Off; 76 | typedef uint16_t ELF64_Half; 77 | typedef uint32_t ELF64_Word; 78 | typedef int32_t ELF64_SWord; 79 | typedef uint64_t ELF64_XWord; 80 | typedef int64_t ELF64_SXWord; 81 | typedef uint8_t ELF64_UChar; 82 | 83 | typedef enum 84 | { 85 | ELF64_ObjectFileClassUnknown = 0, 86 | ELF64_ObjectFileClass32 = 1, 87 | ELF64_ObjectFileClass64 = 2 88 | } 89 | ELF64_ObjectFileClass; 90 | 91 | typedef enum 92 | { 93 | ELF64_DataEncodingUnknown = 0, 94 | ELF64_DataEncodingLSB = 1, 95 | ELF64_DataEncodingMSB = 2 96 | } 97 | ELF64_DataEncoding; 98 | 99 | typedef enum 100 | { 101 | ELF64_OSABIUnknown = 0, 102 | ELF64_OSABISysV = 1, 103 | ELF64_OSABIHPUX = 2, 104 | ELF64_OSABIStandalone = 255 105 | } 106 | ELF64_OSABI; 107 | 108 | typedef enum 109 | { 110 | ELF64_ObjectFileTypeNone = 0, 111 | ELF64_ObjectFileTypeRelocatableObjectFile = 1, 112 | ELF64_ObjectFileTypeExecutableFile = 2, 113 | ELF64_ObjectFileTypeSharedObjectFile = 3, 114 | ELF64_ObjectFileTypeCoreFile = 4 115 | } 116 | ELF64_ObjectFileType; 117 | 118 | typedef enum 119 | { 120 | ELF64_MachineTypeUnknown = 0, /* No machine */ 121 | ELF64_MachineTypeM32 = 1, /* AT&T WE 32100 */ 122 | ELF64_MachineTypeSPARC = 2, /* SPARC */ 123 | ELF64_MachineType386 = 3, /* Intel 80386 */ 124 | ELF64_MachineType68K = 4, /* Motorola 68000 */ 125 | ELF64_MachineType88K = 5, /* Motorola 88000 */ 126 | ELF64_MachineType860 = 7, /* Intel 80860 */ 127 | ELF64_MachineTypeMIPS = 8, /* MIPS I Architecture */ 128 | ELF64_MachineTypeS370 = 9, /* IBM System/370 Processor */ 129 | ELF64_MachineTypeMIPSRS3LE = 10, /* MIPS RS3000 Little-endian */ 130 | ELF64_MachineTypePARISC = 15, /* Hewlett-Packard PA-RISC */ 131 | ELF64_MachineTypeVPP500 = 17, /* Fujitsu VPP500 */ 132 | ELF64_MachineTypeSPARC32Plus = 18, /* Enhanced instruction set SPARC */ 133 | ELF64_MachineType960 = 19, /* Intel 80960 */ 134 | ELF64_MachineTypePPC = 20, /* PowerPC */ 135 | ELF64_MachineTypePPC64 = 21, /* 64-bit PowerPC */ 136 | ELF64_MachineTypeV800 = 36, /* NEC V800 */ 137 | ELF64_MachineTypeFR20 = 37, /* Fujitsu FR20 */ 138 | ELF64_MachineTypeRH32 = 38, /* TRW RH-32 */ 139 | ELF64_MachineTypeRCE = 39, /* Motorola RCE */ 140 | ELF64_MachineTypeARM = 40, /* Advanced RISC Machines ARM */ 141 | ELF64_MachineTypeAlpha = 41, /* Digital Alpha */ 142 | ELF64_MachineTypeSH = 42, /* Hitachi SH */ 143 | ELF64_MachineTypeSPARCV9 = 43, /* SPARC Version 9 */ 144 | ELF64_MachineTypeTricore = 44, /* Siemens Tricore embedded processor */ 145 | ELF64_MachineTypeARC = 45, /* Argonaut RISC Core, Argonaut Technologies Inc. */ 146 | ELF64_MachineTypeH8300 = 46, /* Hitachi H8/300 */ 147 | ELF64_MachineTypeH8300H = 47, /* Hitachi H8/300H */ 148 | ELF64_MachineTypeH8S = 48, /* Hitachi H8S */ 149 | ELF64_MachineTypeH8500 = 49, /* Hitachi H8/500 */ 150 | ELF64_MachineTypeIA64 = 50, /* Intel IA-64 processor architecture */ 151 | ELF64_MachineTypeMIPSX = 51, /* Stanford MIPS-X */ 152 | ELF64_MachineTypeColdFire = 52, /* Motorola ColdFire */ 153 | ELF64_MachineType68HC12 = 53, /* Motorola M68HC12 */ 154 | ELF64_MachineTypeMMA = 54, /* Fujitsu MMA Multimedia Accelerator */ 155 | ELF64_MachineTypePCP = 55, /* Siemens PCP */ 156 | ELF64_MachineTypeNCPU = 56, /* Sony nCPU embedded RISC processor */ 157 | ELF64_MachineTypeNDR1 = 57, /* Denso NDR1 microprocessor */ 158 | ELF64_MachineTypeStarCore = 58, /* Motorola Star*Core processor */ 159 | ELF64_MachineTypeME16 = 59, /* Toyota ME16 processor */ 160 | ELF64_MachineTypeST100 = 60, /* STMicroelectronics ST100 processor */ 161 | ELF64_MachineTypeTinyJ = 61, /* Advanced Logic Corp. TinyJ embedded processor family */ 162 | ELF64_MachineTypeFX66 = 66, /* Siemens FX66 microcontroller */ 163 | ELF64_MachineTypeST9Plus = 67, /* STMicroelectronics ST9+ 8/16 bit microcontroller */ 164 | ELF64_MachineTypeST7 = 68, /* STMicroelectronics ST7 8-bit microcontroller */ 165 | ELF64_MachineType68HC16 = 69, /* Motorola MC68HC16 Microcontroller */ 166 | ELF64_MachineType68HC11 = 70, /* Motorola MC68HC11 Microcontroller */ 167 | ELF64_MachineType68HC08 = 71, /* Motorola MC68HC08 Microcontroller */ 168 | ELF64_MachineType68HC05 = 72, /* Motorola MC68HC05 Microcontroller */ 169 | ELF64_MachineTypeSVX = 73, /* Silicon Graphics SVx */ 170 | ELF64_MachineTypeST19 = 74, /* STMicroelectronics ST19 8-bit microcontroller */ 171 | ELF64_MachineTypeVAX = 75, /* Digital VAX */ 172 | ELF64_MachineTypeCRIS = 76, /* Axis Communications 32-bit embedded processor */ 173 | ELF64_MachineTypeJavelin = 77, /* Infineon Technologies 32-bit embedded processor */ 174 | ELF64_MachineTypeFirePath = 78, /* Element 14 64-bit DSP Processor */ 175 | ELF64_MachineTypeZSP = 79, /* LSI Logic 16-bit DSP Processor */ 176 | ELF64_MachineTypeMMIX = 80, /* Donald Knuth's educational 64-bit processor */ 177 | ELF64_MachineTypeHUANY = 81, /* Harvard University machine-independent object files */ 178 | ELF64_MachineTypePrism = 82 /* SiTera Prism */ 179 | } 180 | ELF64_MachineType; 181 | 182 | typedef enum 183 | { 184 | ELF64_SegmentTypeUnused = 0, 185 | ELF64_SegmentTypeLoadable = 1, 186 | ELF64_SegmentTypeDynamicLinkingTables = 2, 187 | ELF64_SegmentTypeProgramInterpreterPathName = 3, 188 | ELF64_SegmentTypeNoteSections = 4, 189 | ELF64_SegmentTypeProgramHeaderTable = 6 190 | } 191 | ELF64_SegmentType; 192 | 193 | typedef enum 194 | { 195 | ELF64_SegmentAttributeExecute = 1, 196 | ELF64_SegmentAttributeWrite = 2, 197 | ELF64_SegmentAttributeRead = 4 198 | } 199 | ELF64_SegmentAttribute; 200 | 201 | typedef enum 202 | { 203 | ELF64_SectionTypeUnused = 0, 204 | ELF64_SectionTypeProgBits = 1, 205 | ELF64_SectionTypeLinkerSymbolTable = 2, 206 | ELF64_SectionTypeStringTable = 3, 207 | ELF64_SectionTypeRelaRelocationEntries = 4, 208 | ELF64_SectionTypeSymbolHashTable = 5, 209 | ELF64_SectionTypeDynamicLinkingTables = 6, 210 | ELF64_SectionTypeNoteInformation = 7, 211 | ELF64_SectionTypeUninitializedSpace = 8, 212 | ELF64_SectionTypeRelRelocationEntries = 9, 213 | ELF64_SectionTypeDynamicLoaderSymbolTable = 11 214 | } 215 | ELF64_SectionType; 216 | 217 | typedef enum 218 | { 219 | ELF64_SectionAttributeWrite = 1, 220 | ELF64_SectionAttributeAlloc = 2, 221 | ELF64_SectionAttributeExecute = 4 222 | } 223 | ELF64_SectionAttribute; 224 | 225 | typedef enum 226 | { 227 | ELF64_SymbolTypeNone = 0, 228 | ELF64_SymbolTypeDataObject = 1, 229 | ELF64_SymbolTypeFunctionEntryPoint = 2, 230 | ELF64_SymbolTypeSection = 3, 231 | ELF64_SymbolTypeFile = 4 232 | } 233 | ELF64_SymbolType; 234 | 235 | typedef enum 236 | { 237 | ELF64_SymbolBindingLocal = 0, 238 | ELF64_SymbolBindingGlobal = 1, 239 | ELF64_SymbolBindingWeak = 2 240 | } 241 | ELF64_SymbolBinding; 242 | 243 | ELF64_FileRef ELF64_ReadFromData( char * data ); 244 | bool ELF64_FileIsValid( ELF64_FileRef file ); 245 | ELF64_HeaderRef ELF64_FileGetHeader( ELF64_FileRef file ); 246 | ELF64_ProgramHeaderEntryRef ELF64_FileGetProgramHeaderEntry( ELF64_FileRef file, unsigned int index ); 247 | ELF64_SectionHeaderEntryRef ELF64_FileGetSectionHeaderEntry( ELF64_FileRef file, unsigned int index ); 248 | const char * ELF64_FileGetNameOfSection( ELF64_FileRef file, ELF64_SectionHeaderEntryRef section ); 249 | const char * ELF64_FileGetNameOfSectionAtIndex( ELF64_FileRef file, unsigned int index ); 250 | ELF64_UChar * ELF64_FileGetDataForSection( ELF64_FileRef file, ELF64_SectionHeaderEntryRef section ); 251 | ELF64_UChar * ELF64_FileGetDataForSectionAtIndex( ELF64_FileRef file, unsigned int index ); 252 | ELF64_SymbolTableEntryRef ELF64_FileGetSymbolTableEntryForSection( ELF64_FileRef file, ELF64_SectionHeaderEntryRef section, unsigned int index ); 253 | const char * ELF64_FileGetSymbolTableEntryNameForSection( ELF64_FileRef file, ELF64_SymbolTableEntryRef sym, ELF64_SectionHeaderEntryRef section ); 254 | ELF64_SectionHeaderEntryRef ELF64_FileGetStringTableHeaderEntry( ELF64_FileRef file ); 255 | ELF64_SectionHeaderEntryRef ELF64_FileGetSectionHeaderEntryWithName( ELF64_FileRef file, const char * name ); 256 | ELF64_SymbolTableEntryRef ELF64_FileGetSymbolTableEntryWithName( ELF64_FileRef file, const char * name ); 257 | ELF64_SymbolTableEntryRef ELF64_FileGetSymbolTableEntryWithAddress( ELF64_FileRef file, ELF64_Addr address ); 258 | 259 | ELF64_ObjectFileClass ELF64_HeaderGetObjectFileClass( ELF64_HeaderRef header ); 260 | const char * ELF64_HeaderGetObjectFileClassString( ELF64_HeaderRef header ); 261 | ELF64_DataEncoding ELF64_HeaderGetDataEncoding( ELF64_HeaderRef header ); 262 | const char * ELF64_HeaderGetDataEncodingString( ELF64_HeaderRef header ); 263 | ELF64_UChar ELF64_HeaderGetFileVersion( ELF64_HeaderRef header ); 264 | ELF64_OSABI ELF64_HeaderGetOSABI( ELF64_HeaderRef header ); 265 | const char * ELF64_HeaderGetOSABIString( ELF64_HeaderRef header ); 266 | ELF64_ObjectFileType ELF64_HeaderGetObjectFileType( ELF64_HeaderRef header ); 267 | const char * ELF64_HeaderGetObjectFileTypeString( ELF64_HeaderRef header ); 268 | ELF64_Half ELF64_HeaderGetMachine( ELF64_HeaderRef header ); 269 | ELF64_MachineType ELF64_HeaderGetMachineType( ELF64_HeaderRef header ); 270 | const char * ELF64_HeaderGetMachineTypeString( ELF64_HeaderRef header ); 271 | ELF64_Word ELF64_HeaderGetVersion( ELF64_HeaderRef header ); 272 | ELF64_Addr ELF64_HeaderGetEntryPointAddress( ELF64_HeaderRef header ); 273 | ELF64_Off ELF64_HeaderGetProgramHeaderOffset( ELF64_HeaderRef header ); 274 | ELF64_Off ELF64_HeaderGetSectionHeaderOffset( ELF64_HeaderRef header ); 275 | ELF64_Word ELF64_HeaderGetProcessorSpecificFlags( ELF64_HeaderRef header ); 276 | ELF64_Half ELF64_HeaderGetHeaderSize( ELF64_HeaderRef header ); 277 | ELF64_Half ELF64_HeaderGetProgramHeaderEntrySize( ELF64_HeaderRef header ); 278 | ELF64_Half ELF64_HeaderGetProgramHeaderEntryCount( ELF64_HeaderRef header ); 279 | ELF64_Half ELF64_HeaderGetSectionHeaderEntrySize( ELF64_HeaderRef header ); 280 | ELF64_Half ELF64_HeaderGetSectionHeaderEntryCount( ELF64_HeaderRef header ); 281 | ELF64_Half ELF64_HeaderGetSectionNameStringTableIndex( ELF64_HeaderRef header ); 282 | 283 | ELF64_SegmentType ELF64_ProgramHeaderEntryGetType( ELF64_ProgramHeaderEntryRef entry ); 284 | const char * ELF64_ProgramHeaderEntryGetTypeString( ELF64_ProgramHeaderEntryRef entry ); 285 | ELF64_Word ELF64_ProgramHeaderEntryGetAttributes( ELF64_ProgramHeaderEntryRef entry ); 286 | const char * ELF64_ProgramHeaderEntryGetAttributesString( ELF64_ProgramHeaderEntryRef entry ); 287 | ELF64_Off ELF64_ProgramHeaderEntryGetFileOffset( ELF64_ProgramHeaderEntryRef entry ); 288 | ELF64_Addr ELF64_ProgramHeaderEntryGetMemoryVirtualAddress( ELF64_ProgramHeaderEntryRef entry ); 289 | ELF64_XWord ELF64_ProgramHeaderEntryGetFileSize( ELF64_ProgramHeaderEntryRef entry ); 290 | ELF64_XWord ELF64_ProgramHeaderEntryGetMemorySize( ELF64_ProgramHeaderEntryRef entry ); 291 | ELF64_XWord ELF64_ProgramHeaderEntryGetAlignment( ELF64_ProgramHeaderEntryRef entry ); 292 | 293 | ELF64_Word ELF64_SectionHeaderEntryGetNameOffset( ELF64_SectionHeaderEntryRef entry ); 294 | ELF64_SectionType ELF64_SectionHeaderEntryGetType( ELF64_SectionHeaderEntryRef entry ); 295 | const char * ELF64_SectionHeaderEntryGetTypeString( ELF64_SectionHeaderEntryRef entry ); 296 | ELF64_XWord ELF64_SectionHeaderEntryGetAttributes( ELF64_SectionHeaderEntryRef entry ); 297 | const char * ELF64_SectionHeaderEntryGetAttributesString( ELF64_SectionHeaderEntryRef entry ); 298 | ELF64_Addr ELF64_SectionHeaderEntryGetMemoryVirtualAddress( ELF64_SectionHeaderEntryRef entry ); 299 | ELF64_Off ELF64_SectionHeaderEntryGetFileOffset( ELF64_SectionHeaderEntryRef entry ); 300 | ELF64_XWord ELF64_SectionHeaderEntryGetSectionSize( ELF64_SectionHeaderEntryRef entry ); 301 | ELF64_Word ELF64_SectionHeaderEntryGetLinkedSectionIndex( ELF64_SectionHeaderEntryRef entry ); 302 | ELF64_Word ELF64_SectionHeaderEntryGetMiscInfo( ELF64_SectionHeaderEntryRef entry ); 303 | ELF64_XWord ELF64_SectionHeaderEntryGetAddressAlignmentBoundary( ELF64_SectionHeaderEntryRef entry ); 304 | ELF64_XWord ELF64_SectionHeaderEntryGetEntrySize( ELF64_SectionHeaderEntryRef entry ); 305 | unsigned int ELF64_SectionHeaderEntryGetSymbolTableEntryCount( ELF64_SectionHeaderEntryRef section ); 306 | 307 | ELF64_Word ELF64_SymbolTableEntryGetNameOffset( ELF64_SymbolTableEntryRef sym ); 308 | ELF64_UChar ELF64_SymbolTableEntryGetInfo( ELF64_SymbolTableEntryRef sym ); 309 | ELF64_SymbolType ELF64_SymbolTableEntryGetType( ELF64_SymbolTableEntryRef sym ); 310 | const char * ELF64_SymbolTableEntryGetTypeString( ELF64_SymbolTableEntryRef sym ); 311 | ELF64_SymbolBinding ELF64_SymbolTableEntryGetBinding( ELF64_SymbolTableEntryRef sym ); 312 | const char * ELF64_SymbolTableEntryGetBindingString( ELF64_SymbolTableEntryRef sym ); 313 | ELF64_Half ELF64_SymbolTableEntryGetSectionTableIndex( ELF64_SymbolTableEntryRef sym ); 314 | ELF64_Addr ELF64_SymbolTableEntryGetSymbolValue( ELF64_SymbolTableEntryRef sym ); 315 | ELF64_XWord ELF64_SymbolTableEntryGetObjectSize( ELF64_SymbolTableEntryRef sym ); 316 | 317 | unsigned long ELF64_Hash( const char * name ); 318 | -------------------------------------------------------------------------------- /ELFDump/elf.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * XEOS - X86 Experimental Operating System 3 | * 4 | * Copyright (c) 2010-2013, Jean-David Gadina - www.xs-labs.com 5 | * All rights reserved. 6 | * 7 | * XEOS Software License - Version 1.0 - December 21, 2012 8 | * 9 | * Permission is hereby granted, free of charge, to any person or organisation 10 | * obtaining a copy of the software and accompanying documentation covered by 11 | * this license (the "Software") to deal in the Software, with or without 12 | * modification, without restriction, including without limitation the rights 13 | * to use, execute, display, copy, reproduce, transmit, publish, distribute, 14 | * modify, merge, prepare derivative works of the Software, and to permit 15 | * third-parties to whom the Software is furnished to do so, all subject to the 16 | * following conditions: 17 | * 18 | * 1. Redistributions of source code, in whole or in part, must retain the 19 | * above copyright notice and this entire statement, including the 20 | * above license grant, this restriction and the following disclaimer. 21 | * 22 | * 2. Redistributions in binary form must reproduce the above copyright 23 | * notice and this entire statement, including the above license grant, 24 | * this restriction and the following disclaimer in the documentation 25 | * and/or other materials provided with the distribution, unless the 26 | * Software is distributed by the copyright owner as a library. 27 | * A "library" means a collection of software functions and/or data 28 | * prepared so as to be conveniently linked with application programs 29 | * (which use some of those functions and data) to form executables. 30 | * 31 | * 3. The Software, or any substancial portion of the Software shall not 32 | * be combined, included, derived, or linked (statically or 33 | * dynamically) with software or libraries licensed under the terms 34 | * of any GNU software license, including, but not limited to, the GNU 35 | * General Public License (GNU/GPL) or the GNU Lesser General Public 36 | * License (GNU/LGPL). 37 | * 38 | * 4. All advertising materials mentioning features or use of this 39 | * software must display an acknowledgement stating that the product 40 | * includes software developed by the copyright owner. 41 | * 42 | * 5. Neither the name of the copyright owner nor the names of its 43 | * contributors may be used to endorse or promote products derived from 44 | * this software without specific prior written permission. 45 | * 46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNER AND CONTRIBUTORS "AS IS" 47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 48 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 49 | * PURPOSE, TITLE AND NON-INFRINGEMENT ARE DISCLAIMED. 50 | * 51 | * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR ANYONE DISTRIBUTING 52 | * THE SOFTWARE BE LIABLE FOR ANY CLAIM, DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 53 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 54 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 55 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 56 | * WHETHER IN ACTION OF CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 57 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF OR IN CONNECTION WITH 58 | * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE, EVEN IF ADVISED 59 | * OF THE POSSIBILITY OF SUCH DAMAGE. 60 | ******************************************************************************/ 61 | 62 | /* $Id$ */ 63 | 64 | #include "elf.h" 65 | #include 66 | 67 | struct __ELF64_SymbolTableEntry 68 | { 69 | ELF64_Word st_name; /* Symbol name */ 70 | ELF64_UChar st_info; /* Type and binding attributes */ 71 | ELF64_UChar st_other; /* Reserved */ 72 | ELF64_Half st_shndx; /* Section table index */ 73 | ELF64_Addr st_value; /* Symbol value */ 74 | ELF64_XWord st_size; /* Size of object */ 75 | }; 76 | 77 | struct __ELF64_ProgramHeaderEntry 78 | { 79 | ELF64_Word p_type; /* Type of segment */ 80 | ELF64_Word p_flags; /* Segment attributes */ 81 | ELF64_Off p_offset; /* Offset in file */ 82 | ELF64_Addr p_vaddr; /* Virtual address in memory */ 83 | ELF64_Addr p_paddr; /* Reserved */ 84 | ELF64_XWord p_filesz; /* Size of segment in file */ 85 | ELF64_XWord p_memsz; /* Size of segment in memory */ 86 | ELF64_XWord p_align; /* Alignment of segment */ 87 | }; 88 | 89 | struct __ELF64_SectionHeaderEntry 90 | { 91 | ELF64_Word sh_name; /* Section name */ 92 | ELF64_Word sh_type; /* Section type */ 93 | ELF64_XWord sh_flags; /* Section attributes */ 94 | ELF64_Addr sh_addr; /* Virtual address in memory */ 95 | ELF64_Off sh_offset; /* Offset in file */ 96 | ELF64_XWord sh_size; /* Size of section */ 97 | ELF64_Word sh_link; /* Link to other section */ 98 | ELF64_Word sh_info; /* Miscellaneous information */ 99 | ELF64_XWord sh_addralign; /* Address alignment boundary */ 100 | ELF64_XWord sh_entsize; /* Size of entries, if section has table */ 101 | }; 102 | 103 | struct __ELF64_Header 104 | { 105 | ELF64_UChar e_ident[ 16 ]; /* ELF identification */ 106 | ELF64_Half e_type; /* Object file type */ 107 | ELF64_Half e_machine; /* Machine type */ 108 | ELF64_Word e_version; /* Object file version */ 109 | ELF64_Addr e_entry; /* Entry point address */ 110 | ELF64_Off e_phoff; /* Program header offset */ 111 | ELF64_Off e_shoff; /* Section header offset */ 112 | ELF64_Word e_flags; /* Processor-specific flags */ 113 | ELF64_Half e_ehsize; /* ELF header size */ 114 | ELF64_Half e_phentsize; /* Size of program header entry */ 115 | ELF64_Half e_phnum; /* Number of program header entries */ 116 | ELF64_Half e_shentsize; /* Size of section header entry */ 117 | ELF64_Half e_shnum; /* Number of section header entries */ 118 | ELF64_Half e_shstrndx; /* Section name string table index */ 119 | }; 120 | 121 | struct __ELF64_File 122 | { 123 | struct __ELF64_Header header; 124 | }; 125 | 126 | ELF64_FileRef ELF64_ReadFromData( char * data ) 127 | { 128 | return ( ELF64_FileRef )( ( void * )data ); 129 | } 130 | 131 | bool ELF64_FileIsValid( ELF64_FileRef file ) 132 | { 133 | if( file == NULL ) 134 | { 135 | return false; 136 | } 137 | 138 | if 139 | ( 140 | file->header.e_ident[ 0 ] == 0x7F 141 | && file->header.e_ident[ 1 ] == 0x45 /* E */ 142 | && file->header.e_ident[ 2 ] == 0x4C /* L */ 143 | && file->header.e_ident[ 3 ] == 0x46 /* F */ 144 | ) 145 | { 146 | return true; 147 | } 148 | 149 | return false; 150 | } 151 | 152 | ELF64_HeaderRef ELF64_FileGetHeader( ELF64_FileRef file ) 153 | { 154 | if( file == NULL ) 155 | { 156 | return NULL; 157 | } 158 | 159 | return &( file->header ); 160 | } 161 | 162 | ELF64_ProgramHeaderEntryRef ELF64_FileGetProgramHeaderEntry( ELF64_FileRef file, unsigned int index ) 163 | { 164 | ELF64_HeaderRef header; 165 | ELF64_Off offset; 166 | ELF64_Half entrySize; 167 | 168 | if( file == NULL ) 169 | { 170 | return NULL; 171 | } 172 | 173 | header = ELF64_FileGetHeader( file ); 174 | 175 | if( header == NULL || index >= ELF64_HeaderGetProgramHeaderEntryCount( header ) ) 176 | { 177 | return NULL; 178 | } 179 | 180 | offset = ELF64_HeaderGetProgramHeaderOffset( header ); 181 | entrySize = ELF64_HeaderGetProgramHeaderEntrySize( header ); 182 | 183 | return ( ELF64_ProgramHeaderEntryRef )( ( void * )( ( char * )file + offset + ( entrySize * index ) ) ); 184 | } 185 | 186 | ELF64_SectionHeaderEntryRef ELF64_FileGetSectionHeaderEntry( ELF64_FileRef file, unsigned int index ) 187 | { 188 | ELF64_HeaderRef header; 189 | ELF64_Off offset; 190 | ELF64_Half entrySize; 191 | 192 | if( file == NULL ) 193 | { 194 | return NULL; 195 | } 196 | 197 | header = ELF64_FileGetHeader( file ); 198 | 199 | if( header == NULL || index >= ELF64_HeaderGetSectionHeaderEntryCount( header ) ) 200 | { 201 | return NULL; 202 | } 203 | 204 | offset = ELF64_HeaderGetSectionHeaderOffset( header ); 205 | entrySize = ELF64_HeaderGetSectionHeaderEntrySize( header ); 206 | 207 | return ( ELF64_SectionHeaderEntryRef )( ( void * )( ( char * )file + offset + ( entrySize * index ) ) ); 208 | } 209 | 210 | const char * ELF64_FileGetNameOfSection( ELF64_FileRef file, ELF64_SectionHeaderEntryRef section ) 211 | { 212 | ELF64_HeaderRef header; 213 | ELF64_SectionHeaderEntryRef stringTable; 214 | ELF64_Word nameOffset; 215 | 216 | if( file == NULL || section == NULL ) 217 | { 218 | return NULL; 219 | } 220 | 221 | header = ELF64_FileGetHeader( file ); 222 | 223 | if( header == NULL ) 224 | { 225 | return NULL; 226 | } 227 | 228 | stringTable = ELF64_FileGetStringTableHeaderEntry( file ); 229 | nameOffset = ELF64_SectionHeaderEntryGetNameOffset( section ); 230 | 231 | return ( const char * )( ELF64_FileGetDataForSection( file, stringTable ) + nameOffset ); 232 | } 233 | 234 | const char * ELF64_FileGetNameOfSectionAtIndex( ELF64_FileRef file, unsigned int index ) 235 | { 236 | return ELF64_FileGetNameOfSection( file, ELF64_FileGetSectionHeaderEntry( file, index ) ); 237 | } 238 | 239 | ELF64_UChar * ELF64_FileGetDataForSection( ELF64_FileRef file, ELF64_SectionHeaderEntryRef section ) 240 | { 241 | ELF64_Off fileOffset; 242 | 243 | if( section == NULL ) 244 | { 245 | return NULL; 246 | } 247 | 248 | fileOffset = ELF64_SectionHeaderEntryGetFileOffset( section ); 249 | 250 | return ( ELF64_UChar * )file + fileOffset; 251 | } 252 | 253 | ELF64_UChar * ELF64_FileGetDataForSectionAtIndex( ELF64_FileRef file, unsigned int index ) 254 | { 255 | return ELF64_FileGetDataForSection( file, ELF64_FileGetSectionHeaderEntry( file, index ) ); 256 | } 257 | 258 | ELF64_SymbolTableEntryRef ELF64_FileGetSymbolTableEntryForSection( ELF64_FileRef file, ELF64_SectionHeaderEntryRef section, unsigned int index ) 259 | { 260 | ELF64_XWord entrySize; 261 | 262 | if( ELF64_SectionHeaderEntryGetType( section ) != ELF64_SectionTypeLinkerSymbolTable ) 263 | { 264 | return NULL; 265 | } 266 | 267 | if( index >= ELF64_SectionHeaderEntryGetSymbolTableEntryCount( section ) ) 268 | { 269 | return NULL; 270 | } 271 | 272 | entrySize = ELF64_SectionHeaderEntryGetEntrySize( section ); 273 | 274 | return ( ELF64_SymbolTableEntryRef )( ( void * )( ELF64_FileGetDataForSection( file, section ) + ( index * entrySize ) ) ); 275 | } 276 | 277 | const char * ELF64_FileGetSymbolTableEntryNameForSection( ELF64_FileRef file, ELF64_SymbolTableEntryRef sym, ELF64_SectionHeaderEntryRef section ) 278 | { 279 | ELF64_Word stringTableIndex; 280 | ELF64_SectionHeaderEntryRef stringTable; 281 | ELF64_Word nameOffset; 282 | const char * name; 283 | 284 | if( file == NULL || sym == NULL || section == NULL ) 285 | { 286 | return NULL; 287 | } 288 | 289 | stringTableIndex = ELF64_SectionHeaderEntryGetLinkedSectionIndex( section ); 290 | stringTable = ELF64_FileGetSectionHeaderEntry( file, stringTableIndex ); 291 | 292 | if( stringTable == NULL ) 293 | { 294 | return NULL; 295 | } 296 | 297 | nameOffset = ELF64_SymbolTableEntryGetNameOffset( sym ); 298 | name = ( const char * )( ELF64_FileGetDataForSection( file, stringTable ) + nameOffset ); 299 | 300 | if( strlen( name ) == 0 ) 301 | { 302 | return ""; 303 | } 304 | 305 | return name; 306 | } 307 | 308 | ELF64_SectionHeaderEntryRef ELF64_FileGetStringTableHeaderEntry( ELF64_FileRef file ) 309 | { 310 | ELF64_HeaderRef header; 311 | ELF64_Half stringTableIndex; 312 | 313 | if( file == NULL ) 314 | { 315 | return NULL; 316 | } 317 | 318 | header = ELF64_FileGetHeader( file ); 319 | 320 | if( header == NULL ) 321 | { 322 | return NULL; 323 | } 324 | 325 | stringTableIndex = ELF64_HeaderGetSectionNameStringTableIndex( header ); 326 | 327 | return ELF64_FileGetSectionHeaderEntry( file, stringTableIndex ); 328 | } 329 | 330 | ELF64_SectionHeaderEntryRef ELF64_FileGetSectionHeaderEntryWithName( ELF64_FileRef file, const char * name ) 331 | { 332 | ELF64_Half i; 333 | ELF64_HeaderRef header; 334 | ELF64_SectionHeaderEntryRef section; 335 | const char * sName; 336 | 337 | if( file == NULL ) 338 | { 339 | return NULL; 340 | } 341 | 342 | header = ELF64_FileGetHeader( file ); 343 | 344 | if( header == NULL ) 345 | { 346 | return NULL; 347 | } 348 | 349 | for( i = 0; i < ELF64_HeaderGetSectionHeaderEntryCount( header ); i++ ) 350 | { 351 | section = ELF64_FileGetSectionHeaderEntry( file, i ); 352 | sName = ELF64_FileGetNameOfSection( file, section ); 353 | 354 | if( strcmp( name, sName ) == 0 ) 355 | { 356 | return section; 357 | } 358 | } 359 | 360 | return NULL; 361 | } 362 | 363 | ELF64_SymbolTableEntryRef ELF64_FileGetSymbolTableEntryWithName( ELF64_FileRef file, const char * name ) 364 | { 365 | ELF64_HeaderRef header; 366 | ELF64_SectionHeaderEntryRef sHeader; 367 | ELF64_Half i; 368 | unsigned int symCount; 369 | unsigned int j; 370 | ELF64_SymbolTableEntryRef sym; 371 | const char * symName; 372 | 373 | if( file == NULL ) 374 | { 375 | return NULL; 376 | } 377 | 378 | header = ELF64_FileGetHeader( file ); 379 | 380 | if( header == NULL ) 381 | { 382 | return NULL; 383 | } 384 | 385 | for( i = 0; i < ELF64_HeaderGetSectionHeaderEntryCount( header ); i++ ) 386 | { 387 | sHeader = ELF64_FileGetSectionHeaderEntry( file, i ); 388 | 389 | if( ELF64_SectionHeaderEntryGetType( sHeader ) != ELF64_SectionTypeLinkerSymbolTable ) 390 | { 391 | continue; 392 | } 393 | 394 | symCount = ELF64_SectionHeaderEntryGetSymbolTableEntryCount( sHeader ); 395 | 396 | for( j = 0; j < symCount; j++ ) 397 | { 398 | sym = ELF64_FileGetSymbolTableEntryForSection( file, sHeader, j ); 399 | symName = ELF64_FileGetSymbolTableEntryNameForSection( file, sym, sHeader ); 400 | 401 | if( strcmp( name, symName ) == 0 ) 402 | { 403 | return sym; 404 | } 405 | } 406 | } 407 | 408 | return NULL; 409 | } 410 | 411 | ELF64_SymbolTableEntryRef ELF64_FileGetSymbolTableEntryWithAddress( ELF64_FileRef file, ELF64_Addr address ) 412 | { 413 | ELF64_HeaderRef header; 414 | ELF64_SectionHeaderEntryRef sHeader; 415 | ELF64_Half i; 416 | unsigned int symCount; 417 | unsigned int j; 418 | ELF64_SymbolTableEntryRef sym; 419 | ELF64_Addr symAddress; 420 | 421 | if( file == NULL ) 422 | { 423 | return NULL; 424 | } 425 | 426 | header = ELF64_FileGetHeader( file ); 427 | 428 | if( header == NULL ) 429 | { 430 | return NULL; 431 | } 432 | 433 | for( i = 0; i < ELF64_HeaderGetSectionHeaderEntryCount( header ); i++ ) 434 | { 435 | sHeader = ELF64_FileGetSectionHeaderEntry( file, i ); 436 | 437 | if( ELF64_SectionHeaderEntryGetType( sHeader ) != ELF64_SectionTypeLinkerSymbolTable ) 438 | { 439 | continue; 440 | } 441 | 442 | symCount = ELF64_SectionHeaderEntryGetSymbolTableEntryCount( sHeader ); 443 | 444 | for( j = 0; j < symCount; j++ ) 445 | { 446 | sym = ELF64_FileGetSymbolTableEntryForSection( file, sHeader, j ); 447 | symAddress = ELF64_SymbolTableEntryGetSymbolValue( sym ); 448 | 449 | if( address == symAddress ) 450 | { 451 | return sym; 452 | } 453 | } 454 | } 455 | 456 | return NULL; 457 | } 458 | 459 | ELF64_ObjectFileClass ELF64_HeaderGetObjectFileClass( ELF64_HeaderRef header ) 460 | { 461 | if( header == NULL ) 462 | { 463 | return ELF64_ObjectFileClassUnknown; 464 | } 465 | 466 | switch( header->e_ident[ 4 ] ) 467 | { 468 | case 1: return ELF64_ObjectFileClass32; 469 | case 2: return ELF64_ObjectFileClass64; 470 | default: break; 471 | } 472 | 473 | return ELF64_ObjectFileClassUnknown; 474 | } 475 | 476 | const char * ELF64_HeaderGetObjectFileClassString( ELF64_HeaderRef header ) 477 | { 478 | switch( ELF64_HeaderGetObjectFileClass( header ) ) 479 | { 480 | case ELF64_ObjectFileClassUnknown: return "Unknown"; 481 | case ELF64_ObjectFileClass32: return "32 bits"; 482 | case ELF64_ObjectFileClass64: return "64 bits"; 483 | } 484 | } 485 | 486 | ELF64_DataEncoding ELF64_HeaderGetDataEncoding( ELF64_HeaderRef header ) 487 | { 488 | if( header == NULL ) 489 | { 490 | return ELF64_DataEncodingUnknown; 491 | } 492 | 493 | switch( header->e_ident[ 5 ] ) 494 | { 495 | case 1: return ELF64_DataEncodingLSB; 496 | case 2: return ELF64_DataEncodingMSB; 497 | default: break; 498 | } 499 | 500 | return ELF64_DataEncodingUnknown; 501 | } 502 | 503 | const char * ELF64_HeaderGetDataEncodingString( ELF64_HeaderRef header ) 504 | { 505 | switch( ELF64_HeaderGetDataEncoding( header ) ) 506 | { 507 | case ELF64_DataEncodingUnknown: return "LSB"; 508 | case ELF64_DataEncodingLSB: return "LSB"; 509 | case ELF64_DataEncodingMSB: return "MSB"; 510 | } 511 | } 512 | 513 | ELF64_UChar ELF64_HeaderGetFileVersion( ELF64_HeaderRef header ) 514 | { 515 | if( header == NULL ) 516 | { 517 | return 0; 518 | } 519 | 520 | return header->e_ident[ 6 ]; 521 | } 522 | 523 | ELF64_OSABI ELF64_HeaderGetOSABI( ELF64_HeaderRef header ) 524 | { 525 | if( header == NULL ) 526 | { 527 | return ELF64_OSABIUnknown; 528 | } 529 | 530 | switch( header->e_ident[ 8 ] ) 531 | { 532 | case 0: return ELF64_OSABISysV; 533 | case 1: return ELF64_OSABIHPUX; 534 | case 255: return ELF64_OSABIStandalone; 535 | default: break; 536 | } 537 | 538 | return ELF64_OSABIUnknown; 539 | } 540 | 541 | const char * ELF64_HeaderGetOSABIString( ELF64_HeaderRef header ) 542 | { 543 | switch( ELF64_HeaderGetOSABI( header ) ) 544 | { 545 | case ELF64_OSABIUnknown: return "Unknown"; 546 | case ELF64_OSABISysV: return "System V"; 547 | case ELF64_OSABIHPUX: return "HP/UX"; 548 | case ELF64_OSABIStandalone: return "Standalone"; 549 | } 550 | } 551 | 552 | ELF64_ObjectFileType ELF64_HeaderGetObjectFileType( ELF64_HeaderRef header ) 553 | { 554 | if( header == NULL ) 555 | { 556 | return ELF64_ObjectFileTypeNone; 557 | } 558 | 559 | switch( header->e_type ) 560 | { 561 | case 0: return ELF64_ObjectFileTypeNone; 562 | case 1: return ELF64_ObjectFileTypeRelocatableObjectFile; 563 | case 2: return ELF64_ObjectFileTypeExecutableFile; 564 | case 3: return ELF64_ObjectFileTypeSharedObjectFile; 565 | case 4: return ELF64_ObjectFileTypeCoreFile; 566 | default: break; 567 | } 568 | 569 | return ELF64_ObjectFileTypeNone; 570 | } 571 | 572 | const char * ELF64_HeaderGetObjectFileTypeString( ELF64_HeaderRef header ) 573 | { 574 | switch( ELF64_HeaderGetObjectFileType( header ) ) 575 | { 576 | case ELF64_ObjectFileTypeNone: return "None"; 577 | case ELF64_ObjectFileTypeRelocatableObjectFile: return "Relocatable object file"; 578 | case ELF64_ObjectFileTypeExecutableFile: return "Executable file"; 579 | case ELF64_ObjectFileTypeSharedObjectFile: return "Shared object file"; 580 | case ELF64_ObjectFileTypeCoreFile: return "Core file"; 581 | } 582 | } 583 | 584 | ELF64_Half ELF64_HeaderGetMachine( ELF64_HeaderRef header ) 585 | { 586 | if( header == NULL ) 587 | { 588 | return 0; 589 | } 590 | 591 | return header->e_machine; 592 | } 593 | 594 | ELF64_MachineType ELF64_HeaderGetMachineType( ELF64_HeaderRef header ) 595 | { 596 | if( header == NULL ) 597 | { 598 | return ELF64_MachineTypeUnknown; 599 | } 600 | 601 | switch( ELF64_HeaderGetMachine( header ) ) 602 | { 603 | case 0: return ELF64_MachineTypeUnknown; 604 | case 1: return ELF64_MachineTypeM32; 605 | case 2: return ELF64_MachineTypeSPARC; 606 | case 3: return ELF64_MachineType386; 607 | case 4: return ELF64_MachineType68K; 608 | case 5: return ELF64_MachineType88K; 609 | case 7: return ELF64_MachineType860; 610 | case 8: return ELF64_MachineTypeMIPS; 611 | case 9: return ELF64_MachineTypeS370; 612 | case 10: return ELF64_MachineTypeMIPSRS3LE; 613 | case 15: return ELF64_MachineTypePARISC; 614 | case 17: return ELF64_MachineTypeVPP500; 615 | case 18: return ELF64_MachineTypeSPARC32Plus; 616 | case 19: return ELF64_MachineType960; 617 | case 20: return ELF64_MachineTypePPC; 618 | case 21: return ELF64_MachineTypePPC64; 619 | case 36: return ELF64_MachineTypeV800; 620 | case 37: return ELF64_MachineTypeFR20; 621 | case 38: return ELF64_MachineTypeRH32; 622 | case 39: return ELF64_MachineTypeRCE; 623 | case 40: return ELF64_MachineTypeARM; 624 | case 41: return ELF64_MachineTypeAlpha; 625 | case 42: return ELF64_MachineTypeSH; 626 | case 43: return ELF64_MachineTypeSPARCV9; 627 | case 44: return ELF64_MachineTypeTricore; 628 | case 45: return ELF64_MachineTypeARC; 629 | case 46: return ELF64_MachineTypeH8300; 630 | case 47: return ELF64_MachineTypeH8300H; 631 | case 48: return ELF64_MachineTypeH8S; 632 | case 49: return ELF64_MachineTypeH8500; 633 | case 50: return ELF64_MachineTypeIA64; 634 | case 51: return ELF64_MachineTypeMIPSX; 635 | case 52: return ELF64_MachineTypeColdFire; 636 | case 53: return ELF64_MachineType68HC12; 637 | case 54: return ELF64_MachineTypeMMA; 638 | case 55: return ELF64_MachineTypePCP; 639 | case 56: return ELF64_MachineTypeNCPU; 640 | case 57: return ELF64_MachineTypeNDR1; 641 | case 58: return ELF64_MachineTypeStarCore; 642 | case 59: return ELF64_MachineTypeME16; 643 | case 60: return ELF64_MachineTypeST100; 644 | case 61: return ELF64_MachineTypeTinyJ; 645 | case 66: return ELF64_MachineTypeFX66; 646 | case 67: return ELF64_MachineTypeST9Plus; 647 | case 68: return ELF64_MachineTypeST7; 648 | case 69: return ELF64_MachineType68HC16; 649 | case 70: return ELF64_MachineType68HC11; 650 | case 71: return ELF64_MachineType68HC08; 651 | case 72: return ELF64_MachineType68HC05; 652 | case 73: return ELF64_MachineTypeSVX; 653 | case 74: return ELF64_MachineTypeST19; 654 | case 75: return ELF64_MachineTypeVAX; 655 | case 76: return ELF64_MachineTypeCRIS; 656 | case 77: return ELF64_MachineTypeJavelin; 657 | case 78: return ELF64_MachineTypeFirePath; 658 | case 79: return ELF64_MachineTypeZSP; 659 | case 80: return ELF64_MachineTypeMMIX; 660 | case 81: return ELF64_MachineTypeHUANY; 661 | case 82: return ELF64_MachineTypePrism; 662 | default: break; 663 | } 664 | 665 | return ELF64_MachineTypeUnknown; 666 | } 667 | 668 | const char * ELF64_HeaderGetMachineTypeString( ELF64_HeaderRef header ) 669 | { 670 | switch( ELF64_HeaderGetMachineType( header ) ) 671 | { 672 | case ELF64_MachineTypeUnknown: return "Unknown"; 673 | case ELF64_MachineTypeM32: return "AT&T WE 32100"; 674 | case ELF64_MachineTypeSPARC: return "SPARC"; 675 | case ELF64_MachineType386: return "Intel 80386"; 676 | case ELF64_MachineType68K: return "Motorola 68000"; 677 | case ELF64_MachineType88K: return "Motorola 88000"; 678 | case ELF64_MachineType860: return "Intel 80860"; 679 | case ELF64_MachineTypeMIPS: return "MIPS I Architecture"; 680 | case ELF64_MachineTypeS370: return "IBM System/370 Processor"; 681 | case ELF64_MachineTypeMIPSRS3LE: return "MIPS RS3000 Little-endian"; 682 | case ELF64_MachineTypePARISC: return "Hewlett-Packard PA-RISC"; 683 | case ELF64_MachineTypeVPP500: return "Fujitsu VPP500"; 684 | case ELF64_MachineTypeSPARC32Plus: return "Enhanced instruction set SPARC"; 685 | case ELF64_MachineType960: return "Intel 80960"; 686 | case ELF64_MachineTypePPC: return "PowerPC"; 687 | case ELF64_MachineTypePPC64: return "64-bit PowerPC"; 688 | case ELF64_MachineTypeV800: return "NEC V800"; 689 | case ELF64_MachineTypeFR20: return "Fujitsu FR20"; 690 | case ELF64_MachineTypeRH32: return "TRW RH-32"; 691 | case ELF64_MachineTypeRCE: return "Motorola RCE"; 692 | case ELF64_MachineTypeARM: return "Advanced RISC Machines ARM"; 693 | case ELF64_MachineTypeAlpha: return "Digital Alpha"; 694 | case ELF64_MachineTypeSH: return "Hitachi SH"; 695 | case ELF64_MachineTypeSPARCV9: return "SPARC Version 9"; 696 | case ELF64_MachineTypeTricore: return "Siemens Tricore embedded processor"; 697 | case ELF64_MachineTypeARC: return "Argonaut RISC Core, Argonaut Technologies Inc."; 698 | case ELF64_MachineTypeH8300: return "Hitachi H8/300"; 699 | case ELF64_MachineTypeH8300H: return "Hitachi H8/300H"; 700 | case ELF64_MachineTypeH8S: return "Hitachi H8S"; 701 | case ELF64_MachineTypeH8500: return "Hitachi H8/500"; 702 | case ELF64_MachineTypeIA64: return "Intel IA-64 processor architecture"; 703 | case ELF64_MachineTypeMIPSX: return "Stanford MIPS-X"; 704 | case ELF64_MachineTypeColdFire: return "Motorola ColdFire"; 705 | case ELF64_MachineType68HC12: return "Motorola M68HC12"; 706 | case ELF64_MachineTypeMMA: return "Fujitsu MMA Multimedia Accelerator"; 707 | case ELF64_MachineTypePCP: return "Siemens PCP"; 708 | case ELF64_MachineTypeNCPU: return "Sony nCPU embedded RISC processor"; 709 | case ELF64_MachineTypeNDR1: return "Denso NDR1 microprocessor"; 710 | case ELF64_MachineTypeStarCore: return "Motorola Star*Core processor"; 711 | case ELF64_MachineTypeME16: return "Toyota ME16 processor"; 712 | case ELF64_MachineTypeST100: return "STMicroelectronics ST100 processor"; 713 | case ELF64_MachineTypeTinyJ: return "Advanced Logic Corp. TinyJ embedded processor family"; 714 | case ELF64_MachineTypeFX66: return "Siemens FX66 microcontroller"; 715 | case ELF64_MachineTypeST9Plus: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; 716 | case ELF64_MachineTypeST7: return "STMicroelectronics ST7 8-bit microcontroller"; 717 | case ELF64_MachineType68HC16: return "Motorola MC68HC16 Microcontroller"; 718 | case ELF64_MachineType68HC11: return "Motorola MC68HC11 Microcontroller"; 719 | case ELF64_MachineType68HC08: return "Motorola MC68HC08 Microcontroller"; 720 | case ELF64_MachineType68HC05: return "Motorola MC68HC05 Microcontroller"; 721 | case ELF64_MachineTypeSVX: return "Silicon Graphics SVx"; 722 | case ELF64_MachineTypeST19: return "STMicroelectronics ST19 8-bit microcontroller"; 723 | case ELF64_MachineTypeVAX: return "Digital VAX"; 724 | case ELF64_MachineTypeCRIS: return "Axis Communications 32-bit embedded processor"; 725 | case ELF64_MachineTypeJavelin: return "Infineon Technologies 32-bit embedded processor"; 726 | case ELF64_MachineTypeFirePath: return "Element 14 64-bit DSP Processor"; 727 | case ELF64_MachineTypeZSP: return "LSI Logic 16-bit DSP Processor"; 728 | case ELF64_MachineTypeMMIX: return "Donald Knuth's educational 64-bit processor"; 729 | case ELF64_MachineTypeHUANY: return "Harvard University machine-independent object files"; 730 | case ELF64_MachineTypePrism: return "SiTera Prism"; 731 | } 732 | } 733 | 734 | ELF64_Word ELF64_HeaderGetVersion( ELF64_HeaderRef header ) 735 | { 736 | if( header == NULL ) 737 | { 738 | return 0; 739 | } 740 | 741 | return header->e_version; 742 | } 743 | 744 | ELF64_Addr ELF64_HeaderGetEntryPointAddress( ELF64_HeaderRef header ) 745 | { 746 | if( header == NULL ) 747 | { 748 | return 0; 749 | } 750 | 751 | return header->e_entry; 752 | } 753 | 754 | ELF64_Off ELF64_HeaderGetProgramHeaderOffset( ELF64_HeaderRef header ) 755 | { 756 | if( header == NULL ) 757 | { 758 | return 0; 759 | } 760 | 761 | return header->e_phoff; 762 | } 763 | 764 | ELF64_Off ELF64_HeaderGetSectionHeaderOffset( ELF64_HeaderRef header ) 765 | { 766 | if( header == NULL ) 767 | { 768 | return 0; 769 | } 770 | 771 | return header->e_shoff; 772 | } 773 | 774 | ELF64_Word ELF64_HeaderGetProcessorSpecificFlags( ELF64_HeaderRef header ) 775 | { 776 | if( header == NULL ) 777 | { 778 | return 0; 779 | } 780 | 781 | return header->e_flags; 782 | } 783 | 784 | ELF64_Half ELF64_HeaderGetHeaderSize( ELF64_HeaderRef header ) 785 | { 786 | if( header == NULL ) 787 | { 788 | return 0; 789 | } 790 | 791 | return header->e_ehsize; 792 | } 793 | 794 | ELF64_Half ELF64_HeaderGetProgramHeaderEntrySize( ELF64_HeaderRef header ) 795 | { 796 | if( header == NULL ) 797 | { 798 | return 0; 799 | } 800 | 801 | return header->e_phentsize; 802 | } 803 | 804 | ELF64_Half ELF64_HeaderGetProgramHeaderEntryCount( ELF64_HeaderRef header ) 805 | { 806 | if( header == NULL ) 807 | { 808 | return 0; 809 | } 810 | 811 | return header->e_phnum; 812 | } 813 | 814 | ELF64_Half ELF64_HeaderGetSectionHeaderEntrySize( ELF64_HeaderRef header ) 815 | { 816 | if( header == NULL ) 817 | { 818 | return 0; 819 | } 820 | 821 | return header->e_shentsize; 822 | } 823 | 824 | ELF64_Half ELF64_HeaderGetSectionHeaderEntryCount( ELF64_HeaderRef header ) 825 | { 826 | if( header == NULL ) 827 | { 828 | return 0; 829 | } 830 | 831 | return header->e_shnum; 832 | } 833 | 834 | ELF64_Half ELF64_HeaderGetSectionNameStringTableIndex( ELF64_HeaderRef header ) 835 | { 836 | if( header == NULL ) 837 | { 838 | return 0; 839 | } 840 | 841 | return header->e_shstrndx; 842 | } 843 | 844 | ELF64_SegmentType ELF64_ProgramHeaderEntryGetType( ELF64_ProgramHeaderEntryRef entry ) 845 | { 846 | if( entry == NULL ) 847 | { 848 | return ELF64_SegmentTypeUnused; 849 | } 850 | 851 | switch( entry->p_type ) 852 | { 853 | case 0: return ELF64_SegmentTypeUnused; 854 | case 1: return ELF64_SegmentTypeLoadable; 855 | case 2: return ELF64_SegmentTypeDynamicLinkingTables; 856 | case 3: return ELF64_SegmentTypeProgramInterpreterPathName; 857 | case 4: return ELF64_SegmentTypeNoteSections; 858 | case 6: return ELF64_SegmentTypeProgramHeaderTable; 859 | default: break; 860 | } 861 | 862 | return ELF64_SegmentTypeUnused; 863 | } 864 | 865 | const char * ELF64_ProgramHeaderEntryGetTypeString( ELF64_ProgramHeaderEntryRef entry ) 866 | { 867 | switch( ELF64_ProgramHeaderEntryGetType( entry ) ) 868 | { 869 | case ELF64_SegmentTypeUnused: return "Unused entry"; 870 | case ELF64_SegmentTypeLoadable: return "Loadable segment"; 871 | case ELF64_SegmentTypeDynamicLinkingTables: return "Dynamic linking tables"; 872 | case ELF64_SegmentTypeProgramInterpreterPathName: return "Program interpreter path name"; 873 | case ELF64_SegmentTypeNoteSections: return "Note sections"; 874 | case ELF64_SegmentTypeProgramHeaderTable: return "Program header table"; 875 | } 876 | } 877 | 878 | ELF64_Word ELF64_ProgramHeaderEntryGetAttributes( ELF64_ProgramHeaderEntryRef entry ) 879 | { 880 | if( entry == NULL ) 881 | { 882 | return 0; 883 | } 884 | 885 | return entry->p_flags; 886 | } 887 | 888 | const char * ELF64_ProgramHeaderEntryGetAttributesString( ELF64_ProgramHeaderEntryRef entry ) 889 | { 890 | ELF64_Word flags; 891 | 892 | flags = ELF64_ProgramHeaderEntryGetAttributes( entry ); 893 | 894 | if( flags & ELF64_SegmentAttributeRead && flags & ELF64_SegmentAttributeWrite && flags & ELF64_SegmentAttributeExecute ) 895 | { 896 | return "rwx"; 897 | } 898 | else if( flags & ELF64_SegmentAttributeRead && flags & ELF64_SegmentAttributeWrite ) 899 | { 900 | return "rw-"; 901 | } 902 | else if( flags & ELF64_SegmentAttributeRead && flags & ELF64_SegmentAttributeExecute ) 903 | { 904 | return "r-x"; 905 | } 906 | else if( flags & ELF64_SegmentAttributeWrite && flags & ELF64_SegmentAttributeExecute ) 907 | { 908 | return "-wx"; 909 | } 910 | else if( flags & ELF64_SegmentAttributeRead ) 911 | { 912 | return "r--"; 913 | } 914 | else if( flags & ELF64_SegmentAttributeWrite ) 915 | { 916 | return "-w-"; 917 | } 918 | else if( flags & ELF64_SegmentAttributeExecute ) 919 | { 920 | return "--x"; 921 | } 922 | 923 | return "---"; 924 | } 925 | 926 | ELF64_Off ELF64_ProgramHeaderEntryGetFileOffset( ELF64_ProgramHeaderEntryRef entry ) 927 | { 928 | if( entry == NULL ) 929 | { 930 | return 0; 931 | } 932 | 933 | return entry->p_offset; 934 | } 935 | 936 | ELF64_Addr ELF64_ProgramHeaderEntryGetMemoryVirtualAddress( ELF64_ProgramHeaderEntryRef entry ) 937 | { 938 | if( entry == NULL ) 939 | { 940 | return 0; 941 | } 942 | 943 | return entry->p_vaddr; 944 | } 945 | 946 | ELF64_XWord ELF64_ProgramHeaderEntryGetFileSize( ELF64_ProgramHeaderEntryRef entry ) 947 | { 948 | if( entry == NULL ) 949 | { 950 | return 0; 951 | } 952 | 953 | return entry->p_filesz; 954 | } 955 | 956 | ELF64_XWord ELF64_ProgramHeaderEntryGetMemorySize( ELF64_ProgramHeaderEntryRef entry ) 957 | { 958 | if( entry == NULL ) 959 | { 960 | return 0; 961 | } 962 | 963 | return entry->p_memsz; 964 | } 965 | 966 | ELF64_XWord ELF64_ProgramHeaderEntryGetAlignment( ELF64_ProgramHeaderEntryRef entry ) 967 | { 968 | if( entry == NULL ) 969 | { 970 | return 0; 971 | } 972 | 973 | return entry->p_align; 974 | } 975 | 976 | ELF64_Word ELF64_SectionHeaderEntryGetNameOffset( ELF64_SectionHeaderEntryRef entry ) 977 | { 978 | if( entry == NULL ) 979 | { 980 | return 0; 981 | } 982 | 983 | return entry->sh_name; 984 | } 985 | 986 | ELF64_SectionType ELF64_SectionHeaderEntryGetType( ELF64_SectionHeaderEntryRef entry ) 987 | { 988 | if( entry == NULL ) 989 | { 990 | return ELF64_SectionTypeUnused; 991 | } 992 | 993 | switch( entry->sh_type ) 994 | { 995 | case 0: return ELF64_SectionTypeUnused; 996 | case 1: return ELF64_SectionTypeProgBits; 997 | case 2: return ELF64_SectionTypeLinkerSymbolTable; 998 | case 3: return ELF64_SectionTypeStringTable; 999 | case 4: return ELF64_SectionTypeRelaRelocationEntries; 1000 | case 5: return ELF64_SectionTypeSymbolHashTable; 1001 | case 6: return ELF64_SectionTypeDynamicLinkingTables; 1002 | case 7: return ELF64_SectionTypeNoteInformation; 1003 | case 8: return ELF64_SectionTypeUninitializedSpace; 1004 | case 9: return ELF64_SectionTypeRelRelocationEntries; 1005 | case 11: return ELF64_SectionTypeDynamicLoaderSymbolTable; 1006 | default: break; 1007 | } 1008 | 1009 | return ELF64_SectionTypeUnused; 1010 | } 1011 | 1012 | const char * ELF64_SectionHeaderEntryGetTypeString( ELF64_SectionHeaderEntryRef entry ) 1013 | { 1014 | switch( ELF64_SectionHeaderEntryGetType( entry ) ) 1015 | { 1016 | case ELF64_SectionTypeUnused: return "Unused section"; 1017 | case ELF64_SectionTypeProgBits: return "Program information"; 1018 | case ELF64_SectionTypeLinkerSymbolTable: return "Linker symbol table"; 1019 | case ELF64_SectionTypeStringTable: return "String table"; 1020 | case ELF64_SectionTypeRelaRelocationEntries: return "\"Rela\" type relocation entries"; 1021 | case ELF64_SectionTypeSymbolHashTable: return "Symbol hash table"; 1022 | case ELF64_SectionTypeDynamicLinkingTables: return "Dynamic linking tables"; 1023 | case ELF64_SectionTypeNoteInformation: return "Note information"; 1024 | case ELF64_SectionTypeUninitializedSpace: return "Uninitialized space"; 1025 | case ELF64_SectionTypeRelRelocationEntries: return "\"Rel\" type relocation entries"; 1026 | case ELF64_SectionTypeDynamicLoaderSymbolTable: return "Dynamic loader symbol table"; 1027 | } 1028 | } 1029 | 1030 | ELF64_XWord ELF64_SectionHeaderEntryGetAttributes( ELF64_SectionHeaderEntryRef entry ) 1031 | { 1032 | if( entry == NULL ) 1033 | { 1034 | return 0; 1035 | } 1036 | 1037 | return entry->sh_flags; 1038 | } 1039 | 1040 | const char * ELF64_SectionHeaderEntryGetAttributesString( ELF64_SectionHeaderEntryRef entry ) 1041 | { 1042 | ELF64_XWord flags; 1043 | 1044 | flags = ELF64_SectionHeaderEntryGetAttributes( entry ); 1045 | 1046 | if( flags & ELF64_SectionAttributeWrite && flags & ELF64_SectionAttributeAlloc && flags & ELF64_SectionAttributeExecute ) 1047 | { 1048 | return "wax"; 1049 | } 1050 | else if( flags & ELF64_SectionAttributeWrite && flags & ELF64_SectionAttributeAlloc ) 1051 | { 1052 | return "wa-"; 1053 | } 1054 | else if( flags & ELF64_SectionAttributeWrite && flags & ELF64_SegmentAttributeExecute ) 1055 | { 1056 | return "w-x"; 1057 | } 1058 | else if( flags & ELF64_SectionAttributeAlloc && flags & ELF64_SegmentAttributeExecute ) 1059 | { 1060 | return "-ax"; 1061 | } 1062 | else if( flags & ELF64_SectionAttributeWrite ) 1063 | { 1064 | return "w--"; 1065 | } 1066 | else if( flags & ELF64_SectionAttributeAlloc ) 1067 | { 1068 | return "-a-"; 1069 | } 1070 | else if( flags & ELF64_SectionAttributeExecute ) 1071 | { 1072 | return "--x"; 1073 | } 1074 | 1075 | return "---"; 1076 | } 1077 | 1078 | ELF64_Addr ELF64_SectionHeaderEntryGetMemoryVirtualAddress( ELF64_SectionHeaderEntryRef entry ) 1079 | { 1080 | if( entry == NULL ) 1081 | { 1082 | return 0; 1083 | } 1084 | 1085 | return entry->sh_addr; 1086 | } 1087 | 1088 | ELF64_Off ELF64_SectionHeaderEntryGetFileOffset( ELF64_SectionHeaderEntryRef entry ) 1089 | { 1090 | if( entry == NULL ) 1091 | { 1092 | return 0; 1093 | } 1094 | 1095 | return entry->sh_offset; 1096 | } 1097 | 1098 | ELF64_XWord ELF64_SectionHeaderEntryGetSectionSize( ELF64_SectionHeaderEntryRef entry ) 1099 | { 1100 | if( entry == NULL ) 1101 | { 1102 | return 0; 1103 | } 1104 | 1105 | return entry->sh_size; 1106 | } 1107 | 1108 | ELF64_Word ELF64_SectionHeaderEntryGetLinkedSectionIndex( ELF64_SectionHeaderEntryRef entry ) 1109 | { 1110 | if( entry == NULL ) 1111 | { 1112 | return 0; 1113 | } 1114 | 1115 | return entry->sh_link; 1116 | } 1117 | 1118 | ELF64_Word ELF64_SectionHeaderEntryGetMiscInfo( ELF64_SectionHeaderEntryRef entry ) 1119 | { 1120 | if( entry == NULL ) 1121 | { 1122 | return 0; 1123 | } 1124 | 1125 | return entry->sh_info; 1126 | } 1127 | 1128 | ELF64_XWord ELF64_SectionHeaderEntryGetAddressAlignmentBoundary( ELF64_SectionHeaderEntryRef entry ) 1129 | { 1130 | if( entry == NULL ) 1131 | { 1132 | return 0; 1133 | } 1134 | 1135 | return entry->sh_addralign; 1136 | } 1137 | 1138 | ELF64_XWord ELF64_SectionHeaderEntryGetEntrySize( ELF64_SectionHeaderEntryRef entry ) 1139 | { 1140 | if( entry == NULL ) 1141 | { 1142 | return 0; 1143 | } 1144 | 1145 | return entry->sh_entsize; 1146 | } 1147 | 1148 | unsigned int ELF64_SectionHeaderEntryGetSymbolTableEntryCount( ELF64_SectionHeaderEntryRef section ) 1149 | { 1150 | ELF64_XWord entrySize; 1151 | ELF64_XWord sectionSize; 1152 | 1153 | if( ELF64_SectionHeaderEntryGetType( section ) != ELF64_SectionTypeLinkerSymbolTable ) 1154 | { 1155 | return 0; 1156 | } 1157 | 1158 | entrySize = ELF64_SectionHeaderEntryGetEntrySize( section ); 1159 | sectionSize = ELF64_SectionHeaderEntryGetSectionSize( section ); 1160 | 1161 | if( entrySize == 0 ) 1162 | { 1163 | return 0; 1164 | } 1165 | 1166 | return ( unsigned int )( sectionSize / entrySize ); 1167 | } 1168 | 1169 | ELF64_Word ELF64_SymbolTableEntryGetNameOffset( ELF64_SymbolTableEntryRef sym ) 1170 | { 1171 | if( sym == NULL ) 1172 | { 1173 | return 0; 1174 | } 1175 | 1176 | return sym->st_name; 1177 | } 1178 | 1179 | ELF64_UChar ELF64_SymbolTableEntryGetInfo( ELF64_SymbolTableEntryRef sym ) 1180 | { 1181 | if( sym == NULL ) 1182 | { 1183 | return 0; 1184 | } 1185 | 1186 | return sym->st_info; 1187 | } 1188 | 1189 | ELF64_SymbolType ELF64_SymbolTableEntryGetType( ELF64_SymbolTableEntryRef sym ) 1190 | { 1191 | if( sym == NULL ) 1192 | { 1193 | return ELF64_SymbolTypeNone; 1194 | } 1195 | 1196 | switch( ELF64_SymbolTableEntryGetInfo( sym ) & 0x0F ) 1197 | { 1198 | case 0: return ELF64_SymbolTypeNone; 1199 | case 1: return ELF64_SymbolTypeDataObject; 1200 | case 2: return ELF64_SymbolTypeFunctionEntryPoint; 1201 | case 3: return ELF64_SymbolTypeSection; 1202 | case 4: return ELF64_SymbolTypeFile; 1203 | default: break; 1204 | } 1205 | 1206 | return ELF64_SymbolTypeNone; 1207 | } 1208 | 1209 | const char * ELF64_SymbolTableEntryGetTypeString( ELF64_SymbolTableEntryRef sym ) 1210 | { 1211 | switch( ELF64_SymbolTableEntryGetType( sym ) ) 1212 | { 1213 | case ELF64_SymbolTypeNone: return "No type specified"; 1214 | case ELF64_SymbolTypeDataObject: return "Data object"; 1215 | case ELF64_SymbolTypeFunctionEntryPoint: return "Function entry point"; 1216 | case ELF64_SymbolTypeSection: return "Symbol associated with a section"; 1217 | case ELF64_SymbolTypeFile: return "Source file associated with the object file"; 1218 | } 1219 | } 1220 | 1221 | ELF64_SymbolBinding ELF64_SymbolTableEntryGetBinding( ELF64_SymbolTableEntryRef sym ) 1222 | { 1223 | if( sym == NULL ) 1224 | { 1225 | return ELF64_SymbolBindingLocal; 1226 | } 1227 | 1228 | switch( ELF64_SymbolTableEntryGetInfo( sym ) & 0xF0 ) 1229 | { 1230 | case 0: return ELF64_SymbolBindingLocal; 1231 | case 1: return ELF64_SymbolBindingGlobal; 1232 | case 2: return ELF64_SymbolBindingWeak; 1233 | default: break; 1234 | } 1235 | 1236 | return ELF64_SymbolBindingLocal; 1237 | } 1238 | 1239 | const char * ELF64_SymbolTableEntryGetBindingString( ELF64_SymbolTableEntryRef sym ) 1240 | { 1241 | switch( ELF64_SymbolTableEntryGetBinding( sym ) ) 1242 | { 1243 | case ELF64_SymbolBindingLocal: return "Local"; 1244 | case ELF64_SymbolBindingGlobal: return "Global"; 1245 | case ELF64_SymbolBindingWeak: return "Weak"; 1246 | } 1247 | } 1248 | 1249 | ELF64_Half ELF64_SymbolTableEntryGetSectionTableIndex( ELF64_SymbolTableEntryRef sym ) 1250 | { 1251 | if( sym == NULL ) 1252 | { 1253 | return 0; 1254 | } 1255 | 1256 | return sym->st_shndx; 1257 | } 1258 | 1259 | ELF64_Addr ELF64_SymbolTableEntryGetSymbolValue( ELF64_SymbolTableEntryRef sym ) 1260 | { 1261 | if( sym == NULL ) 1262 | { 1263 | return 0; 1264 | } 1265 | 1266 | return sym->st_value; 1267 | } 1268 | 1269 | ELF64_XWord ELF64_SymbolTableEntryGetObjectSize( ELF64_SymbolTableEntryRef sym ) 1270 | { 1271 | if( sym == NULL ) 1272 | { 1273 | return 0; 1274 | } 1275 | 1276 | return sym->st_size; 1277 | } 1278 | 1279 | unsigned long ELF64_Hash( const char * name ) 1280 | { 1281 | unsigned long h; 1282 | unsigned long g; 1283 | 1284 | h = 0; 1285 | 1286 | while( *( name ) ) 1287 | { 1288 | h = ( h << 4 ) + *( ( const unsigned char * )name++ ); 1289 | 1290 | if( ( g = h & 0xF0000000 ) ) 1291 | { 1292 | h ^= g >> 24; 1293 | } 1294 | 1295 | h &= 0x0FFFFFFF; 1296 | } 1297 | 1298 | return h; 1299 | } 1300 | --------------------------------------------------------------------------------