From 1e50213ebc46a199128808913279b994d0f9de4a Mon Sep 17 00:00:00 2001 From: Maria <77745122+mariaWitch@users.noreply.github.com> Date: Sun, 19 Feb 2023 16:54:42 -0500 Subject: [PATCH 1/3] Pass 1 complete --- tools/cxbe/Exe.cpp | 40 +++++++++++++++++++++++++++++++++++++++- tools/cxbe/Exe.h | 3 +++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tools/cxbe/Exe.cpp b/tools/cxbe/Exe.cpp index b3279e85a..95d451faa 100644 --- a/tools/cxbe/Exe.cpp +++ b/tools/cxbe/Exe.cpp @@ -6,9 +6,14 @@ // SPDX-FileCopyrightText: 2021 Stefan Schmidt #include "Exe.h" +#include "Xbe.h" -#include #include +#include +#include +#include +#include +#include // construct via Exe file Exe::Exe(const char *x_szFilename) @@ -177,6 +182,39 @@ Exe::Exe(const char *x_szFilename) return; } +Exe(class Xbe *x_Xbe, const char *x_szTitle, bool x_bRetail) { + + ConstructorInit(); + + time_t CurrentTime; + + time(&CurrentTime); + + printf("Exe::Exe: Pass 1 (Simple Pass)..."); + + //pass 1 + { + //standard Pe magic Number + m_Header.m_magic = *(uint32 *)"PE\0\0"; + //m_Header.dwBaseAddr = 0x00010000; + //we want the same number of sections as our xbe file + m_Header.m_sections= x_Xbe->dwSections; + //copies of various same header values + { + m_Header.m_OptionalHeader.m_sizeof_stack_reserve = x_Xbe->dwPeStackCommit; + m_Header.m_OptionalHeader.m_sizeof_heap_reserve= x_Xbe->dwPeHeapReserve; + m_OptionalHeader.m_sizeof_heap_commit= x_Xbe->dwPeHeapCommit; + m_OptionalHeader.m_sizeof_image= x_Xbe-> dwPeSizeofImage; + //dwPeChecksum Is this needed? + m_Header.m_timedate=X_Xbe->dwPeTimeDate; + } + + + } + +} + + // constructor initialization void Exe::ConstructorInit() { diff --git a/tools/cxbe/Exe.h b/tools/cxbe/Exe.h index 42da78808..8739124aa 100644 --- a/tools/cxbe/Exe.h +++ b/tools/cxbe/Exe.h @@ -15,6 +15,9 @@ class Exe : public Error public: // construct via Exe file Exe(const char *x_szFilename); + + // Construct via Xbe file + Exe(class Xbe *x_Xbe, const char *x_szTitle, bool x_bRetail); // deconstructor ~Exe(); From 12700937ad3924d050819e1b62f1f325ef3f9591 Mon Sep 17 00:00:00 2001 From: MariaWitch <77745122+mariaWitch@users.noreply.github.com> Date: Mon, 20 Feb 2023 11:16:45 -0500 Subject: [PATCH 2/3] Finalize trivial header structures --- tools/cxbe/Exe.cpp | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/tools/cxbe/Exe.cpp b/tools/cxbe/Exe.cpp index 95d451faa..e2947922d 100644 --- a/tools/cxbe/Exe.cpp +++ b/tools/cxbe/Exe.cpp @@ -182,7 +182,7 @@ Exe::Exe(const char *x_szFilename) return; } -Exe(class Xbe *x_Xbe, const char *x_szTitle, bool x_bRetail) { +Exe::Exe(class Xbe *x_Xbe, const char *x_szTitle, bool x_bRetail) { ConstructorInit(); @@ -196,17 +196,48 @@ Exe(class Xbe *x_Xbe, const char *x_szTitle, bool x_bRetail) { { //standard Pe magic Number m_Header.m_magic = *(uint32 *)"PE\0\0"; + //always i386 + m_Header.m_machine= IMAGE_FILE_MACHINE_I386; //m_Header.dwBaseAddr = 0x00010000; //we want the same number of sections as our xbe file - m_Header.m_sections= x_Xbe->dwSections; + m_Header.m_sections= (uint16) x_Xbe->m_Header.dwSections; + //magic number + m_Header.m_characteristics = 0x010F; //ripped from EmuExe.cpp + + + //copies of various same header values { - m_Header.m_OptionalHeader.m_sizeof_stack_reserve = x_Xbe->dwPeStackCommit; - m_Header.m_OptionalHeader.m_sizeof_heap_reserve= x_Xbe->dwPeHeapReserve; - m_OptionalHeader.m_sizeof_heap_commit= x_Xbe->dwPeHeapCommit; - m_OptionalHeader.m_sizeof_image= x_Xbe-> dwPeSizeofImage; + m_OptionalHeader.m_sizeof_stack_reserve = x_Xbe->m_Header.dwPeStackCommit; + m_OptionalHeader.m_sizeof_heap_reserve= x_Xbe->m_Header.dwPeHeapReserve; + m_OptionalHeader.m_sizeof_heap_commit= x_Xbe->m_Header.dwPeHeapCommit; + m_OptionalHeader.m_sizeof_image= x_Xbe-> m_Header.dwPeSizeofImage; //dwPeChecksum Is this needed? - m_Header.m_timedate=X_Xbe->dwPeTimeDate; + m_Header.m_timedate=x_Xbe->m_Header.dwPeTimeDate; + m_OptionalHeader.m_image_base= x_Xbe->m_Header.dwBaseAddr; + + } + // optional header init + { + m_Header.m_sizeof_optional_header =sizeof(OptionalHeader); + m_OptionalHeader.m_magic=0x010B; + m_OptionalHeader.m_file_alignment= PE_FILE_ALIGN; + m_OptionalHeader.m_section_alignment= PE_SEGM_ALIGN; + m_OptionalHeader.m_sizeof_headers= sizeof (bzDOSStub)+ sizeof(m_Header); + m_OptionalHeader.m_sizeof_headers += sizeof (m_OptionalHeader)+ sizeof(*m_SectionHeader)*m_Header.m_sections; + m_OptionalHeader.m_sizeof_headers = RoundUp(m_OptionalHeader.m_sizeof_headers, PE_FILE_ALIGN); + m_OptionalHeader.m_data_directories = 0x10; + } + + printf("OK\n"); + printf("Exe::Exe: Pass 2 (Calculating Requirements)..."); + + //pass 2 + { + // make-room cursor + uint32 mrc = m_OptionalHeader.m_image_base + sizeof(m_Header+m_OptionalHeader); // This seems more logical than just m_Header + + } From c49e87835ca6a22bc5ce0d6e5aad6cdcd92a2459 Mon Sep 17 00:00:00 2001 From: MariaWitch <77745122+mariaWitch@users.noreply.github.com> Date: Mon, 20 Feb 2023 12:47:38 -0500 Subject: [PATCH 3/3] Fixed misc errors. --- tools/cxbe/Exe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cxbe/Exe.cpp b/tools/cxbe/Exe.cpp index e2947922d..158e045a1 100644 --- a/tools/cxbe/Exe.cpp +++ b/tools/cxbe/Exe.cpp @@ -235,7 +235,7 @@ Exe::Exe(class Xbe *x_Xbe, const char *x_szTitle, bool x_bRetail) { //pass 2 { // make-room cursor - uint32 mrc = m_OptionalHeader.m_image_base + sizeof(m_Header+m_OptionalHeader); // This seems more logical than just m_Header + uint32 mrc = m_OptionalHeader.m_image_base + sizeof(m_Header) + sizeof(m_OptionalHeader) ; // This seems more logical than just m_Header }