Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use a rather old version of ubuntu to ensure compatibility regarding libc
FROM --platform=linux/amd64 debian:9
FROM --platform=linux/amd64 ubuntu:20.04
LABEL description="Build environment for piutools"

# Install build dependencies, multilib to get 32-bit versions
Expand All @@ -19,6 +19,7 @@ RUN apt-get install -y libx11-dev:i386
RUN apt-get install -y libcurl4-gnutls-dev:i386
RUN apt-get install -y libglu1-mesa-dev:i386
RUN apt-get install -y libgl1:i386
RUN apt-get install -y sudo

# Delete apt-cache to reduce image size
RUN rm -rf /var/lib/apt/lists/*
Expand All @@ -27,4 +28,7 @@ RUN rm -rf /var/lib/apt/lists/*
RUN mkdir /piutools
WORKDIR /piutools

# docker build -t piutools_buildenv .
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

# docker build -t piutools_buildenv .
39 changes: 31 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ all: $(BUILD_ROOT)/piutools.so plugins

.PHONY: dist
dist:
mkdir -p ./dist
mkdir -p ./dist/plugins
cp -R ./ext/* ./dist/
cp -R ./build/* ./dist/

$(BUILD_ROOT):
mkdir -p $@
if [ -d ./build ]; then cp -R ./build/* ./dist/; fi

.PHONY: piutools.so
piutools.so: $(BUILD_ROOT)/piutools.so
Expand All @@ -37,7 +34,7 @@ GENERIC_PLUGINS := asound ata_hdd ata_hdd_infinity eeprom exec_blocker fake_libu
io_buttonboard io_mk5io io_mk6io locale lockchip \
network pit s3d_opengl sighandler statfix system_info \
ticket_dispenser
PLUGINS := ds1963s_in_ds2480b microdog stlfix usb_profile x11_keyboard_input $(GENERIC_PLUGINS)
PLUGINS := ds1963s_in_ds2480b pro1_data_zip microdog stlfix usb_profile x11_keyboard_input $(GENERIC_PLUGINS)
PLUGIN_OBJS := $(patsubst %,$(PLUGIN_BUILD_ROOT)/%.plugin,$(PLUGINS))

.PHONY: plugins
Expand All @@ -47,7 +44,7 @@ $(PLUGIN_BUILD_ROOT):
mkdir -p $(PLUGIN_BUILD_ROOT)

define generic_plugin_build
$(PLUGIN_BUILD_ROOT)/$(1).plugin: $$(wildcard src/plugins/$(1)/*.c) | $(PLUGIN_BUILD_ROOT)
$(PLUGIN_BUILD_ROOT)/$(1).plugin: $$(wildcard src/plugins/$(1)/*.c) | $(BUILD_ROOT)
cc -shared -m32 -fPIC $(CFLAGS) $$^ $(PLUGIN_INCLUDES) -o $$@
endef

Expand Down Expand Up @@ -82,7 +79,33 @@ DS1963S_IN_DS2480B_SOURCES := src/plugins/ds1963s_in_ds2480b/ds1963s_in_ds2480b.
src/plugins/ds1963s_in_ds2480b/base64.c

$(PLUGIN_BUILD_ROOT)/ds1963s_in_ds2480b.plugin: $(DS1963S_UTILS_SOURCES) $(DS1963S_IN_DS2480B_SOURCES)
cc -shared -m32 -fPIC $(CFLAGS) $(DS1963s_IN_DS2480B_SOURCES) $(DS1963S_UTILS_SOURCES) $(PLUGIN_INCLUDES) -lpthread -I src/plugins/ds1963s_in_ds2480b/ds1963s-utils/src -o $@
cc -shared -m32 -fPIC $(CFLAGS) $(DS1963S_IN_DS2480B_SOURCES) $(DS1963S_UTILS_SOURCES) $(PLUGIN_INCLUDES) -lpthread -I src/plugins/ds1963s_in_ds2480b/ds1963s-utils/src -o $@

PRO1_DATA_ZIP_OW_SOURCES := src/plugins/pro1_data_zip/ow/crcutil.c \
src/plugins/pro1_data_zip/ow/ds2480ut.c \
src/plugins/pro1_data_zip/ow/linuxlnk.c \
src/plugins/pro1_data_zip/ow/owerr.c \
src/plugins/pro1_data_zip/ow/owllu.c \
src/plugins/pro1_data_zip/ow/ownetu.c \
src/plugins/pro1_data_zip/ow/owsesu.c \
src/plugins/pro1_data_zip/ow/owtrnu.c \
src/plugins/pro1_data_zip/ow/sha18.c \
src/plugins/pro1_data_zip/ow/shaib.c

PRO1_DATA_ZIP_SOURCES := src/plugins/pro1_data_zip/pro1_data_zip.c \
src/plugins/pro1_data_zip/aes.c \
src/plugins/pro1_data_zip/dongle.c \
src/plugins/pro1_data_zip/enc_zip_file.c \
src/plugins/pro1_data_zip/sig.c \
src/plugins/pro1_data_zip/util.c

#LTC_OBJS := src/plugins/pro1_data_zip/ltc/linux_x86/libtomcrypt.a \
# src/plugins/pro1_data_zip/ltc/linux_x86/libtommath.a
LTC_OBJS := src/plugins/pro1_data_zip/ltc/linux_x86/libtomcrypt_debug.a \
src/plugins/pro1_data_zip/ltc/linux_x86/libtommath.a

$(PLUGIN_BUILD_ROOT)/pro1_data_zip.plugin: $(PRO1_DATA_ZIP_OW_SOURCES) $(PRO1_DATA_ZIP_SOURCES) $(LTC_OBJS)
cc -shared -m32 -fPIC $(CFLAGS) $(PRO1_DATA_ZIP_SOURCES) $(PRO1_DATA_ZIP_OW_SOURCES) $(LTC_OBJS) -I src/plugins/pro1_data_zip/ltc/headers $(PLUGIN_INCLUDES) -o $@

.PHONY: clean
clean:
Expand Down
17 changes: 17 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

BUILDENV_IMG_NAME=${1:-piutools_buildenv}
BUILDENV_IMG_VERSION=${2:-latest}

repo_name="${BUILDENV_IMG_NAME}:${BUILDENV_IMG_VERSION}"

GID="$(id -g ${UID})"

docker build -t ${repo_name} .
docker run --rm -v $PWD:/piutools \
-e "CFLAGS=${CFLAGS:-""}" \
-e "MY_UID=${UID}" \
-e "MY_GID=${GID}" \
${repo_name} make
17 changes: 17 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

MY_UID="${MY_UID:-"0"}"
MY_GID="${MY_GID:-"0"}"

# maintain permissions of calling user
if [ "x$MY_UID" != "x0" ]; then
groupadd -g $MY_GID somegroup
useradd -g $MY_UID someuser
echo "running as sudo ($MY_UID:$MY_GID): $@"
env
sudo --preserve-env=CFLAGS -g somegroup -u someuser "$@"
else
exec "$@"
fi
23 changes: 17 additions & 6 deletions ext/run_container.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fi

# Load Our Native Paths
piutools_native_path=$(realpath $(pwd))
piutools_native_src_path=$(realpath $piutools_native_path/../src)
piutools_native_rom_path=$piutools_native_path/roms/$game_name
piutools_native_config_path=$piutools_native_path/config/$game_name/$game_version.conf

Expand All @@ -93,17 +94,25 @@ piutools_rom=$piutools_root/rom
piutools_save=$piutools_root/save
piutools_mnt=$piutools_root/mnt
piutools_tmp=$piutools_root/tmp
piutools_src=$piutools_root/src

#run_command= RUN_STRACE, RUN_GDB, RUN_GAME,RUN_LTRACE

img_name="${PIUTOOLS_CONTAINER_IMG_NAME:-"pumpos_classic"}"

docker_args="run --device /dev/fuse --cap-add SYS_ADMIN --rm -it"
# Add the Graphics Support Stuff
docker_args+=" --gpus all -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY"
# Add the Sound Stuff
docker_args+=" -e PULSE_SERVER=$PULSE_SERVER -v /mnt/wslg/:/mnt/wslg/"
if [ -e /mnt/wslg ]; then
docker_args+=" -e PULSE_SERVER=$PULSE_SERVER -v /mnt/wslg/:/mnt/wslg/"
fi
# Allow ptrace (and disabling ASLR) for gdb and strace to work
docker_args+=" --cap-add=SYS_PTRACE --security-opt seccomp=unconfined"
# Add Our PIUTools Mounts
docker_args+=" -v $piutools_native_path:$piutools_bin"
docker_args+=" -v $piutools_native_rom_path:$piutools_rom:ro"
docker_args+=" -v $piutools_native_src_path:$piutools_src:ro"
docker_args+=" -v $piutools_native_save_path:$piutools_save"
# Add Our PIUTools Envars
docker_args+=" -e PIUTOOLS_GAME_NAME=$game_name"
Expand All @@ -112,20 +121,22 @@ docker_args+=" -e PIUTOOLS_PATH=$piutools_bin"
docker_args+=" -e PIUTOOLS_CONFIG_PATH=$piutools_config_path"
docker_args+=" -e PIUTOOLS_PLUGIN_PATH=$piutools_plugins_path"
docker_args+=" -e PIUTOOLS_ROM_PATH=$piutools_rom"
docker_args+=" -e PIUTOOLS_SRC_PATH=$piutools_src"
docker_args+=" -e PIUTOOLS_SAVE_PATH=$piutools_save"
docker_args+=" -e PIUTOOLS_TMP_PATH=$piutools_tmp"
docker_args+=" -e PIUTOOLS_MNT_PATH=$piutools_mnt"
docker_args+=" -e PIUTOOLS_SRC_PATH=$piutools_src"
docker_args+=" -e PIUTOOLS_ROMS=$game_roms"
docker_args+=" -e PIUTOOLS_EXE_PATH=$exe_path"
docker_args+=" -e PIUTOOLS_EXE_ARGS=$exe_args"
docker_args+=" -e PIUTOOLS_GAME_DIR=$exe_game_dir"
docker_args+=" -e PIUTOOLS_DEBUG=1"
docker_args+=" -e RUN_GAME=1"
#docker_args+=" -e RUN_GDB=1"
#docker_args+=" -e RUN_STRACE=1"
#docker_args+=" -e RUN_LTRACE=1"
docker_args+=" -e RUN_GAME=${RUN_GAME:-""}"
docker_args+=" -e RUN_GDB=${RUN_GDB:-""}"
docker_args+=" -e RUN_STRACE=${RUN_STRACE:-""}"
docker_args+=" -e RUN_LTRACE=${RUN_STRACE:-""}"

docker_args+=" pumpos_classic $piutools_bin/tools/bootstrap_game.sh"
docker_args+=" ${img_name} $piutools_bin/tools/bootstrap_game.sh"

echo $docker_args

Expand Down
4 changes: 2 additions & 2 deletions ext/tools/bootstrap_game.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cat $PIUTOOLS_PATH/tools/pump_arrows.graphic
#cat $PIUTOOLS_PATH/am.graphic
#cat $PIUTOOLS_PATH/pumplogo.graphic
# Set PIUTools Stuff
mkdir $PIUTOOLS_TMP_PATH
mkdir -p $PIUTOOLS_TMP_PATH

# Read the list of gamedata roms and mount each.
IFS=',' read -ra roms_array <<< "$PIUTOOLS_ROMS"
Expand Down Expand Up @@ -71,4 +71,4 @@ elif [ -n "$RUN_GAME" ]; then
else
unset LD_PRELOAD
exec /bin/bash
fi
fi
6 changes: 3 additions & 3 deletions include/PIUTools_Hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ typedef struct _HOOK_ENTRY {


int PIUTools_Hook_GetFunctionAddress(const char* library_name, const char* function_name, void** pfunction_address);
void* PIUTools_Hook_Inline(const char* module_name, const char* function_name, void* hook_addr);
void* PIUTools_Hook_Import(const char* module_name, const char* library_name, const char* function_name, void* hook_addr);
void* PIUTools_Hook_Inline(const char* module_name, const char* function_name, void* hook_addr, const char *plugin_name);
void* PIUTools_Hook_Import(const char* module_name, const char* library_name, const char* function_name, void* hook_addr, const char *plugin_name);


typedef const PHookEntry (*plugin_init_t)(void);
typedef const PHookEntry (*plugin_init_t)(void);
2 changes: 1 addition & 1 deletion include/PIUTools_Plugin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

void PIUTools_Plugin_Init(void);
void PIUTools_Plugin_LoadHook(void* entry);
void PIUTools_Plugin_LoadHook(void* entry, const char *plugin_name);
2 changes: 1 addition & 1 deletion src/core/PIUTools_Filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void PIUTools_Filesystem_Redirect_Init(void){
PHookEntry fsredirect_entry = filesystem_redirect_entries;
if (fsredirect_entry != NULL) {
while (fsredirect_entry->hook_type != HOOK_ENTRY_END) {
PIUTools_Plugin_LoadHook(fsredirect_entry);
PIUTools_Plugin_LoadHook(fsredirect_entry, "filesystem_redirect");
// Move to the next entry
fsredirect_entry++;
}
Expand Down
18 changes: 9 additions & 9 deletions src/core/PIUTools_Hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,39 @@ static int piutools_hook_init(void){
return 1;
}

static void print_hook_status(const char* hook_type, const char* module_name, const char* library_name, const char* function_name, int hook_status){
static void print_hook_status(const char* hook_type, const char* plugin_name, const char* module_name, const char* library_name, const char* function_name, int hook_status){
const char* hook_fail_msg = "\033[1;31mHook Fail:\033[0m";
const char* hook_ok_msg = "\033[1;32mHook OK:\033[0m";
const char* hook_status_msg = (hook_status) ? hook_ok_msg:hook_fail_msg;
if(module_name == NULL){
module_name = "Main Executable";
}

DBG_printf("[%s]: %s -- %s %s %s",hook_type,hook_status_msg, module_name, library_name, function_name);
DBG_printf("[plugin:%s][%s]: %s -- %s %s %s", plugin_name, hook_type, hook_status_msg, module_name, library_name, function_name);
}

int PIUTools_Hook_GetFunctionAddress(const char* library_name, const char* function_name, void** pfunction_address){
// If we didn't specify a place to store the function address, we can't do anything.
if (pfunction_address == NULL) {
DBG_printf("[%s] (%s:%s) Error: pfunction_address cannot be NULL", __FUNCTION__, library_name, function_name);
errno = EINVAL;
DBG_printf("[%s] Error: %s", __FUNCTION__, strerror(errno));
return 0;
}

// Open our library or die.
DBG_printf("[%s] %s:%s",__FUNCTION__,library_name,function_name);
void* hLibrary = dlopen(library_name, RTLD_LAZY);
if(hLibrary == NULL){
DBG_printf("[%s] (%s:%s) Error: %s", __FUNCTION__, library_name, function_name, dlerror());
errno = EACCES;
DBG_printf("[%s] Error: %s", __FUNCTION__, strerror(errno));
return 0;
}
// Resolve our Symbol
*pfunction_address = dlsym(hLibrary,function_name);
// If we didn't resolve our symbol - die.
if(*pfunction_address == NULL){
DBG_printf("[%s] (%s:%s) Error: %s", __FUNCTION__, library_name, function_name, dlerror());
errno = EINVAL;
DBG_printf("[%s] Error: %s", __FUNCTION__, strerror(errno));
return 0;
}

Expand All @@ -78,16 +78,16 @@ int PIUTools_Hook_GetFunctionAddress(const char* library_name, const char* funct



void* PIUTools_Hook_Inline(const char* module_name, const char* function_name, void* hook_addr){
void* PIUTools_Hook_Inline(const char* module_name, const char* function_name, void* hook_addr, const char *plugin_name){
if(!module_initialized){if(!piutools_hook_init()){exit(-1);}}
void* res = hook_function_byname(module_name,function_name, hook_addr);
print_hook_status("HOOK_INLINE",module_name,"",function_name,(res != NULL));
print_hook_status("HOOK_INLINE",plugin_name,module_name,"",function_name,(res != NULL));
return res;
}

void* PIUTools_Hook_Import(const char* module_name, const char* library_name, const char* function_name, void* hook_addr){
void* PIUTools_Hook_Import(const char* module_name, const char* library_name, const char* function_name, void* hook_addr, const char *plugin_name){
if(!module_initialized){if(!piutools_hook_init()){exit(-1);}}
void* res = hook_import_byname(module_name,library_name,function_name,hook_addr);
print_hook_status("HOOK_IMPORT",module_name,library_name,function_name,(res != NULL));
print_hook_status("HOOK_IMPORT",plugin_name,module_name,library_name,function_name,(res != NULL));
return res;
}
10 changes: 5 additions & 5 deletions src/core/PIUTools_Plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void load_plugin(const char* plugin_name){

if (cur_entry != NULL) {
while (cur_entry->hook_type != HOOK_ENTRY_END) {
PIUTools_Plugin_LoadHook((void*)cur_entry);
PIUTools_Plugin_LoadHook((void*)cur_entry, plugin_name);
// Move to the next entry
cur_entry++;
}
Expand Down Expand Up @@ -58,17 +58,17 @@ void PIUTools_Plugin_Init(void){
ini_parse(plugin_config_path,parse_loader_config,NULL);
}

void PIUTools_Plugin_LoadHook(void* ventry){
void PIUTools_Plugin_LoadHook(void* ventry, const char *plugin_name){
PHookEntry entry = (PHookEntry)ventry;
if(!module_initialized){PIUTools_Plugin_Init();}
if(entry->hook_enabled){
void* rfa;
switch(entry->hook_type){
case HOOK_TYPE_INLINE:
rfa = PIUTools_Hook_Inline(entry->source_library_name,entry->target_function_name, entry->hook_function_addr);
rfa = PIUTools_Hook_Inline(entry->source_library_name,entry->target_function_name, entry->hook_function_addr, plugin_name);
break;
case HOOK_TYPE_IMPORT:
rfa = PIUTools_Hook_Import(entry->target_binary_name,entry->source_library_name,entry->target_function_name, entry->hook_function_addr);
rfa = PIUTools_Hook_Import(entry->target_binary_name,entry->source_library_name,entry->target_function_name, entry->hook_function_addr, plugin_name);
break;
default:
break;
Expand All @@ -77,4 +77,4 @@ void PIUTools_Plugin_LoadHook(void* ventry){
*entry->original_function_addr_ptr = rfa;
}
}
}
}
Loading