-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PE & MDMP base relocations #4711
Conversation
Some things I wasn't sure about:
|
librz/bin/p/bin_pe.inc
Outdated
@@ -554,30 +638,16 @@ err: | |||
} | |||
|
|||
static int has_canary(RzBinFile *bf) { | |||
// XXX: We only need imports here but this causes leaks, we need to wait for the below. This is a horrible solution! | |||
// TODO: use O(1) when imports sdbized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment too
For now, I think some code duplication is fine. Sharing the code between two plugins is non-trivial at this point. |
64455b5
to
7cac944
Compare
@@ -0,0 +1,4 @@ | |||
// SPDX-FileCopyrightText: 2024 Roee Toledano <[email protected]> | |||
// SPDX-License-Identifier: LGPL-3.0-only | |||
#define RZ_BIN_PE64 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be tested via distro-
branch before merge. @XVilka
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please always initialize the variables to 0
or NULL
so we can avoid random crashes and weird unintentional behavior.
Sorry for the ugly commit history. I could rebase interactive + squash with the old ones so it's easier to review. |
All tests are green except flagspace tests. Because there is no symbol associated with base relocations, they have no name associated with them, so I'm not sure how we can use flags here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good changes, but why did you remove MDMP relocs completely?
I think it should be in 0.8.0 release, assuming it will be finished in time. |
Ok, i checked the documentation and saw how other tools shows this, so the changes are ok, just give it a name like please also fix the mdmp relocs that you have removed. |
librz/bin/format/pe/pe.h
Outdated
ut32 page_rva; | ||
ut32 block_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please give a short description of what these fields are.
Example of formatting
ut32 page_rva; | |
ut32 block_size; | |
ut32 page_rva; ///< PE RVA see doc https://bla | |
ut32 block_size; ///< PE reloc block size for xxxxx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a link to the base relocations documentation section of the specification, I will add detailed comments to each struct field too though
MDMP doesn't have any relocations (base or COFF), only contains imports of the dumped executable. Up until now, imports were used which is wrong. * Remove MDMP relocations * Remove MDMP relocations tests
1. Everything is based off of Microsoft's PE format documentation [found here](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format) 2. Up until now, imports were used for relocations in the PE & MDMP format, which is wrong. PE uses base relocations. 3. PE relocations do not have symbols associated with them, and thus have no name. In order to still have flags in relocs flagspace, dummy symbols were allocated with generic names composed of the relocation's virtual address space. * Remove old code of setting import entries to PE relocations * Parse PE base relocations * Implement converting from the specific RzBinPeRelocEnt type to the general RzBinReloc type * Implement corrent type naming of PE relocations * Add missing `PE_IMAGE_FILE_MACHINE` types * Add PE base relocation types * Fix PE format 'has_canary' function * Remove 'RzBinPEObj.endian' and use 'RzBinPEObj.big_endian' instead * Removed a.exe and b.exe tests, as they don't contain base relocations and swapped them with correct tests * Corrected old PE relocation tests * Add new PE base relocation tests
Your checklist for this pull request
Detailed description
Up until now PE relocations were implemented as imports, which is incorrect. The PE format uses base relocations for image files (ie executable files) and classic COFF relocations for object files.
Implemented so far:
Still need to implement:
relocation patching- Rizin always loads the binary in it's expected base address, so no patching is needed (I added a detailed comment about this inrelocs
function inbin_pe.inc
)make MDMP use the new base relocationMDMP doesn't have relocations, only imports.add COFF relocations for object filestechnically PE can have COFF relocations since it's based off of COFF, but COFF relocations are only used for for object files, and there is no reason to use PE for object files, so it's never actually used.Notes:
type
andoffset
to apply the relocation in....
Test plan
All tests green.
...
Closing issues
...