Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is busybox available in shared library form?

Tags:

c

linux

Is busybox available in shared library form? I would like to use individual apps programmatically instead of using system(). I've heard about libbusybox and libbb but could not find any documentation.

like image 898
zer0stimulus Avatar asked Aug 21 '10 01:08

zer0stimulus


1 Answers

There exists busybox library in a shared form called libbusybox(.so), you just have to enable it while making menuconfig. When you have compiled, it will be avalible in 0_lib folder. In this library you have nice little function called int lbb_main(char **argv).

What you need to do in your code is something like this:

extern int lbb_main(char **argv);

int main()
{
    char* strarray[] = {"ifconfig",0};
    lbb_main(strarray);

    return 1;
}

You could import libb.h, but that didn't work for me, because I got many errors.

After that you just have to compile using somethin like gcc -o code code.c -Lpath_to_0_lib_fodler -lbusyboxand that's it!

To intercept output you will have to redefine printf and similar calls, buts that's clearly doable by using soemthing macros like #define printf(...) code' inlibb.h'.

You could even spawn busybox's shell that doesn't use fork or system, but that doesn't work well yet.

like image 134
offlinehacker Avatar answered Nov 06 '22 00:11

offlinehacker