mame82 / duck2spark

Converter for raw RubberDucky payloads to Digispark Arduino IDE Sketch source.
472 stars 95 forks source link

"hex(ord(...))" not needed on lines 65 and 66 #6

Open holly-hacker opened 7 years ago

holly-hacker commented 7 years ago

The following code is line 64, 65 and 66 from the main .py file:

    for c in range(l - 1):
        declare += str(payload[c]) + ", "
    declare += str(payload[l - 1]) + "\n};\nint i = %d; //-snip-\n" % loop_count

I ran this code with python 3.6, and got the following error:

Traceback (most recent call last):
  File "C:\Users\PC1\Desktop\Programming\DigiSpark\duck2spark.py", line 155, in <module>
    main(sys.argv[1:])
  File "C:\Users\PC1\Desktop\Programming\DigiSpark\duck2spark.py", line 140, in main
    result = generate_source(payload, init_delay=init_delay, loop_count=loop_count, loop_delay=loop_delay, blink=blink)
  File "C:\Users\PC1\Desktop\Programming\DigiSpark\duck2spark.py", line 65, in generate_source
    declare += str(hex(ord(payload[c]))) + ", "
TypeError: ord() expected string of length 1, but int found

Since I know some python, I decided to look into the problem and it turns out that simply removing the calls to hex() and ord() makes the script run without problems. I verified that the output still works.

Changed code becomes this:

    for c in range(l - 1):
        declare += str(payload[c]) + ", "
    declare += str(payload[l - 1]) + "\n};\nint i = %d; //-snip-\n" % loop_count

I have not tested with python 2.x.

ratzvasky commented 6 years ago

The same problem happen here, the code from @HoLLy-HaCKeR solved the problem.

Thanks!

3ldidi94 commented 5 years ago

The code from @HoLLy-HaCKeR solved the issue for me too. I am using Python 3.7 Thanks

0x48piraj commented 5 years ago

Throws TypeError: ord()

$> py duck2spark.py -i raw.bin -l 1 -f 2000 -o sketch.ino
Traceback (most recent call last):
  File "duck2spark.py", line 155, in <module>
    main(sys.argv[1:])
  File "duck2spark.py", line 140, in main
    result = generate_source(payload, init_delay=init_delay, loop_count=loop_count, loop_delay=loop_delay, blink=blink)
  File "duck2spark.py", line 65, in generate_source
    declare += str(hex(ord(payload[c]))) + ", "
TypeError: ord() expected string of length 1, but int found

Ping @mame82

gstorelli commented 5 years ago

Please merge it with the Master as the provided original code is not working with Python 3. @HoLLy-HaCKeR one works perfectly!

HenriquesCoutinho commented 1 year ago

I changed lines 64, 65 and 66. now it is showing the error:

File "C:\Users\HENRIQUES COUTINHO\Documents\Get-Chrome80Dump-main\duck2spark\duck2spark.py", line 7 def generate_source(payload, init_delay=2500, loop_count=-1, loop_delay=5000, blink=True, c): ^ SyntaxError: non-default argument follows default argument

How to solve?