Skip to content

Extending PINCE with .so files

Korcan Karaokçu edited this page Jan 3, 2024 · 2 revisions

If you need to execute a function from a .so file within gdb, there's an automated way of doing it.

1-) Open the GDB Console by clicking the console icon from top right in the main window. Execute the command pince-init-so-file with the path of the .so file as the parameter. I'll use the C code located at "/PINCE/libpince/gdb_python_scripts/tests/example.c" for this tutorial. If you don't know how to compile your code into a .so file, check "Notes.txt" file in the same directory with "example.c". Here's the code for the first step:
pince-init-so-file /home/korcan/PINCE/libpince/gdb_python_scripts/tests/example.so

2-Optional) See loaded functions by executing the command pince-get-so-file-information

3-) Execute the function you want with the command pince-execute-from-so-file as python code by using the variable lib. In "example.c" we have a function called "hello_world". It takes an integer as the parameter and prints "Hello World! for n times" for n times and returns n+1 as an integer. To call that function, execute this command:
pince-execute-from-so-file lib.hello_world(3)
You have to write the the parameter as a python code. The variable lib holds all members of the loaded so file. PINCE will assign the result of the call to a gdb convenience variable. For our example, you'll see something like this:
"$28 = 4"
"$28" is the gdb convenience variable and "4" is the result returned from the call. Now you can use that gdb convenience variable in other gdb commands as well. For instance, executing set *0x00400000=$28 will set the value of address 0x00400000 to 4.

If this stuff looks too tedious, you can create a short script and call it with the command source. If we try to create a script with the commands above, it'll look like this:


pince-init-so-file /home/korcan/PINCE/libpince/gdb_python_scripts/tests/example.so
pince-get-so-file-information
pince-execute-from-so-file lib.hello_world(3)


Now, save it somewhere. Let's say you saved it as "load_so_file". You can now call it like this: source /home/korcan/load_so_file

Clone this wiki locally