]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/scripting.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2013 m h swende <martin at swende.se>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // Some lua scripting glue to proxmark core.
9 //-----------------------------------------------------------------------------
14 #include "proxmark3.h"
17 #include "scripting.h"
19 * The following params expected:
25 static int l_SendCommand(lua_State
*L
){
29 The SendCommand (native) expects the following structure:
32 uint64_t cmd; //8 bytes
33 uint64_t arg[3]; // 8*3 bytes = 24 bytes
35 uint8_t asBytes[USB_CMD_DATA_SIZE]; // 1 byte * 512 = 512 bytes (OR)
36 uint32_t asDwords[USB_CMD_DATA_SIZE/4]; // 4 byte * 128 = 512 bytes
40 ==> A 544 byte buffer will do.
43 UsbCommand
*c
= (UsbCommand
*)lua_touserdata(L
, 1);
44 luaL_argcheck(L
, c
!= NULL
, 1, "'UsbCommand' expected");
49 * @brief The following params expected:
55 static int l_WaitForResponseTimeout(lua_State
*L
){
58 uint32_t cmd
= luaL_checkunsigned(L
,1);
59 printf("in l_WaitForResponseTimeout, got cmd 0x%0x\n",(int) cmd
);
60 //UsbCommand response;
62 //We allocate the usbcommand as userdata on the Lua-stack
63 size_t nbytes
= sizeof(UsbCommand
);
65 UsbCommand
*response
= (UsbCommand
*)lua_newuserdata(L
, nbytes
);
67 size_t ms_timeout
= 2000;
68 //Did the user send a timeout ?
69 //Check if the current top of stack is an integer
71 if(lua_isnumber( L
, 2))
73 printf("You sent a timout-value\n");
74 ms_timeout
= luaL_checkunsigned(L
,2);
76 printf("Timeout set to %dms\n" , (int) ms_timeout
);
78 if(WaitForResponseTimeout(cmd
, response
, ms_timeout
))
80 //Return the UsbCommand as userdata
81 //the usbcommand is already on the stack
82 // return 1 to signal one return value
86 //Don't return the UsbCommand. Pop it.
93 static int l_nonce2key(lua_State
*L
){ return CmdHF14AMfRdSc(luaL_checkstring(L
, 1));}
94 static int l_PrintAndLog(lua_State
*L
){ return CmdHF14AMfDump(luaL_checkstring(L
, 1));}
96 void set_pm3_libraries(lua_State
*L
)
98 static const luaL_Reg libs
[] = {
99 {"SendCommand", l_SendCommand
},
100 {"WaitForResponseTimeout", l_WaitForResponseTimeout
},
101 {"nonce2key", l_nonce2key
},
102 {"PrintAndLog", l_PrintAndLog
},
106 lua_pushglobaltable(L
);
107 // Core library is in this table. Contains '
108 //this is 'pm3' table
111 //Put the function into the hash table.
112 for (int i
= 0; libs
[i
].name
; i
++) {
113 lua_pushcfunction(L
, libs
[i
].func
);
114 lua_setfield(L
, -2, libs
[i
].name
);//set the name, pop stack
117 lua_setfield(L
, -2, "core");
119 //-- remove the global environment table from the stack