Created
October 2, 2015 22:30
-
-
Save strazzere/fefc1fa2c92fdcb8b00c to your computer and use it in GitHub Desktop.
UREE toy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOCAL_PATH := $(call my-dir) | |
include $(CLEAR_VARS) | |
LOCAL_SRC_FILES := \ | |
uree_toy.c | |
LOCAL_C_INCLUDE := ${ANDROID_NDK_ROOT}/platforms/android-14/arch-arm/usr/include/ | |
LOCAL_MODULE := uree_toy | |
LOCAL_MODULE_TAGS := optional | |
# Allow execution on android-16 | |
LOCAL_CFLAGS += -pie -fPIE | |
LOCAL_LDFLAGS += -pie -fPIE | |
APP_ABI := armeabi armeabi-v7a x86 | |
include $(BUILD_STATIC_EXECUTABLE) | |
include $(BUILD_EXECUTABLE) | |
include $(call all-makefiles-under,$(LOCAL_PATH)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Tim 'diff' Strazzere | |
* <[email protected]> | |
*/ | |
#include <stdlib.h> // avoid exit warning | |
#include <stdio.h> | |
#include <dlfcn.h> // dlopen/dlclose | |
#include <unistd.h> // access | |
#define ALMOND_LIB "/system/lib/libtz_uree.so" | |
#define TZ_TA_DBG_UUID "42a10730-f349-11e2-a99a-d4856458b228" | |
#define TZ_RESULT_SUCCESS 0x00000000 | |
typedef unsigned int UREE_SESSION_HANDLE; | |
typedef int TZ_RESULT; | |
typedef TZ_RESULT (*UREE_CreateSession)(char*, UREE_SESSION_HANDLE*); | |
typedef char* (*TZ_GetErrorString)(int); | |
static UREE_SESSION_HANDLE dbg_session; | |
int main(int argc, const char* argv[]) { | |
printf(" [+] Attempting to load UREE Trustzone library\n"); | |
void* handle = dlopen(ALMOND_LIB, RTLD_LAZY); | |
if(handle == NULL) { | |
printf(" [!] Could not load library : %s\n", dlerror()); | |
return -1; | |
} | |
printf(" [+] Library Loaded!\n"); | |
UREE_CreateSession createSession = dlsym(handle, "UREE_CreateSession"); | |
if(createSession == NULL) { | |
printf(" [!] Function not found!\n"); | |
return -1; | |
} | |
TZ_RESULT ret = createSession(TZ_TA_DBG_UUID, &dbg_session); | |
TZ_GetErrorString getErrorString = dlsym(handle, "TZ_GetErrorString"); | |
if(ret != TZ_RESULT_SUCCESS) { | |
printf("CreateSession TZ_TA_DBG_UUID Error: %s\n", getErrorString(ret)); | |
return -1; | |
} | |
printf(" [+] Closing library\n"); | |
dlclose(handle); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment