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

macOS support #42

Merged
merged 58 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3f7c211
Initial commit for macos CI
lewisclark Oct 27, 2022
1c28a3b
Update name
lewisclark Oct 27, 2022
2c8ed97
Link libSystem.dylib
lewisclark Oct 27, 2022
1446c4f
Temp link System
lewisclark Oct 27, 2022
db84949
lib prefix?
lewisclark Oct 27, 2022
da34cdc
Find libSystem
lewisclark Oct 27, 2022
b4a13b8
Add more names
lewisclark Oct 27, 2022
5e16a48
Update flags
lewisclark Oct 27, 2022
04d2788
Add prefix
lewisclark Oct 27, 2022
7c641ce
Change order
lewisclark Oct 27, 2022
3b3a3ba
Link
lewisclark Oct 27, 2022
63a2ed1
Move stuff
lewisclark Oct 27, 2022
5c54525
Debug output
lewisclark Oct 27, 2022
d9295e6
Debug output
lewisclark Oct 27, 2022
b9d61d4
Reverse gcc-32bit toolchain
lewisclark Oct 27, 2022
c43b6b4
Link options
lewisclark Oct 27, 2022
5cf31d3
CMAKE_TRY_COMPILE_TARGET_TYPE
lewisclark Oct 27, 2022
b31629f
Add macOS 11 to CI matrix
lewisclark Oct 27, 2022
74c9062
Remove link.h include for macos
lewisclark Oct 27, 2022
df2f5af
Include dyld.h
lewisclark Oct 28, 2022
4378182
Set arch to i386
lewisclark Oct 29, 2022
fcab91e
Set sysroot
lewisclark Oct 29, 2022
bd4d4ed
Set CMake sysroot and deployment target
lewisclark Oct 29, 2022
b7006ee
Remove -lSystem flag
lewisclark Oct 29, 2022
d26d467
Set up xcode version
lewisclark Oct 29, 2022
eaabfbb
Fix indentation
lewisclark Oct 29, 2022
cec6257
Revert "Fix indentation"
lewisclark Oct 29, 2022
2b216c0
Revert "Set up xcode version"
lewisclark Oct 29, 2022
6aba6e4
CMAKE_OSX_ARCHITECTURES
lewisclark Oct 29, 2022
258242f
Clean up
lewisclark Oct 29, 2022
f8a4359
Remove sysroot and deployment target flags
lewisclark Oct 29, 2022
4af6af1
macOS build instructions
lewisclark Oct 29, 2022
a054e3d
Initial implementation of loaded library fetching
lewisclark Oct 29, 2022
a9dd2df
Add logging
lewisclark Oct 29, 2022
b56f6eb
Include logger.hpp
lewisclark Oct 29, 2022
ff0e99a
Use dlopen instead of _dyld_get_image_vmaddr_slide
lewisclark Oct 29, 2022
8315571
Merge branch 'master' into osx
lewisclark Oct 29, 2022
a447f0e
Add num_images as arg to debug log
lewisclark Oct 29, 2022
53fcd26
Remove old debug stuff
lewisclark Oct 29, 2022
dfad3a9
Merge branch 'master' into osx
lewisclark Oct 29, 2022
90d9449
Update actions/checkout to v3 for macOS CI
lewisclark Oct 29, 2022
56474f6
Force trace debug level
lewisclark Oct 30, 2022
34f05cb
Add x86_64 arch macOS toolchain
lewisclark Oct 31, 2022
7ac3285
Rename toolchain gcc-macos-32bit to gcc-macos-i386
lewisclark Oct 31, 2022
9ab35d5
Change macOS 64bit ci to x86_64 toolchain
lewisclark Oct 31, 2022
febdc48
Add macOS fat toolchain and to CI
lewisclark Oct 31, 2022
adaadae
Correctly set cache variable CMAKE_OSX_ARCHITECTURES
lewisclark Oct 31, 2022
b54eb95
Remove 32-bit/i386 macOS build from CI
lewisclark Oct 31, 2022
da0ff0d
Update README
lewisclark Oct 31, 2022
e0ae849
Update README
lewisclark Oct 31, 2022
21ef281
Update README
lewisclark Oct 31, 2022
682e05f
Fix typo
lewisclark Oct 31, 2022
7a78d2d
Revert "Force trace debug level"
lewisclark Nov 1, 2022
c5eaf94
Set cmake try compile back to executable
lewisclark Nov 1, 2022
6122910
Update README.md
lewisclark Nov 1, 2022
f567b23
Update readme
lewisclark Nov 1, 2022
8ec5dec
Update readme
lewisclark Nov 1, 2022
786254b
Bump version to 2.1
lewisclark Nov 1, 2022
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
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,41 @@ jobs:
- name: Test
working-directory: ${{runner.workspace}}/build
run: ctest -V -C ${{matrix.build_type}} --timeout 60
macos:
strategy:
matrix:
os:
- { name: "macOS Big Sur 11", distro: macos-11 }
- { name: "macOS Monterey 12", distro: macos-12 }
build_type: [Debug, Release]
toolchain: ["gcc-macos-x86_64"]

