mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-04-02 18:39:57 +08:00
SWIG: create pm3.c
This commit is contained in:
parent
05ba6a73f8
commit
ef309cfdf7
7 changed files with 62 additions and 51 deletions
client
|
@ -251,6 +251,7 @@ set (TARGET_SOURCES
|
|||
${PM3_ROOT}/client/src/graph.c
|
||||
${PM3_ROOT}/client/src/jansson_path.c
|
||||
${PM3_ROOT}/client/src/preferences.c
|
||||
${PM3_ROOT}/client/src/pm3.c
|
||||
${PM3_ROOT}/client/src/pm3_binlib.c
|
||||
${PM3_ROOT}/client/src/pm3_bitlib.c
|
||||
${PM3_ROOT}/client/src/prng.c
|
||||
|
|
|
@ -512,6 +512,7 @@ SRCS = aidsearch.c \
|
|||
mifare/mifaredefault.c \
|
||||
mifare/mifarehost.c \
|
||||
mifare/ndef.c \
|
||||
pm3.c \
|
||||
pm3_binlib.c \
|
||||
pm3_bitlib.c \
|
||||
preferences.c \
|
||||
|
|
|
@ -251,6 +251,7 @@ set (TARGET_SOURCES
|
|||
${PM3_ROOT}/client/src/graph.c
|
||||
${PM3_ROOT}/client/src/jansson_path.c
|
||||
${PM3_ROOT}/client/src/preferences.c
|
||||
${PM3_ROOT}/client/src/pm3.c
|
||||
${PM3_ROOT}/client/src/pm3_binlib.c
|
||||
${PM3_ROOT}/client/src/pm3_bitlib.c
|
||||
${PM3_ROOT}/client/src/prng.c
|
||||
|
|
|
@ -251,6 +251,7 @@ set (TARGET_SOURCES
|
|||
${PM3_ROOT}/client/src/graph.c
|
||||
${PM3_ROOT}/client/src/jansson_path.c
|
||||
${PM3_ROOT}/client/src/preferences.c
|
||||
${PM3_ROOT}/client/src/pm3.c
|
||||
${PM3_ROOT}/client/src/pm3_binlib.c
|
||||
${PM3_ROOT}/client/src/pm3_bitlib.c
|
||||
${PM3_ROOT}/client/src/prng.c
|
||||
|
|
55
client/src/pm3.c
Normal file
55
client/src/pm3.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// User API
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "pm3.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "cmdmain.h"
|
||||
#include "ui.h"
|
||||
#include "usart_defs.h"
|
||||
#include "util_posix.h"
|
||||
#include "comms.h"
|
||||
|
||||
pm3_device* pm3_open(char *port) {
|
||||
pm3_init();
|
||||
OpenProxmark(&session.current_device, port, false, 20, false, USART_BAUD_RATE);
|
||||
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) {
|
||||
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n");
|
||||
CloseProxmark(session.current_device);
|
||||
}
|
||||
|
||||
if ((port != NULL) && (!session.pm3_present))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (!session.pm3_present)
|
||||
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode");
|
||||
// For now, there is no real device context:
|
||||
return session.current_device;
|
||||
}
|
||||
|
||||
void pm3_close(pm3_device* dev) {
|
||||
// Clean up the port
|
||||
if (session.pm3_present) {
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
|
||||
msleep(100); // Make sure command is sent before killing client
|
||||
CloseProxmark(dev);
|
||||
}
|
||||
}
|
||||
|
||||
int pm3_console(pm3_device* dev, char *Cmd) {
|
||||
// For now, there is no real device context:
|
||||
(void) dev;
|
||||
return CommandReceived(Cmd);
|
||||
}
|
||||
|
||||
const char *pm3_name_get(pm3_device* dev) {
|
||||
return dev->conn->serial_port_name;
|
||||
}
|
||||
|
||||
pm3_device* pm3_get_current_dev(void) {
|
||||
return session.current_device;
|
||||
}
|
|
@ -690,7 +690,7 @@ static bool DetectWindowsAnsiSupport(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static void init(void) {
|
||||
void pm3_init(void) {
|
||||
srand(time(0));
|
||||
|
||||
session.pm3_present = false;
|
||||
|
@ -706,57 +706,9 @@ static void init(void) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================= */
|
||||
/* user API */
|
||||
|
||||
pm3_device* pm3_open(char *port) {
|
||||
init();
|
||||
OpenProxmark(&session.current_device, port, false, 20, false, USART_BAUD_RATE);
|
||||
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) {
|
||||
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n");
|
||||
CloseProxmark(session.current_device);
|
||||
}
|
||||
|
||||
if ((port != NULL) && (!session.pm3_present))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (!session.pm3_present)
|
||||
PrintAndLogEx(INFO, "Running in " _YELLOW_("OFFLINE") " mode");
|
||||
// For now, there is no real device context:
|
||||
return session.current_device;
|
||||
}
|
||||
|
||||
void pm3_close(pm3_device* dev) {
|
||||
// For now, there is no real device context:
|
||||
(void) dev;
|
||||
// Clean up the port
|
||||
if (session.pm3_present) {
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_QUIT_SESSION, NULL, 0);
|
||||
msleep(100); // Make sure command is sent before killing client
|
||||
CloseProxmark(dev);
|
||||
}
|
||||
}
|
||||
|
||||
int pm3_console(pm3_device* dev, char *Cmd) {
|
||||
// For now, there is no real device context:
|
||||
(void) dev;
|
||||
return CommandReceived(Cmd);
|
||||
}
|
||||
|
||||
const char *pm3_name_get(pm3_device* dev) {
|
||||
return dev->conn->serial_port_name;
|
||||
}
|
||||
|
||||
pm3_device* pm3_get_current_dev(void) {
|
||||
return session.current_device;
|
||||
}
|
||||
/* ======================================================= */
|
||||
|
||||
#ifndef LIBPM3
|
||||
int main(int argc, char *argv[]) {
|
||||
init();
|
||||
pm3_init();
|
||||
bool waitCOMPort = false;
|
||||
bool addLuaExec = false;
|
||||
bool stayInCommandLoop = false;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
#include "pm3.h"
|
||||
|
||||
#define PROXPROMPT_MAX_SIZE 255
|
||||
|
||||
|
@ -50,6 +49,7 @@ int push_cmdscriptfile(char *path, bool stayafter);
|
|||
const char *get_my_executable_path(void);
|
||||
const char *get_my_executable_directory(void);
|
||||
const char *get_my_user_directory(void);
|
||||
void pm3_init(void);
|
||||
void main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Reference in a new issue