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 work-in-progress xbe-loader, for bootstrapping background tasks #63

Closed
wants to merge 6 commits into from

Conversation

JayFoxRox
Copy link
Owner

@JayFoxRox JayFoxRox commented Aug 17, 2018

Requires JayFoxRox/nxdk#7

This has basically gotten no testing. I only started working on it 3 hours ago.
I expect there to be plenty of bugs - but I'm okay with that.
This tool is a temporary proof-of-concept and bootstrapping (for projects like nv2a-trace, but also an open-source dashboard and other tools).

I've only tried running XboxDev/nxdk#46 without the XVideo init during startup.
I've also made the LED hook specifically for that binary.

It depends on the ".reloc" section being present, so it does not work for retail games (yet).
It does support self-relocation now, but XDK applications just return immediately for unknown reasons.


static uint32_t LookupKernelExport(unsigned int ordinal) {
uint32_t image_base = 0x80010000;
uint32_t tmp = *(uint32_t*)(image_base + 0x3C);

Choose a reason for hiding this comment

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

Since you've defined _NO_RETURN and others, it's probably best to use defines for these magic constants too (0x3C, 0x78, 0x14, 0x1C, ...)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Code was stolen from xboxpy, which, I believe, was stolen from elsewhere (probably a project by @Ernegien).
I don't even remember what each of those magics were, and I don't care enough to fix it myself. But I definitely agree.


// Relocate our binary
if (relocation_section == NULL) {
debugPrint("Unable to find relocation section; will break if image base %d is not %d xbe base\n", image_base, xbe);

Choose a reason for hiding this comment

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

s/%d/%x

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, I had this, but nxdk does not support "%X". I'm not sure if it supports "%x" and did not try it. I just figured "%d" was probably the most reliable printf for now (I have to FTP each change to Xbox first, so I wasn't really motivated to try many options).



static uint32_t LookupKernelExport(unsigned int ordinal) {
uint32_t image_base = 0x80010000;

Choose a reason for hiding this comment

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

const static

Copy link
Owner Author

Choose a reason for hiding this comment

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

Will do and probably make it a global, because we might want to resolve other PE module exports later. Issue exists because this is just xboxpy (Python) code with uint32_t added infront of each line.


unsigned int index = ordinal - 1;

return image_base + *(uint32_t*)(ExportBase + index * 4);
Copy link

@PatrickvL PatrickvL Aug 17, 2018

Choose a reason for hiding this comment

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

Perhaps calculate ExportBase once in caller, so that LookupKernelExport can accept it as an argument?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't think that's a good idea. If anything, I'd rather see proper structs for the exe.

For now, there are bigger design issues, rather than these small implementation details.
The kernel lookup also isn't critical for performance (and a couple of indirect lookups aren't that bad).

Choose a reason for hiding this comment

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

true

@JayFoxRox JayFoxRox force-pushed the xbe-loader branch 2 times, most recently from e87e2a4 to ddd4321 Compare August 17, 2018 22:39
@JayFoxRox
Copy link
Owner Author

Leaking line_buffer

switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
//FIXME: Handle these
default:
assert(false)
Copy link

Choose a reason for hiding this comment

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

Missing ;?

Copy link
Owner Author

@JayFoxRox JayFoxRox Sep 21, 2018

Choose a reason for hiding this comment

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

yup. I assume the code still works because I define asserts away. Will fix in the future

@JayFoxRox
Copy link
Owner Author

Note to self: Deleted branch locally. Moved to separate personal projects (not XboxDev; git history not preserved).

@JayFoxRox
Copy link
Owner Author

I've moved this to https://github.com/JayFoxRox/xbe-loader now.
I'm open to contributions / PRs there. I intend to move it to XboxDev/xbe-loader in the future, once it's actually usable.

I did not check the state of the code before pushing to the new location. I'll also keep a xbe-loader-cleanup of this on my local copy of xbox-tools (the cleanup has files moved around, but otherwise isn't any useful).

@JayFoxRox JayFoxRox closed this Oct 22, 2018
@JayFoxRox JayFoxRox deleted the xbe-loader branch October 22, 2018 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants