diff --git a/Makefile b/Makefile index 8338a6959..b7e942f58 100644 --- a/Makefile +++ b/Makefile @@ -251,7 +251,7 @@ print-%: ; @echo $* = $($*) cliparser: # Get list of all commands - cat doc/commands.md | grep -e ^\|\` | cut -f 2 -d "\`" | grep -v help | awk '{$$1=$$1};1' > cliparser_all_commands.tmp + cat doc/commands.md | grep -e ^\|\` | cut -f 2 -d "\`" | grep -v 'help\|list\|mem spiffs\|quit\|exit' | awk '{$$1=$$1};1' > cliparser_all_commands.tmp # Get list of cliparserized commands grep -r CLIParserInit ./client/src/ | cut -f 2 -d "\"" | awk '{$$1=$$1};1' > cliparser_done.tmp # Determine commands that still need cliparser conversion diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 72dfe87bd..0ed5271fc 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -907,7 +907,13 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_LF_TI_WRITE: { - WriteTItag(packet->oldarg[0], packet->oldarg[1], packet->oldarg[2]); + struct p { + uint32_t high; + uint32_t low; + uint16_t crc; + } PACKED; + struct p *payload = (struct p *)packet->data.asBytes; + WriteTItag(payload->high, payload->low, packet->crc); break; } case CMD_LF_SIMULATE: { diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 0d578295f..2bd5dc279 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -803,7 +803,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc) { AcquireTiType(); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - DbpString("Now use `lf ti read` to check"); + DbpString("Now use `lf ti reader` to check"); StopTicks(); } diff --git a/client/include/pm3.h b/client/include/pm3.h index cfdb69944..b9814ae48 100644 --- a/client/include/pm3.h +++ b/client/include/pm3.h @@ -4,8 +4,8 @@ typedef struct pm3_device pm3; pm3 *pm3_open(char *port); -int pm3_console(pm3* dev, char *cmd); -const char *pm3_name_get(pm3* dev); -void pm3_close(pm3* dev); +int pm3_console(pm3 *dev, char *cmd); +const char *pm3_name_get(pm3 *dev); +void pm3_close(pm3 *dev); pm3 *pm3_get_current_dev(void); #endif // LIBPM3_H diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 04382b7db..fdfc27946 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -3024,7 +3024,7 @@ static int CmdHFiClassLookUp(const char *Cmd) { typedef struct { uint8_t thread_idx; - uint8_t use_raw; + uint8_t use_raw; uint8_t use_elite; uint32_t keycnt; uint8_t csn[8]; @@ -3038,25 +3038,25 @@ typedef struct { static size_t iclass_tc = 1; -static void* bf_generate_mac(void *thread_arg) { - +static void *bf_generate_mac(void *thread_arg) { + iclass_thread_arg_t *targ = (iclass_thread_arg_t *)thread_arg; const uint8_t idx = targ->thread_idx; const uint8_t use_raw = targ->use_raw; const uint8_t use_elite = targ->use_elite; const uint32_t keycnt = targ->keycnt; - + uint8_t *keys = targ->keys; iclass_premac_t *list = targ->list.premac; - + uint8_t csn[8]; uint8_t cc_nr[12]; memcpy(csn, targ->csn, sizeof(csn)); memcpy(cc_nr, targ->cc_nr, sizeof(cc_nr)); - + uint8_t key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - + for (uint32_t i = idx; i < keycnt; i += iclass_tc) { memcpy(key, keys + 8 * i, 8); @@ -3080,14 +3080,14 @@ void GenerateMacFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, // init thread arguments for (uint8_t i = 0; i < iclass_tc; i++) { args[i].thread_idx = i; - args[i].use_raw = use_raw; + args[i].use_raw = use_raw; args[i].use_elite = use_elite; args[i].keycnt = keycnt; args[i].keys = keys; args[i].list.premac = list; - - memcpy(args[i].csn, CSN, sizeof(args[i].csn) ); - memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr) ); + + memcpy(args[i].csn, CSN, sizeof(args[i].csn)); + memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr)); } for (int i = 0; i < iclass_tc; i++) { @@ -3103,22 +3103,22 @@ void GenerateMacFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, pthread_join(threads[i], NULL); } -static void* bf_generate_mackey(void *thread_arg) { - +static void *bf_generate_mackey(void *thread_arg) { + iclass_thread_arg_t *targ = (iclass_thread_arg_t *)thread_arg; const uint8_t idx = targ->thread_idx; const uint8_t use_raw = targ->use_raw; const uint8_t use_elite = targ->use_elite; const uint32_t keycnt = targ->keycnt; - + uint8_t *keys = targ->keys; iclass_prekey_t *list = targ->list.prekey; - + uint8_t csn[8]; uint8_t cc_nr[12]; memcpy(csn, targ->csn, sizeof(csn)); memcpy(cc_nr, targ->cc_nr, sizeof(cc_nr)); - + uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; for (uint32_t i = idx; i < keycnt; i += iclass_tc) { @@ -3143,14 +3143,14 @@ void GenerateMacKeyFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elit // init thread arguments for (uint8_t i = 0; i < iclass_tc; i++) { args[i].thread_idx = i; - args[i].use_raw = use_raw; + args[i].use_raw = use_raw; args[i].use_elite = use_elite; args[i].keycnt = keycnt; args[i].keys = keys; args[i].list.prekey = list; - - memcpy(args[i].csn, CSN, sizeof(args[i].csn) ); - memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr) ); + + memcpy(args[i].csn, CSN, sizeof(args[i].csn)); + memcpy(args[i].cc_nr, CCNR, sizeof(args[i].cc_nr)); } for (int i = 0; i < iclass_tc; i++) { @@ -3164,7 +3164,7 @@ void GenerateMacKeyFrom(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elit for (int i = 0; i < iclass_tc; i++) pthread_join(threads[i], NULL); - + PrintAndLogEx(NORMAL, ""); } diff --git a/client/src/cmdhflto.c b/client/src/cmdhflto.c index 69dab2108..61b4b7b97 100644 --- a/client/src/cmdhflto.c +++ b/client/src/cmdhflto.c @@ -13,6 +13,7 @@ #include #include #include +#include "cliparser.h" #include "cmdparser.h" // command_t #include "comms.h" #include "cmdtrace.h" @@ -36,62 +37,6 @@ static int CmdHelp(const char *Cmd); -static int usage_lto_info(void) { - PrintAndLogEx(NORMAL, "Usage: hf lto info [h]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf lto info")); - return PM3_SUCCESS; -} - -static int usage_lto_rdbl(void) { - PrintAndLogEx(NORMAL, "Usage: hf lto rdbl [h] s e "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " s start block in decimal >= 0"); - PrintAndLogEx(NORMAL, " e end block in decimal <= 254"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf lto rdbl s 0 e 254") " - Read data block from 0 to 254"); - return PM3_SUCCESS; -} - -static int usage_lto_wrbl(void) { - PrintAndLogEx(NORMAL, "Usage: hf lto wrbl [h] b d "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " b block address (decimal, 0 - 254) "); - PrintAndLogEx(NORMAL, " d 32 bytes of data to write (64 hex characters, no space)"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf lto wrbl b 128 d 0001020304050607080910111213141516171819202122232425262728293031") " - write 00..31 to block address 128"); - return PM3_SUCCESS; -} - -static int usage_lto_dump(void) { - PrintAndLogEx(NORMAL, "Usage: hf lto dump [h|p] f "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " f file name"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf lto dump f myfile")); - return PM3_SUCCESS; -} - -static int usage_lto_restore(void) { - PrintAndLogEx(NORMAL, "Usage: hf lto restore [h] f "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " f file name [.bin|.eml]"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf lto restore f hf_lto_92C7842CFF.bin|.eml")); - return PM3_SUCCESS; -} - static void lto_switch_off_field(void) { SendCommandMIX(CMD_HF_ISO14443A_READER, 0, 0, 0, NULL, 0); } @@ -173,24 +118,16 @@ static int lto_select(uint8_t *id_response, uint8_t id_len, uint8_t *type_respon } static int CmdHfLTOInfo(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto info", + "Get info from LTO tags", + "hf lto info"); - uint8_t cmdp = 0; - bool errors = false; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lto_info(); - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - - //Validations - if (errors) { - return usage_lto_info(); - } + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); return infoLTO(true); } @@ -304,48 +241,31 @@ int rdblLTO(uint8_t st_blk, uint8_t end_blk, bool verbose) { } static int CmdHfLTOReadBlock(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto rdbl", + "Reead blocks from LTO tag", + "hf lto rdbl --first 0 --last 254"); - uint8_t cmdp = 0; - bool errors = false; - uint8_t st_blk = 0; - uint8_t end_blk = 254; + void *argtable[] = { + arg_param_begin, + arg_int0(NULL, "first", "", "The first block number to read as an integer"), + arg_int0(NULL, "last", "", "The last block number to read as an integer"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lto_rdbl(); - case 's': - st_blk = param_get8(Cmd, cmdp + 1); - if (end_blk < st_blk) { - errors = true; - break; - } - cmdp += 2; - break; + int startblock = arg_get_int_def(ctx, 1, 0); + int endblock = arg_get_int_def(ctx, 2, 254); - case 'e': - end_blk = param_get8(Cmd, cmdp + 1); - if (end_blk < st_blk) { - errors = true; - break; - } - cmdp += 2; - break; - - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } + CLIParserFree(ctx); //Validations - if (errors) { - usage_lto_rdbl(); + if (endblock < startblock) { + PrintAndLogEx(ERR, "First block must be less than last block"); return PM3_EINVARG; } - return rdblLTO(st_blk, end_blk, true); + return rdblLTO(startblock, endblock, true); } static int lto_wrbl(uint8_t blk, uint8_t *data, bool verbose) { @@ -407,46 +327,33 @@ int wrblLTO(uint8_t blk, uint8_t *data, bool verbose) { } static int CmdHfLTOWriteBlock(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto wrbl", + "Write data to block on LTO tag", + "hf lto wrbl --block 128 -d 0001020304050607080910111213141516171819202122232425262728293031"); - uint8_t cmdp = 0; - bool errors = false; - bool b_opt_selected = false; - bool d_opt_selected = false; - uint8_t blk = 128; + void *argtable[] = { + arg_param_begin, + arg_str1("d", "data", "", "32 bytes of data to write (64 hex symbols, no spaces)"), + arg_int1(NULL, "block", "", "The block number to write to as an integer"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int block_data_len = 0; uint8_t block_data[32] = {0}; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lto_wrbl(); - case 'b': - blk = param_get8(Cmd, cmdp + 1); - b_opt_selected = true; - cmdp += 2; - break; - case 'd': - if (param_gethex(Cmd, cmdp + 1, block_data, 64)) { - PrintAndLogEx(WARNING, "block data must include 64 HEX symbols"); - errors = true; - break; - } - d_opt_selected = true; - cmdp += 2; - break; - default: - PrintAndLogEx(WARNING, "unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } + CLIGetHexWithReturn(ctx, 1, block_data, &block_data_len); + + if (block_data_len != 32) { + PrintAndLogEx(ERR, "Block data is incorrect length"); + CLIParserFree(ctx); + return PM3_EINVARG; } - //Validations - if (errors) { - return usage_lto_wrbl(); - } else if (b_opt_selected == false || d_opt_selected == false) { - PrintAndLogEx(WARNING, "Need to specify block address and data."); - return usage_lto_wrbl(); - } + int blk = arg_get_int_def(ctx, 2, 0); + + CLIParserFree(ctx); int res = wrblLTO(blk, block_data, true); if (res == PM3_SUCCESS) @@ -504,35 +411,25 @@ int dumpLTO(uint8_t *dump, bool verbose) { } static int CmdHfLTODump(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto dump", + "Dump data from LTO tag", + "hf lto dump -f myfile"); - uint8_t cmdp = 0; - bool errors = false; - uint32_t dump_len = CM_MEM_MAX_SIZE; + void *argtable[] = { + arg_param_begin, + arg_str1("f", "file", "", "specify a filename for dumpfile"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int fnlen = 0; char filename[FILE_PATH_SIZE] = {0}; + CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lto_dump(); - case 'f': - if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { - PrintAndLogEx(FAILED, "filename too long"); - errors = true; - break; - } - cmdp += 2; - break; - default: - PrintAndLogEx(WARNING, "unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } + CLIParserFree(ctx); - if (errors) { - usage_lto_dump(); - return PM3_EINVARG; - } + uint32_t dump_len = CM_MEM_MAX_SIZE; uint8_t *dump = calloc(dump_len, sizeof(uint8_t)); if (!dump) { @@ -596,32 +493,23 @@ int restoreLTO(uint8_t *dump, bool verbose) { } static int CmdHfLTRestore(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto restore", + "Restore data from dumpfile to LTO tag", + "hf lto restore -f hf-lto-92C7842CFF.bin|.eml"); - uint8_t cmdp = 0; - bool errors = false; + void *argtable[] = { + arg_param_begin, + arg_str1("f", "file", "", "specify a filename for dumpfile"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int fnlen = 0; char filename[FILE_PATH_SIZE] = {0}; + CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lto_restore(); - case 'f': - param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE); - if (strlen(filename) < 5) - errors = true; - - cmdp += 2; - break; - default: - PrintAndLogEx(WARNING, "unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - - if (errors || strlen(Cmd) == 0) { - return usage_lto_restore(); - } + CLIParserFree(ctx); size_t dump_len = 0; char *lowstr = str_dup(filename); diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index 1f0d47ae5..46d7bf0cf 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -266,7 +266,17 @@ static int get_plus_version(uint8_t *version, int *version_len) { } static int CmdHFMFPInfo(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf mfp info", + "Get info from MIFARE Plus tags", + "hf mfp info"); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------"); diff --git a/client/src/cmdlfawid.c b/client/src/cmdlfawid.c index 1616c63fe..185e9a2f4 100644 --- a/client/src/cmdlfawid.c +++ b/client/src/cmdlfawid.c @@ -10,97 +10,28 @@ // Low frequency AWID26/50 commands // FSK2a, RF/50, 96 bits (complete) //----------------------------------------------------------------------------- -#include "cmdlfawid.h" // AWID function declarations - +#include "cmdlfawid.h" // AWID function declarations #include #include #include - -#include "commonutil.h" // ARRAYLEN +#include "commonutil.h" // ARRAYLEN #include "cmdparser.h" // command_t #include "comms.h" #include "graph.h" #include "cmddata.h" - -#include "ui.h" // PrintAndLog -#include "lfdemod.h" // parityTest -#include "cmdlf.h" // lf read -#include "protocols.h" // for T55xx config register definitions +#include "ui.h" // PrintAndLog +#include "lfdemod.h" // parityTest +#include "cmdlf.h" // lf read +#include "protocols.h" // for T55xx config register definitions #include "util_posix.h" -#include "cmdlft55xx.h" // verifywrite +#include "cmdlft55xx.h" // verifywrite +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines static int CmdHelp(const char *Cmd); -static int usage_lf_awid_watch(void) { - PrintAndLogEx(NORMAL, "Enables AWID compatible reader mode printing details of scanned AWID26 or AWID50 tags."); - PrintAndLogEx(NORMAL, "By default, values are printed and logged until the button is pressed or another USB command is issued."); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf awid watch"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid watch")); - return PM3_SUCCESS; -} - -static int usage_lf_awid_sim(void) { - PrintAndLogEx(NORMAL, "Enables simulation of AWID card with specified facility-code and card number."); - PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued."); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf awid sim [h] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : format length 26|34|37|50"); - PrintAndLogEx(NORMAL, " : 8|16bit value facility code"); - PrintAndLogEx(NORMAL, " : 16|32-bit value card number"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid sim 26 224 1337")); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid sim 50 2001 13371337")); - return PM3_SUCCESS; -} - -static int usage_lf_awid_clone(void) { - PrintAndLogEx(NORMAL, "Enables cloning of AWID card with specified facility-code and card number onto T55x7 or Q5/T5555."); - PrintAndLogEx(NORMAL, "The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process."); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf awid clone [h] [Q5]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : format length 26|34|37|50"); - PrintAndLogEx(NORMAL, " : 8|16bit value facility code"); - PrintAndLogEx(NORMAL, " : 16|32-bit value card number"); - PrintAndLogEx(NORMAL, " Q5 : optional - specify writing to Q5/T5555 tag"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid clone 26 224 1337")); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid clone 50 2001 13371337")); - return PM3_SUCCESS; -} - -static int usage_lf_awid_brute(void) { - PrintAndLogEx(NORMAL, "Enables bruteforce of AWID reader with specified facility-code."); - PrintAndLogEx(NORMAL, "This is a attack against reader. if cardnumber is given, it starts with it and goes up / down one step"); - PrintAndLogEx(NORMAL, "if cardnumber is not given, it starts with 1 and goes up to 65535"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf awid brute [h] [v] a f c d "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " a : format length 26|50"); - PrintAndLogEx(NORMAL, " f : 8|16bit value facility code"); - PrintAndLogEx(NORMAL, " c : (optional) cardnumber to start with, max 65535"); - PrintAndLogEx(NORMAL, " d : delay betweens attempts in ms. Default 1000ms"); - PrintAndLogEx(NORMAL, " v : verbose logging, show all tries"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid brute a 26 f 224")); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid brute a 50 f 2001 d 2000")); - PrintAndLogEx(NORMAL, _YELLOW_(" lf awid brute v a 50 f 2001 c 200 d 2000")); - return PM3_SUCCESS; -} - static int sendPing(void) { - SendCommandNG(CMD_PING, NULL, 0); - SendCommandNG(CMD_PING, NULL, 0); + SendCommandNG(CMD_BREAK_LOOP, NULL, 0); SendCommandNG(CMD_PING, NULL, 0); clearCommandBuffer(); PacketResponseNG resp; @@ -112,7 +43,7 @@ static int sendPing(void) { static int sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, size_t bs_len, bool verbose) { if (verbose) - PrintAndLogEx(INFO, "Trying FC: %u; CN: %u", fc, cn); + PrintAndLogEx(INFO, "Trying FC: " _YELLOW_("%u") " CN: " _YELLOW_("%u"), fc, cn); if (getAWIDBits(fmtlen, fc, cn, bits) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); @@ -180,8 +111,19 @@ static void verify_values(uint8_t *fmtlen, uint32_t *fc, uint32_t *cn) { // this read loops on device side. // uses the demod in lfops.c static int CmdAWIDWatch(const char *Cmd) { - uint8_t c = tolower(param_getchar(Cmd, 0)); - if (c == 'h') return usage_lf_awid_watch(); + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf awid watch", + "Enables AWID compatible reader mode printing details of scanned AWID26 or AWID50 tags.\n" + "Run until the button is pressed or another USB command is issued.", + "lf awid watch" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); PrintAndLogEx(SUCCESS, "Watching for AWID cards - place tag on antenna"); PrintAndLogEx(INFO, "Press pm3-button to stop reading cards"); @@ -339,31 +281,152 @@ int demodAWID(bool verbose) { } static int CmdAWIDDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf awid demod", + "Try to find AWID Prox preamble, if found decode / descramble data", + "lf awid demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodAWID(true); } // this read is the "normal" read, which download lf signal and tries to demod here. -static int CmdAWIDRead(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - lf_read(false, 12000); - return demodAWID(true); +static int CmdAWIDReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf awid reader", + "read a AWID Prox tag", + "lf awid reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 12000); + demodAWID(!cm); + } while (cm && !kbd_enter_pressed()); + + return PM3_SUCCESS; +} + +static int CmdAWIDClone(const char *Cmd) { + + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf awid clone", + "clone a AWID Prox tag to a T55x7, Q5/T5555 or EM4305/4469 tag", + "lf awid clone --fmt 26 --fc 123 --cn 1337\n" + "lf awid clone --fmt 50 --fc 2001 --cn 13371337\n" + "lf awid clone --q5 --fmt 26 --fc 123 --cn 1337 -> encode for Q5/T5555 tag\n" + "lf awid clone --em --fmt 26 --fc 123 --cn 1337 -> encode for EM4305/4469" + ); + + void *argtable[] = { + arg_param_begin, + arg_u64_1(NULL, "fmt", "", "format length 26|34|37|50"), + arg_u64_1(NULL, "fc", "", "8|16bit value facility code"), + arg_u64_1(NULL, "cn", "", "16|32-bit value card number"), + arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), + arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint8_t fmtlen = arg_get_u32_def(ctx, 1, 0); + uint32_t fc = arg_get_u32_def(ctx, 2, 0); + uint32_t cn = arg_get_u32_def(ctx, 3, 0); + bool q5 = arg_get_lit(ctx, 4); + bool em = arg_get_lit(ctx, 5); + CLIParserFree(ctx); + + if (q5 && em) { + PrintAndLogEx(FAILED, "Can't specify both Q5 and EM4305 at the same time"); + return PM3_EINVARG; + } + + uint32_t blocks[4] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0}; + char cardtype[16] = {"T55x7"}; + // Q5 + if (q5) { + //t5555 (Q5) BITRATE = (RF-2)/2 (iceman) + blocks[0] = T5555_FIXED | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(50) | 3 << T5555_MAXBLOCK_SHIFT; + snprintf(cardtype, sizeof(cardtype), "Q5/T5555"); + } + + // EM4305 + if (em) { + blocks[0] = EM4305_AWID_CONFIG_BLOCK; + snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); + } + + verify_values(&fmtlen, &fc, &cn); + + uint8_t *bits = calloc(96, sizeof(uint8_t)); + + if (getAWIDBits(fmtlen, fc, cn, bits) != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Error with tag bitstream generation."); + free(bits); + return PM3_ESOFT; + } + + blocks[1] = bytebits_to_byte(bits, 32); + blocks[2] = bytebits_to_byte(bits + 32, 32); + blocks[3] = bytebits_to_byte(bits + 64, 32); + + free(bits); + + PrintAndLogEx(INFO, "Preparing to clone AWID %u to " _YELLOW_("%s") " with FC: " _GREEN_("%u") " CN: " _GREEN_("%u"), fmtlen, cardtype, fc, cn); + print_blocks(blocks, ARRAYLEN(blocks)); + + int res; + if (em) { + res = em4x05_clone_tag(blocks, ARRAYLEN(blocks), 0, false); + } else { + res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + } + PrintAndLogEx(SUCCESS, "Done"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf awid reader`") " to verify"); + return res; } static int CmdAWIDSim(const char *Cmd) { - uint32_t fc = 0, cn = 0; - uint8_t fmtlen = 0; + + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf awid sim", + "Enables simulation of AWID card with specified facility-code and card number.\n" + "Simulation runs until the button is pressed or another USB command is issued.", + "lf awid sim --fmt 26 --fc 123 --cn 1337\n" + "lf awid sim --fmt 50 --fc 2001 --cn 13371337" + ); + + void *argtable[] = { + arg_param_begin, + arg_u64_1(NULL, "fmt", "", "format length 26|32|36|40"), + arg_u64_1(NULL, "fc", "", "8-bit value facility code"), + arg_u64_1(NULL, "cn", "", "16-bit value card number"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint8_t fmtlen = arg_get_u32_def(ctx, 1, 0); + uint32_t fc = arg_get_u32_def(ctx, 2, 0); + uint32_t cn = arg_get_u32_def(ctx, 3, 0); + CLIParserFree(ctx); + uint8_t bs[96]; memset(bs, 0x00, sizeof(bs)); - char cmdp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_awid_sim(); - - fmtlen = param_get8(Cmd, 0); - fc = param_get32ex(Cmd, 1, 0, 10); - cn = param_get32ex(Cmd, 2, 0, 10); - if (!fc || !cn) return usage_lf_awid_sim(); - verify_values(&fmtlen, &fc, &cn); if (getAWIDBits(fmtlen, fc, cn, bs) != PM3_SUCCESS) { @@ -371,7 +434,7 @@ static int CmdAWIDSim(const char *Cmd) { return PM3_ESOFT; } - PrintAndLogEx(SUCCESS, "Simulating AWID %u -- FC: %u; CN: %u\n", fmtlen, fc, cn); + PrintAndLogEx(SUCCESS, "Simulating AWID %u -- FC: " _YELLOW_("%u") " CN: " _YELLOW_("%u"), fmtlen, fc, cn); PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or run another command"); // AWID uses: FSK2a fcHigh: 10, fcLow: 8, clk: 50, invert: 1 @@ -398,97 +461,34 @@ static int CmdAWIDSim(const char *Cmd) { return PM3_SUCCESS; } -static int CmdAWIDClone(const char *Cmd) { - uint32_t fc = 0, cn = 0; - uint8_t fmtlen = 0; - char cmdp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_awid_clone(); - - fmtlen = param_get8(Cmd, 0); - fc = param_get32ex(Cmd, 1, 0, 10); - cn = param_get32ex(Cmd, 2, 0, 10); - - if (!fc || !cn) return usage_lf_awid_clone(); - - uint32_t blocks[4] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0}; - - bool q5 = tolower(param_getchar(Cmd, 3)) == 'q'; - if (q5) - //t5555 (Q5) BITRATE = (RF-2)/2 (iceman) - blocks[0] = T5555_FIXED | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(50) | 3 << T5555_MAXBLOCK_SHIFT; - - verify_values(&fmtlen, &fc, &cn); - - uint8_t *bits = calloc(96, sizeof(uint8_t)); - - if (getAWIDBits(fmtlen, fc, cn, bits) != PM3_SUCCESS) { - PrintAndLogEx(ERR, "Error with tag bitstream generation."); - free(bits); - return PM3_ESOFT; - } - - blocks[1] = bytebits_to_byte(bits, 32); - blocks[2] = bytebits_to_byte(bits + 32, 32); - blocks[3] = bytebits_to_byte(bits + 64, 32); - - free(bits); - - PrintAndLogEx(INFO, "Preparing to clone AWID %u to " _YELLOW_("%s") " with FC: %u, CN: %u", fmtlen, (q5) ? "Q5/T5555" : "T55x7", fc, cn); - print_blocks(blocks, ARRAYLEN(blocks)); - - int res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); - PrintAndLogEx(SUCCESS, "Done"); - PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf awid read`") " to verify"); - return res; -} - static int CmdAWIDBrute(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf awid brute", + "Enables bruteforce of AWID reader with specified facility-code.\n" + "This is a attack against reader. if cardnumber is given, it starts with it and goes up / down one step\n" + "if cardnumber is not given, it starts with 1 and goes up to 65535", + "lf awid brute --fmt 26 --fc 224\n" + "lf awid brute --fmt 50 --fc 2001 --delay 2000\n" + "lf awid brute --fmt 50 --fc 2001 --cn 200 --delay 2000 -v" + ); - bool errors = false, verbose = false; - uint32_t fc = 0, cn = 0, delay = 1000; - uint8_t fmtlen = 0; - uint8_t bits[96]; - size_t size = sizeof(bits); - memset(bits, 0x00, size); - uint8_t cmdp = 0; + void *argtable[] = { + arg_param_begin, + arg_u64_1(NULL, "fmt", "", "format length 26|50"), + arg_u64_1(NULL, "fc", "", "8|16bit value facility code"), + arg_u64_0(NULL, "cn", "", "optional - card number to start with, max 65535"), + arg_u64_0(NULL, "delay", "", "optional - delay betweens attempts in ms. Default 1000ms"), + arg_lit0("v", "verbose", "verbose logging, show all tries"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lf_awid_brute(); - case 'f': - fc = param_get32ex(Cmd, cmdp + 1, 0, 10); - if (!fc) - errors = true; - cmdp += 2; - break; - case 'd': - // delay between attemps, defaults to 1000ms. - delay = param_get32ex(Cmd, cmdp + 1, 1000, 10); - cmdp += 2; - break; - case 'c': - cn = param_get32ex(Cmd, cmdp + 1, 0, 10); - // truncate cardnumber. - cn &= 0xFFFF; - cmdp += 2; - break; - case 'a': - fmtlen = param_get8(Cmd, cmdp + 1); - cmdp += 2; - break; - case 'v': - verbose = true; - cmdp++; - break; - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - if (fc == 0) errors = true; - if (errors) return usage_lf_awid_brute(); + uint8_t fmtlen = arg_get_u32_def(ctx, 1, 0); + uint32_t fc = arg_get_u32_def(ctx, 2, 0); + uint32_t cn = arg_get_u32_def(ctx, 3, 0); + uint32_t delay = arg_get_u32_def(ctx, 4, 1000); + bool verbose = arg_get_lit(ctx, 5); + CLIParserFree(ctx); // limit fc according to selected format switch (fmtlen) { @@ -506,12 +506,23 @@ static int CmdAWIDBrute(const char *Cmd) { break; } - PrintAndLogEx(SUCCESS, "Bruteforceing AWID %d Reader", fmtlen); + + // truncate card number + if ((cn & 0xFFFF) != cn) { + cn &= 0xFFFF; + PrintAndLogEx(INFO, "Card number truncated to 16-bits : %u", cn); + } + + PrintAndLogEx(SUCCESS, "Bruteforceing AWID %d reader", fmtlen); PrintAndLogEx(SUCCESS, "Press pm3-button to abort simulation or press Enter"); uint16_t up = cn; uint16_t down = cn; + uint8_t bits[96]; + size_t size = sizeof(bits); + memset(bits, 0x00, size); + // main loop for (;;) { @@ -525,13 +536,20 @@ static int CmdAWIDBrute(const char *Cmd) { } // Do one up - if (up < 0xFFFF) - if (sendTry(fmtlen, fc, up++, delay, bits, size, verbose) != PM3_SUCCESS) return PM3_ESOFT; + if (up < 0xFFFF) { + if (sendTry(fmtlen, fc, up++, delay, bits, size, verbose) != PM3_SUCCESS) { + return PM3_ESOFT; + } + } // Do one down (if cardnumber is given) - if (cn > 1) - if (down > 1) - if (sendTry(fmtlen, fc, --down, delay, bits, size, verbose) != PM3_SUCCESS) return PM3_ESOFT; + if (cn > 1) { + if (down > 1) { + if (sendTry(fmtlen, fc, --down, delay, bits, size, verbose) != PM3_SUCCESS) { + return PM3_ESOFT; + } + } + } } return PM3_SUCCESS; } @@ -539,7 +557,7 @@ static int CmdAWIDBrute(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "this help"}, {"demod", CmdAWIDDemod, AlwaysAvailable, "demodulate an AWID FSK tag from the GraphBuffer"}, - {"read", CmdAWIDRead, IfPm3Lf, "attempt to read and extract tag data"}, + {"reader", CmdAWIDReader, IfPm3Lf, "attempt to read and extract tag data"}, {"clone", CmdAWIDClone, IfPm3Lf, "clone AWID tag to T55x7 or Q5/T5555"}, {"sim", CmdAWIDSim, IfPm3Lf, "simulate AWID tag"}, {"brute", CmdAWIDBrute, IfPm3Lf, "Bruteforce card number against reader"}, diff --git a/client/src/cmdlfcotag.c b/client/src/cmdlfcotag.c index 21a3b5786..a85ff8c3c 100644 --- a/client/src/cmdlfcotag.c +++ b/client/src/cmdlfcotag.c @@ -8,33 +8,18 @@ // Low frequency COTAG commands //----------------------------------------------------------------------------- #include "cmdlfcotag.h" // COTAG function declarations - #include #include - #include "cmdparser.h" // command_t #include "comms.h" #include "lfdemod.h" #include "cmddata.h" // getSamples #include "ui.h" // PrintAndLog #include "ctype.h" // tolower +#include "cliparser.h" static int CmdHelp(const char *Cmd); -static int usage_lf_cotag_read(void) { - PrintAndLogEx(NORMAL, "Usage: lf COTAG read [h] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " <0|1|2> : 0 - HIGH/LOW signal; maxlength bigbuff"); - PrintAndLogEx(NORMAL, " : 1 - translation of HI/LO into bytes with manchester 0,1"); - PrintAndLogEx(NORMAL, " : 2 - raw signal; maxlength bigbuff"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Example:"); - PrintAndLogEx(NORMAL, " lf cotag read 0"); - PrintAndLogEx(NORMAL, " lf cotag read 1"); - return PM3_SUCCESS; -} - // COTAG demod should be able to use GraphBuffer, // when data load samples int demodCOTAG(bool verbose) { @@ -74,22 +59,63 @@ int demodCOTAG(bool verbose) { } static int CmdCOTAGDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf cotag demod", + "Try to find COTAG preamble, if found decode / descramble data", + "lf cotag demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodCOTAG(true); } + // When reading a COTAG. // 0 = HIGH/LOW signal - maxlength bigbuff // 1 = translation for HI/LO into bytes with manchester 0,1 - length 300 // 2 = raw signal - maxlength bigbuff -static int CmdCOTAGRead(const char *Cmd) { +static int CmdCOTAGReader(const char *Cmd) { - if (tolower(Cmd[0]) == 'h') - return usage_lf_cotag_read(); + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf cotag reader", + "read a COTAG tag, the current support for COTAG is limited. ", + "lf cotag reader -2" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("1", NULL, "HIGH/LOW signal; maxlength bigbuff"), + arg_lit0("2", NULL, "translation of HIGH/LOW into bytes with manchester 0,1"), + arg_lit0("3", NULL, "raw signal; maxlength bigbuff"), + arg_param_end + }; + + CLIExecWithReturn(ctx, Cmd, argtable, false); + bool mode0 = arg_get_lit(ctx, 1); + bool mode1 = arg_get_lit(ctx, 2); + bool mode2 = arg_get_lit(ctx, 3); + CLIParserFree(ctx); + + if ((mode0 + mode1 + mode2) > 1) { + PrintAndLogEx(ERR, "You can only use one option at a time"); + return PM3_EINVARG; + } + uint8_t mode = 0xFF; + if (mode0) + mode = 0; + if (mode1) + mode = 1; + if (mode2) + mode = 2; struct p { uint8_t mode; } PACKED payload; - payload.mode = param_get8ex(Cmd, 0, 1, 10); + payload.mode = mode; PacketResponseNG resp; clearCommandBuffer(); @@ -126,9 +152,9 @@ static int CmdCOTAGRead(const char *Cmd) { } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"demod", CmdCOTAGDemod, AlwaysAvailable, "Tries to decode a COTAG signal"}, - {"read", CmdCOTAGRead, IfPm3Lf, "Attempt to read and extract tag data"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"demod", CmdCOTAGDemod, AlwaysAvailable, "Tries to decode a COTAG signal"}, + {"reader", CmdCOTAGReader, IfPm3Lf, "Attempt to read and extract tag data"}, {NULL, NULL, NULL, NULL} }; @@ -144,5 +170,5 @@ int CmdLFCOTAG(const char *Cmd) { } int readCOTAGUid(void) { - return (CmdCOTAGRead("") == PM3_SUCCESS); + return (CmdCOTAGReader("") == PM3_SUCCESS); } diff --git a/client/src/cmdlfdestron.c b/client/src/cmdlfdestron.c index 59d0c3813..aa73c1f79 100644 --- a/client/src/cmdlfdestron.c +++ b/client/src/cmdlfdestron.c @@ -7,22 +7,22 @@ // Low frequency FDX-A FECAVA Destron tag commands //----------------------------------------------------------------------------- #include "cmdlfdestron.h" - -#include //tolower -#include // memcpy -#include "commonutil.h" // ARRAYLEN +#include // tolower +#include // memcpy +#include "commonutil.h" // ARRAYLEN #include "common.h" #include "cmdparser.h" // command_t #include "comms.h" #include "ui.h" #include "cmddata.h" #include "cmdlf.h" -#include "lfdemod.h" // preamble test -#include "protocols.h" // t55xx defines -#include "cmdlft55xx.h" // clone.. -#include "cmdlf.h" // cmdlfconfig -#include "cliparser.h" // cli parse input +#include "lfdemod.h" // preamble test +#include "protocols.h" // t55xx defines +#include "cmdlft55xx.h" // clone.. +#include "cmdlf.h" // cmdlfconfig #include "parity.h" +#include "cliparser.h" // cli parse input +#include "cmdlfem4x05.h" // EM defines #define DESTRON_FRAME_SIZE 96 #define DESTRON_PREAMBLE_SIZE 16 @@ -36,6 +36,7 @@ int demodDestron(bool verbose) { PrintAndLogEx(DEBUG, "DEBUG: Error - Destron: FSK Demod failed"); return PM3_ESOFT; } + size_t size = DemodBufferLen; int ans = detectDestron(DemodBuffer, &size); if (ans < 0) { @@ -50,12 +51,13 @@ int demodDestron(bool verbose) { return PM3_ESOFT; } + setDemodBuff(DemodBuffer, DESTRON_FRAME_SIZE, ans); setClockGrid(g_DemodClock, g_DemodStartIdx + (ans * g_DemodClock)); uint8_t bits[DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE] = {0}; size_t bitlen = DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE; - memcpy(bits, DemodBuffer + 16, DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE); + memcpy(bits, DemodBuffer + DESTRON_PREAMBLE_SIZE, DESTRON_FRAME_SIZE - DESTRON_PREAMBLE_SIZE); uint8_t alignPos = 0; uint16_t errCnt = manrawdecode(bits, &bitlen, 0, &alignPos); @@ -75,75 +77,155 @@ int demodDestron(bool verbose) { PrintAndLogEx(DEBUG, "DEBUG: Error - Destron: parity errors: %d", parity_err); return PM3_ESOFT; } - PrintAndLogEx(SUCCESS, "FDX-A FECAVA Destron: " _GREEN_("%02X%02X%02X%02X%02X"), data[0], data[1], data[2], data[3], data[4]); + PrintAndLogEx(SUCCESS, "FDX-A FECAVA Destron: " _GREEN_("%s"), sprint_hex_inrow(data, 5)); return PM3_SUCCESS; } static int CmdDestronDemod(const char *Cmd) { - (void)Cmd; - return demodDestron(true); -} - -static int CmdDestronRead(const char *Cmd) { - lf_read(false, 16000); - return demodDestron(true); -} - -static int CmdDestronClone(const char *Cmd) { - - uint32_t blocks[4] = {0}; - uint8_t data[8]; - int datalen = 0; - CLIParserContext *ctx; - CLIParserInit(&ctx, "lf destron clone", - "Enables cloning of Destron card with specified uid onto T55x7", - "lf destron clone 1A2B3C4D5E" + CLIParserInit(&ctx, "lf destron demod", + "Try to find Destron preamble, if found decode / descramble data", + "lf destron demod" ); void *argtable[] = { arg_param_begin, - arg_strx1(NULL, NULL, "", NULL), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); + return demodDestron(true); +} + +static int CmdDestronReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf destron reader", + "read a Destron tag", + "lf destron reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 16000); + demodDestron(!cm); + } while (cm && !kbd_enter_pressed()); + + return PM3_SUCCESS; +} + +static int CmdDestronClone(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf destron clone", + "clone a Destron tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", + "lf destron clone --uid 1A2B3C4D5E\n" + "lf destron clone --q5 --uid 1A2B3C4D5E -> encode for Q5/T5555 tag\n" + "lf destron clone --em --uid 1A2B3C4D5E -> encode for EM4305/4469" + ); + + void *argtable[] = { + arg_param_begin, + arg_strx1("u", "uid", "", "5 bytes max"), + arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), + arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), arg_param_end }; //TODO add selection of chip for Q5 or T55x7 CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint8_t data[8]; + int datalen = 0; CLIGetHexWithReturn(ctx, 1, data, &datalen); + bool q5 = arg_get_lit(ctx, 2); + bool em = arg_get_lit(ctx, 3); CLIParserFree(ctx); + if (q5 && em) { + PrintAndLogEx(FAILED, "Can't specify both Q5 and EM4305 at the same time"); + return PM3_EINVARG; + } + + if (datalen > 5) { + PrintAndLogEx(FAILED, "Uid is max 5 bytes. (got %u)", datalen); + return PM3_EINVARG; + } + + uint32_t blocks[4] = {0}; + blocks[0] = T55x7_BITRATE_RF_50 | T55x7_MODULATION_FSK2 | 3 << T55x7_MAXBLOCK_SHIFT; + char cardtype[16] = {"T55x7"}; + // Q5 + if (q5) { + blocks[0] = T5555_FIXED | T5555_MODULATION_FSK2 | T5555_SET_BITRATE(50) | 3 << T5555_MAXBLOCK_SHIFT; + snprintf(cardtype, sizeof(cardtype), "Q5/T5555"); + } + + // EM4305 + if (em) { + blocks[0] = EM4305_DESTRON_CONFIG_BLOCK; + snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); + } + uint8_t data_ex[12 + 24] = {0}; // ManchesterEncode need extra room for (int i = 0; i < datalen; i++) { - data_ex[i + 1] = ~data [i] | (evenparity8(data[i]) << 7); + data_ex[i + 1] = ~(data [i] | (oddparity8(data[i]) << 7)); } + + // manchester encode it for (int i = 0; i < 3; i++) { blocks[i + 1] = manchesterEncode2Bytes((data_ex[i * 2] << 8) + data_ex[i * 2 + 1]); } // inject preamble blocks[1] = (blocks[1] & 0xFFFF) | 0xAAE20000; - PrintAndLogEx(INFO, "Preparing to clone Destron tag with ID: %s", sprint_hex(data, datalen)); - blocks[0] = T55x7_BITRATE_RF_50 | T55x7_MODULATION_FSK2 | 3 << T55x7_MAXBLOCK_SHIFT; + PrintAndLogEx(INFO, "Preparing to clone Destron tag to " _YELLOW_("%s") " with ID: " _YELLOW_("%s") + , cardtype + , sprint_hex_inrow(data, datalen) + ); + print_blocks(blocks, ARRAYLEN(blocks)); - int res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + int res; + if (em) { + res = em4x05_clone_tag(blocks, ARRAYLEN(blocks), 0, false); + } else { + res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + } PrintAndLogEx(SUCCESS, "Done"); - PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf Destron read`") " to verify"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf destron reader`") " to verify"); return res; } static int CmdDestronSim(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf destron sim", + "Try to find Destron preamble, if found decode / descramble data", + "lf destron sim" + ); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); PrintAndLogEx(INFO, " To be implemented, feel free to contribute!"); return PM3_SUCCESS; } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"demod", CmdDestronDemod, AlwaysAvailable, "Demodulate an Destron tag from the GraphBuffer"}, - {"read", CmdDestronRead, IfPm3Lf, "Attempt to read and extract tag data from the antenna"}, - {"clone", CmdDestronClone, IfPm3Lf, "Clone Destron tag to T55x7"}, - {"sim", CmdDestronSim, IfPm3Lf, "Simulate Destron tag"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"demod", CmdDestronDemod, AlwaysAvailable, "Demodulate an Destron tag from the GraphBuffer"}, + {"reader", CmdDestronReader, IfPm3Lf, "Attempt to read and extract tag data from the antenna"}, + {"clone", CmdDestronClone, IfPm3Lf, "Clone Destron tag to T55x7"}, + {"sim", CmdDestronSim, IfPm3Lf, "Simulate Destron tag"}, {NULL, NULL, NULL, NULL} }; @@ -185,5 +267,5 @@ int detectDestron(uint8_t *dest, size_t *size) { } int readDestronUid(void) { - return (CmdDestronRead("") == PM3_SUCCESS); + return (CmdDestronReader("") == PM3_SUCCESS); } diff --git a/client/src/cmdlfem4x05.h b/client/src/cmdlfem4x05.h index dfe91da09..cdcff7896 100644 --- a/client/src/cmdlfem4x05.h +++ b/client/src/cmdlfem4x05.h @@ -30,7 +30,9 @@ #define EM4305_NORALSY_CONFIG_BLOCK (EM4x05_SET_BITRATE(32) | EM4x05_MODULATION_MANCHESTER | EM4x05_SET_NUM_BLOCKS(3) ) // ASK, data rate 32, 3 data blocks #define EM4305_PRESCO_CONFIG_BLOCK (EM4x05_SET_BITRATE(32) | EM4x05_MODULATION_MANCHESTER | EM4x05_SET_NUM_BLOCKS(4) ) // ASK/MAN, data rate 32, 4 data blocks #define EM4305_SECURAKEY_CONFIG_BLOCK (EM4x05_SET_BITRATE(40) | EM4x05_MODULATION_MANCHESTER | EM4x05_SET_NUM_BLOCKS(3) ) // ASK/MAN, data rate 40, 3 data blocks +#define EM4305_GALLAGHER_CONFIG_BLOCK (EM4x05_SET_BITRATE(32) | EM4x05_MODULATION_MANCHESTER | EM4x05_SET_NUM_BLOCKS(3) ) // ASK/MAN, data rate 32, 3 data blocks +#define EM4305_DESTRON_CONFIG_BLOCK (EM4x05_SET_BITRATE(50) | EM4x05_MODULATION_FSK2 | EM4x05_SET_NUM_BLOCKS(3) ) // FSK2a, hid 26 bit, data rate 50, 3 data blocks #define EM4305_HID_26_CONFIG_BLOCK (EM4x05_SET_BITRATE(50) | EM4x05_MODULATION_FSK2 | EM4x05_SET_NUM_BLOCKS(3) ) // FSK2a, hid 26 bit, data rate 50, 3 data blocks #define EM4305_PARADOX_CONFIG_BLOCK (EM4x05_SET_BITRATE(50) | EM4x05_MODULATION_FSK2 | EM4x05_SET_NUM_BLOCKS(3) ) // FSK2a, hid 26 bit, data rate 50, 3 data blocks #define EM4305_AWID_CONFIG_BLOCK (EM4x05_SET_BITRATE(50) | EM4x05_MODULATION_FSK2 | EM4x05_SET_NUM_BLOCKS(3) ) // FSK2a, hid 26 bit, data rate 50, 3 data blocks @@ -47,6 +49,7 @@ #define EM4305_GUARDPROXII_CONFIG_BLOCK (EM4x05_SET_BITRATE(64) | EM4x05_MODULATION_BIPHASE | EM4x05_SET_NUM_BLOCKS(3) ) // Biphase, data rate 64, Direct modulation, 3 data blocks #define EM4305_NEDAP_64_CONFIG_BLOCK (EM4x05_SET_BITRATE(64) | EM4x05_MODULATION_BIPHASE | EM4x05_SET_NUM_BLOCKS(2) ) // Biphase, data rate 64, 2 data blocks #define EM4305_NEDAP_128_CONFIG_BLOCK (EM4x05_SET_BITRATE(64) | EM4x05_MODULATION_BIPHASE | EM4x05_SET_NUM_BLOCKS(4) ) // Biphase, data rate 64, 4 data blocks +#define EM4305_FDXB_CONFIG_BLOCK (EM4x05_SET_BITRATE(32) | EM4x05_MODULATION_BIPHASE | EM4x05_SET_NUM_BLOCKS(4) ) // Biphase, data rate 32, 4 data blocks #define EM4305_PAC_CONFIG_BLOCK (EM4x05_SET_BITRATE(32) | EM4x05_MODULATION_NRZ | EM4x05_SET_NUM_BLOCKS(4) ) // NRZ, data rate 32, 4 data blocks #define EM4305_VERICHIP_CONFIG_BLOCK (EM4x05_SET_BITRATE(40) | EM4x05_MODULATION_NRZ | EM4x05_SET_NUM_BLOCKS(4) ) // NRZ, data rate 40, 4 data blocks diff --git a/client/src/cmdlffdxb.c b/client/src/cmdlffdxb.c index 92e466358..95e152716 100644 --- a/client/src/cmdlffdxb.c +++ b/client/src/cmdlffdxb.c @@ -9,23 +9,22 @@ //----------------------------------------------------------------------------- #include "cmdlffdxb.h" - #include #include #include -#include // tolower - +#include // tolower #include "cmdparser.h" // command_t #include "comms.h" #include "commonutil.h" - -#include "ui.h" // PrintAndLog +#include "ui.h" // PrintAndLog #include "cmddata.h" -#include "cmdlf.h" // lf read -#include "crc16.h" // for checksum crc-16_ccitt -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest -#include "cmdlft55xx.h" // verifywrite +#include "cmdlf.h" // lf read +#include "crc16.h" // for checksum crc-16_ccitt +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest +#include "cmdlft55xx.h" // verifywrite +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines /* FDX-B ISO11784/85 demod (aka animal tag) BIPHASE, inverted, rf/32, with preamble of 00000000001 (128bits) @@ -48,55 +47,63 @@ static int CmdHelp(const char *Cmd); -static int usage_lf_fdxb_clone(void) { - PrintAndLogEx(NORMAL, "Clone a FDX-B animal tag to a T55x7 or Q5/T5555 tag."); - PrintAndLogEx(NORMAL, "Usage: lf fdxb clone [h] [c ] [n ] [e ] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " c : (dec) Country code"); - PrintAndLogEx(NORMAL, " n : (dec) National code"); - PrintAndLogEx(NORMAL, " e : (hex) Extended data"); - PrintAndLogEx(NORMAL, " s : Set animal bit"); - PrintAndLogEx(NORMAL, " : Specify writing to Q5/T5555 tag"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf fdxb clone c 999 n 112233 s")); - PrintAndLogEx(NORMAL, _YELLOW_(" lf fdxb clone c 999 n 112233 e 16a")); - return PM3_SUCCESS; -} +static int getFDXBBits(uint64_t national_code, uint16_t country_code, uint8_t is_animal, uint8_t is_extended, uint16_t extended, uint8_t *bits) { -static int usage_lf_fdxb_read(void) { - PrintAndLogEx(NORMAL, "Read FDX-B animal tag"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf fdxb read [h] [@]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " @ : run continuously until a key is pressed (optional)"); - PrintAndLogEx(NORMAL, "Note that the continuous mode is less verbose"); - return PM3_SUCCESS; -} + // add preamble ten 0x00 and one 0x01 + memset(bits, 0x00, 10); + bits[10] = 1; -static int usage_lf_fdxb_sim(void) { - PrintAndLogEx(NORMAL, "Enables simulation of FDX-B animal tag"); - PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued."); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf fdxb sim [h] [c ] [n ] [e ] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " c : (dec) Country code"); - PrintAndLogEx(NORMAL, " n : (dec) National code"); - PrintAndLogEx(NORMAL, " e : (hex) Extended data"); - PrintAndLogEx(NORMAL, " s : Set animal bit"); - PrintAndLogEx(NORMAL, " : Specify writing to Q5/T5555 tag"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf fdxb sim c 999 n 112233 s")); - PrintAndLogEx(NORMAL, _YELLOW_(" lf fdxb sim c 999 n 112233 e 16a")); + // 128bits + // every 9th bit is 0x01, but we can just fill the rest with 0x01 and overwrite + memset(bits, 0x01, 128); + + // add preamble ten 0x00 and one 0x01 + memset(bits, 0x00, 10); + + // add reserved + num_to_bytebitsLSBF(0x00, 7, bits + 66); + num_to_bytebitsLSBF(0x00 >> 7, 7, bits + 74); + + // add animal flag - OK + bits[81] = is_animal; + + // add extended flag - OK + bits[65] = is_extended; + + // add national code 40bits - OK + num_to_bytebitsLSBF(national_code >> 0, 8, bits + 11); + num_to_bytebitsLSBF(national_code >> 8, 8, bits + 20); + num_to_bytebitsLSBF(national_code >> 16, 8, bits + 29); + num_to_bytebitsLSBF(national_code >> 24, 8, bits + 38); + num_to_bytebitsLSBF(national_code >> 32, 6, bits + 47); + + // add country code - OK + num_to_bytebitsLSBF(country_code >> 0, 2, bits + 53); + num_to_bytebitsLSBF(country_code >> 2, 8, bits + 56); + + // add crc-16 - OK + uint8_t raw[8]; + for (uint8_t i = 0; i < 8; ++i) + raw[i] = bytebits_to_byte(bits + 11 + i * 9, 8); + + init_table(CRC_11784); + uint16_t crc = crc16_fdxb(raw, 8); + num_to_bytebitsLSBF(crc >> 0, 8, bits + 83); + num_to_bytebitsLSBF(crc >> 8, 8, bits + 92); + + // extended data - OK + num_to_bytebitsLSBF(extended >> 0, 8, bits + 101); + num_to_bytebitsLSBF(extended >> 8, 8, bits + 110); + num_to_bytebitsLSBF(extended >> 16, 8, bits + 119); + + // 8 16 24 32 40 48 49 + // A8 28 0C 92 EA 6F 00 01 + // A8 28 0C 92 EA 6F 80 00 return PM3_SUCCESS; } // clearing the topbit needed for the preambl detection. -static void verify_values(uint64_t *animalid, uint32_t *countryid, uint32_t *extended, uint8_t *is_animal) { +static void verify_values(uint64_t *animalid, uint32_t *countryid, uint16_t *extended) { if ((*animalid & 0x3FFFFFFFFF) != *animalid) { *animalid &= 0x3FFFFFFFFF; PrintAndLogEx(INFO, "Animal ID truncated to 38bits: " _YELLOW_("%"PRIx64), *animalid); @@ -109,8 +116,6 @@ static void verify_values(uint64_t *animalid, uint32_t *countryid, uint32_t *ext *extended &= 0xFFF; PrintAndLogEx(INFO, "Extended truncated to 24bits: " _YELLOW_("0x%03X"), *extended); } - - *is_animal &= 0x01; } static inline uint32_t bitcount(uint32_t a) { @@ -607,71 +612,75 @@ int demodFDXB(bool verbose) { } static int CmdFdxBDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf fdxb demod", + "Try to find FDX-B preamble, if found decode / descramble data", + "lf fdxb demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodFDXB(true); } -static int CmdFdxBRead(const char *Cmd) { +static int CmdFdxBReader(const char *Cmd) { + + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf fdxb reader", + "read a FDX-B animal tag\n" + "Note that the continuous mode is less verbose", + "lf fdxb reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + sample_config config; memset(&config, 0, sizeof(sample_config)); - int retval = lf_getconfig(&config); - if (retval != PM3_SUCCESS) { + int res = lf_getconfig(&config); + if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "failed to get current device LF config"); - return retval; + return res; } - bool errors = false; - bool continuous = false; - uint8_t cmdp = 0; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lf_fdxb_read(); - case '@': - continuous = true; - cmdp++; - break; - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - - //Validations - if (errors) return usage_lf_fdxb_read(); int16_t tmp_div = config.divisor; if (tmp_div != LF_DIVISOR_134) { config.divisor = LF_DIVISOR_134; config.verbose = false; - retval = lf_config(&config); - if (retval != PM3_SUCCESS) { + res = lf_config(&config); + if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "failed to change LF configuration"); - return retval; + return res; } } - if (continuous) { - PrintAndLogEx(INFO, "Press " _GREEN_("Enter") " to exit"); + + if (cm) { + PrintAndLogEx(INFO, "Press " _GREEN_("") " to exit"); } + int ret = PM3_SUCCESS; do { - retval = lf_read(false, 10000); - if (retval != PM3_SUCCESS) { - PrintAndLogEx(ERR, "failed to get LF read from device"); - return retval; - } - ret = demodFDXB(!continuous); // be verbose only if not in continuous mode - if (kbd_enter_pressed()) { - break; - } - PrintAndLogEx(INPLACE, ""); - } while (continuous); + lf_read(false, 10000); + ret = demodFDXB(!cm); // be verbose only if not in continuous mode + //PrintAndLogEx(INPLACE, ""); + } while (cm && !kbd_enter_pressed()); + if (tmp_div != LF_DIVISOR_134) { config.divisor = tmp_div; - retval = lf_config(&config); - if (retval != PM3_SUCCESS) { + res = lf_config(&config); + if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "failed to restore LF configuration"); - return retval; + return res; } } return ret; @@ -679,145 +688,159 @@ static int CmdFdxBRead(const char *Cmd) { static int CmdFdxBClone(const char *Cmd) { - uint32_t country_code = 0, extended = 0; - uint64_t national_code = 0; - uint8_t is_animal = 0, cmdp = 0; - bool errors = false, has_extended = false, q5 = false; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf fdxb clone", + "clone a FDX-B tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", + "lf fdxb clone --country 999 --national 1337 --animal\n" + "lf fdxb clone --country 999 --national 1337 --extended 016A\n" + "lf fdxb clone --q5 --country 999 --national 1337 -> encode for Q5/T5555 tag\n" + "lf fdxb clone --em --country 999 --national 1337 -> encode for EM4305/4469" + ); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lf_fdxb_clone(); - case 'c': { - country_code = param_get32ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - } - case 'n': { - national_code = param_get64ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - } - case 'e': { - extended = param_get32ex(Cmd, cmdp + 1, 0, 16); - has_extended = true; - cmdp += 2; - break; - } - case 's': { - is_animal = 1; - cmdp++; - break; - } - case 'q': { - q5 = true; - cmdp++; - break; - } - default: { - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } + void *argtable[] = { + arg_param_begin, + arg_u64_1("c", "country", "", "country code"), + arg_u64_1("n", "national", "", "national code"), + arg_str0(NULL, "extended", "", "extended data"), + arg_lit0("a", "animal", "optional - set animal bit"), + arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), + arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint32_t country_code = arg_get_u32_def(ctx, 1, 0); + uint64_t national_code = arg_get_u64_def(ctx, 2, 0); + + int extended_len = 0; + uint8_t edata[2] = {0}; + CLIGetHexWithReturn(ctx, 3, edata, &extended_len); + + bool is_animal = arg_get_lit(ctx, 4); + bool q5 = arg_get_lit(ctx, 5); + bool em = arg_get_lit(ctx, 6); + CLIParserFree(ctx); + + if (q5 && em) { + PrintAndLogEx(FAILED, "Can't specify both Q5 and EM4305 at the same time"); + return PM3_EINVARG; } - if (errors || strlen(Cmd) == 0) return usage_lf_fdxb_clone(); - verify_values(&national_code, &country_code, &extended, &is_animal); + uint16_t extended = 0; + bool has_extended = false; + if (extended_len) { + extended = bytes_to_num(edata, extended_len); + has_extended = true; + } - PrintAndLogEx(INFO, " Country code %"PRIu32, country_code); - PrintAndLogEx(INFO, " National code %"PRIu64, national_code); - PrintAndLogEx(INFO, " Set animal bit %c", (is_animal) ? 'Y' : 'N'); - PrintAndLogEx(INFO, "Set data block bit %c", (has_extended) ? 'Y' : 'N'); - PrintAndLogEx(INFO, " Extended data 0x%"PRIX32, extended); - PrintAndLogEx(INFO, " RFU 0"); + verify_values(&national_code, &country_code, &extended); - uint8_t *bits = calloc(128, sizeof(uint8_t)); - if (getFDXBBits(national_code, country_code, is_animal, has_extended, extended, bits) != PM3_SUCCESS) { + PrintAndLogEx(INFO, "Country code........ %"PRIu32, country_code); + PrintAndLogEx(INFO, "National code....... %"PRIu64, national_code); + PrintAndLogEx(INFO, "Set animal bit...... %c", (is_animal) ? 'Y' : 'N'); + PrintAndLogEx(INFO, "Set data block bit.. %c", (has_extended) ? 'Y' : 'N'); + PrintAndLogEx(INFO, "Extended data....... 0x%"PRIX32, extended); + PrintAndLogEx(INFO, "RFU................. 0"); + + uint8_t *bs = calloc(128, sizeof(uint8_t)); + if (getFDXBBits(national_code, country_code, is_animal, has_extended, extended, bs) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); - free(bits); + free(bs); return PM3_ESOFT; } uint32_t blocks[5] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0}; + char cardtype[16] = {"T55x7"}; - //Q5 - if (q5) + // Q5 + if (q5) { blocks[0] = T5555_FIXED | T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(32) | 4 << T5555_MAXBLOCK_SHIFT; + snprintf(cardtype, sizeof(cardtype), "Q5/T5555"); + } + + // EM4305 + if (em) { + blocks[0] = EM4305_FDXB_CONFIG_BLOCK; + snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); + } // convert from bit stream to block data - blocks[1] = bytebits_to_byte(bits, 32); - blocks[2] = bytebits_to_byte(bits + 32, 32); - blocks[3] = bytebits_to_byte(bits + 64, 32); - blocks[4] = bytebits_to_byte(bits + 96, 32); + blocks[1] = bytebits_to_byte(bs, 32); + blocks[2] = bytebits_to_byte(bs + 32, 32); + blocks[3] = bytebits_to_byte(bs + 64, 32); + blocks[4] = bytebits_to_byte(bs + 96, 32); - free(bits); + free(bs); - PrintAndLogEx(INFO, "Preparing to clone FDX-B to " _YELLOW_("%s") " with animal ID: " _GREEN_("%04u-%"PRIu64), (q5) ? "Q5/T5555" : "T55x7", country_code, national_code); + PrintAndLogEx(INFO, "Preparing to clone FDX-B to " _YELLOW_("%s") " with animal ID: " _GREEN_("%04u-%"PRIu64) + , cardtype + , country_code + , national_code + ); print_blocks(blocks, ARRAYLEN(blocks)); - int res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + int res; + if (em) { + res = em4x05_clone_tag(blocks, ARRAYLEN(blocks), 0, false); + } else { + res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + } PrintAndLogEx(SUCCESS, "Done"); - PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf fdxb read`") " to verify"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf fdxb reader`") " to verify"); return res; } static int CmdFdxBSim(const char *Cmd) { - uint32_t country_code = 0, extended = 0; - uint64_t national_code = 0; - uint8_t is_animal = 0, cmdp = 0; - bool errors = false, has_extended = false; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf fdxb sim", + "Enables simulation of FDX-B animal tag.\n" + "Simulation runs until the button is pressed or another USB command is issued.", + "lf fdxb sim --country 999 --national 1337 --animal\n" + "lf fdxb sim --country 999 --national 1337 --extended 016A\n" + ); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lf_fdxb_sim(); - case 'c': { - country_code = param_get32ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - } - case 'n': { - national_code = param_get64ex(Cmd, cmdp + 1, 0, 10); - cmdp += 2; - break; - } - case 'e': { - extended = param_get32ex(Cmd, cmdp + 1, 0, 10); - has_extended = true; - cmdp += 2; - break; - } - case 's': { - is_animal = 1; - cmdp++; - break; - } - default: { - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } + void *argtable[] = { + arg_param_begin, + arg_u64_1("c", "country", "", "country code"), + arg_u64_1("n", "national", "", "national code"), + arg_str0(NULL, "extended", "", "extended data"), + arg_lit0("a", "animal", "optional - set animal bit"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + uint32_t country_code = arg_get_u32_def(ctx, 1, 0); + uint64_t national_code = arg_get_u64_def(ctx, 2, 0); + int extended_len = 0; + uint8_t edata[2] = {0}; + CLIGetHexWithReturn(ctx, 3, edata, &extended_len); + + bool is_animal = arg_get_lit(ctx, 4); + CLIParserFree(ctx); + + uint16_t extended = 0; + bool has_extended = false; + if (extended_len) { + extended = bytes_to_num(edata, extended_len); + has_extended = true; } - if (errors) return usage_lf_fdxb_sim(); - verify_values(&national_code, &country_code, &extended, &is_animal); + verify_values(&national_code, &country_code, &extended); - PrintAndLogEx(INFO, " Country code %"PRIu32, country_code); - PrintAndLogEx(INFO, " National code %"PRIu64, national_code); - PrintAndLogEx(INFO, " Set animal bit %c", (is_animal) ? 'Y' : 'N'); - PrintAndLogEx(INFO, "Set data block bit %c", (has_extended) ? 'Y' : 'N'); - PrintAndLogEx(INFO, " Extended data 0x%"PRIX32, extended); - PrintAndLogEx(INFO, " RFU 0"); + PrintAndLogEx(INFO, "Country code........ %"PRIu32, country_code); + PrintAndLogEx(INFO, "National code....... %"PRIu64, national_code); + PrintAndLogEx(INFO, "Set animal bit...... %c", (is_animal) ? 'Y' : 'N'); + PrintAndLogEx(INFO, "Set data block bit.. %c", (has_extended) ? 'Y' : 'N'); + PrintAndLogEx(INFO, "Extended data....... 0x%"PRIX16, extended); + PrintAndLogEx(INFO, "RFU................. 0"); - PrintAndLogEx(SUCCESS, "Simulating FDX-B animal ID: " _GREEN_("%04u-%"PRIu64), country_code, national_code); + PrintAndLogEx(SUCCESS, "Simulating FDX-B animal ID: " _YELLOW_("%04u-%"PRIu64), country_code, national_code); - uint8_t *bits = calloc(128, sizeof(uint8_t)); - if (getFDXBBits(national_code, country_code, is_animal, (extended > 0), extended, bits) != PM3_SUCCESS) { + uint8_t *bs = calloc(128, sizeof(uint8_t)); + if (getFDXBBits(national_code, country_code, is_animal, (extended > 0), extended, bs) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); - free(bits); + free(bs); return PM3_ESOFT; } @@ -827,12 +850,12 @@ static int CmdFdxBSim(const char *Cmd) { payload->invert = 1; payload->separator = 0; payload->clock = 32; - memcpy(payload->data, bits, 128); + memcpy(payload->data, bs, 128); clearCommandBuffer(); SendCommandNG(CMD_LF_ASK_SIMULATE, (uint8_t *)payload, sizeof(lf_asksim_t) + 128); - free(bits); + free(bs); free(payload); PacketResponseNG resp; @@ -846,11 +869,11 @@ static int CmdFdxBSim(const char *Cmd) { } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "this help"}, - {"demod", CmdFdxBDemod, AlwaysAvailable, "demodulate a FDX-B ISO11784/85 tag from the GraphBuffer"}, - {"read", CmdFdxBRead, IfPm3Lf, "attempt to read at 134kHz and extract tag data"}, - {"clone", CmdFdxBClone, IfPm3Lf, "clone animal ID tag to T55x7 or Q5/T5555"}, - {"sim", CmdFdxBSim, IfPm3Lf, "simulate Animal ID tag"}, + {"help", CmdHelp, AlwaysAvailable, "this help"}, + {"demod", CmdFdxBDemod, AlwaysAvailable, "demodulate a FDX-B ISO11784/85 tag from the GraphBuffer"}, + {"reader", CmdFdxBReader, IfPm3Lf, "attempt to read at 134kHz and extract tag data"}, + {"clone", CmdFdxBClone, IfPm3Lf, "clone animal ID tag to T55x7 or Q5/T5555"}, + {"sim", CmdFdxBSim, IfPm3Lf, "simulate Animal ID tag"}, {NULL, NULL, NULL, NULL} }; @@ -878,59 +901,3 @@ int detectFDXB(uint8_t *dest, size_t *size) { //return start position return (int)startIdx; } - -int getFDXBBits(uint64_t national_code, uint16_t country_code, uint8_t is_animal, uint8_t is_extended, uint32_t extended, uint8_t *bits) { - - // add preamble ten 0x00 and one 0x01 - memset(bits, 0x00, 10); - bits[10] = 1; - - // 128bits - // every 9th bit is 0x01, but we can just fill the rest with 0x01 and overwrite - memset(bits, 0x01, 128); - - // add preamble ten 0x00 and one 0x01 - memset(bits, 0x00, 10); - - // add reserved - num_to_bytebitsLSBF(0x00, 7, bits + 66); - num_to_bytebitsLSBF(0x00 >> 7, 7, bits + 74); - - // add animal flag - OK - bits[81] = is_animal; - - // add extended flag - OK - bits[65] = is_extended; - - // add national code 40bits - OK - num_to_bytebitsLSBF(national_code >> 0, 8, bits + 11); - num_to_bytebitsLSBF(national_code >> 8, 8, bits + 20); - num_to_bytebitsLSBF(national_code >> 16, 8, bits + 29); - num_to_bytebitsLSBF(national_code >> 24, 8, bits + 38); - num_to_bytebitsLSBF(national_code >> 32, 6, bits + 47); - - // add country code - OK - num_to_bytebitsLSBF(country_code >> 0, 2, bits + 53); - num_to_bytebitsLSBF(country_code >> 2, 8, bits + 56); - - // add crc-16 - OK - uint8_t raw[8]; - for (uint8_t i = 0; i < 8; ++i) - raw[i] = bytebits_to_byte(bits + 11 + i * 9, 8); - - init_table(CRC_11784); - uint16_t crc = crc16_fdxb(raw, 8); - num_to_bytebitsLSBF(crc >> 0, 8, bits + 83); - num_to_bytebitsLSBF(crc >> 8, 8, bits + 92); - - // extended data - OK - num_to_bytebitsLSBF(extended >> 0, 8, bits + 101); - num_to_bytebitsLSBF(extended >> 8, 8, bits + 110); - num_to_bytebitsLSBF(extended >> 16, 8, bits + 119); - - // 8 16 24 32 40 48 49 - // A8 28 0C 92 EA 6F 00 01 - // A8 28 0C 92 EA 6F 80 00 - return PM3_SUCCESS; -} - diff --git a/client/src/cmdlffdxb.h b/client/src/cmdlffdxb.h index af08ce38f..34c474a08 100644 --- a/client/src/cmdlffdxb.h +++ b/client/src/cmdlffdxb.h @@ -19,7 +19,7 @@ typedef struct { int CmdLFFdxB(const char *Cmd); int detectFDXB(uint8_t *dest, size_t *size); int demodFDXB(bool verbose); -int getFDXBBits(uint64_t national_code, uint16_t country_code, uint8_t is_animal, uint8_t is_extended, uint32_t extended, uint8_t *bits); +//int getFDXBBits(uint64_t national_code, uint16_t country_code, uint8_t is_animal, uint8_t is_extended, uint16_t extended, uint8_t *bits); #endif diff --git a/client/src/cmdlfgallagher.c b/client/src/cmdlfgallagher.c index 43db532a9..dcd15180b 100644 --- a/client/src/cmdlfgallagher.c +++ b/client/src/cmdlfgallagher.c @@ -10,36 +10,25 @@ // sample Q5 , ASK RF/32, STT, 96 bits (3blocks) ( 0x9000F006) //----------------------------------------------------------------------------- #include "cmdlfgallagher.h" - -#include //tolower +#include // memcpy +#include // tolower #include -#include "commonutil.h" // ARRAYLEN +#include "commonutil.h" // ARRAYLEN #include "common.h" -#include "cmdparser.h" // command_t +#include "cmdparser.h" // command_t #include "comms.h" #include "ui.h" #include "cmddata.h" #include "cmdlf.h" -#include "lfdemod.h" // preamble test -#include "protocols.h" // t55xx defines -#include "cmdlft55xx.h" // clone.. -#include "crc.h" // CRC8/Cardx +#include "lfdemod.h" // preamble test +#include "protocols.h" // t55xx defines +#include "cmdlft55xx.h" // clone.. +#include "crc.h" // CRC8/Cardx +#include "cmdlfem4x05.h" // +#include "cliparser.h" static int CmdHelp(const char *Cmd); -static int usage_lf_gallagher_clone(void) { - PrintAndLogEx(NORMAL, "clone a GALLAGHER tag to a T55x7 tag."); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf gallagher clone [h] [b ]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, " b : raw hex data. 12 bytes max"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf gallagher clone b 0FFD5461A9DA1346B2D1AC32")); - return PM3_SUCCESS; -} - static void descramble(uint8_t *arr, uint8_t len) { uint8_t lut[] = { @@ -134,73 +123,165 @@ int demodGallagher(bool verbose) { } static int CmdGallagherDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gallagher demod", + "Try to find GALLAGHER preamble, if found decode / descramble data", + "lf gallagher demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodGallagher(true); } -static int CmdGallagherRead(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - lf_read(false, 4096 * 2 + 20); - return demodGallagher(true); +static int CmdGallagherReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gallagher reader", + "read a GALLAGHER tag", + "lf gallagher reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 4096 * 2 + 20); + demodGallagher(!cm); + } while (cm && !kbd_enter_pressed()); + return PM3_SUCCESS; } static int CmdGallagherClone(const char *Cmd) { - uint32_t blocks[4]; - bool errors = false; - uint8_t cmdp = 0; - int datalen = 0; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gallagher clone", + "clone a GALLAGHER tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", + "lf gallagher clone --raw 0FFD5461A9DA1346B2D1AC32\n" + "lf gallagher clone --q5 --raw 0FFD5461A9DA1346B2D1AC32 -> encode for Q5/T5555 tag\n" + "lf gallagher clone --em --raw 0FFD5461A9DA1346B2D1AC32 -> encode for EM4305/4469" + ); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lf_gallagher_clone(); - case 'b': { - // skip first block, 3*4 = 12 bytes left - uint8_t rawhex[12] = {0}; - int res = param_gethex_to_eol(Cmd, cmdp + 1, rawhex, sizeof(rawhex), &datalen); - if (res != 0) - errors = true; + void *argtable[] = { + arg_param_begin, + arg_str1("r", "raw", "", "raw hex data. 12 bytes max"), + arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), + arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); - for (uint8_t i = 1; i < ARRAYLEN(blocks); i++) { - blocks[i] = bytes_to_num(rawhex + ((i - 1) * 4), sizeof(uint32_t)); - } - cmdp += 2; - break; - } - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } + int raw_len = 0; + // skip first block, 3*4 = 12 bytes left + uint8_t raw[12] = {0}; + CLIGetHexWithReturn(ctx, 1, raw, &raw_len); + bool q5 = arg_get_lit(ctx, 2); + bool em = arg_get_lit(ctx, 3); + CLIParserFree(ctx); + + if (q5 && em) { + PrintAndLogEx(FAILED, "Can't specify both Q5 and EM4305 at the same time"); + return PM3_EINVARG; } - if (errors || cmdp == 0) return usage_lf_gallagher_clone(); + uint32_t blocks[4]; + for (uint8_t i = 1; i < ARRAYLEN(blocks); i++) { + blocks[i] = bytes_to_num(raw + ((i - 1) * 4), sizeof(uint32_t)); + } //Pac - compat mode, NRZ, data rate 40, 3 data blocks blocks[0] = T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_32 | 3 << T55x7_MAXBLOCK_SHIFT; + char cardtype[16] = {"T55x7"}; + // Q5 + if (q5) { + blocks[0] = T5555_FIXED | T5555_MODULATION_MANCHESTER | T5555_SET_BITRATE(32) | 3 << T5555_MAXBLOCK_SHIFT; + snprintf(cardtype, sizeof(cardtype), "Q5/T5555"); + } - PrintAndLogEx(INFO, "Preparing to clone Gallagher to T55x7 with raw hex"); + // EM4305 + if (em) { + blocks[0] = EM4305_GALLAGHER_CONFIG_BLOCK; + snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); + } + + PrintAndLogEx(INFO, "Preparing to clone Gallagher to " _YELLOW_("%s") " with raw hex", cardtype); print_blocks(blocks, ARRAYLEN(blocks)); - int res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + int res; + if (em) { + res = em4x05_clone_tag(blocks, ARRAYLEN(blocks), 0, false); + } else { + res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + } PrintAndLogEx(SUCCESS, "Done"); - PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf gallagher read`") " to verify"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf gallagher reader`") " to verify"); return res; } static int CmdGallagherSim(const char *Cmd) { + + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gallagher sim", + "Enables simulation of GALLAGHER card with specified card number.\n" + "Simulation runs until the button is pressed or another USB command is issued.\n", + "lf gallagher sim --raw 0FFD5461A9DA1346B2D1AC32" + ); + + void *argtable[] = { + arg_param_begin, + arg_str1("r", "raw", "", "raw hex data. 12 bytes max"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + int raw_len = 0; + // skip first block, 3*4 = 12 bytes left + uint8_t raw[12] = {0}; + CLIGetHexWithReturn(ctx, 1, raw, &raw_len); + CLIParserFree(ctx); + // ASK/MAN sim. - PrintAndLogEx(INFO, " To be implemented, feel free to contribute!"); + PrintAndLogEx(SUCCESS, "Simulating Gallagher - raw " _YELLOW_("%s"), sprint_hex_inrow(raw, sizeof(raw))); + + uint8_t bs[sizeof(raw) * 8]; + bytes_to_bytebits(raw, sizeof(raw), bs); + + lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); + payload->encoding = 1; + payload->invert = 0; + payload->separator = 0; + payload->clock = 32; + memcpy(payload->data, bs, sizeof(bs)); + + clearCommandBuffer(); + SendCommandNG(CMD_LF_ASK_SIMULATE, (uint8_t *)payload, sizeof(lf_asksim_t) + sizeof(bs)); + free(payload); + + PacketResponseNG resp; + WaitForResponse(CMD_LF_ASK_SIMULATE, &resp); + + PrintAndLogEx(INFO, "Done"); + if (resp.status != PM3_EOPABORTED) + return resp.status; + + return PM3_SUCCESS; return PM3_SUCCESS; } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"demod", CmdGallagherDemod, AlwaysAvailable, "Demodulate an GALLAGHER tag from the GraphBuffer"}, - {"read", CmdGallagherRead, IfPm3Lf, "Attempt to read and extract tag data from the antenna"}, - {"clone", CmdGallagherClone, IfPm3Lf, "clone GALLAGHER tag to T55x7"}, - {"sim", CmdGallagherSim, IfPm3Lf, "simulate GALLAGHER tag"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"demod", CmdGallagherDemod, AlwaysAvailable, "Demodulate an GALLAGHER tag from the GraphBuffer"}, + {"reader", CmdGallagherReader, IfPm3Lf, "Attempt to read and extract tag data from the antenna"}, + {"clone", CmdGallagherClone, IfPm3Lf, "clone GALLAGHER tag to T55x7"}, + {"sim", CmdGallagherSim, IfPm3Lf, "simulate GALLAGHER tag"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdlfguard.c b/client/src/cmdlfguard.c index 75ecb55bb..051437242 100644 --- a/client/src/cmdlfguard.c +++ b/client/src/cmdlfguard.c @@ -1,4 +1,5 @@ //----------------------------------------------------------------------------- +// Marshmellow // // This code is licensed to you under the terms of the GNU GPL, version 2 or, // at your option, any later version. See the LICENSE.txt file for the text of @@ -8,63 +9,28 @@ // Biphase, rf/ , 96 bits (unknown key calc + some bits) //----------------------------------------------------------------------------- #include "cmdlfguard.h" - #include #include #include #include - -#include "commonutil.h" // ARRAYLEN +#include "commonutil.h" // ARRAYLEN #include "cmdparser.h" // command_t #include "comms.h" #include "ui.h" #include "cmddata.h" #include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest -#include "cmdlft55xx.h" // verifywrite +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest +#include "cmdlft55xx.h" // verifywrite +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines static int CmdHelp(const char *Cmd); -static int usage_lf_guard_clone(void) { - PrintAndLogEx(NORMAL, "clone a Guardall tag to a T55x7 or Q5/T5555 tag."); - PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated. "); - PrintAndLogEx(NORMAL, "Currently work only on 26bit"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf gprox clone [h] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " : format length 26|32|36|40"); - PrintAndLogEx(NORMAL, " : 8-bit value facility code"); - PrintAndLogEx(NORMAL, " : 16-bit value card number"); - PrintAndLogEx(NORMAL, " : Specify writing to Q5/T5555 tag"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf gprox clone 26 123 11223")); - return PM3_SUCCESS; -} - -static int usage_lf_guard_sim(void) { - PrintAndLogEx(NORMAL, "Enables simulation of Guardall card with specified card number."); - PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued."); - PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated."); - PrintAndLogEx(NORMAL, "Currently work only on 26bit"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: lf gprox sim [h] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " : format length 26|32|36|40"); - PrintAndLogEx(NORMAL, " : 8-bit value facility code"); - PrintAndLogEx(NORMAL, " : 16-bit value card number"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf gprox sim 26 123 11223")); - return PM3_SUCCESS; -} - -//by marshmellow -//attempts to demodulate and identify a G_Prox_II verex/chubb card -//WARNING: if it fails during some points it will destroy the DemodBuffer data +// attempts to demodulate and identify a G_Prox_II verex/chubb card +// WARNING: if it fails during some points it will destroy the DemodBuffer data // but will leave the GraphBuffer intact. -//if successful it will push askraw data back to demod buffer ready for emulation +// if successful it will push askraw data back to demod buffer ready for emulation int demodGuard(bool verbose) { (void) verbose; // unused so far //Differential Biphase @@ -150,43 +116,104 @@ int demodGuard(bool verbose) { } static int CmdGuardDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gproxii demod", + "Try to find Guardall Prox-II preamble, if found decode / descramble data", + "lf gproxii demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodGuard(true); } -static int CmdGuardRead(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - lf_read(false, 10000); - return demodGuard(true); +static int CmdGuardReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gproxii reader", + "read a Guardall tag", + "lf gproxii reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 10000); + demodGuard(!cm); + } while (cm && !kbd_enter_pressed()); + + return PM3_SUCCESS; } static int CmdGuardClone(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gproxii clone", + "clone a Guardall tag to a T55x7, Q5/T5555 or EM4305/4469 tag.\n" + "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.\n" + "Currently work only on 26bit", + "lf gproxii clone --fmt 26 --fc 123 --cn 1337\n" + "lf gproxii clone --q5 --fmt 26 --fc 123 --cn 1337 -> encode for Q5/T5555 tag\n" + "lf gproxii clone --em --fmt 26 --fc 123 --cn 1337 -> encode for EM4305/4469" + ); - char cmdp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_guard_clone(); + void *argtable[] = { + arg_param_begin, + arg_u64_1(NULL, "fmt", "", "format length 26|32|36|40"), + arg_u64_1(NULL, "fc", "", "8-bit value facility code"), + arg_u64_1(NULL, "cn", "", "16-bit value card number"), + arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), + arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); - uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0, fmtlen = 0; + uint32_t fmtlen = arg_get_u32_def(ctx, 1, 0); + uint32_t fc = arg_get_u32_def(ctx, 2, 0); + uint32_t cn = arg_get_u32_def(ctx, 3, 0); + bool q5 = arg_get_lit(ctx, 4); + bool em = arg_get_lit(ctx, 5); + CLIParserFree(ctx); - if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn) != 3) return usage_lf_guard_clone(); + if (q5 && em) { + PrintAndLogEx(FAILED, "Can't specify both Q5 and EM4305 at the same time"); + return PM3_EINVARG; + } fmtlen &= 0x7f; - facilitycode = (fc & 0x000000FF); - cardnumber = (cn & 0x0000FFFF); + uint32_t facilitycode = (fc & 0x000000FF); + uint32_t cardnumber = (cn & 0x0000FFFF); //GuardProxII - compat mode, ASK/Biphase, data rate 64, 3 data blocks - uint32_t blocks[4] = {T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0}; uint8_t *bs = calloc(96, sizeof(uint8_t)); - if (getGuardBits(fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); free(bs); return PM3_ESOFT; } + uint32_t blocks[4] = {T55x7_MODULATION_BIPHASE | T55x7_BITRATE_RF_64 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0}; + char cardtype[16] = {"T55x7"}; // Q5 - bool q5 = tolower(param_getchar(Cmd, 3)) == 'q'; - if (q5) + if (q5) { blocks[0] = T5555_FIXED | T5555_MODULATION_BIPHASE | T5555_SET_BITRATE(64) | 3 << T5555_MAXBLOCK_SHIFT; + snprintf(cardtype, sizeof(cardtype), "Q5/T5555"); + } + + // EM4305 + if (em) { + blocks[0] = EM4305_GUARDPROXII_CONFIG_BLOCK; + snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); + } blocks[1] = bytebits_to_byte(bs, 32); blocks[2] = bytebits_to_byte(bs + 32, 32); @@ -194,37 +221,65 @@ static int CmdGuardClone(const char *Cmd) { free(bs); - PrintAndLogEx(INFO, "Preparing to clone Guardall to " _YELLOW_("%s") " with Facility Code: %u, Card Number: %u", (q5) ? "Q5/T5555" : "T55x7", facilitycode, cardnumber); + PrintAndLogEx(INFO, "Preparing to clone Guardall to " _YELLOW_("%s") " with Facility Code: " _GREEN_("%u") " Card Number: " _GREEN_("%u") + , cardtype + , facilitycode + , cardnumber + ); print_blocks(blocks, ARRAYLEN(blocks)); - int res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + int res; + if (em) { + res = em4x05_clone_tag(blocks, ARRAYLEN(blocks), 0, false); + } else { + res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + } PrintAndLogEx(SUCCESS, "Done"); - PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf gprox read`") " to verify"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf gproxii reader`") " to verify"); return res; } static int CmdGuardSim(const char *Cmd) { - uint32_t facilitycode = 0, cardnumber = 0, fc = 0, cn = 0, fmtlen = 0; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf gproxii sim", + "Enables simulation of Guardall card with specified card number.\n" + "Simulation runs until the button is pressed or another USB command is issued.\n" + "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.\n" + "Currently work only on 26bit", + "lf gproxii sim --fmt 26 --fc 123 --cn 1337\n" + ); - char cmdp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_guard_sim(); + void *argtable[] = { + arg_param_begin, + arg_u64_1(NULL, "fmt", "", "format length 26|32|36|40"), + arg_u64_1(NULL, "fc", "", "8-bit value facility code"), + arg_u64_1(NULL, "cn", "", "16-bit value card number"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); - if (sscanf(Cmd, "%u %u %u", &fmtlen, &fc, &cn) != 3) return usage_lf_guard_sim(); + uint32_t fmtlen = arg_get_u32_def(ctx, 1, 0); + uint32_t fc = arg_get_u32_def(ctx, 2, 0); + uint32_t cn = arg_get_u32_def(ctx, 3, 0); + CLIParserFree(ctx); + + fmtlen &= 0x7F; + uint32_t facilitycode = (fc & 0x000000FF); + uint32_t cardnumber = (cn & 0x0000FFFF); uint8_t bs[96]; memset(bs, 0x00, sizeof(bs)); - fmtlen &= 0x7F; - facilitycode = (fc & 0x000000FF); - cardnumber = (cn & 0x0000FFFF); - if (getGuardBits(fmtlen, facilitycode, cardnumber, bs) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error with tag bitstream generation."); return PM3_ESOFT; } - PrintAndLogEx(SUCCESS, "Simulating Guardall - Facility Code: %u, CardNumber: %u", facilitycode, cardnumber); + PrintAndLogEx(SUCCESS, "Simulating Guardall Prox - Facility Code: " _YELLOW_("%u") " CardNumber: " _YELLOW_("%u") + , facilitycode + , cardnumber + ); // Guard uses: clk: 64, invert: 0, encoding: 2 (ASK Biphase) lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + sizeof(bs)); @@ -250,7 +305,7 @@ static int CmdGuardSim(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "this help"}, {"demod", CmdGuardDemod, AlwaysAvailable, "demodulate a G Prox II tag from the GraphBuffer"}, - {"read", CmdGuardRead, IfPm3Lf, "attempt to read and extract tag data from the antenna"}, + {"reader", CmdGuardReader, IfPm3Lf, "attempt to read and extract tag data from the antenna"}, {"clone", CmdGuardClone, IfPm3Lf, "clone Guardall tag to T55x7 or Q5/T5555"}, {"sim", CmdGuardSim, IfPm3Lf, "simulate Guardall tag"}, {NULL, NULL, NULL, NULL} @@ -267,7 +322,6 @@ int CmdLFGuard(const char *Cmd) { return CmdsParse(CommandTable, Cmd); } -// by marshmellow // demod gProxIIDemod // error returns as -x // success returns start position in bitstream diff --git a/client/src/cmdlfhid.c b/client/src/cmdlfhid.c index 178a75449..9b73dda19 100644 --- a/client/src/cmdlfhid.c +++ b/client/src/cmdlfhid.c @@ -19,13 +19,10 @@ //----------------------------------------------------------------------------- #include "cmdlfhid.h" - #include #include - #include #include - #include "cmdparser.h" // command_t #include "comms.h" #include "commonutil.h" // ARRAYLEN @@ -38,6 +35,7 @@ #include "lfdemod.h" #include "wiegand_formats.h" #include "wiegand_formatutils.h" +#include "cmdlfem4x05.h" // EM defines #ifndef BITS # define BITS 96 @@ -153,15 +151,44 @@ int demodHID(bool verbose) { } static int CmdHIDDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf hid demod", + "Try to find HID Prox preamble, if found decode / descramble data", + "lf hid demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodHID(true); } // this read is the "normal" read, which download lf signal and tries to demod here. static int CmdHIDRead(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - lf_read(false, 16000); - return demodHID(true); + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf hid reader", + "read a HID Prox tag", + "lf hid reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 16000); + demodHID(!cm); + } while (cm && !kbd_enter_pressed()); + + return PM3_SUCCESS; } // this read loops on device side. @@ -212,7 +239,6 @@ static int CmdHIDSim(const char *Cmd) { arg_int0("i", NULL, "", "issue level"), arg_int0("o", "oem", "", "OEM code"), arg_strx0("r", "raw", "", "raw bytes"), -// arg_lit0("q", "Q5", "optional - specify writing to Q5/T5555 tag"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -231,8 +257,6 @@ static int CmdHIDSim(const char *Cmd) { int raw_len = 0; char raw[40] = {0}; CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)raw, sizeof(raw), &raw_len); - - //bool q5 = arg_get_lit(ctx, 7); CLIParserFree(ctx); wiegand_message_t packed; diff --git a/client/src/cmdlfidteck.c b/client/src/cmdlfidteck.c index 1499aa7c9..076f3fc8e 100644 --- a/client/src/cmdlfidteck.c +++ b/client/src/cmdlfidteck.c @@ -9,13 +9,10 @@ // PSK //----------------------------------------------------------------------------- #include "cmdlfidteck.h" - #include #include #include - #include "common.h" - #include "cmdparser.h" // command_t #include "comms.h" #include "ui.h" @@ -23,6 +20,8 @@ #include "cmdlf.h" #include "lfdemod.h" #include "commonutil.h" // num_to_bytes +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines static int CmdHelp(const char *Cmd); @@ -87,20 +86,49 @@ int demodIdteck(bool verbose) { } static int CmdIdteckDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf idteck demod", + "Try to find Idteck preamble, if found decode / descramble data", + "lf idteck demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodIdteck(true); } -static int CmdIdteckRead(const char *Cmd) { - (void)Cmd; - lf_read(false, 5000); - return demodIdteck(true); +static int CmdIdteckReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf idteck reader", + "read a Idteck tag", + "lf idteck reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 5000); + demodIdteck(!cm); + } while (cm && !kbd_enter_pressed()); + + return PM3_SUCCESS; } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"demod", CmdIdteckDemod, AlwaysAvailable, "Demodulate an Idteck tag from the GraphBuffer"}, - {"read", CmdIdteckRead, IfPm3Lf, "Attempt to read and Extract tag data from the antenna"}, + {"help", CmdHelp, AlwaysAvailable, "This help"}, + {"demod", CmdIdteckDemod, AlwaysAvailable, "Demodulate an Idteck tag from the GraphBuffer"}, + {"reader", CmdIdteckReader, IfPm3Lf, "Attempt to read and Extract tag data from the antenna"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdlfindala.c b/client/src/cmdlfindala.c index b9a811fd7..c932ca164 100644 --- a/client/src/cmdlfindala.c +++ b/client/src/cmdlfindala.c @@ -9,13 +9,10 @@ //----------------------------------------------------------------------------- #include "cmdlfindala.h" - #include #include - #include #include - #include "cmdparser.h" // command_t #include "comms.h" #include "graph.h" @@ -28,6 +25,8 @@ #include "cmdlf.h" // lf_read #include "protocols.h" // t55 defines #include "cmdlft55xx.h" // verifywrite +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines #define INDALA_ARR_LEN 64 @@ -499,16 +498,33 @@ static int CmdIndalaDemodAlt(const char *Cmd) { } // this read is the "normal" read, which download lf signal and tries to demod here. -static int CmdIndalaRead(const char *Cmd) { - char cmdp = tolower(param_getchar(Cmd, 0)); - if (cmdp == 'h') return usage_lf_indala_demod(); +static int CmdIndalaReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf indala reader", + "read a Indala Prox tag", + "lf indala reader -@ -> continuous reader mode" + ); - int clk = 32, invert = 0, maxErr = 100; - if (strlen(Cmd) > 0) { - sscanf(Cmd, "%i %i %i", &clk, &invert, &maxErr); - } - lf_read(false, 30000); - return demodIndalaEx(clk, invert, maxErr, true); + void *argtable[] = { + arg_param_begin, + arg_int0(NULL, "clock", "", "optional - set clock (as integer), if not set, autodetect."), + arg_int0(NULL, "maxerr", "", "optional - set maximum allowed errors, default = 100"), + arg_lit0("i", "invert", "optional - invert output"), + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + uint32_t clk = arg_get_u32_def(ctx, 1, 32); + uint32_t max_err = arg_get_u32_def(ctx, 2, 100); + bool invert = arg_get_lit(ctx, 3); + bool cm = arg_get_lit(ctx, 4); + CLIParserFree(ctx); + + do { + lf_read(false, 30000); + demodIndalaEx(clk, invert, max_err, !cm); + } while (cm && !kbd_enter_pressed()); + return PM3_SUCCESS; } static int CmdIndalaSim(const char *Cmd) { @@ -699,7 +715,7 @@ static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "this help"}, {"demod", CmdIndalaDemod, AlwaysAvailable, "demodulate an indala tag (PSK1) from GraphBuffer"}, {"altdemod", CmdIndalaDemodAlt, AlwaysAvailable, "alternative method to Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)"}, - {"read", CmdIndalaRead, IfPm3Lf, "read an Indala Prox tag from the antenna"}, + {"reader", CmdIndalaReader, IfPm3Lf, "read an Indala Prox tag from the antenna"}, {"clone", CmdIndalaClone, IfPm3Lf, "clone Indala tag to T55x7 or Q5/T5555"}, {"sim", CmdIndalaSim, IfPm3Lf, "simulate Indala tag"}, {NULL, NULL, NULL, NULL} diff --git a/client/src/cmdlfio.c b/client/src/cmdlfio.c index f0f76e61d..123fc56fc 100644 --- a/client/src/cmdlfio.c +++ b/client/src/cmdlfio.c @@ -9,23 +9,22 @@ //----------------------------------------------------------------------------- #include "cmdlfio.h" - -#include // sscanf +#include // sscanf #include #include - #include - -#include "commonutil.h" //ARRAYLEN +#include "commonutil.h" // ARRAYLEN #include "cmdparser.h" // command_t #include "comms.h" #include "graph.h" #include "cmdlf.h" -#include "ui.h" // PrintAndLog -#include "lfdemod.h" // parityTest, bitbytes_to_byte -#include "protocols.h" // for T55xx config register definitions +#include "ui.h" // PrintAndLog +#include "lfdemod.h" // parityTest, bitbytes_to_byte +#include "protocols.h" // for T55xx config register definitions #include "cmddata.h" -#include "cmdlft55xx.h" // verifywrite +#include "cmdlft55xx.h" // verifywrite +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines static int CmdHelp(const char *Cmd); @@ -192,14 +191,43 @@ int demodIOProx(bool verbose) { } static int CmdIOProxDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf io demod", + "Try to find IO Prox preamble, if found decode / descramble data", + "lf io demod\n" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodIOProx(true); } // this read is the "normal" read, which download lf signal and tries to demod here. -static int CmdIOProxRead(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - lf_read(false, 12000); - return demodIOProx(true); +static int CmdIOProxReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf io reader", + "read a IO Prox tag", + "lf io reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 12000); + demodIOProx(!cm); + } while (cm && !kbd_enter_pressed()); + + return PM3_SUCCESS; } static int CmdIOProxSim(const char *Cmd) { uint16_t cn = 0; @@ -297,12 +325,12 @@ static int CmdIOProxClone(const char *Cmd) { } static command_t CommandTable[] = { - {"help", CmdHelp, AlwaysAvailable, "this help"}, - {"demod", CmdIOProxDemod, AlwaysAvailable, "demodulate an IOProx tag from the GraphBuffer"}, - {"read", CmdIOProxRead, IfPm3Lf, "attempt to read and extract tag data"}, - {"clone", CmdIOProxClone, IfPm3Lf, "clone IOProx tag to T55x7 or Q5/T5555"}, - {"sim", CmdIOProxSim, IfPm3Lf, "simulate IOProx tag"}, - {"watch", CmdIOProxWatch, IfPm3Lf, "continuously watch for cards. Reader mode"}, + {"help", CmdHelp, AlwaysAvailable, "this help"}, + {"demod", CmdIOProxDemod, AlwaysAvailable, "demodulate an IOProx tag from the GraphBuffer"}, + {"reader", CmdIOProxReader, IfPm3Lf, "attempt to read and extract tag data"}, + {"clone", CmdIOProxClone, IfPm3Lf, "clone IOProx tag to T55x7 or Q5/T5555"}, + {"sim", CmdIOProxSim, IfPm3Lf, "simulate IOProx tag"}, + {"watch", CmdIOProxWatch, IfPm3Lf, "continuously watch for cards. Reader mode"}, {NULL, NULL, NULL, NULL} }; diff --git a/client/src/cmdlfjablotron.c b/client/src/cmdlfjablotron.c index 9005743bf..25f6f3afd 100644 --- a/client/src/cmdlfjablotron.c +++ b/client/src/cmdlfjablotron.c @@ -9,40 +9,26 @@ //----------------------------------------------------------------------------- #include "cmdlfjablotron.h" - #include #include #include #include - #include "cmdparser.h" // command_t #include "comms.h" -#include "commonutil.h" // ARRAYLEN +#include "commonutil.h" // ARRAYLEN #include "ui.h" #include "cmddata.h" #include "cmdlf.h" -#include "protocols.h" // for T55xx config register definitions -#include "lfdemod.h" // parityTest -#include "cmdlft55xx.h" // verifywrite +#include "protocols.h" // for T55xx config register definitions +#include "lfdemod.h" // parityTest +#include "cmdlft55xx.h" // verifywrite +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines #define JABLOTRON_ARR_LEN 64 static int CmdHelp(const char *Cmd); -static int usage_lf_jablotron_clone(void) { - PrintAndLogEx(NORMAL, "clone a Jablotron tag to a T55x7 or Q5/T5555 tag."); - PrintAndLogEx(NORMAL, "Usage: lf jablotron clone [h] "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : jablotron card ID"); - PrintAndLogEx(NORMAL, " : specify writing to Q5/T5555 tag"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" lf jablotron clone 112233")); - PrintAndLogEx(NORMAL, ""); - return PM3_SUCCESS; -} - static int usage_lf_jablotron_sim(void) { PrintAndLogEx(NORMAL, "Enables simulation of jablotron card with specified card number."); PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued."); @@ -134,30 +120,93 @@ int demodJablotron(bool verbose) { //see ASKDemod for what args are accepted static int CmdJablotronDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf jablotron demod", + "Try to find Jablotron preamble, if found decode / descramble data", + "lf jablotron demod\n" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodJablotron(true); } -static int CmdJablotronRead(const char *Cmd) { - (void)Cmd; // Cmd is not used so far - lf_read(false, 16000); - return demodJablotron(true); +static int CmdJablotronReader(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf jablotron reader", + "read a jablotron tag", + "lf jablotron reader -@ -> continuous reader mode" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("@", NULL, "optional - continuous reader mode"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + bool cm = arg_get_lit(ctx, 1); + CLIParserFree(ctx); + + do { + lf_read(false, 16000); + demodJablotron(!cm); + } while (cm && !kbd_enter_pressed()); + + return PM3_SUCCESS; } static int CmdJablotronClone(const char *Cmd) { - uint64_t fullcode = 0; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf jablotron clone", + "clone a Jablotron tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", + "lf jablotron clone --cn 01b669\n" + "lf jablotron clone --q5 --cn 01b669 -> encode for Q5/T5555 tag\n" + "lf jablotron clone --em --cn 01b669 -> encode for EM4305/4469" + ); + + void *argtable[] = { + arg_param_begin, + arg_str1(NULL, "cn", "", "Jablotron card ID - 5 bytes max"), + arg_lit0(NULL, "q5", "optional - specify writing to Q5/T5555 tag"), + arg_lit0(NULL, "em", "optional - specify writing to EM4305/4469 tag"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int raw_len = 0; + uint8_t raw[5] = {0}; + CLIGetHexWithReturn(ctx, 1, raw, &raw_len); + + bool q5 = arg_get_lit(ctx, 2); + bool em = arg_get_lit(ctx, 3); + CLIParserFree(ctx); + + if (q5 && em) { + PrintAndLogEx(FAILED, "Can't specify both Q5 and EM4305 at the same time"); + return PM3_EINVARG; + } + uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2 << T55x7_MAXBLOCK_SHIFT, 0, 0}; - - char cmdp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_jablotron_clone(); - - fullcode = param_get64ex(Cmd, 0, 0, 16); - - //Q5 - bool q5 = tolower(param_getchar(Cmd, 1)) == 'q'; - if (q5) + char cardtype[16] = {"T55x7"}; + // Q5 + if (q5) { blocks[0] = T5555_FIXED | T5555_MODULATION_BIPHASE | T5555_INVERT_OUTPUT | T5555_SET_BITRATE(64) | 2 << T5555_MAXBLOCK_SHIFT; + snprintf(cardtype, sizeof(cardtype), "Q5/T5555"); + } + + // EM4305 + if (em) { + blocks[0] = EM4305_JABLOTRON_CONFIG_BLOCK; + snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); + } + + + uint64_t fullcode = bytes_to_num(raw, raw_len); // clearing the topbit needed for the preambl detection. if ((fullcode & 0x7FFFFFFFFF) != fullcode) { @@ -181,10 +230,20 @@ static int CmdJablotronClone(const char *Cmd) { free(bits); - PrintAndLogEx(INFO, "Preparing to clone Jablotron to " _YELLOW_("%s") " with FullCode: %"PRIx64, (q5) ? "Q5/T5555" : "T55x7", fullcode); - print_blocks(blocks, ARRAYLEN(blocks)); + uint64_t id = getJablontronCardId(fullcode); - return clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + PrintAndLogEx(INFO, "Preparing to clone Jablotron to " _YELLOW_("%s") " with FullCode: " _GREEN_("%"PRIx64)" id: " _GREEN_("%"PRIx64), cardtype, fullcode, id); + print_blocks(blocks, ARRAYLEN(blocks)); + + int res; + if (em) { + res = em4x05_clone_tag(blocks, ARRAYLEN(blocks), 0, false); + } else { + res = clone_t55xx_tag(blocks, ARRAYLEN(blocks)); + } + PrintAndLogEx(SUCCESS, "Done"); + PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf jablotron reader`") " to verify"); + return res; } static int CmdJablotronSim(const char *Cmd) { @@ -201,7 +260,7 @@ static int CmdJablotronSim(const char *Cmd) { PrintAndLogEx(INFO, "Card Number Truncated to 39bits: %"PRIx64, fullcode); } - PrintAndLogEx(SUCCESS, "Simulating Jablotron - FullCode: %"PRIx64, fullcode); + PrintAndLogEx(SUCCESS, "Simulating Jablotron - FullCode: " _YELLOW_("%"PRIx64), fullcode); uint8_t *bs = calloc(JABLOTRON_ARR_LEN, sizeof(uint8_t)); if (bs == NULL) { @@ -236,7 +295,7 @@ static int CmdJablotronSim(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, {"demod", CmdJablotronDemod, AlwaysAvailable, "Demodulate an Jablotron tag from the GraphBuffer"}, - {"read", CmdJablotronRead, IfPm3Lf, "Attempt to read and extract tag data from the antenna"}, + {"reader", CmdJablotronReader, IfPm3Lf, "Attempt to read and extract tag data from the antenna"}, {"clone", CmdJablotronClone, IfPm3Lf, "clone jablotron tag to T55x7 or Q5/T5555"}, {"sim", CmdJablotronSim, IfPm3Lf, "simulate jablotron tag"}, {NULL, NULL, NULL, NULL} diff --git a/client/src/cmdlfkeri.c b/client/src/cmdlfkeri.c index 93e8a2521..dfd0153fd 100644 --- a/client/src/cmdlfkeri.c +++ b/client/src/cmdlfkeri.c @@ -175,7 +175,18 @@ int demodKeri(bool verbose) { } static int CmdKeriDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf keri demod", + "Try to find KERI preamble, if found decode / descramble data", + "lf keri demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodKeri(true); } diff --git a/client/src/cmdlfmotorola.c b/client/src/cmdlfmotorola.c index 9f700c043..cf3f79137 100644 --- a/client/src/cmdlfmotorola.c +++ b/client/src/cmdlfmotorola.c @@ -116,9 +116,19 @@ int demodMotorola(bool verbose) { return PM3_SUCCESS; } -//see PSKDemod for what args are accepted static int CmdMotorolaDemod(const char *Cmd) { - (void)Cmd; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf motorola demod", + "Try to find Motorola preamble, if found decode / descramble data", + "lf motorola demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodMotorola(true); } @@ -218,9 +228,9 @@ static int CmdMotorolaClone(const char *Cmd) { // config for Motorola 64 format (RF/32;PSK1 with RF/2; Maxblock=2) PrintAndLogEx(INFO, "Preparing to clone Motorola 64bit to " _YELLOW_("%s") " with raw " _GREEN_("%s") - , cardtype - , sprint_hex_inrow(raw, sizeof(raw)) - ); + , cardtype + , sprint_hex_inrow(raw, sizeof(raw)) + ); print_blocks(blocks, ARRAYLEN(blocks)); int res; @@ -235,7 +245,20 @@ static int CmdMotorolaClone(const char *Cmd) { } static int CmdMotorolaSim(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf motorola sim", + "Enables simulation of Motorola card with specified card number.\n" + "Simulation runs until the button is pressed or another USB command is issued.", + "lf motorola sim" + ); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); + // PSK sim. PrintAndLogEx(INFO, " PSK1 at 66 kHz... Interesting."); PrintAndLogEx(INFO, " To be implemented, feel free to contribute!"); diff --git a/client/src/cmdlfnedap.c b/client/src/cmdlfnedap.c index 06daf357e..1ee2923c1 100644 --- a/client/src/cmdlfnedap.c +++ b/client/src/cmdlfnedap.c @@ -11,10 +11,8 @@ #define _GNU_SOURCE #include - #include #include - #include "cmdparser.h" // command_t #include "comms.h" #include "crc16.h" @@ -24,6 +22,8 @@ #include "cmdlf.h" #include "lfdemod.h" #include "protocols.h" +#include "cliparser.h" +#include "cmdlfem4x05.h" // EM defines #define FIXED_71 0x71 #define FIXED_40 0x40 @@ -262,7 +262,18 @@ int demodNedap(bool verbose) { } static int CmdLFNedapDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf nedap demod", + "Try to find Nedap preamble, if found decode / descramble data", + "lf nedap demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodNedap(true); } /* Index map E E diff --git a/client/src/cmdlfnexwatch.c b/client/src/cmdlfnexwatch.c index 3224e94a7..ea69535f3 100644 --- a/client/src/cmdlfnexwatch.c +++ b/client/src/cmdlfnexwatch.c @@ -217,14 +217,25 @@ int demodNexWatch(bool verbose) { } static int CmdNexWatchDemod(const char *Cmd) { - (void)Cmd; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf nexwatch demod", + "Try to find Nexwatch preamble, if found decode / descramble data", + "lf nexwatch demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodNexWatch(true); } static int CmdNexWatchReader(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "lf nexwatch reader", - "read a nexwatch tag", + "read a Nexwatch tag", "lf nexwatch reader -@ -> continuous reader mode" ); @@ -385,7 +396,7 @@ static int CmdNexWatchSim(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, false); - int raw_len = 0; + int raw_len = 0; // skip first block, 3*4 = 12 bytes left uint8_t raw[12] = {0x56, 0}; CLIGetHexWithReturn(ctx, 1, raw, &raw_len); @@ -438,7 +449,7 @@ static int CmdNexWatchSim(const char *Cmd) { uint8_t bs[96]; memset(bs, 0, sizeof(bs)); - // hex to bits. (3 * 32 == 96) + // hex to bits. (3 * 32 == 96) for (size_t i = 0; i < 3; i++) { uint32_t tmp = bytes_to_num(raw + (i * sizeof(uint32_t)), sizeof(uint32_t)); num_to_bytebits(tmp, sizeof(uint32_t) * 8, bs + (i * sizeof(uint32_t) * 8)); diff --git a/client/src/cmdlfnoralsy.c b/client/src/cmdlfnoralsy.c index a49093ec8..73a027c33 100644 --- a/client/src/cmdlfnoralsy.c +++ b/client/src/cmdlfnoralsy.c @@ -103,14 +103,25 @@ int demodNoralsy(bool verbose) { } static int CmdNoralsyDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf noralsy demod", + "Try to find Noralsy preamble, if found decode / descramble data", + "lf noralsy demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodNoralsy(true); } static int CmdNoralsyReader(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "lf noralsy reader", - "read a noralsy tag", + "read a Noralsy tag", "lf noralsy reader -@ -> continuous reader mode" ); @@ -133,7 +144,7 @@ static int CmdNoralsyReader(const char *Cmd) { static int CmdNoralsyClone(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "lf noralsy clone", - "clone a noralsy tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", + "clone a Noralsy tag to a T55x7, Q5/T5555 or EM4305/4469 tag.", "lf noralsy clone --cn 112233\n" "lf noralsy clone --cn 112233 --q5 -> encode for Q5/T5555 tag\n" "lf noralsy clone --cn 112233 --em -> encode for EM4305/4469" diff --git a/client/src/cmdlfpac.c b/client/src/cmdlfpac.c index fbc642850..99495641f 100644 --- a/client/src/cmdlfpac.c +++ b/client/src/cmdlfpac.c @@ -69,7 +69,7 @@ static int pac_buf_to_cardid(uint8_t *src, const size_t src_size, uint8_t *dst, // convert a 16 byte array of raw demod data (FF204990XX...) to 8 bytes of PAC_8byte ID // performs no parity or checksum validation -static void pac_raw_to_cardid(const uint8_t* src, uint8_t *dst) { +static void pac_raw_to_cardid(const uint8_t *src, uint8_t *dst) { for (int i = 4; i < 12; i++) { uint8_t shift = 7 - (i + 3) % 4 * 2; size_t index = i + (i - 1) / 4; @@ -157,15 +157,26 @@ int demodPac(bool verbose) { } static int CmdPacDemod(const char *Cmd) { - (void)Cmd; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf pac demod", + "Try to find PAC/Stanley preamble, if found decode / descramble data", + "lf pac demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodPac(true); } static int CmdPacReader(const char *Cmd) { - + CLIParserContext *ctx; CLIParserInit(&ctx, "lf pac reader", - "read a pac tag", + "read a PAC/Stanley tag", "lf pac reader -@ -> continuous reader mode" ); @@ -208,7 +219,7 @@ static int CmdPacClone(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, false); uint8_t cnstr[9]; - int cnlen = 9; + int cnlen = 9; memset(cnstr, 0x00, sizeof(cnstr)); CLIGetStrWithReturn(ctx, 1, cnstr, &cnlen); @@ -236,7 +247,7 @@ static int CmdPacClone(const char *Cmd) { } if (cnlen == 8 || cnlen == 9) { - pac_cardid_to_raw((char*)cnstr, raw); + pac_cardid_to_raw((char *)cnstr, raw); } else { pac_raw_to_cardid(raw, cnstr); } @@ -262,10 +273,10 @@ static int CmdPacClone(const char *Cmd) { } PrintAndLogEx(INFO, "Preparing to clone PAC/Stanley tag to " _YELLOW_("%s") " with ID " _GREEN_("%s") " raw " _GREEN_("%s") - , cardtype - , cnstr - , sprint_hex_inrow(raw, sizeof(raw)) - ); + , cardtype + , cnstr + , sprint_hex_inrow(raw, sizeof(raw)) + ); print_blocks(blocks, ARRAYLEN(blocks)); @@ -300,7 +311,7 @@ static int CmdPacSim(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, false); uint8_t cnstr[10]; - int cnlen = 9; + int cnlen = 9; memset(cnstr, 0x00, sizeof(cnstr)); CLIGetStrWithReturn(ctx, 1, cnstr, &cnlen); @@ -321,7 +332,7 @@ static int CmdPacSim(const char *Cmd) { } if (cnlen == 8 || cnlen == 9) { - pac_cardid_to_raw((char*)cnstr, raw); + pac_cardid_to_raw((char *)cnstr, raw); } else { pac_raw_to_cardid(raw, cnstr); } @@ -333,9 +344,9 @@ static int CmdPacSim(const char *Cmd) { } PrintAndLogEx(SUCCESS, "Simulating PAC/Stanley - ID " _YELLOW_("%s")" raw " _YELLOW_("%s") - , cnstr - , sprint_hex_inrow(raw, sizeof(raw)) - ); + , cnstr + , sprint_hex_inrow(raw, sizeof(raw)) + ); // NRZ sim. lf_nrzsim_t *payload = calloc(1, sizeof(lf_nrzsim_t) + sizeof(bs)); diff --git a/client/src/cmdlfparadox.c b/client/src/cmdlfparadox.c index 08b67de1c..f740721e9 100644 --- a/client/src/cmdlfparadox.c +++ b/client/src/cmdlfparadox.c @@ -170,7 +170,18 @@ int demodParadox(bool verbose) { } static int CmdParadoxDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf paradox demod", + "Try to find Paradox preamble, if found decode / descramble data", + "lf paradox demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodParadox(true); } @@ -240,7 +251,7 @@ static int CmdParadoxClone(const char *Cmd) { for (uint8_t i = 1; i < ARRAYLEN(blocks); i++) { blocks[i] = bytes_to_num(raw + ((i - 1) * 4), sizeof(uint32_t)); } - + // Paradox - FSK2a, data rate 50, 3 data blocks blocks[0] = T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3 << T55x7_MAXBLOCK_SHIFT; char cardtype[16] = {"T55x7"}; @@ -255,7 +266,7 @@ static int CmdParadoxClone(const char *Cmd) { blocks[0] = EM4305_PARADOX_CONFIG_BLOCK; snprintf(cardtype, sizeof(cardtype), "EM4305/4469"); } - + PrintAndLogEx(INFO, "Preparing to clone Paradox to " _YELLOW_("%s") " with raw hex", cardtype); print_blocks(blocks, ARRAYLEN(blocks)); @@ -323,7 +334,8 @@ static int CmdParadoxSim(const char *Cmd) { if (resp.status != PM3_EOPABORTED) return resp.status; - return PM3_SUCCESS;} + return PM3_SUCCESS; +} /* if (sscanf(Cmd, "%u %u", &fc, &cn) != 2) return usage_lf_paradox_sim(); diff --git a/client/src/cmdlfpresco.c b/client/src/cmdlfpresco.c index 3857cdd83..d629e1224 100644 --- a/client/src/cmdlfpresco.c +++ b/client/src/cmdlfpresco.c @@ -40,7 +40,7 @@ static int detectPresco(uint8_t *dest, size_t *size) { // convert base 12 ID to sitecode & usercode & 8 bit other unknown code static int getWiegandFromPrintedPresco(void *arr, uint32_t *fullcode) { - char *s = (char*)arr; + char *s = (char *)arr; uint8_t val = 0; for (int i = 0; i < strlen(s); ++i) { // Get value from number string. @@ -103,16 +103,27 @@ int demodPresco(bool verbose) { uint32_t sitecode = (fullcode >> 24) & 0x000000FF; PrintAndLogEx(SUCCESS, "Presco Site code: " _GREEN_("%u") " User code: " _GREEN_("%u") " Full code: " _GREEN_("%08X") " Raw: " _YELLOW_("%08X%08X%08X%08X") - , sitecode - , usercode - , fullcode - , raw1, raw2, raw3, raw4 - ); + , sitecode + , usercode + , fullcode + , raw1, raw2, raw3, raw4 + ); return PM3_SUCCESS; } static int CmdPrescoDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf presco demod", + "Try to find presco preamble, if found decode / descramble data", + "lf presco demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodPresco(true); } @@ -120,8 +131,8 @@ static int CmdPrescoDemod(const char *Cmd) { static int CmdPrescoReader(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "lf presco reader", - "read a presco tag", - "lf presco reader -@ -> continuous reader mode" + "read a presco tag", + "lf presco reader -@ -> continuous reader mode" ); void *argtable[] = { @@ -162,11 +173,11 @@ static int CmdPrescoClone(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, false); int hex_len = 0; - uint8_t hex[4] = {0,0,0,0}; + uint8_t hex[4] = {0, 0, 0, 0}; CLIGetHexWithReturn(ctx, 1, hex, &hex_len); uint8_t idstr[11]; - int slen = 9; + int slen = 9; memset(idstr, 0x00, sizeof(idstr)); CLIGetStrWithReturn(ctx, 2, idstr, &slen); @@ -227,11 +238,11 @@ static int CmdPrescoClone(const char *Cmd) { blocks[4] = fullcode; PrintAndLogEx(INFO, "Preparing to clone Presco to " _GREEN_("%s") " with Site code: " _GREEN_("%u") " User code: " _GREEN_("%u") " Full code: " _GREEN_("%08x") - , cardtype - , sitecode - , usercode - , fullcode - ); + , cardtype + , sitecode + , usercode + , fullcode + ); print_blocks(blocks, ARRAYLEN(blocks)); int res; @@ -265,11 +276,11 @@ static int CmdPrescoSim(const char *Cmd) { CLIExecWithReturn(ctx, Cmd, argtable, false); int hex_len = 0; - uint8_t hex[4] = {0,0,0,0}; + uint8_t hex[4] = {0, 0, 0, 0}; CLIGetHexWithReturn(ctx, 1, hex, &hex_len); uint8_t idstr[11]; - int slen = 9; + int slen = 9; memset(idstr, 0x00, sizeof(idstr)); CLIGetStrWithReturn(ctx, 2, idstr, &slen); CLIParserFree(ctx); @@ -300,10 +311,10 @@ static int CmdPrescoSim(const char *Cmd) { } PrintAndLogEx(SUCCESS, "Simulating Presco - Site Code: " _GREEN_("%u") " User Code: " _GREEN_("%u") " Full Code: " _GREEN_("%08X") - , sitecode - , usercode - , fullcode) - ; + , sitecode + , usercode + , fullcode) + ; uint8_t bs[128]; getPrescoBits(fullcode, bs); diff --git a/client/src/cmdlfpyramid.c b/client/src/cmdlfpyramid.c index 452f3f61e..b21c5c974 100644 --- a/client/src/cmdlfpyramid.c +++ b/client/src/cmdlfpyramid.c @@ -178,7 +178,18 @@ int demodPyramid(bool verbose) { } static int CmdPyramidDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf pyramid demod", + "Try to find Farpoint/Pyramid preamble, if found decode / descramble data", + "lf pyramid demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodPyramid(true); } diff --git a/client/src/cmdlfsecurakey.c b/client/src/cmdlfsecurakey.c index 04bdb3445..4c3fa6ba3 100644 --- a/client/src/cmdlfsecurakey.c +++ b/client/src/cmdlfsecurakey.c @@ -8,18 +8,18 @@ // ASK/Manchester, RF/40, 96 bits long (unknown cs) //----------------------------------------------------------------------------- #include "cmdlfsecurakey.h" -#include // memcpy -#include // tolower -#include "commonutil.h" // ARRAYLEN -#include "cmdparser.h" // command_t +#include // memcpy +#include // tolower +#include "commonutil.h" // ARRAYLEN +#include "cmdparser.h" // command_t #include "comms.h" #include "ui.h" #include "cmddata.h" #include "cmdlf.h" -#include "lfdemod.h" // preamble test -#include "parity.h" // for wiegand parity test -#include "protocols.h" // t55xx defines -#include "cmdlft55xx.h" // clone.. +#include "lfdemod.h" // preamble test +#include "parity.h" // for wiegand parity test +#include "protocols.h" // t55xx defines +#include "cmdlft55xx.h" // clone.. #include "cliparser.h" #include "cmdlfem4x05.h" // EM defines @@ -114,7 +114,18 @@ int demodSecurakey(bool verbose) { } static int CmdSecurakeyDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf securakey demod", + "Try to find Securakey preamble, if found decode / descramble data", + "lf securakey demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodSecurakey(true); } @@ -240,7 +251,7 @@ static int CmdSecurakeySim(const char *Cmd) { return PM3_EINVARG; } - PrintAndLogEx(SUCCESS, "Simulating SecuraKey - raw " _YELLOW_("%s"), sprint_hex_inrow(raw, sizeof(raw))); + PrintAndLogEx(SUCCESS, "Simulating SecuraKey - raw " _YELLOW_("%s"), sprint_hex_inrow(raw, sizeof(raw))); uint8_t bs[sizeof(raw) * 8]; bytes_to_bytebits(raw, sizeof(raw), bs); diff --git a/client/src/cmdlfti.c b/client/src/cmdlfti.c index e2d7716d2..f6e8b3027 100644 --- a/client/src/cmdlfti.c +++ b/client/src/cmdlfti.c @@ -272,7 +272,18 @@ out: } static int CmdTIDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf ti demod", + "Try to find TI preamble, if found decode / descramble data", + "lf ti demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodTI(true); } @@ -303,19 +314,43 @@ static int CmdTIReader(const char *Cmd) { // write new data to a r/w TI tag static int CmdTIWrite(const char *Cmd) { - int res = 0; - uint64_t arg0, arg1, arg2; - res = sscanf(Cmd, "%012" SCNx64 " %012" SCNx64 " %012" SCNx64 "", &arg0, &arg1, &arg2); - if (res == 2) - arg2 = 0; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf ti write", + "write to a r/w TI tag.", + "lf ti write --raw 1122334455667788\n" + "lf ti write --raw 1122334455667788 --crc 1122\n" + ); + + void *argtable[] = { + arg_param_begin, + arg_str1("r", "raw", "", "raw hex data. 8 bytes max"), + arg_str0(NULL, "crc", "", "optional - crc"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int raw_len = 0; + uint8_t raw[8] = {0}; + CLIGetHexWithReturn(ctx, 1, raw, &raw_len); + + int crc_len = 0; + uint8_t crc[2] = {0}; + CLIGetHexWithReturn(ctx, 2, crc, &crc_len); + CLIParserFree(ctx); + + struct { + uint32_t high; + uint32_t low; + uint16_t crc; + } PACKED payload; + + payload.high = bytes_to_num(raw, 4); + payload.low = bytes_to_num(raw + 4, 4); + payload.crc = bytes_to_num(crc, crc_len); - if (res < 2) { - PrintAndLogEx(WARNING, "Please specify the data as two hex strings, optionally the CRC as a third"); - return PM3_EINVARG; - } clearCommandBuffer(); - SendCommandMIX(CMD_LF_TI_WRITE, arg0, arg1, arg2, NULL, 0); + SendCommandNG(CMD_LF_TI_WRITE, (uint8_t*)&payload, sizeof(payload)); PrintAndLogEx(SUCCESS, "Done"); PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`lf ti reader`") " to verify"); return PM3_SUCCESS; @@ -323,7 +358,7 @@ static int CmdTIWrite(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"demod", CmdTIDemod, AlwaysAvailable, "Demodulate raw bits for TI-type LF tag from the GraphBuffer"}, + {"demod", CmdTIDemod, AlwaysAvailable, "Demodulate raw bits for TI LF tag from the GraphBuffer"}, {"reader", CmdTIReader, IfPm3Lf, "Read and decode a TI 134 kHz tag"}, {"write", CmdTIWrite, IfPm3Lf, "Write new data to a r/w TI 134 kHz tag"}, {NULL, NULL, NULL, NULL} diff --git a/client/src/cmdlfviking.c b/client/src/cmdlfviking.c index 0da4bcbd5..0727a7f96 100644 --- a/client/src/cmdlfviking.c +++ b/client/src/cmdlfviking.c @@ -54,7 +54,18 @@ int demodViking(bool verbose) { } static int CmdVikingDemod(const char *Cmd) { - (void)Cmd; + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf viking demod", + "Try to find Viking AM preamble, if found decode / descramble data", + "lf viking demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodViking(true); } diff --git a/client/src/cmdlfvisa2000.c b/client/src/cmdlfvisa2000.c index 2e57202c2..582b29686 100644 --- a/client/src/cmdlfvisa2000.c +++ b/client/src/cmdlfvisa2000.c @@ -133,7 +133,18 @@ int demodVisa2k(bool verbose) { } static int CmdVisa2kDemod(const char *Cmd) { - (void)Cmd; // Cmd is not used so far + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf visa2000 demod", + "Try to find visa2000 preamble, if found decode / descramble data", + "lf visa2000 demod" + ); + + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); return demodVisa2k(true); } diff --git a/client/src/cmdscript.c b/client/src/cmdscript.c index b66516296..4f3aad7d9 100644 --- a/client/src/cmdscript.c +++ b/client/src/cmdscript.c @@ -32,12 +32,12 @@ #include "fileutils.h" #ifdef HAVE_LUA_SWIG -extern int luaopen_pm3(lua_State* L); +extern int luaopen_pm3(lua_State *L); #endif #ifdef HAVE_PYTHON #ifdef HAVE_PYTHON_SWIG -extern PyObject* PyInit__pm3(void); +extern PyObject *PyInit__pm3(void); #endif // HAVE_PYTHON_SWIG // Partly ripped from PyRun_SimpleFileExFlags diff --git a/client/src/loclass/elite_crack.c b/client/src/loclass/elite_crack.c index 250fdc2ad..2d1650d0d 100644 --- a/client/src/loclass/elite_crack.c +++ b/client/src/loclass/elite_crack.c @@ -232,7 +232,7 @@ void hash2(uint8_t *key64, uint8_t *outp_keytable) { if (g_debugMode > 0) { PrintAndLogEx(DEBUG, "High security custom key (Kcus):"); - PrintAndLogEx(DEBUG, "z0 %s", sprint_hex(z[0],8)); + PrintAndLogEx(DEBUG, "z0 %s", sprint_hex(z[0], 8)); } uint8_t y[8][8] = {{0}, {0}}; @@ -308,7 +308,7 @@ typedef struct { static size_t loclass_tc = 1; static int loclass_found = 0; -static void* bf_thread(void* thread_arg) { +static void *bf_thread(void *thread_arg) { loclass_thread_arg_t *targ = (loclass_thread_arg_t *)thread_arg; const uint32_t endmask = targ->endmask; @@ -332,7 +332,7 @@ static void* bf_thread(void* thread_arg) { int found; while (!(brute & endmask)) { - found = __atomic_load_n (&loclass_found, __ATOMIC_SEQ_CST); + found = __atomic_load_n(&loclass_found, __ATOMIC_SEQ_CST); if (found != 0xFF) return NULL; @@ -370,13 +370,13 @@ static void* bf_thread(void* thread_arg) { // success if (memcmp(calculated_MAC, mac, 4) == 0) { - loclass_thread_ret_t *r = (loclass_thread_ret_t*)malloc(sizeof(loclass_thread_ret_t)); + loclass_thread_ret_t *r = (loclass_thread_ret_t *)malloc(sizeof(loclass_thread_ret_t)); for (uint8_t i = 0 ; i < numbytes_to_recover; i++) { r->values[i] = keytable[bytes_to_recover[i]] & 0xFF; } __atomic_store_n(&loclass_found, targ->thread_idx, __ATOMIC_SEQ_CST); - pthread_exit ((void*)r); + pthread_exit((void *)r); } brute += loclass_tc; @@ -385,19 +385,19 @@ static void* bf_thread(void* thread_arg) { if (numbytes_to_recover == 3) { if ((brute > 0) && ((brute & 0xFFFF) == 0)) { - PrintAndLogEx(INPLACE, "[ %02x %02x %02x ] %8u / %u", bytes_to_recover[0], bytes_to_recover[1], bytes_to_recover[2] , brute, 0xFFFFFF); + PrintAndLogEx(INPLACE, "[ %02x %02x %02x ] %8u / %u", bytes_to_recover[0], bytes_to_recover[1], bytes_to_recover[2], brute, 0xFFFFFF); } } else if (numbytes_to_recover == 2) { if ((brute > 0) && ((brute & 0x3F) == 0)) - PrintAndLogEx(INPLACE, "[ %02x %02x ] %5u / %u" _CLR_ , bytes_to_recover[0], bytes_to_recover[1], brute, 0xFFFF); + PrintAndLogEx(INPLACE, "[ %02x %02x ] %5u / %u" _CLR_, bytes_to_recover[0], bytes_to_recover[1], brute, 0xFFFF); } else { if ((brute > 0) && ((brute & 0x1F) == 0)) PrintAndLogEx(INPLACE, "[ %02x ] %3u / %u" _CLR_, bytes_to_recover[0], brute, 0xFF); } } pthread_exit(NULL); - - void* dummyptr = NULL; + + void *dummyptr = NULL; return dummyptr; } @@ -455,9 +455,9 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) { args[i].numbytes_to_recover = numbytes_to_recover; args[i].endmask = 1 << 8 * numbytes_to_recover; - memcpy((void*)&args[i].item, (void*)&item, sizeof(loclass_dumpdata_t)); - memcpy(args[i].bytes_to_recover, bytes_to_recover, sizeof(args[i].bytes_to_recover) ); - memcpy(args[i].key_index, key_index, sizeof(args[i].key_index) ); + memcpy((void *)&args[i].item, (void *)&item, sizeof(loclass_dumpdata_t)); + memcpy(args[i].bytes_to_recover, bytes_to_recover, sizeof(args[i].bytes_to_recover)); + memcpy(args[i].key_index, key_index, sizeof(args[i].key_index)); memcpy(args[i].keytable, keytable, sizeof(args[i].keytable)); } @@ -472,7 +472,7 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) { } } // wait for threads to terminate: - void* ptrs[loclass_tc]; + void *ptrs[loclass_tc]; for (int i = 0; i < loclass_tc; i++) pthread_join(threads[i], &ptrs[i]); @@ -526,18 +526,18 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) { uint8_t key_index[8] = {0}; hash1(item.csn, key_index); */ - /* - * Determine which bytes to retrieve. A hash is typically - * 01010000454501 - * We go through that hash, and in the corresponding keytable, we put markers - * on what state that particular index is: - * - CRACKED (this has already been cracked) - * - BEING_CRACKED (this is being bruteforced now) - * - CRACK_FAILED (self-explaining...) - * - * The markers are placed in the high area of the 16 bit key-table. - * Only the lower eight bits correspond to the (hopefully cracked) key-value. - **/ +/* + * Determine which bytes to retrieve. A hash is typically + * 01010000454501 + * We go through that hash, and in the corresponding keytable, we put markers + * on what state that particular index is: + * - CRACKED (this has already been cracked) + * - BEING_CRACKED (this is being bruteforced now) + * - CRACK_FAILED (self-explaining...) + * + * The markers are placed in the high area of the 16 bit key-table. + * Only the lower eight bits correspond to the (hopefully cracked) key-value. + **/ /* @@ -571,13 +571,13 @@ int bruteforceItem(loclass_dumpdata_t item, uint16_t keytable[]) { //A uint32 has room for 4 bytes, we'll only need 24 of those bits to bruteforce up to three bytes, uint32_t brute = 0; */ - /* - Determine where to stop the bruteforce. A 1-byte attack stops after 256 tries, - (when brute reaches 0x100). And so on... - bytes_to_recover = 1 --> endmask = 0x000000100 - bytes_to_recover = 2 --> endmask = 0x000010000 - bytes_to_recover = 3 --> endmask = 0x001000000 - */ +/* + Determine where to stop the bruteforce. A 1-byte attack stops after 256 tries, + (when brute reaches 0x100). And so on... + bytes_to_recover = 1 --> endmask = 0x000000100 + bytes_to_recover = 2 --> endmask = 0x000010000 + bytes_to_recover = 3 --> endmask = 0x001000000 +*/ /* uint32_t endmask = 1 << 8 * numbytes_to_recover; PrintAndLogEx(NORMAL, "----------------------------"); @@ -903,11 +903,11 @@ int testElite(bool slowtests) { int res = PM3_SUCCESS; PrintAndLogEx(INFO, "Testing hash1..."); res += _testHash1(); - PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " hash1 (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail") ); + PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " hash1 (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail")); PrintAndLogEx(INFO, "Testing key diversification..."); res += _test_iclass_key_permutation(); - PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " key diversification (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail") ); + PrintAndLogEx((res == PM3_SUCCESS) ? SUCCESS : WARNING, " key diversification (%s)", (res == PM3_SUCCESS) ? _GREEN_("ok") : _RED_("fail")); if (slowtests) res += _testBruteforce(); diff --git a/client/src/loclass/ikeys.c b/client/src/loclass/ikeys.c index 38adc04b0..d2798a14e 100644 --- a/client/src/loclass/ikeys.c +++ b/client/src/loclass/ikeys.c @@ -210,12 +210,12 @@ static void permute(BitstreamIn *p_in, uint64_t z, int l, int r, BitstreamOut *o return; bool pn = tailBit(p_in); - if (pn) { + if (pn) { // pn = 1 uint8_t zl = getSixBitByte(z, l); push6bits(out, zl + 1); permute(p_in, z, l + 1, r, out); - } else { + } else { // otherwise uint8_t zr = getSixBitByte(z, r); push6bits(out, zr); @@ -256,8 +256,8 @@ void hash0(uint64_t c, uint8_t k[8]) { c = swapZvalues(c); if (g_debugMode > 0) { - PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); - printState("origin", c); + PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); + printState("origin", c); } //These 64 bits are divided as c = x, y, z [0] , . . . , z [7] // x = 8 bits @@ -421,7 +421,7 @@ static int testDES(uint8_t *key, testcase_t testcase) { uint8_t des_encrypted_csn[8] = {0}; uint8_t decrypted[8] = {0}; uint8_t div_key[8] = {0}; - + mbedtls_des_context ctx_enc; mbedtls_des_context ctx_dec; @@ -466,12 +466,12 @@ static int testDES(uint8_t *key, testcase_t testcase) { static bool des_getParityBitFromKey(uint8_t key) { // The top 7 bits is used bool parity = ((key & 0x80) >> 7) - ^ ((key & 0x40) >> 6) - ^ ((key & 0x20) >> 5) - ^ ((key & 0x10) >> 4) - ^ ((key & 0x08) >> 3) - ^ ((key & 0x04) >> 2) - ^ ((key & 0x02) >> 1); + ^ ((key & 0x40) >> 6) + ^ ((key & 0x20) >> 5) + ^ ((key & 0x10) >> 4) + ^ ((key & 0x08) >> 3) + ^ ((key & 0x04) >> 2) + ^ ((key & 0x02) >> 1); return !parity; } @@ -613,7 +613,7 @@ static int testDES2(uint8_t *key, uint64_t csn, uint64_t expected) { uint64_t crypt_csn = x_bytes_to_num(result, 8); PrintAndLogEx(DEBUG, " {csn} %"PRIx64, crypt_csn); - PrintAndLogEx(DEBUG, " expected %"PRIx64 " (%s)", expected, (expected == crypt_csn) ? _GREEN_("ok") : _RED_("fail") ); + PrintAndLogEx(DEBUG, " expected %"PRIx64 " (%s)", expected, (expected == crypt_csn) ? _GREEN_("ok") : _RED_("fail")); if (expected != crypt_csn) return PM3_ESOFT; diff --git a/client/src/pm3.c b/client/src/pm3.c index 14f0b00ad..a4c9518c3 100644 --- a/client/src/pm3.c +++ b/client/src/pm3.c @@ -13,7 +13,7 @@ #include "util_posix.h" #include "comms.h" -pm3_device* pm3_open(char *port) { +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)) { @@ -30,7 +30,7 @@ pm3_device* pm3_open(char *port) { return session.current_device; } -void pm3_close(pm3_device* dev) { +void pm3_close(pm3_device *dev) { // Clean up the port if (session.pm3_present) { clearCommandBuffer(); @@ -40,16 +40,16 @@ void pm3_close(pm3_device* dev) { } } -int pm3_console(pm3_device* dev, char *Cmd) { +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) { +const char *pm3_name_get(pm3_device *dev) { return dev->conn->serial_port_name; } -pm3_device* pm3_get_current_dev(void) { +pm3_device *pm3_get_current_dev(void) { return session.current_device; } diff --git a/client/src/pm3_luawrap.c b/client/src/pm3_luawrap.c index cc8ca7dcf..565fd9d42 100644 --- a/client/src/pm3_luawrap.c +++ b/client/src/pm3_luawrap.c @@ -305,10 +305,10 @@ # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) SWIGINTERNINLINE int SWIG_AddCast(int r) { - return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; + return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; } SWIGINTERNINLINE int SWIG_CheckState(int r) { - return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ # define SWIG_AddCast(r) (r) @@ -327,32 +327,32 @@ typedef struct swig_type_info *(*swig_dycast_func)(void **); /* Structure to store information on one type */ typedef struct swig_type_info { - const char *name; /* mangled name of this type */ - const char *str; /* human readable name of this type */ - swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ - struct swig_cast_info *cast; /* linked list of types that can cast into this type */ - void *clientdata; /* language specific type data */ - int owndata; /* flag if the structure owns the clientdata */ + const char *name; /* mangled name of this type */ + const char *str; /* human readable name of this type */ + swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ + struct swig_cast_info *cast; /* linked list of types that can cast into this type */ + void *clientdata; /* language specific type data */ + int owndata; /* flag if the structure owns the clientdata */ } swig_type_info; /* Structure to store a type and conversion function used for casting */ typedef struct swig_cast_info { - swig_type_info *type; /* pointer to type that is equivalent to this type */ - swig_converter_func converter; /* function to cast the void pointers */ - struct swig_cast_info *next; /* pointer to next cast in linked list */ - struct swig_cast_info *prev; /* pointer to the previous cast */ + swig_type_info *type; /* pointer to type that is equivalent to this type */ + swig_converter_func converter; /* function to cast the void pointers */ + struct swig_cast_info *next; /* pointer to next cast in linked list */ + struct swig_cast_info *prev; /* pointer to the previous cast */ } swig_cast_info; /* Structure used to store module information * Each module generates one structure like this, and the runtime collects * all of these structures and stores them in a circularly linked list.*/ typedef struct swig_module_info { - swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ - size_t size; /* Number of types in this module */ - struct swig_module_info *next; /* Pointer to next element in circularly linked list */ - swig_type_info **type_initial; /* Array of initially generated type structures */ - swig_cast_info **cast_initial; /* Array of initially generated casting structures */ - void *clientdata; /* Language specific module data */ + swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ + size_t size; /* Number of types in this module */ + struct swig_module_info *next; /* Pointer to next element in circularly linked list */ + swig_type_info **type_initial; /* Array of initially generated type structures */ + swig_cast_info **cast_initial; /* Array of initially generated casting structures */ + void *clientdata; /* Language specific module data */ } swig_module_info; /* @@ -364,13 +364,13 @@ typedef struct swig_module_info { */ SWIGRUNTIME int SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; - } - return (int)((l1 - f1) - (l2 - f2)); + const char *f2, const char *l2) { + for (; (f1 != l1) && (f2 != l2); ++f1, ++f2) { + while ((*f1 == ' ') && (f1 != l1)) ++f1; + while ((*f2 == ' ') && (f2 != l2)) ++f2; + if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; + } + return (int)((l1 - f1) - (l2 - f2)); } /* @@ -379,17 +379,17 @@ SWIG_TypeNameComp(const char *f1, const char *l1, */ SWIGRUNTIME int SWIG_TypeCmp(const char *nb, const char *tb) { - int equiv = 1; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (equiv != 0 && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; + int equiv = 1; + const char *te = tb + strlen(tb); + const char *ne = nb; + while (equiv != 0 && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = SWIG_TypeNameComp(nb, ne, tb, te); + if (*ne) ++ne; } - equiv = SWIG_TypeNameComp(nb, ne, tb, te); - if (*ne) ++ne; - } - return equiv; + return equiv; } /* @@ -398,7 +398,7 @@ SWIG_TypeCmp(const char *nb, const char *tb) { */ SWIGRUNTIME int SWIG_TypeEquiv(const char *nb, const char *tb) { - return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; + return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; } /* @@ -406,26 +406,26 @@ SWIG_TypeEquiv(const char *nb, const char *tb) { */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheck(const char *c, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (strcmp(iter->type->name, c) == 0) { - if (iter == ty->cast) - return iter; - /* Move iter to the top of the linked list */ - iter->prev->next = iter->next; - if (iter->next) - iter->next->prev = iter->prev; - iter->next = ty->cast; - iter->prev = 0; - if (ty->cast) ty->cast->prev = iter; - ty->cast = iter; - return iter; - } - iter = iter->next; + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (strcmp(iter->type->name, c) == 0) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } } - } - return 0; + return 0; } /* @@ -433,26 +433,26 @@ SWIG_TypeCheck(const char *c, swig_type_info *ty) { */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (iter->type == from) { - if (iter == ty->cast) - return iter; - /* Move iter to the top of the linked list */ - iter->prev->next = iter->next; - if (iter->next) - iter->next->prev = iter->prev; - iter->next = ty->cast; - iter->prev = 0; - if (ty->cast) ty->cast->prev = iter; - ty->cast = iter; - return iter; - } - iter = iter->next; + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (iter->type == from) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } } - } - return 0; + return 0; } /* @@ -460,7 +460,7 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { */ SWIGRUNTIMEINLINE void * SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* @@ -468,13 +468,13 @@ SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { */ SWIGRUNTIME swig_type_info * SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; + swig_type_info *lastty = ty; + if (!ty || !ty->dcast) return ty; + while (ty && (ty->dcast)) { + ty = (*ty->dcast)(ptr); + if (ty) lastty = ty; + } + return lastty; } /* @@ -482,7 +482,7 @@ SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { */ SWIGRUNTIMEINLINE const char * SWIG_TypeName(const swig_type_info *ty) { - return ty->name; + return ty->name; } /* @@ -491,20 +491,19 @@ SWIG_TypeName(const swig_type_info *ty) { */ SWIGRUNTIME const char * SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (!type) return NULL; - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; + /* The "str" field contains the equivalent pretty names of the + type, separated by vertical-bar characters. We choose + to print the last name, as it is often (?) the most + specific. */ + if (!type) return NULL; + if (type->str != NULL) { + const char *last_name = type->str; + const char *s; + for (s = type->str; *s; s++) + if (*s == '|') last_name = s + 1; + return last_name; + } else + return type->name; } /* @@ -512,24 +511,24 @@ SWIG_TypePrettyName(const swig_type_info *type) { */ SWIGRUNTIME void SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_cast_info *cast = ti->cast; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; + swig_cast_info *cast = ti->cast; + /* if (ti->clientdata == clientdata) return; */ + ti->clientdata = clientdata; - while (cast) { - if (!cast->converter) { - swig_type_info *tc = cast->type; - if (!tc->clientdata) { - SWIG_TypeClientData(tc, clientdata); - } + while (cast) { + if (!cast->converter) { + swig_type_info *tc = cast->type; + if (!tc->clientdata) { + SWIG_TypeClientData(tc, clientdata); + } + } + cast = cast->next; } - cast = cast->next; - } } SWIGRUNTIME void SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { - SWIG_TypeClientData(ti, clientdata); - ti->owndata = 1; + SWIG_TypeClientData(ti, clientdata); + ti->owndata = 1; } /* @@ -543,37 +542,37 @@ SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { SWIGRUNTIME swig_type_info * SWIG_MangledTypeQueryModule(swig_module_info *start, swig_module_info *end, - const char *name) { - swig_module_info *iter = start; - do { - if (iter->size) { - size_t l = 0; - size_t r = iter->size - 1; - do { - /* since l+r >= 0, we can (>> 1) instead (/ 2) */ - size_t i = (l + r) >> 1; - const char *iname = iter->types[i]->name; - if (iname) { - int compare = strcmp(name, iname); - if (compare == 0) { - return iter->types[i]; - } else if (compare < 0) { - if (i) { - r = i - 1; - } else { - break; - } - } else if (compare > 0) { - l = i + 1; - } - } else { - break; /* should never happen */ - } - } while (l <= r); - } - iter = iter->next; - } while (iter != end); - return 0; + const char *name) { + swig_module_info *iter = start; + do { + if (iter->size) { + size_t l = 0; + size_t r = iter->size - 1; + do { + /* since l+r >= 0, we can (>> 1) instead (/ 2) */ + size_t i = (l + r) >> 1; + const char *iname = iter->types[i]->name; + if (iname) { + int compare = strcmp(name, iname); + if (compare == 0) { + return iter->types[i]; + } else if (compare < 0) { + if (i) { + r = i - 1; + } else { + break; + } + } else if (compare > 0) { + l = i + 1; + } + } else { + break; /* should never happen */ + } + } while (l <= r); + } + iter = iter->next; + } while (iter != end); + return 0; } /* @@ -588,27 +587,27 @@ SWIG_MangledTypeQueryModule(swig_module_info *start, SWIGRUNTIME swig_type_info * SWIG_TypeQueryModule(swig_module_info *start, swig_module_info *end, - const char *name) { - /* STEP 1: Search the name field using binary search */ - swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); - if (ret) { - return ret; - } else { - /* STEP 2: If the type hasn't been found, do a complete search - of the str field (the human readable name) */ - swig_module_info *iter = start; - do { - size_t i = 0; - for (; i < iter->size; ++i) { - if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) - return iter->types[i]; - } - iter = iter->next; - } while (iter != end); - } + const char *name) { + /* STEP 1: Search the name field using binary search */ + swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); + if (ret) { + return ret; + } else { + /* STEP 2: If the type hasn't been found, do a complete search + of the str field (the human readable name) */ + swig_module_info *iter = start; + do { + size_t i = 0; + for (; i < iter->size; ++i) { + if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) + return iter->types[i]; + } + iter = iter->next; + } while (iter != end); + } - /* neither found a match */ - return 0; + /* neither found a match */ + return 0; } /* @@ -616,15 +615,15 @@ SWIG_TypeQueryModule(swig_module_info *start, */ SWIGRUNTIME char * SWIG_PackData(char *c, void *ptr, size_t sz) { - static const char hex[17] = "0123456789abcdef"; - const unsigned char *u = (unsigned char *) ptr; - const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - unsigned char uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; + static const char hex[17] = "0123456789abcdef"; + const unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + unsigned char uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; } /* @@ -632,27 +631,27 @@ SWIG_PackData(char *c, void *ptr, size_t sz) { */ SWIGRUNTIME const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { - unsigned char *u = (unsigned char *) ptr; - const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - char d = *(c++); - unsigned char uu; - if ((d >= '0') && (d <= '9')) - uu = (unsigned char)((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = (unsigned char)((d - ('a'-10)) << 4); - else - return (char *) 0; - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (unsigned char)(d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (unsigned char)(d - ('a'-10)); - else - return (char *) 0; - *u = uu; - } - return c; + unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + char d = *(c++); + unsigned char uu; + if ((d >= '0') && (d <= '9')) + uu = (unsigned char)((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = (unsigned char)((d - ('a' - 10)) << 4); + else + return (char *) 0; + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (unsigned char)(d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (unsigned char)(d - ('a' - 10)); + else + return (char *) 0; + *u = uu; + } + return c; } /* @@ -660,54 +659,54 @@ SWIG_UnpackData(const char *c, void *ptr, size_t sz) { */ SWIGRUNTIME char * SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { - char *r = buff; - if ((2*sizeof(void *) + 2) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - if (strlen(name) + 1 > (bsz - (r - buff))) return 0; - strcpy(r,name); - return buff; + char *r = buff; + if ((2 * sizeof(void *) + 2) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r, &ptr, sizeof(void *)); + if (strlen(name) + 1 > (bsz - (r - buff))) return 0; + strcpy(r, name); + return buff; } SWIGRUNTIME const char * SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - *ptr = (void *) 0; - return name; - } else { - return 0; + if (*c != '_') { + if (strcmp(c, "NULL") == 0) { + *ptr = (void *) 0; + return name; + } else { + return 0; + } } - } - return SWIG_UnpackData(++c,ptr,sizeof(void *)); + return SWIG_UnpackData(++c, ptr, sizeof(void *)); } SWIGRUNTIME char * SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { - char *r = buff; - size_t lname = (name ? strlen(name) : 0); - if ((2*sz + 2 + lname) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - if (lname) { - strncpy(r,name,lname+1); - } else { - *r = 0; - } - return buff; + char *r = buff; + size_t lname = (name ? strlen(name) : 0); + if ((2 * sz + 2 + lname) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r, ptr, sz); + if (lname) { + strncpy(r, name, lname + 1); + } else { + *r = 0; + } + return buff; } SWIGRUNTIME const char * SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - memset(ptr,0,sz); - return name; - } else { - return 0; + if (*c != '_') { + if (strcmp(c, "NULL") == 0) { + memset(ptr, 0, sz); + return name; + } else { + return 0; + } } - } - return SWIG_UnpackData(++c,ptr,sz); + return SWIG_UnpackData(++c, ptr, sz); } #ifdef __cplusplus @@ -765,32 +764,32 @@ extern "C" { struct swig_elua_entry; typedef struct swig_elua_key { - int type; - union { - const char* strkey; - lua_Number numkey; - } key; + int type; + union { + const char *strkey; + lua_Number numkey; + } key; } swig_elua_key; typedef struct swig_elua_val { - int type; - union { - lua_Number number; - const struct swig_elua_entry *table; - const char *string; - lua_CFunction function; - struct { - char member; - long lvalue; - void *pvalue; - swig_type_info **ptype; - } userdata; - } value; + int type; + union { + lua_Number number; + const struct swig_elua_entry *table; + const char *string; + lua_CFunction function; + struct { + char member; + long lvalue; + void *pvalue; + swig_type_info **ptype; + } userdata; + } value; } swig_elua_val; typedef struct swig_elua_entry { - swig_elua_key key; - swig_elua_val value; + swig_elua_key key; + swig_elua_val value; } swig_elua_entry; #define LSTRKEY(x) {LUA_TSTRING, {.strkey = x} } @@ -824,7 +823,7 @@ typedef struct swig_elua_entry { # define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C) # define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C) # define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C) - /* Those two types of constants are not supported in elua */ +/* Those two types of constants are not supported in elua */ #ifndef SWIG_LUA_CONSTTAB_POINTER #warning eLua does not support pointers as constants. By default, nil will be used as value @@ -916,25 +915,23 @@ typedef struct swig_elua_entry { prefixed with the location of the innermost Lua call-point (as formatted by luaL_where). */ SWIGRUNTIME void -SWIG_Lua_pusherrstring (lua_State *L, const char *str) -{ - luaL_where (L, 1); - lua_pushstring (L, str); - lua_concat (L, 2); +SWIG_Lua_pusherrstring(lua_State *L, const char *str) { + luaL_where(L, 1); + lua_pushstring(L, str); + lua_concat(L, 2); } /* Push a formatted string generated from FMT and following args on the Lua stack, like lua_pushfstring, but prefixed with the location of the innermost Lua call-point (as formatted by luaL_where). */ SWIGRUNTIME void -SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...) -{ - va_list argp; - va_start(argp, fmt); - luaL_where(L, 1); - lua_pushvfstring(L, fmt, argp); - va_end(argp); - lua_concat(L, 2); +SWIG_Lua_pushferrstring(lua_State *L, const char *fmt, ...) { + va_list argp; + va_start(argp, fmt); + luaL_where(L, 1); + lua_pushvfstring(L, fmt, argp); + va_end(argp); + lua_concat(L, 2); } @@ -951,9 +948,9 @@ SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...) /* Structure for variable linking table */ typedef struct { - const char *name; - lua_CFunction get; - lua_CFunction set; + const char *name; + lua_CFunction get; + lua_CFunction set; } swig_lua_var_info; #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) @@ -975,43 +972,43 @@ typedef struct { #endif typedef struct { - const char *name; - lua_CFunction getmethod; - lua_CFunction setmethod; + const char *name; + lua_CFunction getmethod; + lua_CFunction setmethod; } swig_lua_attribute; struct swig_lua_class; /* Can be used to create namespaces. Currently used to wrap class static methods/variables/constants */ typedef struct swig_lua_namespace { - const char *name; - swig_lua_method *ns_methods; - swig_lua_attribute *ns_attributes; - swig_lua_const_info *ns_constants; - struct swig_lua_class **ns_classes; - struct swig_lua_namespace **ns_namespaces; + const char *name; + swig_lua_method *ns_methods; + swig_lua_attribute *ns_attributes; + swig_lua_const_info *ns_constants; + struct swig_lua_class **ns_classes; + struct swig_lua_namespace **ns_namespaces; } swig_lua_namespace; typedef struct swig_lua_class { - const char *name; /* Name that this class has in Lua */ - const char *fqname; /* Fully qualified name - Scope + class name */ - swig_type_info **type; - lua_CFunction constructor; - void (*destructor)(void *); - swig_lua_method *methods; - swig_lua_attribute *attributes; - swig_lua_namespace *cls_static; - swig_lua_method *metatable; /* 0 for -eluac */ - struct swig_lua_class **bases; - const char **base_names; + const char *name; /* Name that this class has in Lua */ + const char *fqname; /* Fully qualified name - Scope + class name */ + swig_type_info **type; + lua_CFunction constructor; + void (*destructor)(void *); + swig_lua_method *methods; + swig_lua_attribute *attributes; + swig_lua_namespace *cls_static; + swig_lua_method *metatable; /* 0 for -eluac */ + struct swig_lua_class **bases; + const char **base_names; } swig_lua_class; /* this is the struct for wrapping all pointers in SwigLua */ typedef struct { - swig_type_info *type; - int own; /* 1 if owned & must be destroyed */ - void *ptr; + swig_type_info *type; + int own; /* 1 if owned & must be destroyed */ + void *ptr; } swig_lua_userdata; /* this is the struct for wrapping arbitrary packed binary data @@ -1020,9 +1017,9 @@ the data ordering is similar to swig_lua_userdata, but it is currently not possi to tell the two structures apart within SWIG, other than by looking at the type */ typedef struct { - swig_type_info *type; - int own; /* 1 if owned & must be destroyed */ - char data[1]; /* arbitrary amount of data */ + swig_type_info *type; + int own; /* 1 if owned & must be destroyed */ + char data[1]; /* arbitrary amount of data */ } swig_lua_rawdata; /* Common SWIG API */ @@ -1082,21 +1079,21 @@ it gets the address, casts it, then dereferences it */ /* storing/access of swig_module_info */ SWIGRUNTIME swig_module_info * SWIG_Lua_GetModule(lua_State *L) { - swig_module_info *ret = 0; - lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); - lua_rawget(L,LUA_REGISTRYINDEX); - if (lua_islightuserdata(L,-1)) - ret=(swig_module_info*)lua_touserdata(L,-1); - lua_pop(L,1); /* tidy */ - return ret; + swig_module_info *ret = 0; + lua_pushstring(L, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_islightuserdata(L, -1)) + ret = (swig_module_info *)lua_touserdata(L, -1); + lua_pop(L, 1); /* tidy */ + return ret; } SWIGRUNTIME void SWIG_Lua_SetModule(lua_State *L, swig_module_info *module) { - /* add this all into the Lua registry: */ - lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); - lua_pushlightuserdata(L,(void*)module); - lua_rawset(L,LUA_REGISTRYINDEX); + /* add this all into the Lua registry: */ + lua_pushstring(L, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); + lua_pushlightuserdata(L, (void *)module); + lua_rawset(L, LUA_REGISTRYINDEX); } /* ----------------------------------------------------------------------------- @@ -1106,153 +1103,147 @@ SWIG_Lua_SetModule(lua_State *L, swig_module_info *module) { /* this function is called when trying to set an immutable. default action is to print an error. This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */ -SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) -{ -/* there should be 1 param passed in: the new value */ +SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) { + /* there should be 1 param passed in: the new value */ #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE - lua_pop(L,1); /* remove it */ - luaL_error(L,"This variable is immutable"); + lua_pop(L, 1); /* remove it */ + luaL_error(L, "This variable is immutable"); #endif return 0; /* should not return anything */ } #ifdef SWIG_LUA_ELUA_EMULATE -SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own); -SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type); +SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L, void *ptr, swig_type_info *type, int own); +SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L, void *ptr, size_t size, swig_type_info *type); static int swig_lua_elua_emulate_unique_key; /* This function emulates eLua rotables behaviour. It loads a rotable definition into the usual lua table. */ -SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table) -{ - int i, table_parsed, parsed_tables_array, target_table; - assert(lua_istable(L,-1)); - target_table = lua_gettop(L); - /* Get the registry where we put all parsed tables to avoid loops */ - lua_rawgetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key); - if(lua_isnil(L,-1)) { - lua_pop(L,1); - lua_newtable(L); - lua_pushvalue(L,-1); - lua_rawsetp(L,LUA_REGISTRYINDEX,(void*)(&swig_lua_elua_emulate_unique_key)); - } - parsed_tables_array = lua_gettop(L); - lua_pushvalue(L,target_table); - lua_rawsetp(L, parsed_tables_array, table); - table_parsed = 0; - const int SWIGUNUSED pairs_start = lua_gettop(L); - for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++) - { - const swig_elua_entry *entry = table + i; - int is_metatable = 0; - switch(entry->key.type) { - case LUA_TSTRING: - lua_pushstring(L,entry->key.key.strkey); - if(strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0) - is_metatable = 1; - break; - case LUA_TNUMBER: - lua_pushnumber(L,entry->key.key.numkey); - break; - case LUA_TNIL: - lua_pushnil(L); - break; - default: - assert(0); +SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table) { + int i, table_parsed, parsed_tables_array, target_table; + assert(lua_istable(L, -1)); + target_table = lua_gettop(L); + /* Get the registry where we put all parsed tables to avoid loops */ + lua_rawgetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_newtable(L); + lua_pushvalue(L, -1); + lua_rawsetp(L, LUA_REGISTRYINDEX, (void *)(&swig_lua_elua_emulate_unique_key)); } - switch(entry->value.type) { - case LUA_TSTRING: - lua_pushstring(L,entry->value.value.string); - break; - case LUA_TNUMBER: - lua_pushnumber(L,entry->value.value.number); - break; - case LUA_TFUNCTION: - lua_pushcfunction(L,entry->value.value.function); - break; - case LUA_TTABLE: - lua_rawgetp(L,parsed_tables_array, entry->value.value.table); - table_parsed = !lua_isnil(L,-1); - if(!table_parsed) { - lua_pop(L,1); /*remove nil */ - lua_newtable(L); - SWIG_Lua_elua_emulate_register(L,entry->value.value.table); - } - if(is_metatable) { - assert(lua_istable(L,-1)); - lua_pushvalue(L,-1); - lua_setmetatable(L,target_table); + parsed_tables_array = lua_gettop(L); + lua_pushvalue(L, target_table); + lua_rawsetp(L, parsed_tables_array, table); + table_parsed = 0; + const int SWIGUNUSED pairs_start = lua_gettop(L); + for (i = 0; table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL; i++) { + const swig_elua_entry *entry = table + i; + int is_metatable = 0; + switch (entry->key.type) { + case LUA_TSTRING: + lua_pushstring(L, entry->key.key.strkey); + if (strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0) + is_metatable = 1; + break; + case LUA_TNUMBER: + lua_pushnumber(L, entry->key.key.numkey); + break; + case LUA_TNIL: + lua_pushnil(L); + break; + default: + assert(0); } + switch (entry->value.type) { + case LUA_TSTRING: + lua_pushstring(L, entry->value.value.string); + break; + case LUA_TNUMBER: + lua_pushnumber(L, entry->value.value.number); + break; + case LUA_TFUNCTION: + lua_pushcfunction(L, entry->value.value.function); + break; + case LUA_TTABLE: + lua_rawgetp(L, parsed_tables_array, entry->value.value.table); + table_parsed = !lua_isnil(L, -1); + if (!table_parsed) { + lua_pop(L, 1); /*remove nil */ + lua_newtable(L); + SWIG_Lua_elua_emulate_register(L, entry->value.value.table); + } + if (is_metatable) { + assert(lua_istable(L, -1)); + lua_pushvalue(L, -1); + lua_setmetatable(L, target_table); + } - break; - case LUA_TUSERDATA: - if(entry->value.value.userdata.member) - SWIG_NewMemberObj(L,entry->value.value.userdata.pvalue, - entry->value.value.userdata.lvalue, - *(entry->value.value.userdata.ptype)); - else - SWIG_NewPointerObj(L,entry->value.value.userdata.pvalue, - *(entry->value.value.userdata.ptype),0); - break; - case LUA_TNIL: - lua_pushnil(L); - break; - default: - assert(0); + break; + case LUA_TUSERDATA: + if (entry->value.value.userdata.member) + SWIG_NewMemberObj(L, entry->value.value.userdata.pvalue, + entry->value.value.userdata.lvalue, + *(entry->value.value.userdata.ptype)); + else + SWIG_NewPointerObj(L, entry->value.value.userdata.pvalue, + *(entry->value.value.userdata.ptype), 0); + break; + case LUA_TNIL: + lua_pushnil(L); + break; + default: + assert(0); + } + assert(lua_gettop(L) == pairs_start + 2); + lua_rawset(L, target_table); } - assert(lua_gettop(L) == pairs_start + 2); - lua_rawset(L,target_table); - } - lua_pop(L,1); /* Removing parsed tables storage */ - assert(lua_gettop(L) == target_table); + lua_pop(L, 1); /* Removing parsed tables storage */ + assert(lua_gettop(L) == target_table); } -SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L) -{ - lua_pushnil(L); - lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key); +SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L) { + lua_pushnil(L); + lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key); } SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L); -SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L) -{ - SWIG_check_num_args("getmetatable(SWIG eLua emulation)", 1, 1); - SWIG_Lua_get_class_registry(L); - lua_getfield(L,-1,"lua_getmetatable"); - lua_remove(L,-2); /* remove the registry*/ - assert(!lua_isnil(L,-1)); - lua_pushvalue(L,1); - assert(lua_gettop(L) == 3); /* object | function | object again */ - lua_call(L,1,1); - if(!lua_isnil(L,-1)) /*There is an ordinary metatable */ +SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L) { + SWIG_check_num_args("getmetatable(SWIG eLua emulation)", 1, 1); + SWIG_Lua_get_class_registry(L); + lua_getfield(L, -1, "lua_getmetatable"); + lua_remove(L, -2); /* remove the registry*/ + assert(!lua_isnil(L, -1)); + lua_pushvalue(L, 1); + assert(lua_gettop(L) == 3); /* object | function | object again */ + lua_call(L, 1, 1); + if (!lua_isnil(L, -1)) /*There is an ordinary metatable */ + return 1; + /*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/ + assert(lua_gettop(L) == 2); + if (lua_istable(L, -2)) { + lua_pop(L, 1); /*remove the nil*/ + lua_getfield(L, -1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY); + } + assert(lua_gettop(L) == 2); return 1; - /*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/ - assert(lua_gettop(L) == 2); - if(lua_istable(L,-2)) { - lua_pop(L,1); /*remove the nil*/ - lua_getfield(L,-1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY); - } - assert(lua_gettop(L) == 2); - return 1; fail: - lua_error(L); - return 0; + lua_error(L); + return 0; } -SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) -{ - SWIG_Lua_get_class_registry(L); - lua_pushglobaltable(L); - lua_pushstring(L,"lua_getmetatable"); - lua_getfield(L,-2,"getmetatable"); - assert(!lua_isnil(L,-1)); - lua_rawset(L,-4); - lua_pushstring(L, "getmetatable"); - lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable); - lua_rawset(L,-3); - lua_pop(L,2); +SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) { + SWIG_Lua_get_class_registry(L); + lua_pushglobaltable(L); + lua_pushstring(L, "lua_getmetatable"); + lua_getfield(L, -2, "getmetatable"); + assert(!lua_isnil(L, -1)); + lua_rawset(L, -4); + lua_pushstring(L, "getmetatable"); + lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable); + lua_rawset(L, -3); + lua_pop(L, 2); } /* END OF REMOVE */ @@ -1262,120 +1253,115 @@ SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) * global variable support code: namespaces and modules (which are the same thing) * ----------------------------------------------------------------------------- */ -SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L) -{ -/* there should be 2 params passed in - (1) table (not the meta table) - (2) string name of the attribute -*/ - assert(lua_istable(L,-2)); /* just in case */ - lua_getmetatable(L,-2); - assert(lua_istable(L,-1)); - SWIG_Lua_get_table(L,".get"); /* find the .get table */ - assert(lua_istable(L,-1)); - /* look for the key in the .get table */ - lua_pushvalue(L,2); /* key */ - lua_rawget(L,-2); - lua_remove(L,-2); /* stack tidy, remove .get table */ - if (lua_iscfunction(L,-1)) - { /* found it so call the fn & return its value */ - lua_call(L,0,1); /* 1 value in (userdata),1 out (result) */ - lua_remove(L,-2); /* stack tidy, remove metatable */ - return 1; - } - lua_pop(L,1); /* remove whatever was there */ - /* ok, so try the .fn table */ - SWIG_Lua_get_table(L,".fn"); /* find the .get table */ - assert(lua_istable(L,-1)); /* just in case */ - lua_pushvalue(L,2); /* key */ - lua_rawget(L,-2); /* look for the fn */ - lua_remove(L,-2); /* stack tidy, remove .fn table */ - if (lua_isfunction(L,-1)) /* note: whether it's a C function or lua function */ - { /* found it so return the fn & let lua call it */ - lua_remove(L,-2); /* stack tidy, remove metatable */ - return 1; - } - lua_pop(L,1); /* remove whatever was there */ - return 0; +SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L) { + /* there should be 2 params passed in + (1) table (not the meta table) + (2) string name of the attribute + */ + assert(lua_istable(L, -2)); /* just in case */ + lua_getmetatable(L, -2); + assert(lua_istable(L, -1)); + SWIG_Lua_get_table(L, ".get"); /* find the .get table */ + assert(lua_istable(L, -1)); + /* look for the key in the .get table */ + lua_pushvalue(L, 2); /* key */ + lua_rawget(L, -2); + lua_remove(L, -2); /* stack tidy, remove .get table */ + if (lua_iscfunction(L, -1)) { + /* found it so call the fn & return its value */ + lua_call(L, 0, 1); /* 1 value in (userdata),1 out (result) */ + lua_remove(L, -2); /* stack tidy, remove metatable */ + return 1; + } + lua_pop(L, 1); /* remove whatever was there */ + /* ok, so try the .fn table */ + SWIG_Lua_get_table(L, ".fn"); /* find the .get table */ + assert(lua_istable(L, -1)); /* just in case */ + lua_pushvalue(L, 2); /* key */ + lua_rawget(L, -2); /* look for the fn */ + lua_remove(L, -2); /* stack tidy, remove .fn table */ + if (lua_isfunction(L, -1)) { /* note: whether it's a C function or lua function */ + /* found it so return the fn & let lua call it */ + lua_remove(L, -2); /* stack tidy, remove metatable */ + return 1; + } + lua_pop(L, 1); /* remove whatever was there */ + return 0; } -SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) -{ -/* there should be 3 params passed in - (1) table (not the meta table) - (2) string name of the attribute - (3) any for the new value -*/ +SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) { + /* there should be 3 params passed in + (1) table (not the meta table) + (2) string name of the attribute + (3) any for the new value + */ - assert(lua_istable(L,1)); - lua_getmetatable(L,1); /* get the meta table */ - assert(lua_istable(L,-1)); + assert(lua_istable(L, 1)); + lua_getmetatable(L, 1); /* get the meta table */ + assert(lua_istable(L, -1)); - SWIG_Lua_get_table(L,".set"); /* find the .set table */ - if (lua_istable(L,-1)) - { - /* look for the key in the .set table */ - lua_pushvalue(L,2); /* key */ - lua_rawget(L,-2); - if (lua_iscfunction(L,-1)) - { /* found it so call the fn & return its value */ - lua_pushvalue(L,3); /* value */ - lua_call(L,1,0); - return 0; + SWIG_Lua_get_table(L, ".set"); /* find the .set table */ + if (lua_istable(L, -1)) { + /* look for the key in the .set table */ + lua_pushvalue(L, 2); /* key */ + lua_rawget(L, -2); + if (lua_iscfunction(L, -1)) { + /* found it so call the fn & return its value */ + lua_pushvalue(L, 3); /* value */ + lua_call(L, 1, 0); + return 0; + } + lua_pop(L, 1); /* remove the value */ } - lua_pop(L,1); /* remove the value */ - } - lua_pop(L,1); /* remove the value .set table */ - lua_pop(L,1); /* remote metatable */ - lua_rawset(L,-3); - return 0; + lua_pop(L, 1); /* remove the value .set table */ + lua_pop(L, 1); /* remote metatable */ + lua_rawset(L, -3); + return 0; } #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */ SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); /* forward declaration */ -SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); /* forward declaration */ -SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss); +SWIGINTERN void SWIG_Lua_add_variable(lua_State *L, const char *name, lua_CFunction getFn, lua_CFunction setFn); /* forward declaration */ +SWIGINTERN void SWIG_Lua_class_register(lua_State *L, swig_lua_class *clss); /* helper function - register namespace methods and attributes into namespace */ -SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns) -{ - int i; - /* There must be namespace table (not metatable) at the top of the stack */ - assert(lua_istable(L,-1)); - SWIG_Lua_InstallConstants(L, ns->ns_constants); +SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns) { + int i; + /* There must be namespace table (not metatable) at the top of the stack */ + assert(lua_istable(L, -1)); + SWIG_Lua_InstallConstants(L, ns->ns_constants); - /* add methods to the namespace/module table */ - for(i=0;ns->ns_methods[i].name;i++){ - SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].func); - } - lua_getmetatable(L,-1); + /* add methods to the namespace/module table */ + for (i = 0; ns->ns_methods[i].name; i++) { + SWIG_Lua_add_function(L, ns->ns_methods[i].name, ns->ns_methods[i].func); + } + lua_getmetatable(L, -1); - /* add fns */ - for(i=0;ns->ns_attributes[i].name;i++){ - SWIG_Lua_add_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod); - } + /* add fns */ + for (i = 0; ns->ns_attributes[i].name; i++) { + SWIG_Lua_add_variable(L, ns->ns_attributes[i].name, ns->ns_attributes[i].getmethod, ns->ns_attributes[i].setmethod); + } - /* clear stack - remove metatble */ - lua_pop(L,1); - return 0; + /* clear stack - remove metatble */ + lua_pop(L, 1); + return 0; } /* Register all classes in the namespace */ -SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns) -{ - swig_lua_class **classes; +SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns) { + swig_lua_class **classes; - /* There must be a module/namespace table at the top of the stack */ - assert(lua_istable(L,-1)); + /* There must be a module/namespace table at the top of the stack */ + assert(lua_istable(L, -1)); - classes = ns->ns_classes; + classes = ns->ns_classes; - if( classes != 0 ) { - while(*classes != 0) { - SWIG_Lua_class_register(L, *classes); - classes++; + if (classes != 0) { + while (*classes != 0) { + SWIG_Lua_class_register(L, *classes); + classes++; + } } - } } /* Helper function. Creates namespace table and adds it to module table @@ -1383,55 +1369,54 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace when function is called). Function always returns newly registered table on top of the stack. */ -SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg) -{ - swig_lua_namespace **sub_namespace; - /* 1 argument - table on the top of the stack */ - const int SWIGUNUSED begin = lua_gettop(L); - assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */ - lua_checkstack(L,5); - lua_newtable(L); /* namespace itself */ - lua_newtable(L); /* metatable for namespace */ +SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg) { + swig_lua_namespace **sub_namespace; + /* 1 argument - table on the top of the stack */ + const int SWIGUNUSED begin = lua_gettop(L); + assert(lua_istable(L, -1)); /* just in case. This is supposed to be module table or parent namespace table */ + lua_checkstack(L, 5); + lua_newtable(L); /* namespace itself */ + lua_newtable(L); /* metatable for namespace */ - /* add a table called ".get" */ - lua_pushstring(L,".get"); - lua_newtable(L); - lua_rawset(L,-3); - /* add a table called ".set" */ - lua_pushstring(L,".set"); - lua_newtable(L); - lua_rawset(L,-3); - /* add a table called ".fn" */ - lua_pushstring(L,".fn"); - lua_newtable(L); - lua_rawset(L,-3); + /* add a table called ".get" */ + lua_pushstring(L, ".get"); + lua_newtable(L); + lua_rawset(L, -3); + /* add a table called ".set" */ + lua_pushstring(L, ".set"); + lua_newtable(L); + lua_rawset(L, -3); + /* add a table called ".fn" */ + lua_pushstring(L, ".fn"); + lua_newtable(L); + lua_rawset(L, -3); - /* add accessor fns for using the .get,.set&.fn */ - SWIG_Lua_add_function(L,"__index",SWIG_Lua_namespace_get); - SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set); + /* add accessor fns for using the .get,.set&.fn */ + SWIG_Lua_add_function(L, "__index", SWIG_Lua_namespace_get); + SWIG_Lua_add_function(L, "__newindex", SWIG_Lua_namespace_set); - lua_setmetatable(L,-2); /* set metatable */ + lua_setmetatable(L, -2); /* set metatable */ - /* Register all functions, variables etc */ - SWIG_Lua_add_namespace_details(L,ns); - /* Register classes */ - SWIG_Lua_add_namespace_classes(L,ns); + /* Register all functions, variables etc */ + SWIG_Lua_add_namespace_details(L, ns); + /* Register classes */ + SWIG_Lua_add_namespace_classes(L, ns); - sub_namespace = ns->ns_namespaces; - if( sub_namespace != 0) { - while(*sub_namespace != 0) { - SWIG_Lua_namespace_register(L, *sub_namespace, 1); - lua_pop(L,1); /* removing sub-namespace table */ - sub_namespace++; + sub_namespace = ns->ns_namespaces; + if (sub_namespace != 0) { + while (*sub_namespace != 0) { + SWIG_Lua_namespace_register(L, *sub_namespace, 1); + lua_pop(L, 1); /* removing sub-namespace table */ + sub_namespace++; + } } - } - if (reg) { - lua_pushstring(L,ns->name); - lua_pushvalue(L,-2); - lua_rawset(L,-4); /* add namespace to module table */ - } - assert(lua_gettop(L) == begin+1); + if (reg) { + lua_pushstring(L, ns->name); + lua_pushvalue(L, -2); + lua_rawset(L, -4); /* add namespace to module table */ + } + assert(lua_gettop(L) == begin + 1); } #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */ @@ -1439,13 +1424,12 @@ SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns * global variable support code: classes * ----------------------------------------------------------------------------- */ -SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname); +SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L, const char *cname); -typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret); +typedef int (*swig_lua_base_iterator_func)(lua_State *, swig_type_info *, int, int *ret); -SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED swig_type, - int first_arg, swig_lua_base_iterator_func func, int *const ret) -{ +SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *SWIGUNUSED swig_type, + int first_arg, swig_lua_base_iterator_func func, int *const ret) { /* first_arg - position of the object in stack. Everything that is above are arguments * and is passed to every evocation of the func */ int last_arg = lua_gettop(L);/* position of last argument */ @@ -1454,88 +1438,87 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED int result = SWIG_ERROR; int bases_table; (void)swig_type; - lua_getmetatable(L,first_arg); + lua_getmetatable(L, first_arg); /* initialise base search */ #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) - SWIG_Lua_get_table(L,".bases"); - assert(lua_istable(L,-1)); - bases_count = lua_rawlen(L,-1); + SWIG_Lua_get_table(L, ".bases"); + assert(lua_istable(L, -1)); + bases_count = lua_rawlen(L, -1); bases_table = lua_gettop(L); #else /* In elua .bases table doesn't exist. Use table from swig_lua_class */ (void)bases_table; - assert(swig_type!=0); - swig_module_info *module=SWIG_GetModule(L); - swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases; - const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names; + assert(swig_type != 0); + swig_module_info *module = SWIG_GetModule(L); + swig_lua_class **bases = ((swig_lua_class *)(swig_type->clientdata))->bases; + const char **base_names = ((swig_lua_class *)(swig_type->clientdata))->base_names; bases_count = 0; - for(;base_names[bases_count]; - bases_count++);/* get length of bases */ + for (; base_names[bases_count]; + bases_count++);/* get length of bases */ #endif - if(ret) - *ret = 0; - if(bases_count>0) - { - int to_remove; - size_t i; - int j; - int subcall_last_arg; - int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */ - int valid = 1; - swig_type_info *base_swig_type = 0; - for(j=first_arg;j<=last_arg;j++) - lua_pushvalue(L,j); - subcall_last_arg = lua_gettop(L); + if (ret) + *ret = 0; + if (bases_count > 0) { + int to_remove; + size_t i; + int j; + int subcall_last_arg; + int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */ + int valid = 1; + swig_type_info *base_swig_type = 0; + for (j = first_arg; j <= last_arg; j++) + lua_pushvalue(L, j); + subcall_last_arg = lua_gettop(L); - /* Trick: temporarily replacing original metatable with metatable for base class and call getter */ - for(i=0;ifqname); - base_swig_type = SWIG_TypeQueryModule(module,module,base_names[i]); - assert(base_swig_type != 0); - } + swig_lua_class *base_class = bases[i]; + if (!base_class) { + valid = 0; + } else { + valid = 1; + SWIG_Lua_get_class_metatable(L, base_class->fqname); + base_swig_type = SWIG_TypeQueryModule(module, module, base_names[i]); + assert(base_swig_type != 0); + } #endif - if(!valid) - continue; - assert(lua_isuserdata(L, subcall_first_arg)); - assert(lua_istable(L,-1)); - lua_setmetatable(L,subcall_first_arg); /* Set new metatable */ - assert(lua_gettop(L) == subcall_last_arg); - result = func(L, base_swig_type,subcall_first_arg, ret); /* Forward call */ - if(result != SWIG_ERROR) { - break; + if (!valid) + continue; + assert(lua_isuserdata(L, subcall_first_arg)); + assert(lua_istable(L, -1)); + lua_setmetatable(L, subcall_first_arg); /* Set new metatable */ + assert(lua_gettop(L) == subcall_last_arg); + result = func(L, base_swig_type, subcall_first_arg, ret); /* Forward call */ + if (result != SWIG_ERROR) { + break; + } } - } - /* Restore original metatable */ - lua_pushvalue(L,original_metatable); - lua_setmetatable(L,first_arg); - /* Clear - remove everything between last_arg and subcall_last_arg including */ - to_remove = subcall_last_arg - last_arg; - for(j=0;jtype; - result = SWIG_Lua_class_do_get(L,type,1,&ret); - if(result == SWIG_OK) - return ret; +SWIGINTERN int SWIG_Lua_class_get(lua_State *L) { + /* there should be 2 params passed in + (1) userdata (not the meta table) + (2) string name of the attribute + */ + int result; + swig_lua_userdata *usr; + swig_type_info *type; + int ret = 0; + assert(lua_isuserdata(L, 1)); + usr = (swig_lua_userdata *)lua_touserdata(L, 1); /* get data */ + type = usr->type; + result = SWIG_Lua_class_do_get(L, type, 1, &ret); + if (result == SWIG_OK) + return ret; - result = SWIG_Lua_class_do_get_item(L,type,1,&ret); - if(result == SWIG_OK) - return ret; + result = SWIG_Lua_class_do_get_item(L, type, 1, &ret); + if (result == SWIG_OK) + return ret; - return 0; + return 0; } /* helper for the class.set method, performs the lookup of class attributes * It returns error code. Number of function return values is passed inside 'ret' */ -SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret) -{ -/* there should be 3 params passed in - (1) table (not the meta table) - (2) string name of the attribute - (3) any for the new value - */ +SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret) { + /* there should be 3 params passed in + (1) table (not the meta table) + (2) string name of the attribute + (3) any for the new value + */ - int bases_search_result; - int substack_start = lua_gettop(L) - 3; - lua_checkstack(L,5); - assert(lua_isuserdata(L,substack_start+1)); /* just in case */ - lua_getmetatable(L,substack_start+1); /* get the meta table */ - assert(lua_istable(L,-1)); /* just in case */ - if(ret) - *ret = 0; /* it is setter - number of return values is always 0 */ + int bases_search_result; + int substack_start = lua_gettop(L) - 3; + lua_checkstack(L, 5); + assert(lua_isuserdata(L, substack_start + 1)); /* just in case */ + lua_getmetatable(L, substack_start + 1); /* get the meta table */ + assert(lua_istable(L, -1)); /* just in case */ + if (ret) + *ret = 0; /* it is setter - number of return values is always 0 */ - SWIG_Lua_get_table(L,".set"); /* find the .set table */ - if (lua_istable(L,-1)) - { - /* look for the key in the .set table */ - lua_pushvalue(L,substack_start+2); /* key */ - lua_rawget(L,-2); - lua_remove(L,-2); /* tidy stack, remove .set table */ - if (lua_iscfunction(L,-1)) - { /* found it so call the fn & return its value */ - lua_pushvalue(L,substack_start+1); /* userdata */ - lua_pushvalue(L,substack_start+3); /* value */ - lua_call(L,2,0); - lua_remove(L,substack_start+4); /*remove metatable*/ - return SWIG_OK; + SWIG_Lua_get_table(L, ".set"); /* find the .set table */ + if (lua_istable(L, -1)) { + /* look for the key in the .set table */ + lua_pushvalue(L, substack_start + 2); /* key */ + lua_rawget(L, -2); + lua_remove(L, -2); /* tidy stack, remove .set table */ + if (lua_iscfunction(L, -1)) { + /* found it so call the fn & return its value */ + lua_pushvalue(L, substack_start + 1); /* userdata */ + lua_pushvalue(L, substack_start + 3); /* value */ + lua_call(L, 2, 0); + lua_remove(L, substack_start + 4); /*remove metatable*/ + return SWIG_OK; + } + lua_pop(L, 1); /* remove the value */ + } else { + lua_pop(L, 1); /* remove the answer for .set table request*/ } - lua_pop(L,1); /* remove the value */ - } else { - lua_pop(L,1); /* remove the answer for .set table request*/ - } - /* NEW: looks for the __setitem() fn - this is a user provided set fn */ - SWIG_Lua_get_table(L,"__setitem"); /* find the fn */ - if (lua_iscfunction(L,-1)) /* if its there */ - { /* found it so call the fn & return its value */ - lua_pushvalue(L,substack_start+1); /* the userdata */ - lua_pushvalue(L,substack_start+2); /* the parameter */ - lua_pushvalue(L,substack_start+3); /* the value */ - lua_call(L,3,0); /* 3 values in ,0 out */ - lua_remove(L,-2); /* stack tidy, remove metatable */ - return SWIG_OK; - } - lua_pop(L,1); /* remove value */ + /* NEW: looks for the __setitem() fn + this is a user provided set fn */ + SWIG_Lua_get_table(L, "__setitem"); /* find the fn */ + if (lua_iscfunction(L, -1)) { /* if its there */ + /* found it so call the fn & return its value */ + lua_pushvalue(L, substack_start + 1); /* the userdata */ + lua_pushvalue(L, substack_start + 2); /* the parameter */ + lua_pushvalue(L, substack_start + 3); /* the value */ + lua_call(L, 3, 0); /* 3 values in ,0 out */ + lua_remove(L, -2); /* stack tidy, remove metatable */ + return SWIG_OK; + } + lua_pop(L, 1); /* remove value */ - lua_pop(L,1); /* remove metatable */ - /* Search among bases */ - bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret); - if(ret) - assert(*ret == 0); - assert(lua_gettop(L) == substack_start + 3); - return bases_search_result; + lua_pop(L, 1); /* remove metatable */ + /* Search among bases */ + bases_search_result = SWIG_Lua_iterate_bases(L, type, first_arg, SWIG_Lua_class_do_set, ret); + if (ret) + assert(*ret == 0); + assert(lua_gettop(L) == substack_start + 3); + return bases_search_result; } /* This is the actual method exported to Lua. It calls SWIG_Lua_class_do_set and correctly * handles return values. */ -SWIGINTERN int SWIG_Lua_class_set(lua_State *L) -{ -/* There should be 3 params passed in - (1) table (not the meta table) - (2) string name of the attribute - (3) any for the new value - */ - int ret = 0; - int result; - swig_lua_userdata *usr; - swig_type_info *type; - assert(lua_isuserdata(L,1)); - usr=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */ - type = usr->type; - result = SWIG_Lua_class_do_set(L,type,1,&ret); - if(result != SWIG_OK) { - SWIG_Lua_pushferrstring(L,"Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method."); - lua_error(L); - } else { - assert(ret==0); - } - return 0; +SWIGINTERN int SWIG_Lua_class_set(lua_State *L) { + /* There should be 3 params passed in + (1) table (not the meta table) + (2) string name of the attribute + (3) any for the new value + */ + int ret = 0; + int result; + swig_lua_userdata *usr; + swig_type_info *type; + assert(lua_isuserdata(L, 1)); + usr = (swig_lua_userdata *)lua_touserdata(L, 1); /* get data */ + type = usr->type; + result = SWIG_Lua_class_do_set(L, type, 1, &ret); + if (result != SWIG_OK) { + SWIG_Lua_pushferrstring(L, "Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method."); + lua_error(L); + } else { + assert(ret == 0); + } + return 0; } /* the class.destruct method called by the interpreter */ -SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L) -{ -/* there should be 1 params passed in - (1) userdata (not the meta table) */ - swig_lua_userdata *usr; - swig_lua_class *clss; - assert(lua_isuserdata(L,-1)); /* just in case */ - usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */ - /* if must be destroyed & has a destructor */ - if (usr->own) /* if must be destroyed */ - { - clss=(swig_lua_class*)usr->type->clientdata; /* get the class */ - if (clss && clss->destructor) /* there is a destroy fn */ - { - clss->destructor(usr->ptr); /* bye bye */ +SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L) { + /* there should be 1 params passed in + (1) userdata (not the meta table) */ + swig_lua_userdata *usr; + swig_lua_class *clss; + assert(lua_isuserdata(L, -1)); /* just in case */ + usr = (swig_lua_userdata *)lua_touserdata(L, -1); /* get it */ + /* if must be destroyed & has a destructor */ + if (usr->own) { /* if must be destroyed */ + clss = (swig_lua_class *)usr->type->clientdata; /* get the class */ + if (clss && clss->destructor) { /* there is a destroy fn */ + clss->destructor(usr->ptr); /* bye bye */ + } } - } - return 0; + return 0; } /* the class.__tostring method called by the interpreter and print */ -SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L) -{ -/* there should be 1 param passed in - (1) userdata (not the metatable) */ - swig_lua_userdata* userData; - assert(lua_isuserdata(L,1)); /* just in case */ - userData = (swig_lua_userdata*)lua_touserdata(L,1); /* get the userdata address */ +SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L) { + /* there should be 1 param passed in + (1) userdata (not the metatable) */ + swig_lua_userdata *userData; + assert(lua_isuserdata(L, 1)); /* just in case */ + userData = (swig_lua_userdata *)lua_touserdata(L, 1); /* get the userdata address */ - lua_pushfstring(L, "", userData->type->str, userData->ptr); - return 1; + lua_pushfstring(L, "", userData->type->str, userData->ptr); + return 1; } /* to manually disown some userdata */ -SWIGINTERN int SWIG_Lua_class_disown(lua_State *L) -{ -/* there should be 1 params passed in - (1) userdata (not the meta table) */ - swig_lua_userdata *usr; - assert(lua_isuserdata(L,-1)); /* just in case */ - usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */ +SWIGINTERN int SWIG_Lua_class_disown(lua_State *L) { + /* there should be 1 params passed in + (1) userdata (not the meta table) */ + swig_lua_userdata *usr; + assert(lua_isuserdata(L, -1)); /* just in case */ + usr = (swig_lua_userdata *)lua_touserdata(L, -1); /* get it */ - usr->own = 0; /* clear our ownership */ - return 0; + usr->own = 0; /* clear our ownership */ + return 0; } /* lua callable function to compare userdata's value the issue is that two userdata may point to the same thing but to lua, they are different objects */ -SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L) -{ - int result; - swig_lua_userdata *usr1,*usr2; - if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2)) /* just in case */ - return 0; /* nil reply */ - usr1=(swig_lua_userdata*)lua_touserdata(L,1); /* get data */ - usr2=(swig_lua_userdata*)lua_touserdata(L,2); /* get data */ - /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/ - result=(usr1->ptr==usr2->ptr); - lua_pushboolean(L,result); - return 1; +SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L) { + int result; + swig_lua_userdata *usr1, *usr2; + if (!lua_isuserdata(L, 1) || !lua_isuserdata(L, 2)) /* just in case */ + return 0; /* nil reply */ + usr1 = (swig_lua_userdata *)lua_touserdata(L, 1); /* get data */ + usr2 = (swig_lua_userdata *)lua_touserdata(L, 2); /* get data */ + /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/ + result = (usr1->ptr == usr2->ptr); + lua_pushboolean(L, result); + return 1; } /* populate table at the top of the stack with metamethods that ought to be inherited */ -SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L) -{ - SWIG_Lua_add_boolean(L, "__add", 1); - SWIG_Lua_add_boolean(L, "__sub", 1); - SWIG_Lua_add_boolean(L, "__mul", 1); - SWIG_Lua_add_boolean(L, "__div", 1); - SWIG_Lua_add_boolean(L, "__mod", 1); - SWIG_Lua_add_boolean(L, "__pow", 1); - SWIG_Lua_add_boolean(L, "__unm", 1); - SWIG_Lua_add_boolean(L, "__len", 1 ); - SWIG_Lua_add_boolean(L, "__concat", 1 ); - SWIG_Lua_add_boolean(L, "__eq", 1); - SWIG_Lua_add_boolean(L, "__lt", 1); - SWIG_Lua_add_boolean(L, "__le", 1); - SWIG_Lua_add_boolean(L, "__call", 1); - SWIG_Lua_add_boolean(L, "__tostring", 1); - SWIG_Lua_add_boolean(L, "__gc", 0); +SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L) { + SWIG_Lua_add_boolean(L, "__add", 1); + SWIG_Lua_add_boolean(L, "__sub", 1); + SWIG_Lua_add_boolean(L, "__mul", 1); + SWIG_Lua_add_boolean(L, "__div", 1); + SWIG_Lua_add_boolean(L, "__mod", 1); + SWIG_Lua_add_boolean(L, "__pow", 1); + SWIG_Lua_add_boolean(L, "__unm", 1); + SWIG_Lua_add_boolean(L, "__len", 1); + SWIG_Lua_add_boolean(L, "__concat", 1); + SWIG_Lua_add_boolean(L, "__eq", 1); + SWIG_Lua_add_boolean(L, "__lt", 1); + SWIG_Lua_add_boolean(L, "__le", 1); + SWIG_Lua_add_boolean(L, "__call", 1); + SWIG_Lua_add_boolean(L, "__tostring", 1); + SWIG_Lua_add_boolean(L, "__gc", 0); } /* creates the swig registry */ -SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L) -{ - /* create main SWIG registry table */ - lua_pushstring(L,"SWIG"); - lua_newtable(L); - /* populate it with some predefined data */ - - /* .library table. Placeholder */ - lua_pushstring(L,".library"); - lua_newtable(L); - { - /* list of metamethods that class inherits from its bases */ - lua_pushstring(L,"inheritable_metamethods"); +SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L) { + /* create main SWIG registry table */ + lua_pushstring(L, "SWIG"); lua_newtable(L); - /* populate with list of metamethods */ - SWIG_Lua_populate_inheritable_metamethods(L); - lua_rawset(L,-3); - } - lua_rawset(L,-3); + /* populate it with some predefined data */ - lua_rawset(L,LUA_REGISTRYINDEX); + /* .library table. Placeholder */ + lua_pushstring(L, ".library"); + lua_newtable(L); + { + /* list of metamethods that class inherits from its bases */ + lua_pushstring(L, "inheritable_metamethods"); + lua_newtable(L); + /* populate with list of metamethods */ + SWIG_Lua_populate_inheritable_metamethods(L); + lua_rawset(L, -3); + } + lua_rawset(L, -3); + + lua_rawset(L, LUA_REGISTRYINDEX); } /* gets the swig registry (or creates it) */ -SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L) -{ - /* add this all into the swig registry: */ - lua_pushstring(L,"SWIG"); - lua_rawget(L,LUA_REGISTRYINDEX); /* get the registry */ - if (!lua_istable(L,-1)) /* not there */ - { /* must be first time, so add it */ - lua_pop(L,1); /* remove the result */ - SWIG_Lua_create_class_registry(L); - /* then get it */ - lua_pushstring(L,"SWIG"); - lua_rawget(L,LUA_REGISTRYINDEX); - } +SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L) { + /* add this all into the swig registry: */ + lua_pushstring(L, "SWIG"); + lua_rawget(L, LUA_REGISTRYINDEX); /* get the registry */ + if (!lua_istable(L, -1)) { /* not there */ + /* must be first time, so add it */ + lua_pop(L, 1); /* remove the result */ + SWIG_Lua_create_class_registry(L); + /* then get it */ + lua_pushstring(L, "SWIG"); + lua_rawget(L, LUA_REGISTRYINDEX); + } } -SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L) -{ - SWIG_Lua_get_class_registry(L); - lua_pushstring(L, ".library"); - lua_rawget(L,-2); - assert( !lua_isnil(L,-1) ); - lua_pushstring(L, "inheritable_metamethods"); - lua_rawget(L,-2); +SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L) { + SWIG_Lua_get_class_registry(L); + lua_pushstring(L, ".library"); + lua_rawget(L, -2); + assert(!lua_isnil(L, -1)); + lua_pushstring(L, "inheritable_metamethods"); + lua_rawget(L, -2); - /* Remove class registry and library table */ - lua_remove(L,-2); - lua_remove(L,-2); + /* Remove class registry and library table */ + lua_remove(L, -2); + lua_remove(L, -2); } /* Helper function to get the classes metatable from the register */ -SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname) -{ - SWIG_Lua_get_class_registry(L); /* get the registry */ - lua_pushstring(L,cname); /* get the name */ - lua_rawget(L,-2); /* get it */ - lua_remove(L,-2); /* tidy up (remove registry) */ +SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L, const char *cname) { + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L, cname); /* get the name */ + lua_rawget(L, -2); /* get it */ + lua_remove(L, -2); /* tidy up (remove registry) */ } /* Set up the base classes pointers. @@ -1900,165 +1866,151 @@ It cannot be done at compile time, as this will not work with hireachies spread over more than one swig file. Therefore it must be done at runtime, querying the SWIG type system. */ -SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss) -{ - int i=0; - swig_module_info *module=SWIG_GetModule(L); - for(i=0;clss->base_names[i];i++) - { - if (clss->bases[i]==0) /* not found yet */ - { - /* lookup and cache the base class */ - swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]); - if (info) clss->bases[i] = (swig_lua_class *) info->clientdata; +SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L, swig_lua_class *clss) { + int i = 0; + swig_module_info *module = SWIG_GetModule(L); + for (i = 0; clss->base_names[i]; i++) { + if (clss->bases[i] == 0) { /* not found yet */ + /* lookup and cache the base class */ + swig_type_info *info = SWIG_TypeQueryModule(module, module, clss->base_names[i]); + if (info) clss->bases[i] = (swig_lua_class *) info->clientdata; + } } - } } #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* Merges two tables */ -SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source) -{ - /* iterating */ - lua_pushnil(L); - while (lua_next(L,source) != 0) { - /* -1 - value, -2 - index */ - /* have to copy to assign */ - lua_pushvalue(L,-2); /* copy of index */ - lua_pushvalue(L,-2); /* copy of value */ - lua_rawset(L, target); - lua_pop(L,1); - /* only key is left */ - } +SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source) { + /* iterating */ + lua_pushnil(L); + while (lua_next(L, source) != 0) { + /* -1 - value, -2 - index */ + /* have to copy to assign */ + lua_pushvalue(L, -2); /* copy of index */ + lua_pushvalue(L, -2); /* copy of value */ + lua_rawset(L, target); + lua_pop(L, 1); + /* only key is left */ + } } /* Merges two tables with given name. original - index of target metatable, base - index of source metatable */ -SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base) -{ - /* push original[name], then base[name] */ - lua_pushstring(L,name); - lua_rawget(L,original); - int original_table = lua_gettop(L); - lua_pushstring(L,name); - lua_rawget(L,base); - int base_table = lua_gettop(L); - SWIG_Lua_merge_tables_by_index(L, original_table, base_table); - /* clearing stack */ - lua_pop(L,2); +SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char *name, int original, int base) { + /* push original[name], then base[name] */ + lua_pushstring(L, name); + lua_rawget(L, original); + int original_table = lua_gettop(L); + lua_pushstring(L, name); + lua_rawget(L, base); + int base_table = lua_gettop(L); + SWIG_Lua_merge_tables_by_index(L, original_table, base_table); + /* clearing stack */ + lua_pop(L, 2); } /* Function takes all symbols from base and adds it to derived class. It's just a helper. */ -SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls) -{ - /* There is one parameter - original, i.e. 'derived' class metatable */ - assert(lua_istable(L,-1)); - int original = lua_gettop(L); - SWIG_Lua_get_class_metatable(L,base_cls->fqname); - int base = lua_gettop(L); - SWIG_Lua_merge_tables(L, ".fn", original, base ); - SWIG_Lua_merge_tables(L, ".set", original, base ); - SWIG_Lua_merge_tables(L, ".get", original, base ); - lua_pop(L,1); +SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls) { + /* There is one parameter - original, i.e. 'derived' class metatable */ + assert(lua_istable(L, -1)); + int original = lua_gettop(L); + SWIG_Lua_get_class_metatable(L, base_cls->fqname); + int base = lua_gettop(L); + SWIG_Lua_merge_tables(L, ".fn", original, base); + SWIG_Lua_merge_tables(L, ".set", original, base); + SWIG_Lua_merge_tables(L, ".get", original, base); + lua_pop(L, 1); } /* Function squashes all symbols from 'clss' bases into itself */ -SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) -{ - int i; - SWIG_Lua_get_class_metatable(L,clss->fqname); - for(i=0;clss->base_names[i];i++) - { - if (clss->bases[i]==0) /* Somehow it's not found. Skip it */ - continue; - /* Thing is: all bases are already registered. Thus they have already executed - * this function. So we just need to squash them into us, because their bases - * are already squashed into them. No need for recursion here! - */ - SWIG_Lua_class_squash_base(L, clss->bases[i]); - } - lua_pop(L,1); /*tidy stack*/ +SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) { + int i; + SWIG_Lua_get_class_metatable(L, clss->fqname); + for (i = 0; clss->base_names[i]; i++) { + if (clss->bases[i] == 0) /* Somehow it's not found. Skip it */ + continue; + /* Thing is: all bases are already registered. Thus they have already executed + * this function. So we just need to squash them into us, because their bases + * are already squashed into them. No need for recursion here! + */ + SWIG_Lua_class_squash_base(L, clss->bases[i]); + } + lua_pop(L, 1); /*tidy stack*/ } #endif #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */ /* helper add a variable to a registered class */ -SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn) -{ - assert(lua_istable(L,-1)); /* just in case */ - SWIG_Lua_get_table(L,".get"); /* find the .get table */ - assert(lua_istable(L,-1)); /* just in case */ - SWIG_Lua_add_function(L,name,getFn); - lua_pop(L,1); /* tidy stack (remove table) */ - if (setFn) - { - SWIG_Lua_get_table(L,".set"); /* find the .set table */ - assert(lua_istable(L,-1)); /* just in case */ - SWIG_Lua_add_function(L,name,setFn); - lua_pop(L,1); /* tidy stack (remove table) */ - } +SWIGINTERN void SWIG_Lua_add_variable(lua_State *L, const char *name, lua_CFunction getFn, lua_CFunction setFn) { + assert(lua_istable(L, -1)); /* just in case */ + SWIG_Lua_get_table(L, ".get"); /* find the .get table */ + assert(lua_istable(L, -1)); /* just in case */ + SWIG_Lua_add_function(L, name, getFn); + lua_pop(L, 1); /* tidy stack (remove table) */ + if (setFn) { + SWIG_Lua_get_table(L, ".set"); /* find the .set table */ + assert(lua_istable(L, -1)); /* just in case */ + SWIG_Lua_add_function(L, name, setFn); + lua_pop(L, 1); /* tidy stack (remove table) */ + } } /* helper to recursively add class static details (static attributes, operations and constants) */ -SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss) -{ - int i = 0; - /* The class namespace table must be on the top of the stack */ - assert(lua_istable(L,-1)); - /* call all the base classes first: we can then override these later: */ - for(i=0;clss->bases[i];i++) - { - SWIG_Lua_add_class_static_details(L,clss->bases[i]); - } +SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss) { + int i = 0; + /* The class namespace table must be on the top of the stack */ + assert(lua_istable(L, -1)); + /* call all the base classes first: we can then override these later: */ + for (i = 0; clss->bases[i]; i++) { + SWIG_Lua_add_class_static_details(L, clss->bases[i]); + } - SWIG_Lua_add_namespace_details(L, clss->cls_static); + SWIG_Lua_add_namespace_details(L, clss->cls_static); } SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss); /* forward declaration */ /* helper to recursively add class details (attributes & operations) */ -SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss) -{ - int i; - size_t bases_count = 0; - /* Add bases to .bases table */ - SWIG_Lua_get_table(L,".bases"); - assert(lua_istable(L,-1)); /* just in case */ - for(i=0;clss->bases[i];i++) - { - SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname); - /* Base class must be already registered */ - assert(lua_istable(L,-1)); - lua_rawseti(L,-2,i+1); /* In lua indexing starts from 1 */ - bases_count++; - } - assert(lua_rawlen(L,-1) == bases_count); - lua_pop(L,1); /* remove .bases table */ - /* add attributes */ - for(i=0;clss->attributes[i].name;i++){ - SWIG_Lua_add_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod); - } - /* add methods to the metatable */ - SWIG_Lua_get_table(L,".fn"); /* find the .fn table */ - assert(lua_istable(L,-1)); /* just in case */ - for(i=0;clss->methods[i].name;i++){ - SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func); - } - lua_pop(L,1); /* tidy stack (remove table) */ - /* add operator overloads - This adds methods from metatable array to metatable. Can mess up garbage - collectind if someone defines __gc method - */ - if(clss->metatable) { - for(i=0;clss->metatable[i].name;i++) { - SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func); +SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss) { + int i; + size_t bases_count = 0; + /* Add bases to .bases table */ + SWIG_Lua_get_table(L, ".bases"); + assert(lua_istable(L, -1)); /* just in case */ + for (i = 0; clss->bases[i]; i++) { + SWIG_Lua_get_class_metatable(L, clss->bases[i]->fqname); + /* Base class must be already registered */ + assert(lua_istable(L, -1)); + lua_rawseti(L, -2, i + 1); /* In lua indexing starts from 1 */ + bases_count++; + } + assert(lua_rawlen(L, -1) == bases_count); + lua_pop(L, 1); /* remove .bases table */ + /* add attributes */ + for (i = 0; clss->attributes[i].name; i++) { + SWIG_Lua_add_variable(L, clss->attributes[i].name, clss->attributes[i].getmethod, clss->attributes[i].setmethod); + } + /* add methods to the metatable */ + SWIG_Lua_get_table(L, ".fn"); /* find the .fn table */ + assert(lua_istable(L, -1)); /* just in case */ + for (i = 0; clss->methods[i].name; i++) { + SWIG_Lua_add_function(L, clss->methods[i].name, clss->methods[i].func); + } + lua_pop(L, 1); /* tidy stack (remove table) */ + /* add operator overloads + This adds methods from metatable array to metatable. Can mess up garbage + collectind if someone defines __gc method + */ + if (clss->metatable) { + for (i = 0; clss->metatable[i].name; i++) { + SWIG_Lua_add_function(L, clss->metatable[i].name, clss->metatable[i].func); + } } - } #if !defined(SWIG_LUA_SQUASH_BASES) - /* Adding metamethods that are defined in base classes. If bases were squashed - * then it is obviously unnecessary - */ - SWIG_Lua_add_class_user_metamethods(L, clss); + /* Adding metamethods that are defined in base classes. If bases were squashed + * then it is obviously unnecessary + */ + SWIG_Lua_add_class_user_metamethods(L, clss); #endif } @@ -2088,70 +2040,67 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration * SWIG_Lua_resolve_metamethod * */ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx, - int skip_check) -{ - /* This function is called recursively */ - int result = 0; - int i = 0; + int skip_check) { + /* This function is called recursively */ + int result = 0; + int i = 0; - if (!skip_check) { - SWIG_Lua_get_class_metatable(L, clss->fqname); - lua_pushvalue(L, metamethod_name_idx); - lua_rawget(L,-2); - /* If this is cfunction and it is equal to SWIG_Lua_resolve_metamethod then - * this isn't the function we are looking for :) - * lua_tocfunction will return NULL if not cfunction - */ - if (!lua_isnil(L,-1) && lua_tocfunction(L,-1) != SWIG_Lua_resolve_metamethod ) { - lua_remove(L,-2); /* removing class metatable */ - return 1; + if (!skip_check) { + SWIG_Lua_get_class_metatable(L, clss->fqname); + lua_pushvalue(L, metamethod_name_idx); + lua_rawget(L, -2); + /* If this is cfunction and it is equal to SWIG_Lua_resolve_metamethod then + * this isn't the function we are looking for :) + * lua_tocfunction will return NULL if not cfunction + */ + if (!lua_isnil(L, -1) && lua_tocfunction(L, -1) != SWIG_Lua_resolve_metamethod) { + lua_remove(L, -2); /* removing class metatable */ + return 1; + } + lua_pop(L, 2); /* remove class metatable and query result */ } - lua_pop(L,2); /* remove class metatable and query result */ - } - /* Forwarding calls to bases */ - for(i=0;clss->bases[i];i++) - { - result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0); - if (result) - break; - } + /* Forwarding calls to bases */ + for (i = 0; clss->bases[i]; i++) { + result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0); + if (result) + break; + } - return result; + return result; } /* The proxy function for metamethod. All parameters are passed as cclosure. Searches for actual method * and calls it */ -SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L) -{ - int numargs; - int metamethod_name_idx; - const swig_lua_class* clss; - int result; +SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L) { + int numargs; + int metamethod_name_idx; + const swig_lua_class *clss; + int result; - lua_checkstack(L,5); - numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */ + lua_checkstack(L, 5); + numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */ - /* Get upvalues from closure */ - lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/ - metamethod_name_idx = lua_gettop(L); + /* Get upvalues from closure */ + lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/ + metamethod_name_idx = lua_gettop(L); - lua_pushvalue(L, lua_upvalueindex(2)); - clss = (const swig_lua_class*)(lua_touserdata(L,-1)); - lua_pop(L,1); /* remove lightuserdata with clss from stack */ + lua_pushvalue(L, lua_upvalueindex(2)); + clss = (const swig_lua_class *)(lua_touserdata(L, -1)); + lua_pop(L, 1); /* remove lightuserdata with clss from stack */ - /* Actual work */ - result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1); - if (!result) { - SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actual metamethod. Memory corruption is most likely explanation."); - lua_error(L); - return 0; - } + /* Actual work */ + result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1); + if (!result) { + SWIG_Lua_pushferrstring(L, "The metamethod proxy is set, but it failed to find actual metamethod. Memory corruption is most likely explanation."); + lua_error(L); + return 0; + } - lua_remove(L,-2); /* remove metamethod key */ - lua_insert(L,1); /* move function to correct position */ - lua_call(L, numargs, LUA_MULTRET); - return lua_gettop(L); /* return all results */ + lua_remove(L, -2); /* remove metamethod key */ + lua_insert(L, 1); /* move function to correct position */ + lua_call(L, numargs, LUA_MULTRET); + return lua_gettop(L); /* return all results */ } @@ -2159,292 +2108,281 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L) * Returns 1 if successfully added, 0 if not added because no base class has it, -1 * if method is defined in the class metatable itself */ -SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index) -{ - int key_index; - int success = 0; - int i = 0; +SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index) { + int key_index; + int success = 0; + int i = 0; - /* metamethod name - on the top of the stack */ - assert(lua_isstring(L,-1)); + /* metamethod name - on the top of the stack */ + assert(lua_isstring(L, -1)); - key_index = lua_gettop(L); + key_index = lua_gettop(L); - /* Check whether method is already defined in metatable */ - lua_pushvalue(L,key_index); /* copy of the key */ - lua_gettable(L,metatable_index); - if( !lua_isnil(L,-1) ) { - lua_pop(L,1); - return -1; - } - lua_pop(L,1); - - /* Iterating over immediate bases */ - for(i=0;clss->bases[i];i++) - { - const swig_lua_class *base = clss->bases[i]; - SWIG_Lua_get_class_metatable(L, base->fqname); - lua_pushvalue(L, key_index); - lua_rawget(L, -2); - if( !lua_isnil(L,-1) ) { - lua_pushvalue(L, key_index); - - /* Add proxy function */ - lua_pushvalue(L, key_index); /* first closure value is function name */ - lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */ - lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2); - - lua_rawset(L, metatable_index); - success = 1; + /* Check whether method is already defined in metatable */ + lua_pushvalue(L, key_index); /* copy of the key */ + lua_gettable(L, metatable_index); + if (!lua_isnil(L, -1)) { + lua_pop(L, 1); + return -1; } - lua_pop(L,1); /* remove function or nil */ - lua_pop(L,1); /* remove base class metatable */ + lua_pop(L, 1); - if( success ) - break; - } + /* Iterating over immediate bases */ + for (i = 0; clss->bases[i]; i++) { + const swig_lua_class *base = clss->bases[i]; + SWIG_Lua_get_class_metatable(L, base->fqname); + lua_pushvalue(L, key_index); + lua_rawget(L, -2); + if (!lua_isnil(L, -1)) { + lua_pushvalue(L, key_index); - return success; + /* Add proxy function */ + lua_pushvalue(L, key_index); /* first closure value is function name */ + lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */ + lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2); + + lua_rawset(L, metatable_index); + success = 1; + } + lua_pop(L, 1); /* remove function or nil */ + lua_pop(L, 1); /* remove base class metatable */ + + if (success) + break; + } + + return success; } -SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss) -{ - int metatable_index; - int metamethods_info_index; - int tostring_undefined; - int eq_undefined = 0; +SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss) { + int metatable_index; + int metamethods_info_index; + int tostring_undefined; + int eq_undefined = 0; - SWIG_Lua_get_class_metatable(L, clss->fqname); - metatable_index = lua_gettop(L); - SWIG_Lua_get_inheritable_metamethods(L); - assert(lua_istable(L,-1)); - metamethods_info_index = lua_gettop(L); - lua_pushnil(L); /* first key */ - while(lua_next(L, metamethods_info_index) != 0 ) { - /* key at index -2, value at index -1 */ - const int is_inheritable = lua_toboolean(L,-2); - lua_pop(L,1); /* remove value - we don't need it anymore */ + SWIG_Lua_get_class_metatable(L, clss->fqname); + metatable_index = lua_gettop(L); + SWIG_Lua_get_inheritable_metamethods(L); + assert(lua_istable(L, -1)); + metamethods_info_index = lua_gettop(L); + lua_pushnil(L); /* first key */ + while (lua_next(L, metamethods_info_index) != 0) { + /* key at index -2, value at index -1 */ + const int is_inheritable = lua_toboolean(L, -2); + lua_pop(L, 1); /* remove value - we don't need it anymore */ - if(is_inheritable) { /* if metamethod is inheritable */ - SWIG_Lua_add_class_user_metamethod(L,clss,metatable_index); + if (is_inheritable) { /* if metamethod is inheritable */ + SWIG_Lua_add_class_user_metamethod(L, clss, metatable_index); + } } - } - lua_pop(L,1); /* remove inheritable metatmethods table */ + lua_pop(L, 1); /* remove inheritable metatmethods table */ - /* Special handling for __tostring method */ - lua_pushstring(L, "__tostring"); - lua_pushvalue(L,-1); - lua_rawget(L,metatable_index); - tostring_undefined = lua_isnil(L,-1); - lua_pop(L,1); - if( tostring_undefined ) { - lua_pushcfunction(L, SWIG_Lua_class_tostring); - lua_rawset(L, metatable_index); - } else { - lua_pop(L,1); /* remove copy of the key */ - } + /* Special handling for __tostring method */ + lua_pushstring(L, "__tostring"); + lua_pushvalue(L, -1); + lua_rawget(L, metatable_index); + tostring_undefined = lua_isnil(L, -1); + lua_pop(L, 1); + if (tostring_undefined) { + lua_pushcfunction(L, SWIG_Lua_class_tostring); + lua_rawset(L, metatable_index); + } else { + lua_pop(L, 1); /* remove copy of the key */ + } - /* Special handling for __eq method */ - lua_pushstring(L, "__eq"); - lua_pushvalue(L,-1); - lua_rawget(L,metatable_index); - eq_undefined = lua_isnil(L,-1); - lua_pop(L,1); - if( eq_undefined ) { - lua_pushcfunction(L, SWIG_Lua_class_equal); - lua_rawset(L, metatable_index); - } else { - lua_pop(L,1); /* remove copy of the key */ - } - /* Warning: __index and __newindex are SWIG-defined. For user-defined operator[] - * a __getitem/__setitem method should be defined - */ - lua_pop(L,1); /* pop class metatable */ + /* Special handling for __eq method */ + lua_pushstring(L, "__eq"); + lua_pushvalue(L, -1); + lua_rawget(L, metatable_index); + eq_undefined = lua_isnil(L, -1); + lua_pop(L, 1); + if (eq_undefined) { + lua_pushcfunction(L, SWIG_Lua_class_equal); + lua_rawset(L, metatable_index); + } else { + lua_pop(L, 1); /* remove copy of the key */ + } + /* Warning: __index and __newindex are SWIG-defined. For user-defined operator[] + * a __getitem/__setitem method should be defined + */ + lua_pop(L, 1); /* pop class metatable */ } /* Register class static methods,attributes etc as well as constructor proxy */ -SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss) -{ - const int SWIGUNUSED begin = lua_gettop(L); - lua_checkstack(L,5); /* just in case */ - assert(lua_istable(L,-1)); /* just in case */ - assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */ +SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss) { + const int SWIGUNUSED begin = lua_gettop(L); + lua_checkstack(L, 5); /* just in case */ + assert(lua_istable(L, -1)); /* just in case */ + assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */ - SWIG_Lua_namespace_register(L,clss->cls_static, 1); + SWIG_Lua_namespace_register(L, clss->cls_static, 1); - assert(lua_istable(L,-1)); /* just in case */ + assert(lua_istable(L, -1)); /* just in case */ - /* add its constructor to module with the name of the class - so you can do MyClass(...) as well as new_MyClass(...) - BUT only if a constructor is defined - (this overcomes the problem of pure virtual classes without constructors)*/ - if (clss->constructor) - { - lua_getmetatable(L,-1); - assert(lua_istable(L,-1)); /* just in case */ - SWIG_Lua_add_function(L,"__call", clss->constructor); - lua_pop(L,1); - } + /* add its constructor to module with the name of the class + so you can do MyClass(...) as well as new_MyClass(...) + BUT only if a constructor is defined + (this overcomes the problem of pure virtual classes without constructors)*/ + if (clss->constructor) { + lua_getmetatable(L, -1); + assert(lua_istable(L, -1)); /* just in case */ + SWIG_Lua_add_function(L, "__call", clss->constructor); + lua_pop(L, 1); + } - assert(lua_istable(L,-1)); /* just in case */ - SWIG_Lua_add_class_static_details(L, clss); + assert(lua_istable(L, -1)); /* just in case */ + SWIG_Lua_add_class_static_details(L, clss); - /* clear stack */ - lua_pop(L,1); - assert( lua_gettop(L) == begin ); + /* clear stack */ + lua_pop(L, 1); + assert(lua_gettop(L) == begin); } /* Performs the instance (non-static) class registration process. Metatable for class is created * and added to the class registry. */ -SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss) -{ - const int SWIGUNUSED begin = lua_gettop(L); - int i; - /* if name already there (class is already registered) then do nothing */ - SWIG_Lua_get_class_registry(L); /* get the registry */ - lua_pushstring(L,clss->fqname); /* get the name */ - lua_rawget(L,-2); - if(!lua_isnil(L,-1)) { - lua_pop(L,2); - assert(lua_gettop(L)==begin); - return; - } - lua_pop(L,2); /* tidy stack */ - /* Recursively initialize all bases */ - for(i=0;clss->bases[i];i++) - { - SWIG_Lua_class_register_instance(L,clss->bases[i]); - } - /* Again, get registry and push name */ - SWIG_Lua_get_class_registry(L); /* get the registry */ - lua_pushstring(L,clss->fqname); /* get the name */ - lua_newtable(L); /* create the metatable */ -#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) - /* If squashing is requested, then merges all bases metatable into this one. - * It would get us all special methods: __getitem, __add etc. - * This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away - */ - { - int new_metatable_index = lua_absindex(L,-1); - for(i=0;clss->bases[i];i++) - { - int base_metatable; - SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname); - base_metatable = lua_absindex(L,-1); - SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable); - lua_pop(L,1); +SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L, swig_lua_class *clss) { + const int SWIGUNUSED begin = lua_gettop(L); + int i; + /* if name already there (class is already registered) then do nothing */ + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L, clss->fqname); /* get the name */ + lua_rawget(L, -2); + if (!lua_isnil(L, -1)) { + lua_pop(L, 2); + assert(lua_gettop(L) == begin); + return; } - } - /* And now we will overwrite all incorrectly set data */ + lua_pop(L, 2); /* tidy stack */ + /* Recursively initialize all bases */ + for (i = 0; clss->bases[i]; i++) { + SWIG_Lua_class_register_instance(L, clss->bases[i]); + } + /* Again, get registry and push name */ + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L, clss->fqname); /* get the name */ + lua_newtable(L); /* create the metatable */ +#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) + /* If squashing is requested, then merges all bases metatable into this one. + * It would get us all special methods: __getitem, __add etc. + * This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away + */ + { + int new_metatable_index = lua_absindex(L, -1); + for (i = 0; clss->bases[i]; i++) { + int base_metatable; + SWIG_Lua_get_class_metatable(L, clss->bases[i]->fqname); + base_metatable = lua_absindex(L, -1); + SWIG_Lua_merge_tables_by_index(L, new_metatable_index, base_metatable); + lua_pop(L, 1); + } + } + /* And now we will overwrite all incorrectly set data */ #endif - /* add string of class name called ".type" */ - lua_pushstring(L,".type"); - lua_pushstring(L,clss->fqname); - lua_rawset(L,-3); - /* add a table called bases */ - lua_pushstring(L,".bases"); - lua_newtable(L); - lua_rawset(L,-3); - /* add a table called ".get" */ - lua_pushstring(L,".get"); - lua_newtable(L); - lua_rawset(L,-3); - /* add a table called ".set" */ - lua_pushstring(L,".set"); - lua_newtable(L); - lua_rawset(L,-3); - /* add a table called ".fn" */ - lua_pushstring(L,".fn"); - lua_newtable(L); - /* add manual disown method */ - SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown); - lua_rawset(L,-3); - /* add accessor fns for using the .get,.set&.fn */ - SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get); - SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set); - SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct); - /* add it */ - lua_rawset(L,-3); /* metatable into registry */ - lua_pop(L,1); /* tidy stack (remove registry) */ - assert(lua_gettop(L) == begin); + /* add string of class name called ".type" */ + lua_pushstring(L, ".type"); + lua_pushstring(L, clss->fqname); + lua_rawset(L, -3); + /* add a table called bases */ + lua_pushstring(L, ".bases"); + lua_newtable(L); + lua_rawset(L, -3); + /* add a table called ".get" */ + lua_pushstring(L, ".get"); + lua_newtable(L); + lua_rawset(L, -3); + /* add a table called ".set" */ + lua_pushstring(L, ".set"); + lua_newtable(L); + lua_rawset(L, -3); + /* add a table called ".fn" */ + lua_pushstring(L, ".fn"); + lua_newtable(L); + /* add manual disown method */ + SWIG_Lua_add_function(L, "__disown", SWIG_Lua_class_disown); + lua_rawset(L, -3); + /* add accessor fns for using the .get,.set&.fn */ + SWIG_Lua_add_function(L, "__index", SWIG_Lua_class_get); + SWIG_Lua_add_function(L, "__newindex", SWIG_Lua_class_set); + SWIG_Lua_add_function(L, "__gc", SWIG_Lua_class_destruct); + /* add it */ + lua_rawset(L, -3); /* metatable into registry */ + lua_pop(L, 1); /* tidy stack (remove registry) */ + assert(lua_gettop(L) == begin); #if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) - /* Now merge all symbols from .fn, .set, .get etc from bases to our tables */ - SWIG_Lua_class_squash_bases(L,clss); + /* Now merge all symbols from .fn, .set, .get etc from bases to our tables */ + SWIG_Lua_class_squash_bases(L, clss); #endif - SWIG_Lua_get_class_metatable(L,clss->fqname); - SWIG_Lua_add_class_instance_details(L,clss); /* recursive adding of details (atts & ops) */ - lua_pop(L,1); /* tidy stack (remove class metatable) */ - assert( lua_gettop(L) == begin ); + SWIG_Lua_get_class_metatable(L, clss->fqname); + SWIG_Lua_add_class_instance_details(L, clss); /* recursive adding of details (atts & ops) */ + lua_pop(L, 1); /* tidy stack (remove class metatable) */ + assert(lua_gettop(L) == begin); } -SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss) -{ - int SWIGUNUSED begin; - assert(lua_istable(L,-1)); /* This is a table (module or namespace) where classes will be added */ - SWIG_Lua_class_register_instance(L,clss); - SWIG_Lua_class_register_static(L,clss); +SWIGINTERN void SWIG_Lua_class_register(lua_State *L, swig_lua_class *clss) { + int SWIGUNUSED begin; + assert(lua_istable(L, -1)); /* This is a table (module or namespace) where classes will be added */ + SWIG_Lua_class_register_instance(L, clss); + SWIG_Lua_class_register_static(L, clss); - /* Add links from static part to instance part and vice versa */ - /* [SWIG registry] [Module] - * "MyClass" ----> [MyClass metatable] <===== "MyClass" -+> [static part] - * ".get" ----> ... | | getmetatable()----| - * ".set" ----> ... | | | - * ".static" --------------)----------------/ [static part metatable] - * | ".get" --> ... - * | ".set" --> .... - * |=============================== ".instance" - */ - begin = lua_gettop(L); - lua_pushstring(L,clss->cls_static->name); - lua_rawget(L,-2); /* get class static table */ - assert(lua_istable(L,-1)); - lua_getmetatable(L,-1); - assert(lua_istable(L,-1)); /* get class static metatable */ - lua_pushstring(L,".instance"); /* prepare key */ + /* Add links from static part to instance part and vice versa */ + /* [SWIG registry] [Module] + * "MyClass" ----> [MyClass metatable] <===== "MyClass" -+> [static part] + * ".get" ----> ... | | getmetatable()----| + * ".set" ----> ... | | | + * ".static" --------------)----------------/ [static part metatable] + * | ".get" --> ... + * | ".set" --> .... + * |=============================== ".instance" + */ + begin = lua_gettop(L); + lua_pushstring(L, clss->cls_static->name); + lua_rawget(L, -2); /* get class static table */ + assert(lua_istable(L, -1)); + lua_getmetatable(L, -1); + assert(lua_istable(L, -1)); /* get class static metatable */ + lua_pushstring(L, ".instance"); /* prepare key */ - SWIG_Lua_get_class_metatable(L,clss->fqname); /* get class metatable */ - assert(lua_istable(L,-1)); - lua_pushstring(L,".static"); /* prepare key */ - lua_pushvalue(L, -4); /* push static class TABLE */ - assert(lua_istable(L,-1)); - lua_rawset(L,-3); /* assign static class table(!NOT metatable) as ".static" member of class metatable */ - lua_rawset(L,-3); /* assign class metatable as ".instance" member of class static METATABLE */ - lua_pop(L,2); - assert(lua_gettop(L) == begin); + SWIG_Lua_get_class_metatable(L, clss->fqname); /* get class metatable */ + assert(lua_istable(L, -1)); + lua_pushstring(L, ".static"); /* prepare key */ + lua_pushvalue(L, -4); /* push static class TABLE */ + assert(lua_istable(L, -1)); + lua_rawset(L, -3); /* assign static class table(!NOT metatable) as ".static" member of class metatable */ + lua_rawset(L, -3); /* assign class metatable as ".instance" member of class static METATABLE */ + lua_pop(L, 2); + assert(lua_gettop(L) == begin); } #endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */ #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) -SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss) -{ - const int SWIGUNUSED begin = lua_gettop(L); - int i; - /* if name already there (class is already registered) then do nothing */ - SWIG_Lua_get_class_registry(L); /* get the registry */ - lua_pushstring(L,clss->fqname); /* get the name */ - lua_rawget(L,-2); - if(!lua_isnil(L,-1)) { - lua_pop(L,2); - assert(lua_gettop(L)==begin); - return; - } - lua_pop(L,2); /* tidy stack */ - /* Recursively initialize all bases */ - for(i=0;clss->bases[i];i++) - { - SWIG_Lua_elua_class_register_instance(L,clss->bases[i]); - } - /* Again, get registry and push name */ - SWIG_Lua_get_class_registry(L); /* get the registry */ - lua_pushstring(L,clss->fqname); /* get the name */ - assert(clss->metatable); - lua_pushrotable(L, (void*)(clss->metatable)); /* create the metatable */ - lua_rawset(L,-3); - lua_pop(L,1); - assert(lua_gettop(L) == begin); +SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss) { + const int SWIGUNUSED begin = lua_gettop(L); + int i; + /* if name already there (class is already registered) then do nothing */ + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L, clss->fqname); /* get the name */ + lua_rawget(L, -2); + if (!lua_isnil(L, -1)) { + lua_pop(L, 2); + assert(lua_gettop(L) == begin); + return; + } + lua_pop(L, 2); /* tidy stack */ + /* Recursively initialize all bases */ + for (i = 0; clss->bases[i]; i++) { + SWIG_Lua_elua_class_register_instance(L, clss->bases[i]); + } + /* Again, get registry and push name */ + SWIG_Lua_get_class_registry(L); /* get the registry */ + lua_pushstring(L, clss->fqname); /* get the name */ + assert(clss->metatable); + lua_pushrotable(L, (void *)(clss->metatable)); /* create the metatable */ + lua_rawset(L, -3); + lua_pop(L, 1); + assert(lua_gettop(L) == begin); } #endif /* elua && eluac */ @@ -2453,130 +2391,112 @@ SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_cla * ----------------------------------------------------------------------------- */ /* helper to add metatable to new lua object */ -SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L,swig_type_info *type) -{ - if (type->clientdata) /* there is clientdata: so add the metatable */ - { - SWIG_Lua_get_class_metatable(L,((swig_lua_class*)(type->clientdata))->fqname); - if (lua_istable(L,-1)) - { - lua_setmetatable(L,-2); +SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L, swig_type_info *type) { + if (type->clientdata) { /* there is clientdata: so add the metatable */ + SWIG_Lua_get_class_metatable(L, ((swig_lua_class *)(type->clientdata))->fqname); + if (lua_istable(L, -1)) { + lua_setmetatable(L, -2); + } else { + lua_pop(L, 1); + } } - else - { - lua_pop(L,1); - } - } } /* pushes a new object into the lua stack */ -SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own) -{ - swig_lua_userdata *usr; - if (!ptr){ - lua_pushnil(L); - return; - } - usr=(swig_lua_userdata*)lua_newuserdata(L,sizeof(swig_lua_userdata)); /* get data */ - usr->ptr=ptr; /* set the ptr */ - usr->type=type; - usr->own=own; +SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L, void *ptr, swig_type_info *type, int own) { + swig_lua_userdata *usr; + if (!ptr) { + lua_pushnil(L); + return; + } + usr = (swig_lua_userdata *)lua_newuserdata(L, sizeof(swig_lua_userdata)); /* get data */ + usr->ptr = ptr; /* set the ptr */ + usr->type = type; + usr->own = own; #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) - SWIG_Lua_AddMetatable(L,type); /* add metatable */ + SWIG_Lua_AddMetatable(L, type); /* add metatable */ #endif } /* takes a object from the lua stack & converts it into an object of the correct type (if possible) */ -SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type_info *type,int flags) -{ - swig_lua_userdata *usr; - swig_cast_info *cast; - /* special case: lua nil => NULL pointer */ - if (lua_isnil(L,index)) - { - *ptr=0; - return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; - } - usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */ - if (usr) - { - if (flags & SWIG_POINTER_DISOWN) /* must disown the object */ - { - usr->own=0; +SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L, int index, void **ptr, swig_type_info *type, int flags) { + swig_lua_userdata *usr; + swig_cast_info *cast; + /* special case: lua nil => NULL pointer */ + if (lua_isnil(L, index)) { + *ptr = 0; + return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } - if (!type) /* special cast void*, no casting fn */ - { - *ptr=usr->ptr; - return SWIG_OK; /* ok */ + usr = (swig_lua_userdata *)lua_touserdata(L, index); /* get data */ + if (usr) { + if (flags & SWIG_POINTER_DISOWN) { /* must disown the object */ + usr->own = 0; + } + if (!type) { /* special cast void*, no casting fn */ + *ptr = usr->ptr; + return SWIG_OK; /* ok */ + } + cast = SWIG_TypeCheckStruct(usr->type, type); /* performs normal type checking */ + if (cast) { + int newmemory = 0; + *ptr = SWIG_TypeCast(cast, usr->ptr, &newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + return SWIG_OK; /* ok */ + } } - cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */ - if (cast) - { - int newmemory = 0; - *ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - return SWIG_OK; /* ok */ - } - } - return SWIG_ERROR; /* error */ + return SWIG_ERROR; /* error */ } -SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags, - int argnum,const char *func_name){ - void *result; - if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){ - luaL_error (L,"Error in %s, expected a %s at argument number %d\n", - func_name,(type && type->str)?type->str:"void*",argnum); - } - return result; +SWIGRUNTIME void *SWIG_Lua_MustGetPtr(lua_State *L, int index, swig_type_info *type, int flags, + int argnum, const char *func_name) { + void *result; + if (!SWIG_IsOK(SWIG_ConvertPtr(L, index, &result, type, flags))) { + luaL_error(L, "Error in %s, expected a %s at argument number %d\n", + func_name, (type && type->str) ? type->str : "void*", argnum); + } + return result; } /* pushes a packed userdata. user for member fn pointers only */ -SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type) -{ - swig_lua_rawdata *raw; - assert(ptr); /* not acceptable to pass in a NULL value */ - raw=(swig_lua_rawdata*)lua_newuserdata(L,sizeof(swig_lua_rawdata)-1+size); /* alloc data */ - raw->type=type; - raw->own=0; - memcpy(raw->data,ptr,size); /* copy the data */ - SWIG_Lua_AddMetatable(L,type); /* add metatable */ +SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L, void *ptr, size_t size, swig_type_info *type) { + swig_lua_rawdata *raw; + assert(ptr); /* not acceptable to pass in a NULL value */ + raw = (swig_lua_rawdata *)lua_newuserdata(L, sizeof(swig_lua_rawdata) - 1 + size); /* alloc data */ + raw->type = type; + raw->own = 0; + memcpy(raw->data, ptr, size); /* copy the data */ + SWIG_Lua_AddMetatable(L, type); /* add metatable */ } /* converts a packed userdata. user for member fn pointers only */ -SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t size,swig_type_info *type) -{ - swig_lua_rawdata *raw; - raw=(swig_lua_rawdata*)lua_touserdata(L,index); /* get data */ - if (!raw) return SWIG_ERROR; /* error */ - if (type==0 || type==raw->type) /* void* or identical type */ - { - memcpy(ptr,raw->data,size); /* copy it */ - return SWIG_OK; /* ok */ - } - return SWIG_ERROR; /* error */ +SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L, int index, void *ptr, size_t size, swig_type_info *type) { + swig_lua_rawdata *raw; + raw = (swig_lua_rawdata *)lua_touserdata(L, index); /* get data */ + if (!raw) return SWIG_ERROR; /* error */ + if (type == 0 || type == raw->type) { /* void* or identical type */ + memcpy(ptr, raw->data, size); /* copy it */ + return SWIG_OK; /* ok */ + } + return SWIG_ERROR; /* error */ } /* a function to get the typestring of a piece of data */ -SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp) -{ - swig_lua_userdata *usr; - if (lua_isuserdata(L,tp)) - { - usr=(swig_lua_userdata*)lua_touserdata(L,tp); /* get data */ - if (usr && usr->type && usr->type->str) - return usr->type->str; - return "userdata (unknown type)"; - } - return lua_typename(L,lua_type(L,tp)); +SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp) { + swig_lua_userdata *usr; + if (lua_isuserdata(L, tp)) { + usr = (swig_lua_userdata *)lua_touserdata(L, tp); /* get data */ + if (usr && usr->type && usr->type->str) + return usr->type->str; + return "userdata (unknown type)"; + } + return lua_typename(L, lua_type(L, tp)); } /* lua callable function to get the userdata's type */ -SWIGRUNTIME int SWIG_Lua_type(lua_State *L) -{ - lua_pushstring(L,SWIG_Lua_typename(L,1)); - return 1; +SWIGRUNTIME int SWIG_Lua_type(lua_State *L) { + lua_pushstring(L, SWIG_Lua_typename(L, 1)); + return 1; } /* ----------------------------------------------------------------------------- @@ -2587,46 +2507,46 @@ SWIGRUNTIME int SWIG_Lua_type(lua_State *L) /* Install Constants */ SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) { - int i; - for (i = 0; constants[i].type; i++) { - switch(constants[i].type) { - case SWIG_LUA_INT: - lua_pushstring(L,constants[i].name); - lua_pushinteger(L,(lua_Integer)constants[i].lvalue); - lua_rawset(L,-3); - break; - case SWIG_LUA_FLOAT: - lua_pushstring(L,constants[i].name); - lua_pushnumber(L,(lua_Number)constants[i].dvalue); - lua_rawset(L,-3); - break; - case SWIG_LUA_CHAR: - lua_pushstring(L,constants[i].name); - { - char c = (char)constants[i].lvalue; - lua_pushlstring(L,&c,1); - } - lua_rawset(L,-3); - break; - case SWIG_LUA_STRING: - lua_pushstring(L,constants[i].name); - lua_pushstring(L,(char *) constants[i].pvalue); - lua_rawset(L,-3); - break; - case SWIG_LUA_POINTER: - lua_pushstring(L,constants[i].name); - SWIG_NewPointerObj(L,constants[i].pvalue, *(constants[i]).ptype,0); - lua_rawset(L,-3); - break; - case SWIG_LUA_BINARY: - lua_pushstring(L,constants[i].name); - SWIG_NewMemberObj(L,constants[i].pvalue,constants[i].lvalue,*(constants[i]).ptype); - lua_rawset(L,-3); - break; - default: - break; + int i; + for (i = 0; constants[i].type; i++) { + switch (constants[i].type) { + case SWIG_LUA_INT: + lua_pushstring(L, constants[i].name); + lua_pushinteger(L, (lua_Integer)constants[i].lvalue); + lua_rawset(L, -3); + break; + case SWIG_LUA_FLOAT: + lua_pushstring(L, constants[i].name); + lua_pushnumber(L, (lua_Number)constants[i].dvalue); + lua_rawset(L, -3); + break; + case SWIG_LUA_CHAR: + lua_pushstring(L, constants[i].name); + { + char c = (char)constants[i].lvalue; + lua_pushlstring(L, &c, 1); + } + lua_rawset(L, -3); + break; + case SWIG_LUA_STRING: + lua_pushstring(L, constants[i].name); + lua_pushstring(L, (char *) constants[i].pvalue); + lua_rawset(L, -3); + break; + case SWIG_LUA_POINTER: + lua_pushstring(L, constants[i].name); + SWIG_NewPointerObj(L, constants[i].pvalue, *(constants[i]).ptype, 0); + lua_rawset(L, -3); + break; + case SWIG_LUA_BINARY: + lua_pushstring(L, constants[i].name); + SWIG_NewMemberObj(L, constants[i].pvalue, constants[i].lvalue, *(constants[i]).ptype); + lua_rawset(L, -3); + break; + default: + break; + } } - } } #endif @@ -2644,19 +2564,19 @@ In lua 5.1.X it's luaL_dostring() */ SWIGINTERN int SWIG_Lua_dostring(lua_State *L, const char *str) { - int ok,top; - if (str==0 || str[0]==0) return 0; /* nothing to do */ - top=lua_gettop(L); /* save stack */ + int ok, top; + if (str == 0 || str[0] == 0) return 0; /* nothing to do */ + top = lua_gettop(L); /* save stack */ #if (defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM>=501)) - ok=luaL_dostring(L,str); /* looks like this is lua 5.1.X or later, good */ + ok = luaL_dostring(L, str); /* looks like this is lua 5.1.X or later, good */ #else - ok=lua_dostring(L,str); /* might be lua 5.0.x, using lua_dostring */ + ok = lua_dostring(L, str); /* might be lua 5.0.x, using lua_dostring */ #endif - if (ok!=0) { - SWIG_DOSTRING_FAIL(lua_tostring(L,-1)); - } - lua_settop(L,top); /* restore the stack */ - return ok; + if (ok != 0) { + SWIG_DOSTRING_FAIL(lua_tostring(L, -1)); + } + lua_settop(L, top); /* restore the stack */ + return ok; } #ifdef __cplusplus @@ -2686,187 +2606,192 @@ static swig_module_info swig_module = {swig_types, 1, 0, 0, 0, 0}; #include "pm3.h" #include "comms.h" -SWIGINTERN pm3 *new_pm3__SWIG_0(void){ +SWIGINTERN pm3 *new_pm3__SWIG_0(void) { // printf("SWIG pm3 constructor, get current pm3\n"); - pm3_device * p = pm3_get_current_dev(); - p->script_embedded = 1; - return p; - } - -SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) { - int ret = lua_isstring(L, idx); - if (!ret) - ret = lua_isnil(L, idx); - return ret; + pm3_device *p = pm3_get_current_dev(); + p->script_embedded = 1; + return p; } -SWIGINTERN pm3 *new_pm3__SWIG_1(char *port){ +SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) { + int ret = lua_isstring(L, idx); + if (!ret) + ret = lua_isnil(L, idx); + return ret; +} + +SWIGINTERN pm3 *new_pm3__SWIG_1(char *port) { // printf("SWIG pm3 constructor with port, open pm3\n"); - pm3_device * p = pm3_open(port); - p->script_embedded = 0; - return p; - } -SWIGINTERN void delete_pm3(pm3 *self){ - if (self->script_embedded) { + pm3_device *p = pm3_open(port); + p->script_embedded = 0; + return p; +} +SWIGINTERN void delete_pm3(pm3 *self) { + if (self->script_embedded) { // printf("SWIG pm3 destructor, nothing to do\n"); - } else { + } else { // printf("SWIG pm3 destructor, close pm3\n"); - pm3_close(self); - } - } + pm3_close(self); + } +} #ifdef __cplusplus extern "C" { #endif -static int _wrap_new_pm3__SWIG_0(lua_State* L) { - int SWIG_arg = 0; - pm3 *result = 0 ; - - SWIG_check_num_args("pm3::pm3",0,0) - result = (pm3 *)new_pm3__SWIG_0(); - SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3,1); SWIG_arg++; - return SWIG_arg; - - if(0) SWIG_fail; - +static int _wrap_new_pm3__SWIG_0(lua_State *L) { + int SWIG_arg = 0; + pm3 *result = 0 ; + + SWIG_check_num_args("pm3::pm3", 0, 0) + result = (pm3 *)new_pm3__SWIG_0(); + SWIG_NewPointerObj(L, result, SWIGTYPE_p_pm3, 1); + SWIG_arg++; + return SWIG_arg; + + if (0) SWIG_fail; + fail: - lua_error(L); - return SWIG_arg; + lua_error(L); + return SWIG_arg; } -static int _wrap_new_pm3__SWIG_1(lua_State* L) { - int SWIG_arg = 0; - char *arg1 = (char *) 0 ; - pm3 *result = 0 ; - - SWIG_check_num_args("pm3::pm3",1,1) - if(!SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("pm3::pm3",1,"char *"); - arg1 = (char *)lua_tostring(L, 1); - result = (pm3 *)new_pm3__SWIG_1(arg1); - SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3,1); SWIG_arg++; - return SWIG_arg; - - if(0) SWIG_fail; - +static int _wrap_new_pm3__SWIG_1(lua_State *L) { + int SWIG_arg = 0; + char *arg1 = (char *) 0 ; + pm3 *result = 0 ; + + SWIG_check_num_args("pm3::pm3", 1, 1) + if (!SWIG_lua_isnilstring(L, 1)) SWIG_fail_arg("pm3::pm3", 1, "char *"); + arg1 = (char *)lua_tostring(L, 1); + result = (pm3 *)new_pm3__SWIG_1(arg1); + SWIG_NewPointerObj(L, result, SWIGTYPE_p_pm3, 1); + SWIG_arg++; + return SWIG_arg; + + if (0) SWIG_fail; + fail: - lua_error(L); - return SWIG_arg; + lua_error(L); + return SWIG_arg; } -static int _wrap_new_pm3(lua_State* L) { - int argc; - int argv[2]={ - 1,2 - }; - - argc = lua_gettop(L); - if (argc == 0) { - return _wrap_new_pm3__SWIG_0(L); - } - if (argc == 1) { - int _v; - { - _v = SWIG_lua_isnilstring(L,argv[0]); +static int _wrap_new_pm3(lua_State *L) { + int argc; + int argv[2] = { + 1, 2 + }; + + argc = lua_gettop(L); + if (argc == 0) { + return _wrap_new_pm3__SWIG_0(L); } - if (_v) { - return _wrap_new_pm3__SWIG_1(L); + if (argc == 1) { + int _v; + { + _v = SWIG_lua_isnilstring(L, argv[0]); + } + if (_v) { + return _wrap_new_pm3__SWIG_1(L); + } } - } - - SWIG_Lua_pusherrstring(L,"Wrong arguments for overloaded function 'new_pm3'\n" - " Possible C/C++ prototypes are:\n" - " pm3::pm3()\n" - " pm3::pm3(char *)\n"); - lua_error(L);return 0; + + SWIG_Lua_pusherrstring(L, "Wrong arguments for overloaded function 'new_pm3'\n" + " Possible C/C++ prototypes are:\n" + " pm3::pm3()\n" + " pm3::pm3(char *)\n"); + lua_error(L); + return 0; } -static int _wrap_pm3_console(lua_State* L) { - int SWIG_arg = 0; - pm3 *arg1 = (pm3 *) 0 ; - char *arg2 = (char *) 0 ; - int result; - - SWIG_check_num_args("pm3::console",2,2) - if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3::console",1,"pm3 *"); - if(!SWIG_lua_isnilstring(L,2)) SWIG_fail_arg("pm3::console",2,"char *"); - - if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_pm3,0))){ - SWIG_fail_ptr("pm3_console",1,SWIGTYPE_p_pm3); - } - - arg2 = (char *)lua_tostring(L, 2); - result = (int)pm3_console(arg1,arg2); - lua_pushnumber(L, (lua_Number) result); SWIG_arg++; - return SWIG_arg; - - if(0) SWIG_fail; - +static int _wrap_pm3_console(lua_State *L) { + int SWIG_arg = 0; + pm3 *arg1 = (pm3 *) 0 ; + char *arg2 = (char *) 0 ; + int result; + + SWIG_check_num_args("pm3::console", 2, 2) + if (!SWIG_isptrtype(L, 1)) SWIG_fail_arg("pm3::console", 1, "pm3 *"); + if (!SWIG_lua_isnilstring(L, 2)) SWIG_fail_arg("pm3::console", 2, "char *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L, 1, (void **)&arg1, SWIGTYPE_p_pm3, 0))) { + SWIG_fail_ptr("pm3_console", 1, SWIGTYPE_p_pm3); + } + + arg2 = (char *)lua_tostring(L, 2); + result = (int)pm3_console(arg1, arg2); + lua_pushnumber(L, (lua_Number) result); + SWIG_arg++; + return SWIG_arg; + + if (0) SWIG_fail; + fail: - lua_error(L); - return SWIG_arg; + lua_error(L); + return SWIG_arg; } -static int _wrap_pm3_name_get(lua_State* L) { - int SWIG_arg = 0; - pm3 *arg1 = (pm3 *) 0 ; - char *result = 0 ; - - SWIG_check_num_args("pm3::name",1,1) - if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("pm3::name",1,"pm3 *"); - - if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_pm3,0))){ - SWIG_fail_ptr("pm3_name_get",1,SWIGTYPE_p_pm3); - } - - result = (char *)pm3_name_get(arg1); - lua_pushstring(L,(const char *)result); SWIG_arg++; - return SWIG_arg; - - if(0) SWIG_fail; - +static int _wrap_pm3_name_get(lua_State *L) { + int SWIG_arg = 0; + pm3 *arg1 = (pm3 *) 0 ; + char *result = 0 ; + + SWIG_check_num_args("pm3::name", 1, 1) + if (!SWIG_isptrtype(L, 1)) SWIG_fail_arg("pm3::name", 1, "pm3 *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L, 1, (void **)&arg1, SWIGTYPE_p_pm3, 0))) { + SWIG_fail_ptr("pm3_name_get", 1, SWIGTYPE_p_pm3); + } + + result = (char *)pm3_name_get(arg1); + lua_pushstring(L, (const char *)result); + SWIG_arg++; + return SWIG_arg; + + if (0) SWIG_fail; + fail: - lua_error(L); - return SWIG_arg; + lua_error(L); + return SWIG_arg; } static void swig_delete_pm3(void *obj) { -pm3 *arg1 = (pm3 *) obj; -delete_pm3(arg1); + pm3 *arg1 = (pm3 *) obj; + delete_pm3(arg1); } static int _proxy__wrap_new_pm3(lua_State *L) { - assert(lua_istable(L,1)); - lua_pushcfunction(L,_wrap_new_pm3); - assert(!lua_isnil(L,-1)); - lua_replace(L,1); /* replace our table with real constructor */ - lua_call(L,lua_gettop(L)-1,1); + assert(lua_istable(L, 1)); + lua_pushcfunction(L, _wrap_new_pm3); + assert(!lua_isnil(L, -1)); + lua_replace(L, 1); /* replace our table with real constructor */ + lua_call(L, lua_gettop(L) - 1, 1); return 1; } static swig_lua_attribute swig_pm3_attributes[] = { { "name", _wrap_pm3_name_get, SWIG_Lua_set_immutable }, - {0,0,0} + {0, 0, 0} }; -static swig_lua_method swig_pm3_methods[]= { +static swig_lua_method swig_pm3_methods[] = { { "console", _wrap_pm3_console}, - {0,0} + {0, 0} }; static swig_lua_method swig_pm3_meta[] = { - {0,0} + {0, 0} }; static swig_lua_attribute swig_pm3_Sf_SwigStatic_attributes[] = { - {0,0,0} + {0, 0, 0} }; -static swig_lua_const_info swig_pm3_Sf_SwigStatic_constants[]= { - {0,0,0,0,0,0} +static swig_lua_const_info swig_pm3_Sf_SwigStatic_constants[] = { + {0, 0, 0, 0, 0, 0} }; -static swig_lua_method swig_pm3_Sf_SwigStatic_methods[]= { - {0,0} +static swig_lua_method swig_pm3_Sf_SwigStatic_methods[] = { + {0, 0} }; -static swig_lua_class* swig_pm3_Sf_SwigStatic_classes[]= { +static swig_lua_class *swig_pm3_Sf_SwigStatic_classes[] = { 0 }; @@ -2880,22 +2805,22 @@ static swig_lua_namespace swig_pm3_Sf_SwigStatic = { }; static swig_lua_class *swig_pm3_bases[] = {0}; static const char *swig_pm3_base_names[] = {0}; -static swig_lua_class _wrap_class_pm3 = { "pm3", "pm3", &SWIGTYPE_p_pm3,_proxy__wrap_new_pm3, swig_delete_pm3, swig_pm3_methods, swig_pm3_attributes, &swig_pm3_Sf_SwigStatic, swig_pm3_meta, swig_pm3_bases, swig_pm3_base_names }; +static swig_lua_class _wrap_class_pm3 = { "pm3", "pm3", &SWIGTYPE_p_pm3, _proxy__wrap_new_pm3, swig_delete_pm3, swig_pm3_methods, swig_pm3_attributes, &swig_pm3_Sf_SwigStatic, swig_pm3_meta, swig_pm3_bases, swig_pm3_base_names }; static swig_lua_attribute swig_SwigModule_attributes[] = { - {0,0,0} + {0, 0, 0} }; -static swig_lua_const_info swig_SwigModule_constants[]= { - {0,0,0,0,0,0} +static swig_lua_const_info swig_SwigModule_constants[] = { + {0, 0, 0, 0, 0, 0} }; -static swig_lua_method swig_SwigModule_methods[]= { - {0,0} +static swig_lua_method swig_SwigModule_methods[] = { + {0, 0} }; -static swig_lua_class* swig_SwigModule_classes[]= { -&_wrap_class_pm3, +static swig_lua_class *swig_SwigModule_classes[] = { + &_wrap_class_pm3, 0 }; -static swig_lua_namespace* swig_SwigModule_namespaces[] = { +static swig_lua_namespace *swig_SwigModule_namespaces[] = { 0 }; @@ -2913,16 +2838,16 @@ static swig_lua_namespace swig_SwigModule = { /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ -static swig_type_info _swigt__p_pm3 = {"_p_pm3", "pm3 *", 0, 0, (void*)&_wrap_class_pm3, 0}; +static swig_type_info _swigt__p_pm3 = {"_p_pm3", "pm3 *", 0, 0, (void *) &_wrap_class_pm3, 0}; static swig_type_info *swig_type_initial[] = { - &_swigt__p_pm3, + &_swigt__p_pm3, }; -static swig_cast_info _swigc__p_pm3[] = { {&_swigt__p_pm3, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_pm3[] = { {&_swigt__p_pm3, 0, 0, 0}, {0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { - _swigc__p_pm3, + _swigc__p_pm3, }; @@ -2983,144 +2908,144 @@ extern "C" { SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { - size_t i; - swig_module_info *module_head, *iter; - int init; + size_t i; + swig_module_info *module_head, *iter; + int init; - /* check to see if the circular list has been setup, if not, set it up */ - if (swig_module.next==0) { - /* Initialize the swig_module */ - swig_module.type_initial = swig_type_initial; - swig_module.cast_initial = swig_cast_initial; - swig_module.next = &swig_module; - init = 1; - } else { - init = 0; - } - - /* Try and load any already created modules */ - module_head = SWIG_GetModule(clientdata); - if (!module_head) { - /* This is the first module loaded for this interpreter */ - /* so set the swig module into the interpreter */ - SWIG_SetModule(clientdata, &swig_module); - } else { - /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - iter=module_head; - do { - if (iter==&swig_module) { - /* Our module is already in the list, so there's nothing more to do. */ - return; - } - iter=iter->next; - } while (iter!= module_head); - - /* otherwise we must add our module into the list */ - swig_module.next = module_head->next; - module_head->next = &swig_module; - } - - /* When multiple interpreters are used, a module could have already been initialized in - a different interpreter, but not yet have a pointer in this interpreter. - In this case, we do not want to continue adding types... everything should be - set up already */ - if (init == 0) return; - - /* Now work on filling in swig_module.types */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); -#endif - for (i = 0; i < swig_module.size; ++i) { - swig_type_info *type = 0; - swig_type_info *ret; - swig_cast_info *cast; - -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); -#endif - - /* if there is another module already loaded */ - if (swig_module.next != &swig_module) { - type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); - } - if (type) { - /* Overwrite clientdata field */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found type %s\n", type->name); -#endif - if (swig_module.type_initial[i]->clientdata) { - type->clientdata = swig_module.type_initial[i]->clientdata; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); -#endif - } + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next == 0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + init = 1; } else { - type = swig_module.type_initial[i]; + init = 0; } - /* Insert casting types */ - cast = swig_module.cast_initial[i]; - while (cast->type) { + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + iter = module_head; + do { + if (iter == &swig_module) { + /* Our module is already in the list, so there's nothing more to do. */ + return; + } + iter = iter->next; + } while (iter != module_head); - /* Don't need to add information already in the list */ - ret = 0; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); -#endif - if (swig_module.next != &swig_module) { - ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); -#ifdef SWIGRUNTIME_DEBUG - if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); -#endif - } - if (ret) { - if (type == swig_module.type_initial[i]) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: skip old type %s\n", ret->name); -#endif - cast->type = ret; - ret = 0; - } else { - /* Check for casting already in the list */ - swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); -#ifdef SWIGRUNTIME_DEBUG - if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); -#endif - if (!ocast) ret = 0; - } - } + /* otherwise we must add our module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } - if (!ret) { + /* When multiple interpreters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + + /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); + printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); #endif - if (type->cast) { - type->cast->prev = cast; - cast->next = type->cast; + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); +#endif + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); } - type->cast = cast; - } - cast++; + if (type) { + /* Overwrite clientdata field */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found type %s\n", type->name); +#endif + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } + } else { + type = swig_module.type_initial[i]; + } + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + + /* Don't need to add information already in the list */ + ret = 0; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); +#endif + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); +#ifdef SWIGRUNTIME_DEBUG + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; } - /* Set entry in modules->types array equal to the type */ - swig_module.types[i] = type; - } - swig_module.types[i] = 0; + swig_module.types[i] = 0; #ifdef SWIGRUNTIME_DEBUG - printf("**** SWIG_InitializeModule: Cast List ******\n"); - for (i = 0; i < swig_module.size; ++i) { - int j = 0; - swig_cast_info *cast = swig_module.cast_initial[i]; - printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); - while (cast->type) { - printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); - cast++; - ++j; + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n", j); } - printf("---- Total casts: %d\n",j); - } - printf("**** SWIG_InitializeModule: Cast List ******\n"); + printf("**** SWIG_InitializeModule: Cast List ******\n"); #endif } @@ -3131,30 +3056,31 @@ SWIG_InitializeModule(void *clientdata) { */ SWIGRUNTIME void SWIG_PropagateClientData(void) { - size_t i; - swig_cast_info *equiv; - static int init_run = 0; + size_t i; + swig_cast_info *equiv; + static int init_run = 0; - if (init_run) return; - init_run = 1; + if (init_run) return; + init_run = 1; - for (i = 0; i < swig_module.size; i++) { - if (swig_module.types[i]->clientdata) { - equiv = swig_module.types[i]->cast; - while (equiv) { - if (!equiv->converter) { - if (equiv->type && !equiv->type->clientdata) - SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } } - equiv = equiv->next; - } } - } } #ifdef __cplusplus #if 0 -{ /* c-mode */ +{ + /* c-mode */ #endif } #endif @@ -3162,8 +3088,8 @@ SWIG_PropagateClientData(void) { /* Forward declaration of where the user's %init{} gets inserted */ -void SWIG_init_user(lua_State* L ); - +void SWIG_init_user(lua_State *L); + #ifdef __cplusplus extern "C" { #endif @@ -3172,74 +3098,74 @@ extern "C" { the function is always called SWIG_init, but an earlier #define will rename it */ #if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)) -LUALIB_API int SWIG_init(lua_State* L) +LUALIB_API int SWIG_init(lua_State *L) #else -SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ +SWIGEXPORT int SWIG_init(lua_State *L) /* default Lua action */ #endif { #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */ - int i; - int globalRegister = 0; - /* start with global table */ - lua_pushglobaltable (L); - /* SWIG's internal initialisation */ - SWIG_InitializeModule((void*)L); - SWIG_PropagateClientData(); + int i; + int globalRegister = 0; + /* start with global table */ + lua_pushglobaltable(L); + /* SWIG's internal initialisation */ + SWIG_InitializeModule((void *)L); + SWIG_PropagateClientData(); #endif #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) || defined(SWIG_LUA_ELUA_EMULATE) - /* add a global fn */ - SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type); - SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_class_equal); + /* add a global fn */ + SWIG_Lua_add_function(L, "swig_type", SWIG_Lua_type); + SWIG_Lua_add_function(L, "swig_equals", SWIG_Lua_class_equal); #endif #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) - /* set up base class pointers (the hierarchy) */ - for (i = 0; swig_types[i]; i++){ - if (swig_types[i]->clientdata){ - SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata)); + /* set up base class pointers (the hierarchy) */ + for (i = 0; swig_types[i]; i++) { + if (swig_types[i]->clientdata) { + SWIG_Lua_init_base_class(L, (swig_lua_class *)(swig_types[i]->clientdata)); + } } - } #ifdef SWIG_LUA_MODULE_GLOBAL - globalRegister = 1; + globalRegister = 1; #endif #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) - SWIG_Lua_namespace_register(L,&swig_SwigModule, globalRegister); + SWIG_Lua_namespace_register(L, &swig_SwigModule, globalRegister); #endif #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC) - for (i = 0; swig_types[i]; i++){ - if (swig_types[i]->clientdata){ - SWIG_Lua_elua_class_register_instance(L,(swig_lua_class*)(swig_types[i]->clientdata)); + for (i = 0; swig_types[i]; i++) { + if (swig_types[i]->clientdata) { + SWIG_Lua_elua_class_register_instance(L, (swig_lua_class *)(swig_types[i]->clientdata)); + } } - } #endif #if defined(SWIG_LUA_ELUA_EMULATE) - lua_newtable(L); - SWIG_Lua_elua_emulate_register(L,swig_SwigModule.ns_methods); - SWIG_Lua_elua_emulate_register_clear(L); - if(globalRegister) { - lua_pushstring(L,swig_SwigModule.name); - lua_pushvalue(L,-2); - lua_rawset(L,-4); - } + lua_newtable(L); + SWIG_Lua_elua_emulate_register(L, swig_SwigModule.ns_methods); + SWIG_Lua_elua_emulate_register_clear(L); + if (globalRegister) { + lua_pushstring(L, swig_SwigModule.name); + lua_pushvalue(L, -2); + lua_rawset(L, -4); + } #endif #endif #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) - /* invoke user-specific initialization */ - SWIG_init_user(L); - /* end module */ - /* Note: We do not clean up the stack here (Lua will do this for us). At this - point, we have the globals table and out module table on the stack. Returning - one value makes the module table the result of the require command. */ - return 1; + /* invoke user-specific initialization */ + SWIG_init_user(L); + /* end module */ + /* Note: We do not clean up the stack here (Lua will do this for us). At this + point, we have the globals table and out module table on the stack. Returning + one value makes the module table the result of the require command. */ + return 1; #else - return 0; + return 0; #endif } @@ -3248,12 +3174,11 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */ #endif -const char* SWIG_LUACODE= - ""; +const char *SWIG_LUACODE = + ""; -void SWIG_init_user(lua_State* L) -{ - /* exec Lua code if applicable */ - SWIG_Lua_dostring(L,SWIG_LUACODE); +void SWIG_init_user(lua_State *L) { + /* exec Lua code if applicable */ + SWIG_Lua_dostring(L, SWIG_LUACODE); } diff --git a/client/src/pm3_pywrap.c b/client/src/pm3_pywrap.c index 03a584e48..e8e9b71b3 100644 --- a/client/src/pm3_pywrap.c +++ b/client/src/pm3_pywrap.c @@ -319,10 +319,10 @@ # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) SWIGINTERNINLINE int SWIG_AddCast(int r) { - return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; + return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; } SWIGINTERNINLINE int SWIG_CheckState(int r) { - return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; } #else /* no cast-rank mode */ # define SWIG_AddCast(r) (r) @@ -341,32 +341,32 @@ typedef struct swig_type_info *(*swig_dycast_func)(void **); /* Structure to store information on one type */ typedef struct swig_type_info { - const char *name; /* mangled name of this type */ - const char *str; /* human readable name of this type */ - swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ - struct swig_cast_info *cast; /* linked list of types that can cast into this type */ - void *clientdata; /* language specific type data */ - int owndata; /* flag if the structure owns the clientdata */ + const char *name; /* mangled name of this type */ + const char *str; /* human readable name of this type */ + swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ + struct swig_cast_info *cast; /* linked list of types that can cast into this type */ + void *clientdata; /* language specific type data */ + int owndata; /* flag if the structure owns the clientdata */ } swig_type_info; /* Structure to store a type and conversion function used for casting */ typedef struct swig_cast_info { - swig_type_info *type; /* pointer to type that is equivalent to this type */ - swig_converter_func converter; /* function to cast the void pointers */ - struct swig_cast_info *next; /* pointer to next cast in linked list */ - struct swig_cast_info *prev; /* pointer to the previous cast */ + swig_type_info *type; /* pointer to type that is equivalent to this type */ + swig_converter_func converter; /* function to cast the void pointers */ + struct swig_cast_info *next; /* pointer to next cast in linked list */ + struct swig_cast_info *prev; /* pointer to the previous cast */ } swig_cast_info; /* Structure used to store module information * Each module generates one structure like this, and the runtime collects * all of these structures and stores them in a circularly linked list.*/ typedef struct swig_module_info { - swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ - size_t size; /* Number of types in this module */ - struct swig_module_info *next; /* Pointer to next element in circularly linked list */ - swig_type_info **type_initial; /* Array of initially generated type structures */ - swig_cast_info **cast_initial; /* Array of initially generated casting structures */ - void *clientdata; /* Language specific module data */ + swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ + size_t size; /* Number of types in this module */ + struct swig_module_info *next; /* Pointer to next element in circularly linked list */ + swig_type_info **type_initial; /* Array of initially generated type structures */ + swig_cast_info **cast_initial; /* Array of initially generated casting structures */ + void *clientdata; /* Language specific module data */ } swig_module_info; /* @@ -378,13 +378,13 @@ typedef struct swig_module_info { */ SWIGRUNTIME int SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; - } - return (int)((l1 - f1) - (l2 - f2)); + const char *f2, const char *l2) { + for (; (f1 != l1) && (f2 != l2); ++f1, ++f2) { + while ((*f1 == ' ') && (f1 != l1)) ++f1; + while ((*f2 == ' ') && (f2 != l2)) ++f2; + if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; + } + return (int)((l1 - f1) - (l2 - f2)); } /* @@ -393,17 +393,17 @@ SWIG_TypeNameComp(const char *f1, const char *l1, */ SWIGRUNTIME int SWIG_TypeCmp(const char *nb, const char *tb) { - int equiv = 1; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (equiv != 0 && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; + int equiv = 1; + const char *te = tb + strlen(tb); + const char *ne = nb; + while (equiv != 0 && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = SWIG_TypeNameComp(nb, ne, tb, te); + if (*ne) ++ne; } - equiv = SWIG_TypeNameComp(nb, ne, tb, te); - if (*ne) ++ne; - } - return equiv; + return equiv; } /* @@ -412,7 +412,7 @@ SWIG_TypeCmp(const char *nb, const char *tb) { */ SWIGRUNTIME int SWIG_TypeEquiv(const char *nb, const char *tb) { - return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; + return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0; } /* @@ -420,26 +420,26 @@ SWIG_TypeEquiv(const char *nb, const char *tb) { */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheck(const char *c, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (strcmp(iter->type->name, c) == 0) { - if (iter == ty->cast) - return iter; - /* Move iter to the top of the linked list */ - iter->prev->next = iter->next; - if (iter->next) - iter->next->prev = iter->prev; - iter->next = ty->cast; - iter->prev = 0; - if (ty->cast) ty->cast->prev = iter; - ty->cast = iter; - return iter; - } - iter = iter->next; + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (strcmp(iter->type->name, c) == 0) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } } - } - return 0; + return 0; } /* @@ -447,26 +447,26 @@ SWIG_TypeCheck(const char *c, swig_type_info *ty) { */ SWIGRUNTIME swig_cast_info * SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { - if (ty) { - swig_cast_info *iter = ty->cast; - while (iter) { - if (iter->type == from) { - if (iter == ty->cast) - return iter; - /* Move iter to the top of the linked list */ - iter->prev->next = iter->next; - if (iter->next) - iter->next->prev = iter->prev; - iter->next = ty->cast; - iter->prev = 0; - if (ty->cast) ty->cast->prev = iter; - ty->cast = iter; - return iter; - } - iter = iter->next; + if (ty) { + swig_cast_info *iter = ty->cast; + while (iter) { + if (iter->type == from) { + if (iter == ty->cast) + return iter; + /* Move iter to the top of the linked list */ + iter->prev->next = iter->next; + if (iter->next) + iter->next->prev = iter->prev; + iter->next = ty->cast; + iter->prev = 0; + if (ty->cast) ty->cast->prev = iter; + ty->cast = iter; + return iter; + } + iter = iter->next; + } } - } - return 0; + return 0; } /* @@ -474,7 +474,7 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { */ SWIGRUNTIMEINLINE void * SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* @@ -482,13 +482,13 @@ SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { */ SWIGRUNTIME swig_type_info * SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; + swig_type_info *lastty = ty; + if (!ty || !ty->dcast) return ty; + while (ty && (ty->dcast)) { + ty = (*ty->dcast)(ptr); + if (ty) lastty = ty; + } + return lastty; } /* @@ -496,7 +496,7 @@ SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { */ SWIGRUNTIMEINLINE const char * SWIG_TypeName(const swig_type_info *ty) { - return ty->name; + return ty->name; } /* @@ -505,20 +505,19 @@ SWIG_TypeName(const swig_type_info *ty) { */ SWIGRUNTIME const char * SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (!type) return NULL; - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; + /* The "str" field contains the equivalent pretty names of the + type, separated by vertical-bar characters. We choose + to print the last name, as it is often (?) the most + specific. */ + if (!type) return NULL; + if (type->str != NULL) { + const char *last_name = type->str; + const char *s; + for (s = type->str; *s; s++) + if (*s == '|') last_name = s + 1; + return last_name; + } else + return type->name; } /* @@ -526,24 +525,24 @@ SWIG_TypePrettyName(const swig_type_info *type) { */ SWIGRUNTIME void SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_cast_info *cast = ti->cast; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; + swig_cast_info *cast = ti->cast; + /* if (ti->clientdata == clientdata) return; */ + ti->clientdata = clientdata; - while (cast) { - if (!cast->converter) { - swig_type_info *tc = cast->type; - if (!tc->clientdata) { - SWIG_TypeClientData(tc, clientdata); - } + while (cast) { + if (!cast->converter) { + swig_type_info *tc = cast->type; + if (!tc->clientdata) { + SWIG_TypeClientData(tc, clientdata); + } + } + cast = cast->next; } - cast = cast->next; - } } SWIGRUNTIME void SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { - SWIG_TypeClientData(ti, clientdata); - ti->owndata = 1; + SWIG_TypeClientData(ti, clientdata); + ti->owndata = 1; } /* @@ -557,37 +556,37 @@ SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { SWIGRUNTIME swig_type_info * SWIG_MangledTypeQueryModule(swig_module_info *start, swig_module_info *end, - const char *name) { - swig_module_info *iter = start; - do { - if (iter->size) { - size_t l = 0; - size_t r = iter->size - 1; - do { - /* since l+r >= 0, we can (>> 1) instead (/ 2) */ - size_t i = (l + r) >> 1; - const char *iname = iter->types[i]->name; - if (iname) { - int compare = strcmp(name, iname); - if (compare == 0) { - return iter->types[i]; - } else if (compare < 0) { - if (i) { - r = i - 1; - } else { - break; - } - } else if (compare > 0) { - l = i + 1; - } - } else { - break; /* should never happen */ - } - } while (l <= r); - } - iter = iter->next; - } while (iter != end); - return 0; + const char *name) { + swig_module_info *iter = start; + do { + if (iter->size) { + size_t l = 0; + size_t r = iter->size - 1; + do { + /* since l+r >= 0, we can (>> 1) instead (/ 2) */ + size_t i = (l + r) >> 1; + const char *iname = iter->types[i]->name; + if (iname) { + int compare = strcmp(name, iname); + if (compare == 0) { + return iter->types[i]; + } else if (compare < 0) { + if (i) { + r = i - 1; + } else { + break; + } + } else if (compare > 0) { + l = i + 1; + } + } else { + break; /* should never happen */ + } + } while (l <= r); + } + iter = iter->next; + } while (iter != end); + return 0; } /* @@ -602,27 +601,27 @@ SWIG_MangledTypeQueryModule(swig_module_info *start, SWIGRUNTIME swig_type_info * SWIG_TypeQueryModule(swig_module_info *start, swig_module_info *end, - const char *name) { - /* STEP 1: Search the name field using binary search */ - swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); - if (ret) { - return ret; - } else { - /* STEP 2: If the type hasn't been found, do a complete search - of the str field (the human readable name) */ - swig_module_info *iter = start; - do { - size_t i = 0; - for (; i < iter->size; ++i) { - if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) - return iter->types[i]; - } - iter = iter->next; - } while (iter != end); - } + const char *name) { + /* STEP 1: Search the name field using binary search */ + swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); + if (ret) { + return ret; + } else { + /* STEP 2: If the type hasn't been found, do a complete search + of the str field (the human readable name) */ + swig_module_info *iter = start; + do { + size_t i = 0; + for (; i < iter->size; ++i) { + if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) + return iter->types[i]; + } + iter = iter->next; + } while (iter != end); + } - /* neither found a match */ - return 0; + /* neither found a match */ + return 0; } /* @@ -630,15 +629,15 @@ SWIG_TypeQueryModule(swig_module_info *start, */ SWIGRUNTIME char * SWIG_PackData(char *c, void *ptr, size_t sz) { - static const char hex[17] = "0123456789abcdef"; - const unsigned char *u = (unsigned char *) ptr; - const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - unsigned char uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; + static const char hex[17] = "0123456789abcdef"; + const unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + unsigned char uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; } /* @@ -646,27 +645,27 @@ SWIG_PackData(char *c, void *ptr, size_t sz) { */ SWIGRUNTIME const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { - unsigned char *u = (unsigned char *) ptr; - const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - char d = *(c++); - unsigned char uu; - if ((d >= '0') && (d <= '9')) - uu = (unsigned char)((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = (unsigned char)((d - ('a'-10)) << 4); - else - return (char *) 0; - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (unsigned char)(d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (unsigned char)(d - ('a'-10)); - else - return (char *) 0; - *u = uu; - } - return c; + unsigned char *u = (unsigned char *) ptr; + const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + char d = *(c++); + unsigned char uu; + if ((d >= '0') && (d <= '9')) + uu = (unsigned char)((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = (unsigned char)((d - ('a' - 10)) << 4); + else + return (char *) 0; + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (unsigned char)(d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (unsigned char)(d - ('a' - 10)); + else + return (char *) 0; + *u = uu; + } + return c; } /* @@ -674,54 +673,54 @@ SWIG_UnpackData(const char *c, void *ptr, size_t sz) { */ SWIGRUNTIME char * SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { - char *r = buff; - if ((2*sizeof(void *) + 2) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - if (strlen(name) + 1 > (bsz - (r - buff))) return 0; - strcpy(r,name); - return buff; + char *r = buff; + if ((2 * sizeof(void *) + 2) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r, &ptr, sizeof(void *)); + if (strlen(name) + 1 > (bsz - (r - buff))) return 0; + strcpy(r, name); + return buff; } SWIGRUNTIME const char * SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - *ptr = (void *) 0; - return name; - } else { - return 0; + if (*c != '_') { + if (strcmp(c, "NULL") == 0) { + *ptr = (void *) 0; + return name; + } else { + return 0; + } } - } - return SWIG_UnpackData(++c,ptr,sizeof(void *)); + return SWIG_UnpackData(++c, ptr, sizeof(void *)); } SWIGRUNTIME char * SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { - char *r = buff; - size_t lname = (name ? strlen(name) : 0); - if ((2*sz + 2 + lname) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - if (lname) { - strncpy(r,name,lname+1); - } else { - *r = 0; - } - return buff; + char *r = buff; + size_t lname = (name ? strlen(name) : 0); + if ((2 * sz + 2 + lname) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r, ptr, sz); + if (lname) { + strncpy(r, name, lname + 1); + } else { + *r = 0; + } + return buff; } SWIGRUNTIME const char * SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - memset(ptr,0,sz); - return name; - } else { - return 0; + if (*c != '_') { + if (strcmp(c, "NULL") == 0) { + memset(ptr, 0, sz); + return name; + } else { + return 0; + } } - } - return SWIG_UnpackData(++c,ptr,sz); + return SWIG_UnpackData(++c, ptr, sz); } #ifdef __cplusplus @@ -757,7 +756,7 @@ SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { #define PyString_FromString(x) PyUnicode_FromString(x) #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args) #define PyString_AsString(str) PyBytes_AsString(str) -#define PyString_Size(str) PyBytes_Size(str) +#define PyString_Size(str) PyBytes_Size(str) #define PyString_InternFromString(key) PyUnicode_InternFromString(key) #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE #define PyString_AS_STRING(x) PyUnicode_AS_STRING(x) @@ -781,40 +780,38 @@ SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { /* Warning: This function will allocate a new string in Python 3, * so please call SWIG_Python_str_DelForPy3(x) to free the space. */ -SWIGINTERN char* -SWIG_Python_str_AsChar(PyObject *str) -{ +SWIGINTERN char * +SWIG_Python_str_AsChar(PyObject *str) { #if PY_VERSION_HEX >= 0x03000000 - char *newstr = 0; - str = PyUnicode_AsUTF8String(str); - if (str) { - char *cstr; - Py_ssize_t len; - PyBytes_AsStringAndSize(str, &cstr, &len); - newstr = (char *) malloc(len+1); - memcpy(newstr, cstr, len+1); - Py_XDECREF(str); - } - return newstr; + char *newstr = 0; + str = PyUnicode_AsUTF8String(str); + if (str) { + char *cstr; + Py_ssize_t len; + PyBytes_AsStringAndSize(str, &cstr, &len); + newstr = (char *) malloc(len + 1); + memcpy(newstr, cstr, len + 1); + Py_XDECREF(str); + } + return newstr; #else - return PyString_AsString(str); + return PyString_AsString(str); #endif } #if PY_VERSION_HEX >= 0x03000000 # define SWIG_Python_str_DelForPy3(x) free( (void*) (x) ) #else -# define SWIG_Python_str_DelForPy3(x) +# define SWIG_Python_str_DelForPy3(x) #endif -SWIGINTERN PyObject* -SWIG_Python_str_FromChar(const char *c) -{ +SWIGINTERN PyObject * +SWIG_Python_str_FromChar(const char *c) { #if PY_VERSION_HEX >= 0x03000000 - return PyUnicode_FromString(c); + return PyUnicode_FromString(c); #else - return PyString_FromString(c); + return PyString_FromString(c); #endif } @@ -837,105 +834,102 @@ SWIG_Python_str_FromChar(const char *c) * error manipulation * ----------------------------------------------------------------------------- */ -SWIGRUNTIME PyObject* +SWIGRUNTIME PyObject * SWIG_Python_ErrorType(int code) { - PyObject* type = 0; - switch(code) { - case SWIG_MemoryError: - type = PyExc_MemoryError; - break; - case SWIG_IOError: - type = PyExc_IOError; - break; - case SWIG_RuntimeError: - type = PyExc_RuntimeError; - break; - case SWIG_IndexError: - type = PyExc_IndexError; - break; - case SWIG_TypeError: - type = PyExc_TypeError; - break; - case SWIG_DivisionByZero: - type = PyExc_ZeroDivisionError; - break; - case SWIG_OverflowError: - type = PyExc_OverflowError; - break; - case SWIG_SyntaxError: - type = PyExc_SyntaxError; - break; - case SWIG_ValueError: - type = PyExc_ValueError; - break; - case SWIG_SystemError: - type = PyExc_SystemError; - break; - case SWIG_AttributeError: - type = PyExc_AttributeError; - break; - default: - type = PyExc_RuntimeError; - } - return type; + PyObject *type = 0; + switch (code) { + case SWIG_MemoryError: + type = PyExc_MemoryError; + break; + case SWIG_IOError: + type = PyExc_IOError; + break; + case SWIG_RuntimeError: + type = PyExc_RuntimeError; + break; + case SWIG_IndexError: + type = PyExc_IndexError; + break; + case SWIG_TypeError: + type = PyExc_TypeError; + break; + case SWIG_DivisionByZero: + type = PyExc_ZeroDivisionError; + break; + case SWIG_OverflowError: + type = PyExc_OverflowError; + break; + case SWIG_SyntaxError: + type = PyExc_SyntaxError; + break; + case SWIG_ValueError: + type = PyExc_ValueError; + break; + case SWIG_SystemError: + type = PyExc_SystemError; + break; + case SWIG_AttributeError: + type = PyExc_AttributeError; + break; + default: + type = PyExc_RuntimeError; + } + return type; } SWIGRUNTIME void -SWIG_Python_AddErrorMsg(const char* mesg) -{ - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; +SWIG_Python_AddErrorMsg(const char *mesg) { + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; - if (PyErr_Occurred()) - PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject *old_str = PyObject_Str(value); - const char *tmp = SWIG_Python_str_AsChar(old_str); - PyErr_Clear(); - Py_XINCREF(type); - if (tmp) - PyErr_Format(type, "%s %s", tmp, mesg); - else - PyErr_Format(type, "%s", mesg); - SWIG_Python_str_DelForPy3(tmp); - Py_DECREF(old_str); - Py_DECREF(value); - } else { - PyErr_SetString(PyExc_RuntimeError, mesg); - } + if (PyErr_Occurred()) + PyErr_Fetch(&type, &value, &traceback); + if (value) { + PyObject *old_str = PyObject_Str(value); + const char *tmp = SWIG_Python_str_AsChar(old_str); + PyErr_Clear(); + Py_XINCREF(type); + if (tmp) + PyErr_Format(type, "%s %s", tmp, mesg); + else + PyErr_Format(type, "%s", mesg); + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(old_str); + Py_DECREF(value); + } else { + PyErr_SetString(PyExc_RuntimeError, mesg); + } } SWIGRUNTIME int -SWIG_Python_TypeErrorOccurred(PyObject *obj) -{ - PyObject *error; - if (obj) - return 0; - error = PyErr_Occurred(); - return error && PyErr_GivenExceptionMatches(error, PyExc_TypeError); +SWIG_Python_TypeErrorOccurred(PyObject *obj) { + PyObject *error; + if (obj) + return 0; + error = PyErr_Occurred(); + return error && PyErr_GivenExceptionMatches(error, PyExc_TypeError); } SWIGRUNTIME void -SWIG_Python_RaiseOrModifyTypeError(const char *message) -{ - if (SWIG_Python_TypeErrorOccurred(NULL)) { - /* Use existing TypeError to preserve stacktrace and enhance with given message */ - PyObject *newvalue; - PyObject *type = NULL, *value = NULL, *traceback = NULL; - PyErr_Fetch(&type, &value, &traceback); +SWIG_Python_RaiseOrModifyTypeError(const char *message) { + if (SWIG_Python_TypeErrorOccurred(NULL)) { + /* Use existing TypeError to preserve stacktrace and enhance with given message */ + PyObject *newvalue; + PyObject *type = NULL, *value = NULL, *traceback = NULL; + PyErr_Fetch(&type, &value, &traceback); #if PY_VERSION_HEX >= 0x03000000 - newvalue = PyUnicode_FromFormat("%S\nAdditional information:\n%s", value, message); + newvalue = PyUnicode_FromFormat("%S\nAdditional information:\n%s", value, message); #else - newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message); + newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message); #endif - Py_XDECREF(value); - PyErr_Restore(type, newvalue, traceback); - } else { - /* Raise TypeError using given message */ - PyErr_SetString(PyExc_TypeError, message); - } + Py_XDECREF(value); + PyErr_Restore(type, newvalue, traceback); + } else { + /* Raise TypeError using given message */ + PyErr_SetString(PyExc_TypeError, message); + } } #if defined(SWIG_PYTHON_NO_THREADS) @@ -949,25 +943,25 @@ SWIG_Python_RaiseOrModifyTypeError(const char *message) # endif # if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ # ifndef SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() +# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() # endif # ifdef __cplusplus /* C++ code */ - class SWIG_Python_Thread_Block { - bool status; - PyGILState_STATE state; - public: - void end() { if (status) { PyGILState_Release(state); status = false;} } - SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} - ~SWIG_Python_Thread_Block() { end(); } - }; - class SWIG_Python_Thread_Allow { - bool status; - PyThreadState *save; - public: - void end() { if (status) { PyEval_RestoreThread(save); status = false; }} - SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} - ~SWIG_Python_Thread_Allow() { end(); } - }; +class SWIG_Python_Thread_Block { + bool status; + PyGILState_STATE state; + public: + void end() { if (status) { PyGILState_Release(state); status = false;} } + SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} + ~SWIG_Python_Thread_Block() { end(); } +}; +class SWIG_Python_Thread_Allow { + bool status; + PyThreadState *save; + public: + void end() { if (status) { PyEval_RestoreThread(save); status = false; }} + SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} + ~SWIG_Python_Thread_Allow() { end(); } +}; # define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block # define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() # define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow @@ -1021,12 +1015,12 @@ extern "C" { /* Constant information structure */ typedef struct swig_const_info { - int type; - const char *name; - long lvalue; - double dvalue; - void *pvalue; - swig_type_info **ptype; + int type; + const char *name; + long lvalue; + double dvalue; + void *pvalue; + swig_type_info **ptype; } swig_const_info; #ifdef __cplusplus @@ -1066,7 +1060,7 @@ typedef struct swig_const_info { #define SWIG_InternalNewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags) -#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) +#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) #define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) #define swig_owntype int @@ -1093,30 +1087,30 @@ typedef struct swig_const_info { #define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) #define SWIG_NewClientData(obj) SwigPyClientData_New(obj) -#define SWIG_SetErrorObj SWIG_Python_SetErrorObj -#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg -#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) -#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) -#define SWIG_fail goto fail +#define SWIG_SetErrorObj SWIG_Python_SetErrorObj +#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg +#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) +#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) +#define SWIG_fail goto fail /* Runtime API implementation */ /* Error manipulation */ -SWIGINTERN void +SWIGINTERN void SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetObject(errtype, obj); - Py_DECREF(obj); - SWIG_PYTHON_THREAD_END_BLOCK; + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetObject(errtype, obj); + Py_DECREF(obj); + SWIG_PYTHON_THREAD_END_BLOCK; } -SWIGINTERN void +SWIGINTERN void SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(errtype, msg); - SWIG_PYTHON_THREAD_END_BLOCK; + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(errtype, msg); + SWIG_PYTHON_THREAD_END_BLOCK; } #define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) @@ -1127,96 +1121,95 @@ SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { SWIGINTERN void SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) { - PyObject *s = PyString_InternFromString(key); - PyList_Append(seq, s); - Py_DECREF(s); + PyObject *s = PyString_InternFromString(key); + PyList_Append(seq, s); + Py_DECREF(s); } SWIGINTERN void -SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { - PyDict_SetItemString(d, name, obj); - Py_DECREF(obj); - if (public_interface) - SwigPyBuiltin_AddPublicSymbol(public_interface, name); +SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) { + PyDict_SetItemString(d, name, obj); + Py_DECREF(obj); + if (public_interface) + SwigPyBuiltin_AddPublicSymbol(public_interface, name); } #else SWIGINTERN void -SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { - PyDict_SetItemString(d, name, obj); - Py_DECREF(obj); +SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { + PyDict_SetItemString(d, name, obj); + Py_DECREF(obj); } #endif /* Append a value to the result obj */ -SWIGINTERN PyObject* -SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyList_Check(result)) { - PyObject *o2 = result; - result = PyList_New(1); - PyList_SetItem(result, 0, o2); +SWIGINTERN PyObject * +SWIG_Python_AppendOutput(PyObject *result, PyObject *obj) { + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyList_Check(result)) { + PyObject *o2 = result; + result = PyList_New(1); + PyList_SetItem(result, 0, o2); + } + PyList_Append(result, obj); + Py_DECREF(obj); } - PyList_Append(result,obj); - Py_DECREF(obj); - } - return result; + return result; } /* Unpack the argument tuple */ SWIGINTERN Py_ssize_t -SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) -{ - if (!args) { - if (!min && !max) { - return 1; - } else { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", - name, (min == max ? "" : "at least "), (int)min); - return 0; +SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) { + if (!args) { + if (!min && !max) { + return 1; + } else { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", + name, (min == max ? "" : "at least "), (int)min); + return 0; + } } - } - if (!PyTuple_Check(args)) { - if (min <= 1 && max >= 1) { - Py_ssize_t i; - objs[0] = args; - for (i = 1; i < max; ++i) { - objs[i] = 0; - } - return 2; - } - PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); - return 0; - } else { - Py_ssize_t l = PyTuple_GET_SIZE(args); - if (l < min) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at least "), (int)min, (int)l); - return 0; - } else if (l > max) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at most "), (int)max, (int)l); - return 0; + if (!PyTuple_Check(args)) { + if (min <= 1 && max >= 1) { + Py_ssize_t i; + objs[0] = args; + for (i = 1; i < max; ++i) { + objs[i] = 0; + } + return 2; + } + PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); + return 0; } else { - Py_ssize_t i; - for (i = 0; i < l; ++i) { - objs[i] = PyTuple_GET_ITEM(args, i); - } - for (; l < max; ++l) { - objs[l] = 0; - } - return i + 1; - } - } + Py_ssize_t l = PyTuple_GET_SIZE(args); + if (l < min) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at least "), (int)min, (int)l); + return 0; + } else if (l > max) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at most "), (int)max, (int)l); + return 0; + } else { + Py_ssize_t i; + for (i = 0; i < l; ++i) { + objs[i] = PyTuple_GET_ITEM(args, i); + } + for (; l < max; ++l) { + objs[l] = 0; + } + return i + 1; + } + } } /* A functor is a function object with one single object argument */ @@ -1251,107 +1244,104 @@ extern "C" { /* The python void return value */ -SWIGRUNTIMEINLINE PyObject * -SWIG_Py_Void(void) -{ - PyObject *none = Py_None; - Py_INCREF(none); - return none; +SWIGRUNTIMEINLINE PyObject * +SWIG_Py_Void(void) { + PyObject *none = Py_None; + Py_INCREF(none); + return none; } /* SwigPyClientData */ typedef struct { - PyObject *klass; - PyObject *newraw; - PyObject *newargs; - PyObject *destroy; - int delargs; - int implicitconv; - PyTypeObject *pytype; + PyObject *klass; + PyObject *newraw; + PyObject *newargs; + PyObject *destroy; + int delargs; + int implicitconv; + PyTypeObject *pytype; } SwigPyClientData; -SWIGRUNTIMEINLINE int -SWIG_Python_CheckImplicit(swig_type_info *ty) -{ - SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; - int fail = data ? data->implicitconv : 0; - if (fail) - PyErr_SetString(PyExc_TypeError, "Implicit conversion is prohibited for explicit constructors."); - return fail; +SWIGRUNTIMEINLINE int +SWIG_Python_CheckImplicit(swig_type_info *ty) { + SwigPyClientData *data = (SwigPyClientData *)ty->clientdata; + int fail = data ? data->implicitconv : 0; + if (fail) + PyErr_SetString(PyExc_TypeError, "Implicit conversion is prohibited for explicit constructors."); + return fail; } SWIGRUNTIMEINLINE PyObject * SWIG_Python_ExceptionType(swig_type_info *desc) { - SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; - PyObject *klass = data ? data->klass : 0; - return (klass ? klass : PyExc_RuntimeError); + SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0; + PyObject *klass = data ? data->klass : 0; + return (klass ? klass : PyExc_RuntimeError); } -SWIGRUNTIME SwigPyClientData * -SwigPyClientData_New(PyObject* obj) -{ - if (!obj) { - return 0; - } else { - SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); - /* the klass element */ - data->klass = obj; - Py_INCREF(data->klass); - /* the newraw method and newargs arguments used to create a new raw instance */ - if (PyClass_Check(obj)) { - data->newraw = 0; - data->newargs = obj; - Py_INCREF(obj); +SWIGRUNTIME SwigPyClientData * +SwigPyClientData_New(PyObject *obj) { + if (!obj) { + return 0; } else { - data->newraw = PyObject_GetAttrString(data->klass, "__new__"); - if (data->newraw) { - Py_INCREF(data->newraw); - data->newargs = PyTuple_New(1); - PyTuple_SetItem(data->newargs, 0, obj); - } else { - data->newargs = obj; - } - Py_INCREF(data->newargs); + SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData)); + /* the klass element */ + data->klass = obj; + Py_INCREF(data->klass); + /* the newraw method and newargs arguments used to create a new raw instance */ + if (PyClass_Check(obj)) { + data->newraw = 0; + data->newargs = obj; + Py_INCREF(obj); + } else { + data->newraw = PyObject_GetAttrString(data->klass, "__new__"); + if (data->newraw) { + Py_INCREF(data->newraw); + data->newargs = PyTuple_New(1); + PyTuple_SetItem(data->newargs, 0, obj); + } else { + data->newargs = obj; + } + Py_INCREF(data->newargs); + } + /* the destroy method, aka as the C++ delete method */ + data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__"); + if (PyErr_Occurred()) { + PyErr_Clear(); + data->destroy = 0; + } + if (data->destroy) { + int flags; + Py_INCREF(data->destroy); + flags = PyCFunction_GET_FLAGS(data->destroy); + data->delargs = !(flags & (METH_O)); + } else { + data->delargs = 0; + } + data->implicitconv = 0; + data->pytype = 0; + return data; } - /* the destroy method, aka as the C++ delete method */ - data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__"); - if (PyErr_Occurred()) { - PyErr_Clear(); - data->destroy = 0; - } - if (data->destroy) { - int flags; - Py_INCREF(data->destroy); - flags = PyCFunction_GET_FLAGS(data->destroy); - data->delargs = !(flags & (METH_O)); - } else { - data->delargs = 0; - } - data->implicitconv = 0; - data->pytype = 0; - return data; - } } -SWIGRUNTIME void +SWIGRUNTIME void SwigPyClientData_Del(SwigPyClientData *data) { - Py_XDECREF(data->newraw); - Py_XDECREF(data->newargs); - Py_XDECREF(data->destroy); + Py_XDECREF(data->newraw); + Py_XDECREF(data->newargs); + Py_XDECREF(data->destroy); } /* =============== SwigPyObject =====================*/ typedef struct { - PyObject_HEAD - void *ptr; - swig_type_info *ty; - int own; - PyObject *next; + PyObject_HEAD + void *ptr; + swig_type_info *ty; + int own; + PyObject *next; #ifdef SWIGPYTHON_BUILTIN - PyObject *dict; + PyObject *dict; #endif } SwigPyObject; @@ -1359,139 +1349,130 @@ typedef struct { #ifdef SWIGPYTHON_BUILTIN SWIGRUNTIME PyObject * -SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) -{ - SwigPyObject *sobj = (SwigPyObject *)v; +SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { + SwigPyObject *sobj = (SwigPyObject *)v; - if (!sobj->dict) - sobj->dict = PyDict_New(); + if (!sobj->dict) + sobj->dict = PyDict_New(); - Py_INCREF(sobj->dict); - return sobj->dict; + Py_INCREF(sobj->dict); + return sobj->dict; } #endif SWIGRUNTIME PyObject * -SwigPyObject_long(SwigPyObject *v) -{ - return PyLong_FromVoidPtr(v->ptr); +SwigPyObject_long(SwigPyObject *v) { + return PyLong_FromVoidPtr(v->ptr); } SWIGRUNTIME PyObject * -SwigPyObject_format(const char* fmt, SwigPyObject *v) -{ - PyObject *res = NULL; - PyObject *args = PyTuple_New(1); - if (args) { - if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { - PyObject *ofmt = SWIG_Python_str_FromChar(fmt); - if (ofmt) { +SwigPyObject_format(const char *fmt, SwigPyObject *v) { + PyObject *res = NULL; + PyObject *args = PyTuple_New(1); + if (args) { + if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { + PyObject *ofmt = SWIG_Python_str_FromChar(fmt); + if (ofmt) { #if PY_VERSION_HEX >= 0x03000000 - res = PyUnicode_Format(ofmt,args); + res = PyUnicode_Format(ofmt, args); #else - res = PyString_Format(ofmt,args); + res = PyString_Format(ofmt, args); #endif - Py_DECREF(ofmt); - } - Py_DECREF(args); + Py_DECREF(ofmt); + } + Py_DECREF(args); + } } - } - return res; + return res; } SWIGRUNTIME PyObject * -SwigPyObject_oct(SwigPyObject *v) -{ - return SwigPyObject_format("%o",v); +SwigPyObject_oct(SwigPyObject *v) { + return SwigPyObject_format("%o", v); } SWIGRUNTIME PyObject * -SwigPyObject_hex(SwigPyObject *v) -{ - return SwigPyObject_format("%x",v); +SwigPyObject_hex(SwigPyObject *v) { + return SwigPyObject_format("%x", v); } SWIGRUNTIME PyObject * -SwigPyObject_repr(SwigPyObject *v) -{ - const char *name = SWIG_TypePrettyName(v->ty); - PyObject *repr = SWIG_Python_str_FromFormat("", (name ? name : "unknown"), (void *)v); - if (v->next) { - PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); +SwigPyObject_repr(SwigPyObject *v) { + const char *name = SWIG_TypePrettyName(v->ty); + PyObject *repr = SWIG_Python_str_FromFormat("", (name ? name : "unknown"), (void *)v); + if (v->next) { + PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); # if PY_VERSION_HEX >= 0x03000000 - PyObject *joined = PyUnicode_Concat(repr, nrep); - Py_DecRef(repr); - Py_DecRef(nrep); - repr = joined; + PyObject *joined = PyUnicode_Concat(repr, nrep); + Py_DecRef(repr); + Py_DecRef(nrep); + repr = joined; # else - PyString_ConcatAndDel(&repr,nrep); + PyString_ConcatAndDel(&repr, nrep); # endif - } - return repr; + } + return repr; } /* We need a version taking two PyObject* parameters so it's a valid * PyCFunction to use in swigobject_methods[]. */ SWIGRUNTIME PyObject * -SwigPyObject_repr2(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) -{ - return SwigPyObject_repr((SwigPyObject*)v); +SwigPyObject_repr2(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { + return SwigPyObject_repr((SwigPyObject *)v); } SWIGRUNTIME int -SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) -{ - void *i = v->ptr; - void *j = w->ptr; - return (i < j) ? -1 : ((i > j) ? 1 : 0); +SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) { + void *i = v->ptr; + void *j = w->ptr; + return (i < j) ? -1 : ((i > j) ? 1 : 0); } /* Added for Python 3.x, would it also be useful for Python 2.x? */ -SWIGRUNTIME PyObject* -SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) -{ - PyObject* res; - if( op != Py_EQ && op != Py_NE ) { - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } - res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0); - return res; +SWIGRUNTIME PyObject * +SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op) { + PyObject *res; + if (op != Py_EQ && op != Py_NE) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + res = PyBool_FromLong((SwigPyObject_compare(v, w) == 0) == (op == Py_EQ) ? 1 : 0); + return res; } -SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void); +SWIGRUNTIME PyTypeObject *SwigPyObject_TypeOnce(void); #ifdef SWIGPYTHON_BUILTIN static swig_type_info *SwigPyObject_stype = 0; -SWIGRUNTIME PyTypeObject* +SWIGRUNTIME PyTypeObject * SwigPyObject_type(void) { SwigPyClientData *cd; assert(SwigPyObject_stype); - cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; + cd = (SwigPyClientData *) SwigPyObject_stype->clientdata; assert(cd); assert(cd->pytype); return cd->pytype; } #else -SWIGRUNTIME PyTypeObject* +SWIGRUNTIME PyTypeObject * SwigPyObject_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce(); - return type; + static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce(); + return type; } #endif SWIGRUNTIMEINLINE int SwigPyObject_Check(PyObject *op) { #ifdef SWIGPYTHON_BUILTIN - PyTypeObject *target_tp = SwigPyObject_type(); - if (PyType_IsSubtype(op->ob_type, target_tp)) - return 1; - return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); + PyTypeObject *target_tp = SwigPyObject_type(); + if (PyType_IsSubtype(op->ob_type, target_tp)) + return 1; + return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0); #else - return (Py_TYPE(op) == SwigPyObject_type()) - || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); + return (Py_TYPE(op) == SwigPyObject_type()) + || (strcmp(Py_TYPE(op)->tp_name, "SwigPyObject") == 0); #endif } @@ -1499,266 +1480,259 @@ SWIGRUNTIME PyObject * SwigPyObject_New(void *ptr, swig_type_info *ty, int own); SWIGRUNTIME void -SwigPyObject_dealloc(PyObject *v) -{ - SwigPyObject *sobj = (SwigPyObject *) v; - PyObject *next = sobj->next; - if (sobj->own == SWIG_POINTER_OWN) { - swig_type_info *ty = sobj->ty; - SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; - PyObject *destroy = data ? data->destroy : 0; - if (destroy) { - /* destroy is always a VARARGS method */ - PyObject *res; +SwigPyObject_dealloc(PyObject *v) { + SwigPyObject *sobj = (SwigPyObject *) v; + PyObject *next = sobj->next; + if (sobj->own == SWIG_POINTER_OWN) { + swig_type_info *ty = sobj->ty; + SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; + PyObject *destroy = data ? data->destroy : 0; + if (destroy) { + /* destroy is always a VARARGS method */ + PyObject *res; - /* PyObject_CallFunction() has the potential to silently drop - the active exception. In cases of unnamed temporary - variable or where we just finished iterating over a generator - StopIteration will be active right now, and this needs to - remain true upon return from SwigPyObject_dealloc. So save - and restore. */ - - PyObject *type = NULL, *value = NULL, *traceback = NULL; - PyErr_Fetch(&type, &value, &traceback); + /* PyObject_CallFunction() has the potential to silently drop + the active exception. In cases of unnamed temporary + variable or where we just finished iterating over a generator + StopIteration will be active right now, and this needs to + remain true upon return from SwigPyObject_dealloc. So save + and restore. */ - if (data->delargs) { - /* we need to create a temporary object to carry the destroy operation */ - PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); - } else { - PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); - PyObject *mself = PyCFunction_GET_SELF(destroy); - res = ((*meth)(mself, v)); - } - if (!res) - PyErr_WriteUnraisable(destroy); + PyObject *type = NULL, *value = NULL, *traceback = NULL; + PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(type, value, traceback); + if (data->delargs) { + /* we need to create a temporary object to carry the destroy operation */ + PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); + res = SWIG_Python_CallFunctor(destroy, tmp); + Py_DECREF(tmp); + } else { + PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); + PyObject *mself = PyCFunction_GET_SELF(destroy); + res = ((*meth)(mself, v)); + } + if (!res) + PyErr_WriteUnraisable(destroy); - Py_XDECREF(res); - } + PyErr_Restore(type, value, traceback); + + Py_XDECREF(res); + } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - else { - const char *name = SWIG_TypePrettyName(ty); - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); - } + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); + } #endif - } - Py_XDECREF(next); - PyObject_DEL(v); + } + Py_XDECREF(next); + PyObject_DEL(v); } -SWIGRUNTIME PyObject* -SwigPyObject_append(PyObject* v, PyObject* next) -{ - SwigPyObject *sobj = (SwigPyObject *) v; - if (!SwigPyObject_Check(next)) { - PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject"); - return NULL; - } - sobj->next = next; - Py_INCREF(next); - return SWIG_Py_Void(); -} - -SWIGRUNTIME PyObject* -SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -{ - SwigPyObject *sobj = (SwigPyObject *) v; - if (sobj->next) { - Py_INCREF(sobj->next); - return sobj->next; - } else { +SWIGRUNTIME PyObject * +SwigPyObject_append(PyObject *v, PyObject *next) { + SwigPyObject *sobj = (SwigPyObject *) v; + if (!SwigPyObject_Check(next)) { + PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject"); + return NULL; + } + sobj->next = next; + Py_INCREF(next); return SWIG_Py_Void(); - } } -SWIGINTERN PyObject* -SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -{ - SwigPyObject *sobj = (SwigPyObject *)v; - sobj->own = 0; - return SWIG_Py_Void(); +SWIGRUNTIME PyObject * +SwigPyObject_next(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { + SwigPyObject *sobj = (SwigPyObject *) v; + if (sobj->next) { + Py_INCREF(sobj->next); + return sobj->next; + } else { + return SWIG_Py_Void(); + } } -SWIGINTERN PyObject* -SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -{ - SwigPyObject *sobj = (SwigPyObject *)v; - sobj->own = SWIG_POINTER_OWN; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -SwigPyObject_own(PyObject *v, PyObject *args) -{ - PyObject *val = 0; - if (!PyArg_UnpackTuple(args, "own", 0, 1, &val)) { - return NULL; - } else { +SWIGINTERN PyObject * +SwigPyObject_disown(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { SwigPyObject *sobj = (SwigPyObject *)v; - PyObject *obj = PyBool_FromLong(sobj->own); - if (val) { - if (PyObject_IsTrue(val)) { - SwigPyObject_acquire(v,args); - } else { - SwigPyObject_disown(v,args); - } - } - return obj; - } + sobj->own = 0; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject * +SwigPyObject_acquire(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) { + SwigPyObject *sobj = (SwigPyObject *)v; + sobj->own = SWIG_POINTER_OWN; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject * +SwigPyObject_own(PyObject *v, PyObject *args) { + PyObject *val = 0; + if (!PyArg_UnpackTuple(args, "own", 0, 1, &val)) { + return NULL; + } else { + SwigPyObject *sobj = (SwigPyObject *)v; + PyObject *obj = PyBool_FromLong(sobj->own); + if (val) { + if (PyObject_IsTrue(val)) { + SwigPyObject_acquire(v, args); + } else { + SwigPyObject_disown(v, args); + } + } + return obj; + } } static PyMethodDef swigobject_methods[] = { - {"disown", SwigPyObject_disown, METH_NOARGS, "releases ownership of the pointer"}, - {"acquire", SwigPyObject_acquire, METH_NOARGS, "acquires ownership of the pointer"}, - {"own", SwigPyObject_own, METH_VARARGS, "returns/sets ownership of the pointer"}, - {"append", SwigPyObject_append, METH_O, "appends another 'this' object"}, - {"next", SwigPyObject_next, METH_NOARGS, "returns the next 'this' object"}, - {"__repr__",SwigPyObject_repr2, METH_NOARGS, "returns object representation"}, - {0, 0, 0, 0} + {"disown", SwigPyObject_disown, METH_NOARGS, "releases ownership of the pointer"}, + {"acquire", SwigPyObject_acquire, METH_NOARGS, "acquires ownership of the pointer"}, + {"own", SwigPyObject_own, METH_VARARGS, "returns/sets ownership of the pointer"}, + {"append", SwigPyObject_append, METH_O, "appends another 'this' object"}, + {"next", SwigPyObject_next, METH_NOARGS, "returns the next 'this' object"}, + {"__repr__", SwigPyObject_repr2, METH_NOARGS, "returns object representation"}, + {0, 0, 0, 0} }; -SWIGRUNTIME PyTypeObject* +SWIGRUNTIME PyTypeObject * SwigPyObject_TypeOnce(void) { - static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; + static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; - static PyNumberMethods SwigPyObject_as_number = { - (binaryfunc)0, /*nb_add*/ - (binaryfunc)0, /*nb_subtract*/ - (binaryfunc)0, /*nb_multiply*/ - /* nb_divide removed in Python 3 */ + static PyNumberMethods SwigPyObject_as_number = { + (binaryfunc)0, /*nb_add*/ + (binaryfunc)0, /*nb_subtract*/ + (binaryfunc)0, /*nb_multiply*/ + /* nb_divide removed in Python 3 */ #if PY_VERSION_HEX < 0x03000000 - (binaryfunc)0, /*nb_divide*/ + (binaryfunc)0, /*nb_divide*/ #endif - (binaryfunc)0, /*nb_remainder*/ - (binaryfunc)0, /*nb_divmod*/ - (ternaryfunc)0,/*nb_power*/ - (unaryfunc)0, /*nb_negative*/ - (unaryfunc)0, /*nb_positive*/ - (unaryfunc)0, /*nb_absolute*/ - (inquiry)0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ + (binaryfunc)0, /*nb_remainder*/ + (binaryfunc)0, /*nb_divmod*/ + (ternaryfunc)0,/*nb_power*/ + (unaryfunc)0, /*nb_negative*/ + (unaryfunc)0, /*nb_positive*/ + (unaryfunc)0, /*nb_absolute*/ + (inquiry)0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ #if PY_VERSION_HEX < 0x03000000 - 0, /*nb_coerce*/ + 0, /*nb_coerce*/ #endif - (unaryfunc)SwigPyObject_long, /*nb_int*/ + (unaryfunc)SwigPyObject_long, /*nb_int*/ #if PY_VERSION_HEX < 0x03000000 - (unaryfunc)SwigPyObject_long, /*nb_long*/ + (unaryfunc)SwigPyObject_long, /*nb_long*/ #else - 0, /*nb_reserved*/ + 0, /*nb_reserved*/ #endif - (unaryfunc)0, /*nb_float*/ + (unaryfunc)0, /*nb_float*/ #if PY_VERSION_HEX < 0x03000000 - (unaryfunc)SwigPyObject_oct, /*nb_oct*/ - (unaryfunc)SwigPyObject_hex, /*nb_hex*/ + (unaryfunc)SwigPyObject_oct, /*nb_oct*/ + (unaryfunc)SwigPyObject_hex, /*nb_hex*/ #endif #if PY_VERSION_HEX >= 0x03050000 /* 3.5 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_matrix_multiply */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* nb_inplace_add -> nb_inplace_matrix_multiply */ #elif PY_VERSION_HEX >= 0x03000000 /* 3.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */ #else - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ -#endif - }; - - static PyTypeObject swigpyobject_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp = { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(NULL, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif - "SwigPyObject", /* tp_name */ - sizeof(SwigPyObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SwigPyObject_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ -#if PY_VERSION_HEX >= 0x03000000 - 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ -#else - (cmpfunc)SwigPyObject_compare, /* tp_compare */ -#endif - (reprfunc)SwigPyObject_repr, /* tp_repr */ - &SwigPyObject_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigobject_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - swigobject_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - 0, /* tp_del */ - 0, /* tp_version_tag */ -#if PY_VERSION_HEX >= 0x03040000 - 0, /* tp_finalize */ -#endif -#ifdef COUNT_ALLOCS - 0, /* tp_allocs */ - 0, /* tp_frees */ - 0, /* tp_maxalloc */ - 0, /* tp_prev */ - 0 /* tp_next */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* nb_inplace_add -> nb_index */ #endif }; - swigpyobject_type = tmp; - type_init = 1; - if (PyType_Ready(&swigpyobject_type) < 0) - return NULL; - } - return &swigpyobject_type; + + static PyTypeObject swigpyobject_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp = { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(NULL, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + "SwigPyObject", /* tp_name */ + sizeof(SwigPyObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyObject_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ +#if PY_VERSION_HEX >= 0x03000000 + 0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */ +#else + (cmpfunc)SwigPyObject_compare, /* tp_compare */ +#endif + (reprfunc)SwigPyObject_repr, /* tp_repr */ + &SwigPyObject_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + 0, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigobject_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + (richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + swigobject_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ + 0, /* tp_del */ + 0, /* tp_version_tag */ +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#ifdef COUNT_ALLOCS + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ + 0, /* tp_prev */ + 0 /* tp_next */ +#endif + }; + swigpyobject_type = tmp; + type_init = 1; + if (PyType_Ready(&swigpyobject_type) < 0) + return NULL; + } + return &swigpyobject_type; } SWIGRUNTIME PyObject * -SwigPyObject_New(void *ptr, swig_type_info *ty, int own) -{ - SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type()); - if (sobj) { - sobj->ptr = ptr; - sobj->ty = ty; - sobj->own = own; - sobj->next = 0; - } - return (PyObject *)sobj; +SwigPyObject_New(void *ptr, swig_type_info *ty, int own) { + SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type()); + if (sobj) { + sobj->ptr = ptr; + sobj->ty = ty; + sobj->own = own; + sobj->next = 0; + } + return (PyObject *)sobj; } /* ----------------------------------------------------------------------------- @@ -1766,179 +1740,173 @@ SwigPyObject_New(void *ptr, swig_type_info *ty, int own) * ----------------------------------------------------------------------------- */ typedef struct { - PyObject_HEAD - void *pack; - swig_type_info *ty; - size_t size; + PyObject_HEAD + void *pack; + swig_type_info *ty; + size_t size; } SwigPyPacked; SWIGRUNTIME PyObject * -SwigPyPacked_repr(SwigPyPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - return SWIG_Python_str_FromFormat("", result, v->ty->name); - } else { - return SWIG_Python_str_FromFormat("", v->ty->name); - } +SwigPyPacked_repr(SwigPyPacked *v) { + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + return SWIG_Python_str_FromFormat("", result, v->ty->name); + } else { + return SWIG_Python_str_FromFormat("", v->ty->name); + } } SWIGRUNTIME PyObject * -SwigPyPacked_str(SwigPyPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ - return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); - } else { - return SWIG_Python_str_FromChar(v->ty->name); - } +SwigPyPacked_str(SwigPyPacked *v) { + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name); + } else { + return SWIG_Python_str_FromChar(v->ty->name); + } } SWIGRUNTIME int -SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) -{ - size_t i = v->size; - size_t j = w->size; - int s = (i < j) ? -1 : ((i > j) ? 1 : 0); - return s ? s : strncmp((const char *)v->pack, (const char *)w->pack, 2*v->size); +SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w) { + size_t i = v->size; + size_t j = w->size; + int s = (i < j) ? -1 : ((i > j) ? 1 : 0); + return s ? s : strncmp((const char *)v->pack, (const char *)w->pack, 2 * v->size); } -SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void); +SWIGRUNTIME PyTypeObject *SwigPyPacked_TypeOnce(void); -SWIGRUNTIME PyTypeObject* +SWIGRUNTIME PyTypeObject * SwigPyPacked_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce(); - return type; + static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce(); + return type; } SWIGRUNTIMEINLINE int SwigPyPacked_Check(PyObject *op) { - return ((op)->ob_type == SwigPyPacked_TypeOnce()) - || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0); + return ((op)->ob_type == SwigPyPacked_TypeOnce()) + || (strcmp((op)->ob_type->tp_name, "SwigPyPacked") == 0); } SWIGRUNTIME void -SwigPyPacked_dealloc(PyObject *v) -{ - if (SwigPyPacked_Check(v)) { - SwigPyPacked *sobj = (SwigPyPacked *) v; - free(sobj->pack); - } - PyObject_DEL(v); +SwigPyPacked_dealloc(PyObject *v) { + if (SwigPyPacked_Check(v)) { + SwigPyPacked *sobj = (SwigPyPacked *) v; + free(sobj->pack); + } + PyObject_DEL(v); } -SWIGRUNTIME PyTypeObject* +SWIGRUNTIME PyTypeObject * SwigPyPacked_TypeOnce(void) { - static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; - static PyTypeObject swigpypacked_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp = { + static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; + static PyTypeObject swigpypacked_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp = { #if PY_VERSION_HEX>=0x03000000 - PyVarObject_HEAD_INIT(NULL, 0) + PyVarObject_HEAD_INIT(NULL, 0) #else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ #endif - "SwigPyPacked", /* tp_name */ - sizeof(SwigPyPacked), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ + "SwigPyPacked", /* tp_name */ + sizeof(SwigPyPacked), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)SwigPyPacked_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ #if PY_VERSION_HEX>=0x03000000 - 0, /* tp_reserved in 3.0.1 */ + 0, /* tp_reserved in 3.0.1 */ #else - (cmpfunc)SwigPyPacked_compare, /* tp_compare */ + (cmpfunc)SwigPyPacked_compare, /* tp_compare */ #endif - (reprfunc)SwigPyPacked_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)SwigPyPacked_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigpacked_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ - 0, /* tp_del */ - 0, /* tp_version_tag */ + (reprfunc)SwigPyPacked_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)SwigPyPacked_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigpacked_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ + 0, /* tp_del */ + 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 - 0, /* tp_finalize */ + 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0, /* tp_allocs */ - 0, /* tp_frees */ - 0, /* tp_maxalloc */ - 0, /* tp_prev */ - 0 /* tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ + 0, /* tp_prev */ + 0 /* tp_next */ #endif - }; - swigpypacked_type = tmp; - type_init = 1; - if (PyType_Ready(&swigpypacked_type) < 0) - return NULL; - } - return &swigpypacked_type; + }; + swigpypacked_type = tmp; + type_init = 1; + if (PyType_Ready(&swigpypacked_type) < 0) + return NULL; + } + return &swigpypacked_type; } SWIGRUNTIME PyObject * -SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) -{ - SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type()); - if (sobj) { - void *pack = malloc(size); - if (pack) { - memcpy(pack, ptr, size); - sobj->pack = pack; - sobj->ty = ty; - sobj->size = size; - } else { - PyObject_DEL((PyObject *) sobj); - sobj = 0; +SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty) { + SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type()); + if (sobj) { + void *pack = malloc(size); + if (pack) { + memcpy(pack, ptr, size); + sobj->pack = pack; + sobj->ty = ty; + sobj->size = size; + } else { + PyObject_DEL((PyObject *) sobj); + sobj = 0; + } } - } - return (PyObject *) sobj; + return (PyObject *) sobj; } SWIGRUNTIME swig_type_info * -SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) -{ - if (SwigPyPacked_Check(obj)) { - SwigPyPacked *sobj = (SwigPyPacked *)obj; - if (sobj->size != size) return 0; - memcpy(ptr, sobj->pack, size); - return sobj->ty; - } else { - return 0; - } +SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) { + if (SwigPyPacked_Check(obj)) { + SwigPyPacked *sobj = (SwigPyPacked *)obj; + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; + } else { + return 0; + } } /* ----------------------------------------------------------------------------- @@ -1948,81 +1916,79 @@ SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size) static PyObject *Swig_This_global = NULL; SWIGRUNTIME PyObject * -SWIG_This(void) -{ - if (Swig_This_global == NULL) - Swig_This_global = SWIG_Python_str_FromChar("this"); - return Swig_This_global; +SWIG_This(void) { + if (Swig_This_global == NULL) + Swig_This_global = SWIG_Python_str_FromChar("this"); + return Swig_This_global; } /* #define SWIG_PYTHON_SLOW_GETSET_THIS */ /* TODO: I don't know how to implement the fast getset in Python 3 right now */ #if PY_VERSION_HEX>=0x03000000 -#define SWIG_PYTHON_SLOW_GETSET_THIS +#define SWIG_PYTHON_SLOW_GETSET_THIS #endif SWIGRUNTIME SwigPyObject * -SWIG_Python_GetSwigThis(PyObject *pyobj) -{ - PyObject *obj; +SWIG_Python_GetSwigThis(PyObject *pyobj) { + PyObject *obj; - if (SwigPyObject_Check(pyobj)) - return (SwigPyObject *) pyobj; + if (SwigPyObject_Check(pyobj)) + return (SwigPyObject *) pyobj; #ifdef SWIGPYTHON_BUILTIN - (void)obj; + (void)obj; # ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - pyobj = PyWeakref_GET_OBJECT(pyobj); - if (pyobj && SwigPyObject_Check(pyobj)) - return (SwigPyObject*) pyobj; - } + if (PyWeakref_CheckProxy(pyobj)) { + pyobj = PyWeakref_GET_OBJECT(pyobj); + if (pyobj && SwigPyObject_Check(pyobj)) + return (SwigPyObject *) pyobj; + } # endif - return NULL; + return NULL; #else - obj = 0; + obj = 0; #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - if (PyInstance_Check(pyobj)) { - obj = _PyInstance_Lookup(pyobj, SWIG_This()); - } else { - PyObject **dictptr = _PyObject_GetDictPtr(pyobj); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; + if (PyInstance_Check(pyobj)) { + obj = _PyInstance_Lookup(pyobj, SWIG_This()); } else { + PyObject **dictptr = _PyObject_GetDictPtr(pyobj); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; + } else { #ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); - return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; - } + if (PyWeakref_CheckProxy(pyobj)) { + PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); + return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; + } #endif - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } + obj = PyObject_GetAttr(pyobj, SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } + } } - } #else - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } + obj = PyObject_GetAttr(pyobj, SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } #endif - if (obj && !SwigPyObject_Check(obj)) { - /* a PyObject is called 'this', try to get the 'real this' - SwigPyObject from it */ - return SWIG_Python_GetSwigThis(obj); - } - return (SwigPyObject *)obj; + if (obj && !SwigPyObject_Check(obj)) { + /* a PyObject is called 'this', try to get the 'real this' + SwigPyObject from it */ + return SWIG_Python_GetSwigThis(obj); + } + return (SwigPyObject *)obj; #endif } @@ -2030,166 +1996,166 @@ SWIG_Python_GetSwigThis(PyObject *pyobj) SWIGRUNTIME int SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own == SWIG_POINTER_OWN) { - SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); - if (sobj) { - int oldown = sobj->own; - sobj->own = own; - return oldown; + if (own == SWIG_POINTER_OWN) { + SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj); + if (sobj) { + int oldown = sobj->own; + sobj->own = own; + return oldown; + } } - } - return 0; + return 0; } /* Convert a pointer value */ SWIGRUNTIME int SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { - int res; - SwigPyObject *sobj; - int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0; + int res; + SwigPyObject *sobj; + int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0; - if (!obj) - return SWIG_ERROR; - if (obj == Py_None && !implicit_conv) { - if (ptr) - *ptr = 0; - return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; - } - - res = SWIG_ERROR; - - sobj = SWIG_Python_GetSwigThis(obj); - if (own) - *own = 0; - while (sobj) { - void *vptr = sobj->ptr; - if (ty) { - swig_type_info *to = sobj->ty; - if (to == ty) { - /* no type cast needed */ - if (ptr) *ptr = vptr; - break; - } else { - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) { - sobj = (SwigPyObject *)sobj->next; - } else { - if (ptr) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - if (newmemory == SWIG_CAST_NEW_MEMORY) { - assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ - if (own) - *own = *own | SWIG_CAST_NEW_MEMORY; - } - } - break; - } - } - } else { - if (ptr) *ptr = vptr; - break; - } - } - if (sobj) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) { - sobj->own = 0; - } - res = SWIG_OK; - } else { - if (implicit_conv) { - SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; - if (data && !data->implicitconv) { - PyObject *klass = data->klass; - if (klass) { - PyObject *impconv; - data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ - impconv = SWIG_Python_CallFunctor(klass, obj); - data->implicitconv = 0; - if (PyErr_Occurred()) { - PyErr_Clear(); - impconv = 0; - } - if (impconv) { - SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); - if (iobj) { - void *vptr; - res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); - if (SWIG_IsOK(res)) { - if (ptr) { - *ptr = vptr; - /* transfer the ownership to 'ptr' */ - iobj->own = 0; - res = SWIG_AddCast(res); - res = SWIG_AddNewMask(res); - } else { - res = SWIG_AddCast(res); - } - } - } - Py_DECREF(impconv); - } - } - } - if (!SWIG_IsOK(res) && obj == Py_None) { + if (!obj) + return SWIG_ERROR; + if (obj == Py_None && !implicit_conv) { if (ptr) - *ptr = 0; - if (PyErr_Occurred()) - PyErr_Clear(); - res = SWIG_OK; - } + *ptr = 0; + return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } - } - return res; + + res = SWIG_ERROR; + + sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; + while (sobj) { + void *vptr = sobj->ptr; + if (ty) { + swig_type_info *to = sobj->ty; + if (to == ty) { + /* no type cast needed */ + if (ptr) *ptr = vptr; + break; + } else { + swig_cast_info *tc = SWIG_TypeCheck(to->name, ty); + if (!tc) { + sobj = (SwigPyObject *)sobj->next; + } else { + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc, vptr, &newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } + break; + } + } + } else { + if (ptr) *ptr = vptr; + break; + } + } + if (sobj) { + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) { + sobj->own = 0; + } + res = SWIG_OK; + } else { + if (implicit_conv) { + SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0; + if (data && !data->implicitconv) { + PyObject *klass = data->klass; + if (klass) { + PyObject *impconv; + data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ + impconv = SWIG_Python_CallFunctor(klass, obj); + data->implicitconv = 0; + if (PyErr_Occurred()) { + PyErr_Clear(); + impconv = 0; + } + if (impconv) { + SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv); + if (iobj) { + void *vptr; + res = SWIG_Python_ConvertPtrAndOwn((PyObject *)iobj, &vptr, ty, 0, 0); + if (SWIG_IsOK(res)) { + if (ptr) { + *ptr = vptr; + /* transfer the ownership to 'ptr' */ + iobj->own = 0; + res = SWIG_AddCast(res); + res = SWIG_AddNewMask(res); + } else { + res = SWIG_AddCast(res); + } + } + } + Py_DECREF(impconv); + } + } + } + if (!SWIG_IsOK(res) && obj == Py_None) { + if (ptr) + *ptr = 0; + if (PyErr_Occurred()) + PyErr_Clear(); + res = SWIG_OK; + } + } + } + return res; } /* Convert a function ptr value */ SWIGRUNTIME int SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { - if (!PyCFunction_Check(obj)) { - return SWIG_ConvertPtr(obj, ptr, ty, 0); - } else { - void *vptr = 0; - swig_cast_info *tc; - - /* here we get the method pointer for callbacks */ - const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); - const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; - if (desc) - desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; - if (!desc) - return SWIG_ERROR; - tc = SWIG_TypeCheck(desc,ty); - if (tc) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ + if (!PyCFunction_Check(obj)) { + return SWIG_ConvertPtr(obj, ptr, ty, 0); } else { - return SWIG_ERROR; + void *vptr = 0; + swig_cast_info *tc; + + /* here we get the method pointer for callbacks */ + const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); + const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; + if (desc) + desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; + if (!desc) + return SWIG_ERROR; + tc = SWIG_TypeCheck(desc, ty); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc, vptr, &newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } + return SWIG_OK; } - return SWIG_OK; - } } /* Convert a packed pointer value */ SWIGRUNTIME int SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { - swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); - if (!to) return SWIG_ERROR; - if (ty) { - if (to != ty) { - /* check type cast? */ - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) return SWIG_ERROR; + swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz); + if (!to) return SWIG_ERROR; + if (ty) { + if (to != ty) { + /* check type cast? */ + swig_cast_info *tc = SWIG_TypeCheck(to->name, ty); + if (!tc) return SWIG_ERROR; + } } - } - return SWIG_OK; -} + return SWIG_OK; +} /* ----------------------------------------------------------------------------- * Create a new pointer object @@ -2200,157 +2166,155 @@ SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *t 'this' attribute. */ -SWIGRUNTIME PyObject* -SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) -{ - PyObject *inst = 0; - PyObject *newraw = data->newraw; - if (newraw) { - inst = PyObject_Call(newraw, data->newargs, NULL); - if (inst) { -#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - PyDict_SetItem(dict, SWIG_This(), swig_this); - } - } -#else - PyObject *key = SWIG_This(); - PyObject_SetAttr(inst, key, swig_this); -#endif - } - } else { -#if PY_VERSION_HEX >= 0x03000000 - PyObject *empty_args = PyTuple_New(0); - if (empty_args) { - PyObject *empty_kwargs = PyDict_New(); - if (empty_kwargs) { - inst = ((PyTypeObject *)data->newargs)->tp_new((PyTypeObject *)data->newargs, empty_args, empty_kwargs); - Py_DECREF(empty_kwargs); +SWIGRUNTIME PyObject * +SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) { + PyObject *inst = 0; + PyObject *newraw = data->newraw; + if (newraw) { + inst = PyObject_Call(newraw, data->newargs, NULL); if (inst) { - PyObject_SetAttr(inst, SWIG_This(), swig_this); - Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; - } - } - Py_DECREF(empty_args); - } +#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + PyDict_SetItem(dict, SWIG_This(), swig_this); + } + } #else - PyObject *dict = PyDict_New(); - if (dict) { - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - } + PyObject *key = SWIG_This(); + PyObject_SetAttr(inst, key, swig_this); #endif - } - return inst; + } + } else { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *empty_args = PyTuple_New(0); + if (empty_args) { + PyObject *empty_kwargs = PyDict_New(); + if (empty_kwargs) { + inst = ((PyTypeObject *)data->newargs)->tp_new((PyTypeObject *)data->newargs, empty_args, empty_kwargs); + Py_DECREF(empty_kwargs); + if (inst) { + PyObject_SetAttr(inst, SWIG_This(), swig_this); + Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; + } + } + Py_DECREF(empty_args); + } +#else + PyObject *dict = PyDict_New(); + if (dict) { + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + } +#endif + } + return inst; } SWIGRUNTIME void -SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) -{ - PyObject *dict; +SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) { + PyObject *dict; #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - } - PyDict_SetItem(dict, SWIG_This(), swig_this); - return; - } + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + PyDict_SetItem(dict, SWIG_This(), swig_this); + return; + } #endif - dict = PyObject_GetAttrString(inst, "__dict__"); - PyDict_SetItem(dict, SWIG_This(), swig_this); - Py_DECREF(dict); -} + dict = PyObject_GetAttrString(inst, "__dict__"); + PyDict_SetItem(dict, SWIG_This(), swig_this); + Py_DECREF(dict); +} SWIGINTERN PyObject * SWIG_Python_InitShadowInstance(PyObject *args) { - PyObject *obj[2]; - if (!SWIG_Python_UnpackTuple(args, "swiginit", 2, 2, obj)) { - return NULL; - } else { - SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); - if (sthis) { - SwigPyObject_append((PyObject*) sthis, obj[1]); + PyObject *obj[2]; + if (!SWIG_Python_UnpackTuple(args, "swiginit", 2, 2, obj)) { + return NULL; } else { - SWIG_Python_SetSwigThis(obj[0], obj[1]); + SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); + if (sthis) { + SwigPyObject_append((PyObject *) sthis, obj[1]); + } else { + SWIG_Python_SetSwigThis(obj[0], obj[1]); + } + return SWIG_Py_Void(); } - return SWIG_Py_Void(); - } } /* Create a new pointer object */ SWIGRUNTIME PyObject * SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { - SwigPyClientData *clientdata; - PyObject * robj; - int own; + SwigPyClientData *clientdata; + PyObject *robj; + int own; - if (!ptr) - return SWIG_Py_Void(); + if (!ptr) + return SWIG_Py_Void(); - clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; - own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - if (clientdata && clientdata->pytype) { - SwigPyObject *newobj; - if (flags & SWIG_BUILTIN_TP_INIT) { - newobj = (SwigPyObject*) self; - if (newobj->ptr) { - PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0); - while (newobj->next) - newobj = (SwigPyObject *) newobj->next; - newobj->next = next_self; - newobj = (SwigPyObject *)next_self; + clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0; + own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + if (clientdata && clientdata->pytype) { + SwigPyObject *newobj; + if (flags & SWIG_BUILTIN_TP_INIT) { + newobj = (SwigPyObject *) self; + if (newobj->ptr) { + PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0); + while (newobj->next) + newobj = (SwigPyObject *) newobj->next; + newobj->next = next_self; + newobj = (SwigPyObject *)next_self; #ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; + newobj->dict = 0; #endif - } - } else { - newobj = PyObject_New(SwigPyObject, clientdata->pytype); + } + } else { + newobj = PyObject_New(SwigPyObject, clientdata->pytype); #ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; + newobj->dict = 0; #endif + } + if (newobj) { + newobj->ptr = ptr; + newobj->ty = type; + newobj->own = own; + newobj->next = 0; + return (PyObject *) newobj; + } + return SWIG_Py_Void(); } - if (newobj) { - newobj->ptr = ptr; - newobj->ty = type; - newobj->own = own; - newobj->next = 0; - return (PyObject*) newobj; + + assert(!(flags & SWIG_BUILTIN_TP_INIT)); + + robj = SwigPyObject_New(ptr, type, own); + if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { + PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); + Py_DECREF(robj); + robj = inst; } - return SWIG_Py_Void(); - } - - assert(!(flags & SWIG_BUILTIN_TP_INIT)); - - robj = SwigPyObject_New(ptr, type, own); - if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { - PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - Py_DECREF(robj); - robj = inst; - } - return robj; + return robj; } /* Create a new packed object */ SWIGRUNTIMEINLINE PyObject * SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { - return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); + return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); } /* -----------------------------------------------------------------------------* - * Get type list + * Get type list * -----------------------------------------------------------------------------*/ #ifdef SWIG_LINK_RUNTIME @@ -2359,86 +2323,84 @@ void *SWIG_ReturnGlobalTypeList(void *); SWIGRUNTIME swig_module_info * SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { - static void *type_pointer = (void *)0; - /* first check if module already created */ - if (!type_pointer) { + static void *type_pointer = (void *)0; + /* first check if module already created */ + if (!type_pointer) { #ifdef SWIG_LINK_RUNTIME - type_pointer = SWIG_ReturnGlobalTypeList((void *)0); + type_pointer = SWIG_ReturnGlobalTypeList((void *)0); #else - type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); - if (PyErr_Occurred()) { - PyErr_Clear(); - type_pointer = (void *)0; - } + type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); + if (PyErr_Occurred()) { + PyErr_Clear(); + type_pointer = (void *)0; + } #endif - } - return (swig_module_info *) type_pointer; + } + return (swig_module_info *) type_pointer; } SWIGRUNTIME void -SWIG_Python_DestroyModule(PyObject *obj) -{ - swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME); - swig_type_info **types = swig_module->types; - size_t i; - for (i =0; i < swig_module->size; ++i) { - swig_type_info *ty = types[i]; - if (ty->owndata) { - SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; - if (data) SwigPyClientData_Del(data); +SWIG_Python_DestroyModule(PyObject *obj) { + swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME); + swig_type_info **types = swig_module->types; + size_t i; + for (i = 0; i < swig_module->size; ++i) { + swig_type_info *ty = types[i]; + if (ty->owndata) { + SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; + if (data) SwigPyClientData_Del(data); + } } - } - Py_DECREF(SWIG_This()); - Swig_This_global = NULL; + Py_DECREF(SWIG_This()); + Swig_This_global = NULL; } SWIGRUNTIME void SWIG_Python_SetModule(swig_module_info *swig_module) { #if PY_VERSION_HEX >= 0x03000000 - /* Add a dummy module object into sys.modules */ - PyObject *module = PyImport_AddModule("swig_runtime_data" SWIG_RUNTIME_VERSION); + /* Add a dummy module object into sys.modules */ + PyObject *module = PyImport_AddModule("swig_runtime_data" SWIG_RUNTIME_VERSION); #else - static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */ - PyObject *module = Py_InitModule("swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table); + static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */ + PyObject *module = Py_InitModule("swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table); #endif - PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); - if (pointer && module) { - PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer); - } else { - Py_XDECREF(pointer); - } + PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); + if (pointer && module) { + PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer); + } else { + Py_XDECREF(pointer); + } } /* The python cached type query */ SWIGRUNTIME PyObject * SWIG_Python_TypeCache(void) { - static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); - return cache; + static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); + return cache; } SWIGRUNTIME swig_type_info * -SWIG_Python_TypeQuery(const char *type) -{ - PyObject *cache = SWIG_Python_TypeCache(); - PyObject *key = SWIG_Python_str_FromChar(type); - PyObject *obj = PyDict_GetItem(cache, key); - swig_type_info *descriptor; - if (obj) { - descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, NULL); - } else { - swig_module_info *swig_module = SWIG_GetModule(0); - descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); - if (descriptor) { - obj = PyCapsule_New((void*) descriptor, NULL, NULL); - PyDict_SetItem(cache, key, obj); - Py_DECREF(obj); +SWIG_Python_TypeQuery(const char *type) { + PyObject *cache = SWIG_Python_TypeCache(); + PyObject *key = SWIG_Python_str_FromChar(type); + PyObject *obj = PyDict_GetItem(cache, key); + swig_type_info *descriptor; + if (obj) { + descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, NULL); + } else { + swig_module_info *swig_module = SWIG_GetModule(0); + descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); + if (descriptor) { + obj = PyCapsule_New((void *) descriptor, NULL, NULL); + PyDict_SetItem(cache, key, obj); + Py_DECREF(obj); + } } - } - Py_DECREF(key); - return descriptor; + Py_DECREF(key); + return descriptor; } -/* +/* For backward compatibility only */ #define SWIG_POINTER_EXCEPTION 0 @@ -2446,160 +2408,156 @@ SWIG_Python_TypeQuery(const char *type) #define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) SWIGRUNTIME int -SWIG_Python_AddErrMesg(const char* mesg, int infront) -{ - if (PyErr_Occurred()) { - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject *old_str = PyObject_Str(value); - const char *tmp = SWIG_Python_str_AsChar(old_str); - const char *errmesg = tmp ? tmp : "Invalid error message"; - Py_XINCREF(type); - PyErr_Clear(); - if (infront) { - PyErr_Format(type, "%s %s", mesg, errmesg); - } else { - PyErr_Format(type, "%s %s", errmesg, mesg); - } - SWIG_Python_str_DelForPy3(tmp); - Py_DECREF(old_str); +SWIG_Python_AddErrMesg(const char *mesg, int infront) { + if (PyErr_Occurred()) { + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + PyErr_Fetch(&type, &value, &traceback); + if (value) { + PyObject *old_str = PyObject_Str(value); + const char *tmp = SWIG_Python_str_AsChar(old_str); + const char *errmesg = tmp ? tmp : "Invalid error message"; + Py_XINCREF(type); + PyErr_Clear(); + if (infront) { + PyErr_Format(type, "%s %s", mesg, errmesg); + } else { + PyErr_Format(type, "%s %s", errmesg, mesg); + } + SWIG_Python_str_DelForPy3(tmp); + Py_DECREF(old_str); + } + return 1; + } else { + return 0; } - return 1; - } else { - return 0; - } } - + SWIGRUNTIME int -SWIG_Python_ArgFail(int argnum) -{ - if (PyErr_Occurred()) { - /* add information about failing argument */ - char mesg[256]; - PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); - return SWIG_Python_AddErrMesg(mesg, 1); - } else { - return 0; - } +SWIG_Python_ArgFail(int argnum) { + if (PyErr_Occurred()) { + /* add information about failing argument */ + char mesg[256]; + PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); + return SWIG_Python_AddErrMesg(mesg, 1); + } else { + return 0; + } } SWIGRUNTIMEINLINE const char * -SwigPyObject_GetDesc(PyObject *self) -{ - SwigPyObject *v = (SwigPyObject *)self; - swig_type_info *ty = v ? v->ty : 0; - return ty ? ty->str : ""; +SwigPyObject_GetDesc(PyObject *self) { + SwigPyObject *v = (SwigPyObject *)self; + swig_type_info *ty = v ? v->ty : 0; + return ty ? ty->str : ""; } SWIGRUNTIME void -SWIG_Python_TypeError(const char *type, PyObject *obj) -{ - if (type) { +SWIG_Python_TypeError(const char *type, PyObject *obj) { + if (type) { #if defined(SWIG_COBJECT_TYPES) - if (obj && SwigPyObject_Check(obj)) { - const char *otype = (const char *) SwigPyObject_GetDesc(obj); - if (otype) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", - type, otype); - return; - } - } else -#endif - { - const char *otype = (obj ? obj->ob_type->tp_name : 0); - if (otype) { - PyObject *str = PyObject_Str(obj); - const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0; - if (cstr) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", - type, otype, cstr); - SWIG_Python_str_DelForPy3(cstr); - } else { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", - type, otype); - } - Py_XDECREF(str); - return; - } - } - PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); - } else { - PyErr_Format(PyExc_TypeError, "unexpected type is received"); - } + if (obj && SwigPyObject_Check(obj)) { + const char *otype = (const char *) SwigPyObject_GetDesc(obj); + if (otype) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received", + type, otype); + return; + } + } else +#endif + { + const char *otype = (obj ? obj->ob_type->tp_name : 0); + if (otype) { + PyObject *str = PyObject_Str(obj); + const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0; + if (cstr) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", + type, otype, cstr); + SWIG_Python_str_DelForPy3(cstr); + } else { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", + type, otype); + } + Py_XDECREF(str); + return; + } + } + PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); + } else { + PyErr_Format(PyExc_TypeError, "unexpected type is received"); + } } /* Convert a pointer value, signal an exception on a type mismatch */ SWIGRUNTIME void * SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) { - void *result; - if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { - PyErr_Clear(); + void *result; + if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { + PyErr_Clear(); #if SWIG_POINTER_EXCEPTION - if (flags) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - SWIG_Python_ArgFail(argnum); - } + if (flags) { + SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); + SWIG_Python_ArgFail(argnum); + } #endif - } - return result; + } + return result; } #ifdef SWIGPYTHON_BUILTIN SWIGRUNTIME int SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { - PyTypeObject *tp = obj->ob_type; - PyObject *descr; - PyObject *encoded_name; - descrsetfunc f; - int res = -1; + PyTypeObject *tp = obj->ob_type; + PyObject *descr; + PyObject *encoded_name; + descrsetfunc f; + int res = -1; # ifdef Py_USING_UNICODE - if (PyString_Check(name)) { - name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); - if (!name) - return -1; - } else if (!PyUnicode_Check(name)) -# else - if (!PyString_Check(name)) -# endif - { - PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); - return -1; - } else { - Py_INCREF(name); - } - - if (!tp->tp_dict) { - if (PyType_Ready(tp) < 0) - goto done; - } - - descr = _PyType_Lookup(tp, name); - f = NULL; - if (descr != NULL) - f = descr->ob_type->tp_descr_set; - if (!f) { if (PyString_Check(name)) { - encoded_name = name; - Py_INCREF(name); - } else { - encoded_name = PyUnicode_AsUTF8String(name); - if (!encoded_name) + name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL); + if (!name) + return -1; + } else if (!PyUnicode_Check(name)) +# else + if (!PyString_Check(name)) +# endif + { + PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); return -1; + } else { + Py_INCREF(name); } - PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); - Py_DECREF(encoded_name); - } else { - res = f(descr, obj, value); - } - - done: - Py_DECREF(name); - return res; + + if (!tp->tp_dict) { + if (PyType_Ready(tp) < 0) + goto done; + } + + descr = _PyType_Lookup(tp, name); + f = NULL; + if (descr != NULL) + f = descr->ob_type->tp_descr_set; + if (!f) { + if (PyString_Check(name)) { + encoded_name = name; + Py_INCREF(name); + } else { + encoded_name = PyUnicode_AsUTF8String(name); + if (!encoded_name) + return -1; + } + PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); + Py_DECREF(encoded_name); + } else { + res = f(descr, obj, value); + } + +done: + Py_DECREF(name); + return res; } #endif @@ -2610,9 +2568,9 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { -#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) +#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) -#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else +#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else @@ -2659,397 +2617,395 @@ static swig_module_info swig_module = {swig_types, 2, 0, 0, 0, 0}; #endif #define SWIG_name "_pm3" -#define SWIGVERSION 0x040001 +#define SWIGVERSION 0x040001 #define SWIG_VERSION SWIGVERSION -#define SWIG_as_voidptr(a) (void *)((const void *)(a)) -#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) +#define SWIG_as_voidptr(a) (void *)((const void *)(a)) +#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) /* Include the header in the wrapper code */ #include "pm3.h" #include "comms.h" -SWIGINTERN pm3 *new_pm3__SWIG_0(void){ +SWIGINTERN pm3 *new_pm3__SWIG_0(void) { // printf("SWIG pm3 constructor, get current pm3\n"); - pm3_device * p = pm3_get_current_dev(); - p->script_embedded = 1; - return p; - } + pm3_device *p = pm3_get_current_dev(); + p->script_embedded = 1; + return p; +} -SWIGINTERN swig_type_info* -SWIG_pchar_descriptor(void) -{ - static int init = 0; - static swig_type_info* info = 0; - if (!init) { - info = SWIG_TypeQuery("_p_char"); - init = 1; - } - return info; +SWIGINTERN swig_type_info * +SWIG_pchar_descriptor(void) { + static int init = 0; + static swig_type_info *info = 0; + if (!init) { + info = SWIG_TypeQuery("_p_char"); + init = 1; + } + return info; } SWIGINTERN int -SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) -{ +SWIG_AsCharPtrAndSize(PyObject *obj, char **cptr, size_t *psize, int *alloc) { #if PY_VERSION_HEX>=0x03000000 #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - if (PyBytes_Check(obj)) + if (PyBytes_Check(obj)) #else - if (PyUnicode_Check(obj)) + if (PyUnicode_Check(obj)) #endif -#else - if (PyString_Check(obj)) +#else + if (PyString_Check(obj)) #endif - { - char *cstr; Py_ssize_t len; - int ret = SWIG_OK; + { + char *cstr; + Py_ssize_t len; + int ret = SWIG_OK; #if PY_VERSION_HEX>=0x03000000 #if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - if (!alloc && cptr) { - /* We can't allow converting without allocation, since the internal - representation of string in Python 3 is UCS-2/UCS-4 but we require - a UTF-8 representation. - TODO(bhy) More detailed explanation */ - return SWIG_RuntimeError; - } - obj = PyUnicode_AsUTF8String(obj); - if (!obj) - return SWIG_TypeError; - if (alloc) - *alloc = SWIG_NEWOBJ; + if (!alloc && cptr) { + /* We can't allow converting without allocation, since the internal + representation of string in Python 3 is UCS-2/UCS-4 but we require + a UTF-8 representation. + TODO(bhy) More detailed explanation */ + return SWIG_RuntimeError; + } + obj = PyUnicode_AsUTF8String(obj); + if (!obj) + return SWIG_TypeError; + if (alloc) + *alloc = SWIG_NEWOBJ; #endif - PyBytes_AsStringAndSize(obj, &cstr, &len); + PyBytes_AsStringAndSize(obj, &cstr, &len); #else - PyString_AsStringAndSize(obj, &cstr, &len); + PyString_AsStringAndSize(obj, &cstr, &len); #endif - if (cptr) { - if (alloc) { - if (*alloc == SWIG_NEWOBJ) { - *cptr = (char *)memcpy(malloc((len + 1)*sizeof(char)), cstr, sizeof(char)*(len + 1)); - *alloc = SWIG_NEWOBJ; - } else { - *cptr = cstr; - *alloc = SWIG_OLDOBJ; - } - } else { + if (cptr) { + if (alloc) { + if (*alloc == SWIG_NEWOBJ) { + *cptr = (char *)memcpy(malloc((len + 1) * sizeof(char)), cstr, sizeof(char) * (len + 1)); + *alloc = SWIG_NEWOBJ; + } else { + *cptr = cstr; + *alloc = SWIG_OLDOBJ; + } + } else { #if PY_VERSION_HEX>=0x03000000 #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - *cptr = PyBytes_AsString(obj); + *cptr = PyBytes_AsString(obj); #else - assert(0); /* Should never reach here with Unicode strings in Python 3 */ + assert(0); /* Should never reach here with Unicode strings in Python 3 */ #endif #else - *cptr = SWIG_Python_str_AsChar(obj); - if (!*cptr) - ret = SWIG_TypeError; + *cptr = SWIG_Python_str_AsChar(obj); + if (!*cptr) + ret = SWIG_TypeError; #endif - } - } - if (psize) *psize = len + 1; + } + } + if (psize) *psize = len + 1; #if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - Py_XDECREF(obj); + Py_XDECREF(obj); #endif - return ret; - } else { + return ret; + } else { #if defined(SWIG_PYTHON_2_UNICODE) #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) #error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once" #endif #if PY_VERSION_HEX<0x03000000 - if (PyUnicode_Check(obj)) { - char *cstr; Py_ssize_t len; - if (!alloc && cptr) { - return SWIG_RuntimeError; - } - obj = PyUnicode_AsUTF8String(obj); - if (!obj) - return SWIG_TypeError; - if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) { - if (cptr) { - if (alloc) *alloc = SWIG_NEWOBJ; - *cptr = (char *)memcpy(malloc((len + 1)*sizeof(char)), cstr, sizeof(char)*(len + 1)); + if (PyUnicode_Check(obj)) { + char *cstr; + Py_ssize_t len; + if (!alloc && cptr) { + return SWIG_RuntimeError; + } + obj = PyUnicode_AsUTF8String(obj); + if (!obj) + return SWIG_TypeError; + if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) { + if (cptr) { + if (alloc) *alloc = SWIG_NEWOBJ; + *cptr = (char *)memcpy(malloc((len + 1) * sizeof(char)), cstr, sizeof(char) * (len + 1)); + } + if (psize) *psize = len + 1; + + Py_XDECREF(obj); + return SWIG_OK; + } else { + Py_XDECREF(obj); + } } - if (psize) *psize = len + 1; - - Py_XDECREF(obj); - return SWIG_OK; - } else { - Py_XDECREF(obj); - } - } #endif #endif - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - if (pchar_descriptor) { - void* vptr = 0; - if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { - if (cptr) *cptr = (char *) vptr; - if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; - if (alloc) *alloc = SWIG_OLDOBJ; - return SWIG_OK; - } + swig_type_info *pchar_descriptor = SWIG_pchar_descriptor(); + if (pchar_descriptor) { + void *vptr = 0; + if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { + if (cptr) *cptr = (char *) vptr; + if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; + if (alloc) *alloc = SWIG_OLDOBJ; + return SWIG_OK; + } + } } - } - return SWIG_TypeError; + return SWIG_TypeError; } -SWIGINTERN pm3 *new_pm3__SWIG_1(char *port){ +SWIGINTERN pm3 *new_pm3__SWIG_1(char *port) { // printf("SWIG pm3 constructor with port, open pm3\n"); - pm3_device * p = pm3_open(port); - p->script_embedded = 0; - return p; - } -SWIGINTERN void delete_pm3(pm3 *self){ - if (self->script_embedded) { + pm3_device *p = pm3_open(port); + p->script_embedded = 0; + return p; +} +SWIGINTERN void delete_pm3(pm3 *self) { + if (self->script_embedded) { // printf("SWIG pm3 destructor, nothing to do\n"); - } else { + } else { // printf("SWIG pm3 destructor, close pm3\n"); - pm3_close(self); - } - } + pm3_close(self); + } +} -SWIGINTERNINLINE PyObject* - SWIG_From_int (int value) -{ - return PyInt_FromLong((long) value); +SWIGINTERNINLINE PyObject * +SWIG_From_int(int value) { + return PyInt_FromLong((long) value); } SWIGINTERNINLINE PyObject * -SWIG_FromCharPtrAndSize(const char* carray, size_t size) -{ - if (carray) { - if (size > INT_MAX) { - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - return pchar_descriptor ? - SWIG_InternalNewPointerObj((char *)(carray), pchar_descriptor, 0) : SWIG_Py_Void(); - } else { +SWIG_FromCharPtrAndSize(const char *carray, size_t size) { + if (carray) { + if (size > INT_MAX) { + swig_type_info *pchar_descriptor = SWIG_pchar_descriptor(); + return pchar_descriptor ? + SWIG_InternalNewPointerObj((char *)(carray), pchar_descriptor, 0) : SWIG_Py_Void(); + } else { #if PY_VERSION_HEX >= 0x03000000 #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR) - return PyBytes_FromStringAndSize(carray, (Py_ssize_t)(size)); + return PyBytes_FromStringAndSize(carray, (Py_ssize_t)(size)); #else - return PyUnicode_DecodeUTF8(carray, (Py_ssize_t)(size), "surrogateescape"); + return PyUnicode_DecodeUTF8(carray, (Py_ssize_t)(size), "surrogateescape"); #endif #else - return PyString_FromStringAndSize(carray, (Py_ssize_t)(size)); + return PyString_FromStringAndSize(carray, (Py_ssize_t)(size)); #endif + } + } else { + return SWIG_Py_Void(); } - } else { - return SWIG_Py_Void(); - } } -SWIGINTERNINLINE PyObject * -SWIG_FromCharPtr(const char *cptr) -{ - return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); +SWIGINTERNINLINE PyObject * +SWIG_FromCharPtr(const char *cptr) { + return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); } #ifdef __cplusplus extern "C" { #endif SWIGINTERN PyObject *_wrap_new_pm3__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) { - PyObject *resultobj = 0; - pm3 *result = 0 ; - - if ((nobjs < 0) || (nobjs > 0)) SWIG_fail; - result = (pm3 *)new_pm3__SWIG_0(); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_pm3, SWIG_POINTER_NEW | 0 ); - return resultobj; + PyObject *resultobj = 0; + pm3 *result = 0 ; + + if ((nobjs < 0) || (nobjs > 0)) SWIG_fail; + result = (pm3 *)new_pm3__SWIG_0(); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_pm3, SWIG_POINTER_NEW | 0); + return resultobj; fail: - return NULL; + return NULL; } SWIGINTERN PyObject *_wrap_new_pm3__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) { - PyObject *resultobj = 0; - char *arg1 = (char *) 0 ; - int res1 ; - char *buf1 = 0 ; - int alloc1 = 0 ; - pm3 *result = 0 ; - - if ((nobjs < 1) || (nobjs > 1)) SWIG_fail; - res1 = SWIG_AsCharPtrAndSize(swig_obj[0], &buf1, NULL, &alloc1); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_pm3" "', argument " "1"" of type '" "char *""'"); - } - arg1 = (char *)(buf1); - result = (pm3 *)new_pm3__SWIG_1(arg1); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_pm3, SWIG_POINTER_NEW | 0 ); - if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); - return resultobj; + PyObject *resultobj = 0; + char *arg1 = (char *) 0 ; + int res1 ; + char *buf1 = 0 ; + int alloc1 = 0 ; + pm3 *result = 0 ; + + if ((nobjs < 1) || (nobjs > 1)) SWIG_fail; + res1 = SWIG_AsCharPtrAndSize(swig_obj[0], &buf1, NULL, &alloc1); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_pm3" "', argument " "1"" of type '" "char *""'"); + } + arg1 = (char *)(buf1); + result = (pm3 *)new_pm3__SWIG_1(arg1); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_pm3, SWIG_POINTER_NEW | 0); + if (alloc1 == SWIG_NEWOBJ) free((char *)buf1); + return resultobj; fail: - if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); - return NULL; + if (alloc1 == SWIG_NEWOBJ) free((char *)buf1); + return NULL; } SWIGINTERN PyObject *_wrap_new_pm3(PyObject *self, PyObject *args) { - Py_ssize_t argc; - PyObject *argv[2] = { - 0 - }; - - if (!(argc = SWIG_Python_UnpackTuple(args, "new_pm3", 0, 1, argv))) SWIG_fail; - --argc; - if (argc == 0) { - return _wrap_new_pm3__SWIG_0(self, argc, argv); - } - if (argc == 1) { - int _v; - int res = SWIG_AsCharPtrAndSize(argv[0], 0, NULL, 0); - _v = SWIG_CheckState(res); - if (_v) { - return _wrap_new_pm3__SWIG_1(self, argc, argv); + Py_ssize_t argc; + PyObject *argv[2] = { + 0 + }; + + if (!(argc = SWIG_Python_UnpackTuple(args, "new_pm3", 0, 1, argv))) SWIG_fail; + --argc; + if (argc == 0) { + return _wrap_new_pm3__SWIG_0(self, argc, argv); } - } - + if (argc == 1) { + int _v; + int res = SWIG_AsCharPtrAndSize(argv[0], 0, NULL, 0); + _v = SWIG_CheckState(res); + if (_v) { + return _wrap_new_pm3__SWIG_1(self, argc, argv); + } + } + fail: - SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_pm3'.\n" - " Possible C/C++ prototypes are:\n" - " pm3::pm3()\n" - " pm3::pm3(char *)\n"); - return 0; + SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_pm3'.\n" + " Possible C/C++ prototypes are:\n" + " pm3::pm3()\n" + " pm3::pm3(char *)\n"); + return 0; } SWIGINTERN PyObject *_wrap_delete_pm3(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - pm3 *arg1 = (pm3 *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_pm3, SWIG_POINTER_DISOWN | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_pm3" "', argument " "1"" of type '" "pm3 *""'"); - } - arg1 = (pm3 *)(argp1); - delete_pm3(arg1); - resultobj = SWIG_Py_Void(); - return resultobj; + PyObject *resultobj = 0; + pm3 *arg1 = (pm3 *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_pm3, SWIG_POINTER_DISOWN | 0); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_pm3" "', argument " "1"" of type '" "pm3 *""'"); + } + arg1 = (pm3 *)(argp1); + delete_pm3(arg1); + resultobj = SWIG_Py_Void(); + return resultobj; fail: - return NULL; + return NULL; } SWIGINTERN PyObject *_wrap_pm3_console(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - pm3 *arg1 = (pm3 *) 0 ; - char *arg2 = (char *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - int res2 ; - char *buf2 = 0 ; - int alloc2 = 0 ; - PyObject *swig_obj[2] ; - int result; - - if (!SWIG_Python_UnpackTuple(args, "pm3_console", 2, 2, swig_obj)) SWIG_fail; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_pm3, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "pm3_console" "', argument " "1"" of type '" "pm3 *""'"); - } - arg1 = (pm3 *)(argp1); - res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "pm3_console" "', argument " "2"" of type '" "char *""'"); - } - arg2 = (char *)(buf2); - result = (int)pm3_console(arg1,arg2); - resultobj = SWIG_From_int((int)(result)); - if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); - return resultobj; + PyObject *resultobj = 0; + pm3 *arg1 = (pm3 *) 0 ; + char *arg2 = (char *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + PyObject *swig_obj[2] ; + int result; + + if (!SWIG_Python_UnpackTuple(args, "pm3_console", 2, 2, swig_obj)) SWIG_fail; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_pm3, 0 | 0); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "pm3_console" "', argument " "1"" of type '" "pm3 *""'"); + } + arg1 = (pm3 *)(argp1); + res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "pm3_console" "', argument " "2"" of type '" "char *""'"); + } + arg2 = (char *)(buf2); + result = (int)pm3_console(arg1, arg2); + resultobj = SWIG_From_int((int)(result)); + if (alloc2 == SWIG_NEWOBJ) free((char *)buf2); + return resultobj; fail: - if (alloc2 == SWIG_NEWOBJ) free((char*)buf2); - return NULL; + if (alloc2 == SWIG_NEWOBJ) free((char *)buf2); + return NULL; } SWIGINTERN PyObject *_wrap_pm3_name_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *resultobj = 0; - pm3 *arg1 = (pm3 *) 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject *swig_obj[1] ; - char *result = 0 ; - - if (!args) SWIG_fail; - swig_obj[0] = args; - res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_pm3, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "pm3_name_get" "', argument " "1"" of type '" "pm3 *""'"); - } - arg1 = (pm3 *)(argp1); - result = (char *)pm3_name_get(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); - return resultobj; + PyObject *resultobj = 0; + pm3 *arg1 = (pm3 *) 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + PyObject *swig_obj[1] ; + char *result = 0 ; + + if (!args) SWIG_fail; + swig_obj[0] = args; + res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_pm3, 0 | 0); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "pm3_name_get" "', argument " "1"" of type '" "pm3 *""'"); + } + arg1 = (pm3 *)(argp1); + result = (char *)pm3_name_get(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; fail: - return NULL; + return NULL; } SWIGINTERN PyObject *pm3_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - PyObject *obj; - if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; - SWIG_TypeNewClientData(SWIGTYPE_p_pm3, SWIG_NewClientData(obj)); - return SWIG_Py_Void(); + PyObject *obj; + if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL; + SWIG_TypeNewClientData(SWIGTYPE_p_pm3, SWIG_NewClientData(obj)); + return SWIG_Py_Void(); } SWIGINTERN PyObject *pm3_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { - return SWIG_Python_InitShadowInstance(args); + return SWIG_Python_InitShadowInstance(args); } static PyMethodDef SwigMethods[] = { - { "SWIG_PyInstanceMethod_New", SWIG_PyInstanceMethod_New, METH_O, NULL}, - { "new_pm3", _wrap_new_pm3, METH_VARARGS, NULL}, - { "delete_pm3", _wrap_delete_pm3, METH_O, NULL}, - { "pm3_console", _wrap_pm3_console, METH_VARARGS, NULL}, - { "pm3_name_get", _wrap_pm3_name_get, METH_O, NULL}, - { "pm3_swigregister", pm3_swigregister, METH_O, NULL}, - { "pm3_swiginit", pm3_swiginit, METH_VARARGS, NULL}, - { NULL, NULL, 0, NULL } + { "SWIG_PyInstanceMethod_New", SWIG_PyInstanceMethod_New, METH_O, NULL}, + { "new_pm3", _wrap_new_pm3, METH_VARARGS, NULL}, + { "delete_pm3", _wrap_delete_pm3, METH_O, NULL}, + { "pm3_console", _wrap_pm3_console, METH_VARARGS, NULL}, + { "pm3_name_get", _wrap_pm3_name_get, METH_O, NULL}, + { "pm3_swigregister", pm3_swigregister, METH_O, NULL}, + { "pm3_swiginit", pm3_swiginit, METH_VARARGS, NULL}, + { NULL, NULL, 0, NULL } }; static PyMethodDef SwigMethods_proxydocs[] = { - { NULL, NULL, 0, NULL } + { NULL, NULL, 0, NULL } }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ -static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_pm3 = {"_p_pm3", "pm3 *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void *)0, 0}; +static swig_type_info _swigt__p_pm3 = {"_p_pm3", "pm3 *", 0, 0, (void *)0, 0}; static swig_type_info *swig_type_initial[] = { - &_swigt__p_char, - &_swigt__p_pm3, + &_swigt__p_char, + &_swigt__p_pm3, }; -static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_pm3[] = { {&_swigt__p_pm3, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0}, {0, 0, 0, 0}}; +static swig_cast_info _swigc__p_pm3[] = { {&_swigt__p_pm3, 0, 0, 0}, {0, 0, 0, 0}}; static swig_cast_info *swig_cast_initial[] = { - _swigc__p_char, - _swigc__p_pm3, + _swigc__p_char, + _swigc__p_pm3, }; /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ static swig_const_info swig_const_table[] = { -{0, 0, 0, 0.0, 0, 0}}; + {0, 0, 0, 0.0, 0, 0} +}; #ifdef __cplusplus } @@ -3109,143 +3065,143 @@ extern "C" { SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { - size_t i; - swig_module_info *module_head, *iter; - int init; - - /* check to see if the circular list has been setup, if not, set it up */ - if (swig_module.next==0) { - /* Initialize the swig_module */ - swig_module.type_initial = swig_type_initial; - swig_module.cast_initial = swig_cast_initial; - swig_module.next = &swig_module; - init = 1; - } else { - init = 0; - } - - /* Try and load any already created modules */ - module_head = SWIG_GetModule(clientdata); - if (!module_head) { - /* This is the first module loaded for this interpreter */ - /* so set the swig module into the interpreter */ - SWIG_SetModule(clientdata, &swig_module); - } else { - /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - iter=module_head; - do { - if (iter==&swig_module) { - /* Our module is already in the list, so there's nothing more to do. */ - return; - } - iter=iter->next; - } while (iter!= module_head); - - /* otherwise we must add our module into the list */ - swig_module.next = module_head->next; - module_head->next = &swig_module; - } - - /* When multiple interpreters are used, a module could have already been initialized in - a different interpreter, but not yet have a pointer in this interpreter. - In this case, we do not want to continue adding types... everything should be - set up already */ - if (init == 0) return; - - /* Now work on filling in swig_module.types */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); -#endif - for (i = 0; i < swig_module.size; ++i) { - swig_type_info *type = 0; - swig_type_info *ret; - swig_cast_info *cast; - -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); -#endif - - /* if there is another module already loaded */ - if (swig_module.next != &swig_module) { - type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); - } - if (type) { - /* Overwrite clientdata field */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found type %s\n", type->name); -#endif - if (swig_module.type_initial[i]->clientdata) { - type->clientdata = swig_module.type_initial[i]->clientdata; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); -#endif - } + size_t i; + swig_module_info *module_head, *iter; + int init; + + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next == 0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + init = 1; } else { - type = swig_module.type_initial[i]; + init = 0; } - - /* Insert casting types */ - cast = swig_module.cast_initial[i]; - while (cast->type) { - /* Don't need to add information already in the list */ - ret = 0; + + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + iter = module_head; + do { + if (iter == &swig_module) { + /* Our module is already in the list, so there's nothing more to do. */ + return; + } + iter = iter->next; + } while (iter != module_head); + + /* otherwise we must add our module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } + + /* When multiple interpreters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + + /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); + printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size); #endif - if (swig_module.next != &swig_module) { - ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + #ifdef SWIGRUNTIME_DEBUG - if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); + printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); #endif - } - if (ret) { - if (type == swig_module.type_initial[i]) { + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); + } + if (type) { + /* Overwrite clientdata field */ #ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: skip old type %s\n", ret->name); + printf("SWIG_InitializeModule: found type %s\n", type->name); #endif - cast->type = ret; - ret = 0; + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } } else { - /* Check for casting already in the list */ - swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); -#ifdef SWIGRUNTIME_DEBUG - if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); -#endif - if (!ocast) ret = 0; + type = swig_module.type_initial[i]; } - } - - if (!ret) { + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + /* Don't need to add information already in the list */ + ret = 0; #ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); #endif - if (type->cast) { - type->cast->prev = cast; - cast->next = type->cast; - } - type->cast = cast; - } - cast++; - } - /* Set entry in modules->types array equal to the type */ - swig_module.types[i] = type; - } - swig_module.types[i] = 0; - + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); #ifdef SWIGRUNTIME_DEBUG - printf("**** SWIG_InitializeModule: Cast List ******\n"); - for (i = 0; i < swig_module.size; ++i) { - int j = 0; - swig_cast_info *cast = swig_module.cast_initial[i]; - printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); - while (cast->type) { - printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); - cast++; - ++j; + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; } - printf("---- Total casts: %d\n",j); - } - printf("**** SWIG_InitializeModule: Cast List ******\n"); + swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n", j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); #endif } @@ -3256,31 +3212,31 @@ SWIG_InitializeModule(void *clientdata) { */ SWIGRUNTIME void SWIG_PropagateClientData(void) { - size_t i; - swig_cast_info *equiv; - static int init_run = 0; - - if (init_run) return; - init_run = 1; - - for (i = 0; i < swig_module.size; i++) { - if (swig_module.types[i]->clientdata) { - equiv = swig_module.types[i]->cast; - while (equiv) { - if (!equiv->converter) { - if (equiv->type && !equiv->type->clientdata) - SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + size_t i; + swig_cast_info *equiv; + static int init_run = 0; + + if (init_run) return; + init_run = 1; + + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } } - equiv = equiv->next; - } } - } } #ifdef __cplusplus #if 0 { - /* c-mode */ + /* c-mode */ #endif } #endif @@ -3290,57 +3246,57 @@ SWIG_PropagateClientData(void) { #ifdef __cplusplus extern "C" { #endif - - /* Python-specific SWIG API */ + +/* Python-specific SWIG API */ #define SWIG_newvarlink() SWIG_Python_newvarlink() #define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) #define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) - - /* ----------------------------------------------------------------------------- - * global variable support code. - * ----------------------------------------------------------------------------- */ - - typedef struct swig_globalvar { + +/* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + +typedef struct swig_globalvar { char *name; /* Name of global variable */ PyObject *(*get_attr)(void); /* Return the current value */ - int (*set_attr)(PyObject *); /* Set the value */ + int (*set_attr)(PyObject *); /* Set the value */ struct swig_globalvar *next; - } swig_globalvar; - - typedef struct swig_varlinkobject { +} swig_globalvar; + +typedef struct swig_varlinkobject { PyObject_HEAD swig_globalvar *vars; - } swig_varlinkobject; - - SWIGINTERN PyObject * - swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { +} swig_varlinkobject; + +SWIGINTERN PyObject * +swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { #if PY_VERSION_HEX >= 0x03000000 return PyUnicode_InternFromString(""); #else return PyString_FromString(""); #endif - } - - SWIGINTERN PyObject * - swig_varlink_str(swig_varlinkobject *v) { +} + +SWIGINTERN PyObject * +swig_varlink_str(swig_varlinkobject *v) { #if PY_VERSION_HEX >= 0x03000000 PyObject *str = PyUnicode_InternFromString("("); PyObject *tail; PyObject *joined; swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - tail = PyUnicode_FromString(var->name); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; - if (var->next) { - tail = PyUnicode_InternFromString(", "); + for (var = v->vars; var; var = var->next) { + tail = PyUnicode_FromString(var->name); joined = PyUnicode_Concat(str, tail); Py_DecRef(str); Py_DecRef(tail); str = joined; - } + if (var->next) { + tail = PyUnicode_InternFromString(", "); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + } } tail = PyUnicode_InternFromString(")"); joined = PyUnicode_Concat(str, tail); @@ -3350,289 +3306,289 @@ extern "C" { #else PyObject *str = PyString_FromString("("); swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - PyString_ConcatAndDel(&str,PyString_FromString(var->name)); - if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); + for (var = v->vars; var; var = var->next) { + PyString_ConcatAndDel(&str, PyString_FromString(var->name)); + if (var->next) PyString_ConcatAndDel(&str, PyString_FromString(", ")); } - PyString_ConcatAndDel(&str,PyString_FromString(")")); + PyString_ConcatAndDel(&str, PyString_FromString(")")); #endif return str; - } - - SWIGINTERN void - swig_varlink_dealloc(swig_varlinkobject *v) { +} + +SWIGINTERN void +swig_varlink_dealloc(swig_varlinkobject *v) { swig_globalvar *var = v->vars; while (var) { - swig_globalvar *n = var->next; - free(var->name); - free(var); - var = n; + swig_globalvar *n = var->next; + free(var->name); + free(var); + var = n; } - } - - SWIGINTERN PyObject * - swig_varlink_getattr(swig_varlinkobject *v, char *n) { +} + +SWIGINTERN PyObject * +swig_varlink_getattr(swig_varlinkobject *v, char *n) { PyObject *res = NULL; swig_globalvar *var = v->vars; while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->get_attr)(); - break; - } - var = var->next; + if (strcmp(var->name, n) == 0) { + res = (*var->get_attr)(); + break; + } + var = var->next; } if (res == NULL && !PyErr_Occurred()) { - PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; - } - - SWIGINTERN int - swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { +} + +SWIGINTERN int +swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { int res = 1; swig_globalvar *var = v->vars; while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->set_attr)(p); - break; - } - var = var->next; + if (strcmp(var->name, n) == 0) { + res = (*var->set_attr)(p); + break; + } + var = var->next; } if (res == 1 && !PyErr_Occurred()) { - PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); } return res; - } - - SWIGINTERN PyTypeObject* - swig_varlink_type(void) { +} + +SWIGINTERN PyTypeObject * +swig_varlink_type(void) { static char varlink__doc__[] = "Swig var link object"; static PyTypeObject varlink_type; static int type_init = 0; if (!type_init) { - const PyTypeObject tmp = { + const PyTypeObject tmp = { #if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(NULL, 0) + PyVarObject_HEAD_INIT(NULL, 0) #else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ #endif - "swigvarlink", /* tp_name */ - sizeof(swig_varlinkobject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor) swig_varlink_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - (getattrfunc) swig_varlink_getattr, /* tp_getattr */ - (setattrfunc) swig_varlink_setattr, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc) swig_varlink_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc) swig_varlink_str, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - 0, /* tp_flags */ - varlink__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ - 0, /* tp_del */ - 0, /* tp_version_tag */ + "swigvarlink", /* tp_name */ + sizeof(swig_varlinkobject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor) swig_varlink_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + (getattrfunc) swig_varlink_getattr, /* tp_getattr */ + (setattrfunc) swig_varlink_setattr, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc) swig_varlink_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + varlink__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* tp_iter -> tp_weaklist */ + 0, /* tp_del */ + 0, /* tp_version_tag */ #if PY_VERSION_HEX >= 0x03040000 - 0, /* tp_finalize */ + 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0, /* tp_allocs */ - 0, /* tp_frees */ - 0, /* tp_maxalloc */ - 0, /* tp_prev */ - 0 /* tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ + 0, /* tp_prev */ + 0 /* tp_next */ #endif - }; - varlink_type = tmp; - type_init = 1; - if (PyType_Ready(&varlink_type) < 0) - return NULL; + }; + varlink_type = tmp; + type_init = 1; + if (PyType_Ready(&varlink_type) < 0) + return NULL; } return &varlink_type; - } - - /* Create a variable linking object for use later */ - SWIGINTERN PyObject * - SWIG_Python_newvarlink(void) { +} + +/* Create a variable linking object for use later */ +SWIGINTERN PyObject * +SWIG_Python_newvarlink(void) { swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); if (result) { - result->vars = 0; + result->vars = 0; } - return ((PyObject*) result); - } - - SWIGINTERN void - SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + return ((PyObject *) result); +} + +SWIGINTERN void +SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject * (*get_attr)(void), int (*set_attr)(PyObject *p)) { swig_varlinkobject *v = (swig_varlinkobject *) p; swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); if (gv) { - size_t size = strlen(name)+1; - gv->name = (char *)malloc(size); - if (gv->name) { - memcpy(gv->name, name, size); - gv->get_attr = get_attr; - gv->set_attr = set_attr; - gv->next = v->vars; - } + size_t size = strlen(name) + 1; + gv->name = (char *)malloc(size); + if (gv->name) { + memcpy(gv->name, name, size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } } v->vars = gv; - } - - SWIGINTERN PyObject * - SWIG_globals(void) { +} + +SWIGINTERN PyObject * +SWIG_globals(void) { static PyObject *globals = 0; if (!globals) { - globals = SWIG_newvarlink(); + globals = SWIG_newvarlink(); } return globals; - } - - /* ----------------------------------------------------------------------------- - * constants/methods manipulation - * ----------------------------------------------------------------------------- */ - - /* Install Constants */ - SWIGINTERN void - SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { +} + +/* ----------------------------------------------------------------------------- + * constants/methods manipulation + * ----------------------------------------------------------------------------- */ + +/* Install Constants */ +SWIGINTERN void +SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { PyObject *obj = 0; size_t i; for (i = 0; constants[i].type; ++i) { - switch(constants[i].type) { - case SWIG_PY_POINTER: - obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); - break; - case SWIG_PY_BINARY: - obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); - break; - default: - obj = 0; - break; - } - if (obj) { - PyDict_SetItemString(d, constants[i].name, obj); - Py_DECREF(obj); - } + switch (constants[i].type) { + case SWIG_PY_POINTER: + obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype, 0); + break; + case SWIG_PY_BINARY: + obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); + break; + default: + obj = 0; + break; + } + if (obj) { + PyDict_SetItemString(d, constants[i].name, obj); + Py_DECREF(obj); + } } - } - - /* -----------------------------------------------------------------------------*/ - /* Fix SwigMethods to carry the callback ptrs when needed */ - /* -----------------------------------------------------------------------------*/ - - SWIGINTERN void - SWIG_Python_FixMethods(PyMethodDef *methods, - swig_const_info *const_table, - swig_type_info **types, - swig_type_info **types_initial) { +} + +/* -----------------------------------------------------------------------------*/ +/* Fix SwigMethods to carry the callback ptrs when needed */ +/* -----------------------------------------------------------------------------*/ + +SWIGINTERN void +SWIG_Python_FixMethods(PyMethodDef *methods, + swig_const_info *const_table, + swig_type_info **types, + swig_type_info **types_initial) { size_t i; for (i = 0; methods[i].ml_name; ++i) { - const char *c = methods[i].ml_doc; - if (!c) continue; - c = strstr(c, "swig_ptr: "); - if (c) { - int j; - swig_const_info *ci = 0; - const char *name = c + 10; - for (j = 0; const_table[j].type; ++j) { - if (strncmp(const_table[j].name, name, - strlen(const_table[j].name)) == 0) { - ci = &(const_table[j]); - break; - } - } - if (ci) { - void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; - if (ptr) { - size_t shift = (ci->ptype) - types; - swig_type_info *ty = types_initial[shift]; - size_t ldoc = (c - methods[i].ml_doc); - size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; - char *ndoc = (char*)malloc(ldoc + lptr + 10); - if (ndoc) { - char *buff = ndoc; - memcpy(buff, methods[i].ml_doc, ldoc); - buff += ldoc; - memcpy(buff, "swig_ptr: ", 10); - buff += 10; - SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); - methods[i].ml_doc = ndoc; + const char *c = methods[i].ml_doc; + if (!c) continue; + c = strstr(c, "swig_ptr: "); + if (c) { + int j; + swig_const_info *ci = 0; + const char *name = c + 10; + for (j = 0; const_table[j].type; ++j) { + if (strncmp(const_table[j].name, name, + strlen(const_table[j].name)) == 0) { + ci = &(const_table[j]); + break; + } + } + if (ci) { + void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; + if (ptr) { + size_t shift = (ci->ptype) - types; + swig_type_info *ty = types_initial[shift]; + size_t ldoc = (c - methods[i].ml_doc); + size_t lptr = strlen(ty->name) + 2 * sizeof(void *) +2; + char *ndoc = (char *)malloc(ldoc + lptr + 10); + if (ndoc) { + char *buff = ndoc; + memcpy(buff, methods[i].ml_doc, ldoc); + buff += ldoc; + memcpy(buff, "swig_ptr: ", 10); + buff += 10; + SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); + methods[i].ml_doc = ndoc; + } + } } - } } - } } - } - - /* ----------------------------------------------------------------------------- - * Method creation and docstring support functions - * ----------------------------------------------------------------------------- */ - - /* ----------------------------------------------------------------------------- - * Function to find the method definition with the correct docstring for the - * proxy module as opposed to the low-level API - * ----------------------------------------------------------------------------- */ - - SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name) { +} + +/* ----------------------------------------------------------------------------- + * Method creation and docstring support functions + * ----------------------------------------------------------------------------- */ + +/* ----------------------------------------------------------------------------- + * Function to find the method definition with the correct docstring for the + * proxy module as opposed to the low-level API + * ----------------------------------------------------------------------------- */ + +SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name) { /* Find the function in the modified method table */ size_t offset = 0; int found = 0; while (SwigMethods_proxydocs[offset].ml_meth != NULL) { - if (strcmp(SwigMethods_proxydocs[offset].ml_name, name) == 0) { - found = 1; - break; - } - offset++; + if (strcmp(SwigMethods_proxydocs[offset].ml_name, name) == 0) { + found = 1; + break; + } + offset++; } /* Use the copy with the modified docstring if available */ return found ? &SwigMethods_proxydocs[offset] : NULL; - } - - /* ----------------------------------------------------------------------------- - * Wrapper of PyInstanceMethod_New() used in Python 3 - * It is exported to the generated module, used for -fastproxy - * ----------------------------------------------------------------------------- */ - - SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) { +} + +/* ----------------------------------------------------------------------------- + * Wrapper of PyInstanceMethod_New() used in Python 3 + * It is exported to the generated module, used for -fastproxy + * ----------------------------------------------------------------------------- */ + +SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) { if (PyCFunction_Check(func)) { - PyCFunctionObject *funcobj = (PyCFunctionObject *)func; - PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name); - if (ml) - func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module); + PyCFunctionObject *funcobj = (PyCFunctionObject *)func; + PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name); + if (ml) + func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module); } #if PY_VERSION_HEX >= 0x03000000 return PyInstanceMethod_New(func); #else return PyMethod_New(func, NULL, NULL); #endif - } - - /* ----------------------------------------------------------------------------- - * Wrapper of PyStaticMethod_New() - * It is exported to the generated module, used for -fastproxy - * ----------------------------------------------------------------------------- */ - - SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) { +} + +/* ----------------------------------------------------------------------------- + * Wrapper of PyStaticMethod_New() + * It is exported to the generated module, used for -fastproxy + * ----------------------------------------------------------------------------- */ + +SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) { if (PyCFunction_Check(func)) { - PyCFunctionObject *funcobj = (PyCFunctionObject *)func; - PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name); - if (ml) - func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module); + PyCFunctionObject *funcobj = (PyCFunctionObject *)func; + PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name); + if (ml) + func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module); } return PyStaticMethod_New(func); - } - +} + #ifdef __cplusplus } #endif @@ -3645,137 +3601,137 @@ extern "C" { extern "C" #endif -SWIGEXPORT +SWIGEXPORT #if PY_VERSION_HEX >= 0x03000000 -PyObject* +PyObject * #else void #endif SWIG_init(void) { - PyObject *m, *d, *md, *globals; - + PyObject *m, *d, *md, *globals; + #if PY_VERSION_HEX >= 0x03000000 - static struct PyModuleDef SWIG_module = { - PyModuleDef_HEAD_INIT, - SWIG_name, - NULL, - -1, - SwigMethods, - NULL, - NULL, - NULL, - NULL - }; + static struct PyModuleDef SWIG_module = { + PyModuleDef_HEAD_INIT, + SWIG_name, + NULL, + -1, + SwigMethods, + NULL, + NULL, + NULL, + NULL + }; #endif - + #if defined(SWIGPYTHON_BUILTIN) - static SwigPyClientData SwigPyObject_clientdata = { - 0, 0, 0, 0, 0, 0, 0 - }; - static PyGetSetDef this_getset_def = { - (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL - }; - static SwigPyGetSet thisown_getset_closure = { - SwigPyObject_own, - SwigPyObject_own - }; - static PyGetSetDef thisown_getset_def = { - (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure - }; - PyTypeObject *builtin_pytype; - int builtin_base_count; - swig_type_info *builtin_basetype; - PyObject *tuple; - PyGetSetDescrObject *static_getset; - PyTypeObject *metatype; - PyTypeObject *swigpyobject; - SwigPyClientData *cd; - PyObject *public_interface, *public_symbol; - PyObject *this_descr; - PyObject *thisown_descr; - PyObject *self = 0; - int i; - - (void)builtin_pytype; - (void)builtin_base_count; - (void)builtin_basetype; - (void)tuple; - (void)static_getset; - (void)self; - - /* Metaclass is used to implement static member variables */ - metatype = SwigPyObjectType(); - assert(metatype); + static SwigPyClientData SwigPyObject_clientdata = { + 0, 0, 0, 0, 0, 0, 0 + }; + static PyGetSetDef this_getset_def = { + (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL + }; + static SwigPyGetSet thisown_getset_closure = { + SwigPyObject_own, + SwigPyObject_own + }; + static PyGetSetDef thisown_getset_def = { + (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure + }; + PyTypeObject *builtin_pytype; + int builtin_base_count; + swig_type_info *builtin_basetype; + PyObject *tuple; + PyGetSetDescrObject *static_getset; + PyTypeObject *metatype; + PyTypeObject *swigpyobject; + SwigPyClientData *cd; + PyObject *public_interface, *public_symbol; + PyObject *this_descr; + PyObject *thisown_descr; + PyObject *self = 0; + int i; + + (void)builtin_pytype; + (void)builtin_base_count; + (void)builtin_basetype; + (void)tuple; + (void)static_getset; + (void)self; + + /* Metaclass is used to implement static member variables */ + metatype = SwigPyObjectType(); + assert(metatype); #endif - - (void)globals; - - /* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */ - SWIG_This(); - SWIG_Python_TypeCache(); - SwigPyPacked_type(); + + (void)globals; + + /* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */ + SWIG_This(); + SWIG_Python_TypeCache(); + SwigPyPacked_type(); #ifndef SWIGPYTHON_BUILTIN - SwigPyObject_type(); + SwigPyObject_type(); #endif - - /* Fix SwigMethods to carry the callback ptrs when needed */ - SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); - + + /* Fix SwigMethods to carry the callback ptrs when needed */ + SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); + #if PY_VERSION_HEX >= 0x03000000 - m = PyModule_Create(&SWIG_module); + m = PyModule_Create(&SWIG_module); #else - m = Py_InitModule(SWIG_name, SwigMethods); + m = Py_InitModule(SWIG_name, SwigMethods); #endif - - md = d = PyModule_GetDict(m); - (void)md; - - SWIG_InitializeModule(0); - + + md = d = PyModule_GetDict(m); + (void)md; + + SWIG_InitializeModule(0); + #ifdef SWIGPYTHON_BUILTIN - swigpyobject = SwigPyObject_TypeOnce(); - - SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); - assert(SwigPyObject_stype); - cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; - if (!cd) { - SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; - SwigPyObject_clientdata.pytype = swigpyobject; - } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) { - PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); + swigpyobject = SwigPyObject_TypeOnce(); + + SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); + assert(SwigPyObject_stype); + cd = (SwigPyClientData *) SwigPyObject_stype->clientdata; + if (!cd) { + SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; + SwigPyObject_clientdata.pytype = swigpyobject; + } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) { + PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); # if PY_VERSION_HEX >= 0x03000000 - return NULL; + return NULL; # else - return; + return; # endif - } - - /* All objects have a 'this' attribute */ - this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); - (void)this_descr; - - /* All objects have a 'thisown' attribute */ - thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); - (void)thisown_descr; - - public_interface = PyList_New(0); - public_symbol = 0; - (void)public_symbol; - - PyDict_SetItemString(md, "__all__", public_interface); - Py_DECREF(public_interface); - for (i = 0; SwigMethods[i].ml_name != NULL; ++i) - SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); - for (i = 0; swig_const_table[i].name != 0; ++i) - SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); + } + + /* All objects have a 'this' attribute */ + this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); + (void)this_descr; + + /* All objects have a 'thisown' attribute */ + thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); + (void)thisown_descr; + + public_interface = PyList_New(0); + public_symbol = 0; + (void)public_symbol; + + PyDict_SetItemString(md, "__all__", public_interface); + Py_DECREF(public_interface); + for (i = 0; SwigMethods[i].ml_name != NULL; ++i) + SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); + for (i = 0; swig_const_table[i].name != 0; ++i) + SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); #endif - - SWIG_InstallConstants(d,swig_const_table); - + + SWIG_InstallConstants(d, swig_const_table); + #if PY_VERSION_HEX >= 0x03000000 - return m; + return m; #else - return; + return; #endif } diff --git a/client/src/util.c b/client/src/util.c index e9fd171e2..4ba4af108 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -446,10 +446,10 @@ void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest) { } } -void bytes_to_bytebits(void* src, size_t srclen, void* dest) { +void bytes_to_bytebits(void *src, size_t srclen, void *dest) { - uint8_t *s = (uint8_t*)src; - uint8_t *d = (uint8_t*)dest; + uint8_t *s = (uint8_t *)src; + uint8_t *d = (uint8_t *)dest; uint32_t i = srclen * 8; while (srclen--) { diff --git a/client/src/util.h b/client/src/util.h index 28ca74917..66b72491f 100644 --- a/client/src/util.h +++ b/client/src/util.h @@ -56,7 +56,7 @@ void print_blocks(uint32_t *data, size_t len); int hex_to_bytes(const char *hexValue, uint8_t *bytesValue, size_t maxBytesValueLen); void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest); void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest); -void bytes_to_bytebits(void* src, size_t srclen, void* dest); +void bytes_to_bytebits(void *src, size_t srclen, void *dest); // Swap endian on arrays up to 64bytes. uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize); diff --git a/common_arm/Makefile.hal b/common_arm/Makefile.hal index c7625b4aa..2ab6e1ddf 100644 --- a/common_arm/Makefile.hal +++ b/common_arm/Makefile.hal @@ -143,9 +143,10 @@ PLATFORM_DEFS+=$(STANDALONE_PLATFORM_DEFS) $(info $(findstring WITH_STANDALONE_*,$(PLATFORM_DEFS))) -# Misc -#PLATFORM_DEFS += -DWITH_LCD - +# Misc (LCD support) +ifneq (,$(findstring WITH_LCD,$(PLATFORM_DEFS))) + #PLATFORM_DEFS += -DWITH_LCD +endif # Add flags dependencies : diff --git a/doc/cliparser_todo.txt b/doc/cliparser_todo.txt index 4e8c4e36b..5cf24f1e8 100644 --- a/doc/cliparser_todo.txt +++ b/doc/cliparser_todo.txt @@ -1,8 +1,6 @@ clear pref rem -quit -exit analyse lcr analyse crc analyse chksum @@ -13,6 +11,7 @@ analyse a analyse nuid analyse demodbuff analyse freq +analyse foo data biphaserawdecode data detectclock data fsktonrz @@ -44,20 +43,15 @@ data print data samples data setdebugmode data tune -emv list -hf list hf tune hf search hf sniff -hf 14a list hf 14a reader hf 14a cuids hf 14a sim hf 14a sniff hf 14a config -hf 14b list hf 14b sriwrite -hf 15 list hf 15 dump hf 15 info hf 15 raw @@ -69,7 +63,6 @@ hf 15 writeafi hf 15 writedsfid hf epa cnonces hf epa preplay -hf felica list hf felica reader hf felica sniff hf felica raw @@ -85,11 +78,9 @@ hf felica rqspecver hf felica resetmode hf felica litesim hf felica litedump -hf fido list hf fido info hf iclass info -hf iclass list -hf legic list +hf iclass permutekey hf legic reader hf legic info hf legic dump @@ -101,13 +92,6 @@ hf legic crc hf legic eload hf legic esave hf legic wipe -hf lto dump -hf lto restore -hf lto info -hf lto rdbl -hf lto wrbl -hf lto list -hf mf list hf mf darkside hf mf nested hf mf hardnested @@ -144,7 +128,6 @@ hf mf gen3uid hf mf gen3blk hf mf gen3freeze hf mf ice -hf mfp info hf mfu info hf mfu dump hf mfu restore @@ -161,12 +144,8 @@ hf mfu otptear hf mfdes enum hf mfdes getuid hf mfdes info -hf mfdes list -hf st list hf thinfilm info -hf thinfilm list hf thinfilm sim -hf topaz list hf topaz info hf topaz reader hf topaz sim @@ -199,17 +178,6 @@ lf simpsk lf simbidir lf sniff lf tune -lf awid demod -lf awid read -lf awid clone -lf awid sim -lf awid brute -lf awid watch -lf cotag demod -lf cotag read -lf destron demod -lf destron read -lf destron sim lf em 410x_demod lf em 410x_read lf em 410x_sim @@ -229,21 +197,7 @@ lf em 4x50_write lf em 4x50_write_password lf em 4x50_read lf em 4x50_wipe -lf fdxb demod -lf fdxb read -lf fdxb clone -lf fdxb sim -lf gallagher demod -lf gallagher read -lf gallagher clone -lf gallagher sim -lf gproxii demod -lf gproxii read -lf gproxii clone -lf gproxii sim -lf hid demod lf hid read -lf hitag list lf hitag info lf hitag reader lf hitag sim @@ -251,41 +205,20 @@ lf hitag sniff lf hitag writer lf hitag dump lf hitag cc -lf idteck demod -lf idteck read lf indala demod lf indala altdemod -lf indala read lf indala sim -lf io demod -lf io read lf io clone lf io sim lf io watch -lf jablotron demod -lf jablotron read -lf jablotron clone lf jablotron sim -lf keri demod -lf motorola demod -lf motorola sim -lf nedap demod lf nedap generate lf nedap read lf nedap clone lf nedap sim -lf nexwatch demod -lf noralsy demod -lf pac demod -lf paradox demod lf pcf7931 read lf pcf7931 write lf pcf7931 config -lf presco demod -lf pyramid demod -lf securakey demod -lf ti demod -lf ti write lf t55xx config lf t55xx dangerraw lf t55xx detect @@ -306,17 +239,12 @@ lf t55xx recoverpw lf t55xx sniff lf t55xx special lf t55xx wipe -lf viking demod -lf visa2000 demod -mem spiffs -smart list smart info smart reader smart raw smart upgrade smart setclock smart brute -script list script run usart btpin usart btfactory @@ -326,4 +254,3 @@ usart txrx usart txhex usart rxhex usart config -wiegand list diff --git a/doc/cloner_notes.md b/doc/cloner_notes.md index 2802f4494..71cada411 100644 --- a/doc/cloner_notes.md +++ b/doc/cloner_notes.md @@ -1,82 +1,82 @@ -# Notes on Cloner guns - -This document is based mostly on information posted on http://www.proxmark.org/forum/viewtopic.php?pid=39903#p39903 - -- [Notes on Cloner guns](#notes-on-cloner-guns) -- [Blue and black cloners](#blue-and-black-cloners) -- [White cloner (pre 2015)](#white-cloner-pre-2015) -- [White cloner (after 2016)](#white-cloner-after-2016) -- [White cloner (after 2016 D Quality)](#white-cloner-after-2016-d-quality) -- [Restore page1 data](#restore-page1-data) -- [Sniffing the comms](#sniffing-the-comms) - - -# Blue and black cloners - -3 variants: -1. EM cloner -2. HID cloner -3. EM/HID cloner - -Quality varies my manufacturer (Quality A (Good) until D (Bad)) -They set a password on block 7 of the chip and set the password enable bit in block 0 -``` -Standard password is normally: 51243648 -``` -**Be sure to purchase the EM/HID version** - -# White cloner (pre 2015) - -Multifrequency -Buttons light up BLUE -Reads data correctly -Coil performance acceptable -``` -Standard password is normally (for T55xx): AA55BBBB -Standard password 13,56mHz: individual per white cloner -``` - - -# White cloner (after 2016) -Multifrequency -Buttons light up WHITE -Data scrambled (variable per individual cloner, possibly due to prevent legal issues) -Coil performance good -``` -Standard password is normally (for T55xx): AA55BBBB -Standard password 13,56mHz: individual per white cloner -``` - - -# White cloner (after 2016 D Quality) -Multifrequency (it says so but it doesn't) -Only works for EM/HID card (125kHz) -High frequency not working -``` -Standard password is normally (for T55xx): AA55BBBB -``` -**Note: Sets the HID card in TEST MODE** - - -# Restore page1 data -``` -lf t55xx write b 1 d E0150A48 1 -If t55xx write b 2 d 2D782308 1 -``` - -# Sniffing the comms -The T55x7 protocol uses a pwm based protocol for writing to tags. In order to make decoding easier try the new command as seen below instead. It will try to extract the data written. - -``` --- after threshold limit 20 is triggered, skip 10000 samples before collecting samples. -lf config s 10000 t 20 -lf t55xx sniff - --- if you have a save trace from before, try -data load -f xxxxxxx.pm3 -lf t55xx sniff 1 -``` - -It uses the existing `lf sniff` command to collect the data, so setting that first as per normal sniffing is recommended. Once you have a sniff, you can "re-sniff" from the stored sniffed data and try different settings, if you think the data is not clean. - +# Notes on Cloner guns + +This document is based mostly on information posted on http://www.proxmark.org/forum/viewtopic.php?pid=39903#p39903 + +- [Notes on Cloner guns](#notes-on-cloner-guns) +- [Blue and black cloners](#blue-and-black-cloners) +- [White cloner (pre 2015)](#white-cloner-pre-2015) +- [White cloner (after 2016)](#white-cloner-after-2016) +- [White cloner (after 2016 D Quality)](#white-cloner-after-2016-d-quality) +- [Restore page1 data](#restore-page1-data) +- [Sniffing the comms](#sniffing-the-comms) + + +# Blue and black cloners + +3 variants: +1. EM cloner +2. HID cloner +3. EM/HID cloner + +Quality varies my manufacturer (Quality A (Good) until D (Bad)) +They set a password on block 7 of the chip and set the password enable bit in block 0 +``` +Standard password is normally: 51243648 +``` +**Be sure to purchase the EM/HID version** + +# White cloner (pre 2015) + +Multifrequency +Buttons light up BLUE +Reads data correctly +Coil performance acceptable +``` +Standard password is normally (for T55xx): AA55BBBB +Standard password 13,56mHz: individual per white cloner +``` + + +# White cloner (after 2016) +Multifrequency +Buttons light up WHITE +Data scrambled (variable per individual cloner, possibly due to prevent legal issues) +Coil performance good +``` +Standard password is normally (for T55xx): AA55BBBB +Standard password 13,56mHz: individual per white cloner +``` + + +# White cloner (after 2016 D Quality) +Multifrequency (it says so but it doesn't) +Only works for EM/HID card (125kHz) +High frequency not working +``` +Standard password is normally (for T55xx): AA55BBBB +``` +**Note: Sets the HID card in TEST MODE** + + +# Restore page1 data +``` +lf t55xx write b 1 d E0150A48 1 +If t55xx write b 2 d 2D782308 1 +``` + +# Sniffing the comms +The T55x7 protocol uses a pwm based protocol for writing to tags. In order to make decoding easier try the new command as seen below instead. It will try to extract the data written. + +``` +-- after threshold limit 20 is triggered, skip 10000 samples before collecting samples. +lf config s 10000 t 20 +lf t55xx sniff + +-- if you have a save trace from before, try +data load -f xxxxxxx.pm3 +lf t55xx sniff 1 +``` + +It uses the existing `lf sniff` command to collect the data, so setting that first as per normal sniffing is recommended. Once you have a sniff, you can "re-sniff" from the stored sniffed data and try different settings, if you think the data is not clean. + As normal, the cloner may write data past the end of the 40K sample buffer. So using the `lf config s ` then re-run the sniff to see if there is more data. \ No newline at end of file diff --git a/doc/colors_notes.md b/doc/colors_notes.md index c06a584e1..74d0cbb92 100644 --- a/doc/colors_notes.md +++ b/doc/colors_notes.md @@ -1,50 +1,50 @@ - -# Notes on Color usage. - -## Table of Contents - * [style/color](#style_color) - * [Proxspace](#proxspace) - * [](#) - -The client should autodetect color support when starting. - -You can also use the command `pref show` to see and set your personal setting. - -Why use colors in the Proxmark client? When everything is white it is hard to extract the important information fast. You also need new-lines for extra space to be easier to read. -We have gradually been introducing this color scheme into the client since we got decent color support on all systems: OSX, Linux, WSL, Proxspace. - - -## style/color -^[Top](#top) -The following definition has be crystallized out from these experiments. Its not set in stone yet so take this document as a guideline for how to create unified system scheme. - -### Definition -^[Top](#top) -- blue - system related headers, banner -- white - normal -- cyan - headers -- red - warning, error, catastrophic failures -- yellow - informative (to make things stick out from white blob) -- green - successful, (to make things stick out from white blob) -- magenta - device side messages - - -### Styled header -^[Top](#top) -``` - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------"); - PrintAndLogEx(INFO, "-------------------------------------------------------------"); -``` -For more examples, see also all **-h** helptext now in the LUA scripts. -For the command help texts using _YELLOW_ for the example makes it very easy to see what is the command vs the description. - -### non styled header -^[Top](#top) -Most commands doesn't use a header yet. We added it to make it standout (ie: yellow, green) of the informative tidbits in the output of a command. - - -## Proxspace -^[Top](#top) -Proxspace has support for colors. - + +# Notes on Color usage. + +## Table of Contents + * [style/color](#style_color) + * [Proxspace](#proxspace) + * [](#) + +The client should autodetect color support when starting. + +You can also use the command `pref show` to see and set your personal setting. + +Why use colors in the Proxmark client? When everything is white it is hard to extract the important information fast. You also need new-lines for extra space to be easier to read. +We have gradually been introducing this color scheme into the client since we got decent color support on all systems: OSX, Linux, WSL, Proxspace. + + +## style/color +^[Top](#top) +The following definition has be crystallized out from these experiments. Its not set in stone yet so take this document as a guideline for how to create unified system scheme. + +### Definition +^[Top](#top) +- blue - system related headers, banner +- white - normal +- cyan - headers +- red - warning, error, catastrophic failures +- yellow - informative (to make things stick out from white blob) +- green - successful, (to make things stick out from white blob) +- magenta - device side messages + + +### Styled header +^[Top](#top) +``` + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------"); + PrintAndLogEx(INFO, "-------------------------------------------------------------"); +``` +For more examples, see also all **-h** helptext now in the LUA scripts. +For the command help texts using _YELLOW_ for the example makes it very easy to see what is the command vs the description. + +### non styled header +^[Top](#top) +Most commands doesn't use a header yet. We added it to make it standout (ie: yellow, green) of the informative tidbits in the output of a command. + + +## Proxspace +^[Top](#top) +Proxspace has support for colors. + diff --git a/doc/commands.md b/doc/commands.md index 57038cbba..f4bab39da 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -38,6 +38,7 @@ Check column "offline" for their availability. |`analyse nuid `|Y |`create NUID from 7byte UID` |`analyse demodbuff `|Y |`Load binary string to demodbuffer` |`analyse freq `|Y |`Calc wave lengths` +|`analyse foo `|Y |`muxer` ### data @@ -267,7 +268,7 @@ Check column "offline" for their availability. |`hf iclass encrypt `|Y |`[options..] Encrypt given block data` |`hf iclass decrypt `|Y |`[options..] Decrypt given block data or tag dump file` |`hf iclass managekeys `|Y |`[options..] Manage keys to use with iclass commands` -|`hf iclass permute `|N |` Permute function from 'heart of darkness' paper` +|`hf iclass permutekey `|N |` Permute function from 'heart of darkness' paper` |`hf iclass view `|Y |`[options..] Display content from tag dump file` @@ -538,7 +539,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf awid help `|Y |`this help` |`lf awid demod `|Y |`demodulate an AWID FSK tag from the GraphBuffer` -|`lf awid read `|N |`attempt to read and extract tag data` +|`lf awid reader `|N |`attempt to read and extract tag data` |`lf awid clone `|N |`clone AWID tag to T55x7 or Q5/T5555` |`lf awid sim `|N |`simulate AWID tag` |`lf awid brute `|N |`Bruteforce card number against reader` @@ -553,7 +554,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf cotag help `|Y |`This help` |`lf cotag demod `|Y |`Tries to decode a COTAG signal` -|`lf cotag read `|N |`Attempt to read and extract tag data` +|`lf cotag reader `|N |`Attempt to read and extract tag data` ### lf destron @@ -564,7 +565,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf destron help `|Y |`This help` |`lf destron demod `|Y |`Demodulate an Destron tag from the GraphBuffer` -|`lf destron read `|N |`Attempt to read and extract tag data from the antenna` +|`lf destron reader `|N |`Attempt to read and extract tag data from the antenna` |`lf destron clone `|N |`Clone Destron tag to T55x7` |`lf destron sim `|N |`Simulate Destron tag` @@ -609,7 +610,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf fdxb help `|Y |`this help` |`lf fdxb demod `|Y |`demodulate a FDX-B ISO11784/85 tag from the GraphBuffer` -|`lf fdxb read `|N |`attempt to read at 134kHz and extract tag data` +|`lf fdxb reader `|N |`attempt to read at 134kHz and extract tag data` |`lf fdxb clone `|N |`clone animal ID tag to T55x7 or Q5/T5555` |`lf fdxb sim `|N |`simulate Animal ID tag` @@ -622,7 +623,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf gallagher help `|Y |`This help` |`lf gallagher demod `|Y |`Demodulate an GALLAGHER tag from the GraphBuffer` -|`lf gallagher read `|N |`Attempt to read and extract tag data from the antenna` +|`lf gallagher reader `|N |`Attempt to read and extract tag data from the antenna` |`lf gallagher clone `|N |`clone GALLAGHER tag to T55x7` |`lf gallagher sim `|N |`simulate GALLAGHER tag` @@ -635,7 +636,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf gproxii help `|Y |`this help` |`lf gproxii demod `|Y |`demodulate a G Prox II tag from the GraphBuffer` -|`lf gproxii read `|N |`attempt to read and extract tag data from the antenna` +|`lf gproxii reader `|N |`attempt to read and extract tag data from the antenna` |`lf gproxii clone `|N |`clone Guardall tag to T55x7 or Q5/T5555` |`lf gproxii sim `|N |`simulate Guardall tag` @@ -680,7 +681,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf idteck help `|Y |`This help` |`lf idteck demod `|Y |`Demodulate an Idteck tag from the GraphBuffer` -|`lf idteck read `|N |`Attempt to read and Extract tag data from the antenna` +|`lf idteck reader `|N |`Attempt to read and Extract tag data from the antenna` ### lf indala @@ -692,7 +693,7 @@ Check column "offline" for their availability. |`lf indala help `|Y |`this help` |`lf indala demod `|Y |`demodulate an indala tag (PSK1) from GraphBuffer` |`lf indala altdemod `|Y |`alternative method to Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)` -|`lf indala read `|N |`read an Indala Prox tag from the antenna` +|`lf indala reader `|N |`read an Indala Prox tag from the antenna` |`lf indala clone `|N |`clone Indala tag to T55x7 or Q5/T5555` |`lf indala sim `|N |`simulate Indala tag` @@ -705,7 +706,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf io help `|Y |`this help` |`lf io demod `|Y |`demodulate an IOProx tag from the GraphBuffer` -|`lf io read `|N |`attempt to read and extract tag data` +|`lf io reader `|N |`attempt to read and extract tag data` |`lf io clone `|N |`clone IOProx tag to T55x7 or Q5/T5555` |`lf io sim `|N |`simulate IOProx tag` |`lf io watch `|N |`continuously watch for cards. Reader mode` @@ -719,7 +720,7 @@ Check column "offline" for their availability. |------- |------- |----------- |`lf jablotron help `|Y |`This help` |`lf jablotron demod `|Y |`Demodulate an Jablotron tag from the GraphBuffer` -|`lf jablotron read `|N |`Attempt to read and extract tag data from the antenna` +|`lf jablotron reader `|N |`Attempt to read and extract tag data from the antenna` |`lf jablotron clone `|N |`clone jablotron tag to T55x7 or Q5/T5555` |`lf jablotron sim `|N |`simulate jablotron tag` @@ -874,7 +875,7 @@ Check column "offline" for their availability. |command |offline |description |------- |------- |----------- |`lf ti help `|Y |`This help` -|`lf ti demod `|Y |`Demodulate raw bits for TI-type LF tag from the GraphBuffer` +|`lf ti demod `|Y |`Demodulate raw bits for TI LF tag from the GraphBuffer` |`lf ti reader `|N |`Read and decode a TI 134 kHz tag` |`lf ti write `|N |`Write new data to a r/w TI 134 kHz tag` diff --git a/doc/fpga_arm_notes.md b/doc/fpga_arm_notes.md index 15a09057a..37aa6a911 100644 --- a/doc/fpga_arm_notes.md +++ b/doc/fpga_arm_notes.md @@ -1,249 +1,249 @@ -# Notes on ARM & FPGA comms - - -https://github.com/RfidResearchGroup/proxmark3/blob/master/doc/original_proxmark3/proxmark3.pdf - -INTERFACE FROM THE ARM TO THE FPGA -================================== - -The FPGA and the ARM can communicate in two main ways: using the ARM's -general-purpose synchronous serial port (the SSP), or using the ARM's -SPI port. The SPI port is used to configure the FPGA. The ARM writes a -configuration word to the FPGA, which determines what operation will -be performed (e.g. read 13.56 MHz vs. read 125 kHz vs. read 134 kHz -vs...). The SPI is used exclusively for configuration. - -The SSP is used for actual data sent over the air. The ARM's SSP can -work in slave mode, which means that we can send the data using clocks -generated by the FPGA (either from the PCK0 clock, which the ARM itself -supplies, or from the 13.56 MHz clock, which is certainly not going to -be synchronous to anything in the ARM), which saves synchronizing logic -in the FPGA. The SSP is bi-directional and full-duplex. - - -The FPGA communicates with the ARM through either -1) SPI port (the ARM is the master) -2) SSC synchronous serial port (the ARM is the master). - - -opamps, (*note, this affects source code in ARM, calculating actual voltage from antenna. Manufacturers never report what they use to much frustration) -comparators -coil drivers - -LF analog path (MCP6294 opamp. This has a GBW of 10 MHz), all 'slow' signals. Used for low frequency signals. Follows the peak detector. Signal centered around generated voltage Vmid. - - -## FPGA -Since the SPARTAN II is a old outdated FPGA, thus is very limited resource there was a need to split LF and HF functionality into two separate FPGA images. Which are stored in ARM flash memory as bitstreams. - -We swap between these images by flashing fpga from ARM on the go. It takes about 1sec. Hence its usually a bad idea to program your device to continuously execute LF alt HF commands. - -The FPGA images is precompiled and located inside the /fpga folder. - - fpga_hf.bit - - fpga_lf.bit - -There is very rarely changes to the images so there is no need to setup a fpga tool chain to compile it yourself. -Since the FPGA is very old, the Xilinx WebPack ISE 10.1 is the last working tool chain. You can download this legacy development on Xilinx and register for a free product installation id. -Or use mine `11LTAJ5ZJK3PXTUBMF0C0J6C4` The package to download is about 7Gb and linux based. Though I recently managed to install it on WSL for Windows 10. - -In order to save space, these fpga images are LZ4 compressed and included in the fullimage.elf file when compiling the ARM SRC. `make armsrc` -This means we save some precious space on the ARM but its a bit more complex when flashing to fpga since it has to decompress on the fly. - - -### FPGA modes. - - Major modes - - Minor modes - -## ARM FPGA communications. - -The ARM talks with FPGA over the Synchronous Serial Port (SSC) rx an tx. - -ARM, send a 16bit configuration with fits the select major mode. - - - -## ARM GPIO setup - -``` - // First configure the GPIOs, and get ourselves a clock. - AT91C_BASE_PIOA->PIO_ASR = - GPIO_SSC_FRAME | - GPIO_SSC_DIN | - GPIO_SSC_DOUT | - GPIO_SSC_CLK; - AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DOUT; - - AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_SSC); - - // Now set up the SSC proper, starting from a known state. - AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST; - - // RX clock comes from TX clock, RX starts on Transmit Start, - // data and frame signal is sampled on falling edge of RK - AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1); - - // 8, 16 or 32 bits per transfer, no loopback, MSB first, 1 transfer per sync - // pulse, no output sync - if ((FPGA_mode & FPGA_MAJOR_MODE_MASK) == FPGA_MAJOR_MODE_HF_READER && FpgaGetCurrent() == FPGA_BITSTREAM_HF) { - AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); - } else { - AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); - } - - // TX clock comes from TK pin, no clock output, outputs change on rising edge of TK, - // TF (frame sync) is sampled on falling edge of TK, start TX on rising edge of TF - AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5); - - // tx framing is the same as the rx framing - AT91C_BASE_SSC->SSC_TFMR = AT91C_BASE_SSC->SSC_RFMR; - -``` - -## FPGA Setup - -// Set up DMA to receive samples from the FPGA. We will use the PDC, with -// a single buffer as a circular buffer (so that we just chain back to - - - -# HARDWARE OVERVIEW - -## ADC (ANALOG TO DIGITAL CONVERTER) -The analogue signal that comes from the antenna circuit is fed into an 8-bit Analogue to Digital Converter -(ADC). This delivers 8 output bits in parallel which represent the current voltage retrieved from the field. - - -## FIELD PROGRAMMABLE GATE ARRAY, FPGA -The 8 output pins from the ADC are connected to 8 pins of the Field Programmable Gate Array (FPGA). An -FPGA has a great advantage over a normal microcontroller in the sense that it emulates hardware. A -hardware description can be compiled and flashed into an FPGA. - -Because basic arithmetic functions can be performed fast and in parallel by an FPGA it is faster than an -implementation on a normal microcontroller. Only a real hardware implementation would be faster but -this lacks the flexibility of an FPGA. - -The FPGA can therefore be seen as dynamic hardware. It is possible to make a hardware design and flash -it into the memory of the FPGA. This gives some major advantages: - - - - "Hardware" errors can be corrected; the FPGA can be flashed with a new hardware design. - - Although not as fast as a real hardware implementation, an FPGA is faster than its equivalent on microprocessor. That is, it is specialized for one job. - -The FPGA has two main tasks. The first task is to demodulate the signal received from the ADC and relay -this as a digital encoded signal to the ARM. Depending on the task this might be the demodulation of a -100% Amplitude Shift Keying (ASK) signal from the reader or the load modulation of a card. The encoding -schemes used to communicate the signal to the ARM are Modified Miller for the reader and Manchester -encoding for the card signal. - -The second task is to modulate an encoded signal that is received from the ARM into the field of the -antenna. This can be both the encoding of reader messages or card messages. For reader messages the -FPGA generates an electromagnetic field on power hi and drops the amplitude for short periods. - - -## MICROCONTROLLER -The microcontroller is responsible for the protocol management. It receives the digital encoded signals -from the FPGA and decodes them. The decoded signals can just be copied to a buffer in the EEPROM -memory. Additionally, an answer to the received message can be send by encoding a reply and -communicating this to the FPGA. - -The microcontroller (ARM) implements the transport layer. First it decodes the samples received from -the FPGA. These samples are stored in a Direct Memory Access (DMA) buffer. The samples are binary -sequences that represent whether the signal was high or low. The software on the ARM tries to decode -these samples. When the Proxmark is in sniffing mode this is done for both the Manchester and Modified -Miller at the same time. Whenever one of the decoding procedures returns a valid message, this message -is stored in another buffer (BigBuf) and both decoding procedures are set to an un-synced state. The -BigBuf is limited to the available memory on the ARM. The current firmware has 2 KB of memory -reserved for traces (Besides the trace, the buffer also stores some temporary data that is needed in the -processing). When the BigBuf buffer is full the function normally returns. A new function call from the -client is needed to download the BigBuf contents to the computer. The BigBuf is especially useful for -protocol investigation. Every single message is stored in this buffer. When a card is emulated or when the -Proxmark is used as a reader the BigBuf can be used to store status messages or protocol exceptions. - -``` -HF PATH - -- ANTENNA -> rectifying -> lowpass filter -> ADC -> FPGA -> ARM -> USB/CDC | FPC -> CLIENT - | | | | - induct peak detect (8bit) -- modes: - via circuit HF - peak-detected - HF - RAW - HF - -``` - - -``` -LF PATH - - -- ANTENNA -> rectifying -> lowpass filter -> ADC -> FPGA -> ARM -> USB/CDC | FPC -> CLIENT - | | | | - induct peak detect (8bit) -- modes: - via circuit LF - peak-detected - LF - RAW -``` -Problems: - 1. dynamic range of signal. Ie: High Carrier signal (reader) and low - - -## - -## To behave like a READER. -By driving all of the buffers LOW, it is possible to make the antenna -look to the receive path like a parallel LC circuit; this provides a -high-voltage output signal. This is typically what will be done when we -are not actively transmitting a carrier (i.e., behaving as a reader). - -## To behave like a TAG -On the receive side, there are two possibilities, which are selected by -RLY1. A mechanical relay is used, because the signal from the antenna is -likely to be more positive or negative than the highest or lowest supply -voltages on-board. In the usual case (PEAK-DETECTED mode), the received -signal is peak-detected by an analog circuit, then filtered slightly, -and then digitized by the ADC. This is the case for both the low- and -high-frequency paths, although the details of the circuits for the -two cases are somewhat different. This receive path would typically -be selected when the device is behaving as a reader, or when it is -eavesdropping at close range. - -It is also possible to digitize the signal from the antenna directly (RAW -mode), after passing it through a gain stage. This is more likely to be -useful in reading signals at long range, but the available dynamic range -will be poor, since it is limited by the 8-bit A/D. - -In either case, an analog signal is digitized by the ADC, and -from there goes in to the FPGA. The FPGA is big enough that it -can perform DSP operations itself. For some high-frequency standards, -the subcarriers are fast enough that it would be inconvenient to do all -the math on a general-purpose CPU. The FPGA can therefore correlate for -the desired signal itself, and simply report the total to the ARM. For -low-frequency tags, it probably makes sense just to pass data straight -through to the ARM. - -The FPGA communicates with the ARM through either its SPI port (the ARM -is the master) or its generic synchronous serial port (again, the ARM -is the master). The ARM connects to the outside world over USB. - -## To sniff traffic - - - -## FPGA purpose -Digital signal processing. -In short, apply low pass / hi pass filtering, peak detect, correlate signal meaning IQ pair collecting. - -IQ means measure at In-phase and 90 phase shift later Quadrature-phase, with IQ samples you can plot the signal on a vector plan. - - -``` -IQ1 = 1,1 : 1, -1 (rising) -IQ2 = -1,1 : 1, 1 (falling) - - - - -1,1 | 1,1 - | (q2) - (i2) | (i1) - | - ----------0------------> - | - | (q1) - -1,-1 | 1, -1 -``` +# Notes on ARM & FPGA comms + + +https://github.com/RfidResearchGroup/proxmark3/blob/master/doc/original_proxmark3/proxmark3.pdf + +INTERFACE FROM THE ARM TO THE FPGA +================================== + +The FPGA and the ARM can communicate in two main ways: using the ARM's +general-purpose synchronous serial port (the SSP), or using the ARM's +SPI port. The SPI port is used to configure the FPGA. The ARM writes a +configuration word to the FPGA, which determines what operation will +be performed (e.g. read 13.56 MHz vs. read 125 kHz vs. read 134 kHz +vs...). The SPI is used exclusively for configuration. + +The SSP is used for actual data sent over the air. The ARM's SSP can +work in slave mode, which means that we can send the data using clocks +generated by the FPGA (either from the PCK0 clock, which the ARM itself +supplies, or from the 13.56 MHz clock, which is certainly not going to +be synchronous to anything in the ARM), which saves synchronizing logic +in the FPGA. The SSP is bi-directional and full-duplex. + + +The FPGA communicates with the ARM through either +1) SPI port (the ARM is the master) +2) SSC synchronous serial port (the ARM is the master). + + +opamps, (*note, this affects source code in ARM, calculating actual voltage from antenna. Manufacturers never report what they use to much frustration) +comparators +coil drivers + +LF analog path (MCP6294 opamp. This has a GBW of 10 MHz), all 'slow' signals. Used for low frequency signals. Follows the peak detector. Signal centered around generated voltage Vmid. + + +## FPGA +Since the SPARTAN II is a old outdated FPGA, thus is very limited resource there was a need to split LF and HF functionality into two separate FPGA images. Which are stored in ARM flash memory as bitstreams. + +We swap between these images by flashing fpga from ARM on the go. It takes about 1sec. Hence its usually a bad idea to program your device to continuously execute LF alt HF commands. + +The FPGA images is precompiled and located inside the /fpga folder. + - fpga_hf.bit + - fpga_lf.bit + +There is very rarely changes to the images so there is no need to setup a fpga tool chain to compile it yourself. +Since the FPGA is very old, the Xilinx WebPack ISE 10.1 is the last working tool chain. You can download this legacy development on Xilinx and register for a free product installation id. +Or use mine `11LTAJ5ZJK3PXTUBMF0C0J6C4` The package to download is about 7Gb and linux based. Though I recently managed to install it on WSL for Windows 10. + +In order to save space, these fpga images are LZ4 compressed and included in the fullimage.elf file when compiling the ARM SRC. `make armsrc` +This means we save some precious space on the ARM but its a bit more complex when flashing to fpga since it has to decompress on the fly. + + +### FPGA modes. + - Major modes + - Minor modes + +## ARM FPGA communications. + +The ARM talks with FPGA over the Synchronous Serial Port (SSC) rx an tx. + +ARM, send a 16bit configuration with fits the select major mode. + + + +## ARM GPIO setup + +``` + // First configure the GPIOs, and get ourselves a clock. + AT91C_BASE_PIOA->PIO_ASR = + GPIO_SSC_FRAME | + GPIO_SSC_DIN | + GPIO_SSC_DOUT | + GPIO_SSC_CLK; + AT91C_BASE_PIOA->PIO_PDR = GPIO_SSC_DOUT; + + AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_SSC); + + // Now set up the SSC proper, starting from a known state. + AT91C_BASE_SSC->SSC_CR = AT91C_SSC_SWRST; + + // RX clock comes from TX clock, RX starts on Transmit Start, + // data and frame signal is sampled on falling edge of RK + AT91C_BASE_SSC->SSC_RCMR = SSC_CLOCK_MODE_SELECT(1) | SSC_CLOCK_MODE_START(1); + + // 8, 16 or 32 bits per transfer, no loopback, MSB first, 1 transfer per sync + // pulse, no output sync + if ((FPGA_mode & FPGA_MAJOR_MODE_MASK) == FPGA_MAJOR_MODE_HF_READER && FpgaGetCurrent() == FPGA_BITSTREAM_HF) { + AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(16) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); + } else { + AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0); + } + + // TX clock comes from TK pin, no clock output, outputs change on rising edge of TK, + // TF (frame sync) is sampled on falling edge of TK, start TX on rising edge of TF + AT91C_BASE_SSC->SSC_TCMR = SSC_CLOCK_MODE_SELECT(2) | SSC_CLOCK_MODE_START(5); + + // tx framing is the same as the rx framing + AT91C_BASE_SSC->SSC_TFMR = AT91C_BASE_SSC->SSC_RFMR; + +``` + +## FPGA Setup + +// Set up DMA to receive samples from the FPGA. We will use the PDC, with +// a single buffer as a circular buffer (so that we just chain back to + + + +# HARDWARE OVERVIEW + +## ADC (ANALOG TO DIGITAL CONVERTER) +The analogue signal that comes from the antenna circuit is fed into an 8-bit Analogue to Digital Converter +(ADC). This delivers 8 output bits in parallel which represent the current voltage retrieved from the field. + + +## FIELD PROGRAMMABLE GATE ARRAY, FPGA +The 8 output pins from the ADC are connected to 8 pins of the Field Programmable Gate Array (FPGA). An +FPGA has a great advantage over a normal microcontroller in the sense that it emulates hardware. A +hardware description can be compiled and flashed into an FPGA. + +Because basic arithmetic functions can be performed fast and in parallel by an FPGA it is faster than an +implementation on a normal microcontroller. Only a real hardware implementation would be faster but +this lacks the flexibility of an FPGA. + +The FPGA can therefore be seen as dynamic hardware. It is possible to make a hardware design and flash +it into the memory of the FPGA. This gives some major advantages: + + + - "Hardware" errors can be corrected; the FPGA can be flashed with a new hardware design. + - Although not as fast as a real hardware implementation, an FPGA is faster than its equivalent on microprocessor. That is, it is specialized for one job. + +The FPGA has two main tasks. The first task is to demodulate the signal received from the ADC and relay +this as a digital encoded signal to the ARM. Depending on the task this might be the demodulation of a +100% Amplitude Shift Keying (ASK) signal from the reader or the load modulation of a card. The encoding +schemes used to communicate the signal to the ARM are Modified Miller for the reader and Manchester +encoding for the card signal. + +The second task is to modulate an encoded signal that is received from the ARM into the field of the +antenna. This can be both the encoding of reader messages or card messages. For reader messages the +FPGA generates an electromagnetic field on power hi and drops the amplitude for short periods. + + +## MICROCONTROLLER +The microcontroller is responsible for the protocol management. It receives the digital encoded signals +from the FPGA and decodes them. The decoded signals can just be copied to a buffer in the EEPROM +memory. Additionally, an answer to the received message can be send by encoding a reply and +communicating this to the FPGA. + +The microcontroller (ARM) implements the transport layer. First it decodes the samples received from +the FPGA. These samples are stored in a Direct Memory Access (DMA) buffer. The samples are binary +sequences that represent whether the signal was high or low. The software on the ARM tries to decode +these samples. When the Proxmark is in sniffing mode this is done for both the Manchester and Modified +Miller at the same time. Whenever one of the decoding procedures returns a valid message, this message +is stored in another buffer (BigBuf) and both decoding procedures are set to an un-synced state. The +BigBuf is limited to the available memory on the ARM. The current firmware has 2 KB of memory +reserved for traces (Besides the trace, the buffer also stores some temporary data that is needed in the +processing). When the BigBuf buffer is full the function normally returns. A new function call from the +client is needed to download the BigBuf contents to the computer. The BigBuf is especially useful for +protocol investigation. Every single message is stored in this buffer. When a card is emulated or when the +Proxmark is used as a reader the BigBuf can be used to store status messages or protocol exceptions. + +``` +HF PATH + -- ANTENNA -> rectifying -> lowpass filter -> ADC -> FPGA -> ARM -> USB/CDC | FPC -> CLIENT + | | | | + induct peak detect (8bit) -- modes: + via circuit HF - peak-detected + HF - RAW + HF - +``` + + +``` +LF PATH + + -- ANTENNA -> rectifying -> lowpass filter -> ADC -> FPGA -> ARM -> USB/CDC | FPC -> CLIENT + | | | | + induct peak detect (8bit) -- modes: + via circuit LF - peak-detected + LF - RAW +``` +Problems: + 1. dynamic range of signal. Ie: High Carrier signal (reader) and low + + +## + +## To behave like a READER. +By driving all of the buffers LOW, it is possible to make the antenna +look to the receive path like a parallel LC circuit; this provides a +high-voltage output signal. This is typically what will be done when we +are not actively transmitting a carrier (i.e., behaving as a reader). + +## To behave like a TAG +On the receive side, there are two possibilities, which are selected by +RLY1. A mechanical relay is used, because the signal from the antenna is +likely to be more positive or negative than the highest or lowest supply +voltages on-board. In the usual case (PEAK-DETECTED mode), the received +signal is peak-detected by an analog circuit, then filtered slightly, +and then digitized by the ADC. This is the case for both the low- and +high-frequency paths, although the details of the circuits for the +two cases are somewhat different. This receive path would typically +be selected when the device is behaving as a reader, or when it is +eavesdropping at close range. + +It is also possible to digitize the signal from the antenna directly (RAW +mode), after passing it through a gain stage. This is more likely to be +useful in reading signals at long range, but the available dynamic range +will be poor, since it is limited by the 8-bit A/D. + +In either case, an analog signal is digitized by the ADC, and +from there goes in to the FPGA. The FPGA is big enough that it +can perform DSP operations itself. For some high-frequency standards, +the subcarriers are fast enough that it would be inconvenient to do all +the math on a general-purpose CPU. The FPGA can therefore correlate for +the desired signal itself, and simply report the total to the ARM. For +low-frequency tags, it probably makes sense just to pass data straight +through to the ARM. + +The FPGA communicates with the ARM through either its SPI port (the ARM +is the master) or its generic synchronous serial port (again, the ARM +is the master). The ARM connects to the outside world over USB. + +## To sniff traffic + + + +## FPGA purpose +Digital signal processing. +In short, apply low pass / hi pass filtering, peak detect, correlate signal meaning IQ pair collecting. + +IQ means measure at In-phase and 90 phase shift later Quadrature-phase, with IQ samples you can plot the signal on a vector plan. + + +``` +IQ1 = 1,1 : 1, -1 (rising) +IQ2 = -1,1 : 1, 1 (falling) + + + + -1,1 | 1,1 + | (q2) + (i2) | (i1) + | + ----------0------------> + | + | (q1) + -1,-1 | 1, -1 +``` diff --git a/doc/mfu_binary_format_notes.md b/doc/mfu_binary_format_notes.md index dfde0da7a..85935160b 100644 --- a/doc/mfu_binary_format_notes.md +++ b/doc/mfu_binary_format_notes.md @@ -1,101 +1,101 @@ -# Notes on MFU binary formats - - - new mfu format - - old mfu format - - plain mfu format - - future mfu format - -## New mfu format -The new mfu binary format was created to compensate for different manufactures tag functions. -Like UL-Ev1 has three counter and tearing bytes, while NTAG only has one counter and tearing byte. -PACK was removed from header, since its just normally part of the tag memory, unreadable, but when -a proxmark3 dumps a tag and we have pwd/pack, we add those to their normal location in memory. -This makes memory not a exact memory dump from a tag, but a "what it should have looked like" if we could read all memory - -``` -// New Ultralight/NTAG dump file format -// Length must be aligned to 4 bytes (UL/NTAG page) -#define MFU_DUMP_PREFIX_LENGTH 56 - -typedef struct { - uint8_t version[8]; - uint8_t tbo[2]; - uint8_t tbo1[1]; - uint8_t pages; // max page number in dump - uint8_t signature[32]; - uint8_t counter_tearing[3][4]; // 3 bytes counter, 1 byte tearing flag - uint8_t data[1024]; -} PACKED mfu_dump_t; -``` - -## Old mfu format -The old binary format saved the extra data on tag in order for the Proxmark3 to able to simulate a real tag. - -``` -// Old Ultralight/NTAG dump file format -#define OLD_MFU_DUMP_PREFIX_LENGTH 48 - -typedef struct { - uint8_t version[8]; - uint8_t tbo[2]; - uint8_t tearing[3]; - uint8_t pack[2]; - uint8_t tbo1[1]; - uint8_t signature[32]; - uint8_t data[1024]; -} old_mfu_dump_t; -``` - -## Plain mfu format -The first binary format for MFU was just a memory dump from the tag block 0 to end. -No extra data was saved. -``` - uint8_t data[1024]; -``` - -## future mfu format -For developers of apps and other tools, like libnfc, we don't recommend using binary formats. -We decided to adopt a JSON based format, which is much more flexible to changes of new tag functionality. - -Example -``` -{ - "Created": "proxmark3", - "FileType": "mfu", - "Card": { - "UID": "04F654CAFC388", - "Version": "0004030101000B0", - "TBO_0": "000", - "TBO_1": "0", - "Signature": "BC9BFD4B550C16B2B5A5ABA10B644A027B4CB03DDB46F94D992DC0FB02E0C3F", - "Counter0": "00000", - "Tearing0": "BD", - "Counter1": "00000", - "Tearing1": "BD", - "Counter2": "00000", - "Tearing2": "BD" - }, - "blocks": { - "0": "04F6542", - "1": "CAFC388", - "2": "8E48000", - "3": "E110120", - "4": "0103A00", - "5": "340300F", - "6": "0000000", - "7": "0000000", - "8": "0000000", - "9": "0000000", - "10": "0000000", - "11": "0000000", - "12": "1122334", - "13": "0000000", - "14": "0000000", - "15": "0000000", - "16": "000000F", - "17": "0005000", - "18": "0000000", - "19": "0000000" - } -} -``` +# Notes on MFU binary formats + + - new mfu format + - old mfu format + - plain mfu format + - future mfu format + +## New mfu format +The new mfu binary format was created to compensate for different manufactures tag functions. +Like UL-Ev1 has three counter and tearing bytes, while NTAG only has one counter and tearing byte. +PACK was removed from header, since its just normally part of the tag memory, unreadable, but when +a proxmark3 dumps a tag and we have pwd/pack, we add those to their normal location in memory. +This makes memory not a exact memory dump from a tag, but a "what it should have looked like" if we could read all memory + +``` +// New Ultralight/NTAG dump file format +// Length must be aligned to 4 bytes (UL/NTAG page) +#define MFU_DUMP_PREFIX_LENGTH 56 + +typedef struct { + uint8_t version[8]; + uint8_t tbo[2]; + uint8_t tbo1[1]; + uint8_t pages; // max page number in dump + uint8_t signature[32]; + uint8_t counter_tearing[3][4]; // 3 bytes counter, 1 byte tearing flag + uint8_t data[1024]; +} PACKED mfu_dump_t; +``` + +## Old mfu format +The old binary format saved the extra data on tag in order for the Proxmark3 to able to simulate a real tag. + +``` +// Old Ultralight/NTAG dump file format +#define OLD_MFU_DUMP_PREFIX_LENGTH 48 + +typedef struct { + uint8_t version[8]; + uint8_t tbo[2]; + uint8_t tearing[3]; + uint8_t pack[2]; + uint8_t tbo1[1]; + uint8_t signature[32]; + uint8_t data[1024]; +} old_mfu_dump_t; +``` + +## Plain mfu format +The first binary format for MFU was just a memory dump from the tag block 0 to end. +No extra data was saved. +``` + uint8_t data[1024]; +``` + +## future mfu format +For developers of apps and other tools, like libnfc, we don't recommend using binary formats. +We decided to adopt a JSON based format, which is much more flexible to changes of new tag functionality. + +Example +``` +{ + "Created": "proxmark3", + "FileType": "mfu", + "Card": { + "UID": "04F654CAFC388", + "Version": "0004030101000B0", + "TBO_0": "000", + "TBO_1": "0", + "Signature": "BC9BFD4B550C16B2B5A5ABA10B644A027B4CB03DDB46F94D992DC0FB02E0C3F", + "Counter0": "00000", + "Tearing0": "BD", + "Counter1": "00000", + "Tearing1": "BD", + "Counter2": "00000", + "Tearing2": "BD" + }, + "blocks": { + "0": "04F6542", + "1": "CAFC388", + "2": "8E48000", + "3": "E110120", + "4": "0103A00", + "5": "340300F", + "6": "0000000", + "7": "0000000", + "8": "0000000", + "9": "0000000", + "10": "0000000", + "11": "0000000", + "12": "1122334", + "13": "0000000", + "14": "0000000", + "15": "0000000", + "16": "000000F", + "17": "0005000", + "18": "0000000", + "19": "0000000" + } +} +``` diff --git a/pm3 b/pm3 index 27e992b11..0d3b9863a 100755 --- a/pm3 +++ b/pm3 @@ -133,7 +133,7 @@ function get_pm3_list_Windows { # Need to look for this first, the call to Win32_serialport "crashes" then native bt serial port. Don't ask why. #BT direct SERIAL PORTS (COM) if $FINDBTRFCOMM; then - for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev/null | awk 'match($0,/COM([0-9]+)/,m){print m[1]}'); do + for DEV in $(wmic /locale:ms_409 path Win32_PnPEntity Where "Caption LIKE '%Bluetooth%(COM%'" Get Name 2> /dev/null | awk -b 'match($0,/(COM[0-9]+)/,m){print m[1]}'); do DEV=${DEV/ */} PM3LIST+=("$DEV") if [ ${#PM3LIST[*]} -ge "$N" ]; then @@ -143,7 +143,7 @@ function get_pm3_list_Windows { fi # Normal SERIAL PORTS (COM) - for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_9AC4&PID_4B8F*' | Select DeviceID" 2>/dev/null | awk '/^COM/{print $1}'); do + for DEV in $(wmic /locale:ms_409 path Win32_SerialPort Where "PNPDeviceID LIKE '%VID_9AC4&PID_4B8F%'" Get DeviceID 2>/dev/null | awk -b '/^COM/{print $1}'); do DEV=${DEV/ */} PM3LIST+=("$DEV") if [ ${#PM3LIST[*]} -ge "$N" ]; then @@ -153,7 +153,7 @@ function get_pm3_list_Windows { #white BT dongle SERIAL PORTS (COM) if $FINDBTDONGLE; then - for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev/null | awk '/^COM/{print $1}'); do + for DEV in $(wmic /locale:ms_409 path Win32_SerialPort Where "PNPDeviceID LIKE '%VID_10C4&PID_EA60%'" Get DeviceID 2>/dev/null | awk -b '/^COM/{print $1}'); do DEV=${DEV/ */} PM3LIST+=("$DEV") if [ ${#PM3LIST[*]} -ge "$N" ]; then