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

Update for UnrealEngine's wrong file path #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
63 changes: 37 additions & 26 deletions PlayTools/PlayLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,27 @@ static OSStatus pt_SecItemDelete(CFDictionaryRef query) {
DYLD_INTERPOSE(pt_SecItemUpdate, SecItemUpdate)
DYLD_INTERPOSE(pt_SecItemDelete, SecItemDelete)

static bool is_ue4 = false;

static char const* ue4_fix_filename(char const* filename) {
char const UE4_PATTERN[] = "Library//Users";
char const* p = NULL;
if (!is_ue4) {
return filename;
}

if ((p = strstr(filename, UE4_PATTERN))) {
return p + 8;
static uint8_t ue_status = 0;

static char const* ue_fix_filename(char const* filename) {
static char UE_PATTERN[1024] = "//Users/";
getlogin_r(UE_PATTERN + 8, sizeof(UE_PATTERN) - 8);
Copy link
Member

Choose a reason for hiding this comment

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

What does this function do in the code (seems unused)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The prefix //Users can be insufficient, so I added the username to the prefix path UE_PATTERN.


char const* p = filename;
Copy link
Member

Choose a reason for hiding this comment

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

Can you rename this variable so it is more descriptive of its purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will rename the variable UE_PATTERN to USER_HOME and add a comment for it.

if (ue_status == 2) {
char const* last_p = p;
while ((p = strstr(p, UE_PATTERN))) {
last_p = ++p;
}

return last_p;
}

return filename;
return p;
}

static int pt_open(char const* restrict filename, int oflag, ... ) {
filename = ue4_fix_filename(filename);
filename = ue_fix_filename(filename);

if (oflag == O_CREAT) {
int mod;
Expand All @@ -212,19 +215,19 @@ static int pt_open(char const* restrict filename, int oflag, ... ) {
}

static int pt_stat(char const* restrict path, struct stat* restrict buf) {
return stat(ue4_fix_filename(path), buf);
return stat(ue_fix_filename(path), buf);
}

static int pt_access(char const* path, int mode) {
return access(ue4_fix_filename(path), mode);
return access(ue_fix_filename(path), mode);
}

static int pt_rename(char const* restrict old_name, char const* restrict new_name) {
return rename(ue4_fix_filename(old_name), ue4_fix_filename(new_name));
return rename(ue_fix_filename(old_name), ue_fix_filename(new_name));
}

static int pt_unlink(char const* path) {
return unlink(ue4_fix_filename(path));
return unlink(ue_fix_filename(path));
}

DYLD_INTERPOSE(pt_open, open)
Expand All @@ -237,15 +240,23 @@ @implementation PlayLoader

static void __attribute__((constructor)) initialize(void) {
[PlayCover launch];

NSURL* appFolder = [[NSBundle mainBundle] bundleURL];
NSURL* ue4commandlinetxt = [appFolder URLByAppendingPathComponent:@"ue4commandline.txt"];

is_ue4 |= !access(
[[ue4commandlinetxt path] cStringUsingEncoding:NSUTF8StringEncoding], F_OK
);
if (is_ue4) {
[PlayKeychain debugLogger: [NSString stringWithFormat:@"Is it UE4? : %@", @(is_ue4)]];

if (ue_status == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Will ue_status never equal 0 on initialization?

NSURL* appFolder = [[NSBundle mainBundle] bundleURL];
NSArray* ueFiles = @[
[appFolder URLByAppendingPathComponent:@"ue4commandline.txt"],
[appFolder URLByAppendingPathComponent:@"uecommandline.txt"],
];

for (NSURL* ueFile in ueFiles) {
if (!access([[ueFile path] cStringUsingEncoding:NSUTF8StringEncoding], F_OK)) {
ue_status = 2;
}
}
}

if (ue_status == 2) {
[PlayKeychain debugLogger: [NSString stringWithFormat:@"UnrealEngine Hooked"]];
}
}

Expand Down
Loading