├── .gitignore ├── LICENSE ├── LICENSE.Apachev2 ├── LICENSE.BSD3 ├── LICENSE.CC0 ├── LICENSE.MIT ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts ├── src └── dorkbox │ └── peParser │ ├── ByteArray.kt │ ├── DataLocation.kt │ ├── PE.kt │ ├── headers │ ├── COFFFileHeader.kt │ ├── Header.kt │ ├── OptionalHeader.kt │ ├── SectionTable.kt │ ├── SectionTableEntry.kt │ ├── flags │ │ ├── Characteristics.kt │ │ ├── DllCharacteristicsType.kt │ │ ├── SectionCharacteristicsType.kt │ │ └── package-info.java │ ├── package-info.java │ └── resources │ │ ├── ResourceDataEntry.kt │ │ ├── ResourceDirectoryEntry.kt │ │ ├── ResourceDirectoryHeader.kt │ │ └── package-info.java │ ├── misc │ ├── DirEntry.kt │ ├── ImageBaseType.kt │ ├── MachineTypeType.kt │ ├── MagicNumberType.kt │ ├── ResourceTypes.kt │ ├── SubsystemType.kt │ └── package-info.java │ ├── package-info.java │ └── types │ ├── AsciiString.kt │ ├── ByteDefinition.kt │ ├── CoffCharacteristics.kt │ ├── DWORD.kt │ ├── DWORD_WIDE.kt │ ├── DllCharacteristics.kt │ ├── HeaderDefinition.kt │ ├── ImageBase.kt │ ├── ImageBase_Wide.kt │ ├── ImageDataDir.kt │ ├── ImageDataDirExtra.kt │ ├── MachineType.kt │ ├── MagicNumber.kt │ ├── RVA.kt │ ├── ResourceDirName.kt │ ├── SectionCharacteristics.kt │ ├── Subsystem.kt │ ├── TInteger.kt │ ├── TimeDate.kt │ ├── WORD.kt │ └── package-info.java └── src9 ├── dorkbox └── peParser │ ├── EmptyClass.java │ ├── headers │ └── EmptyClass.java │ ├── misc │ └── EmptyClass.java │ └── types │ └── EmptyClass.java └── module-info.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 3 | 4 | # User-specific stuff: 5 | .idea/**/workspace.xml 6 | .idea/**/tasks.xml 7 | .idea/dictionaries 8 | .idea/**/codeStyles/ 9 | .idea/**/codeStyleSettings.xml 10 | 11 | # Sensitive or high-churn files: 12 | .idea/**/dataSources/ 13 | .idea/**/dataSources.ids 14 | .idea/**/dataSources.xml 15 | .idea/**/dataSources.local.xml 16 | .idea/**/sqlDataSources.xml 17 | .idea/**/dynamic.xml 18 | .idea/**/uiDesigner.xml 19 | .idea/**/shelf/ 20 | 21 | 22 | # Gradle: 23 | .idea/**/gradle.xml 24 | .idea/**/libraries 25 | 26 | # CMake 27 | cmake-build-debug/ 28 | 29 | # Mongo Explorer plugin: 30 | .idea/**/mongoSettings.xml 31 | 32 | ## File-based project format: 33 | *.iws 34 | 35 | ## Plugin-specific files: 36 | 37 | 38 | # IntelliJ 39 | out/ 40 | 41 | # mpeltonen/sbt-idea plugin 42 | .idea_modules/ 43 | 44 | # JIRA plugin 45 | atlassian-ide-plugin.xml 46 | 47 | # Cursive Clojure plugin 48 | .idea/replstate.xml 49 | 50 | # Crashlytics plugin (for Android Studio and IntelliJ) 51 | com_crashlytics_export_strings.xml 52 | crashlytics.properties 53 | crashlytics-build.properties 54 | fabric.properties 55 | 56 | ###################### 57 | # End JetBrains IDEs # 58 | ###################### 59 | 60 | 61 | # From https://github.com/github/gitignore/blob/master/Gradle.gitignore 62 | .gradle 63 | /build/ 64 | 65 | # Ignore Gradle GUI config 66 | gradle-app.setting 67 | 68 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 69 | !gradle-wrapper.jar 70 | !gradle-wrapper.properties 71 | 72 | # Cache of project 73 | .gradletasknamecache 74 | 75 | 76 | 77 | 78 | # From https://github.com/github/gitignore/blob/master/Java.gitignore 79 | *.class 80 | 81 | # Mobile Tools for Java (J2ME) 82 | .mtj.tmp/ 83 | 84 | 85 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 86 | hs_err_pid* 87 | 88 | *.DS_Store 89 | .AppleDouble 90 | .LSOverride 91 | 92 | # Icon must end with two \r 93 | Icon 94 | 95 | 96 | # Thumbnails 97 | ._* 98 | 99 | # Files that might appear in the root of a volume 100 | .DocumentRevisions-V100 101 | .fseventsd 102 | .Spotlight-V100 103 | .TemporaryItems 104 | .Trashes 105 | .VolumeIcon.icns 106 | .com.apple.timemachine.donotpresent 107 | 108 | # Directories potentially created on remote AFP share 109 | .AppleDB 110 | .AppleDesktop 111 | Network Trash Folder 112 | Temporary Items 113 | .apdisk 114 | 115 | 116 | 117 | ########################################################## 118 | # Specific to this module 119 | 120 | # iml files are generated by intellij/gradle now 121 | **/*.iml 122 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | - PeParser - 2 | [The Apache Software License, Version 2.0] 3 | https://git.dorkbox.com/dorkbox/PeParser 4 | Copyright 2023 5 | Dorkbox LLC 6 | Windows PE (Portable Executable) file parser for Java 8+ 7 | 8 | Extra license information 9 | - Kotlin - 10 | [The Apache Software License, Version 2.0] 11 | https://github.com/JetBrains/kotlin 12 | Copyright 2020 13 | JetBrains s.r.o. and Kotlin Programming Language contributors 14 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 15 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 16 | 17 | - Collections - Collection types and utilities to enhance the default collections. 18 | [The Apache Software License, Version 2.0] 19 | https://git.dorkbox.com/dorkbox/Collections 20 | Copyright 2023 21 | Dorkbox LLC 22 | 23 | Extra license information 24 | - Bias, BinarySearch - 25 | [MIT License] 26 | https://git.dorkbox.com/dorkbox/Collections 27 | https://github.com/timboudreau/util 28 | Copyright 2013 29 | Tim Boudreau 30 | 31 | - ConcurrentEntry - 32 | [The Apache Software License, Version 2.0] 33 | https://git.dorkbox.com/dorkbox/Collections 34 | Copyright 2016 35 | bennidi 36 | dorkbox 37 | 38 | - Collection Utilities (Array, ArrayMap, BooleanArray, ByteArray, CharArray, FloatArray, IdentityMap, IntArray, IntFloatMap, IntIntMap, IntMap, IntSet, LongArray, LongMap, ObjectFloatMap, ObjectIntMap, ObjectMap, ObjectSet, OrderedMap, OrderedSet) - 39 | [The Apache Software License, Version 2.0] 40 | https://git.dorkbox.com/dorkbox/Collections 41 | https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils 42 | Copyright 2011 43 | LibGDX 44 | Mario Zechner (badlogicgames@gmail.com) 45 | Nathan Sweet (nathan.sweet@gmail.com) 46 | 47 | - Predicate - 48 | [The Apache Software License, Version 2.0] 49 | https://git.dorkbox.com/dorkbox/Collections 50 | https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils 51 | Copyright 2011 52 | LibGDX 53 | Mario Zechner (badlogicgames@gmail.com) 54 | Nathan Sweet (nathan.sweet@gmail.com) 55 | xoppa 56 | 57 | - Select, QuickSelect - 58 | [The Apache Software License, Version 2.0] 59 | https://git.dorkbox.com/dorkbox/Collections 60 | https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/utils 61 | Copyright 2011 62 | LibGDX 63 | Mario Zechner (badlogicgames@gmail.com) 64 | Nathan Sweet (nathan.sweet@gmail.com) 65 | Jon Renner 66 | 67 | - Kotlin - 68 | [The Apache Software License, Version 2.0] 69 | https://github.com/JetBrains/kotlin 70 | Copyright 2020 71 | JetBrains s.r.o. and Kotlin Programming Language contributors 72 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 73 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 74 | 75 | - Updates - Software Update Management 76 | [The Apache Software License, Version 2.0] 77 | https://git.dorkbox.com/dorkbox/Updates 78 | Copyright 2021 79 | Dorkbox LLC 80 | 81 | Extra license information 82 | - Kotlin - 83 | [The Apache Software License, Version 2.0] 84 | https://github.com/JetBrains/kotlin 85 | Copyright 2020 86 | JetBrains s.r.o. and Kotlin Programming Language contributors 87 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 88 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 89 | 90 | - ByteUtilities - Byte manipulation and SHA/xxHash utilities 91 | [The Apache Software License, Version 2.0] 92 | https://git.dorkbox.com/dorkbox/ByteUtilities 93 | Copyright 2023 94 | Dorkbox LLC 95 | 96 | Extra license information 97 | - Kryo Serialization - 98 | [BSD 3-Clause License] 99 | https://github.com/EsotericSoftware/kryo 100 | Copyright 2020 101 | Nathan Sweet 102 | 103 | - Base58 - 104 | [The Apache Software License, Version 2.0] 105 | https://bitcoinj.github.io 106 | https://github.com/komputing/KBase58 107 | Copyright 2018 108 | Google Inc 109 | Andreas Schildbach 110 | ligi 111 | 112 | - Kotlin - 113 | [The Apache Software License, Version 2.0] 114 | https://github.com/JetBrains/kotlin 115 | Copyright 2020 116 | JetBrains s.r.o. and Kotlin Programming Language contributors 117 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 118 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 119 | 120 | - Netty - An event-driven asynchronous network application framework 121 | [The Apache Software License, Version 2.0] 122 | https://netty.io 123 | Copyright 2023 124 | The Netty Project 125 | Contributors. See source NOTICE 126 | 127 | - Kryo - Fast and efficient binary object graph serialization framework for Java 128 | [BSD 3-Clause License] 129 | https://github.com/EsotericSoftware/kryo 130 | Copyright 2023 131 | Nathan Sweet 132 | 133 | Extra license information 134 | - ReflectASM - 135 | [BSD 3-Clause License] 136 | https://github.com/EsotericSoftware/reflectasm 137 | Nathan Sweet 138 | 139 | - Objenesis - 140 | [The Apache Software License, Version 2.0] 141 | https://github.com/easymock/objenesis 142 | Objenesis Team and all contributors 143 | 144 | - MinLog-SLF4J - 145 | [BSD 3-Clause License] 146 | https://github.com/EsotericSoftware/minlog 147 | Nathan Sweet 148 | 149 | - LZ4 and xxHash - LZ4 compression for Java, based on Yann Collet's work 150 | [The Apache Software License, Version 2.0] 151 | https://github.com/lz4/lz4 152 | Copyright 2023 153 | Yann Collet 154 | Adrien Grand 155 | 156 | - XZ for Java - Complete implementation of XZ data compression in pure Java 157 | [Public Domain, per Creative Commons CC0] 158 | https://tukaani.org/xz/java.html 159 | Copyright 2023 160 | Lasse Collin 161 | Igor Pavlov 162 | 163 | - Updates - Software Update Management 164 | [The Apache Software License, Version 2.0] 165 | https://git.dorkbox.com/dorkbox/Updates 166 | Copyright 2021 167 | Dorkbox LLC 168 | 169 | Extra license information 170 | - Kotlin - 171 | [The Apache Software License, Version 2.0] 172 | https://github.com/JetBrains/kotlin 173 | Copyright 2020 174 | JetBrains s.r.o. and Kotlin Programming Language contributors 175 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 176 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 177 | 178 | - HexUtilities - Hex conversion utilities for Strings, Collections, ByteArrays, Unsigned numbers, and numbers 179 | [The Apache Software License, Version 2.0] 180 | https://git.dorkbox.com/dorkbox/HexUtilities 181 | Copyright 2023 182 | Dorkbox LLC 183 | 184 | Extra license information 185 | - Hex utility methods - 186 | [The Apache Software License, Version 2.0] 187 | https://git.dorkbox.com/dorkbox/HexUtilities 188 | https://netty.io 189 | https://github.com/netty/netty/blob/4.1/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java 190 | Copyright 2014 191 | The Netty Project 192 | 193 | - Kotlin - 194 | [The Apache Software License, Version 2.0] 195 | https://github.com/JetBrains/kotlin 196 | Copyright 2020 197 | JetBrains s.r.o. and Kotlin Programming Language contributors 198 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 199 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 200 | 201 | - ByteUtilities - Byte manipulation and SHA/xxHash utilities 202 | [The Apache Software License, Version 2.0] 203 | https://git.dorkbox.com/dorkbox/ByteUtilities 204 | Copyright 2023 205 | Dorkbox LLC 206 | 207 | Extra license information 208 | - Kryo Serialization - 209 | [BSD 3-Clause License] 210 | https://github.com/EsotericSoftware/kryo 211 | Copyright 2020 212 | Nathan Sweet 213 | 214 | - Base58 - 215 | [The Apache Software License, Version 2.0] 216 | https://bitcoinj.github.io 217 | https://github.com/komputing/KBase58 218 | Copyright 2018 219 | Google Inc 220 | Andreas Schildbach 221 | ligi 222 | 223 | - Kotlin - 224 | [The Apache Software License, Version 2.0] 225 | https://github.com/JetBrains/kotlin 226 | Copyright 2020 227 | JetBrains s.r.o. and Kotlin Programming Language contributors 228 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 229 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 230 | 231 | - Netty - An event-driven asynchronous network application framework 232 | [The Apache Software License, Version 2.0] 233 | https://netty.io 234 | Copyright 2023 235 | The Netty Project 236 | Contributors. See source NOTICE 237 | 238 | - Kryo - Fast and efficient binary object graph serialization framework for Java 239 | [BSD 3-Clause License] 240 | https://github.com/EsotericSoftware/kryo 241 | Copyright 2023 242 | Nathan Sweet 243 | 244 | Extra license information 245 | - ReflectASM - 246 | [BSD 3-Clause License] 247 | https://github.com/EsotericSoftware/reflectasm 248 | Nathan Sweet 249 | 250 | - Objenesis - 251 | [The Apache Software License, Version 2.0] 252 | https://github.com/easymock/objenesis 253 | Objenesis Team and all contributors 254 | 255 | - MinLog-SLF4J - 256 | [BSD 3-Clause License] 257 | https://github.com/EsotericSoftware/minlog 258 | Nathan Sweet 259 | 260 | - LZ4 and xxHash - LZ4 compression for Java, based on Yann Collet's work 261 | [The Apache Software License, Version 2.0] 262 | https://github.com/lz4/lz4 263 | Copyright 2023 264 | Yann Collet 265 | Adrien Grand 266 | 267 | - XZ for Java - Complete implementation of XZ data compression in pure Java 268 | [Public Domain, per Creative Commons CC0] 269 | https://tukaani.org/xz/java.html 270 | Copyright 2023 271 | Lasse Collin 272 | Igor Pavlov 273 | 274 | - Updates - Software Update Management 275 | [The Apache Software License, Version 2.0] 276 | https://git.dorkbox.com/dorkbox/Updates 277 | Copyright 2021 278 | Dorkbox LLC 279 | 280 | Extra license information 281 | - Kotlin - 282 | [The Apache Software License, Version 2.0] 283 | https://github.com/JetBrains/kotlin 284 | Copyright 2020 285 | JetBrains s.r.o. and Kotlin Programming Language contributors 286 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 287 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 288 | 289 | - Updates - Software Update Management 290 | [The Apache Software License, Version 2.0] 291 | https://git.dorkbox.com/dorkbox/Updates 292 | Copyright 2021 293 | Dorkbox LLC 294 | 295 | Extra license information 296 | - Kotlin - 297 | [The Apache Software License, Version 2.0] 298 | https://github.com/JetBrains/kotlin 299 | Copyright 2020 300 | JetBrains s.r.o. and Kotlin Programming Language contributors 301 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 302 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 303 | 304 | - Updates - Software Update Management 305 | [The Apache Software License, Version 2.0] 306 | https://git.dorkbox.com/dorkbox/Updates 307 | Copyright 2021 308 | Dorkbox LLC 309 | 310 | Extra license information 311 | - Kotlin - 312 | [The Apache Software License, Version 2.0] 313 | https://github.com/JetBrains/kotlin 314 | Copyright 2020 315 | JetBrains s.r.o. and Kotlin Programming Language contributors 316 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 317 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 318 | 319 | - Utilities - Utilities for use within Java projects 320 | [The Apache Software License, Version 2.0] 321 | https://git.dorkbox.com/dorkbox/Utilities 322 | Copyright 2023 323 | Dorkbox LLC 324 | 325 | Extra license information 326 | - MersenneTwisterFast - 327 | [BSD 3-Clause License] 328 | https://git.dorkbox.com/dorkbox/Utilities 329 | Copyright 2003 330 | Sean Luke 331 | Michael Lecuyer (portions Copyright 1993 332 | 333 | - FastThreadLocal - 334 | [BSD 3-Clause License] 335 | https://git.dorkbox.com/dorkbox/Utilities 336 | https://github.com/LWJGL/lwjgl3/blob/5819c9123222f6ce51f208e022cb907091dd8023/modules/core/src/main/java/org/lwjgl/system/FastThreadLocal.java 337 | https://github.com/riven8192/LibStruct/blob/master/src/net/indiespot/struct/runtime/FastThreadLocal.java 338 | Copyright 2014 339 | Lightweight Java Game Library Project 340 | Riven 341 | 342 | - Retrofit - A type-safe HTTP client for Android and Java 343 | [The Apache Software License, Version 2.0] 344 | https://github.com/square/retrofit 345 | Copyright 2020 346 | Square, Inc 347 | 348 | - Resource Listing - Listing the contents of a resource directory 349 | [The Apache Software License, Version 2.0] 350 | https://www.uofr.net/~greg/java/get-resource-listing.html 351 | Copyright 2017 352 | Greg Briggs 353 | 354 | - CommonUtils - Common utility extension functions for kotlin 355 | [The Apache Software License, Version 2.0] 356 | https://www.pronghorn.tech 357 | Copyright 2017 358 | Pronghorn Technology LLC 359 | Dorkbox LLC 360 | 361 | - Kotlin Coroutine CountDownLatch - 362 | [The Apache Software License, Version 2.0] 363 | https://github.com/Kotlin/kotlinx.coroutines/issues/59 364 | https://github.com/venkatperi/kotlin-coroutines-lib 365 | Copyright 2018 366 | Venkat Peri 367 | 368 | - kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support 369 | [The Apache Software License, Version 2.0] 370 | https://github.com/Kotlin/kotlinx.coroutines 371 | Copyright 2023 372 | JetBrains s.r.o. 373 | 374 | - Java Uuid Generator - A set of Java classes for working with UUIDs 375 | [The Apache Software License, Version 2.0] 376 | https://github.com/cowtowncoder/java-uuid-generator 377 | Copyright 2023 378 | Tatu Saloranta (tatu.saloranta@iki.fi) 379 | Contributors. See source release-notes/CREDITS 380 | 381 | - Kotlin - 382 | [The Apache Software License, Version 2.0] 383 | https://github.com/JetBrains/kotlin 384 | Copyright 2020 385 | JetBrains s.r.o. and Kotlin Programming Language contributors 386 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 387 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 388 | 389 | - OS - Information about the system, Java runtime, OS, Window Manager, and Desktop Environment. 390 | [The Apache Software License, Version 2.0] 391 | https://git.dorkbox.com/dorkbox/OS 392 | Copyright 2023 393 | Dorkbox LLC 394 | 395 | Extra license information 396 | - Kotlin - 397 | [The Apache Software License, Version 2.0] 398 | https://github.com/JetBrains/kotlin 399 | Copyright 2020 400 | JetBrains s.r.o. and Kotlin Programming Language contributors 401 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 402 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 403 | 404 | - Updates - Software Update Management 405 | [The Apache Software License, Version 2.0] 406 | https://git.dorkbox.com/dorkbox/Updates 407 | Copyright 2021 408 | Dorkbox LLC 409 | 410 | Extra license information 411 | - Kotlin - 412 | [The Apache Software License, Version 2.0] 413 | https://github.com/JetBrains/kotlin 414 | Copyright 2020 415 | JetBrains s.r.o. and Kotlin Programming Language contributors 416 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 417 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 418 | 419 | - Updates - Software Update Management 420 | [The Apache Software License, Version 2.0] 421 | https://git.dorkbox.com/dorkbox/Updates 422 | Copyright 2021 423 | Dorkbox LLC 424 | 425 | Extra license information 426 | - Kotlin - 427 | [The Apache Software License, Version 2.0] 428 | https://github.com/JetBrains/kotlin 429 | Copyright 2020 430 | JetBrains s.r.o. and Kotlin Programming Language contributors 431 | Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply 432 | See: https://github.com/JetBrains/kotlin/blob/master/license/README.md 433 | -------------------------------------------------------------------------------- /LICENSE.Apachev2: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a 16 | copy of this software and associated documentation files (the "Software"), 17 | to deal in the Software without restriction, including without limitation 18 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 | and/or sell copies of the Software, and to permit persons to whom the 20 | Software is furnished to do so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included 23 | in all copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 26 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 | DEALINGS IN THE SOFTWARE. 32 | "Legal Entity" shall mean the union of the acting entity and all 33 | other entities that control, are controlled by, or are under common 34 | control with that entity. For the purposes of this definition, 35 | "control" means (i) the power, direct or indirect, to cause the 36 | direction or management of such entity, whether by contract or 37 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 38 | outstanding shares, or (iii) beneficial ownership of such entity. 39 | 40 | "You" (or "Your") shall mean an individual or Legal Entity 41 | exercising permissions granted by this License. 42 | 43 | "Source" form shall mean the preferred form for making modifications, 44 | including but not limited to software source code, documentation 45 | source, and configuration files. 46 | 47 | "Object" form shall mean any form resulting from mechanical 48 | transformation or translation of a Source form, including but 49 | not limited to compiled object code, generated documentation, 50 | and conversions to other media types. 51 | 52 | "Work" shall mean the work of authorship, whether in Source or 53 | Object form, made available under the License, as indicated by a 54 | copyright notice that is included in or attached to the work 55 | (an example is provided in the Appendix below). 56 | 57 | "Derivative Works" shall mean any work, whether in Source or Object 58 | form, that is based on (or derived from) the Work and for which the 59 | editorial revisions, annotations, elaborations, or other modifications 60 | represent, as a whole, an original work of authorship. For the purposes 61 | of this License, Derivative Works shall not include works that remain 62 | separable from, or merely link (or bind by name) to the interfaces of, 63 | the Work and Derivative Works thereof. 64 | 65 | "Contribution" shall mean any work of authorship, including 66 | the original version of the Work and any modifications or additions 67 | to that Work or Derivative Works thereof, that is intentionally 68 | submitted to Licensor for inclusion in the Work by the copyright owner 69 | or by an individual or Legal Entity authorized to submit on behalf of 70 | the copyright owner. For the purposes of this definition, "submitted" 71 | means any form of electronic, verbal, or written communication sent 72 | to the Licensor or its representatives, including but not limited to 73 | communication on electronic mailing lists, source code control systems, 74 | and issue tracking systems that are managed by, or on behalf of, the 75 | Licensor for the purpose of discussing and improving the Work, but 76 | excluding communication that is conspicuously marked or otherwise 77 | designated in writing by the copyright owner as "Not a Contribution." 78 | 79 | "Contributor" shall mean Licensor and any individual or Legal Entity 80 | on behalf of whom a Contribution has been received by Licensor and 81 | subsequently incorporated within the Work. 82 | 83 | 2. Grant of Copyright License. Subject to the terms and conditions of 84 | this License, each Contributor hereby grants to You a perpetual, 85 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 86 | copyright license to reproduce, prepare Derivative Works of, 87 | publicly display, publicly perform, sublicense, and distribute the 88 | Work and such Derivative Works in Source or Object form. 89 | 90 | 3. Grant of Patent License. Subject to the terms and conditions of 91 | this License, each Contributor hereby grants to You a perpetual, 92 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 93 | (except as stated in this section) patent license to make, have made, 94 | use, offer to sell, sell, import, and otherwise transfer the Work, 95 | where such license applies only to those patent claims licensable 96 | by such Contributor that are necessarily infringed by their 97 | Contribution(s) alone or by combination of their Contribution(s) 98 | with the Work to which such Contribution(s) was submitted. If You 99 | institute patent litigation against any entity (including a 100 | cross-claim or counterclaim in a lawsuit) alleging that the Work 101 | or a Contribution incorporated within the Work constitutes direct 102 | or contributory patent infringement, then any patent licenses 103 | granted to You under this License for that Work shall terminate 104 | as of the date such litigation is filed. 105 | 106 | 4. Redistribution. You may reproduce and distribute copies of the 107 | Work or Derivative Works thereof in any medium, with or without 108 | modifications, and in Source or Object form, provided that You 109 | meet the following conditions: 110 | 111 | (a) You must give any other recipients of the Work or 112 | Derivative Works a copy of this License; and 113 | 114 | (b) You must cause any modified files to carry prominent notices 115 | stating that You changed the files; and 116 | 117 | (c) You must retain, in the Source form of any Derivative Works 118 | that You distribute, all copyright, patent, trademark, and 119 | attribution notices from the Source form of the Work, 120 | excluding those notices that do not pertain to any part of 121 | the Derivative Works; and 122 | 123 | (d) If the Work includes a "NOTICE" text file as part of its 124 | distribution, then any Derivative Works that You distribute must 125 | include a readable copy of the attribution notices contained 126 | within such NOTICE file, excluding those notices that do not 127 | pertain to any part of the Derivative Works, in at least one 128 | of the following places: within a NOTICE text file distributed 129 | as part of the Derivative Works; within the Source form or 130 | documentation, if provided along with the Derivative Works; or, 131 | within a display generated by the Derivative Works, if and 132 | wherever such third-party notices normally appear. The contents 133 | of the NOTICE file are for informational purposes only and 134 | do not modify the License. You may add Your own attribution 135 | notices within Derivative Works that You distribute, alongside 136 | or as an addendum to the NOTICE text from the Work, provided 137 | that such additional attribution notices cannot be construed 138 | as modifying the License. 139 | 140 | You may add Your own copyright statement to Your modifications and 141 | may provide additional or different license terms and conditions 142 | for use, reproduction, or distribution of Your modifications, or 143 | for any such Derivative Works as a whole, provided Your use, 144 | reproduction, and distribution of the Work otherwise complies with 145 | the conditions stated in this License. 146 | 147 | 5. Submission of Contributions. Unless You explicitly state otherwise, 148 | any Contribution intentionally submitted for inclusion in the Work 149 | by You to the Licensor shall be under the terms and conditions of 150 | this License, without any additional terms or conditions. 151 | Notwithstanding the above, nothing herein shall supersede or modify 152 | the terms of any separate license agreement you may have executed 153 | with Licensor regarding such Contributions. 154 | 155 | 6. Trademarks. This License does not grant permission to use the trade 156 | names, trademarks, service marks, or product names of the Licensor, 157 | except as required for reasonable and customary use in describing the 158 | origin of the Work and reproducing the content of the NOTICE file. 159 | 160 | 7. Disclaimer of Warranty. Unless required by applicable law or 161 | agreed to in writing, Licensor provides the Work (and each 162 | Contributor provides its Contributions) on an "AS IS" BASIS, 163 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 164 | implied, including, without limitation, any warranties or conditions 165 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 166 | PARTICULAR PURPOSE. You are solely responsible for determining the 167 | appropriateness of using or redistributing the Work and assume any 168 | risks associated with Your exercise of permissions under this License. 169 | 170 | 8. Limitation of Liability. In no event and under no legal theory, 171 | whether in tort (including negligence), contract, or otherwise, 172 | unless required by applicable law (such as deliberate and grossly 173 | negligent acts) or agreed to in writing, shall any Contributor be 174 | liable to You for damages, including any direct, indirect, special, 175 | incidental, or consequential damages of any character arising as a 176 | result of this License or out of the use or inability to use the 177 | Work (including but not limited to damages for loss of goodwill, 178 | work stoppage, computer failure or malfunction, or any and all 179 | other commercial damages or losses), even if such Contributor 180 | has been advised of the possibility of such damages. 181 | 182 | 9. Accepting Warranty or Additional Liability. While redistributing 183 | the Work or Derivative Works thereof, You may choose to offer, 184 | and charge a fee for, acceptance of support, warranty, indemnity, 185 | or other liability obligations and/or rights consistent with this 186 | License. However, in accepting such obligations, You may act only 187 | on Your own behalf and on Your sole responsibility, not on behalf 188 | of any other Contributor, and only if You agree to indemnify, 189 | defend, and hold each Contributor harmless for any liability 190 | incurred by, or claims asserted against, such Contributor by reason 191 | of your accepting any such warranty or additional liability. 192 | 193 | END OF TERMS AND CONDITIONS 194 | 195 | APPENDIX: How to apply the Apache License to your work. 196 | 197 | To apply the Apache License to your work, attach the following 198 | boilerplate notice, with the fields enclosed by brackets "[]" 199 | replaced with your own identifying information. (Don't include 200 | the brackets!) The text should be enclosed in the appropriate 201 | comment syntax for the file format. We also recommend that a 202 | file or class name and description of purpose be included on the 203 | same "printed page" as the copyright notice for easier 204 | identification within third-party archives. 205 | 206 | Copyright [yyyy] [name of copyright owner] 207 | 208 | Licensed under the Apache License, Version 2.0 (the "License"); 209 | you may not use this file except in compliance with the License. 210 | You may obtain a copy of the License at 211 | 212 | http://www.apache.org/licenses/LICENSE-2.0 213 | 214 | Unless required by applicable law or agreed to in writing, software 215 | distributed under the License is distributed on an "AS IS" BASIS, 216 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 217 | See the License for the specific language governing permissions and 218 | limitations under the License. -------------------------------------------------------------------------------- /LICENSE.BSD3: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | * Neither the name of the nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /LICENSE.CC0: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. -------------------------------------------------------------------------------- /LICENSE.MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PeParser 2 | ========= 3 | 4 | ###### [![Dorkbox](https://badge.dorkbox.com/dorkbox.svg "Dorkbox")](https://git.dorkbox.com/dorkbox/PeParser) [![Github](https://badge.dorkbox.com/github.svg "Github")](https://github.com/dorkbox/PeParser) [![Gitlab](https://badge.dorkbox.com/gitlab.svg "Gitlab")](https://gitlab.com/dorkbox/PeParser) 5 | 6 | Provides a light-weight way to parse and extract data from windows PE files, from Java. 7 | 8 | This library can access meta-data information and details from within the PE file, and specifically it was designed to access and copy out files from the .rsrc section. 9 | 10 | Windows PE format and details: http://msdn.microsoft.com/en-us/library/ms809762.aspx 11 | 12 | - This is for cross-platform use, specifically - linux 32/64, mac 32/64, and windows 32/64. Java 8+ 13 | 14 | 15 |   16 |   17 | 18 | Maven Info 19 | --------- 20 | ``` 21 | 22 | ... 23 | 24 | com.dorkbox 25 | PeParser 26 | 3.3 27 | 28 | 29 | ``` 30 | 31 | Gradle Info 32 | --------- 33 | ``` 34 | dependencies { 35 | ... 36 | implementation("com.dorkbox:PeParser:3.3") 37 | } 38 | ``` 39 | 40 | Or if you don't want to use Maven, you can access the files directly here: 41 | https://repo1.maven.org/maven2/com/dorkbox/PeParser/ 42 | 43 | 44 | License 45 | --------- 46 | This project is © 2014 dorkbox llc, and is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further references. 47 | 48 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /////////////////////////////// 18 | ////// PUBLISH TO SONATYPE / MAVEN CENTRAL 19 | ////// TESTING : (to local maven repo) <'publish and release' - 'publishToMavenLocal'> 20 | ////// RELEASE : (to sonatype/maven central), <'publish and release' - 'publishToSonatypeAndRelease'> 21 | /////////////////////////////// 22 | 23 | gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS // always show the stacktrace! 24 | 25 | plugins { 26 | id("com.dorkbox.GradleUtils") version "3.18" 27 | id("com.dorkbox.Licensing") version "2.28" 28 | id("com.dorkbox.VersionUpdate") version "2.8" 29 | id("com.dorkbox.GradlePublish") version "1.20" 30 | 31 | kotlin("jvm") version "1.9.0" 32 | } 33 | 34 | object Extras { 35 | // set for the project 36 | const val description = "Windows PE (Portable Executable) file parser for Java 8+" 37 | const val group = "com.dorkbox" 38 | const val version = "3.3" 39 | 40 | // set as project.ext 41 | const val name = "PeParser" 42 | const val id = "PeParser" 43 | const val vendor = "Dorkbox LLC" 44 | const val vendorUrl = "https://dorkbox.com" 45 | const val url = "https://git.dorkbox.com/dorkbox/PeParser" 46 | } 47 | 48 | /////////////////////////////// 49 | ///// assign 'Extras' 50 | /////////////////////////////// 51 | GradleUtils.load("$projectDir/../../gradle.properties", Extras) 52 | GradleUtils.defaults() 53 | GradleUtils.compileConfiguration(JavaVersion.VERSION_1_8) 54 | GradleUtils.jpms(JavaVersion.VERSION_1_9) 55 | 56 | licensing { 57 | license(License.APACHE_2) { 58 | author(Extras.vendor) 59 | url(Extras.url) 60 | note(Extras.description) 61 | } 62 | } 63 | 64 | tasks.jar.get().apply { 65 | manifest { 66 | // https://docs.oracle.com/javase/tutorial/deployment/jar/packageman.html 67 | attributes["Name"] = Extras.name 68 | 69 | attributes["Specification-Title"] = Extras.name 70 | attributes["Specification-Version"] = Extras.version 71 | attributes["Specification-Vendor"] = Extras.vendor 72 | 73 | attributes["Implementation-Title"] = "${Extras.group}.${Extras.id}" 74 | attributes["Implementation-Version"] = GradleUtils.now() 75 | attributes["Implementation-Vendor"] = Extras.vendor 76 | 77 | attributes["Automatic-Module-Name"] = Extras.id 78 | } 79 | } 80 | 81 | dependencies { 82 | api("com.dorkbox:Collections:2.7") 83 | api("com.dorkbox:ByteUtilities:2.0") 84 | api("com.dorkbox:HexUtilities:1.1") 85 | api("com.dorkbox:Updates:1.1") 86 | api("com.dorkbox:Utilities:1.47") 87 | } 88 | 89 | publishToSonatype { 90 | groupId = Extras.group 91 | artifactId = Extras.id 92 | version = Extras.version 93 | 94 | name = Extras.name 95 | description = Extras.description 96 | url = Extras.url 97 | 98 | vendor = Extras.vendor 99 | vendorUrl = Extras.vendorUrl 100 | 101 | issueManagement { 102 | url = "${Extras.url}/issues" 103 | nickname = "Gitea Issues" 104 | } 105 | 106 | developer { 107 | id = "dorkbox" 108 | name = Extras.vendor 109 | email = "email@dorkbox.com" 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties 2 | org.gradle.jvmargs=-Dfile.encoding=UTF-8 3 | 4 | #org.gradle.warning.mode=(all,fail,none,summary) 5 | org.gradle.warning.mode=all 6 | 7 | #org.gradle.daemon=false 8 | # default is 3 hours, this is 1 minute 9 | org.gradle.daemon.idletimeout=60000 10 | 11 | #org.gradle.console=(auto,plain,rich,verbose) 12 | org.gradle.console=auto 13 | 14 | #org.gradle.logging.level=(quiet,warn,lifecycle,info,debug) 15 | org.gradle.logging.level=lifecycle 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dorkbox/PeParser/dae9521b4d5420e32b4a9e0015983868d856067e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | # Collect all arguments for the java command; 201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 202 | # shell script including quotes and variable substitutions, so put them in 203 | # double quotes to make sure that they get re-expanded; and 204 | # * put everything else in single quotes, so that it's not re-expanded. 205 | 206 | set -- \ 207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 208 | -classpath "$CLASSPATH" \ 209 | org.gradle.wrapper.GradleWrapperMain \ 210 | "$@" 211 | 212 | # Stop when "xargs" is not available. 213 | if ! command -v xargs >/dev/null 2>&1 214 | then 215 | die "xargs is not available" 216 | fi 217 | 218 | # Use "xargs" to parse quoted args. 219 | # 220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 221 | # 222 | # In Bash we could simply go: 223 | # 224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 225 | # set -- "${ARGS[@]}" "$@" 226 | # 227 | # but POSIX shell has neither arrays nor command substitution, so instead we 228 | # post-process each arg (as a line of input to sed) to backslash-escape any 229 | # character that might be a shell metacharacter, then use eval to reverse 230 | # that process (while maintaining the separation between arguments), and wrap 231 | # the whole thing up as a single "set" statement. 232 | # 233 | # This will of course break if any of these variables contains a newline or 234 | # an unmatched quote. 235 | # 236 | 237 | eval "set -- $( 238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 239 | xargs -n1 | 240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 241 | tr '\n' ' ' 242 | )" '"$@"' 243 | 244 | exec "$JAVACMD" "$@" 245 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | rootProject.name = "PeParser" 17 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/ByteArray.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser 17 | 18 | import dorkbox.bytes.LittleEndian 19 | import java.io.ByteArrayInputStream 20 | import kotlin.ByteArray 21 | import kotlin.text.Charsets.US_ASCII 22 | 23 | class ByteArray(bytes: ByteArray?) : ByteArrayInputStream(bytes) { 24 | fun readAsciiString(length: Int): String { 25 | // pos is incremented by the copy bytes method 26 | return String(copyBytes(length), US_ASCII).trim { it <= ' ' } 27 | } 28 | 29 | fun readULong(length: Int): ULong { 30 | val result: ULong = LittleEndian.ULong_.from(buf, pos, length) 31 | pos += length 32 | return result 33 | } 34 | 35 | fun readUInt(length: Int): UInt { 36 | val result: UInt = LittleEndian.UInt_.from(buf, pos, length) 37 | pos += length 38 | return result 39 | } 40 | 41 | fun readUShort(length: Int): UShort { 42 | val result: UShort = LittleEndian.UShort_.from(buf, pos, length) 43 | pos += length 44 | return result 45 | } 46 | 47 | fun readUByte(): UByte { 48 | val b: UByte = buf[pos].toUByte() 49 | pos++ 50 | return b 51 | } 52 | 53 | fun readRaw(offset: Int): Byte { 54 | return buf[pos + offset] 55 | } 56 | 57 | fun copyBytes(length: Int): ByteArray { 58 | val data = ByteArray(length) 59 | super.read(data, 0, length) 60 | return data 61 | } 62 | 63 | fun mark() { 64 | super.mark(0) 65 | } 66 | 67 | fun seek(position: Int) { 68 | pos = position 69 | } 70 | 71 | fun position(): Int { 72 | return pos 73 | } 74 | 75 | fun marked(): Int { 76 | return mark 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/DataLocation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser 17 | 18 | data class DataLocation(val location: Int, val size: Int) 19 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/PE.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser 18 | 19 | import dorkbox.os.OS 20 | import dorkbox.peParser.headers.* 21 | import dorkbox.peParser.headers.resources.ResourceDataEntry 22 | import dorkbox.peParser.headers.resources.ResourceDirectoryEntry 23 | import dorkbox.peParser.headers.resources.ResourceDirectoryHeader 24 | import dorkbox.peParser.misc.DirEntry 25 | import dorkbox.updates.Updates.add 26 | import java.io.* 27 | import java.util.* 28 | 29 | class PE { 30 | companion object { 31 | // info from: 32 | // http://evilzone.org/tutorials/(paper)-portable-executable-format-and-its-rsrc-section/ 33 | // http://www.skynet.ie/~caolan/pub/winresdump/winresdump/doc/pefile.html (older version of the doc...) 34 | // http://www.csn.ul.ie/~caolan/pub/winresdump/winresdump/doc/pefile2.html 35 | // http://msdn.microsoft.com/en-us/library/ms809762.aspx 36 | 37 | /** 38 | * Gets the version number. 39 | */ 40 | val version = "3.3" 41 | private const val PE_OFFSET_LOCATION = 0x3c 42 | private val PE_SIG = "PE\u0000\u0000".toByteArray() 43 | 44 | init { 45 | // Add this project to the updates system, which verifies this class + UUID + version information 46 | add(PE::class.java, "5f5fafe156ba4e8f94c28f0c283aa509", version) 47 | } 48 | 49 | @Throws(Exception::class) 50 | fun getVersion(executablePath: String): String? { 51 | val pe = PE(executablePath) 52 | if (pe.invalidFile) { 53 | throw Exception("No version found:$executablePath") 54 | } 55 | for (mainEntry in pe.optionalHeader!!.tables) { 56 | if (mainEntry.type === DirEntry.RESOURCE) { 57 | val root = mainEntry.data as ResourceDirectoryHeader? 58 | for (rootEntry in root!!.entries) { 59 | if ("Version" == rootEntry!!.NAME!!.get()) { 60 | val versionInfoData = rootEntry.directory!!.entries[0]!!.directory!!.entries[0]!!.resourceDataEntry!!.getData( 61 | pe.fileBytes!! 62 | ) 63 | val fileVersionIndex = indexOf(versionInfoData, includeNulls("FileVersion")) + 26 64 | val fileVersionEndIndex = indexOf(versionInfoData, byteArrayOf(0x00, 0x00), fileVersionIndex) 65 | return removeNulls(String(versionInfoData, fileVersionIndex, fileVersionEndIndex - fileVersionIndex)) 66 | } 67 | } 68 | } 69 | } 70 | throw Exception("No version found:$executablePath") 71 | } 72 | 73 | private fun includeNulls(str: String): kotlin.ByteArray { 74 | val chars = str.toCharArray() 75 | val result = ByteArray(chars.size * 2) 76 | var i = 0 77 | var j = 0 78 | while (i < result.size) { 79 | result[i] = chars[j].code.toByte() 80 | i += 2 81 | j++ 82 | } 83 | return result 84 | } 85 | 86 | private fun removeNulls(str: String?): String? { 87 | return str?.replace("\\x00".toRegex(), "") 88 | } 89 | 90 | fun indexOf(outerArray: kotlin.ByteArray, smallerArray: kotlin.ByteArray, begin: Int = 0): Int { 91 | for (i in begin until outerArray.size - smallerArray.size + 1) { 92 | var found = true 93 | for (j in smallerArray.indices) { 94 | if (outerArray[i + j] != smallerArray[j]) { 95 | found = false 96 | break 97 | } 98 | } 99 | if (found) { 100 | return i 101 | } 102 | } 103 | return -1 104 | } 105 | } 106 | 107 | // TODO: should use an input stream to load header info, instead of the entire thing! 108 | var fileBytes: ByteArray? = null 109 | private var coffHeader: COFFFileHeader? = null 110 | var optionalHeader: OptionalHeader? = null 111 | private var sectionTable: SectionTable? = null 112 | private var invalidFile = false 113 | 114 | constructor(fileName: String) { 115 | val file = File(fileName) 116 | try { 117 | val fileInputStream = FileInputStream(file) 118 | fromInputStream(fileInputStream) 119 | } 120 | catch (e: FileNotFoundException) { 121 | e.printStackTrace() 122 | } 123 | catch (e: IOException) { 124 | e.printStackTrace() 125 | } 126 | } 127 | 128 | constructor(inputStream: InputStream) { 129 | try { 130 | fromInputStream(inputStream) 131 | } 132 | catch (e: FileNotFoundException) { 133 | e.printStackTrace() 134 | } 135 | catch (e: IOException) { 136 | e.printStackTrace() 137 | } 138 | } 139 | 140 | @Throws(FileNotFoundException::class, IOException::class) 141 | private fun fromInputStream(inputStream: InputStream) { 142 | val baos = ByteArrayOutputStream(8192) 143 | val buffer = ByteArray(4096) 144 | 145 | var read: Int 146 | while (inputStream.read(buffer).also { read = it } > 0) { 147 | baos.write(buffer, 0, read) 148 | } 149 | 150 | baos.flush() 151 | inputStream.close() 152 | 153 | val bytes = baos.toByteArray() 154 | invalidFile = bytes.size == 0 155 | fileBytes = ByteArray(bytes) 156 | 157 | // initialize header info 158 | if (isPE) { 159 | val offset = PEOffset + PE_SIG.size 160 | fileBytes!!.seek(offset) 161 | coffHeader = COFFFileHeader(fileBytes!!) 162 | optionalHeader = OptionalHeader(fileBytes!!) 163 | val numberOfEntries: Int = coffHeader!!.NumberOfSections!!.get().toInt() 164 | sectionTable = SectionTable(fileBytes!!, numberOfEntries) 165 | 166 | // now the bytes are positioned at the start of the section table. ALl other info MUST be done relative to byte offsets/locations! 167 | 168 | // fixup directory names -> table names (from spec!) 169 | for (section in sectionTable!!.sections) { 170 | val sectionAddress: Long = section.VIRTUAL_ADDRESS.get().toLong() 171 | val sectionSize: Long = section.SIZE_OF_RAW_DATA.get().toLong() 172 | for (entry in optionalHeader!!.tables) { 173 | val optionAddress: Long = entry.get().toLong() 174 | if (sectionAddress <= optionAddress && sectionAddress + sectionSize > optionAddress) { 175 | entry.section = section 176 | break 177 | } 178 | } 179 | } 180 | 181 | // fixup directories 182 | for (entry in optionalHeader!!.tables) { 183 | if (entry.type === DirEntry.RESOURCE) { 184 | // fixup resources 185 | val section = entry.section 186 | if (section != null) { 187 | val delta: Long = section.VIRTUAL_ADDRESS.get().toLong() - section.POINTER_TO_RAW_DATA.get().toLong() 188 | val offsetInFile: Long = entry.get().toLong() - delta 189 | if (offsetInFile > Int.MAX_VALUE) { 190 | throw RuntimeException("Unable to set offset to more than 2gb!") 191 | } 192 | fileBytes!!.seek(offsetInFile.toInt()) 193 | fileBytes!!.mark() // resource data is offset from the beginning of the header! 194 | val root: Header = ResourceDirectoryHeader(fileBytes!!, section, 0) 195 | entry.data = root 196 | } 197 | } 198 | } 199 | } 200 | } 201 | 202 | val info: String 203 | get() = if (isPE) { 204 | val b = StringBuilder() 205 | b.append("PE signature offset: ").append(PEOffset).append(OS.LINE_SEPARATOR).append("PE signature correct: ").append("yes") 206 | .append(OS.LINE_SEPARATOR).append(OS.LINE_SEPARATOR).append("----------------").append(OS.LINE_SEPARATOR).append("COFF header info") 207 | .append(OS.LINE_SEPARATOR).append("----------------").append(OS.LINE_SEPARATOR) 208 | for (bd in coffHeader!!.headers) { 209 | bd.format(b) 210 | } 211 | b.append(OS.LINE_SEPARATOR) 212 | b.append("--------------------").append(OS.LINE_SEPARATOR).append("Optional header info").append(OS.LINE_SEPARATOR) 213 | .append("--------------------").append(OS.LINE_SEPARATOR) 214 | for (bd in optionalHeader!!.headers) { 215 | bd.format(b) 216 | } 217 | b.append(OS.LINE_SEPARATOR) 218 | b.append(OS.LINE_SEPARATOR).append("-------------").append(OS.LINE_SEPARATOR).append("Section Table").append(OS.LINE_SEPARATOR) 219 | .append("-------------").append(OS.LINE_SEPARATOR).append(OS.LINE_SEPARATOR) 220 | for (section in sectionTable!!.sections) { 221 | for (bd in section.headers) { 222 | bd.format(b) 223 | } 224 | } 225 | b.append(OS.LINE_SEPARATOR) 226 | b.toString() 227 | } 228 | else { 229 | "PE signature not found. The given file is not a PE file. $OS.LINE_SEPARATOR" 230 | } 231 | private val PEOffset: Int 232 | get() { 233 | fileBytes!!.mark() 234 | fileBytes!!.seek(PE_OFFSET_LOCATION) 235 | val read: Int = fileBytes!!.readUShort(2).toInt() 236 | fileBytes!!.reset() 237 | return read 238 | } 239 | val isPE: Boolean 240 | get() { 241 | if (invalidFile) { 242 | return false 243 | } 244 | var saved = -1 245 | return try { 246 | // this can screw up if the length of the file is invalid... 247 | val offset = PEOffset 248 | saved = fileBytes!!.position() 249 | 250 | // always have to start from zero if we ask this. 251 | fileBytes!!.seek(0) 252 | for (i in PE_SIG.indices) { 253 | if (fileBytes!!.readRaw(offset + i) != PE_SIG[i]) { 254 | return false 255 | } 256 | } 257 | true 258 | } 259 | catch (e: Exception) { 260 | false 261 | } 262 | finally { 263 | if (saved != -1) { 264 | fileBytes!!.seek(saved) 265 | } 266 | } 267 | } 268 | val largestResourceAsStream: ByteArrayInputStream? 269 | get() { 270 | for (mainEntry in optionalHeader!!.tables) { 271 | if (mainEntry.type === DirEntry.RESOURCE) { 272 | val directoryEntries = LinkedList() 273 | val resourceEntries = LinkedList() 274 | val root = mainEntry.data as ResourceDirectoryHeader? 275 | 276 | for (rootEntry in root!!.entries) { 277 | collect(directoryEntries, resourceEntries, rootEntry) 278 | directoryEntries.add(rootEntry) 279 | } 280 | 281 | var entry: ResourceDirectoryEntry? 282 | while (directoryEntries.poll().also { entry = it } != null) { 283 | collect(directoryEntries, resourceEntries, entry) 284 | } 285 | 286 | var largest: ResourceDataEntry? = null 287 | for (resourceEntry in resourceEntries) { 288 | val dataEntry = resourceEntry!!.resourceDataEntry 289 | if (largest == null || largest.SIZE.get().toLong() < dataEntry!!.SIZE.get().toLong()) { 290 | largest = dataEntry 291 | } 292 | } 293 | 294 | // now return our resource, but it has to be wrapped in a new stream! 295 | return ByteArrayInputStream(largest!!.getData(fileBytes!!)) 296 | } 297 | } 298 | return null 299 | } 300 | 301 | private fun collect( 302 | directoryEntries: LinkedList, 303 | resourceEntries: LinkedList, 304 | entry: ResourceDirectoryEntry? 305 | ) { 306 | if (entry!!.isDirectory) { 307 | for (dirEntry in entry.directory!!.entries) { 308 | directoryEntries.add(dirEntry) 309 | } 310 | } 311 | else { 312 | resourceEntries.add(entry) 313 | } 314 | } 315 | 316 | 317 | } 318 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/COFFFileHeader.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers 17 | 18 | import dorkbox.peParser.ByteArray 19 | import dorkbox.peParser.types.* 20 | 21 | class COFFFileHeader(bytes: ByteArray) : Header() { 22 | companion object { 23 | // see: http://msdn.microsoft.com/en-us/library/ms809762.aspx 24 | const val HEADER_SIZE = 20 25 | } 26 | 27 | /** The CPU that this file is intended for */ 28 | val Machine: MachineType? 29 | 30 | /** The number of sections in the file. */ 31 | val NumberOfSections: WORD? 32 | 33 | /** 34 | * The time that the linker (or compiler for an OBJ file) produced this file. This field holds the number of seconds since December 35 | * 31st, 1969, at 4:00 P.M. (PST) 36 | */ 37 | val TimeDateStamp: TimeDate? 38 | 39 | /** 40 | * The file offset of the COFF symbol table. This field is only used in OBJ files and PE files with COFF debug information. PE files 41 | * support multiple debug formats, so debuggers should refer to the IMAGE_DIRECTORY_ENTRY_DEBUG entry in the data directory (defined 42 | * later). 43 | */ 44 | val PointerToSymbolTable: DWORD? 45 | 46 | /** The number of symbols in the COFF symbol table. See above. */ 47 | val NumberOfSymbols: DWORD? 48 | 49 | /** 50 | * The size of an optional header that can follow this structure. In OBJs, the field is 0. In executables, it is the size of the 51 | * IMAGE_OPTIONAL_HEADER structure that follows this structure. 52 | */ 53 | val SizeOfOptionalHeader: WORD? 54 | 55 | /** Flags with information about the file. */ 56 | val Characteristics: CoffCharacteristics? 57 | 58 | init { 59 | Machine = h(MachineType(bytes.readUShort(2), "machine type")) 60 | NumberOfSections = h(WORD(bytes.readUShort(2), "number of sections")) 61 | TimeDateStamp = h(TimeDate(bytes.readUInt(4), "time date stamp")) 62 | PointerToSymbolTable = h(DWORD(bytes.readUInt(4), "pointer to symbol table")) 63 | NumberOfSymbols = h(DWORD(bytes.readUInt(4), "number of symbols")) 64 | SizeOfOptionalHeader = h(WORD(bytes.readUShort(2), "size of optional header")) 65 | Characteristics = h(CoffCharacteristics(bytes.readUShort(2), "characteristics")) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/Header.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers 17 | 18 | import dorkbox.peParser.types.ByteDefinition 19 | 20 | open class Header { 21 | var headers: MutableList> = ArrayList(0) 22 | protected fun ?> h(`object`: T): T { 23 | headers.add(`object`!!) 24 | return `object` 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/OptionalHeader.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers 17 | 18 | import dorkbox.peParser.ByteArray 19 | import dorkbox.peParser.misc.DirEntry 20 | import dorkbox.peParser.misc.MagicNumberType 21 | import dorkbox.peParser.types.* 22 | 23 | class OptionalHeader(bytes: ByteArray) : Header() { 24 | // see: http://msdn.microsoft.com/en-us/library/ms809762.aspx 25 | var tables: MutableList = ArrayList(0) 26 | 27 | // 28 | // Standard fields. 29 | // 30 | val MAGIC_NUMBER: MagicNumber? 31 | val MAJOR_LINKER_VERSION: WORD? 32 | val MINOR_LINKER_VERSION: WORD? 33 | val SIZE_OF_CODE: DWORD? 34 | val SIZE_OF_INIT_DATA: DWORD? 35 | val SIZE_OF_UNINIT_DATA: DWORD? 36 | val ADDR_OF_ENTRY_POINT: DWORD? 37 | val BASE_OF_CODE: DWORD? 38 | val BASE_OF_DATA: DWORD? 39 | private val IS_32_BIT: Boolean 40 | 41 | // 42 | // NT additional fields. 43 | // 44 | var IMAGE_BASE: ByteDefinition<*>? = null 45 | val SECTION_ALIGNMENT: DWORD? 46 | val FILE_ALIGNMENT: DWORD? 47 | val MAJOR_OS_VERSION: WORD? 48 | val MINOR_OS_VERSION: WORD? 49 | val MAJOR_IMAGE_VERSION: WORD? 50 | val MINOR_IMAGE_VERSION: WORD? 51 | val MAJOR_SUBSYSTEM_VERSION: WORD? 52 | val MINOR_SUBSYSTEM_VERSION: WORD? 53 | val WIN32_VERSION_VALUE: DWORD? 54 | val SIZE_OF_IMAGE: DWORD? 55 | val SIZE_OF_HEADERS: DWORD? 56 | val CHECKSUM: DWORD? 57 | val SUBSYSTEM: Subsystem? 58 | val DLL_CHARACTERISTICS: DllCharacteristics? 59 | var SIZE_OF_STACK_RESERVE: ByteDefinition<*>? = null 60 | var SIZE_OF_STACK_COMMIT: ByteDefinition<*>? = null 61 | var SIZE_OF_HEAP_RESERVE: ByteDefinition<*>? = null 62 | var SIZE_OF_HEAP_COMMIT: ByteDefinition<*>? = null 63 | val LOADER_FLAGS: DWORD? 64 | val NUMBER_OF_RVA_AND_SIZES: RVA? 65 | val EXPORT_TABLE: ImageDataDir? 66 | val IMPORT_TABLE: ImageDataDir? 67 | val RESOURCE_TABLE: ImageDataDir? 68 | val EXCEPTION_TABLE: ImageDataDir? 69 | val CERTIFICATE_TABLE: ImageDataDir? 70 | val BASE_RELOCATION_TABLE: ImageDataDir? 71 | val DEBUG: ImageDataDir? 72 | val COPYRIGHT: ImageDataDir? 73 | val GLOBAL_PTR: ImageDataDir? 74 | val TLS_TABLE: ImageDataDir? 75 | val LOAD_CONFIG_TABLE: ImageDataDir? 76 | val BOUND_IMPORT: ImageDataDirExtra? 77 | val IAT: ImageDataDirExtra? 78 | val DELAY_IMPORT_DESCRIPTOR: ImageDataDirExtra? 79 | val CLR_RUNTIME_HEADER: ImageDataDirExtra? 80 | 81 | init { 82 | // the header length is variable. 83 | 84 | // 85 | // Standard fields. 86 | // 87 | h(HeaderDefinition("Standard fields")) 88 | bytes.mark() 89 | MAGIC_NUMBER = h(MagicNumber(bytes.readUShort(2), "magic number")) 90 | MAJOR_LINKER_VERSION = h(WORD(bytes.readUShort(1), "major linker version")) 91 | MINOR_LINKER_VERSION = h(WORD(bytes.readUShort(1), "minor linker version")) 92 | SIZE_OF_CODE = h(DWORD(bytes.readUInt(4), "size of code")) 93 | SIZE_OF_INIT_DATA = h(DWORD(bytes.readUInt(4), "size of initialized data")) 94 | SIZE_OF_UNINIT_DATA = h(DWORD(bytes.readUInt(4), "size of unitialized data")) 95 | ADDR_OF_ENTRY_POINT = h(DWORD(bytes.readUInt(4), "address of entry point")) 96 | BASE_OF_CODE = h(DWORD(bytes.readUInt(4), "address of base of code")) 97 | BASE_OF_DATA = h(DWORD(bytes.readUInt(4), "address of base of data")) 98 | IS_32_BIT = MAGIC_NUMBER.get() === MagicNumberType.PE32 99 | bytes.reset() 100 | if (IS_32_BIT) { 101 | bytes.skip(28) 102 | } 103 | else { 104 | bytes.skip(24) 105 | } 106 | 107 | 108 | // 109 | // Standard fields. 110 | // 111 | h(HeaderDefinition("Windows specific fields")) 112 | if (IS_32_BIT) { 113 | IMAGE_BASE = h(ImageBase(bytes.readUInt(4), "image base")) 114 | } 115 | else { 116 | IMAGE_BASE = h(ImageBase_Wide(bytes.readULong(8), "image base")) 117 | } 118 | SECTION_ALIGNMENT = h(DWORD(bytes.readUInt(4), "section alignment in bytes")) 119 | FILE_ALIGNMENT = h(DWORD(bytes.readUInt(4), "file alignment in bytes")) 120 | MAJOR_OS_VERSION = h(WORD(bytes.readUShort(2), "major operating system version")) 121 | MINOR_OS_VERSION = h(WORD(bytes.readUShort(2), "minor operating system version")) 122 | MAJOR_IMAGE_VERSION = h(WORD(bytes.readUShort(2), "major image version")) 123 | MINOR_IMAGE_VERSION = h(WORD(bytes.readUShort(2), "minor image version")) 124 | MAJOR_SUBSYSTEM_VERSION = h(WORD(bytes.readUShort(2), "major subsystem version")) 125 | MINOR_SUBSYSTEM_VERSION = h(WORD(bytes.readUShort(2), "minor subsystem version")) 126 | WIN32_VERSION_VALUE = h(DWORD(bytes.readUInt(4), "win32 version value (reserved, must be zero)")) 127 | SIZE_OF_IMAGE = h(DWORD(bytes.readUInt(4), "size of image in bytes")) 128 | SIZE_OF_HEADERS = h(DWORD(bytes.readUInt(4), "size of headers (MS DOS stub, PE header, and section headers)")) 129 | CHECKSUM = h(DWORD(bytes.readUInt(4), "checksum")) 130 | SUBSYSTEM = h(Subsystem(bytes.readUShort(2), "subsystem")) 131 | DLL_CHARACTERISTICS = h(DllCharacteristics(bytes.readUShort(2), "dll characteristics")) 132 | if (IS_32_BIT) { 133 | SIZE_OF_STACK_RESERVE = h(DWORD(bytes.readUInt(4), "size of stack reserve")) 134 | SIZE_OF_STACK_COMMIT = h(DWORD(bytes.readUInt(4), "size of stack commit")) 135 | SIZE_OF_HEAP_RESERVE = h(DWORD(bytes.readUInt(4), "size of heap reserve")) 136 | SIZE_OF_HEAP_COMMIT = h(DWORD(bytes.readUInt(4), "size of heap commit")) 137 | } 138 | else { 139 | SIZE_OF_STACK_RESERVE = h(DWORD_WIDE(bytes.readULong(8), "size of stack reserve")) 140 | SIZE_OF_STACK_COMMIT = h(DWORD_WIDE(bytes.readULong(8), "size of stack commit")) 141 | SIZE_OF_HEAP_RESERVE = h(DWORD_WIDE(bytes.readULong(8), "size of heap reserve")) 142 | SIZE_OF_HEAP_COMMIT = h(DWORD_WIDE(bytes.readULong(8), "size of heap commit")) 143 | } 144 | LOADER_FLAGS = h(DWORD(bytes.readUInt(4), "loader flags (reserved, must be zero)")) 145 | NUMBER_OF_RVA_AND_SIZES = h(RVA(bytes.readUInt(4), "number of rva and sizes")) 146 | bytes.reset() 147 | if (IS_32_BIT) { 148 | bytes.skip(96) 149 | } 150 | else { 151 | bytes.skip(112) 152 | } 153 | 154 | // 155 | // Data directories 156 | // 157 | h(HeaderDefinition("Data Directories")) 158 | EXPORT_TABLE = table(h(ImageDataDir(bytes, DirEntry.EXPORT))) 159 | IMPORT_TABLE = table(h(ImageDataDir(bytes, DirEntry.IMPORT))) 160 | RESOURCE_TABLE = table(h(ImageDataDir(bytes, DirEntry.RESOURCE))) 161 | EXCEPTION_TABLE = table(h(ImageDataDir(bytes, DirEntry.EXCEPTION))) 162 | CERTIFICATE_TABLE = table(h(ImageDataDir(bytes, DirEntry.SECURITY))) 163 | BASE_RELOCATION_TABLE = table(h(ImageDataDir(bytes, DirEntry.BASERELOC))) 164 | DEBUG = table(h(ImageDataDir(bytes, DirEntry.DEBUG))) 165 | COPYRIGHT = table(h(ImageDataDir(bytes, DirEntry.COPYRIGHT))) 166 | GLOBAL_PTR = table(h(ImageDataDir(bytes, DirEntry.GLOBALPTR))) 167 | TLS_TABLE = table(h(ImageDataDir(bytes, DirEntry.TLS))) 168 | LOAD_CONFIG_TABLE = table(h(ImageDataDir(bytes, DirEntry.LOAD_CONFIG))) 169 | BOUND_IMPORT = h(ImageDataDirExtra(bytes, "bound import")) 170 | IAT = h(ImageDataDirExtra(bytes, "IAT")) 171 | DELAY_IMPORT_DESCRIPTOR = h(ImageDataDirExtra(bytes, "delay import descriptor")) 172 | CLR_RUNTIME_HEADER = h(ImageDataDirExtra(bytes, "COM+ runtime header")) 173 | 174 | // reserved 8 bytes!! 175 | bytes.skip(8) 176 | } 177 | 178 | private fun table(`object`: T): T { 179 | tables.add(`object`) 180 | return `object` 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/SectionTable.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers 17 | 18 | import dorkbox.peParser.ByteArray 19 | 20 | class SectionTable(bytes: ByteArray, numberOfEntries: Int) : Header() { 21 | // more info here: http://msdn.microsoft.com/en-us/library/ms809762.aspx 22 | var sections: MutableList 23 | 24 | init { 25 | sections = ArrayList(numberOfEntries) 26 | bytes.mark() 27 | for (i in 0 until numberOfEntries) { 28 | val offset: Int = i * SectionTableEntry.ENTRY_SIZE // 40 bytes per table entry, no spacing between them 29 | bytes.skip(offset.toLong()) 30 | 31 | val sectionTableEntry = SectionTableEntry(bytes, i + 1, offset, SectionTableEntry.ENTRY_SIZE) 32 | sections.add(sectionTableEntry) 33 | bytes.reset() 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/SectionTableEntry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers 17 | 18 | import dorkbox.peParser.ByteArray 19 | import dorkbox.peParser.types.* 20 | 21 | class SectionTableEntry(bytes: ByteArray, entryNumber: Int, offset: Int, size: Int) : Header() { 22 | companion object { 23 | // more info here: http://msdn.microsoft.com/en-us/library/ms809762.aspx 24 | const val ENTRY_SIZE = 40 25 | } 26 | 27 | val NAME: AsciiString 28 | val VIRTUAL_SIZE: DWORD 29 | val VIRTUAL_ADDRESS: DWORD 30 | val SIZE_OF_RAW_DATA: DWORD 31 | val POINTER_TO_RAW_DATA: DWORD 32 | val POINTER_TO_RELOCATIONS: DWORD 33 | val POINTER_TO_LINE_NUMBERS: DWORD 34 | val NUMBER_OF_RELOCATIONS: WORD 35 | val NUMBER_OF_LINE_NUMBERS: WORD 36 | val CHARACTERISTICS: SectionCharacteristics 37 | 38 | init { 39 | h(HeaderDefinition("Section table entry: $entryNumber")) 40 | NAME = h(AsciiString(bytes, 8, "name")) 41 | VIRTUAL_SIZE = h(DWORD(bytes.readUInt(4), "virtual size")) 42 | VIRTUAL_ADDRESS = h(DWORD(bytes.readUInt(4), "virtual address")) 43 | SIZE_OF_RAW_DATA = h(DWORD(bytes.readUInt(4), "size of raw data")) 44 | POINTER_TO_RAW_DATA = h(DWORD(bytes.readUInt(4), "pointer to raw data")) 45 | POINTER_TO_RELOCATIONS = h(DWORD(bytes.readUInt(4), "pointer to relocations")) 46 | POINTER_TO_LINE_NUMBERS = h(DWORD(bytes.readUInt(4), "pointer to line numbers")) 47 | NUMBER_OF_RELOCATIONS = h(WORD(bytes.readUShort(2), "number of relocations")) 48 | NUMBER_OF_LINE_NUMBERS = h(WORD(bytes.readUShort(2), "number of line numbers")) 49 | CHARACTERISTICS = h(SectionCharacteristics(bytes.readUInt(4), "characteristics")) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/flags/Characteristics.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers.flags 17 | 18 | enum class Characteristics(private val hexValue: String, val description: String) { 19 | IMAGE_FILE_RELOCS_STRIPPED("1", "Resource information is stripped from the file"), 20 | IMAGE_FILE_EXECUTABLE_IMAGE("2", "The file is executable (no unresoled external references"), 21 | IMAGE_FILE_LINE_NUMS_STRIPPED("4", "COFF line numbers are stripped from the file (DEPRECATED)"), 22 | IMAGE_FILE_LOCAL_SYMS_STRIPPED("8", "COFF local symbols are stripped form the file (DEPRECATED)"), 23 | IMAGE_FILE_AGGRESSIVE_WS_TRIM("10", "Aggressively trim working set (DEPRECATED for Windows 2000 and later)" ), 24 | IMAGE_FILE_LARGE_ADDRESS_AWARE("20", "Application can handle larger than 2 GB addresses."), 25 | IMAGE_FILE_RESERVED("40", "Use of this flag is reserved."), 26 | IMAGE_FILE_BYTES_REVERSED_LO("80", "Bytes of the word are reversed (REVERSED LO)"), 27 | IMAGE_FILE_32BIT_MACHINE("100", "Machine is based on a 32-bit-word architecture."), 28 | IMAGE_FILE_DEBUG_STRIPPED("200", "Debugging is removed from the file."), 29 | IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP("400", "If the image is on removable media, fully load it and copy it to the swap file."), 30 | IMAGE_FILE_NET_RUN_FROM_SWAP("800", "If the image is on network media, fully load it and copy it to the swap file."), 31 | IMAGE_FILE_SYSTEM("1000", "The image file is a system file, (such as a driver) and not a user program."), 32 | IMAGE_FILE_DLL("2000", "The image file is a dynamic-link library (DLL). Such files are considered executable files for almost all purposes, although they cannot be directly run."), 33 | IMAGE_FILE_UP_SYSTEM_ONLY("4000", "The file should be run only on a uniprocessor machine."), 34 | IMAGE_FILE_BYTES_REVERSED_HI("8000", "Bytes of the word are reversed (REVERSED HI)"); 35 | 36 | companion object { 37 | operator fun get(key: UShort): Array { 38 | // byte[] value = Arrays.copyOfRange(headerbytes, byteDefinition.getByteStart(), byteDefinition.getByteStart() + byteDefinition.getLength()); 39 | // int key = LittleEndian.Int_.fromBytes(value[0], value[1], (byte)0, (byte)0); 40 | 41 | val chars: MutableList = ArrayList(0) 42 | val keyAsInt: Int = key.toInt() 43 | 44 | for (c in values()) { 45 | val mask = c.hexValue.toLong(16) 46 | if (keyAsInt.toLong() and mask != 0L) { 47 | chars.add(c) 48 | } 49 | } 50 | return chars.toTypedArray() 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/flags/DllCharacteristicsType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers.flags 17 | 18 | enum class DllCharacteristicsType(private val hexValue: String, val description: String) { 19 | IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE("40", "DLL can be relocated at load time."), 20 | IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY("80", "Code Integrity checks are enforced."), 21 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT("100", "Image is NX compatible."), 22 | IMAGE_DLL_CHARACTERISTICS_ISOLATION("200", "Isolation aware, but do not isolate the image."), 23 | IMAGE_DLLCHARACTERISTICS_NO_SEH("400", "Does not use structured exception (SE) handling. No SE handler may be called in this image."), 24 | IMAGE_DLLCHARACTERISTICS_NO_BIND("800", "Do not bind the image."), 25 | IMAGE_DLLCHARACTERISTICS_WDM_DRIVER("2000", "A WDM driver."), 26 | IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE("8000", "Terminal Server aware."); 27 | 28 | companion object { 29 | operator fun get(key: UShort): Array { 30 | val chars: MutableList = ArrayList(0) 31 | val keyAsInt: Int = key.toInt() 32 | for (c in values()) { 33 | val mask = c.hexValue.toLong(16) 34 | if (keyAsInt.toLong() and mask != 0L) { 35 | chars.add(c) 36 | } 37 | } 38 | return chars.toTypedArray() 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/flags/SectionCharacteristicsType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers.flags 17 | 18 | enum class SectionCharacteristicsType(private val hexValue: String, val description: String) { 19 | IMAGE_SCN_TYPE_NO_PAD("8", "The section should not be padded to the next boundary. DEPRECATED"), 20 | IMAGE_SCN_CNT_CODE("20", "The section contains executable code."), 21 | IMAGE_SCN_CNT_INITIALIZED_DATA("40", "The section contains initialized data."), 22 | IMAGE_SCN_CNT_UNINITIALIZED_DATA("80", "The section contains uninitialized data."), 23 | IMAGE_SCN_LNK_INFO("200", "The section contains comments or other information. Valid for object files only."), 24 | IMAGE_SCN_LNK_REMOVE("800", "The section will not become part of the image. Valid for object files only."), 25 | IMAGE_SCN_LNK_COMDAT("1000", "The section contains COMDAT data."), 26 | IMAGE_SCN_GPREL("8000", "The section contains data referenced through the global pointer (GP)."), 27 | IMAGE_SCN_MEM_16BIT("20000", "For ARM machine types, the section contains Thumb code."), 28 | IMAGE_SCN_ALIGN_1BYTES("100000", "Align data on a 1-byte boundary. Valid only for object files."), 29 | IMAGE_SCN_ALIGN_2BYTES("200000", "Align data on a 2-byte boundary. Valid only for object files."), 30 | IMAGE_SCN_ALIGN_4BYTES("300000", "Align data on a 4-byte boundary. Valid only for object files."), 31 | IMAGE_SCN_ALIGN_8BYTES("400000", "Align data on a 8-byte boundary. Valid only for object files."), 32 | IMAGE_SCN_ALIGN_16BYTES("500000", "Align data on a 16-byte boundary. Valid only for object files."), 33 | IMAGE_SCN_ALIGN_32BYTES("600000", "Align data on a 32-byte boundary. Valid only for object files."), 34 | IMAGE_SCN_ALIGN_64BYTES("700000", "Align data on a 64-byte boundary. Valid only for object files."), 35 | IMAGE_SCN_ALIGN_128BYTES("800000", "Align data on a 128-byte boundary. Valid only for object files."), 36 | IMAGE_SCN_ALIGN_256BYTES("900000", "Align data on a 256-byte boundary. Valid only for object files."), 37 | IMAGE_SCN_ALIGN_512BYTES("A00000", "Align data on a 512-byte boundary. Valid only for object files."), 38 | IMAGE_SCN_ALIGN_1024BYTES("B00000", "Align data on a 1024-byte boundary. Valid only for object files."), 39 | IMAGE_SCN_ALIGN_2048BYTES("C00000", "Align data on a 2048-byte boundary. Valid only for object files."), 40 | IMAGE_SCN_ALIGN_4096BYTES("D00000", "Align data on a 4096-byte boundary. Valid only for object files."), 41 | IMAGE_SCN_ALIGN_8192BYTES("E00000", "Align data on a 8192-byte boundary. Valid only for object files."), 42 | IMAGE_SCN_LNK_NRELOC_OVFL("1000000", "The section contains extended relocations."), 43 | IMAGE_SCN_MEM_DISCARDABLE("2000000", "The section can be discarded as needed."), 44 | IMAGE_SCN_MEM_NOT_CACHED("4000000", "The section cannot be cached."), 45 | IMAGE_SCN_MEM_NOT_PAGED("8000000", "The section is not pageable."), 46 | IMAGE_SCN_MEM_SHARED("10000000", "The section can be shared in memory."), 47 | IMAGE_SCN_MEM_EXECUTE("20000000", "The section can be executed as code."), 48 | IMAGE_SCN_MEM_READ("80000000", "The section can be read."), 49 | IMAGE_SCN_MEM_WRITE("80000000", "The section can be written to."); 50 | 51 | companion object { 52 | operator fun get(key: UInt): Array { 53 | val chars: MutableList = ArrayList(0) 54 | val keyAsLong: Long = key.toLong() 55 | for (c in values()) { 56 | val mask = c.hexValue.toLong(16) 57 | if (keyAsLong and mask != 0L) { 58 | chars.add(c) 59 | } 60 | } 61 | return chars.toTypedArray() 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/flags/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.headers.flags; 18 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.headers; 18 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/resources/ResourceDataEntry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers.resources 17 | 18 | import dorkbox.peParser.headers.Header 19 | import dorkbox.peParser.headers.SectionTableEntry 20 | import dorkbox.peParser.types.DWORD 21 | 22 | class ResourceDataEntry(bytes: dorkbox.peParser.ByteArray, private val section: SectionTableEntry) : Header() { 23 | // The address of a unit of resource data in the Resource Data area. 24 | val OFFSET_TO_DATA: DWORD 25 | val SIZE: DWORD 26 | val CODE_PAGE: DWORD 27 | val RESERVED: DWORD 28 | 29 | /** 30 | * @param section - necessary to know this section for when computing the location of the resource data! 31 | */ 32 | init { 33 | OFFSET_TO_DATA = DWORD(bytes.readUInt(4), "offsetToData") 34 | SIZE = DWORD(bytes.readUInt(4), "Size") 35 | CODE_PAGE = DWORD(bytes.readUInt(4), "CodePage") 36 | RESERVED = DWORD(bytes.readUInt(4), "Reserved") 37 | } 38 | 39 | fun getData(bytes: dorkbox.peParser.ByteArray): ByteArray { 40 | // this is where to get the data from the ABSOLUTE position in the file! 41 | val dataOffset = section.POINTER_TO_RAW_DATA.get().toLong() + OFFSET_TO_DATA.get().toLong() - section.VIRTUAL_ADDRESS.get().toLong() 42 | if (dataOffset > Int.MAX_VALUE) { 43 | throw RuntimeException("Unable to set offset to more than 2gb!") 44 | } 45 | 46 | //String asHex = Integer.toHexString(dataOffset); 47 | val saved = bytes.position() 48 | bytes.seek(dataOffset.toInt()) 49 | val bytesToCopyLong = SIZE.get().toLong() 50 | if (bytesToCopyLong > Int.MAX_VALUE) { 51 | throw RuntimeException("Unable to copy more than 2gb of bytes!") 52 | } 53 | val copyBytes = bytes.copyBytes(bytesToCopyLong.toInt()) 54 | bytes.seek(saved) 55 | return copyBytes 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/resources/ResourceDirectoryEntry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers.resources 17 | 18 | import dorkbox.peParser.ByteArray 19 | import dorkbox.peParser.headers.Header 20 | import dorkbox.peParser.headers.SectionTableEntry 21 | import dorkbox.peParser.types.DWORD 22 | import dorkbox.peParser.types.ResourceDirName 23 | 24 | class ResourceDirectoryEntry(bytes: ByteArray, section: SectionTableEntry?, val level: Int) : Header() { 25 | companion object { 26 | const val HEADER_SIZE = 8 27 | private const val DATA_IS_DIRECTORY_MASK = -0x80000000 28 | private const val ENTRY_OFFSET_MASK = 0x7FFFFFFF 29 | } 30 | 31 | val NAME: ResourceDirName? 32 | 33 | /** 34 | * This field is either an offset to another resource directory or a pointer to information about a specific resource instance. 35 | * 36 | * If the high bit (0x80000000) is set, this directory entry refers to a subdirectory. 37 | * The lower 31 bits are an offset (relative to the start of the resources) to another IMAGE_RESOURCE_DIRECTORY. 38 | * 39 | * If the high bit isn't set, the lower 31 bits point to an IMAGE_RESOURCE_DATA_ENTRY structure. 40 | * 41 | * The IMAGE_RESOURCE_DATA_ENTRY structure contains the location of the resource's raw data, its size, and its code page. 42 | */ 43 | val DATA_OFFSET: DWORD? 44 | 45 | // is this a directory (according to above) or an entry? 46 | var isDirectory: Boolean 47 | var directory: ResourceDirectoryHeader? = null 48 | var resourceDataEntry: ResourceDataEntry? = null 49 | 50 | /** 51 | * @param level "Type", "Name", or "Language ID" entry, depending on level of table. 52 | */ 53 | init { 54 | // System.err.println(Integer.toHexString(bytes.position)); 55 | 56 | // when this is level 2, it is the SUB-DIR of a main directory, 57 | // IE: 58 | // ROOT (lvl 0) 59 | // \- Bitmap (lvl 1) 60 | // |- Icons 61 | // \- 1 62 | // |- 2 (lvl 2) 63 | // |- Dialog 64 | // |- String 65 | NAME = h(ResourceDirName(bytes.readUInt(4), "name", bytes, level)) 66 | DATA_OFFSET = h(DWORD(bytes.readUInt(4), "data offset")) 67 | val dataOffset: Long = (ENTRY_OFFSET_MASK.toLong() and DATA_OFFSET.get().toLong()) 68 | if (dataOffset == 0L) { 69 | // if it is ZERO, than WTF? is it a directory header! (maybe?) 70 | isDirectory = false 71 | } 72 | else { 73 | if (dataOffset > (Int.MAX_VALUE.toLong())) { 74 | throw RuntimeException("Unable to set offset to more than 2gb!") 75 | } 76 | 77 | isDirectory = 0L != (DATA_IS_DIRECTORY_MASK.toLong() and DATA_OFFSET.get().toLong()) 78 | val saved = bytes.position() 79 | bytes.seek(bytes.marked() + dataOffset.toInt()) 80 | // System.err.println(Integer.toHexString(bytes.position)); 81 | if (isDirectory) { 82 | directory = ResourceDirectoryHeader(bytes, section, level) 83 | } 84 | else { 85 | resourceDataEntry = ResourceDataEntry(bytes, section!!) 86 | } 87 | bytes.seek(saved) 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/resources/ResourceDirectoryHeader.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.headers.resources 17 | 18 | import dorkbox.peParser.ByteArray 19 | import dorkbox.peParser.headers.Header 20 | import dorkbox.peParser.headers.SectionTableEntry 21 | import dorkbox.peParser.types.DWORD 22 | import dorkbox.peParser.types.TimeDate 23 | import dorkbox.peParser.types.WORD 24 | 25 | class ResourceDirectoryHeader(bytes: ByteArray, section: SectionTableEntry?, level: Int) : Header() { 26 | val RSRC_CHARACTERISTICS: DWORD 27 | val TIME_STAMP: TimeDate 28 | val MAJOR_VERSION: WORD 29 | val MINOR_VERSION: WORD 30 | val NUM_NAME_ENTRIES: WORD 31 | val NUM_ID_ENTRIES: WORD 32 | 33 | var entries: Array 34 | 35 | init { 36 | RSRC_CHARACTERISTICS = DWORD(bytes.readUInt(4), "Resource Characteristics") // not used. 37 | TIME_STAMP = TimeDate(bytes.readUInt(4), "Date") // The time that the resource data was created by the resource compiler. 38 | MAJOR_VERSION = WORD(bytes.readUShort(2), "Major Version") 39 | MINOR_VERSION = WORD(bytes.readUShort(2), "Minor Version") 40 | NUM_NAME_ENTRIES = WORD(bytes.readUShort(2), "Number of Name Entries") 41 | NUM_ID_ENTRIES = WORD(bytes.readUShort(2), "Number of ID Entries") 42 | 43 | val numberOfNamedEntires: Int = NUM_NAME_ENTRIES.get().toInt() 44 | val numberOfIDEntires: Int = NUM_ID_ENTRIES.get().toInt() 45 | val numberOfEntries = numberOfNamedEntires + numberOfIDEntires 46 | 47 | entries = arrayOfNulls(numberOfEntries) 48 | // IE: 49 | // ROOT (lvl 0) 50 | // \- Bitmap (lvl 1) 51 | // |- Icons 52 | // \- 1 53 | // |- 2 (lvl 2) 54 | // |- Dialog 55 | // |- String 56 | for (i in 0 until numberOfEntries) { 57 | entries[i] = ResourceDirectoryEntry(bytes, section, level + 1) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/headers/resources/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.headers.resources; 18 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/misc/DirEntry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.misc 17 | 18 | enum class DirEntry(val description: String) { 19 | EXPORT("Export Directory"), 20 | IMPORT("Import Directory"), 21 | RESOURCE("Resource Directory"), 22 | EXCEPTION("Exception Directory"), 23 | SECURITY("Security Directory"), 24 | BASERELOC("Base Relocation Table"), 25 | DEBUG("Debug Directory"), 26 | COPYRIGHT("Description String"), 27 | GLOBALPTR("Machine Value (MIPS GP)"), 28 | TLS("TLS Directory"), 29 | LOAD_CONFIG("Load Configuration Directory") 30 | } 31 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/misc/ImageBaseType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.misc 17 | 18 | enum class ImageBaseType(private val value: Long, val description: String) { 19 | IMAGE_BASE_DEFAULT(0x10000000L, "DLL default"), 20 | IMAGE_BASE_WIN_CE(0x00010000L, "default for Windows CE EXEs"), 21 | IMAGE_BASE_WIN(0x00400000L, "default for Windows NT, 2000, XP, 95, 98 and Me"); 22 | 23 | companion object { 24 | operator fun get(key: UInt): ImageBaseType? { 25 | val keyAsLong: Long = key.toLong() 26 | for (c in values()) { 27 | if (keyAsLong == c.value) { 28 | return c 29 | } 30 | } 31 | 32 | return null 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/misc/MachineTypeType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.misc 17 | 18 | import dorkbox.hex.toHexString 19 | 20 | enum class MachineTypeType(private val hexValue: String, val description: String) { 21 | NONE("", "No specified machine type"), 22 | IMAGE_FILE_MACHINE_UNKNOWN("0", "the contents of this field are assumed to be applicable for any machine type"), 23 | IMAGE_FILE_MACHINE_AM33("1d3", "Matsushita AM33"), 24 | IMAGE_FILE_MACHINE_AMD64("8664", "x64"), 25 | IMAGE_FILE_MACHINE_ARM("1c0", "ARM little endian"), 26 | IMAGE_FILE_MACHINE_ARMV7("1c4", "ARMv7 (or higher) Thumb mode only"), 27 | IMAGE_FILE_MACHINE_EBC("ebc", "EFI byte code"), 28 | IMAGE_FILE_MACHINE_I386("14c", "Intel 386 or later processors and compatible processors"), 29 | IMAGE_FILE_MACHINE_IA64("200", "Intel Itanium processor family"), 30 | IMAGE_FILE_MACHINE_M32R("9041", "Mitsubishi M32R little endian"), 31 | IMAGE_FILE_MACHINE_MIPS16("266", "MIPS16"), 32 | IMAGE_FILE_MACHINE_MIPSFPU("366", "MIPS with FPU"), 33 | IMAGE_FILE_MACHINE_MIPSFPU16("466", "MIPS16 with FPU"), 34 | IMAGE_FILE_MACHINE_POWERPC("1f0", "Power PC little endian"), 35 | IMAGE_FILE_MACHINE_POWERPCFP("1f1", "Power PC with floating point support"), 36 | IMAGE_FILE_MACHINE_R4000("166", "MIPS little endian"), 37 | IMAGE_FILE_MACHINE_SH3("1a2", "Hitachi SH3"), 38 | IMAGE_FILE_MACHINE_SH3DSP("1a3", "Hitachi SH3 DSP"), 39 | IMAGE_FILE_MACHINE_SH4("1a6", "Hitachi SH4"), 40 | IMAGE_FILE_MACHINE_SH5("1a8", "Hitachi SH5"), 41 | IMAGE_FILE_MACHINE_THUMB("1c2", "ARM or Thumb (\"interworking\")"), 42 | IMAGE_FILE_MACHINE_WCEMIPSV2("169", "MIPS little-endian WCE v2"); 43 | 44 | companion object { 45 | operator fun get(value: UShort): MachineTypeType { 46 | val key: String = value.toHexString() 47 | for (mt in values()) { 48 | if (key == mt.hexValue) { 49 | return mt 50 | } 51 | } 52 | return NONE 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/misc/MagicNumberType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.misc 17 | 18 | import dorkbox.hex.toHexString 19 | import java.util.* 20 | 21 | enum class MagicNumberType(hexValue: String, val description: String) { 22 | NONE("", "ERROR, unable to recognize magic number"), 23 | PE32("10B", "PE32, normal executable file"), 24 | PE32_PLUS("20B", "PE32+ executable" ), 25 | ROM("107", "ROM image"); 26 | 27 | private val hexValue: String 28 | 29 | init { 30 | this.hexValue = hexValue.lowercase(Locale.getDefault()) 31 | } 32 | 33 | companion object { 34 | operator fun get(value: UShort): MagicNumberType { 35 | val key: String = value.toHexString() 36 | for (mt in values()) { 37 | if (key == mt.hexValue) { 38 | return mt 39 | } 40 | } 41 | return NONE 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/misc/ResourceTypes.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.misc 17 | 18 | 19 | enum class ResourceTypes(val detailedInfo: String) { 20 | N_1("???_0"), 21 | CURSOR("Cursor"), 22 | BITMAP("Bitmap"), 23 | ICON("Icon"), 24 | MENU("Menu"), 25 | DLG_BOX("Fialog Box"), 26 | STRING_TABLE_ENTRY("String"), 27 | FONT_DIR("Font Directory"), 28 | FONT("Font"), 29 | ACCEL_TABLE("Accelerators"), 30 | RAW_DATA("application defined resource (raw data)"), 31 | MESSAGE_TABLE_ENTRY("Message entry"), 32 | GROUP_CURSOR("Group Cursor"), 33 | N_13("???_13"), 34 | GROUP_ICON("Group Icon"), 35 | N_15("???_15"), 36 | VER_INFO("Version"), 37 | DLG_INCLUDE("dlginclude"), 38 | N_18("???_18"), 39 | PNP_RESOURCE("Plug and Play Resource"), 40 | VXD("VXD"), 41 | ANIM_CURSOR("Animated Cursor"), 42 | ANIM_ICON("Animated Icon"), 43 | HTML("HTML"), 44 | MANIFEST("Manifest"); 45 | 46 | companion object { 47 | operator fun get(valueInt: UInt): ResourceTypes? { 48 | val valueAsInt: Int = valueInt.toInt() 49 | for (t in values()) { 50 | if (valueAsInt == t.ordinal) { 51 | return t 52 | } 53 | } 54 | return null 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/misc/SubsystemType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.misc 17 | 18 | enum class SubsystemType(private val intValue: Int, val description: String) { 19 | IMAGE_SYSTEM_UNKNOWN(0, "unknown subsystem"), 20 | IMAGE_SUBSYSTEM_NATIVE(1,"Device drivers and native Windows processes"), 21 | IMAGE_SUBSYSTEM_WINDOWS_GUI(2, "The Windows graphical user interface (GUI) subsystem"), 22 | IMAGE_SUBSYSTEM_WINDOWS_CUI(3,"The Windows character subsystem"), 23 | IMAGE_SUBSYSTEM_POSIX_CUI(7, "The Posix character subsystem"), 24 | IMAGE_SUBSYSTEM_WINDOWS_CE_GUI(9,"Windows CE"), 25 | IMAGE_SUBSYSTEM_EFI_APPLICATION(10, "An Extensible Firmware Interface (EFI) application"), 26 | IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER(11,"An EFI driver with boot services"), 27 | IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER(12, "An EFI driver with run-time services"), 28 | IMAGE_SUBSYSTEM_EFI_ROM(13,"An EFI ROM image"), 29 | IMAGE_SUBSYSTEM_XBOX(14, "XBOX"); 30 | 31 | companion object { 32 | operator fun get(value: UShort): SubsystemType? { 33 | val valueAsInt: Int = value.toInt() 34 | for (c in values()) { 35 | if (c.intValue == valueAsInt) { 36 | return c 37 | } 38 | } 39 | return null 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/misc/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.misc; 18 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser; 18 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/AsciiString.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import dorkbox.peParser.ByteArray 20 | import kotlin.text.Charsets.US_ASCII 21 | 22 | class AsciiString(bytes: ByteArray, byteLength: Int, descriptiveName: String) : ByteDefinition(descriptiveName) { 23 | private val value: String 24 | 25 | init { 26 | val stringBytes = bytes.copyBytes(byteLength) 27 | value = String(stringBytes, US_ASCII).trim { it <= ' ' } 28 | } 29 | 30 | override fun get(): String { 31 | return value 32 | } 33 | 34 | override fun format(b: StringBuilder) { 35 | b.append(descriptiveName).append(": ").append(value).append(OS.LINE_SEPARATOR) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/ByteDefinition.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | abstract class ByteDefinition(val descriptiveName: String) { 19 | 20 | abstract fun get(): T 21 | abstract fun format(b: StringBuilder) 22 | override fun toString(): String { 23 | val b = StringBuilder() 24 | format(b) 25 | return b.toString() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/CoffCharacteristics.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import dorkbox.peParser.headers.flags.Characteristics 20 | 21 | class CoffCharacteristics(private val value: UShort, descriptiveName: String) : ByteDefinition>(descriptiveName) { 22 | override fun get(): Array { 23 | return Characteristics[value] 24 | } 25 | 26 | override fun format(b: StringBuilder) { 27 | val characteristics = get() 28 | b.append(descriptiveName).append(":").append(OS.LINE_SEPARATOR) 29 | 30 | if (characteristics.size > 0) { 31 | for (c in characteristics) { 32 | b.append("\t * ").append(c.description).append(OS.LINE_SEPARATOR) 33 | } 34 | } 35 | else { 36 | b.append("\t * none").append(OS.LINE_SEPARATOR) 37 | } 38 | 39 | b.append(OS.LINE_SEPARATOR) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/DWORD.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | 21 | class DWORD(value: UInt, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | private val value: UInt 23 | 24 | init { 25 | this.value = value 26 | } 27 | 28 | override fun get(): UInt { 29 | return value 30 | } 31 | 32 | override fun format(b: StringBuilder) { 33 | b.append(descriptiveName).append(": ").append(value).append(" (0x").append(value.toHexString()).append(")").append(OS.LINE_SEPARATOR) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/DWORD_WIDE.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | 21 | class DWORD_WIDE(private val value: ULong, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | override fun get(): ULong { 23 | return value 24 | } 25 | 26 | override fun format(b: StringBuilder) { 27 | b.append(descriptiveName).append(": ").append(value).append(" (0x").append(value.toHexString()).append(")").append(OS.LINE_SEPARATOR) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/DllCharacteristics.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import dorkbox.peParser.headers.flags.DllCharacteristicsType 20 | 21 | class DllCharacteristics(private val value: UShort, descriptiveName: String) : ByteDefinition>(descriptiveName) { 22 | override fun get(): Array { 23 | return DllCharacteristicsType.get(value) 24 | } 25 | 26 | override fun format(b: StringBuilder) { 27 | val characteristics: Array = get() 28 | b!!.append(descriptiveName).append(":").append(OS.LINE_SEPARATOR) 29 | if (characteristics.size > 0) { 30 | for (c in characteristics) { 31 | b.append("\t * ").append(c.description).append(OS.LINE_SEPARATOR) 32 | } 33 | } 34 | else { 35 | b.append("\t * none").append(OS.LINE_SEPARATOR) 36 | } 37 | b.append(OS.LINE_SEPARATOR) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/HeaderDefinition.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | 20 | class HeaderDefinition(descriptiveName: String) : ByteDefinition(descriptiveName) { 21 | override fun get(): String { 22 | return descriptiveName 23 | } 24 | 25 | override fun format(b: StringBuilder) { 26 | b.append(OS.LINE_SEPARATOR) 27 | .append(get()) 28 | .append(OS.LINE_SEPARATOR) 29 | .append(".......................") 30 | .append(OS.LINE_SEPARATOR) 31 | .append(OS.LINE_SEPARATOR) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/ImageBase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | import dorkbox.peParser.misc.ImageBaseType 21 | 22 | class ImageBase(value: UInt, descriptiveName: String) : ByteDefinition(descriptiveName) { 23 | private val value: UInt 24 | 25 | init { 26 | this.value = value 27 | } 28 | 29 | override fun get(): UInt { 30 | return value 31 | } 32 | 33 | override fun format(b: StringBuilder) { 34 | val imageBase = ImageBaseType.get(value) 35 | 36 | b.append(descriptiveName).append(": ").append(value).append(" (0x").append(value.toHexString()).append(") (") 37 | 38 | if (imageBase != null) { 39 | b.append(imageBase.description) 40 | } 41 | else { 42 | b.append("no image base default") 43 | } 44 | b.append(")").append(OS.LINE_SEPARATOR) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/ImageBase_Wide.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | import dorkbox.peParser.misc.ImageBaseType 21 | 22 | class ImageBase_Wide(private val value: ULong, descriptiveName: String) : ByteDefinition(descriptiveName) { 23 | override fun get(): ULong { 24 | return value 25 | } 26 | 27 | override fun format(b: StringBuilder) { 28 | val imageBase = ImageBaseType.get(value.toUInt()) 29 | 30 | b.append(descriptiveName).append(": ").append(value).append(" (0x").append(value.toHexString()).append(") (") 31 | if (imageBase != null) { 32 | b.append(imageBase.description) 33 | } 34 | else { 35 | b.append("no image base default") 36 | } 37 | b.append(")").append(OS.LINE_SEPARATOR) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/ImageDataDir.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | import dorkbox.peParser.ByteArray 21 | import dorkbox.peParser.headers.Header 22 | import dorkbox.peParser.headers.SectionTableEntry 23 | import dorkbox.peParser.misc.DirEntry 24 | 25 | class ImageDataDir(bytes: ByteArray, val type: DirEntry) : ByteDefinition(type.description) { 26 | private val virtualAddress: TInteger 27 | private val size: TInteger 28 | 29 | var section: SectionTableEntry? = null 30 | 31 | var data: Header? = null 32 | 33 | /** 8 bytes each */ 34 | init { 35 | virtualAddress = TInteger(bytes.readUInt(4), "Virtual Address") 36 | size = TInteger(bytes.readUInt(4), "Size") 37 | } 38 | 39 | override fun get(): UInt { 40 | return virtualAddress.get() 41 | } 42 | 43 | fun getSize(): UInt { 44 | return size.get() 45 | } 46 | 47 | override fun format(b: StringBuilder) { 48 | b.append(descriptiveName).append(": ").append(OS.LINE_SEPARATOR) 49 | .append("\t").append("address: ").append(virtualAddress).append(" (").append(virtualAddress.get().toHexString()).append(")").append(OS.LINE_SEPARATOR) 50 | .append("\t").append("size: ").append(size.get()).append(" (").append(size.get().toHexString()).append(")").append(OS.LINE_SEPARATOR) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/ImageDataDirExtra.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | import dorkbox.peParser.ByteArray 21 | 22 | class ImageDataDirExtra(bytes: ByteArray, description: String) : ByteDefinition(description) { 23 | private val virtualAddress: TInteger 24 | private val size: TInteger 25 | 26 | /** 8 bytes each */ 27 | init { 28 | virtualAddress = TInteger(bytes.readUInt(4), "Virtual Address") 29 | size = TInteger(bytes.readUInt(4), "Size") 30 | } 31 | 32 | override fun get(): UInt { 33 | return virtualAddress.get() 34 | } 35 | 36 | fun getSize(): UInt { 37 | return size.get() 38 | } 39 | 40 | override fun format(b: StringBuilder) { 41 | b.append(descriptiveName).append(": ").append(OS.LINE_SEPARATOR) 42 | .append("\t").append("address: ").append(virtualAddress).append(" (").append(virtualAddress.get().toHexString()).append(")").append(OS.LINE_SEPARATOR) 43 | .append("\t").append("size: ").append(size.get()).append(" (").append(size.get().toHexString()).append(")").append(OS.LINE_SEPARATOR) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/MachineType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import dorkbox.peParser.misc.MachineTypeType 20 | 21 | class MachineType(private val value: UShort, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | override fun get(): MachineTypeType { 23 | return MachineTypeType[value] 24 | } 25 | 26 | override fun format(b: StringBuilder) { 27 | b.append(descriptiveName).append(": ").append(get().description).append(OS.LINE_SEPARATOR) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/MagicNumber.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import dorkbox.peParser.misc.MagicNumberType 20 | 21 | class MagicNumber(private val value: UShort, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | override fun get(): MagicNumberType { 23 | return MagicNumberType[value] 24 | } 25 | 26 | override fun format(b: StringBuilder) { 27 | b.append(descriptiveName).append(": ").append(value).append(" --> ").append(get().description).append(OS.LINE_SEPARATOR) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/RVA.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | 20 | 21 | class RVA(value: UInt, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | private val value: UInt 23 | 24 | init { 25 | this.value = value 26 | } 27 | 28 | override fun get(): UInt { 29 | return value 30 | } 31 | 32 | override fun format(b: StringBuilder) { 33 | b.append(descriptiveName).append(": ").append(value.toLong()).append(OS.LINE_SEPARATOR) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/ResourceDirName.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | import dorkbox.peParser.misc.ResourceTypes 21 | import java.nio.charset.StandardCharsets 22 | 23 | class ResourceDirName(intValue: UInt, descriptiveName: String, bytes: dorkbox.peParser.ByteArray, private val level: Int) : 24 | ByteDefinition(descriptiveName) { 25 | 26 | private var value: String? = null 27 | 28 | init { 29 | 30 | /* 31 | * This field contains either an integer ID or a pointer to a structure that contains a string name. 32 | * 33 | * If the high bit (0x80000000) is zero, this field is interpreted as an integer ID. 34 | * 35 | * If the high bit is nonzero, the lower 31 bits are an offset (relative to the start of the resources) to an 36 | * IMAGE_RESOURCE_DIR_STRING_U structure. This structure contains a WORD character count, followed by a UNICODE 37 | * string with the resource name. 38 | * 39 | * Yes, even PE files intended for non-UNICODE Win32 implementations use UNICODE here. To convert the UNICODE 40 | * string to an ANSI string, use the WideCharToMultiByte function. 41 | */ 42 | val valueInt: Long = intValue.toLong() 43 | 44 | // now process the name 45 | val isString = 0L != valueInt and NAME_IS_STRING_MASK.toLong() 46 | if (isString) { 47 | val savedPosition = bytes.position() 48 | // 49 | // High bit is 1 50 | // 51 | val offset = valueInt and NAME_OFFSET_MASK.toLong() 52 | if (offset > Int.MAX_VALUE.toLong()) { 53 | throw RuntimeException("Unable to set offset to more than 2gb!") 54 | } 55 | 56 | // offset from the start of the resource data to the name string of this particular resource. 57 | bytes.seek(bytes.marked() + offset.toInt()) 58 | val length: Int = bytes.readUShort(2).toInt() 59 | val buff = ByteArray(length * 2) // UTF-8 chars are 16 bits = 2 60 | // bytes 61 | for (i in buff.indices) { 62 | buff[i] = bytes.readUByte().toByte() 63 | } 64 | 65 | // go back 66 | bytes.seek(savedPosition) 67 | value = String(buff, StandardCharsets.UTF_16LE).trim { it <= ' ' } 68 | } 69 | else { 70 | // 71 | // High bit is 0 72 | // 73 | 74 | // if it's NOT a STRING, then we do additional lookups. 75 | 76 | // determine what "name" means 77 | when (level) { 78 | 1 -> value = ResourceTypes.get(intValue)?.detailedInfo 79 | 2 -> value = intValue.toHexString() 80 | 3 -> value = intValue.toHexString() 81 | else -> value = intValue.toHexString() 82 | } 83 | } 84 | } 85 | 86 | override fun get(): String { 87 | return value!! 88 | } 89 | 90 | override fun format(b: StringBuilder) { 91 | b.append(descriptiveName).append(": ") 92 | when (level) { 93 | 1 -> {} 94 | 2 -> b.append("name: ") 95 | 3 -> b.append("Language: ") 96 | else -> b.append("??: ") 97 | } 98 | b.append(value).append(OS.LINE_SEPARATOR) 99 | } 100 | 101 | companion object { 102 | private const val NAME_IS_STRING_MASK = -0x80000000 103 | private const val NAME_OFFSET_MASK = 0x7FFFFFFF 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/SectionCharacteristics.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import dorkbox.peParser.headers.flags.SectionCharacteristicsType 20 | 21 | class SectionCharacteristics(value: UInt, descriptiveName: String) : ByteDefinition>(descriptiveName) { 22 | private val value: UInt 23 | 24 | init { 25 | this.value = value 26 | } 27 | 28 | override fun get(): Array { 29 | return SectionCharacteristicsType.get(value) 30 | } 31 | 32 | override fun format(b: StringBuilder) { 33 | val characteristics: Array = get() 34 | b.append(descriptiveName).append(": ").append(OS.LINE_SEPARATOR) 35 | if (characteristics.size > 0) { 36 | for (c in characteristics) { 37 | b.append("\t * ").append(c.description).append(OS.LINE_SEPARATOR) 38 | } 39 | } 40 | else { 41 | b.append("\t * none").append(OS.LINE_SEPARATOR) 42 | } 43 | b.append(OS.LINE_SEPARATOR) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/Subsystem.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import dorkbox.peParser.misc.SubsystemType 20 | 21 | class Subsystem(private val value: UShort, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | override fun get(): SubsystemType { 23 | return SubsystemType.get(value)!! 24 | } 25 | 26 | override fun format(b: StringBuilder) { 27 | val s: SubsystemType = get() 28 | b.append(descriptiveName).append(": ").append(s.description).append(OS.LINE_SEPARATOR) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/TInteger.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | 21 | 22 | class TInteger(value: UInt, descriptiveName: String) : ByteDefinition(descriptiveName) { 23 | private val value: UInt 24 | 25 | init { 26 | this.value = value 27 | } 28 | 29 | override fun get(): UInt { 30 | return value 31 | } 32 | 33 | override fun format(b: StringBuilder) { 34 | b.append(descriptiveName).append(": ").append(value).append(" (0x").append(value.toHexString()).append(")").append(OS.LINE_SEPARATOR) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/TimeDate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.os.OS 19 | import java.util.* 20 | 21 | class TimeDate(value: UInt, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | private val value: UInt 23 | 24 | init { 25 | this.value = value 26 | } 27 | 28 | override fun get(): Date { 29 | val millis: Long = value.toLong() * 1000 30 | return Date(millis) 31 | } 32 | 33 | override fun format(b: StringBuilder) { 34 | b.append(descriptiveName).append(": ").append(get().toString()).append(OS.LINE_SEPARATOR) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/WORD.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dorkbox.peParser.types 17 | 18 | import dorkbox.hex.toHexString 19 | import dorkbox.os.OS 20 | 21 | class WORD(private val value: UShort, descriptiveName: String) : ByteDefinition(descriptiveName) { 22 | override fun get(): UShort { 23 | return value 24 | } 25 | 26 | override fun format(b: StringBuilder) { 27 | b.append(descriptiveName).append(": ").append(value).append(" (0x").append(value.toHexString()).append(")").append(OS.LINE_SEPARATOR) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/dorkbox/peParser/types/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.types; 18 | -------------------------------------------------------------------------------- /src9/dorkbox/peParser/EmptyClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser; 18 | 19 | /** 20 | * Required for intellij to not complain regarding `module-info` for a multi-release jar. 21 | * This file is completely ignored by the gradle build process 22 | */ 23 | public 24 | class EmptyClass {} 25 | -------------------------------------------------------------------------------- /src9/dorkbox/peParser/headers/EmptyClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.headers; 18 | 19 | /** 20 | * Required for intellij to not complain regarding `module-info` for a multi-release jar. 21 | * This file is completely ignored by the gradle build process 22 | */ 23 | public 24 | class EmptyClass {} 25 | -------------------------------------------------------------------------------- /src9/dorkbox/peParser/misc/EmptyClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.misc; 18 | 19 | /** 20 | * Required for intellij to not complain regarding `module-info` for a multi-release jar. 21 | * This file is completely ignored by the gradle build process 22 | */ 23 | public 24 | class EmptyClass {} 25 | -------------------------------------------------------------------------------- /src9/dorkbox/peParser/types/EmptyClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 dorkbox, llc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dorkbox.peParser.types; 18 | 19 | /** 20 | * Required for intellij to not complain regarding `module-info` for a multi-release jar. 21 | * This file is completely ignored by the gradle build process 22 | */ 23 | public 24 | class EmptyClass {} 25 | -------------------------------------------------------------------------------- /src9/module-info.java: -------------------------------------------------------------------------------- 1 | module dorkbox.pe { 2 | exports dorkbox.peParser; 3 | exports dorkbox.peParser.headers; 4 | exports dorkbox.peParser.misc; 5 | exports dorkbox.peParser.types; 6 | 7 | requires transitive dorkbox.collections; 8 | requires transitive dorkbox.byteUtils; 9 | requires transitive dorkbox.hexUtils; 10 | requires transitive dorkbox.updates; 11 | requires transitive dorkbox.utilities; 12 | 13 | requires transitive kotlin.stdlib; 14 | } 15 | --------------------------------------------------------------------------------