Skip to content

Commit

Permalink
Merge pull request RPCS3#9 from Hykem/master
Browse files Browse the repository at this point in the history
Add SELF decryption and ELF32 little endian support
  • Loading branch information
DHrpcs3 committed Oct 28, 2013
2 parents 5874a56 + 198d0a2 commit 6622dc4
Show file tree
Hide file tree
Showing 39 changed files with 10,231 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

*.log
*.exe
*.dll
*.elf
*.lastbuildstate
*.unsuccessfulbuild
Expand All @@ -39,4 +40,5 @@
/bin/VertexProgram.txt
/bin/BreakPoints.dat
/bin/textures
/bin/data/
rpcs3/git-version.h
32 changes: 32 additions & 0 deletions rpcs3.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,38 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "stblib", "stblib", "{9D839D
stblib\stb_image.h = stblib\stb_image.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scetool", "scetool", "{AB33A31B-6D15-45E8-B292-D512DEF0A5B1}"
ProjectSection(SolutionItems) = preProject
scetool\aes.c = scetool\aes.c
scetool\aes.h = scetool\aes.h
scetool\aes_omac.h = scetool\aes_omac.h
scetool\bn.cpp = scetool\bn.cpp
scetool\config.h = scetool\config.h
scetool\ecdsa.h = scetool\ecdsa.h
scetool\elf.h = scetool\elf.h
scetool\elf_inlines.h = scetool\elf_inlines.h
scetool\frontend.h = scetool\frontend.h
scetool\getopt.c = scetool\getopt.c
scetool\getopt.h = scetool\getopt.h
scetool\keys.h = scetool\keys.h
scetool\list.h = scetool\list.h
scetool\mt19937.h = scetool\mt19937.h
scetool\np.h = scetool\np.h
scetool\rvk.h = scetool\rvk.h
scetool\sce.h = scetool\sce.h
scetool\sce_inlines.h = scetool\sce_inlines.h
scetool\scetool.cpp = scetool\scetool.cpp
scetool\self.h = scetool\self.h
scetool\sha1.c = scetool\sha1.c
scetool\sha1.h = scetool\sha1.h
scetool\spp.h = scetool\spp.h
scetool\tables.h = scetool\tables.h
scetool\types.h = scetool\types.h
scetool\util.h = scetool\util.h
scetool\zconf.h = scetool\zconf.h
scetool\zlib.h = scetool\zlib.h
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Emulator::CheckStatus()
void Emulator::Load()
{
if(!wxFileExists(m_path)) return;
ConLog.Write("loading '%s'...", m_path);
ConLog.Write("Loading '%s'...", m_path);
Memory.Init();
GetInfo().Reset();
m_vfs.Init(m_path);
Expand Down Expand Up @@ -322,7 +322,7 @@ void Emulator::LoadPoints(const wxString& path)
if(version != bpdb_version ||
(sizeof(u16) + break_count * sizeof(u64) + sizeof(u32) + marked_count * sizeof(u64) + sizeof(u32)) != f.Length())
{
ConLog.Error("'%s' is borken", path);
ConLog.Error("'%s' is broken", path);
return;
}

Expand Down
92 changes: 92 additions & 0 deletions rpcs3/Gui/AboutDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
class AboutDialog
: public wxDialog
{
enum
{
b_id_website,
b_id_forum
};

public:
AboutDialog(wxWindow *parent);

void OpenWebsite(wxCommandEvent& WXUNUSED(event));
void OpenForum(wxCommandEvent& WXUNUSED(event));
};

AboutDialog::AboutDialog(wxWindow *parent)
: wxDialog(parent, wxID_ANY, "About RPCS3", wxDefaultPosition)
{
wxBoxSizer* s_panel(new wxBoxSizer(wxVERTICAL));

//Logo
wxPanel* s_panel_logo(new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(512,92)));
s_panel_logo->SetBackgroundColour(wxColor(100,100,100));

wxStaticText* t_name = new wxStaticText(this, wxID_ANY, "RPCS3");
t_name->SetFont(wxFont(28, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
t_name->SetBackgroundColour(wxColor(100,100,100));
t_name->SetForegroundColour(wxColor(255,255,255));
t_name->SetPosition(wxPoint(10,6));

wxStaticText* t_descr = new wxStaticText(this, wxID_ANY, "An early but promising PS3 emulator and debugger.");
t_descr->SetBackgroundColour(wxColor(100,100,100));
t_descr->SetForegroundColour(wxColor(255,255,255));
t_descr->SetPosition(wxPoint(12,50));

#ifdef _DEBUG
wxStaticText* t_version = new wxStaticText(this, wxID_ANY, wxString::Format("Version: " _PRGNAME_ " git-" RPCS3_GIT_VERSION));
#else
wxStaticText* t_version = new wxStaticText(this, wxID_ANY, wxString::Format("Version: " _PRGNAME_ " " _PRGVER_));
#endif
t_version->SetBackgroundColour(wxColor(100,100,100));
t_version->SetForegroundColour(wxColor(200,200,200));
t_version->SetPosition(wxPoint(12,66));

//Credits
wxBoxSizer* s_panel_credits(new wxBoxSizer(wxHORIZONTAL));
wxStaticText* t_section1 = new wxStaticText(this, wxID_ANY, "\nDevelopers:\n\n - To be written...\n", wxDefaultPosition, wxSize(156,160));
wxStaticText* t_section2 = new wxStaticText(this, wxID_ANY, "\nThanks:\n\n - To be written...\n", wxDefaultPosition, wxSize(156,160));
wxStaticText* t_section3 = new wxStaticText(this, wxID_ANY, "\nExternal code:\n\n - SELF Decrypter based on scetool (C) 2011-2013 by naehrwert", wxDefaultPosition, wxSize(156,160));
s_panel_credits->AddSpacer(12);
s_panel_credits->Add(t_section1);
s_panel_credits->AddSpacer(8);
s_panel_credits->Add(t_section2);
s_panel_credits->AddSpacer(8);
s_panel_credits->Add(t_section3);
s_panel_credits->AddSpacer(12);

//Buttons
wxBoxSizer* s_panel_buttons(new wxBoxSizer(wxHORIZONTAL));
wxButton* b_website = new wxButton(this, b_id_website, "Website");
wxButton* b_forum = new wxButton(this, b_id_forum, "Forum");
Connect(b_id_website, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AboutDialog::OpenWebsite));
Connect(b_id_forum, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AboutDialog::OpenForum));
b_website->Disable();

s_panel_buttons->AddSpacer(12);
s_panel_buttons->Add(new wxButton(this, wxID_OK), wxLEFT, 0, 5);
s_panel_buttons->AddSpacer(256);
s_panel_buttons->Add(b_website, wxLEFT, 0, 5);
s_panel_buttons->AddSpacer(5);
s_panel_buttons->Add(b_forum, wxLEFT, 0, 5);
s_panel_buttons->AddSpacer(12);

//Panels
s_panel->Add(s_panel_logo);
s_panel->Add(s_panel_credits);
s_panel->Add(s_panel_buttons);

this->SetSizerAndFit(s_panel);
this->SetSize(this->GetSize()-wxSize(0,220));
}

