Skip to content
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

Machine code fix + missing relocations #193

Merged
merged 2 commits into from
Sep 25, 2023
Merged

Conversation

lakor64
Copy link
Contributor

@lakor64 lakor64 commented Sep 23, 2023

  • Fixed bad machine code for Alpha 32-bit and, MIPS R3000 and MIPS R10000
  • Added Hitachi SH3, Loongarch and PPC BE machines
  • Added remaining base relocations

Info gathered from MSDN PE Format documentation page and radare2 pe header file

@lakor64 lakor64 requested a review from woodruffw as a code owner September 23, 2023 09:53
@CLAassistant
Copy link

CLAassistant commented Sep 23, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! A few questions about where the constants came from.

constexpr std::uint16_t IMAGE_FILE_MACHINE_R4000 = 0x166; // MIPS little endian
constexpr std::uint16_t IMAGE_FILE_MACHINE_R10000 = 0x166; // MIPS little endian
constexpr std::uint16_t IMAGE_FILE_MACHINE_R10000 = 0x168; // MIPS little endian
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came from Radare, right? I don't see it in the MSDN docs.

constexpr std::uint16_t IMAGE_FILE_MACHINE_RISCV32 = 0x5032; // RISC-V 32-bit address space
constexpr std::uint16_t IMAGE_FILE_MACHINE_RISCV64 = 0x5064; // RISC-V 64-bit address space
constexpr std::uint16_t IMAGE_FILE_MACHINE_RISCV128 = 0x5128; // RISC-V 128-bit address space
constexpr std::uint16_t IMAGE_FILE_MACHINE_SH3 = 0x1a2; // Hitachi SH3
constexpr std::uint16_t IMAGE_FILE_MACHINE_SH3DSP = 0x1a3; // Hitachi SH3 DSP
constexpr std::uint16_t IMAGE_FILE_MACHINE_SH3E = 0x1a4; // Hitachi SH3E
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question for this one 🙂

@woodruffw
Copy link
Member

@lakor64
Copy link
Contributor Author

lakor64 commented Sep 25, 2023

From the MSDN website there's described the followings:
(https://learn.microsoft.com/en-us/windows/win32/debug/pe-format)
IMAGE_FILE_MACHINE_ALPHA (existed but wrong code)
IMAGE_FILE_MACHINE_LOONGARCH32
IMAGE_FILE_MACHINE_LOONGARCH64
From this site from microsoft.com there's descibed the followings:
(https://learn.microsoft.com/en-us/windows/win32/sysinfo/image-file-machine-constants)
IMAGE_FILE_MACHINE_R3000
IMAGE_FILE_MACHINE_R10000
IMAGE_FILE_MACHINE_SH3E

Relocations are taken from this site: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format

PowerPC BE is usually not documented anywhere as it was used exclusively for Xbox360, but under this repository from Ms we can see it's definition https://github.com/microsoft/microsoft-pdb/blob/master/cvdump/dumppdb.cpp

@woodruffw
Copy link
Member

Got it, thanks! The lint needs to be fixed, but otherwise this LGTM.

@lakor64
Copy link
Contributor Author

lakor64 commented Sep 25, 2023

Got it, thanks! The lint needs to be fixed, but otherwise this LGTM.

Is it related to formatting issue I suppose? I have to run clang-format?

@woodruffw
Copy link
Member

Is it related to formatting issue I suppose? I have to run clang-format?

Yep, correct. There should be a target for it in the CMake-based build.

@lakor64
Copy link
Contributor Author

lakor64 commented Sep 25, 2023

Should be ok now

@woodruffw woodruffw merged commit 17d3842 into trailofbits:master Sep 25, 2023
33 checks passed
@woodruffw
Copy link
Member

Thanks @lakor64!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants