Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Add support for macOS? #11

Open
hyiltiz opened this issue May 19, 2020 · 7 comments
Open

Add support for macOS? #11

hyiltiz opened this issue May 19, 2020 · 7 comments

Comments

@hyiltiz
Copy link
Contributor

hyiltiz commented May 19, 2020

Since it works in Linux Desktop, maybe getting it to work on macOS probably only needs a recompilation with clang (if the original binary was built with clang for macOS) and maybe some more minor tweaks of some constants?

@paintdream
Copy link
Owner

paintdream commented May 20, 2020

Simple recompilation may not work, since machine code matching is compiler dependent and must be reworked for different platforms. I'm happy to see someone else could do it...

The key reason for lack of macOS version is that I have no mac devices. Also, as you know, they are so expensive for the people lived in China that nearly all players here are playing game on Windows.

@hyiltiz
Copy link
Contributor Author

hyiltiz commented May 20, 2020

Yes, I can see most of your use base do not require macOS support, but Apple products are quite prevalent in some other countries. I am not well versed enough to do manual machine code matching myself but if you are willing to write up a detailed instructions for the steps required, I'd give it a try.

If it is any useful info., I am running Debian testing in an old MacBook Pro, and it works. So x86-64 platform and the compiler is what we need match up against? Here is the result of objdump -all-headers dontstarve_steam: https://termbin.com/orqc though not sure if it contains anything useful.

@paintdream
Copy link
Owner

paintdream commented May 22, 2020

Yes, I can see most of your use base do not require macOS support, but Apple products are quite prevalent in some other countries. I am not well versed enough to do manual machine code matching myself but if you are willing to write up a detailed instructions for the steps required, I'd give it a try.

If it is any useful info., I am running Debian testing in an old MacBook Pro, and it works. So x86-64 platform and the compiler is what we need match up against? Here is the result of objdump -all-headers dontstarve_steam: https://termbin.com/orqc though not sure if it contains anything useful.

This is a hard and boring work. But you may try it with following steps (maybe interesting at the first time if you have never done it before):

  1. Compile linux version of the mod. Startup with linux build world saves much of your time.
  2. Run the game with the mod and it crashes. Capture the log that it prints out.
  3. Fix the function mismatch (marked by "Missing") one by one via assembly code comparison (totally almost 100+ functions starts with lua_ or luaL or luaopen) with:
    a) modify comparsion algorithm.
    b) do some modification on lua51 project so it can generate matching machine code.

As you know, the 3.b) step requires various experiences on compiler, you must use the same compiler as Klei and find out the modifications by Klei via disassembled machine code. After reimplementing theses changes to lua51 project, you can check the newly generated machine code by running game again. If it's matched, then move to next missing function and repeat the instructions.

@paintdream
Copy link
Owner

objdump

objdump shows that it exports no lua functions. Machine code matching is the only approach.

@hyiltiz
Copy link
Contributor Author

hyiltiz commented May 22, 2020

Is it possible to automate some part of step 3, maybe in a loop, run the game, grep first missing function, prompt to select from a few matching rules and append that rule to a file. Once done, we can then refine that file into the lua51 project and build it... I have no idea if what I am saying here is even feasible as I've never done stuff like that...

@paintdream
Copy link
Owner

Is it possible to automate some part of step 3, maybe in a loop, run the game, grep first missing function, prompt to select from a few matching rules and append that rule to a file. Once done, we can then refine that file into the lua51 project and build it... I have no idea if what I am saying here is even feasible as I've never done stuff like that...

Unfortunetly it's impossible to select serveral candidates automatically. Once matching failed, it turns out that klei modified some functions, for example:

int _cdecl lua_XXXXX(lua_State* L) {
// luaC_checkGC(L); // One call to checkGC was removed
}

It would generate totally different machine code at first serveral bytes and invalidates all candidates you find out...

When I was developing windows version, I searched them by some reverse engineering techniques (such as tracing back from resolved ones) and finally get them all resolved.

@paintdream
Copy link
Owner

Is it possible to automate some part of step 3, maybe in a loop, run the game, grep first missing function, prompt to select from a few matching rules and append that rule to a file. Once done, we can then refine that file into the lua51 project and build it... I have no idea if what I am saying here is even feasible as I've never done stuff like that...

In fact I'm a not experienced in reverse engineering so I've no better approaches but do it with brute force. My interest is in rendering optimization but it cannot be done due to lack of source.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants