mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 11:39:53 +00:00
ui: Add basic reporting stubs
This commit is contained in:
parent
479070463f
commit
f5a7a90120
@ -39,6 +39,7 @@ sdl.mo-objs := \
|
||||
xemu-net.o \
|
||||
xemu-settings.o \
|
||||
xemu-shaders.o \
|
||||
xemu-reporting.o \
|
||||
|
||||
ui/xemu-shaders.o: ui/shader/xemu-logo-frag.h
|
||||
|
||||
|
4859
ui/httplib.h
Normal file
4859
ui/httplib.h
Normal file
File diff suppressed because it is too large
Load Diff
22875
ui/json.hpp
Normal file
22875
ui/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
133
ui/xemu-hud.cc
133
ui/xemu-hud.cc
@ -34,6 +34,7 @@
|
||||
#include "xemu-net.h"
|
||||
#include "xemu-os-utils.h"
|
||||
#include "xemu-xbe.h"
|
||||
#include "xemu-reporting.h"
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
#include "imgui/examples/imgui_impl_sdl.h"
|
||||
@ -940,11 +941,32 @@ const char *get_cpu_info(void)
|
||||
class CompatibilityReporter
|
||||
{
|
||||
public:
|
||||
CompatibilityReport report;
|
||||
bool dirty;
|
||||
bool is_open;
|
||||
std::string serialized_report;
|
||||
|
||||
CompatibilityReporter()
|
||||
{
|
||||
is_open = false;
|
||||
|
||||
report.token = "";
|
||||
report.xemu_version = xemu_version;
|
||||
report.xemu_branch = xemu_branch;
|
||||
report.xemu_commit = xemu_commit;
|
||||
report.xemu_date = xemu_date;
|
||||
#if defined(__linux__)
|
||||
report.os_platform = "Linux";
|
||||
#elif defined(_WIN32)
|
||||
report.os_platform = "Windows";
|
||||
#elif defined(__APPLE__)
|
||||
report.os_platform = "macOS";
|
||||
#else
|
||||
report.os_platform = "Unknown";
|
||||
#endif
|
||||
report.os_version = xemu_get_os_info();
|
||||
report.cpu = get_cpu_info();
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
~CompatibilityReporter()
|
||||
@ -958,58 +980,25 @@ public:
|
||||
ImVec2 size(450*g_ui_scale, 475*g_ui_scale);
|
||||
|
||||
ImGui::SetNextWindowSize(size, ImGuiCond_Appearing);
|
||||
if (!ImGui::Begin("Report Compatibility", &is_open, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse)) {
|
||||
if (!ImGui::Begin("Report Compatibility", &is_open, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
static char gpu_info[1024];
|
||||
static char xbe_info[512];
|
||||
static char report_info[4096];
|
||||
static int report_info_initialized = 0;
|
||||
|
||||
if (ImGui::IsWindowAppearing()) {
|
||||
// Refresh whenever the window is re-opened
|
||||
report_info_initialized = 0;
|
||||
}
|
||||
|
||||
if (!report_info_initialized) {
|
||||
struct xbe_info *xbe = xemu_get_xbe_info();
|
||||
snprintf(
|
||||
gpu_info,
|
||||
sizeof(gpu_info),
|
||||
"%s, %s, %s, %s",
|
||||
glGetString(GL_VENDOR),
|
||||
glGetString(GL_RENDERER),
|
||||
glGetString(GL_VERSION),
|
||||
glGetString(GL_SHADING_LANGUAGE_VERSION)
|
||||
);
|
||||
|
||||
if (xbe) {
|
||||
snprintf(xbe_info, sizeof(xbe_info),
|
||||
"%s v1.%02d", xbe->cert_title_id_str, xbe->cert_version);
|
||||
} else {
|
||||
xbe_info[0] = '\x00';
|
||||
report.gl_vendor = (const char *)glGetString(GL_VENDOR);
|
||||
report.gl_renderer = (const char *)glGetString(GL_RENDERER);
|
||||
report.gl_version = (const char *)glGetString(GL_VERSION);
|
||||
report.gl_shading_language_version = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
struct xbe_info *xbe = xemu_get_xbe_info();
|
||||
if (xbe != NULL) {
|
||||
report.xbe_timestamp = xbe->timedate;
|
||||
report.xbe_cert_timestamp = xbe->cert_timedate;
|
||||
report.xbe_cert_title_id = xbe->cert_title_id;
|
||||
report.xbe_cert_region = xbe->cert_region;
|
||||
report.xbe_cert_disc_num = xbe->cert_disc_num;
|
||||
report.xbe_cert_version = xbe->cert_version;
|
||||
}
|
||||
|
||||
snprintf(
|
||||
report_info,
|
||||
sizeof(report_info),
|
||||
"xemu: %s [branch %s on %s]\n"
|
||||
"OS: %s\n"
|
||||
"CPU: %s\n"
|
||||
"GPU: %s\n"
|
||||
"XBE: %s",
|
||||
xemu_version,
|
||||
xemu_branch,
|
||||
xemu_date,
|
||||
xemu_get_os_info(),
|
||||
get_cpu_info(),
|
||||
gpu_info,
|
||||
xbe_info
|
||||
);
|
||||
|
||||
report_info_initialized = 1;
|
||||
}
|
||||
|
||||
ImGui::TextWrapped(
|
||||
@ -1025,19 +1014,21 @@ public:
|
||||
|
||||
ImGui::Columns(2, "", false);
|
||||
ImGui::SetColumnWidth(0, ImGui::GetWindowWidth()*0.25);
|
||||
|
||||
char buf[64];
|
||||
buf[0] = '\x00';
|
||||
|
||||
ImGui::Text("User Token");
|
||||
ImGui::SameLine();
|
||||
HelpMarker("Optional. This is a unique token that users may "
|
||||
"provide in order to expedite publication of their compatibility "
|
||||
"reports.");
|
||||
"reports. If a token is not provided, reports will be published "
|
||||
"with submitters public IP address.");
|
||||
ImGui::NextColumn();
|
||||
float item_width = ImGui::GetColumnWidth()-20*g_ui_scale;
|
||||
ImGui::SetNextItemWidth(item_width*0.70);
|
||||
ImGui::InputText("###UserToken", buf, sizeof(buf), 0);
|
||||
static char token_buf[512] = {0};
|
||||
if (ImGui::InputText("###UserToken", token_buf, sizeof(token_buf), 0)) {
|
||||
report.token = token_buf;
|
||||
dirty = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Get Token")) {
|
||||
xemu_open_web_browser("https://xemu.app");
|
||||
@ -1048,28 +1039,48 @@ public:
|
||||
ImGui::NextColumn();
|
||||
static int playability;
|
||||
ImGui::SetNextItemWidth(item_width);
|
||||
ImGui::Combo("###PlayabilityRating", &playability,
|
||||
"Unknown\0" "Broken\0" "Intro/Menus\0" "Starts\0" "Playable\0" "Perfect\0");
|
||||
const char *playability_names[] = {
|
||||
"Unknown",
|
||||
"Broken",
|
||||
"Intro/Menus",
|
||||
"Starts",
|
||||
"Playable",
|
||||
"Perfect",
|
||||
};
|
||||
if (ImGui::Combo("###PlayabilityRating", &playability,
|
||||
"Unknown\0" "Broken\0" "Intro/Menus\0" "Starts\0" "Playable\0" "Perfect\0")) {
|
||||
report.compat_rating = playability_names[playability];
|
||||
dirty = true;
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
|
||||
ImGui::Columns(1);
|
||||
|
||||
char description[255] = {0};
|
||||
static char description[1024] = {0};
|
||||
ImGui::Text("Description");
|
||||
ImGui::InputTextMultiline("###desc", description, sizeof(description), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 6), 0);
|
||||
if (ImGui::InputTextMultiline("###desc", description, sizeof(description), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 6), 0)) {
|
||||
report.compat_comments = description;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
ImGui::Text("Additional Information");
|
||||
ImGui::PushFont(g_fixed_width_font);
|
||||
ImGui::InputTextMultiline("##build_info", report_info, sizeof(report_info), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 7), ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::PopFont();
|
||||
if (ImGui::TreeNode("Full Report Information")) {
|
||||
ImGui::PushFont(g_fixed_width_font);
|
||||
if (dirty) {
|
||||
serialized_report = report.GetSerializedReport();
|
||||
dirty = false;
|
||||
}
|
||||
ImGui::InputTextMultiline("##build_info", (char*)serialized_report.c_str(), strlen(serialized_report.c_str())+1, ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 7), ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::PopFont();
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
ImGui::Columns(1);
|
||||
|
||||
ImGui::SetCursorPosY(ImGui::GetWindowHeight()-(10+25)*g_ui_scale);
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowWidth()-(120+10)*g_ui_scale);
|
||||
|
||||
ImGui::SetItemDefaultFocus();
|
||||
if (ImGui::Button("Send", ImVec2(120*g_ui_scale, 0))) {
|
||||
report.Send();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
@ -1085,8 +1096,6 @@ static CompatibilityReporter compatibility_reporter_window;
|
||||
static NotificationManager notification_manager;
|
||||
static std::deque<const char *> g_errors;
|
||||
|
||||
|
||||
|
||||
class FirstBootWindow
|
||||
{
|
||||
public:
|
||||
|
76
ui/xemu-reporting.cc
Normal file
76
ui/xemu-reporting.cc
Normal file
@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include "xemu-reporting.h"
|
||||
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT 1
|
||||
#include "httplib.h"
|
||||
|
||||
#include "json.hpp"
|
||||
using json = nlohmann::json;
|
||||
|
||||
CompatibilityReport::CompatibilityReport()
|
||||
{
|
||||
}
|
||||
|
||||
CompatibilityReport::~CompatibilityReport()
|
||||
{
|
||||
}
|
||||
|
||||
const std::string &CompatibilityReport::GetSerializedReport()
|
||||
{
|
||||
json report = {
|
||||
{"token", token},
|
||||
{"xemu_version", xemu_version},
|
||||
{"xemu_branch", xemu_branch},
|
||||
{"xemu_commit", xemu_commit},
|
||||
{"xemu_date", xemu_date},
|
||||
{"os_platform", os_platform},
|
||||
{"os_version", os_version},
|
||||
{"cpu", cpu},
|
||||
{"gl_vendor", gl_vendor},
|
||||
{"gl_renderer", gl_renderer},
|
||||
{"gl_version", gl_version},
|
||||
{"gl_shading_language_version", gl_shading_language_version},
|
||||
{"memory", memory},
|
||||
{"xbe_timestamp", xbe_timestamp},
|
||||
{"xbe_cert_timestamp", xbe_cert_timestamp},
|
||||
{"xbe_cert_title_id", xbe_cert_title_id},
|
||||
{"xbe_cert_region", xbe_cert_region},
|
||||
{"xbe_cert_disc_num", xbe_cert_disc_num},
|
||||
{"xbe_cert_version", xbe_cert_version},
|
||||
{"compat_rating", compat_rating},
|
||||
{"compat_comments", compat_comments},
|
||||
};
|
||||
serialized = report.dump(2);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
void CompatibilityReport::Send()
|
||||
{
|
||||
// Serialize the report
|
||||
const std::string &s = GetSerializedReport();
|
||||
|
||||
fprintf(stderr, "%s\n", s.c_str());
|
||||
|
||||
httplib::SSLClient cli("127.0.0.1", 443);
|
||||
// httplib::SSLClient cli("reports.xemu.app", 443);
|
||||
|
||||
cli.set_follow_location(true);
|
||||
cli.set_timeout_sec(5);
|
||||
// cli.enable_server_certificate_verification(true); // FIXME: Package cert bundle
|
||||
|
||||
auto res = cli.Post("/compatibility", s, "application/json");
|
||||
|
||||
if (!res) {
|
||||
#if 0 // FIXME: Handle SSL certificate verification failure
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
auto result = cli.get_openssl_verify_result();
|
||||
if (result) {
|
||||
fprintf(stderr, "verify error: %s\n", X509_verify_cert_error_string(result));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%d\n", res->status);
|
||||
}
|
61
ui/xemu-reporting.h
Normal file
61
ui/xemu-reporting.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* xemu Reporting
|
||||
*
|
||||
* Title compatibility and bug report submission.
|
||||
*
|
||||
* Copyright (C) 2020 Matt Borgerson
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XEMU_REPORTING_H
|
||||
#define XEMU_REPORTING_H
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
class CompatibilityReport {
|
||||
public:
|
||||
std::string token;
|
||||
std::string xemu_version;
|
||||
std::string xemu_branch;
|
||||
std::string xemu_commit;
|
||||
std::string xemu_date;
|
||||
std::string os_platform;
|
||||
std::string os_version;
|
||||
std::string cpu;
|
||||
std::string gl_vendor;
|
||||
std::string gl_renderer;
|
||||
std::string gl_version;
|
||||
std::string gl_shading_language_version;
|
||||
std::string memory;
|
||||
uint32_t xbe_timestamp;
|
||||
uint32_t xbe_cert_timestamp;
|
||||
uint32_t xbe_cert_title_id;
|
||||
uint32_t xbe_cert_region;
|
||||
uint32_t xbe_cert_disc_num;
|
||||
uint32_t xbe_cert_version;
|
||||
std::string compat_rating;
|
||||
std::string compat_comments;
|
||||
|
||||
std::string serialized;
|
||||
|
||||
public:
|
||||
CompatibilityReport();
|
||||
~CompatibilityReport();
|
||||
void Send();
|
||||
const std::string &GetSerializedReport();
|
||||
};
|
||||
|
||||
#endif
|
171
xemu-xbe.c
171
xemu-xbe.c
@ -6,72 +6,8 @@
|
||||
#include "monitor/hmp-target.h"
|
||||
#include "sysemu/hw_accel.h"
|
||||
|
||||
#if 0
|
||||
// http://www.caustik.com/cxbx/download/xbe.htm
|
||||
struct xbe_header
|
||||
{
|
||||
uint32_t m_magic; // magic number [should be "XBEH"]
|
||||
uint8_t m_digsig[256]; // digital signature
|
||||
uint32_t m_base; // base address
|
||||
uint32_t m_sizeof_headers; // size of headers
|
||||
uint32_t m_sizeof_image; // size of image
|
||||
uint32_t m_sizeof_image_header; // size of image header
|
||||
uint32_t m_timedate; // timedate stamp
|
||||
uint32_t m_certificate_addr; // certificate address
|
||||
uint32_t m_sections; // number of sections
|
||||
uint32_t m_section_headers_addr; // section headers address
|
||||
|
||||
struct init_flags
|
||||
{
|
||||
uint32_t m_mount_utility_drive : 1; // mount utility drive flag
|
||||
uint32_t m_format_utility_drive : 1; // format utility drive flag
|
||||
uint32_t m_limit_64mb : 1; // limit development kit run time memory to 64mb flag
|
||||
uint32_t m_dont_setup_harddisk : 1; // don't setup hard disk flag
|
||||
uint32_t m_unused : 4; // unused (or unknown)
|
||||
uint32_t m_unused_b1 : 8; // unused (or unknown)
|
||||
uint32_t m_unused_b2 : 8; // unused (or unknown)
|
||||
uint32_t m_unused_b3 : 8; // unused (or unknown)
|
||||
} m_init_flags;
|
||||
|
||||
uint32_t m_entry; // entry point address
|
||||
uint32_t m_tls_addr; // thread local storage directory address
|
||||
uint32_t m_pe_stack_commit; // size of stack commit
|
||||
uint32_t m_pe_heap_reserve; // size of heap reserve
|
||||
uint32_t m_pe_heap_commit; // size of heap commit
|
||||
uint32_t m_pe_base_addr; // original base address
|
||||
uint32_t m_pe_sizeof_image; // size of original image
|
||||
uint32_t m_pe_checksum; // original checksum
|
||||
uint32_t m_pe_timedate; // original timedate stamp
|
||||
uint32_t m_debug_pathname_addr; // debug pathname address
|
||||
uint32_t m_debug_filename_addr; // debug filename address
|
||||
uint32_t m_debug_unicode_filename_addr; // debug unicode filename address
|
||||
uint32_t m_kernel_image_thunk_addr; // kernel image thunk address
|
||||
uint32_t m_nonkernel_import_dir_addr; // non kernel import directory address
|
||||
uint32_t m_library_versions; // number of library versions
|
||||
uint32_t m_library_versions_addr; // library versions address
|
||||
uint32_t m_kernel_library_version_addr; // kernel library version address
|
||||
uint32_t m_xapi_library_version_addr; // xapi library version address
|
||||
uint32_t m_logo_bitmap_addr; // logo bitmap address
|
||||
uint32_t m_logo_bitmap_size; // logo bitmap size
|
||||
};
|
||||
|
||||
struct xbe_certificate
|
||||
{
|
||||
uint32_t m_size; // size of certificate
|
||||
uint32_t m_timedate; // timedate stamp
|
||||
uint32_t m_titleid; // title id
|
||||
uint16_t m_title_name[40]; // title name (unicode)
|
||||
uint32_t m_alt_title_id[0x10]; // alternate title ids
|
||||
uint32_t m_allowed_media; // allowed media types
|
||||
uint32_t m_game_region; // game region
|
||||
uint32_t m_game_ratings; // game ratings
|
||||
uint32_t m_disk_number; // disk number
|
||||
uint32_t m_version; // version
|
||||
uint8_t m_lan_key[16]; // lan key
|
||||
uint8_t m_sig_key[16]; // signature key
|
||||
uint8_t m_title_alt_sig_key[16][16]; // alternate signature keys
|
||||
};
|
||||
#endif
|
||||
// #include "base64/base64.h"
|
||||
// #include "base64/base64.c"
|
||||
|
||||
static int virt_to_phys(target_ulong virt_addr, hwaddr *phys_addr)
|
||||
{
|
||||
@ -96,54 +32,99 @@ static int virt_to_phys(target_ulong virt_addr, hwaddr *phys_addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t virt_dma_memory_read(vaddr vaddr, void *buf, size_t len)
|
||||
{
|
||||
size_t num_bytes_read = 0;
|
||||
|
||||
while (num_bytes_read < len) {
|
||||
// Get physical page for this offset
|
||||
hwaddr phys_addr = 0;
|
||||
if (virt_to_phys(vaddr+num_bytes_read, &phys_addr) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read contents from the page
|
||||
size_t bytes_in_chunk = (len-num_bytes_read) & (TARGET_PAGE_SIZE-1);
|
||||
// FIXME: Check return value
|
||||
dma_memory_read(&address_space_memory, phys_addr, buf + num_bytes_read, bytes_in_chunk);
|
||||
|
||||
num_bytes_read += bytes_in_chunk;
|
||||
}
|
||||
|
||||
return num_bytes_read;
|
||||
}
|
||||
|
||||
// Get current XBE info
|
||||
struct xbe_info *xemu_get_xbe_info(void)
|
||||
{
|
||||
static struct xbe_info xbe_info;
|
||||
hwaddr hdr_addr;
|
||||
vaddr xbe_hdr_addr_virt = 0x10000;
|
||||
|
||||
// Get physical page offset of headers
|
||||
if (virt_to_phys(0x10000, &hdr_addr) != 0) {
|
||||
static struct xbe_info xbe_info;
|
||||
|
||||
if (xbe_info.headers) {
|
||||
free(xbe_info.headers);
|
||||
xbe_info.headers = NULL;
|
||||
}
|
||||
|
||||
// Get physical page of headers
|
||||
hwaddr hdr_addr_phys = 0;
|
||||
if (virt_to_phys(xbe_hdr_addr_virt, &hdr_addr_phys) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check signature
|
||||
uint32_t sig = ldl_le_phys(&address_space_memory, hdr_addr);
|
||||
// Check `XBEH` signature
|
||||
uint32_t sig = ldl_le_phys(&address_space_memory, hdr_addr_phys);
|
||||
if (sig != 0x48454258) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xbe_info.timedate = ldl_le_phys(&address_space_memory, hdr_addr+0x114);
|
||||
|
||||
// Find certificate (likely on same page, but be safe and map it)
|
||||
uint32_t cert_addr_virt = ldl_le_phys(&address_space_memory, hdr_addr+0x118);
|
||||
if (cert_addr_virt == 0) {
|
||||
// Determine full length of headers
|
||||
xbe_info.headers_len = ldl_le_phys(&address_space_memory,
|
||||
hdr_addr_phys + offsetof(struct xbe_header, m_sizeof_headers));
|
||||
if (xbe_info.headers_len > 4*TARGET_PAGE_SIZE) {
|
||||
// Headers are unusually large
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hwaddr cert_addr;
|
||||
if (virt_to_phys(cert_addr_virt, &cert_addr) != 0) {
|
||||
xbe_info.headers = malloc(xbe_info.headers_len);
|
||||
assert(xbe_info.headers != NULL);
|
||||
|
||||
// Read all XBE headers
|
||||
ssize_t bytes_read = virt_dma_memory_read(xbe_hdr_addr_virt,
|
||||
xbe_info.headers,
|
||||
xbe_info.headers_len);
|
||||
if (bytes_read != xbe_info.headers_len) {
|
||||
// Failed to read headers
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Extract title info from certificate
|
||||
xbe_info.cert_timedate = ldl_le_phys(&address_space_memory, cert_addr+0x04);
|
||||
xbe_info.cert_title_id = ldl_le_phys(&address_space_memory, cert_addr+0x08);
|
||||
xbe_info.cert_version = ldl_le_phys(&address_space_memory, cert_addr+0xac);
|
||||
// Extract XBE header fields
|
||||
xbe_info.xbe_hdr = (struct xbe_header *)xbe_info.headers;
|
||||
xbe_info.timedate = ldl_le_p(&xbe_info.xbe_hdr->m_timedate);
|
||||
|
||||
// Generate friendly name for title id
|
||||
uint8_t pub_hi = xbe_info.cert_title_id >> 24;
|
||||
uint8_t pub_lo = xbe_info.cert_title_id >> 16;
|
||||
|
||||
if ((65 > pub_hi) || (pub_hi > 90) || (65 > pub_lo) || (pub_lo > 90)) {
|
||||
// Non-printable publisher id
|
||||
snprintf(xbe_info.cert_title_id_str, sizeof(xbe_info.cert_title_id_str),
|
||||
"0x%08x", xbe_info.cert_title_id);
|
||||
} else {
|
||||
// Printable publisher id
|
||||
snprintf(xbe_info.cert_title_id_str, sizeof(xbe_info.cert_title_id_str),
|
||||
"%c%c-%03u", pub_hi, pub_lo, xbe_info.cert_title_id & 0xffff);
|
||||
// Get certificate
|
||||
uint32_t cert_addr_virt = ldl_le_p(&xbe_info.xbe_hdr->m_certificate_addr);
|
||||
if ((cert_addr_virt == 0) || ((cert_addr_virt + sizeof(struct xbe_certificate)) > (xbe_hdr_addr_virt + xbe_info.headers_len))) {
|
||||
// Invalid certificate header (a valid certificate is expected for official titles)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Extract certificate fields
|
||||
xbe_info.xbe_cert = (struct xbe_certificate *)(xbe_info.headers + cert_addr_virt - xbe_hdr_addr_virt);
|
||||
xbe_info.cert_timedate = ldl_le_p(&xbe_info.xbe_cert->m_timedate);
|
||||
xbe_info.cert_title_id = ldl_le_p(&xbe_info.xbe_cert->m_titleid);
|
||||
xbe_info.cert_version = ldl_le_p(&xbe_info.xbe_cert->m_version);
|
||||
xbe_info.cert_region = ldl_le_p(&xbe_info.xbe_cert->m_game_region);
|
||||
xbe_info.cert_disc_num = ldl_le_p(&xbe_info.xbe_cert->m_disk_number);
|
||||
|
||||
#if 0
|
||||
// Dump base64 version of headers
|
||||
FILE *fd = fopen("dump2.bin", "wb");
|
||||
void *b64buf = malloc(xbe_info.headers_len*2);
|
||||
int enc = base64_encode(xbe_info.headers, xbe_info.headers_len, b64buf);
|
||||
fwrite(b64buf, 1, enc, fd);
|
||||
free(b64buf);
|
||||
#endif
|
||||
|
||||
return &xbe_info;
|
||||
}
|
||||
|
79
xemu-xbe.h
79
xemu-xbe.h
@ -24,12 +24,89 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// http://www.caustik.com/cxbx/download/xbe.htm
|
||||
#pragma pack(1)
|
||||
struct xbe_header
|
||||
{
|
||||
uint32_t m_magic; // magic number [should be "XBEH"]
|
||||
uint8_t m_digsig[256]; // digital signature
|
||||
uint32_t m_base; // base address
|
||||
uint32_t m_sizeof_headers; // size of headers
|
||||
uint32_t m_sizeof_image; // size of image
|
||||
uint32_t m_sizeof_image_header; // size of image header
|
||||
uint32_t m_timedate; // timedate stamp
|
||||
uint32_t m_certificate_addr; // certificate address
|
||||
uint32_t m_sections; // number of sections
|
||||
uint32_t m_section_headers_addr; // section headers address
|
||||
|
||||
struct init_flags
|
||||
{
|
||||
uint32_t m_mount_utility_drive : 1; // mount utility drive flag
|
||||
uint32_t m_format_utility_drive : 1; // format utility drive flag
|
||||
uint32_t m_limit_64mb : 1; // limit development kit run time memory to 64mb flag
|
||||
uint32_t m_dont_setup_harddisk : 1; // don't setup hard disk flag
|
||||
uint32_t m_unused : 4; // unused (or unknown)
|
||||
uint32_t m_unused_b1 : 8; // unused (or unknown)
|
||||
uint32_t m_unused_b2 : 8; // unused (or unknown)
|
||||
uint32_t m_unused_b3 : 8; // unused (or unknown)
|
||||
} m_init_flags;
|
||||
|
||||
uint32_t m_entry; // entry point address
|
||||
uint32_t m_tls_addr; // thread local storage directory address
|
||||
uint32_t m_pe_stack_commit; // size of stack commit
|
||||
uint32_t m_pe_heap_reserve; // size of heap reserve
|
||||
uint32_t m_pe_heap_commit; // size of heap commit
|
||||
uint32_t m_pe_base_addr; // original base address
|
||||
uint32_t m_pe_sizeof_image; // size of original image
|
||||
uint32_t m_pe_checksum; // original checksum
|
||||
uint32_t m_pe_timedate; // original timedate stamp
|
||||
uint32_t m_debug_pathname_addr; // debug pathname address
|
||||
uint32_t m_debug_filename_addr; // debug filename address
|
||||
uint32_t m_debug_unicode_filename_addr; // debug unicode filename address
|
||||
uint32_t m_kernel_image_thunk_addr; // kernel image thunk address
|
||||
uint32_t m_nonkernel_import_dir_addr; // non kernel import directory address
|
||||
uint32_t m_library_versions; // number of library versions
|
||||
uint32_t m_library_versions_addr; // library versions address
|
||||
uint32_t m_kernel_library_version_addr; // kernel library version address
|
||||
uint32_t m_xapi_library_version_addr; // xapi library version address
|
||||
uint32_t m_logo_bitmap_addr; // logo bitmap address
|
||||
uint32_t m_logo_bitmap_size; // logo bitmap size
|
||||
};
|
||||
|
||||
struct xbe_certificate
|
||||
{
|
||||
uint32_t m_size; // size of certificate
|
||||
uint32_t m_timedate; // timedate stamp
|
||||
uint32_t m_titleid; // title id
|
||||
uint16_t m_title_name[40]; // title name (unicode)
|
||||
uint32_t m_alt_title_id[0x10]; // alternate title ids
|
||||
uint32_t m_allowed_media; // allowed media types
|
||||
uint32_t m_game_region; // game region
|
||||
uint32_t m_game_ratings; // game ratings
|
||||
uint32_t m_disk_number; // disk number
|
||||
uint32_t m_version; // version
|
||||
uint8_t m_lan_key[16]; // lan key
|
||||
uint8_t m_sig_key[16]; // signature key
|
||||
uint8_t m_title_alt_sig_key[16][16]; // alternate signature keys
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
struct xbe_info {
|
||||
// Typically accessed fields extracted from heeaders
|
||||
uint32_t timedate;
|
||||
uint32_t cert_timedate;
|
||||
uint32_t cert_title_id;
|
||||
char cert_title_id_str[12];
|
||||
uint32_t cert_version;
|
||||
uint32_t cert_region;
|
||||
uint32_t cert_disc_num;
|
||||
|
||||
// Full XBE headers, copied into a temporary buffer
|
||||
uint8_t *headers;
|
||||
uint32_t headers_len;
|
||||
|
||||
// Pointer into `headers` (note: little-endian!)
|
||||
struct xbe_header *xbe_hdr;
|
||||
struct xbe_certificate *xbe_cert;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
Reference in New Issue
Block a user