fix cppcheck

This commit is contained in:
iceman1001 2020-06-02 10:38:18 +02:00
parent d840084492
commit fae2438559

View file

@ -27,82 +27,67 @@
#include "fileutils.h"
#include "jni_tools.h"
#define LOCAL_SOCKET_SERVER_NAME "DXL.COM.ASL"
void ShowGraphWindow() {
//iceman, todo: proxify socker server name. Maybe set in preferences?
#define PM3_LOCAL_SOCKET_SERVER "DXL.COM.ASL"
void ShowGraphWindow(void) {
}
void HideGraphWindow(void) {
}
void RepaintGraphWindow() {
void RepaintGraphWindow(void) {
}
int push_cmdscriptfile(char *path, bool stayafter) {
return PM3_SUCCESS;
}
static char *g_android_my_executable_path = NULL;
static char *g_android_my_executable_directory = NULL;
static char *g_android_executable_directory = NULL;
static const char *g_android_user_directory = NULL;
const char *get_my_executable_path(void) {
return g_android_my_executable_path;
const char *get_executable_directory(void) {
if (g_android_executable_directory == NULL) {
char buf[FILE_PATH_SIZE] = {0};
getcwd(buf, sizeof(buf));
strncat(buf, PATHSEP, 1)
g_android_executable_directory = strdup(buf);
}
return g_android_executable_directory;
}
const char *get_my_executable_directory(void) {
if (g_android_my_executable_directory != NULL) free(g_android_my_executable_directory);
char buf[1024];
// get current work directory
getcwd(buf, sizeof(buf));
// add / to end.
sprintf(buf, "%s%s", buf, PATHSEP);
// create on global
g_android_my_executable_directory = strdup(buf);
return g_android_my_executable_directory;
const char *get_user_directory(void) {
return g_android_user_directory;
}
static void set_my_executable_path(void) {
}
static const char *my_user_directory = NULL;
const char *get_my_user_directory(void) {
return my_user_directory;
}
static void set_my_user_directory(void) {
}
static bool open() {
static bool OpenPm3(void) {
if (conn.run) {
return true;
}
// Open with LocalSocket(Not a tcp connection!)
bool ret = OpenProxmark("socket:"LOCAL_SOCKET_SERVER_NAME, false, 1000, false, 115200);
// Open with LocalSocket. Not a tcp connection!
bool ret = OpenProxmark("socket:"PM3_LOCAL_SOCKET_SERVER, false, 1000, false, 115200);
return ret;
}
/*
* Transfers to the command buffer and waits for a new command to be executed
* */
jint sendCMD(JNIEnv *env, jobject instance, jstring cmd_) {
//may be pm3 not running.
jint Console(JNIEnv *env, jobject instance, jstring cmd_) {
if (!conn.run) {
if (open() && TestProxmark() == PM3_SUCCESS) {
LOGD("Open Successfully!");
PrintAndLogEx(NORMAL, "Open Successfully!");
if (OpenPm3() && TestProxmark() == PM3_SUCCESS) {
LOGD("Connected to device");
PrintAndLogEx(SUCCESS, "Connected to device");
} else {
LOGD("Open failed!");
PrintAndLogEx(NORMAL, "Open failed!");
LOGD("Failed to connect to device");
PrintAndLogEx(ERR, "Failed to connect to device");
CloseProxmark();
}
}
// display on new line
PrintAndLogEx(NORMAL, "\n");
PrintAndLogEx(NORMAL, "");
char *cmd = (char *) ((*env)->GetStringUTFChars(env, cmd_, 0));
int ret = CommandReceived(cmd);
if (ret == 99) {
@ -110,6 +95,7 @@ jint sendCMD(JNIEnv *env, jobject instance, jstring cmd_) {
// TODO: implement this
PrintAndLogEx(NORMAL, "Asked to exit, can't really do that yet...");
}
(*env)->ReleaseStringUTFChars(env, cmd_, cmd);
return ret;
}
@ -117,33 +103,34 @@ jint sendCMD(JNIEnv *env, jobject instance, jstring cmd_) {
/*
* Is client running!
* */
jboolean isExecuting(JNIEnv *env, jobject instance) {
jboolean IsClientRunning(JNIEnv *env, jobject instance) {
return (jboolean) ((jboolean) conn.run);
}
/*
* test hw and hw and client.
* */
jboolean testPm3(JNIEnv *env, jobject instance) {
bool ret1 = open();
if (!ret1) {
jboolean TestPm3(JNIEnv *env, jobject instance) {
if (open() == false) {
CloseProxmark();
return false;
}
bool ret2 = TestProxmark() == PM3_SUCCESS;
return (jboolean) (ret1 && ret2);
bool ret = (TestProxmark() == PM3_SUCCESS);
return (jboolean) (ret);
}
/*
* stop pm3 client
* */
void stopPm3(JNIEnv *env, jobject instance) {
void ClosePm3(JNIEnv *env, jobject instance) {
CloseProxmark();
}
/*
* native function map to jvm
* */
//iceman: todo, pm3:ify java class root. Return codes, should match PM3_E* codes.
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *jniEnv = NULL;
if ((*vm)->GetEnv(vm, (void **) &jniEnv, JNI_VERSION_1_4) != JNI_OK) {
@ -156,23 +143,24 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
}
jclass clz_test = (*jniEnv)->FindClass(jniEnv, "cn/rrg/devices/Proxmark3RRGRdv4");
JNINativeMethod methods[] = {
{"startExecute", "(Ljava/lang/String;)I", (void *) sendCMD},
{"stopExecute", "()V", (void *) stopPm3},
{"isExecuting", "()Z", (void *) isExecuting}
{"startExecute", "(Ljava/lang/String;)I", (void *) Console},
{"stopExecute", "()V", (void *) ClosePm3},
{"isExecuting", "()Z", (void *) IsClientRunning}
};
JNINativeMethod methods1[] = {
{"testPm3", "()Z", (void *) testPm3},
{"closePm3", "()V", stopPm3}
{"testPm3", "()Z", (void *) TestPm3},
{"closePm3", "()V", ClosePm3}
};
if ((*jniEnv)->RegisterNatives(jniEnv, clazz, methods, sizeof(methods) / sizeof(methods[0])) !=
JNI_OK) {
if ((*jniEnv)->RegisterNatives(jniEnv, clazz, methods, sizeof(methods) / sizeof(methods[0])) != JNI_OK) {
return -1;
}
if ((*jniEnv)->RegisterNatives(jniEnv, clz_test, methods1,
sizeof(methods1) / sizeof(methods1[0])) !=
JNI_OK) {
if ((*jniEnv)->RegisterNatives(jniEnv, clz_test, methods1, sizeof(methods1) / sizeof(methods1[0])) != JNI_OK) {
return -1;
}
(*jniEnv)->DeleteLocalRef(jniEnv, clazz);
(*jniEnv)->DeleteLocalRef(jniEnv, clz_test);
return JNI_VERSION_1_4;