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 2020-03-23 18:46:57

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

Problem reading input

Hello all,

I have a problem while trying to use utils.input or io.read in my script.
The first reading is ok, but the next one is not. It looks like I have a carriage return in the input captured.
I use io.flush before, but it still doesn't work.

Helllllp smile

Offline

#2 2020-03-23 22:34:02

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

Re: Problem reading input

After further investigations, i've found someting quite strange.

The problem occurs only after calling a core method which calculates CRCs.

Here is a short example which shows the problem : enter 'yes' how many times you want, and it displays that you keyed in 'yes'.
If you enter 'crc', it displays a crc.
After having tried 'crc', try to enter again whatever crc or yes, it won't work anymore ...


local utils = require('utils')

local function main()
local crcD
local bool = true
local kbinput


repeat
kbinput = utils.input("Enter 'yes' or 'crc' :")
if kbinput == "crc" then
    crcD = utils.SwapEndianness(core.reveng_runmodel("CRC-16/ARC", "A00000000000000F", false, '0'),16)
    print("***********************************************************Calc of a CRC :"..crcD)
    end
if kbinput == "yes" then
    print("********************You keyed in :"..kbinput)
    end
until bool == false
   
end

main()

Offline

#3 2020-03-23 23:17:29

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

Re: Problem reading input

Here is a quick and dirty way of getting rid of the bug :

input = utils.input(message)
if string.byte(string.sub(input,-1)) == 13 then input = string.sub(input,1,(string.len(input)-1)) end

Offline

#4 2020-03-24 08:47:39

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

Re: Problem reading input

I don't follow,  the input function works just fine.

local utils = require('utils')

local function main()
    local crcD
    local bool = true
    local kbinput

    repeat
        kbinput = utils.input("Enter 'yes' or 'crc' :")

        if kbinput == "crc" then
            crcD = utils.SwapEndianness(core.reveng_runmodel("CRC-16/ARC", "A00000000000000F", false, '0'),16)
            print("***********************************************************Calc of a CRC :"..crcD)
        end

        if kbinput == "yes" then
            print("********************You keyed in :"..kbinput)
        end
    until bool == false
   
end

main()

result

[usb] pm3 --> scr run a
[+] executing lua /home/iceman/rdv4/client/luascripts/a.lua
[+] args ''
Enter 'yes' or 'crc' :
 > yes
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > yes
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > sad
Enter 'yes' or 'crc' :
 > crc
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > crc
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > cr
Enter 'yes' or 'crc' :
 > ys
Enter 'yes' or 'crc' :
 > yes
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > yes
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > calc
Enter 'yes' or 'crc' :
 > crc
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > yes
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > crc
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > crc
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > ^C

Offline

#5 2020-03-24 09:31:54

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

Re: Problem reading input

Strange ...
Maybe relative to the fact you have compiled your environnement for RDV4 whereas I have compiled for other models ?

This is the results I have :

[usb] pm3 --> script run lou2
[+] executing lua C:\ProxSpace-master\pm3\client\luascripts/lou2.lua
[+] args ''
Enter 'yes' or 'crc' :
 > crc
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > yes
Enter 'yes' or 'crc' :
 > yes
Enter 'yes' or 'crc' :
 > crc
Enter 'yes' or 'crc' :
 > crc
Enter 'yes' or 'crc' :
 >

Offline

#6 2020-03-24 10:12:45

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

Re: Problem reading input

that should not affect the lua part in regards to the utils.lua.

try doing some print  of the variables you are using.

Offline

#7 2020-03-24 11:03:07

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

Re: Problem reading input

New code with some more prints

local utils = require('utils')

local function main()
    local crcD
    local bool = true
    local kbinput

    repeat
        kbinput = utils.input("Enter 'yes' or 'crc' :")
		print("Lenght of input keyed in : "..string.len(kbinput))
		print("Last char of the input : "..string.sub(kbinput,-1).."("..string.byte(string.sub(kbinput,-1))..")")
        if kbinput == "crc" then
            crcD = utils.SwapEndianness(core.reveng_runmodel("CRC-16/ARC", "A00000000000000F", false, '0'),16)
            print("***********************************************************Calc of a CRC :"..crcD)
        end
        if kbinput == "yes" then
            print("********************You keyed in :"..kbinput)
        end
    until bool == false
   
end

main()

Result is :

[usb] pm3 --> script run lou2
[+] executing lua C:\ProxSpace-master\pm3\client\luascripts/lou2.lua
[+] args ''
Enter 'yes' or 'crc' :
 > yes
Lenght of input keyed in : 3
Last char of the input : s(115)
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > crc
Lenght of input keyed in : 3
Last char of the input : c(99)
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > yes
Lenght of input keyed in : 4
(13) char of the input :
Enter 'yes' or 'crc' :

Notice (13) char of the input : : it should have outputed (13) at the end of the line.
Unfortunately, (13) is a carriage return thus the output start at the beginning of the current line, and then scratches the beginning of the line.

Last edited by loupetre (2020-03-24 11:17:09)

Offline

#8 2020-03-25 10:15:30

mwalker
Moderator
Registered: 2019-05-11
Posts: 318

Re: Problem reading input

Just had a quick play and got the same results as loupetre (windows 10)

I split the code a little

--            crcD = utils.SwapEndianness(core.reveng_runmodel("CRC-16/ARC", "A00000000000000F", false, '0'),16)
            data1 = core.reveng_runmodel("CRC-16/ARC", "A00000000000000F", false, '0');
            print (" data len "..string.len(data1).."["..data1.."]")
            crcD = utils.SwapEndianness(data1,16)

and found it happens when core.reveng_runmodel line is run.
If i dont run that, the swapendianness call works and no issue happens.

Its almost as if the function changes an EOL from LF to CR & LF.

Offline

#9 2020-03-25 10:53:31

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

Re: Problem reading input

Verifed the bug,  tried it in Proxspace 3.2,   same error.

io.read suddenly goes to add newline after the call to reveng_runmodel...

Offline

#10 2020-03-25 11:21:47

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

Re: Problem reading input

pull latest source and see if your problem still exists

Offline

#11 2020-03-25 15:46:48

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

Re: Problem reading input

I am on your repo RfidResearchGroup/proxmark3, not on Proxmark/proxmark3.

You 've merged on which one ?

Offline

#12 2020-03-25 16:11:56

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

Re: Problem reading input

rrg/iceman.

Offline

#13 2020-03-25 22:04:00

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

Re: Problem reading input

Well done, it works like a charm smile

[usb] pm3 --> script run lou2
[+] executing lua C:\ProxSpace-master\pm3\client\luascripts/lou2.lua
[+] args ''
Enter 'yes' or 'crc' :
 > yes
Lenght of input keyed in : 3
Last char of the input : s(115)
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > crc
Lenght of input keyed in : 3
Last char of the input : c(99)
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 > yes
Lenght of input keyed in : 3
Last char of the input : s(115)
********************You keyed in :yes
Enter 'yes' or 'crc' :
 > crc
Lenght of input keyed in : 3
Last char of the input : c(99)
***********************************************************Calc of a CRC :31818
Enter 'yes' or 'crc' :
 >

Thank you very much, it will be easier to handle keyboard inputs for me now !

Last edited by loupetre (2020-03-25 22:07:21)

Offline

Board footer

Powered by FluxBB