├── .gitignore
├── img
├── GUI.png
├── iFR.icns
└── iFR.png
├── .gitattributes
├── README.md
├── LICENSE
└── iFR.py
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | dist
3 | build
4 |
--------------------------------------------------------------------------------
/img/GUI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jazzzny/iFR/HEAD/img/GUI.png
--------------------------------------------------------------------------------
/img/iFR.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jazzzny/iFR/HEAD/img/iFR.icns
--------------------------------------------------------------------------------
/img/iFR.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jazzzny/iFR/HEAD/img/iFR.png
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
iFR
4 |
A simple yet powerful Flashrom GUI
5 |

6 |
7 |
8 | ## Features
9 | - Native Flashrom GUI
10 | - Read and write ROM images
11 | - Pad/unpad ROM images
12 | - View ROM chip information
13 | - Cross-platform
14 | - Support for macOS, Linux, and Windows
15 | - Object-oriented Python 3 design with intuitive WxPython interface
16 | - Open source
17 | - GNU GPL v2.0
18 |
19 | ## Planned Features
20 | - [ ] ROM Image verification/checksum
21 | - [ ] Standalone padding/unpadding
22 | - [ ] ROM chip erasing
23 | - [ ] Embedded Flashrom binary
24 |
25 | ## Requirements
26 | ### Standalone Binary (macOS, Windows)
27 | - `Flashrom` installed and in PATH
28 | - OS X 10.10 or newer, Windows 7 or newer
29 | ### Running from Source
30 | - Python 3.6+
31 | - WxPython 4.1.0+
32 | - `Flashrom` installed and in PATH
33 |
34 | ## Installation
35 | - Download the latest release from the [releases page](https://github.com/Jazzzny/iFR/releases)
36 | - Install `Flashrom` and add it to your PATH
37 | - Run the binary
38 |
39 | ## License
40 | iFR is licensed under the GNU GPL v2.0. See [LICENSE](LICENSE) for more information.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/iFR.py:
--------------------------------------------------------------------------------
1 | """
2 | iFR - A simple yet powerful Flashrom GUI
3 | By Jazzzny. Copyright (c) 2023
4 | Licensed under the GNU GPL v2 license.
5 | """
6 |
7 | import logging
8 | import subprocess
9 | import itertools
10 | import os
11 | import tempfile
12 | import shutil
13 | import wx
14 | import threading
15 |
16 | class Constants():
17 | def __init__(self):
18 | self.version = "1.0.0-devel"
19 | self.flashrom_path = self._find_flashrom()
20 | self.flashrom_version = self._get_flashrom_version(self.flashrom_path)
21 | self.programmer = ""
22 | self.tempdir = self.CreateTemporaryDirectory()
23 |
24 | def _find_flashrom(self):
25 | """
26 | Find the flashrom binary
27 | """
28 | if os.path.isfile("/usr/bin/flashrom"):
29 | return "/usr/bin/flashrom"
30 | elif os.path.isfile("/usr/local/bin/flashrom"):
31 | return "/usr/local/bin/flashrom"
32 | elif os.path.isfile("/opt/homebrew/bin/flashrom"):
33 | return "/opt/homebrew/bin/flashrom"
34 | elif os.path.isfile("/opt/local/bin/flashrom"):
35 | return "/opt/local/bin/flashrom"
36 | else:
37 | return "flashrom"
38 |
39 | def _get_flashrom_version(self, flashrom_path):
40 | ver = subprocess.Popen([flashrom_path, "--version"],
41 | stdout=subprocess.PIPE,
42 | stderr=subprocess.STDOUT,
43 | universal_newlines=True)
44 |
45 | for stdout_line in iter(ver.stdout.readline, ""):
46 | if "flashrom" in stdout_line:
47 | return stdout_line.split(" ")[1].strip()
48 |
49 | def CreateTemporaryDirectory(self):
50 | return tempfile.mkdtemp()
51 |
52 |
53 |
54 | class Support():
55 | """
56 | Support class for iFR - Provides functions for padding and removing padding from ROM dumps
57 | """
58 |
59 | def RemovePadding(file_path):
60 | with open(file_path, 'rb') as file:
61 | padding_size = 0
62 | while True:
63 | # Read a byte from the end of the file
64 | file.seek(-1 - padding_size, 2) # Seek from the end
65 | byte = file.read(1)
66 |
67 | if byte == b'': # Reached the beginning of the file
68 | break
69 |
70 | if byte == b'\xFF':
71 | padding_size += 1
72 | else:
73 | # Stop when non-padding content is encountered
74 | break
75 |
76 | os.truncate(file_path, os.path.getsize(file_path) - padding_size)
77 | return padding_size
78 |
79 | def AddPadding(file_path, result_size):
80 | with open(file_path, 'ab') as file:
81 | file.seek(0, 2) # Seek to the end of the file
82 | current_size = file.tell()
83 | padding_size = result_size - current_size
84 | file.write(b'\xFF' * padding_size)
85 | return padding_size
86 |
87 | class PageRead(wx.Panel):
88 | """
89 | Generates the Read ROM page
90 | """
91 |
92 | def __init__(self, parent, constants):
93 | self.constants = constants
94 | wx.Panel.__init__(self, parent)
95 |
96 | self.filepicker_title = wx.StaticText(self, label="Save ROM to:")
97 | self.filepicker = wx.FilePickerCtrl(self,
98 | message="",
99 | wildcard="*.bin",
100 | style=wx.FLP_SAVE|wx.FLP_USE_TEXTCTRL)
101 |
102 | self.chip_dropdown_title = wx.StaticText(self, label="Select Chip:")
103 | self.chip_dropdown = wx.Choice(self)
104 | self.chip_autodetect = wx.Button(self, label="Auto Detect", size=(100, -1))
105 | self.chip_autodetect.Bind(wx.EVT_BUTTON, self.OnAutoDetect)
106 | self.chip_dropdown.Disable()
107 | self.show_upon_completion = wx.CheckBox(self, label="Reveal upon completion")
108 | self.remove_padding = wx.CheckBox(self, label="Remove padding from ROM dump")
109 |
110 | self.save_button = wx.Button(self, label="Read ROM", size=(150, -1))
111 | self.save_button.Bind(wx.EVT_BUTTON, self.OnSave)
112 |
113 | sizer = wx.BoxSizer(wx.VERTICAL)
114 | chip_sizer = wx.BoxSizer(wx.HORIZONTAL)
115 | chip_sizer.Add(self.chip_dropdown, 1, wx.EXPAND)
116 | chip_sizer.Add(self.chip_autodetect, 0, wx.LEFT, 5)
117 |
118 | sizer.Add(self.filepicker_title, 0, wx.ALIGN_CENTER | wx.TOP|wx.BOTTOM, 10)
119 | sizer.Add(self.filepicker, 0, wx.EXPAND | wx.LEFT|wx.RIGHT, 20)
120 | sizer.Add(self.chip_dropdown_title, 0, wx.ALIGN_CENTER | wx.TOP|wx.BOTTOM, 10)
121 | sizer.Add(chip_sizer, 0, wx.EXPAND | wx.LEFT|wx.RIGHT, 20)
122 | sizer.Add(self.show_upon_completion, 0, wx.ALIGN_CENTER | wx.TOP, 20)
123 | sizer.Add(self.remove_padding, 0, wx.ALIGN_CENTER | wx.TOP, 20)
124 | sizer.Add(self.save_button, 0, wx.ALIGN_CENTER | wx.TOP, 24)
125 | self.SetSizer(sizer)
126 |
127 | def OnSave(self, event):
128 | filepath = self.filepicker.GetPath()
129 | if filepath == "":
130 | logging.info("Please select a file to save to.")
131 | return
132 | if len(self.chip_dropdown.GetItems()) == 0:
133 | logging.info("Please run Auto Detect to determine your chip type.")
134 | return
135 |
136 | result = subprocess.Popen([self.constants.flashrom_path,
137 | "--programmer", self.constants.programmer,
138 | "-r", filepath,
139 | "--chip", self.chip_dropdown.GetStringSelection()],
140 | stdout=subprocess.PIPE,
141 | stderr=subprocess.STDOUT,
142 | universal_newlines=True)
143 |
144 | for stdout_line in iter(result.stdout.readline, ""):
145 | logging.info(stdout_line.strip())
146 | if self.show_upon_completion.GetValue() and os.path.isfile(filepath):
147 | subprocess.Popen(["open", "-R", filepath])
148 |
149 | if self.remove_padding.GetValue() and os.path.isfile(filepath):
150 | logging.info("Removing padding from ROM dump...")
151 | result = Support.RemovePadding(filepath)
152 | logging.info(f"Removed {result} bytes of padding from ROM dump.")
153 |
154 | if not os.path.isfile(filepath):
155 | logging.info("ERROR: ROM dump was not saved. Please check the output above for more information.")
156 |
157 | def OnAutoDetect(self, event):
158 | if self.constants.programmer == "":
159 | logging.info("Please select a programmer.")
160 | return
161 | chips_raw = subprocess.Popen([self.constants.flashrom_path,
162 | "--programmer", self.constants.programmer,
163 | "--flash-name"],
164 | stdout=subprocess.PIPE,
165 | stderr=subprocess.STDOUT,
166 | universal_newlines=True)
167 |
168 | for stdout_line in iter(chips_raw.stdout.readline, ""):
169 | if "Found" in stdout_line:
170 | # Cannot use f-string unless we use Python 3.12
171 | logging.info("Found ROM chip: " + stdout_line.strip().split('"')[1])
172 | self.chip_dropdown.Append(stdout_line.strip().split('"')[1])
173 |
174 | if len(self.chip_dropdown.GetItems()) > 1:
175 | logging.info("WARNING: More than 1 possible chip detected. Please select the correct chip from the dropdown.")
176 | dlg = wx.MessageDialog(self,
177 | "More than 1 possible chip detected. Please select the correct chip from the dropdown.",
178 | "Warning",
179 | wx.OK | wx.ICON_WARNING)
180 | dlg.ShowModal()
181 | self.chip_dropdown.Enable()
182 | elif len(self.chip_dropdown.GetItems()) == 0:
183 | logging.info("No ROM chip detected. Please check your programmer connection.")
184 |
185 | class PageWrite(wx.Panel):
186 | """
187 | Generates the Write ROM page
188 | """
189 |
190 | def __init__(self, parent, constants):
191 | self.constants = constants
192 | wx.Panel.__init__(self, parent)
193 |
194 | self.filepicker_title = wx.StaticText(self, label="File to Flash:")
195 | self.filepicker = wx.FilePickerCtrl(self,
196 | message="",
197 | wildcard="ROM and BIN files (*.rom;*.bin)|*.rom;*.bin",
198 | style=wx.FLP_USE_TEXTCTRL)
199 |
200 | self.chip_dropdown_title = wx.StaticText(self, label="Select Chip:")
201 | self.chip_dropdown = wx.Choice(self)
202 | self.chip_autodetect = wx.Button(self, label="Auto Detect", size=(100, -1))
203 | self.chip_autodetect.Bind(wx.EVT_BUTTON, self.OnAutoDetect)
204 | self.chip_dropdown.Disable()
205 | self.pad_file = wx.CheckBox(self, label="Pad file to match chip size")
206 |
207 | self.save_button = wx.Button(self, label="Write ROM", size=(150, -1))
208 | self.save_button.Bind(wx.EVT_BUTTON, self.OnWrite)
209 |
210 | sizer = wx.BoxSizer(wx.VERTICAL)
211 | chip_sizer = wx.BoxSizer(wx.HORIZONTAL)
212 | chip_sizer.Add(self.chip_dropdown, 1, wx.EXPAND)
213 | chip_sizer.Add(self.chip_autodetect, 0, wx.LEFT, 5)
214 |
215 | sizer.Add(self.filepicker_title, 0, wx.ALIGN_CENTER | wx.TOP|wx.BOTTOM, 10)
216 | sizer.Add(self.filepicker, 0, wx.EXPAND | wx.LEFT|wx.RIGHT, 20)
217 | sizer.Add(self.chip_dropdown_title, 0, wx.ALIGN_CENTER | wx.TOP|wx.BOTTOM, 10)
218 | sizer.Add(chip_sizer, 0, wx.EXPAND | wx.LEFT|wx.RIGHT, 20)
219 | sizer.Add(self.pad_file, 0, wx.ALIGN_CENTER | wx.TOP|wx.BOTTOM, 20)
220 | sizer.Add(self.save_button, 0, wx.ALIGN_CENTER | wx.TOP, 40)
221 | self.SetSizer(sizer)
222 |
223 | def OnWrite(self, event):
224 | filepath = self.filepicker.GetPath()
225 | if filepath == "":
226 | logging.info("Please select a file to flash.")
227 | return
228 | if len(self.chip_dropdown.GetItems()) == 0:
229 | logging.info("Please run Auto Detect to determine your chip type.")
230 | return
231 |
232 | warndlg = wx.MessageDialog(self,
233 | "Are you sure you want to flash this ROM? This action cannot be undone. It is strongly recommmended to back up the ROM first!",
234 | "Warning",
235 | wx.YES_NO | wx.ICON_WARNING)
236 | if warndlg.ShowModal() == wx.ID_NO:
237 | return
238 |
239 | if self.pad_file.GetValue():
240 | logging.info("Padding temporary file to match chip size...")
241 | chipsize = subprocess.Popen([self.constants.flashrom_path,
242 | "--programmer", self.constants.programmer,
243 | "--chip", self.chip_dropdown.GetStringSelection(),
244 | "--flash-size"],
245 | stdout=subprocess.PIPE,
246 | stderr=subprocess.STDOUT
247 | ).stdout.readlines()[-1].decode('utf-8').strip()
248 |
249 | filecopy = shutil.copy(filepath, self.constants.tempdir)
250 | padresult = Support.AddPadding(filecopy, int(chipsize))
251 | filepath = filecopy
252 | logging.info(f"Padded temporary file by {padresult} bytes.")
253 |
254 | result = subprocess.Popen([self.constants.flashrom_path,
255 | "--programmer", self.constants.programmer,
256 | "-w", filepath,
257 | "--chip", self.chip_dropdown.GetStringSelection()],
258 | stdout=subprocess.PIPE,
259 | stderr=subprocess.STDOUT,
260 | universal_newlines=True)
261 |
262 | for stdout_line in iter(result.stdout.readline, ""):
263 | logging.info(stdout_line.strip())
264 |
265 | def OnAutoDetect(self, event):
266 | if self.constants.programmer == "":
267 | logging.info("Please select a programmer.")
268 | return
269 |
270 | chips_raw = subprocess.Popen([self.constants.flashrom_path,
271 | "--programmer", self.constants.programmer,
272 | "--flash-name"],
273 | stdout=subprocess.PIPE,
274 | stderr=subprocess.STDOUT,
275 | universal_newlines=True)
276 |
277 | for stdout_line in iter(chips_raw.stdout.readline, ""):
278 | if "Found" in stdout_line:
279 | # Cannot use f-string unless we use Python 3.12
280 | logging.info("Found ROM chip: " + stdout_line.strip().split('"')[1])
281 | self.chip_dropdown.Append(stdout_line.strip().split('"')[1])
282 |
283 | if len(self.chip_dropdown.GetItems()) > 1:
284 | logging.info(
285 | "WARNING: More than 1 possible chip detected. Please select the correct chip from the dropdown."
286 | )
287 | dlg = wx.MessageDialog(self,
288 | "More than 1 possible chip detected. Please select the correct chip from the dropdown.",
289 | "Warning",
290 | wx.OK | wx.ICON_WARNING)
291 | dlg.ShowModal()
292 | self.chip_dropdown.Enable()
293 | elif len(self.chip_dropdown.GetItems()) == 0:
294 | logging.info("No ROM chip detected. Please check your programmer connection.")
295 |
296 | class PageInfo(wx.Panel):
297 | """
298 | Generates the ROM Info page
299 | """
300 |
301 | def __init__(self, parent, constants):
302 | self.constants = constants
303 | wx.Panel.__init__(self, parent)
304 |
305 | self.chip_dropdown_title = wx.StaticText(self, label="Select Chip:")
306 | self.chip_dropdown = wx.Choice(self)
307 | self.chip_autodetect = wx.Button(self, label="Auto Detect", size=(100, -1))
308 | self.chip_autodetect.Bind(wx.EVT_BUTTON, self.OnAutoDetect)
309 | self.chip_dropdown.Disable()
310 | self.read_chip = wx.Button(self, label="Read Chip Information", size=(150, -1))
311 | self.read_chip.Bind(wx.EVT_BUTTON, self.GetChipInfo)
312 |
313 | self.list = wx.ListCtrl(self,style=wx.LC_REPORT|wx.LC_NO_HEADER)
314 |
315 | # Add some columns
316 | self.list.InsertColumn(0, "Name")
317 | self.list.InsertColumn(1, "Value")
318 |
319 | data = [
320 | ("Model", ""),
321 | ("Vendor", ""),
322 | ("Size", ""),
323 | ("Space Used", ""),
324 | ("Write Protection", "")
325 | ]
326 |
327 | # Add the rows
328 | for item in data:
329 | index = self.list.InsertItem(self.list.GetItemCount(), item[0])
330 | for col, text in enumerate(item[1:]):
331 | self.list.SetItem(index, col+1, text)
332 |
333 | # Set the width of the columns
334 | self.list.SetColumnWidth(0, 140)
335 | self.list.SetColumnWidth(1, 270)
336 |
337 | sizer = wx.BoxSizer(wx.VERTICAL)
338 | chip_sizer = wx.BoxSizer(wx.HORIZONTAL)
339 | chip_sizer.Add(self.chip_dropdown, 1, wx.EXPAND)
340 | chip_sizer.Add(self.chip_autodetect, 0, wx.LEFT, 5)
341 | sizer.Add(self.chip_dropdown_title, 0, wx.ALIGN_CENTER | wx.TOP|wx.BOTTOM, 5)
342 | sizer.Add(chip_sizer, 0, wx.EXPAND | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)
343 | sizer.Add(self.read_chip, 0, wx.ALIGN_CENTER | wx.BOTTOM, 10)
344 | sizer.Add(self.list, 1, wx.EXPAND | wx.LEFT|wx.RIGHT, 0)
345 | self.SetSizer(sizer)
346 |
347 | def OnAutoDetect(self, event):
348 | if self.constants.programmer == "":
349 | logging.info("Please select a programmer.")
350 | return
351 | chips_raw = subprocess.Popen([self.constants.flashrom_path,
352 | "--programmer", self.constants.programmer,
353 | "--flash-name"],
354 | stdout=subprocess.PIPE,
355 | stderr=subprocess.STDOUT,
356 | universal_newlines=True)
357 |
358 | for stdout_line in iter(chips_raw.stdout.readline, ""):
359 | if "Found" in stdout_line:
360 | # Cannot use f-string unless we use Python 3.12
361 | logging.info("Found ROM chip: " + stdout_line.strip().split('"')[1])
362 | self.chip_dropdown.Append(stdout_line.strip().split('"')[1])
363 | if len(self.chip_dropdown.GetItems()) > 1:
364 | logging.info(
365 | "WARNING: More than 1 possible chip detected. Please select the correct chip from the dropdown."
366 | )
367 | dlg = wx.MessageDialog(self,
368 | "More than 1 possible chip detected. Please select the correct chip from the dropdown.",
369 | "Warning",
370 | wx.OK | wx.ICON_WARNING)
371 | dlg.ShowModal()
372 | self.chip_dropdown.Enable()
373 | elif len(self.chip_dropdown.GetItems()) == 0:
374 | logging.info("No ROM chip detected. Please check your programmer connection.")
375 |
376 | def GetChipInfo(self, event):
377 | if len(self.chip_dropdown.GetItems()) == 0:
378 | logging.info("Please run Auto Detect to determine your chip type.")
379 | return
380 | result = subprocess.Popen([self.constants.flashrom_path,
381 | "--programmer", self.constants.programmer,
382 | "--chip", self.chip_dropdown.GetStringSelection(),
383 | "--flash-name"],
384 | stdout=subprocess.PIPE,
385 | stderr=subprocess.STDOUT)
386 | result.wait()
387 | result = result.stdout.readlines()[-1].decode('utf-8').strip()
388 |
389 | vendor = result.split('"')[1]
390 |
391 | model = result.split('"')[3]
392 | size = subprocess.Popen([self.constants.flashrom_path,
393 | "--programmer", self.constants.programmer,
394 | "--chip", self.chip_dropdown.GetStringSelection(),
395 | "--flash-size"],
396 | stdout=subprocess.PIPE,
397 | stderr=subprocess.STDOUT)
398 | size.wait()
399 | size = int(size.stdout.readlines()[-1].decode('utf-8').strip())
400 | subprocess.Popen([self.constants.flashrom_path,
401 | "--programmer", self.constants.programmer,
402 | "-r", f"{self.constants.tempdir}/temp.bin",
403 | "--chip", self.chip_dropdown.GetStringSelection()],
404 | stdout=subprocess.PIPE,
405 | stderr=subprocess.STDOUT).wait()
406 |
407 | if os.path.isfile(f"{self.constants.tempdir}/temp.bin"):
408 | space_used = size - Support.RemovePadding(f"{self.constants.tempdir}/temp.bin")
409 | space_used = 0
410 | write_protection = subprocess.Popen([self.constants.flashrom_path,
411 | "--programmer", self.constants.programmer,
412 | "--chip", self.chip_dropdown.GetStringSelection(),
413 | "--wp-status"],
414 | stdout=subprocess.PIPE,
415 | stderr=subprocess.STDOUT
416 | ).stdout.readlines()[-1].decode('utf-8').strip()
417 |
418 | self.list.SetItem(0, 1, model)
419 | self.list.SetItem(1, 1, vendor)
420 | self.list.SetItem(2, 1, str(round(size/1024,1)) + " kB")
421 | if space_used:
422 | self.list.SetItem(3, 1, str(round(space_used/1024,1)) + " kB")
423 | else:
424 | self.list.SetItem(3, 1, "N/A")
425 | self.list.SetItem(4, 1, write_protection)
426 |
427 | class wxLogHandler(logging.Handler):
428 | """
429 | Provides a logging handler for wxPython
430 | """
431 |
432 | def __init__(self, handler: wx.TextCtrl):
433 | logging.Handler.__init__(self)
434 | self.handler = handler
435 | def emit(self, record):
436 | wx.CallAfter(self.handler.AppendText, self.format(record) + '\n')
437 |
438 | class iFR(wx.Frame):
439 | """
440 | Main iFR window
441 | """
442 |
443 | def __init__(self, parent, title):
444 | wx.SystemOptions.SetOption("osx.openfiledialog.always-show-types","1")
445 | super(iFR, self).__init__(parent, title=title, size=(450, 500))
446 | self.InitUI()
447 |
448 | def InitUI(self):
449 | self.constants = Constants()
450 |
451 | menubar = wx.MenuBar()
452 | fileMenu = wx.Menu()
453 |
454 | aboutItem = fileMenu.Append(wx.ID_ABOUT, "&About iFR")
455 | settingsItem = fileMenu.Append(wx.ID_PREFERENCES)
456 |
457 | menubar.Append(fileMenu, "&Help")
458 |
459 | self.SetMenuBar(menubar)
460 | #self.Bind(wx.EVT_MENU, self.on_about, id=wx.ID_ABOUT)
461 | #self.Bind(wx.EVT_MENU, self.on_settings, id=wx.ID_PREFERENCES)
462 |
463 | panel = wx.Panel(self)
464 | self.toolbar = self.CreateToolBar(wx.TB_TEXT)
465 |
466 | self.toolbar.EnableTool(14, False)
467 |
468 | self.programmer_combo = wx.ComboBox(self.toolbar, choices=[], size=(125,30))
469 | self.programmer_combo.Bind(wx.EVT_COMBOBOX, self.OnProgrammerSelect)
470 | self.toolbar.AddControl(self.programmer_combo, "Select Programmer")
471 | self.toolbar.Realize()
472 | sizer = wx.BoxSizer(wx.VERTICAL)
473 | self.notebook = wx.Notebook(panel)
474 | self.notebook.AddPage(PageRead(self.notebook, self.constants), "Read ROM")
475 | self.notebook.AddPage(PageWrite(self.notebook, self.constants), "Write ROM")
476 | self.notebook.AddPage(PageInfo(self.notebook, self.constants), "ROM Info")
477 | self.consoletitle = wx.StaticText(panel, label="Output")
478 | self.textctrl = wx.TextCtrl(panel, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2)
479 | self.textctrl.SetFont(wx.Font(12, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
480 |
481 | sizer = wx.BoxSizer(wx.VERTICAL)
482 | sizer.Add(self.notebook, 2, wx.EXPAND | wx.ALL, 10)
483 | rectbox = wx.StaticBox(panel, -1)
484 | rectsizer = wx.StaticBoxSizer(rectbox, wx.VERTICAL)
485 | rectsizer.Add(self.consoletitle, 0, wx.ALIGN_CENTRE | wx.BOTTOM, 5)
486 | rectsizer.Add(self.textctrl, 1, wx.EXPAND | wx.ALL, 0)
487 | sizer.Add(rectsizer, 1, wx.EXPAND | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)
488 | panel.SetSizer(sizer)
489 | self.Centre()
490 | self.SetSize((450, 500))
491 | self.SetMinSize((450, 500))
492 | self.Show()
493 |
494 | logObj = logging.getLogger()
495 | logObj.addHandler(wxLogHandler(self.textctrl))
496 | logObj.setLevel(logging.INFO)
497 | logging.info(f"Welcome to iFR {self.constants.version}\nA simple yet powerful Flashrom GUI\n\nFlashrom version: {self.constants.flashrom_version}\n")
498 | self.PopulateAvailableProgrammers()
499 |
500 | def PopulateAvailableProgrammers(self):
501 | output = subprocess.Popen([self.constants.flashrom_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
502 | output_lines = output.stdout.readlines()
503 | try:
504 | options_start = output_lines.index(b'Valid choices are:\n')
505 | except:
506 | options_start = output_lines.index(b"To choose the mainboard of this computer use 'internal'. Valid choices are:\n")
507 | options = [line.decode('utf-8').strip() for line in output_lines[options_start+1:]]
508 | programmers = list(
509 | itertools.chain.from_iterable(
510 | [line.replace(".", "").replace(",", "").split() for line in options]
511 | )
512 | )
513 |
514 | for programmer in programmers:
515 | self.programmer_combo.Append(programmer)
516 |
517 | def OnProgrammerSelect(self, event):
518 | self.constants.programmer = self.programmer_combo.GetValue()
519 | logging.info(f"Programmer set to {self.constants.programmer}")
520 |
521 |
522 | if __name__ == '__main__':
523 | app = wx.App()
524 | iFR(None, title='iFR')
525 | app.MainLoop()
526 |
--------------------------------------------------------------------------------