Git Product home page Git Product logo

stack-shim's Introduction

This is a copy of my sed script for LD_PRELOAD libraries (available on this site as well) modified to just relay the call to the original library. If you compile this with the appropriate options, it will force 16-byte stack alignment.

While the sed script generates most of the code, you still have to identify fucntions to override, find their prototypes, and add them to the code. I have done this for the game Eschalon Book I in stack-fix.c: at first I added functions that were crashing, but when gdb was no longer able to identify these (due to missing unwind information), I went ahead and added all symbols in glx or GL directly referred to by the binary. This also includes glXGetProcAddressARB, which I treat differently in order to find out what addresses are being queried and adding them manually (in this case, only one function).

To generate the code, run sed (you will end up with a mostly empty/non-functional binary otherwise):

sed -i -f addldovr.sed stack-fix.c

To compile, make sure and set the stack alignment option. The following assumes that -mpreferred-stack-boundary=4 is the default (that's the cause of this issue in the first place, so it's pretty likely); otherwise add that as well.

gcc -m32 -mincoming-stack-boundary=2 -shared -o stack-fix.{so,c} -ldl -lX11 -lGL

To clean the source for further editing and/or git activity, run sed:

sed -i -f delldovr.sed stack-fix.c

To use, just add stack-fix.so to the LD_PRELOAD environment variable, using the full path if not in your LD_LIBRARY_PATH.

This cures the mysterious crashing on the Eschalon game series. Books II and III don't use any additional GL functions, and they haven't crashed so far. It may cure others, as well, if you add enough prototypes.

stack-shim's People

Contributors

darktjm avatar

Stargazers

 avatar Old Man Programmer avatar

Watchers

 avatar

stack-shim's Issues

wrong ELF class: ELFCLASS32

Hello,

Many thanks for publishing this on GitHub!

I am running Debian GNU/Linux 12 (bookworm) amd64 and I was at a loss on how to fix the eschalon segfault until I read this!

What I did is as follows:

$ pushd /tmp
/tmp ~
$ git clone https://github.com/darktjm/stack-shim.git
Cloning into 'stack-shim'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 14 (delta 3), reused 14 (delta 3), pack-reused 0
Receiving objects: 100% (14/14), 5.51 KiB | 5.51 MiB/s, done.
Resolving deltas: 100% (3/3), done.
$ cd ./stack-shim/
$ sudo apt install gcc-i686-linux-gnu libxcb1-dev:i386 libx11-dev:i386 libglx-dev:i386 libglu1-mesa-dev:i386
[...]
$ sed -f addldovr.sed stack-fix.c > stack-fix_full.c
$ /usr/bin/i686-linux-gnu-gcc -m32 -mincoming-stack-boundary=2 -mpreferred-stack-boundary=4 -shared -o stack-fix.so stack-fix_full.c -ldl -lX11 -lGL
$ ls -l stack-fix.so 
-rwxr-xr-x 1 joe joe 29560 Aug 16 22:14 stack-fix.so
$ ldd stack-fix.so 
	linux-gate.so.1 (0xf7eef000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7c00000)
	/lib/ld-linux.so.2 (0xf7ef1000)
$ LD_PRELOAD=/tmp/stack-shim/stack-fix.so /usr/games/eschalon-book-1
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/tmp/stack-shim/stack-fix.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.

And then the launch menu appears and the sound starts playing!!!

Any ideas why I get those wrong ELF class errors? Do you get them too? Are they harmful?

Thanks again,
--Joe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.