mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-20 15:26:13 +08:00
make style
This commit is contained in:
parent
05b4b27823
commit
41f36ca20b
|
@ -1140,24 +1140,24 @@ void SimulateIso14443aTag(int tagType, int flags, uint8_t *data) {
|
|||
AddCrc14A(emdata, len);
|
||||
EmSendCmd(emdata, len + 2);
|
||||
p_response = NULL;
|
||||
} else if ((receivedCmd[0] == MIFARE_ULC_WRITE || receivedCmd[0] == MIFARE_ULC_COMP_WRITE) && (tagType == 2 || tagType == 7)) { // Received a WRITE
|
||||
// cmd + block + 4/16 bytes data + 2 bytes crc
|
||||
if (len == 8 || len == 20) {
|
||||
bool isCrcCorrect = CheckCrc14A(receivedCmd, len);
|
||||
if (isCrcCorrect) {
|
||||
int block = receivedCmd[1] + 12; // first 12 blocks of emu are [getversion answer - check tearing - pack - 0x00 - signature]
|
||||
emlSetMem_xt(&receivedCmd[2], block, 1, 4);
|
||||
// send ACK
|
||||
EmSend4bit(CARD_ACK);
|
||||
} else {
|
||||
// send NACK 0x1 == crc/parity error
|
||||
EmSend4bit(CARD_NACK_PA);
|
||||
}
|
||||
} else {
|
||||
// send NACK 0x0 == invalid argument
|
||||
EmSend4bit(CARD_NACK_IV);
|
||||
}
|
||||
p_response = NULL;
|
||||
} else if ((receivedCmd[0] == MIFARE_ULC_WRITE || receivedCmd[0] == MIFARE_ULC_COMP_WRITE) && (tagType == 2 || tagType == 7)) { // Received a WRITE
|
||||
// cmd + block + 4/16 bytes data + 2 bytes crc
|
||||
if (len == 8 || len == 20) {
|
||||
bool isCrcCorrect = CheckCrc14A(receivedCmd, len);
|
||||
if (isCrcCorrect) {
|
||||
int block = receivedCmd[1] + 12; // first 12 blocks of emu are [getversion answer - check tearing - pack - 0x00 - signature]
|
||||
emlSetMem_xt(&receivedCmd[2], block, 1, 4);
|
||||
// send ACK
|
||||
EmSend4bit(CARD_ACK);
|
||||
} else {
|
||||
// send NACK 0x1 == crc/parity error
|
||||
EmSend4bit(CARD_NACK_PA);
|
||||
}
|
||||
} else {
|
||||
// send NACK 0x0 == invalid argument
|
||||
EmSend4bit(CARD_NACK_IV);
|
||||
}
|
||||
p_response = NULL;
|
||||
} else if (receivedCmd[0] == MIFARE_ULEV1_READSIG && tagType == 7) { // Received a READ SIGNATURE --
|
||||
// first 12 blocks of emu are [getversion answer - check tearing - pack - 0x00 - signature]
|
||||
uint16_t start = 4 * 4;
|
||||
|
|
|
@ -106,7 +106,7 @@ typedef struct {
|
|||
|
||||
#ifndef CheckCrc14A
|
||||
# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par);
|
||||
|
||||
|
|
|
@ -540,7 +540,7 @@ size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout) {
|
|||
uint8_t cmd[cmdlen];
|
||||
memset(cmd, 0, cmdlen);
|
||||
|
||||
cmd[0] = 0x0A; // 0x0A = send cid, 0x02 = no cid.
|
||||
cmd[0] = 0x0A; // 0x0A = send cid, 0x02 = no cid.
|
||||
cmd[0] |= pcb_blocknum; // OR the block number into the PCB
|
||||
cmd[1] = 0x00; // CID: 0x00 //TODO: allow multiple selected cards
|
||||
|
||||
|
|
|
@ -41,4 +41,4 @@ extern void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t arg2, u
|
|||
// 18 * 8 data bits, 18 * 1 parity bits, 5 start bits, 5 stop bits, 5 correction bits -> need 177 bytes buffer
|
||||
#define ALLOCATED_TAG_MODULATION_BUFFER_SIZE 512 // number of bytes required for precompiled response
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -848,7 +848,7 @@ int CmdHF15Restore(const char *Cmd) {
|
|||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Restoring data blocks.");
|
||||
|
||||
|
||||
while (1) {
|
||||
tried = 0;
|
||||
hex[0] = 0x00;
|
||||
|
|
|
@ -1060,7 +1060,7 @@ int CmdHF14AMfRestore(const char *Cmd) {
|
|||
}
|
||||
}
|
||||
fclose(fdump);
|
||||
PrintAndLogEx(INFO, "Finish restore");
|
||||
PrintAndLogEx(INFO, "Finish restore");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2221,7 +2221,7 @@ int CmdHF14AMfURestore(const char *Cmd) {
|
|||
|
||||
DropField();
|
||||
free(dump);
|
||||
PrintAndLogEx(INFO, "Finish restore");
|
||||
PrintAndLogEx(INFO, "Finish restore");
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
|
|
|
@ -547,7 +547,7 @@ int CmdT55xxDetect(const char *Cmd) {
|
|||
}
|
||||
|
||||
if (!tryDetectModulation())
|
||||
PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'") );
|
||||
PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -767,7 +767,7 @@ bool GetT55xxBlockData(uint32_t *blockdata) {
|
|||
return false;
|
||||
|
||||
uint8_t idx = config.offset;
|
||||
|
||||
|
||||
if (idx + 32 > DemodBufferLen) {
|
||||
PrintAndLogEx(WARNING, "The configured offset %d is too big. Possible offset: %d)", idx, DemodBufferLen - 32);
|
||||
return false;
|
||||
|
@ -1472,7 +1472,7 @@ int CmdT55xxInfo(const char *Cmd) {
|
|||
|
||||
if (((!gotdata) && (!config.Q5)) || (gotdata && (!dataasq5)))
|
||||
printT5x7KnownBlock0(block0);
|
||||
|
||||
|
||||
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -702,46 +702,46 @@ static int l_keygen_algoD(lua_State *L) {
|
|||
}
|
||||
|
||||
/*
|
||||
Read T55Xx block.
|
||||
Read T55Xx block.
|
||||
param1 uint8_t block
|
||||
param2 bool page1
|
||||
param3 bool override
|
||||
param4 uint32_t password
|
||||
*/
|
||||
static int l_T55xx_readblock(lua_State *L) {
|
||||
|
||||
|
||||
//Check number of arguments
|
||||
int n = lua_gettop(L);
|
||||
if ( n != 4 ) {
|
||||
return returnToLuaWithError(L, "Wrong number of arguments, got %d bytes, expected 4", n);
|
||||
if (n != 4) {
|
||||
return returnToLuaWithError(L, "Wrong number of arguments, got %d bytes, expected 4", n);
|
||||
}
|
||||
|
||||
|
||||
uint32_t block, usepage1, override, password;
|
||||
bool usepwd;
|
||||
size_t size;
|
||||
|
||||
|
||||
const char *p_blockno = luaL_checklstring(L, 1, &size);
|
||||
if (size < 1 || size > 2) return returnToLuaWithError(L, "Wrong size of blockNo, got %d, expected 1 or 2", (int) size);
|
||||
sscanf(p_blockno, "%x", &block);
|
||||
|
||||
|
||||
const char *p_usepage1 = luaL_checklstring(L, 2, &size);
|
||||
if (size != 1) return returnToLuaWithError(L, "Wrong size of usePage1, got %d, expected 1", (int) size);
|
||||
sscanf(p_usepage1, "%x", &usepage1);
|
||||
|
||||
|
||||
const char *p_override = luaL_checklstring(L, 3, &size);
|
||||
if (size != 1) return returnToLuaWithError(L, "Wrong size of override, got %d, expected 1", (int) size);
|
||||
sscanf(p_override, "%x", &override);
|
||||
|
||||
|
||||
const char *p_pwd = luaL_checklstring(L, 4, &size);
|
||||
if ( size == 0 ) {
|
||||
if (size == 0) {
|
||||
usepwd = false;
|
||||
} else {
|
||||
|
||||
if (size != 8) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size);
|
||||
sscanf(p_pwd, "%08x", &password);
|
||||
usepwd = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Password mode
|
||||
if (usepwd) {
|
||||
// try reading the config block and verify that PWD bit is set before doing this!
|
||||
|
@ -767,16 +767,16 @@ static int l_T55xx_readblock(lua_State *L) {
|
|||
if (!AquireData(usepage1, block, usepwd, password)) {
|
||||
return returnToLuaWithError(L, "Failed to aquire data from card");
|
||||
}
|
||||
|
||||
|
||||
if (!DecodeT55xxBlock()) {
|
||||
return returnToLuaWithError(L, "Failed to decode signal");
|
||||
}
|
||||
|
||||
|
||||
uint32_t blockData = 0;
|
||||
if (GetT55xxBlockData(&blockData) == false) {
|
||||
return returnToLuaWithError(L, "Failed to get actual data");
|
||||
}
|
||||
|
||||
|
||||
lua_pushunsigned(L, blockData);
|
||||
return 1;
|
||||
}
|
||||
|
@ -787,7 +787,7 @@ static int l_T55xx_detect(lua_State *L) {
|
|||
bool useGB = false, usepwd = false, isok;
|
||||
uint32_t gb, password = 0;
|
||||
size_t size;
|
||||
|
||||
|
||||
//Check number of arguments
|
||||
int n = lua_gettop(L);
|
||||
|
||||
|
@ -796,15 +796,15 @@ static int l_T55xx_detect(lua_State *L) {
|
|||
const char *p_gb = luaL_checklstring(L, 2, &size);
|
||||
if (size != 1) return returnToLuaWithError(L, "Wrong size of useGB, got %d , expected 1", (int) size);
|
||||
sscanf(p_gb, "%u", &gb);
|
||||
useGB = ( gb ) ? true : false;
|
||||
printf("p_gb size %zu | %c \n", size, useGB ? 'Y':'N');
|
||||
useGB = (gb) ? true : false;
|
||||
printf("p_gb size %zu | %c \n", size, useGB ? 'Y' : 'N');
|
||||
}
|
||||
case 1: {
|
||||
const char *p_pwd = luaL_checklstring(L, 1, &size);
|
||||
if ( size == 0 ) {
|
||||
if (size == 0) {
|
||||
usepwd = false;
|
||||
} else {
|
||||
|
||||
|
||||
if (size != 8) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size);
|
||||
sscanf(p_pwd, "%08x", &password);
|
||||
usepwd = true;
|
||||
|
@ -814,24 +814,24 @@ static int l_T55xx_detect(lua_State *L) {
|
|||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!useGB) {
|
||||
|
||||
|
||||
isok = AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password);
|
||||
if ( isok == false ) {
|
||||
if (isok == false) {
|
||||
// signal error by returning Nil, errorstring
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "Failed to aquire LF signal data");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
isok = tryDetectModulation();
|
||||
if ( isok == false ) {
|
||||
if (isok == false) {
|
||||
// signal error by returning Nil, errorstring
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
|
||||
lua_pushinteger(L, isok);
|
||||
|
|
|
@ -44,7 +44,7 @@ local DEBUG = false -- the debug flag
|
|||
local total_tests = 0
|
||||
local total_pass = 0
|
||||
|
||||
local data_blocks_cmds = {
|
||||
local data_blocks_cmds = {
|
||||
[1] = '00000000',
|
||||
[2] = 'ffffffff',
|
||||
[3] = '80000000',
|
||||
|
@ -96,10 +96,10 @@ end
|
|||
local function GetConfigs( modulation )
|
||||
|
||||
local t = {}
|
||||
|
||||
|
||||
t['PSK1'] = {
|
||||
[1] = '00001040',
|
||||
[2] = '00041040',
|
||||
[2] = '00041040',
|
||||
[3] = '00081040',
|
||||
[4] = '000c1040',
|
||||
[5] = '00101040',
|
||||
|
@ -118,7 +118,7 @@ local function GetConfigs( modulation )
|
|||
[7] = '00182040',
|
||||
[8] = '001c2040',
|
||||
}
|
||||
|
||||
|
||||
t['PSK3'] = {
|
||||
[1] = '00003040',
|
||||
[2] = '00043040',
|
||||
|
@ -141,7 +141,7 @@ local function GetConfigs( modulation )
|
|||
[8] = '00184040',
|
||||
[9] = '001c4040',
|
||||
}
|
||||
|
||||
|
||||
t['FSK2'] = {
|
||||
[1] = '00005040',
|
||||
[2] = '00045040',
|
||||
|
@ -152,7 +152,7 @@ local function GetConfigs( modulation )
|
|||
[7] = '00185040',
|
||||
[8] = '001c5040',
|
||||
}
|
||||
|
||||
|
||||
t['FSK1A'] = {
|
||||
[1] = '00006040',
|
||||
[2] = '00046040',
|
||||
|
@ -163,7 +163,7 @@ local function GetConfigs( modulation )
|
|||
[7] = '00186040',
|
||||
[8] = '001c6040',
|
||||
}
|
||||
|
||||
|
||||
t['FSK2A'] = {
|
||||
[1] = '00007040',
|
||||
[2] = '00047040',
|
||||
|
@ -174,10 +174,10 @@ local function GetConfigs( modulation )
|
|||
[7] = '00187040',
|
||||
[8] = '001c7040',
|
||||
}
|
||||
|
||||
|
||||
t['ASK'] = {
|
||||
[1] = '00008040',
|
||||
[2] = '00048040',
|
||||
[2] = '00048040',
|
||||
[3] = '00088040',
|
||||
[4] = '000c8040',
|
||||
[5] = '00108040',
|
||||
|
@ -185,7 +185,7 @@ local function GetConfigs( modulation )
|
|||
[7] = '00188040',
|
||||
[8] = '001c8040',
|
||||
}
|
||||
|
||||
|
||||
t['BI'] = {
|
||||
[1] = '00010040',
|
||||
[2] = '00050040',
|
||||
|
@ -196,7 +196,7 @@ local function GetConfigs( modulation )
|
|||
[7] = '00190040',
|
||||
[8] = '001d0040',
|
||||
}
|
||||
|
||||
|
||||
return t[modulation:upper()]
|
||||
end
|
||||
---
|
||||
|
@ -205,10 +205,10 @@ local function WipeCard()
|
|||
|
||||
print('Wiping card')
|
||||
core.console('lf t55xx wipe')
|
||||
|
||||
|
||||
print('Detecting card')
|
||||
local res, msg = core.t55xx_detect()
|
||||
if not res then
|
||||
if not res then
|
||||
oops("Can't detect modulation. Test failed.")
|
||||
core.console("rem [ERR:DETECT:WIPED] Failed to detect after wipe")
|
||||
return false
|
||||
|
@ -235,20 +235,20 @@ local function CheckReadBlock(block)
|
|||
end
|
||||
|
||||
local function test(modulation)
|
||||
|
||||
|
||||
local process_block0_cmds = {}
|
||||
local y
|
||||
local block = "00"
|
||||
|
||||
|
||||
local s = ('Start test of %s'):format(modulation)
|
||||
print(s)
|
||||
|
||||
|
||||
process_block0_cmds = GetConfigs(modulation)
|
||||
|
||||
|
||||
if process_block0_cmds == nil then return oops('Cant find modulation '..modulation) end
|
||||
|
||||
|
||||
for _ = 1, #process_block0_cmds do
|
||||
|
||||
|
||||
local p_config_cmd = process_block0_cmds[_]
|
||||
local errors = 0
|
||||
core.clearCommandBuffer()
|
||||
|
@ -261,9 +261,9 @@ local function test(modulation)
|
|||
if err then return oops(err) end
|
||||
local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT)
|
||||
|
||||
-- Detect
|
||||
-- Detect
|
||||
local res, msg = core.t55xx_detect()
|
||||
if not res then
|
||||
if not res then
|
||||
print("can't detect modulation, skip to next config")
|
||||
core.console(format("rem [ERR:DETECT:%s] Failed to detect modulation", p_config_cmd))
|
||||
core.console(format('rem [SUMMARY:%s] FAIL detection', p_config_cmd))
|
||||
|
@ -304,11 +304,11 @@ local function main(args)
|
|||
|
||||
core.clearCommandBuffer()
|
||||
local res
|
||||
|
||||
|
||||
-- Adjust this table to set which configurations should be tested
|
||||
-- local test_modes = { 'PSK1', 'PSK2', 'PSK3', 'FSK1', 'FSK2', 'FSK1A', 'FSK2A', 'ASK', 'BI' }
|
||||
local test_modes = { 'ASK', 'PSK1' }
|
||||
|
||||
|
||||
for _ = 1, #test_modes do
|
||||
res = WipeCard()
|
||||
if res then
|
||||
|
@ -322,6 +322,6 @@ local function main(args)
|
|||
|
||||
exitMsg('Tests finished')
|
||||
core.console( format('rem [SUMMARY] Success rate: %d/%d tests passed%s', total_pass, total_tests, total_pass < total_tests and ", help me improving that number!" or " \\o/"))
|
||||
|
||||
|
||||
end
|
||||
main(args)
|
||||
|
|
|
@ -200,8 +200,8 @@ int FillBuffer(uint8_t *data, size_t maxDataLength, size_t *dataLength, ...);
|
|||
|
||||
bool CheckStringIsHEXValue(const char *value);
|
||||
void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len,
|
||||
const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between,
|
||||
bool uppercase);
|
||||
const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between,
|
||||
bool uppercase);
|
||||
|
||||
void print_hex(const uint8_t *data, const size_t len);
|
||||
void print_hex_break(const uint8_t *data, const size_t len, const uint8_t breaks);
|
||||
|
|
14
common/crc.h
14
common/crc.h
|
@ -65,13 +65,13 @@ uint32_t CRC8Legic(uint8_t *buff, size_t size);
|
|||
/* Static initialization of a crc structure */
|
||||
#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \
|
||||
.state = ((_initial_value) & ((1L<<(_order))-1)), \
|
||||
.order = (_order), \
|
||||
.polynom = (_polynom), \
|
||||
.initial_value = (_initial_value), \
|
||||
.final_xor = (_final_xor), \
|
||||
.mask = ((1L<<(_order))-1) \
|
||||
.refin = false, \
|
||||
.refout = false \
|
||||
.order = (_order), \
|
||||
.polynom = (_polynom), \
|
||||
.initial_value = (_initial_value), \
|
||||
.final_xor = (_final_xor), \
|
||||
.mask = ((1L<<(_order))-1) \
|
||||
.refin = false, \
|
||||
.refout = false \
|
||||
}
|
||||
|
||||
#endif /* __CRC_H */
|
||||
|
|
|
@ -1620,7 +1620,7 @@ int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startId
|
|||
if (g_debugMode == 2) prnt("DEBUG nrzRawDemod: just noise detected - quitting");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
size_t clkStartIdx = 0;
|
||||
*clk = DetectNRZClock(dest, *size, *clk, &clkStartIdx);
|
||||
if (*clk == 0) return -2;
|
||||
|
@ -1911,13 +1911,13 @@ int pskRawDemod_ext(uint8_t *dest, size_t *size, int *clock, int *invert, int *s
|
|||
if (waveLenCnt > fc) {
|
||||
//this wave is a phase shift
|
||||
/*
|
||||
prnt("DEBUG: phase shift at: %d, len: %d, nextClk: %d, i: %d, fc: %d"
|
||||
prnt("DEBUG: phase shift at: %d, len: %d, nextClk: %d, i: %d, fc: %d"
|
||||
, waveStart
|
||||
, waveLenCnt
|
||||
, lastClkBit + *clock - tol
|
||||
, i + 1
|
||||
, fc);
|
||||
*/
|
||||
*/
|
||||
if (i + 1 >= lastClkBit + *clock - tol) { //should be a clock bit
|
||||
curPhase ^= 1;
|
||||
dest[numBits++] = curPhase;
|
||||
|
|
Loading…
Reference in a new issue