84 Commits

Author SHA1 Message Date
awgh 4e22595eaa Add relocation CRUD and dyld bind kinds
add remove APIs for ELF/Mach-O/PE relocations and relocation sections
allow ELF alloc relocation sections to grow via new PT_LOAD; stabilize section write order
add Mach-O scattered relocs plus weak/lazy bind stream support
add PE COFF relocation helpers (symbol lookup)
update README and tests
2026-01-28 15:00:15 -08:00
awgh dd7757eeb3 Add relocation editing support across ELF/Mach-O/PE with tests
- implement relocation add/replace APIs and serialization updates per format
- generate dyld rebase/bind info from Mach-O relocs with optional ordinals
- update ELF dynamic relocation tags and safe relayout handling
- add/extend relocation tests and stabilize existing test suite
2026-01-23 20:55:41 -08:00
awgh 26db73212a Merge pull request #25 from C-Sto/moreexports
add delay imports functions, refactor section retrieval
2023-05-08 12:55:19 -07:00
awgh febe44e596 Fixes issue #26, where DOS Stubs were being zeroed out incorrectly.
Thanks to kulinacs for the issue report!
2023-04-18 20:54:12 -07:00
C-Sto 6b69dda15d add delay imports functions, refactor section retrieval 2022-12-21 15:36:56 +08:00
C_Sto c65243ec70 fix import 2021-10-07 14:31:12 +08:00
C_Sto c8a66609ea sanity check import address 2021-10-07 14:08:36 +08:00
awgh 6277045c2f - Added support for IAT linking.
- Fixed a bug where debug/pe would try to read certificate tables in memoryMode
- Added support for Forwarder RVA.
2021-03-12 01:29:33 -08:00
awgh 8d083c1f04 Fixed unit tests for PE.
Fixed a regression from this branch in string table lookups.
Fixed two bugs where we assumed the optional header wasn't optional.
2021-01-01 13:04:12 -08:00
awgh cea0c3109d Fixed a bug where the prepended length of string tables was not saved
and written out correctly.
2020-12-30 19:03:39 -08:00
awgh 26160983c6 Fixed typo in Relocate 2020-12-30 12:21:36 -08:00
awgh 6cd8cb92dc Added support for 64bit, fixed RVA writing errors. 2020-12-30 12:08:50 -08:00
awgh d9ccfe9efd Fixed read issue with RelocationBlock by adding new type
RelocationTableEntry.
2020-12-30 02:57:35 -08:00
awgh 404f72feef Fix for image base being wrong size in 64bit mode. 2020-12-30 02:40:24 -08:00
awgh cef84fa80d Continuing work on implementing base relocations for PE files. 2020-12-30 02:04:56 -08:00
awgh 60012895f1 Added base relocation structs and a function to perform base relocations on an image. 2020-12-28 00:20:58 -08:00
awgh 9a7f55dae8 Completed implementation of ImportLibraries, fixed a couple linter warnings, fixed a TODO from previous maintainers. 2020-12-27 17:07:28 -08:00
C-Sto 4efde44477 Net prefix for exported function 2020-12-04 23:44:19 +08:00
C-Sto 72254acbf4 Add ability to retrieve CLR version from exe 2020-12-04 23:30:33 +08:00
C-Sto cb72c7d000 fix in-memory PE file symbol table offset pointer on write 2020-11-01 09:53:13 +08:00
C-Sto 9cc2bb2714 use internal seek const 2020-11-01 09:43:19 +08:00
C-Sto 3de1428350 fix up strings table location when in memory 2020-10-31 20:17:30 +08:00
C-Sto faed987215 add managed check 2020-07-26 00:27:36 +08:00
C-Sto 1cecce1be4 add rva offset conversion as function to pe file 2020-07-12 11:55:30 +08:00
awgh 63af8e4051 Added NewFileFromMemory, which lets you parse a PE binary from memory instead of file layout. <experimental feature!> 2020-06-20 22:00:44 -07:00
awgh db623b874a Commenting out debug prints. Need a debug/warning/error log scheme in here. 2020-06-20 10:23:50 -07:00
awgh 3ba66a81a9 Added support for ordinal-only exports. 2020-06-20 00:51:18 -07:00
awgh 7976403b13 Added Exports() which returns an array of Export structs describing the exported functions, if there are any. 2020-06-19 23:34:00 -07:00
Vyrus 9846938ecd fixed bug dealing with rich header writes and files with no dos stub 2019-09-29 00:27:09 -07:00
awgh d472551263 Commenting out some debug logging 2019-08-05 14:26:35 -07:00
awgh 8d4fd1e576 Fixed an integer overflow causing shellcode bug in x64. 2019-08-02 23:59:45 -07:00
awgh 8de2a11f74 Fixed padding for 64bit, shellcode isn't quite working for 64bit. 2019-08-02 20:25:13 -07:00
awgh 804a7d342d Made enhancements to allow adding sections that never existed in the original file.
Added some PE consts that were missing along the way.
2019-08-02 14:52:13 -07:00
Andrew LeFevre 2f826f277d Small optimization to only write PE cert info if it changed 2019-01-28 18:05:24 -05:00
Andrew LeFevre ac54a07fc1 Separate PE writing logic into two functions, fix cert writing (again) 2019-01-28 17:15:04 -05:00
Andrew LeFevre 564c67b7e0 More refactoring/fixing 2019-01-28 15:53:11 -05:00
Andrew LeFevre b8a29f67bf Refactored and improved cert writing code 2019-01-28 14:47:04 -05:00
Andrew LeFevre a9b465661b Small tweak to correctly write certain files that don't have a Rich header 2019-01-28 13:55:48 -05:00
Andrew LeFevre 8fcbc6782c Added comments 2019-01-27 23:41:40 -05:00
Andrew LeFevre e3d3d8509f PE parsing and writing Rich header working 2019-01-27 23:36:30 -05:00
Andrew LeFevre ad93c6b189 pe.Write now working with certs 2019-01-17 23:06:18 -05:00
Andrew LeFevre 85680fcd79 pe.Write mostly complete, produces files that execute but with different hashes... 2019-01-17 21:59:53 -05:00
Andrew LeFevre 6bb96c4eba File header writing working for PEs 2019-01-17 19:22:38 -05:00
Andrew LeFevre 66129e3cc8 Added parsing of Dos Header and Stub to debug/pe, cleaned up NewFile 2019-01-17 19:21:01 -05:00
Alex Brainman 497d114ce9 debug/pe: use ws2_32.dll in TestImportTableInUnknownSection
Apparently (see
https://github.com/golang/go/issues/27904#issuecomment-442140627
for details) kernel32.dll file is not present on windows/arm, so
use ws2_32.dll instead. ws2_32.dll imports table also lives in
'.rdata' section, so ws2_32.dll is as good as kernel32.dll for
testing issue #16103.

