- #include <stdio.h>
- #include <dlfcn.h>
- #include <sys/socket.h>
- #include <cutils/sockets.h>
- #define VOLD_NAMESPACE "vold"
- #define SHARED_LIBRARY "/system/lib/libcutils.so"
- #define SHARED_LIB_FUNC "socket"
- #define LOAD_SUCCESS 1
- #define LOAD_FAILURE 0
- typedef int (*ptr_socket_local_client)(const char*, int, int);
- ptr_socket_local_client socket_local_client = NULL;
- void*
- try_find_export(void *handle, const char *name)
- {
- if(handle == NULL || name == NULL){
- return NULL;
- }
- void* func = dlsym(handle, name);
- if (func == NULL) {
- return NULL;
- }
- else {
- return func;
- }
- return NULL;
- }
- int
- try_load_libs(void)
- {
- void *library = dlopen(SHARED_LIBRARY, RTLD_NOW);
- if (library == NULL) {
- printf("Error while getting file handle.\n");
- }
- socket_local_client = (ptr_socket_local_client)try_find_export(library, SHARED_LIB_FUNC);
- if (socket_local_client == NULL) {
- printf("Dying. Couldn't locate socket functions.\n");
- return 0;
- }
- else {
- printf("All libraries accounted for\n");
- return 1;
- }
- return 0;
- }
- int
- main (int argc, const char * argv[])
- {
- // insert code here...
- int sock = -1;
- printf("\n==============================================================\n");
- printf("Vold2 Proof of concept.\nozzeh@manykdepressive.com\n");
- printf("==============================================================\n");
- printf("Trying to assemble the shared libraries.\n");
- if(try_load_libs() != LOAD_SUCCESS) {
- printf("Couldn't load required shared objects for this POC.\n");
- //return 0;
- }
- else {
- printf("Shared objects loaded, attempting to open a client socket\n");
- }
- //sock = socket(AF_INET, SOCK_STREAM, 0);
- socket = socket_local_client(VOLD_NAMESPACE,
- ANDROID_SOCKET_NAMESPACE_RESERVED,
- SOCK_STREAM);
- printf("socket returned: %d\n", sock);
- if (socket > 0) {
- printf("Socket accepted!\n");
- }
- else {
- printf("Socket creation failed.\n");
- }
- return 0;
- }