void AboutDialog::OpenWebsite(wxCommandEvent& WXUNUSED(event))
{
wxLaunchDefaultBrowser("http://www.emunewz.net/forum/forumdisplay.php?fid=162");
}

void AboutDialog::OpenForum(wxCommandEvent& WXUNUSED(event))
{
wxLaunchDefaultBrowser("http://www.emunewz.net/forum/forumdisplay.php?fid=162");
}
35 changes: 28 additions & 7 deletions rpcs3/Gui/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
#include "Emu/GS/sysutil_video.h"
#include "Gui/VHDDManager.h"
#include "Gui/VFSManager.h"
#include "Gui/AboutDialog.cpp"
#include <wx/dynlib.h>

#include "scetool/scetool.cpp"

BEGIN_EVENT_TABLE(MainFrame, FrameBase)
EVT_CLOSE(MainFrame::OnQuit)
END_EVENT_TABLE()
Expand All @@ -26,6 +29,7 @@ enum IDs
id_config_emu,
id_config_vfs_manager,
id_config_vhdd_manager,
id_help_about,
id_update_dbg,
};

Expand Down Expand Up @@ -53,15 +57,17 @@ MainFrame::MainFrame()
wxMenu& menu_boot(*new wxMenu());
wxMenu& menu_sys(*new wxMenu());
wxMenu& menu_conf(*new wxMenu());
wxMenu& menu_help(*new wxMenu());