Updates #27904

Change-Id: Ibc72b24eea9a4d85abd371ffdcf00442e711b745
Reviewed-on: https://go-review.googlesource.com/c/151480
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-29 08:30:13 +00:00
Alex Brainman e7eabeb4ba debug/pe: correct TestImportTableInUnknownSection error message
TestImportTableInUnknownSection uses kernel32.dll file, but the error
message mentions atmfd.dll. Adjust error message to match the test.

This change should have been part of CL 151137.

Updates #27904

Change-Id: Ifc31a12134b328472191122f8426ab6ed234fbd4
Reviewed-on: https://go-review.googlesource.com/c/151477
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-11-27 09:26:16 +00:00
Alex Brainman 0d87393ea3 debug/pe: use kernel32.dll in TestImportTableInUnknownSection
TestImportTableInUnknownSection was introduced in CL 110555 to
test PE executable with import table located in section other than
".idata". We used atmfd.dll for that purpose, but it seems
atmfd.dll is not present on some systems.

Use kernel32.dll instead. kernel32.dll import table is located in
".rdata" section, so it should do the job. And every Windows
system has kernel32.dll file.

Also make TestImportTableInUnknownSection run on windows-arm,
since windows-arm should also have kernel32.dll file.

Updates #27904

Change-Id: Ie005ee10e46ae0c06e83929d581e89f86c051eea
Reviewed-on: https://go-review.googlesource.com/c/151137
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-24 23:55:07 +00:00
Jordan Rhee 14138f7f43 debug/pe: fix TestDWARF to work with relocations
Fixes #27904

Change-Id: Ie2aad20cd66785b6cc1018c0048824382cb39f8c
Reviewed-on: https://go-review.googlesource.com/c/140158
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-05 20:30:11 +00:00
Brad Fitzpatrick ce3af89ba5 debug/pe: skip a test on windows/arm
It requires a DLL that's not available on windows/arm apparently.

Fixes #27904

Change-Id: I082a273f62976b7184636c6aeca6201a7871d238
Reviewed-on: https://go-review.googlesource.com/c/139720
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-10-04 17:50:01 +00:00
Jordan Rhee 8e3116e065 debug/pe: support windows/arm
Enable 'go tool objdump' to disassemble windows/arm images.

Updates #26148

Change-Id: I7d11226f01d92288061f8e25980334b9bd82c41f
Reviewed-on: https://go-review.googlesource.com/125649
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-20 18:12:47 +00:00