Class: Parallel_export

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

Instance Method Summary collapse

Constructor Details

#initialize(chip) ⇒ Parallel_export

Returns a new instance of Parallel_export.



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

def initialize(chip)
  super()
  @view = Ui_Generic_export.new
  centerWindow(self)
  @view.setupUi(self)
  @view.lbl_chip.setText(chip.reference)
  inputRestrict(@view.lie_start, 0)
  inputRestrict(@view.lie_stop, 0)
  @chip = chip
end

Instance Method Details

#control_export_result(stop, time) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/class/PARALLEL/Parallel_export.rb', line 71

def control_export_result(stop, time)
  time = Time.new - time
  file_size = File.size("#{@filepath}")
  # 8 bits test
  if @chip.parallel_setting.word_size.zero?
    if (stop - @view.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
      ErrorMsg.new.filesize_error
    end
  else
    if (stop - @view.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
      ErrorMsg.new.filesize_error
    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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/class/PARALLEL/Parallel_export.rb', line 99

def control_export_settings(type)
  return ErrorMsg.new.settings_missing  if @chip.parallel_setting.nil?
  return ErrorMsg.new.para_read_latency if @chip.parallel_setting.read_latency.nil?
  return ErrorMsg.new.para_word_size    if @chip.parallel_setting.word_size.nil?
  return ErrorMsg.new.full_size_error   if @chip.parallel_setting.total_size.nil?
  return ErrorMsg.new.full_size_error   if @chip.parallel_setting.total_size.zero?
  if type == 'partial'
    return ErrorMsg.new.start_stop_missing if @view.lie_start.text.empty?
    return ErrorMsg.new.start_stop_missing if @view.lie_stop.text.empty?
    start = @view.lie_start.text.to_i
    stop = @view.lie_stop.text.to_i
    total_size = @chip.parallel_setting.total_size
    return ErrorMsg.new.start_neq_stop    if start == stop
    return ErrorMsg.new.start_inf_to_stop if start > stop
    return ErrorMsg.new.inf_to_total_size if start > (total_size - 1)
    return ErrorMsg.new.inf_to_total_size if stop > (total_size - 1)
  end
  return true
end

#exportObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/class/PARALLEL/Parallel_export.rb', line 36

def export
  if sender.objectName == 'btn_full_export'
    return false unless control_export_settings('full')
    start = 0
    stop  = @chip.parallel_setting.total_size - 1
  else
    return false unless control_export_settings('partial')
    start = @view.lie_start.text.to_i
    stop  = @view.lie_stop.text.to_i
  end
  @chip.parallel_setting.word_size == 0 ? word_size = true : word_size = false
  Firmware.new('PARALLEL')
  parallel = HardsploitAPI_PARALLEL.new
  time = Time.new

  parallel.read_Memory_WithoutMultiplexing(
    path:                     @filepath,
    addressStart:             start,
    addressStop:              stop,
    bits8_or_bits16_DataSize: word_size,
    latency:                  @chip.parallel_setting.read_latency
  )

  control_export_result(stop, time)
  @view.btn_export.setEnabled(false)
  @view.btn_full_export.setEnabled(false)
  @filepath = nil
rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
  ErrorMsg.new.hardsploit_not_found
rescue HardsploitAPI::ERROR::USB_ERROR
  ErrorMsg.new.usb_error
rescue Exception => msg
  ErrorMsg.new.unknown(msg)
end

#select_export_fileObject



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

def select_export_file
  @filepath = Qt::FileDialog.getSaveFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
  unless @filepath.nil?
    @view.btn_export.setEnabled(true)
    @view.btn_full_export.setEnabled(true)
  end
rescue Exception => msg
  ErrorMsg.new.unknown(msg)
end