menubar.Append(&menu_boot, "Boot");
menubar.Append(&menu_sys, "System");
menubar.Append(&menu_conf, "Config");
menubar.Append(&menu_help, "Help");

menu_boot.Append(id_boot_game, "Boot game");
menu_boot.AppendSeparator();
menu_boot.Append(id_boot_elf, "Boot Elf");
//menu_boot.Append(id_boot_self, "Boot Self");
menu_boot.Append(id_boot_elf, "Boot ELF");
menu_boot.Append(id_boot_self, "Boot SELF");

menu_sys.Append(id_sys_pause, "Pause")->Enable(false);
menu_sys.Append(id_sys_stop, "Stop\tCtrl + S")->Enable(false);
Expand All @@ -74,6 +80,8 @@ MainFrame::MainFrame()
menu_conf.Append(id_config_vfs_manager, "Virtual File System Manager");
menu_conf.Append(id_config_vhdd_manager, "Virtual HDD Manager");

menu_help.Append(id_help_about, "About...");

SetMenuBar(&menubar);

m_game_viewer = new GameViewer(this);
Expand All @@ -92,6 +100,8 @@ MainFrame::MainFrame()
Connect( id_config_vfs_manager, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::ConfigVFS) );
Connect( id_config_vhdd_manager,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::ConfigVHDD) );

Connect( id_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::AboutDialogHandler) );

Connect( id_update_dbg, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::UpdateUI) );

m_app_connector.Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainFrame::OnKeyDown), (wxObject*)0, this);
Expand Down Expand Up @@ -188,14 +198,14 @@ void MainFrame::BootElf(wxCommandEvent& WXUNUSED(event))
return;
}

ConLog.Write("Elf: booting...");
ConLog.Write("ELF: booting...");

Emu.Stop();

Emu.SetPath(ctrl.GetPath());
Emu.Load();

ConLog.Write("Elf: boot done.");
ConLog.Write("ELF: boot done.");
}

void MainFrame::BootSelf(wxCommandEvent& WXUNUSED(event))
Expand All @@ -220,9 +230,15 @@ void MainFrame::BootSelf(wxCommandEvent& WXUNUSED(event))
ConLog.Write("SELF: booting...");

Emu.Stop();

wxString fileIn = ctrl.GetPath();
wxString fileOut = ctrl.GetPath()+".elf";
scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str());

Emu.SetPath(ctrl.GetPath());
Emu.SetPath(ctrl.GetPath()+".elf");
Emu.Load();
if (!wxRemoveFile(ctrl.GetPath()+".elf"))
ConLog.Warning("Could not delete the decrypted ELF file");

ConLog.Write("SELF: boot done.");
}
Expand Down Expand Up @@ -323,11 +339,11 @@ void MainFrame::Config(wxCommandEvent& WXUNUSED(event))

cbox_keyboard_handler->Append("Null");
cbox_keyboard_handler->Append("Windows");
//cbox_pad_handler->Append("DirectInput");
//cbox_keyboard_handler->Append("DirectInput");

