Class: Parallel_import

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

Instance Method Summary collapse

Constructor Details

#initialize(chip) ⇒ Parallel_import

Returns a new instance of Parallel_import.



14
15
16
17
18
19
20
21
# File 'lib/class/PARALLEL/Parallel_import.rb', line 14

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

Instance Method Details

#close_fileObject



33
34
35
36
37
38
39
# File 'lib/class/PARALLEL/Parallel_import.rb', line 33

def close_file
  unless $file.nil?
    $file.close
  end
rescue Exception => msg
  ErrorMsg.new.unknow(msg)
end

#control_import_settingsObject



61
62
63
64
65
66
67
68
69
70
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/class/PARALLEL/Parallel_import.rb', line 61

def control_import_settings
  file_size = File.size("#{@filepath}")
  if @chip.parallel_setting.nil?
    Qt::MessageBox.new(
      Qt::MessageBox::Warning,
      'Missing parallel settings',
      'No settings saved for this chip'
    ).exec
    return 0
  end
  if @chip.parallel_setting.total_size.nil? || @chip.parallel_setting.word_size.nil?
    Qt::MessageBox.new(
      Qt::MessageBox::Warning,
      'Missing parallel settings',
      'Total size or word size settings missing'
    ).exec
    return 0
  end
  if @chip.parallel_setting.page_size.nil? || @chip.parallel_setting.write_latency.nil?
    Qt::MessageBox.new(
      Qt::MessageBox::Warning,
      'Missing parallel settings',
      'Page size or write latency settings missing'
    ).exec
    return 0
  end
  if @view.lie_start.text.empty?
    Qt::MessageBox.new(
      Qt::MessageBox::Warning,
      'Missing start address',
      'Please fill the start address field'
    ).exec
    return 0
  end
  if file_size > @chip.parallel_setting.total_size
    Qt::MessageBox.new(
      Qt::MessageBox::Warning,
      'Incorrect file size',
      'The file size is superior to the chip capacity'
    ).exec
    return 0
  end
  if file_size > (@chip.parallel_setting.total_size - @view.lie_start)
    Qt::MessageBox.new(
      Qt::MessageBox::Warning,
      'Incorrect file size',
      'Starting at this address, the file size is superior to the chip capacity'
    ).exec
    return 0
  end
  return 1
end

#importObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/class/PARALLEL/Parallel_import.rb', line 41

def import
  return 0 if control_import_settings.zero?
  start = @view.lie_start.text.to_i
  Firmware.new('PARALLEL')
  time = Time.new
  # API COMMAND GOES HERE
rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
  ErrorMsg.new.hardsploit_not_found
  return false
rescue HardsploitAPI::ERROR::USB_ERROR
  ErrorMsg.new.usb_error
  return false
rescue HardsploitAPI::ERROR::PARALLEL_ERROR
  ErrorMsg.new.swd_error
  return false
rescue Exception => msg
  ErrorMsg.new.unknown(msg)
  return false
end

#select_import_fileObject



23
24
25
26
27
28
29
30
31
# File 'lib/class/PARALLEL/Parallel_import.rb', line 23

def select_import_file
  @filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
  unless @filepath.nil?
    $file = File.open("#{@filepath}", 'w')
    @view.btn_import.setEnabled(true)
  end
rescue Exception => msg
  ErrorMsg.new.unknow(msg)
end