1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
10 //-----------------------------------------------------------------------------
12 #include "proxmark3.h"
15 #include <stdio.h> // for Mingw readline
19 #include "usart_defs.h"
20 #include "util_posix.h"
27 #include "fileutils.h"
28 #include "commonutil.h" // ARRAYLEN
29 #include "jni_tools.h"
31 //iceman, todo: proxify socker server name. Maybe set in preferences?
33 // Is a good idea, we can move this def to preferences, but not now.
34 // Because libpm3rrg_rdv4.so cant load preferences.
35 // I will impl a function to load preferences at future.
36 #define PM3_LOCAL_SOCKET_SERVER "DXL.COM.ASL"
38 static char *g_android_executable_directory
= NULL
;
39 static char *g_android_user_directory
= NULL
;
41 char version_information
[] = {""};
43 const char *get_my_executable_directory(void) {
44 if (g_android_executable_directory
== NULL
) {
45 char buf
[FILE_PATH_SIZE
] = {0};
46 getcwd(buf
, sizeof(buf
));
47 strncat(buf
, PATHSEP
, 1);
48 g_android_executable_directory
= strdup(buf
);
50 return g_android_executable_directory
;
53 const char *get_my_user_directory(void) {
54 return g_android_user_directory
;
57 void ShowGraphWindow(void) {}
59 void HideGraphWindow(void) {}
61 void RepaintGraphWindow(void) {}
63 int push_cmdscriptfile(char *path
, bool stayafter
) { return PM3_SUCCESS
; }
65 static bool OpenPm3(void) {
66 if (conn
.run
) { return true; }
67 // Open with LocalSocket. Not a tcp connection!
68 bool ret
= OpenProxmark(session
.current_device
, "socket:"PM3_LOCAL_SOCKET_SERVER
, false, 1000, false, 115200);
73 * Transfers to the command buffer and waits for a new command to be executed
75 jint
Console(JNIEnv
*env
, jobject instance
, jstring cmd_
) {
78 if (OpenPm3() && TestProxmark(session
.current_device
) == PM3_SUCCESS
) {
79 LOGD("Connected to device");
80 PrintAndLogEx(SUCCESS
, "Connected to device");
82 LOGD("Failed to connect to device");
83 PrintAndLogEx(ERR
, "Failed to connect to device");
84 CloseProxmark(session
.current_device
);
88 PrintAndLogEx(NORMAL
, "");
90 char *cmd
= (char *)((*env
)->GetStringUTFChars(env
, cmd_
, 0));
91 int ret
= CommandReceived(cmd
);
94 // TODO: implement this
95 PrintAndLogEx(NORMAL
, "Asked to exit, can't really do that yet...");
98 (*env
)->ReleaseStringUTFChars(env
, cmd_
, cmd
);
105 jboolean
IsClientRunning(JNIEnv
*env
, jobject instance
) {
106 return (jboolean
)((jboolean
) conn
.run
);
110 * test hw and fw and client.
112 jboolean
TestPm3(JNIEnv
*env
, jobject instance
) {
113 if (open() == false) {
114 CloseProxmark(session
.current_device
);
117 bool ret
= (TestProxmark(session
.current_device
) == PM3_SUCCESS
);
118 return (jboolean
)(ret
);
124 void ClosePm3(JNIEnv
*env
, jobject instance
) {
125 CloseProxmark(session
.current_device
);
129 * native function map to jvm
132 //iceman: todo, pm3:ify java class root. Return codes, should match PM3_E* codes.
133 JNIEXPORT jint
JNI_OnLoad(JavaVM
*vm
, void *reserved
) {
134 JNIEnv
*jniEnv
= NULL
;
135 if ((*vm
)->GetEnv(vm
, (void **) &jniEnv
, JNI_VERSION_1_4
) != JNI_OK
) {
138 (*jniEnv
)->GetJavaVM(jniEnv
, &g_JavaVM
);
139 jclass clazz
= (*jniEnv
)->FindClass(jniEnv
, "cn/rrg/natives/Proxmark3RRGRdv4Tools");
143 jclass clz_test
= (*jniEnv
)->FindClass(jniEnv
, "cn/rrg/devices/Proxmark3RRGRdv4");
144 JNINativeMethod methods
[] = {
145 {"startExecute", "(Ljava/lang/String;)I", (void *) Console
},
146 {"stopExecute", "()V", (void *) ClosePm3
},
147 {"isExecuting", "()Z", (void *) IsClientRunning
}
150 JNINativeMethod methods1
[] = {
151 {"testPm3", "()Z", (void *) TestPm3
},
152 {"closePm3", "()V", ClosePm3
}
155 if ((*jniEnv
)->RegisterNatives(jniEnv
, clazz
, methods
, ARRAYLEN(methods
)) !=
160 if ((*jniEnv
)->RegisterNatives(jniEnv
, clz_test
, methods1
,
161 ARRAYLEN(methods1
)) != JNI_OK
) {
165 (*jniEnv
)->DeleteLocalRef(jniEnv
, clazz
);
166 (*jniEnv
)->DeleteLocalRef(jniEnv
, clz_test
);
167 return JNI_VERSION_1_4
;