name: "${{matrix.os.name}} ${{matrix.build_type}} ${{matrix.toolchain}}"
runs-on: ${{matrix.os.distro}}

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Create build environment
working-directory: ${{runner.workspace}}
run: mkdir build

- name: Initialize CMake
env:
CC: /usr/bin/gcc
CXX: /usr/bin/g++
working-directory: ${{runner.workspace}}/build
run: cmake --debug-output $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_TOOLCHAIN_FILE=toolchains/${{matrix.toolchain}}.cmake

- name: Build
shell: bash
working-directory: ${{runner.workspace}}/build
run: make

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
run: ctest -V -C ${{matrix.build_type}}

3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(gluasteal LANGUAGES CXX VERSION 2.0)

project(gluasteal LANGUAGES CXX VERSION 2.1)

enable_testing()

Expand Down
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI Badge](https://github.com/lewisclark/glua-steal/workflows/CI/badge.svg)](https://github.com/lewisclark/glua-steal/actions?query=workflow%3Aci)
![Downloads Badge](https://img.shields.io/github/downloads/lewisclark/glua-steal/total)
![Version Badge](https://img.shields.io/badge/version-2.0-green)
![Version Badge](https://img.shields.io/badge/version-2.1-green)
![License Badge](https://img.shields.io/github/license/lewisclark/glua-steal)
![Issues Badge](https://img.shields.io/github/issues/lewisclark/glua-steal)

Expand All @@ -13,7 +13,14 @@ gluasteal is a better, cross-platform replacement for various Lua dumpers and lo
![Windows usage](https://i.imgur.com/j38AKQ7.png)
![Linux usage](https://i.imgur.com/N7reRXS.png)

Supports Windows & Linux (32-bit & 64-bit). Has not yet been tested on macOS.
Supported operating systems and architectures:
- Windows 32-bit
- Windows 64-bit
- Linux 32-bit
- Linux 64-bit
- macOS 64-bit

Please submit an issue if glua-steal is not working on your system.

---

Expand All @@ -24,8 +31,6 @@ Supports Windows & Linux (32-bit & 64-bit). Has not yet been tested on macOS.
* Lua Blocker - Block Lua scripts of your choosing
* Concurrent IO - The Lua dumper does IO in its own thread to eliminate bottleneck and ensure maximum in-game performance
* Robust protections against servers serving malicious file paths
* Supports the 32-bit and 64-bit versions of the game
* Supports Windows and Linux
* Easily [configurable](#configuration)

---
Expand Down Expand Up @@ -61,7 +66,17 @@ Logs and Lua files will be written to the gluasteal folder, in your home directo

#### macOS

Using DYLD\_INSERT\_LIBRARIES (see LD\_PRELOAD above)
Using LLDB.

```bash
pid=1234
lib_path="/full/path/to/libgluasteal.dylib"

sudo lldb --attach-pid $pid --batch \
-o "p (void*)dlopen(\"$lib_path\", 1)" \
-o detach \
-o quit
```

---

Expand Down Expand Up @@ -155,11 +170,23 @@ git clone https://github.com/lewisclark/glua-steal
cd glua-steal
git submodule update --init --recursive
mkdir build && cd build
choose the 32bit or 64bit toolchain below (toolchains are in toolchains/ folder)
choose the gcc-32bit or gcc-64bit toolchain below (toolchains are in toolchains/ folder)
cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchains/gcc-<32bit/64bit>.cmake
make
```

##### macOS
```
git clone https://github.com/lewisclark/glua-steal
cd glua-steal
git submodule update --init --recursive
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchains/gcc-macos-x86_64.cmake
make
```

If needed, the library can be built in i386 (32-bit) using either the `gcc-macos-i386` or `gcc-macos-fat` toolchain. The 32-bit build of glua-steal has not been built or tested because Xcode [dropped support](../../commit/b54eb95f1412f36d0609ebc59a0af23608d6ea75) for building 32-bit applications.

---

### License
Expand Down
33 changes: 31 additions & 2 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static const std::map<std::string, std::string> extension_mapping = {
#endif
};

#if (defined(OS_LINUX) || defined(OS_MAC))
#if (defined(OS_LINUX))
struct library_entry {
const char* name;
void* lib;
Expand All @@ -57,7 +57,7 @@ glt::lib::Library::Library(const std::string& pathname) :

std::string pathnamext(pathname + GetExtension(pathname));

#if (defined(OS_LINUX) || defined(OS_MAC))
#if (defined(OS_LINUX))
library_entry entry;
entry.name = pathnamext.c_str();
entry.lib = nullptr;
Expand All @@ -84,6 +84,35 @@ glt::lib::Library::Library(const std::string& pathname) :
}

} while (Module32Next(module_snap, &module_entry));
#elif (defined(OS_MAC))
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dyld.3.html

// FIXME: It isn't thread safe to iterate using this count - find an alternative
uint32_t num_images = _dyld_image_count();

const auto& logger = glt::GetLogger();
logger->debug("{} images to enumerate", num_images);

for (uint32_t i = 0; i < num_images; ++i) {
const char* c_name = _dyld_get_image_name(i);

if (!c_name)
continue;

std::string name = c_name;

logger->debug("image \"{}\"", name);

if (name.find(pathnamext) != std::string::npos) {
auto p = dlopen(c_name, RTLD_NOLOAD | RTLD_NOW);

logger->debug("found image \"{}\" at {:x}", name, (uintptr_t)p);

m_handle = reinterpret_cast<std::uintptr_t*>(p);

break;
}
}
#endif

if (!m_handle) {
Expand Down
6 changes: 5 additions & 1 deletion src/library/library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <map>

#include "os.hpp"
#include "logger.hpp"

#if (defined(OS_LINUX) || defined(OS_MAC))
#if (defined(OS_LINUX))
#include <dlfcn.h>
#include <link.h>
#elif (defined(OS_WINDOWS))
#include <windows.h>
#include <tlhelp32.h>
#elif (defined(OS_MAC))
#include <dlfcn.h>
#include <mach-o/dyld.h>
#endif

namespace glt::lib {
Expand Down
4 changes: 4 additions & 0 deletions toolchains/gcc-macos-fat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Wno-unused-variable")
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wno-unused-variable")

set(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "" FORCE)
4 changes: 4 additions & 0 deletions toolchains/gcc-macos-i386.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Wno-unused-variable")
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wno-unused-variable")

set(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "" FORCE)
4 changes: 4 additions & 0 deletions toolchains/gcc-macos-x86_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Wno-unused-variable")
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wno-unused-variable")

set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "" FORCE)