| 113 | } |
| 114 | |
| 115 | void RomSelection::parseROMSegments() { |
| 116 | FILE *fd; |
| 117 | int i, seg; |
| 118 | uint8_t buf[10]; |
| 119 | uint16_t size = 0; |
| 120 | int dumpsize; |
| 121 | |
| 122 | if (!m_alloced) { |
| 123 | m_array = new uint8_t[ROM_SIZE]; |
| 124 | memset(m_array, 255, ROM_SIZE); |
| 125 | m_alloced = true; |
| 126 | } |
| 127 | |
| 128 | for (i = 0; i < m_segs.size(); i++) { |
| 129 | ui->progressBar->setEnabled(true); |
| 130 | fd = fopen_utf8(m_segs.at(i).toStdString().c_str(), "rb"); |
| 131 | if (!fd) goto invalid; |
| 132 | if (fseek(fd, 0x3C, SEEK_SET)) goto invalid; |
| 133 | if (fread(buf, 1, 8, fd) != 8) goto invalid; |
| 134 | if (memcmp(buf, "ROMData", 7)) goto invalid; |
| 135 | |
| 136 | switch (buf[7]) { |
| 137 | case '0': |
| 138 | if (fseek(fd, 0x4A, 0)) goto invalid; |
| 139 | if (fread(buf, 1, 3, fd) != 3) goto invalid; |
| 140 | |
| 141 | dumpsize = static_cast<int>(buf[0] << 0) | |
| 142 | static_cast<int>(buf[1] << 8) | |
| 143 | static_cast<int>(buf[2] << 16); |
| 144 | |
| 145 | m_num = (dumpsize / SEG_SIZE) + 2; |
| 146 | ui->progressBar->setMaximum(m_num); |
| 147 | m_config = true; |
| 148 | break; |
| 149 | |
| 150 | case '1': |
| 151 | if (fseek(fd, 0x48, 0)) goto invalid; |
| 152 | if (fread(&size, sizeof(size), 1 ,fd) != 1) goto invalid; |
| 153 | size = qFromLittleEndian(size); |
| 154 | if (size != SEG_SIZE) goto invalid; |
| 155 | |
| 156 | if (fread(&m_array[CERT_LOC], SEG_SIZE, 1, fd) != 1) { |
| 157 | goto invalid; |
| 158 | } |
| 159 | ui->progressBar->setValue(ui->progressBar->value() + 1); |
| 160 | break; |
| 161 | |
| 162 | default: |
| 163 | if (fseek(fd, 0x48, 0)) goto invalid; |
| 164 | if (fread(&size, sizeof(size), 1 ,fd) != 1) goto invalid; |
| 165 | size = qFromLittleEndian(size); |
| 166 | if (size != SEG_SIZE) goto invalid; |
| 167 | |
| 168 | seg = buf[7] - 'A'; |
| 169 | if (m_status[seg] == false) { |
| 170 | m_status[seg] = true; |
| 171 | if (fread(&m_array[SEG_SIZE * seg], SEG_SIZE, 1, fd) != 1) { |
| 172 | goto invalid; |
nothing calls this directly
no test coverage detected