• Stars
    star
    2,003
  • Rank 22,143 (Top 0.5 %)
  • Language
    C
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A foreign function interface for bash.

ctypes.sh

This is ctypes.sh, a foreign function interface for bash.

ctypes.sh is a bash plugin that provides a foreign function interface directly in your shell. In other words, it allows you to call routines in shared libraries from within bash.

A (very) simple example will help illustrate:

$ dlcall puts "hello, world"
hello, world

# A more complex example, use libm to calculate sin(PI/2)
$ dlopen libm.so.6
0x172ebf0
$ dlcall -r double sin double:1.57079632679489661923
double:1.000000

ctypes.sh can extend bash scripts to accomplish tasks that were previously impossible, or would require external helpers to be written.

ctypes.sh makes it possible to use GTK natively in your shell scripts, or write a high-performance http daemon.

See more examples here

prerequisites

ctypes.sh is dependent on the following libraries and programs:

  • libffi
  • bash
  • libelf (optional)
  • elfutils (optional)
  • libdwarf / libdw (optional)

Fedora

For recent Fedora, this should be enough:

sudo yum install elfutils-devel dnf-utils

Now you can use the debuginfo-install command to install debugging symbols for automatic structure support.

Ubuntu

For recent Ubuntu, this should be enough:

sudo apt install autoconf libltdl-dev libffi-dev libelf-dev elfutils libdw-dev

If you want to use automatic struct support (recommended), you should also make you have ddebs available.

install

ctypes.sh can be installed from source like this:

$ git clone https://github.com/taviso/ctypes.sh.git
$ cd ctypes.sh
$ ./autogen.sh
$ ./configure
$ make
$ [sudo] make install

By default ctypes.sh is installed into /usr/local/bin and /usr/local/lib. You can overload the prefix path by defining the PREFIX environment variable before installing.

$ PREFIX=$HOME make install

example

source ctypes.sh
puts () {
  dlcall puts "$@"
  return $?
}

puts "hello, world"

Here is what people have been saying about ctypes.sh:

  • "that's disgusting"
  • "this has got to stop"
  • "you've gone too far with this"
  • "is this a joke?"
  • "I never knew the c could stand for Cthulhu."

You can read more about ctypes.sh and see it in action on the Wiki

More Repositories

1

loadlibrary

Porting Windows Dynamic Link Libraries to Linux
C
4,286
star
2

ctftool

Interactive CTF Exploration Tool
C
1,628
star
3

123elf

A native port of Lotus 1-2-3 to Linux.
C
1,129
star
4

avscript

Avast JavaScript Interactive Shell
C
663
star
5

rbndr

Simple DNS Rebinding Service
C
589
star
6

wpunix

WordPerfect for UNIX Character Terminals
C
578
star
7

hotcorner

Tiny Hot Corners for Windows 10
C
372
star
8

nntpit

minimalist reddit2nntp gateway
C
231
star
9

rarvmtools

Minimal RarVM Toolchain
C
207
star
10

cefdebug

Minimal code to connect to a CEF debugger.
C
190
star
11

kiewtai

A port of Kaitai to the Hiew hex editor
C
145
star
12

lotusdrv

Lotus 1-2-3 R4D Display Driver for DOSEMU
C
145
star
13

sharapi

Simpsons: Hit & Run JavaScript API
JavaScript
109
star
14

swisstable

Access Abseil Swiss Tables from C
C
96
star
15

dbusmap

This is a simple utility for enumerating D-Bus endpoints, an nmap for D-Bus.
C
76
star
16

scanlimits

Tool to examine the behaviour of setuid binaries under constrained limits.
C
62
star
17

katamascii

An ascii-art physics puzzle, roll around your terminal collecting ascii-art objects!
C
44
star
18

minirun

Run commands with hidden console.
C
30
star
19

timex

A hello world for the timex m851
C
30
star
20

iknowthis

iknowthis Linux SystemCall Fuzzer
C
20
star
21

hiewdocs

Documentation and notes on using the Hiew editor.
HTML
16
star
22

mpgravity

MicroPlanet Gravity
C++
14
star
23

nssecurity

Netscape Plugin Security
C
8
star
24

hiewkey

Keyboard helper for Hiew
C
3
star
25

wpdfilter

Enable Windows to Index WordPerfect UNIX Documents
C++
3
star
26

ncpro

Commandline Interface to NoteCase Pro
Shell
1
star
27

stfjson

Convert Lotus Agenda STF files to JSON
C
1
star