SWIG experiments

Squash of the following commits (a full rebase was too hard :( )
* ef309cfdf N - SWIG: create pm3.c (5 months ago)  <Philippe Teuwen>
* 05ba6a73f N - swig pm3_device -> pm3 (5 months ago)  <Philippe Teuwen>
* d59630183 N - swig: move pm3.i (5 months ago)  <Philippe Teuwen>
* 6adcfad75 N - Fix historic make & cmake (5 months ago)  <Philippe Teuwen>
* bcbef2edf N - Fix typo with script_embedded (5 months ago)  <slurdge>
* 538ee4dab N - Better SWIG integration: autogen func & attributes (5 months ago)  <slurdge>
* 756b62466 N - SWIG: few helper scripts (5 months ago)  <Philippe Teuwen>
* 47ba4acd0 N - SWIG %extend (5 months ago)  <Philippe Teuwen>
* 21841cb9d N - simplify scripts (5 months ago)  <Philippe Teuwen>
* 78c4f7929 N - Revert "SWIG experiments: introduce context" (5 months ago)  <Philippe Teuwen>
* 1562b75fc N - SWIG experiments: introduce context (5 months ago)  <Philippe Teuwen>
* a503dfcd9 N - SWIG experiments (5 months ago)  <Philippe Teuwen>
This commit is contained in:
Philippe Teuwen
2020-05-28 02:13:21 +02:00
parent e959d0e229
commit eadacd82f5
42 changed files with 8542 additions and 34 deletions

View File

@@ -34,6 +34,7 @@
#include "flash.h"
#include "preferences.h"
#ifndef LIBPM3
#define BANNERMSG1 " Iceman :coffee:"
#define BANNERMSG2 " :snowflake: bleeding edge"
#define BANNERMSG3 " https://github.com/rfidresearchgroup/proxmark3/"
@@ -113,6 +114,7 @@ static void showBanner(void) {
fflush(stdout);
g_printAndLog = PRINTANDLOG_PRINT | PRINTANDLOG_LOG;
}
#endif //LIBPM3
static const char *prompt_dev = "";
static const char *prompt_ctx = "";
@@ -134,7 +136,7 @@ static int check_comm(void) {
rl_set_prompt(prompt_filtered);
rl_forced_update_display();
#endif
CloseProxmark();
CloseProxmark(session.current_device);
}
msleep(10);
return 0;
@@ -452,6 +454,7 @@ check_script:
}
}
#ifndef LIBPM3
static void dumpAllHelp(int markdown) {
session.help_dump_mode = true;
PrintAndLogEx(NORMAL, "\n%sProxmark3 command dump%s\n\n", markdown ? "# " : "", markdown ? "" : "\n======================");
@@ -462,6 +465,7 @@ static void dumpAllHelp(int markdown) {
dumpCommandsRecursive(cmds, markdown);
session.help_dump_mode = false;
}
#endif //LIBPM3
static char *my_executable_path = NULL;
static char *my_executable_directory = NULL;
@@ -546,6 +550,7 @@ static void set_my_user_directory(void) {
}
}
#ifndef LIBPM3
static void show_help(bool showFullHelp, char *exec_name) {
PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m]", exec_name);
@@ -631,7 +636,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[
PrintAndLogEx(SUCCESS, " "_YELLOW_("%s"), filepaths[i]);
}
if (OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
if (OpenProxmark(&session.current_device, serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
PrintAndLogEx(NORMAL, _GREEN_(" found"));
} else {
PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name);
@@ -669,7 +674,7 @@ static int flash_pm3(char *serial_port_name, uint8_t num_files, char *filenames[
finish:
ret = flash_stop_flashing();
CloseProxmark();
CloseProxmark(session.current_device);
finish2:
for (int i = 0 ; i < num_files; ++i) {
if (filepaths[i] != NULL)
@@ -682,6 +687,7 @@ finish2:
PrintAndLogEx(NORMAL, "\nHave a nice day!");
return ret;
}
#endif //LIBPM3
#if defined(_WIN32)
static bool DetectWindowsAnsiSupport(void) {
@@ -696,14 +702,28 @@ static bool DetectWindowsAnsiSupport(void) {
return SetConsoleMode(hOut, dwMode) ? true : false;
}
#endif
#endif //_WIN32
int main(int argc, char *argv[]) {
void pm3_init(void) {
srand(time(0));
session.pm3_present = false;
session.help_dump_mode = false;
session.incognito = false;
session.supports_colors = false;
session.emoji_mode = ALTTEXT;
session.stdinOnTTY = false;
session.stdoutOnTTY = false;
// set global variables soon enough to get the log path
set_my_executable_path();
set_my_user_directory();
}
#ifndef LIBPM3
int main(int argc, char *argv[]) {
pm3_init();
bool waitCOMPort = false;
bool addLuaExec = false;
bool stayInCommandLoop = false;
@@ -737,10 +757,6 @@ int main(int argc, char *argv[]) {
int flash_num_files = 0;
char *flash_filenames[FLASH_MAX_FILES];
// set global variables soon enough to get the log path
set_my_executable_path();
set_my_user_directory();
// color management:
// 1. default = no color
// 2. enable colors if OS seems to support colors and if stdin/stdout aren't redirected
@@ -999,12 +1015,12 @@ int main(int argc, char *argv[]) {
// try to open USB connection to Proxmark
if (port != NULL) {
OpenProxmark(port, waitCOMPort, 20, false, speed);
OpenProxmark(&session.current_device, port, waitCOMPort, 20, false, speed);
}
if (session.pm3_present && (TestProxmark() != PM3_SUCCESS)) {
if (session.pm3_present && (TestProxmark(session.current_device) != PM3_SUCCESS)) {
PrintAndLogEx(ERR, _RED_("ERROR:") " cannot communicate with the Proxmark\n");
CloseProxmark();
CloseProxmark(session.current_device);
}
if ((port != NULL) && (!session.pm3_present))
@@ -1060,10 +1076,11 @@ int main(int argc, char *argv[]) {
// Clean up the port
if (session.pm3_present) {
CloseProxmark();
CloseProxmark(session.current_device);
}
if (session.window_changed) // Plot/Overlay moved or resized
preferences_save();
exit(EXIT_SUCCESS);
}
#endif //LIBPM3