cbox_mouse_handler->Append("Null");
cbox_mouse_handler->Append("Windows");
//cbox_pad_handler->Append("DirectInput");
//cbox_mouse_handler->Append("DirectInput");

chbox_gs_vsync->SetValue(Ini.GSVSyncEnable.GetValue());

Expand Down Expand Up @@ -402,6 +418,11 @@ void MainFrame::ConfigVHDD(wxCommandEvent& WXUNUSED(event))
VHDDManagerDialog(this).ShowModal();
}

void MainFrame::AboutDialogHandler(wxCommandEvent& WXUNUSED(event))
{
AboutDialog(this).ShowModal();
}

void MainFrame::UpdateUI(wxCommandEvent& event)
{
event.Skip();
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Gui/MainFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MainFrame : public FrameBase
void Config(wxCommandEvent& event);
void ConfigVFS(wxCommandEvent& event);
void ConfigVHDD(wxCommandEvent& event);
void AboutDialogHandler(wxCommandEvent& event);
void UpdateUI(wxCommandEvent& event);
void OnKeyDown(wxKeyEvent& event);

Expand Down
26 changes: 19 additions & 7 deletions rpcs3/Loader/ELF32.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "stdafx.h"
#include "ELF32.h"

bool isLittleEndian;

ELF32Loader::ELF32Loader(vfsStream& f)
: elf32_f(f)
, LoaderBase()
Expand Down Expand Up @@ -36,13 +38,21 @@ bool ELF32Loader::Close()

bool ELF32Loader::LoadEhdrInfo()
{
u8 endian;
elf32_f.Seek(5);
elf32_f.Read(&endian, 1);
isLittleEndian = (endian == 0x1);

elf32_f.Reset();
elf32_f.Seek(0);
ehdr.Load(elf32_f);
if (isLittleEndian) ehdr.LoadLE(elf32_f);
else ehdr.Load(elf32_f);

if(!ehdr.CheckMagic()) return false;

switch(ehdr.e_machine)
{
case MACHINE_MIPS:
case MACHINE_PPC64:
case MACHINE_SPU:
machine = (Elf_Machine)ehdr.e_machine;
Expand Down Expand Up @@ -76,7 +86,8 @@ bool ELF32Loader::LoadPhdrInfo()
for(uint i=0; i<ehdr.e_phnum; ++i)
{
Elf32_Phdr* phdr = new Elf32_Phdr();
phdr->Load(elf32_f);
if(isLittleEndian) phdr->LoadLE(elf32_f);
else phdr->Load(elf32_f);
phdr_arr.Move(phdr);
}

Expand All @@ -89,13 +100,14 @@ bool ELF32Loader::LoadShdrInfo()
for(u32 i=0; i<ehdr.e_shnum; ++i)
{
Elf32_Shdr* shdr = new Elf32_Shdr();
shdr->Load(elf32_f);
if(isLittleEndian) shdr->LoadLE(elf32_f);
else shdr->Load(elf32_f);
shdr_arr.Move(shdr);
}

if(ehdr.e_shstrndx >= shdr_arr.GetCount())
{
ConLog.Error("LoadShdr64 error: shstrndx too big!");
ConLog.Error("LoadShdr32 error: shstrndx too big!");
return false;
}

Expand All @@ -110,8 +122,7 @@ bool ELF32Loader::LoadShdrInfo()
if(c == 0) break;
name += c;
}

shdr_name_arr.Add(name);
shdr_name_arr.Add(name);
}

return true;
Expand Down Expand Up @@ -162,7 +173,8 @@ bool ELF32Loader::LoadPhdrData(u64 offset)
{
elf32_f.Seek(phdr_arr[i].p_offset);
Elf32_Note note;
note.Load(elf32_f);
if(isLittleEndian) note.LoadLE(elf32_f);
else note.Load(elf32_f);

if(note.type != 1)
{
Expand Down
Loading

0 comments on commit 6622dc4

Please sign in to comment.