Newer
Older
glitch-o-bolt / ConfigGlitchBrute.py
  1. ######
  2. # LEAVE THESE IMPORTS!
  3. ######
  4. import functions
  5. import random
  6. from textual.widgets import Log
  7.  
  8. ######
  9. # config values
  10. ######
  11.  
  12. SERIAL_PORT = '/dev/ttyUSB0'
  13. BAUD_RATE = 115200
  14.  
  15. LENGTH = 1
  16. REPEAT = 1
  17. DELAY = 1
  18.  
  19. ###
  20. # ^ = pullup, v = pulldown
  21. ###
  22. triggers = [
  23. ['-', False], #0
  24. ['-', False], #1
  25. ['-', False], #2
  26. ['-', False], #3
  27. ['-', False], #4
  28. ['-', False], #5
  29. ['-', False], #6
  30. ['-', False], #7
  31. ]
  32.  
  33. ###
  34. # name, enabled, string to match in output, function to run
  35. # if string is blank ("") doesnt show toggle, just run button
  36. ###
  37. conditions = [
  38. ["Flag", True, "ctf", "stop_glitching"],
  39. ["pt1", True, "Hold one of", "start_chal_02"], # requires bolt output gpio pin 0 -> challenge board chall 2 button
  40. ["pt2", True, "Starting challenge 2", "glitched_too_far"],
  41. ["std", True, "1000000", "perform_glitch"]
  42. ]
  43.  
  44. ######
  45. # Custom functions for conditions to trigger
  46. ######
  47.  
  48. def stop_glitching():
  49. elapsed = functions.get_glitch_elapsed()
  50. functions.glitching_switch(False)
  51. functions.add_text(f"[auto] glitching stopped (elapsed: {elapsed})")
  52.  
  53. def start_chal_02():
  54. functions.run_output_high(0, 30000000) ## can also run_output_low() if need too
  55. #functions.execute_condition_action("glitched_too_far")
  56.  
  57. increment_delay = True
  58. increment_length = True
  59. inc_delay_amount = 100
  60. inc_repeat_amount = 100
  61. inc_length_amount = 100
  62.  
  63. def perform_glitch():
  64. global increment_delay, increment_length
  65. global inc_delay_aamount, inc_repeat_amount, inc_length_amount
  66. if increment_delay:
  67. to_increment = "delay"
  68. increment_amount = inc_delay_amount
  69. increment_delay = False
  70. else:
  71. if increment_length:
  72. to_increment = "length"
  73. increment_amount = inc_length_amount
  74. increment_length = False
  75. increment_delay = True
  76. else:
  77. to_increment = "repeat"
  78. increment_amount = inc_repeat_amount
  79. increment_length = True
  80. increment_delay = True
  81. current_val = functions.get_config_value(to_increment)
  82. new_val = current_val + increment_amount
  83. functions.set_config_value(to_increment, new_val)
  84.  
  85. functions.add_text(f"[auto] incrementing: {to_increment}")
  86. Len = functions.get_config_value("length")
  87. Rep = functions.get_config_value("repeat")
  88. Del = functions.get_config_value("delay")
  89. functions.start_glitch(Len, Rep, Del)
  90. def glitched_too_far():
  91. global increment_delay, increment_length
  92. global inc_delay_amount, inc_repeat_amount, inc_length_amount
  93. # Determine which value to decrement based on current state
  94. if increment_delay:
  95. if increment_length:
  96. to_decrement = "repeat"
  97. current_inc_amount = inc_repeat_amount
  98. else:
  99. to_decrement = "length"
  100. current_inc_amount = inc_length_amount
  101. else:
  102. to_decrement = "delay"
  103. current_inc_amount = inc_delay_amount
  104. # Get current value and decrement it
  105. current_val = functions.get_config_value(to_decrement)
  106. new_val = current_val - current_inc_amount
  107. functions.set_config_value(to_decrement, new_val)
  108. # Update the increment amount for next time
  109. if current_inc_amount == 100:
  110. new_inc_amount = 10
  111. elif current_inc_amount == 10:
  112. new_inc_amount = 1
  113. else:
  114. new_inc_amount = current_inc_amount # keep as is if not 100 or 10
  115. # Update the correct increment amount variable
  116. if to_decrement == "delay":
  117. inc_delay_amount = new_inc_amount
  118. elif to_decrement == "length":
  119. inc_length_amount = new_inc_amount
  120. elif to_decrement == "repeat":
  121. inc_repeat_amount = new_inc_amount
  122.  
  123. functions.add_text(f"[auto] decrementing: {to_decrement}")
Buy Me A Coffee