Proxmark3 community

Research, development and trades concerning the powerful Proxmark3 device.

Remember; sharing is caring. Bring something back to the community.


"Learn the tools of the trade the hard way." +Fravia

You are not logged in.

Announcement

Time changes and with it the technology
Proxmark3 @ discord

Users of this forum, please be aware that information stored on this site is not private.

#1 2019-03-18 14:16:38

loupetre
Contributor
Registered: 2019-01-21
Posts: 29

How can I get the return code in lua ?

Hi everybody,

After sending commands to a tag (e.g. hf mf wrbl ...), a result code is sent to the output : isOk:00 or isOk:01.
I would like to get the value of this return code in order to use it in my scripts. How can I do that ?

Thanks

Offline

#2 2019-03-18 19:51:18

iceman
Administrator
Registered: 2013-04-25
Posts: 9,495
Website

Re: How can I get the return code in lua ?

you need to not use the console command but rather implement that direct calls.   Lots of scripts,  which lets you get ideas how to solve your problem

Offline

#3 2020-02-12 22:13:48

Winds
Member
Registered: 2020-01-28
Posts: 53

Re: How can I get the return code in lua ?

iceman wrote:

you need to not use the console command but rather implement that direct calls.   Lots of scripts,  which lets you get ideas how to solve your problem

Iceman, could you please show an example and we see how it to get?
Scripts has using a core.consele method to send and I never seen way for the returning a responce from the console.

Many Thanks

Offline

#4 2020-03-26 21:21:21

loupetre
Contributor
Registered: 2019-01-21
Posts: 29

Re: How can I get the return code in lua ?

Here is an example :

Instead of doing something like

...
local command="hf mf rdbl 0 A FFFFFFFFFFFF"
core.console(command)
...

you can do this

local function getblockdata(response)
    if not response then
	-- print("No response from device")
        return nil, "No response from device"
    end
    if response.Status == PM3_SUCCESS then
        return response.Data, "Success"
    else
	-- print("Couldn't read block .. ["..response.Status.."]")
        return nil, "Couldn't read block .. ["..response.Status.."]"
    end
end

...

local function main()
...
local data = "0000FFFFFFFFFFFF"
local c = Command:newNG{cmd = cmds.CMD_HF_MIFARE_READBL, data = data}
local b, err = getblockdata(c:sendNG(false))

-- you now have access to b.Status, b.Data, ...
...

Last edited by loupetre (2020-03-26 21:24:28)

Offline

#5 2020-12-23 19:19:48

ebodyyy
Contributor
Registered: 2019-10-02
Posts: 14

Re: How can I get the return code in lua ?

Hello,

I tried the code above and entered in a few of the missing "require" commands, but I'm getting an error with reading block 0. . I've looked at all the Lua examples in the Luascripts directory and reviewed the Lua libs.

BTW i do have a MF fob on the proxmark as i run this.


Here's the error i'm getting when i run the script:

Couldn't read block .. [0]	
[-] ⛔ error - ...oel/proxmark4/proxmark3/client/luascripts/e_test.lua:25: attempt to index local 'b' (a nil value)

Here's the code:

local cmds = require('commands')
local getopt = require('getopt')

local function getblockdata(response)
    if not response then
	-- print("No response from device")
        return nil, "No response from device"
    end
    if response.Status == PM3_SUCCESS then
        return response.Data, "Success"
    else
	-- print("Couldn't read block .. ["..response.Status.."]")
        return nil, "Couldn't read block .. ["..response.Status.."]"
    end
end

local function main()

local data = "0000FFFFFFFFFFFF"
local c = Command:newNG{cmd = cmds.CMD_HF_MIFARE_READBL, data = data}
local b, err = getblockdata(c:sendNG(false))
print(b.Data)

end
main()

Last edited by ebodyyy (2020-12-25 21:42:16)

Offline

Board footer

Powered by FluxBB