lewisclark / glua-steal

Retrieves client-sided Lua files from Garry's Mod game servers
GNU General Public License v3.0
151 stars 15 forks source link

The game does not open with this #16

Closed LuaFan2 closed 1 year ago

LuaFan2 commented 4 years ago

Hello. Earlier I inject this lib using "Set launch options" in game options in Steam. I wrote in them "LD_PRELOAD=/path/to/so/ %command%" and all worked like a charm. But when I recompiled it to update it to july version my GMOD stopped launching(it turns off after startup). Ubuntu 16.04. Both 64 bit gmod and 32 bit don't work. What can I do to give you more information?

lewisclark commented 4 years ago

When did LD_PRELOAD injection last work for you? Also, which version of glua-steal last worked for you?

As an alternative, gdb injection works great.

pid=$1
lib=$2

#Credit: Aixxe @ aixxe.net
if grep -q gluasteal.so /proc/$pid/maps; then
    /bin/echo -e "\e[33mAlready injected... Aborting...\e[0m"
    exit
fi

input="$(
sudo gdb -n -q -batch \
  -ex "attach $pid" \
  -ex "set \$dlopen = (void*(*)(char*, int)) dlopen" \
  -ex "call \$dlopen(\"$lib\", 1)" \
  -ex "detach" \
  -ex "quit"
)"

last_line="${input##*$'\n'}"

if [ "$last_line" != "\$1 = (void *) 0x0" ]; then
    /bin/echo -e "\e[32mSuccessfully injected!\e[0m"
else
    /bin/echo -e "\e[31mInjection failed, make sure you've compiled...\e[0m"
fi
LuaFan2 commented 4 years ago

When did LD_PRELOAD injection last work for you? Also, which version of glua-steal last worked for you?

As an alternative, gdb injection works great.

pid=$1
lib=$2

#Credit: Aixxe @ aixxe.net
if grep -q gluasteal.so /proc/$pid/maps; then
    /bin/echo -e "\e[33mAlready injected... Aborting...\e[0m"
    exit
fi

input="$(
sudo gdb -n -q -batch \
  -ex "attach $pid" \
  -ex "set \$dlopen = (void*(*)(char*, int)) dlopen" \
  -ex "call \$dlopen(\"$lib\", 1)" \
  -ex "detach" \
  -ex "quit"
)"

last_line="${input##*$'\n'}"

if [ "$last_line" != "\$1 = (void *) 0x0" ]; then
    /bin/echo -e "\e[32mSuccessfully injected!\e[0m"
else
    /bin/echo -e "\e[31mInjection failed, make sure you've compiled...\e[0m"
fi

I used only two versions of glua-stel - old and new. I downloaded the old version before winter, but I can't remember when it was released. I can't inject using gdb because my computer is missing the GNU C library file. Im too lazy to restore it. I will only do this as a last resort

lewisclark commented 4 years ago

I'm not too sure what the issue is, whether it's a problem with glua-steal or a change in Garry's Mod. I've tested 64-bit and 32-bit injection with v1.7, v1.9 and v1.4 and neither load the library. None of them crash my game though, even using the same exact method as you. In GarrysMod/hl2.sh there is a line that unsets LD_PRELOAD which is only present on the 64-bit branch. This could be affecting things but I doubt it if your game is crashing. I would personally stay away from this method of loading the library anyway, because the gmod process forks and it loads the library more than once.

You could try setting LD_PRELOAD in hl2.sh instead of the Steam launch options. It may yield different results.

LuaFan2 commented 4 years ago

Wow. Tried again to inject lib and did it successfully using https://github.com/gaffe23/linux-inject. There is happiness in the world.

x4fx77x4f commented 3 years ago

I wasn't able to successfully inject glua-steal (1.9, latest commit, bdd414e) on Ubuntu 20.04.1 LTS and 64-bit Garry's Mod with gdb, linux-inject, or LD_PRELOAD. I get a segmentation fault every time. Interestingly, when I use the LD_PRELOAD method (using a modified hl2.sh), it does manage to write the entire initialization text to log.txt before it crashes. Yes, I used the 64-bit toolchain. No, I did not try the default 32-bit branch.

I greatly appreciate the work you've put into this project.

lewisclark commented 3 years ago

Hmm, very strange. Just tested v1.9 64-bit and it's working as expected with gdb injection but I'm on Arch. Could you by any chance attach a debugger such as gdb and then inject using that gdb instance so we can see where it's crashing? If not don't worry, I'll give it a go in a virtual machine.

x4fx77x4f commented 3 years ago

I have been trying for weeks, but just now it magically started working again. I injected by manually typing commands into gdb, and now it works just fine, even when using your injection script that previously failed. I haven't changed anything since the last time I tried. This is beyond perplexing.

For what it's worth, when I was using the injection script prior to this divine intervention, the output it gave was exactly the same as a successful injection, including the $1 = (void *) 0xdeadbeef line (and yes, it was an actual address and not 0xdeadbeef or 0x0).

EDIT:

$ sudo gdb -n -q
[sudo] password for user: 
(gdb) attach 51312
Attaching to process 51312
[New LWP 51315]
[New LWP 51316]
[New LWP 51318]
[New LWP 51321]
[New LWP 51322]
[New LWP 51323]
[New LWP 51324]
[New LWP 51325]
[New LWP 51327]
[New LWP 51328]
[New LWP 51329]
[New LWP 51330]
[New LWP 51331]
[New LWP 51332]
[New LWP 51337]
[New LWP 51338]
[New LWP 51339]
[New LWP 51341]
[New LWP 51343]
[New LWP 51344]
[New LWP 51345]
[New LWP 51346]
[New LWP 51347]
[New LWP 51348]
[New LWP 51350]
[New LWP 51372]
[New LWP 51373]
[New LWP 51374]
[New LWP 51375]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f82d32b6361 in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, 
    req=0x7ffce154ac00, rem=0x7ffce154abf0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:48
48  ../sysdeps/unix/sysv/linux/clock_nanosleep.c: No such file or directory.
(gdb) set $dlopen = (void*(*)(char*, int)) dlopen
(gdb) call $dlopen("/home/user/gluasteal/libgluasteal.so", 1)
[New Thread 0x7f82237fe700 (LWP 51436)]
[New Thread 0x7f8238f4d700 (LWP 51437)]
$1 = (void *) 0xacbba40
(gdb) detach
Detaching from program: /home/user/.steam/steam/steamapps/common/GarrysMod/bin/linux64/gmod, process 51312
[Inferior 1 (process 51312) detached]
(gdb) quit
lewisclark commented 3 years ago

Oh well that's very interesting haha. Thanks for reporting, hopefully I'll run into this crash soon.