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

Add XBE->Exe Functionality #626

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion tools/cxbe/Exe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
// SPDX-FileCopyrightText: 2021 Stefan Schmidt

#include "Exe.h"
#include "Xbe.h"

#include <stdio.h>
#include <memory.h>
#include <locale.h>
#include <stdlib.h>
#include <time.h>
#include <cstring>
#include <cstdio>

// construct via Exe file
Exe::Exe(const char *x_szFilename)
Expand Down Expand Up @@ -177,6 +182,70 @@ Exe::Exe(const char *x_szFilename)
return;
}

Exe::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";
//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= (uint16) x_Xbe->m_Header.dwSections;
//magic number
m_Header.m_characteristics = 0x010F; //ripped from EmuExe.cpp



//copies of various same header values
{
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->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) + sizeof(m_OptionalHeader) ; // This seems more logical than just m_Header


}


}

}


// constructor initialization
void Exe::ConstructorInit()
{
Expand Down
3 changes: 3 additions & 0 deletions tools/cxbe/Exe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down