mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-06 16:27:22 +08:00
fix cppcheck
This commit is contained in:
parent
d840084492
commit
fae2438559
1 changed files with 50 additions and 62 deletions
|
@ -27,82 +27,67 @@
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
#include "jni_tools.h"
|
#include "jni_tools.h"
|
||||||
|
|
||||||
#define LOCAL_SOCKET_SERVER_NAME "DXL.COM.ASL"
|
//iceman, todo: proxify socker server name. Maybe set in preferences?
|
||||||
|
#define PM3_LOCAL_SOCKET_SERVER "DXL.COM.ASL"
|
||||||
void ShowGraphWindow() {
|
|
||||||
|
|
||||||
|
void ShowGraphWindow(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HideGraphWindow(void) {
|
void HideGraphWindow(void) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepaintGraphWindow() {
|
void RepaintGraphWindow(void) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int push_cmdscriptfile(char *path, bool stayafter) {
|
int push_cmdscriptfile(char *path, bool stayafter) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *g_android_my_executable_path = NULL;
|
static char *g_android_executable_directory = NULL;
|
||||||
static char *g_android_my_executable_directory = NULL;
|
static const char *g_android_user_directory = NULL;
|
||||||
|
|
||||||
const char *get_my_executable_path(void) {
|
const char *get_executable_directory(void) {
|
||||||
return g_android_my_executable_path;
|
|
||||||
|
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) {
|
const char *get_user_directory(void) {
|
||||||
if (g_android_my_executable_directory != NULL) free(g_android_my_executable_directory);
|
return g_android_user_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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_my_executable_path(void) {
|
static bool OpenPm3(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() {
|
|
||||||
if (conn.run) {
|
if (conn.run) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Open with LocalSocket(Not a tcp connection!)
|
// Open with LocalSocket. Not a tcp connection!
|
||||||
bool ret = OpenProxmark("socket:"LOCAL_SOCKET_SERVER_NAME, false, 1000, false, 115200);
|
bool ret = OpenProxmark("socket:"PM3_LOCAL_SOCKET_SERVER, false, 1000, false, 115200);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Transfers to the command buffer and waits for a new command to be executed
|
* Transfers to the command buffer and waits for a new command to be executed
|
||||||
* */
|
* */
|
||||||
jint sendCMD(JNIEnv *env, jobject instance, jstring cmd_) {
|
jint Console(JNIEnv *env, jobject instance, jstring cmd_) {
|
||||||
//may be pm3 not running.
|
|
||||||
if (!conn.run) {
|
if (!conn.run) {
|
||||||
if (open() && TestProxmark() == PM3_SUCCESS) {
|
if (OpenPm3() && TestProxmark() == PM3_SUCCESS) {
|
||||||
LOGD("Open Successfully!");
|
LOGD("Connected to device");
|
||||||
PrintAndLogEx(NORMAL, "Open Successfully!");
|
PrintAndLogEx(SUCCESS, "Connected to device");
|
||||||
} else {
|
} else {
|
||||||
LOGD("Open failed!");
|
LOGD("Failed to connect to device");
|
||||||
PrintAndLogEx(NORMAL, "Open failed!");
|
PrintAndLogEx(ERR, "Failed to connect to device");
|
||||||
CloseProxmark();
|
CloseProxmark();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// display on new line
|
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
||||||
char *cmd = (char *) ((*env)->GetStringUTFChars(env, cmd_, 0));
|
char *cmd = (char *) ((*env)->GetStringUTFChars(env, cmd_, 0));
|
||||||
int ret = CommandReceived(cmd);
|
int ret = CommandReceived(cmd);
|
||||||
if (ret == 99) {
|
if (ret == 99) {
|
||||||
|
@ -110,6 +95,7 @@ jint sendCMD(JNIEnv *env, jobject instance, jstring cmd_) {
|
||||||
// TODO: implement this
|
// TODO: implement this
|
||||||
PrintAndLogEx(NORMAL, "Asked to exit, can't really do that yet...");
|
PrintAndLogEx(NORMAL, "Asked to exit, can't really do that yet...");
|
||||||
}
|
}
|
||||||
|
|
||||||
(*env)->ReleaseStringUTFChars(env, cmd_, cmd);
|
(*env)->ReleaseStringUTFChars(env, cmd_, cmd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -117,33 +103,34 @@ jint sendCMD(JNIEnv *env, jobject instance, jstring cmd_) {
|
||||||
/*
|
/*
|
||||||
* Is client running!
|
* Is client running!
|
||||||
* */
|
* */
|
||||||
jboolean isExecuting(JNIEnv *env, jobject instance) {
|
jboolean IsClientRunning(JNIEnv *env, jobject instance) {
|
||||||
return (jboolean) ((jboolean) conn.run);
|
return (jboolean) ((jboolean) conn.run);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test hw and hw and client.
|
* test hw and hw and client.
|
||||||
* */
|
* */
|
||||||
jboolean testPm3(JNIEnv *env, jobject instance) {
|
jboolean TestPm3(JNIEnv *env, jobject instance) {
|
||||||
bool ret1 = open();
|
if (open() == false) {
|
||||||
if (!ret1) {
|
|
||||||
CloseProxmark();
|
CloseProxmark();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool ret2 = TestProxmark() == PM3_SUCCESS;
|
bool ret = (TestProxmark() == PM3_SUCCESS);
|
||||||
return (jboolean) (ret1 && ret2);
|
return (jboolean) (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* stop pm3 client
|
* stop pm3 client
|
||||||
* */
|
* */
|
||||||
void stopPm3(JNIEnv *env, jobject instance) {
|
void ClosePm3(JNIEnv *env, jobject instance) {
|
||||||
CloseProxmark();
|
CloseProxmark();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* native function map to jvm
|
* 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) {
|
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||||
JNIEnv *jniEnv = NULL;
|
JNIEnv *jniEnv = NULL;
|
||||||
if ((*vm)->GetEnv(vm, (void **) &jniEnv, JNI_VERSION_1_4) != JNI_OK) {
|
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");
|
jclass clz_test = (*jniEnv)->FindClass(jniEnv, "cn/rrg/devices/Proxmark3RRGRdv4");
|
||||||
JNINativeMethod methods[] = {
|
JNINativeMethod methods[] = {
|
||||||
{"startExecute", "(Ljava/lang/String;)I", (void *) sendCMD},
|
{"startExecute", "(Ljava/lang/String;)I", (void *) Console},
|
||||||
{"stopExecute", "()V", (void *) stopPm3},
|
{"stopExecute", "()V", (void *) ClosePm3},
|
||||||
{"isExecuting", "()Z", (void *) isExecuting}
|
{"isExecuting", "()Z", (void *) IsClientRunning}
|
||||||
};
|
};
|
||||||
|
|
||||||
JNINativeMethod methods1[] = {
|
JNINativeMethod methods1[] = {
|
||||||
{"testPm3", "()Z", (void *) testPm3},
|
{"testPm3", "()Z", (void *) TestPm3},
|
||||||
{"closePm3", "()V", stopPm3}
|
{"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;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((*jniEnv)->RegisterNatives(jniEnv, clz_test, methods1,
|
|
||||||
sizeof(methods1) / sizeof(methods1[0])) !=
|
if ((*jniEnv)->RegisterNatives(jniEnv, clz_test, methods1, sizeof(methods1) / sizeof(methods1[0])) != JNI_OK) {
|
||||||
JNI_OK) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*jniEnv)->DeleteLocalRef(jniEnv, clazz);
|
(*jniEnv)->DeleteLocalRef(jniEnv, clazz);
|
||||||
(*jniEnv)->DeleteLocalRef(jniEnv, clz_test);
|
(*jniEnv)->DeleteLocalRef(jniEnv, clz_test);
|
||||||
return JNI_VERSION_1_4;
|
return JNI_VERSION_1_4;
|
||||||
|
|
Loading…
Reference in a new issue