Class: Parallel_export

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/class/PARALLEL/Parallel_export.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, chip) ⇒ Parallel_export

Returns a new instance of Parallel_export.

[View source]

15
16
17
18
19
20
21
22
23
24
25
# File 'lib/class/PARALLEL/Parallel_export.rb', line 15

def initialize(api, chip)
  super()
  @parallel_export_gui = Ui_Generic_export.new
  centerWindow(self)
  @parallel_export_gui.setupUi(self)
  @parallel_export_gui.lbl_chip.setText(chip.chip_reference)
  inputRestrict(@parallel_export_gui.lie_start, 0)
  inputRestrict(@parallel_export_gui.lie_stop, 0)
  @api = api
  @chip_settings = Parallel.find_by(parallel_chip: chip.chip_id)
end

Instance Method Details

#check_SendAndReceivedData(value) ⇒ Object

[View source]

134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/class/PARALLEL/Parallel_export.rb', line 134

def check_SendAndReceivedData(value)
  case value
    when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
      Qt::MessageBox.new(Qt::MessageBox::Critical, "Critical error", "PACKET_IS_TOO_LARGE max: #{HardsploitAPI::USB::USB_TRAME_SIZE}").exec
    when HardsploitAPI::USB_STATE::ERROR_SEND
      Qt::MessageBox.new(Qt::MessageBox::Critical, "Critical error", "ERROR_SEND").exec
    when HardsploitAPI::USB_STATE::BUSY
      Qt::MessageBox.new(Qt::MessageBox::Warning, "BUSY", "Device busy").exec
    else
      return value
  end
end

#close_fileObject

[View source]

40
41
42
43
44
45
46
47
48
# File 'lib/class/PARALLEL/Parallel_export.rb', line 40

def close_file
  unless $file.nil?
    $file.close
  end
rescue Exception => msg
  logger = Logger.new($logFilePath)
  logger.error msg
  Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
end

#control_export_result(stop, time) ⇒ Object

[View source]

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/class/PARALLEL/Parallel_export.rb', line 83

def control_export_result(stop, time)
  time = Time.new - time
  file_size = File.size("#{@filepath}")
  # 8 bits test
  if @chip_settings.parallel_word_size.zero?
    if (stop - @cw.lie_start.text.to_i + 1) == file_size
      Qt::MessageBox.new(Qt::MessageBox::Information, "Information", "Dump finished at #{((file_size / time)).round(2)}Bytes/s (#{(file_size)} Bytes in  #{time.round(4)} s)").exec
    else
      Qt::MessageBox.new(Qt::MessageBox::Critical, "Error", "Dump error: Size does not match").exec
    end
  else
    if (stop - @cw.lie_start.text.to_i + 1) == (file_size / 2)
      Qt::MessageBox.new(Qt::MessageBox::Information, "Information", "Dump finished at #{((file_size / time)).round(2)}Bytes/s (#{(file_size)} Bytes in  #{time.round(4)} s)").exec
    else
      Qt::MessageBox.new(Qt::MessageBox::Critical, "Error", "Dump error: File size and dump size does not match").exec
    end
  end
  p "DUMP #{((file_size/time)).round(2)}Bytes/s (#{(file_size)}Bytes in  #{time.round(4)} s)"
end

#control_export_settings(type) ⇒ Object

[View source]

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/class/PARALLEL/Parallel_export.rb', line 103

def control_export_settings(type)
  if @chip_settings.nil?
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'No settings saved for this chip').exec
    return 0
  end
  if @chip_settings.parallel_read_latency.nil? || @chip_settings.parallel_word_size.nil?
    Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'Read latency or word size settings missing').exec
    return 0
  end
  if type == 'full'
    if @chip_settings.parallel_total_size.zero? || @chip_settings.parallel_total_size.nil?
      Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Full size setting missing or equal 0').exec
      return 0
    end
  else
    if @parallel_export_gui.lie_start.text.empty? || @parallel_export_gui.lie_stop.text.empty?
      Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Start and stop address must be filled').exec
      return 0
    end
    if @parallel_export_gui.lie_start.text.to_i > @parallel_export_gui.lie_stop.text.to_i
      Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start address must be inforior to the stop address').exec
      return 0
    end
    if @parallel_export_gui.lie_start.text.to_i > (@chip_settings.parallel_total_size - 1) || @parallel_export_gui.lie_stop.text.to_i > (@chip_settings.parallel_total_size - 1)
      Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start and stop address must be inforior to the chip total size').exec
      return 0
    end
  end
  return 1
end

#exportObject

[View source]

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/class/PARALLEL/Parallel_export.rb', line 50

def export
  if sender.objectName == 'btn_full_export'
    return 0 if control_export_settings('full').zero?
  else
    return 0 if control_export_settings('partial').zero?
  end
  Firmware.new(@api, 'PARALLEL')
  time = Time.new
  if sender.objectName == 'btn_full_export'
    if @chip_settings.parallel_word_size.zero?
      check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(0, @chip_settings.parallel_total_size - 1, true, @chip_settings.parallel_read_latency))
    else
      check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(0, @chip_settings.parallel_total_size - 1, false, @chip_settings.parallel_read_latency))
    end
    close_file
    control_export_result(@chip_settings.parallel_total_size - 1, time)
  else
    if @chip_settings.parallel_word_size.zero?
      check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(@parallel_export_gui.lie_start.text.to_i, @parallel_export_gui.lie_stop.text.to_i, true, @chip_settings.parallel_read_latency))
    else
      check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(@parallel_export_gui.lie_start.text.to_i, @parallel_export_gui.lie_stop.text.to_i, true, @chip_settings.parallel_read_latency))
    end
    close_file
    control_export_result(@parallel_export_gui.lie_stop.text.to_i, time)
  end
  @parallel_export_gui.btn_export.setEnabled(false)
  @parallel_export_gui.btn_full_export.setEnabled(false)
rescue Exception => msg
  logger = Logger.new($logFilePath)
  logger.error msg
  Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while full export operation. Consult the logs for more details').exec
end

#select_export_fileObject

[View source]

27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/class/PARALLEL/Parallel_export.rb', line 27

def select_export_file
  @filepath = Qt::FileDialog.getSaveFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
  unless @filepath.nil?
    $file = File.open("#{@filepath}", 'w')
    @parallel_export_gui.btn_export.setEnabled(true)
    @parallel_export_gui.btn_full_export.setEnabled(true)
  end
rescue Exception => msg
  logger = Logger.new($logFilePath)
  logger.error msg
  Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
end