Skip to content

Fix replace - #77

Merged
cwerling merged 12 commits into
PSPReverse:masterfrom
bird-dancer:fix-replace
Oct 9, 2026
Merged

cwerling merged 12 commits into
PSPReverse:masterfrom
bird-dancer:fix-replace

Conversation

@bird-dancer

@bird-dancer bird-dancer commented Jan 22, 2026 •

Copy link
Copy Markdown
Collaborator
  • When extracting a file, replacing it without change, and extracting it again the file changes significantly.
    This is due to length and offset/ address field being changed incorrectly.
    When substituting a file only the actual file content length was set as the new size. The signature length, which should included in the size is now added.
  • The existing entry.file_offset() logic is no longer (incorrectly 😅) duplicated.
  • Some qol improvements like using enums for address_type and signature_type and removing a redundant function argument.
  • Also added test (written by ai) checking if extracting and reinserting a new file results in the same file as the original image

The size also doesn't (always??) have to be 0x10 aligned as evidenced by the TPMLITE file for this example.

Now the repacked rom is the same as the original.

@github-actions

Copy link
Copy Markdown

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 14,913
Stderr Lines 144
Total Lines 15,057
Error Ratio 0.96%

PSPTool python library metrics

Status Count Percentage
✓ Successful 68 100.0%
✗ Failed 0 0.0%
Total 68 100%

All files parsed successfully!

Comment thread psptool/directory.py Outdated
Comment thread psptool/__main__.py
@bird-dancer
bird-dancer marked this pull request as draft January 26, 2026 23:45
@github-actions

Copy link
Copy Markdown

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 4,596
Stderr Lines 834
Total Lines 5,430
Error Ratio 15.36%

PSPTool python library metrics

Status Count Percentage
✓ Successful 33 48.53%
✗ Failed 35 51.47%
Total 68 100%

Failed Files

  • ASUS_ROG-STRIX-X470-F-GAMING-ASUS-4804.CAP
  • ASUS_ROG-STRIX-B450-F-GAMING-ASUS-2301.CAP
  • ASRock_B450_B45P4_3.31
  • TUF-GAMING-A520M-PLUS-WIFI-ASUS-2604.CAP
  • Lenovo_Thinkpad_T14_WinGLC3A106.ROM
  • ASRock_X470_X47GK4_3.31
  • ASUS_ROG-STRIX-B350-F-GAMING-ASUS-4801.CAP
  • ASUS_TUF-B450M-PRO-GAMING-ASUS-1201.CAP
  • ASUS_PRIME-X470-PRO-4011.CAP
  • Gigabyte_X470AG7W.F40
  • ASUS_PRIME-X370-PRO-3803.CAP
  • ASRock_X370_X370GK45.30
  • ASRock-A520M-HSV-1.31.ROM
  • MSI_X470_E7B77AMS.194
  • ASUS_PRIME-X470-PRO-ASUS-4804.CAP
  • ASUS_PRIME-B350-PLUS-4011.CAP
  • ASUS_ROG-STRIX-X370-F-GAMING-ASUS-4801.CAP
  • ASRock_A320_A32M5.00
  • ASRock_B350_AB35G4_5.70
  • Gigabyte_AX370G3.F31
  • AORUS_X370G5.23d
  • ASUS_B450M_KII_Zen1_ROM_Exploit.rom
  • AORUS_B450AE.F40
  • ASRock_A520M_HVS_1.31.ftpm_with_data.rom
  • Gigabyte_WRX80F2
  • AORUS_X570_X57AOXT2.FCd
  • MSI_X370_E7A33AMS.4I1
  • ASUS_PRIME-B450M-A-ASUS-1201.CAP
  • MSI_B450_E7B86AMS.181
  • Acer_R01-A4.ROM
  • AORUS_X470AG7W.F40
  • ASUS_PRIME-A320M-A-ASUS-4801.CAP
  • MSI_A320_E7A38AMS.2I2
  • Lenovo_Ideapad_5_Pro-16ACH6.rom
  • MSI_B350_E7A34AMS.1O1

@github-actions

Copy link
Copy Markdown

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 4,596
Stderr Lines 834
Total Lines 5,430
Error Ratio 15.36%

PSPTool python library metrics

Status Count Percentage
✓ Successful 33 48.53%
✗ Failed 35 51.47%
Total 68 100%

Failed Files

  • ASUS_ROG-STRIX-X470-F-GAMING-ASUS-4804.CAP
  • ASUS_ROG-STRIX-B450-F-GAMING-ASUS-2301.CAP
  • ASRock_B450_B45P4_3.31
  • TUF-GAMING-A520M-PLUS-WIFI-ASUS-2604.CAP
  • Lenovo_Thinkpad_T14_WinGLC3A106.ROM
  • ASRock_X470_X47GK4_3.31
  • ASUS_ROG-STRIX-B350-F-GAMING-ASUS-4801.CAP
  • ASUS_TUF-B450M-PRO-GAMING-ASUS-1201.CAP
  • ASUS_PRIME-X470-PRO-4011.CAP
  • Gigabyte_X470AG7W.F40
  • ASUS_PRIME-X370-PRO-3803.CAP
  • ASRock_X370_X370GK45.30
  • ASRock-A520M-HSV-1.31.ROM
  • MSI_X470_E7B77AMS.194
  • ASUS_PRIME-X470-PRO-ASUS-4804.CAP
  • ASUS_PRIME-B350-PLUS-4011.CAP
  • ASUS_ROG-STRIX-X370-F-GAMING-ASUS-4801.CAP
  • ASRock_A320_A32M5.00
  • ASRock_B350_AB35G4_5.70
  • Gigabyte_AX370G3.F31
  • AORUS_X370G5.23d
  • ASUS_B450M_KII_Zen1_ROM_Exploit.rom
  • AORUS_B450AE.F40
  • ASRock_A520M_HVS_1.31.ftpm_with_data.rom
  • Gigabyte_WRX80F2
  • AORUS_X570_X57AOXT2.FCd
  • MSI_X370_E7A33AMS.4I1
  • ASUS_PRIME-B450M-A-ASUS-1201.CAP
  • MSI_B450_E7B86AMS.181
  • Acer_R01-A4.ROM
  • AORUS_X470AG7W.F40
  • ASUS_PRIME-A320M-A-ASUS-4801.CAP
  • MSI_A320_E7A38AMS.2I2
  • Lenovo_Ideapad_5_Pro-16ACH6.rom
  • MSI_B350_E7A34AMS.1O1

@github-actions

Copy link
Copy Markdown

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 4,596
Stderr Lines 834
Total Lines 5,430
Error Ratio 15.36%

PSPTool python library metrics

Status Count Percentage
✓ Successful 33 48.53%
✗ Failed 35 51.47%
Total 68 100%

Failed Files

  • ASUS_ROG-STRIX-X470-F-GAMING-ASUS-4804.CAP
  • ASUS_ROG-STRIX-B450-F-GAMING-ASUS-2301.CAP
  • ASRock_B450_B45P4_3.31
  • TUF-GAMING-A520M-PLUS-WIFI-ASUS-2604.CAP
  • Lenovo_Thinkpad_T14_WinGLC3A106.ROM
  • ASRock_X470_X47GK4_3.31
  • ASUS_ROG-STRIX-B350-F-GAMING-ASUS-4801.CAP
  • ASUS_TUF-B450M-PRO-GAMING-ASUS-1201.CAP
  • ASUS_PRIME-X470-PRO-4011.CAP
  • Gigabyte_X470AG7W.F40
  • ASUS_PRIME-X370-PRO-3803.CAP
  • ASRock_X370_X370GK45.30
  • ASRock-A520M-HSV-1.31.ROM
  • MSI_X470_E7B77AMS.194
  • ASUS_PRIME-X470-PRO-ASUS-4804.CAP
  • ASUS_PRIME-B350-PLUS-4011.CAP
  • ASUS_ROG-STRIX-X370-F-GAMING-ASUS-4801.CAP
  • ASRock_A320_A32M5.00
  • ASRock_B350_AB35G4_5.70
  • Gigabyte_AX370G3.F31
  • AORUS_X370G5.23d
  • ASUS_B450M_KII_Zen1_ROM_Exploit.rom
  • AORUS_B450AE.F40
  • ASRock_A520M_HVS_1.31.ftpm_with_data.rom
  • Gigabyte_WRX80F2
  • AORUS_X570_X57AOXT2.FCd
  • MSI_X370_E7A33AMS.4I1
  • ASUS_PRIME-B450M-A-ASUS-1201.CAP
  • MSI_B450_E7B86AMS.181
  • Acer_R01-A4.ROM
  • AORUS_X470AG7W.F40
  • ASUS_PRIME-A320M-A-ASUS-4801.CAP
  • MSI_A320_E7A38AMS.2I2
  • Lenovo_Ideapad_5_Pro-16ACH6.rom
  • MSI_B350_E7A34AMS.1O1

1 similar comment
@github-actions

Copy link
Copy Markdown

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 4,596
Stderr Lines 834
Total Lines 5,430
Error Ratio 15.36%

PSPTool python library metrics

Status Count Percentage
✓ Successful 33 48.53%
✗ Failed 35 51.47%
Total 68 100%

Failed Files

  • ASUS_ROG-STRIX-X470-F-GAMING-ASUS-4804.CAP
  • ASUS_ROG-STRIX-B450-F-GAMING-ASUS-2301.CAP
  • ASRock_B450_B45P4_3.31
  • TUF-GAMING-A520M-PLUS-WIFI-ASUS-2604.CAP
  • Lenovo_Thinkpad_T14_WinGLC3A106.ROM
  • ASRock_X470_X47GK4_3.31
  • ASUS_ROG-STRIX-B350-F-GAMING-ASUS-4801.CAP
  • ASUS_TUF-B450M-PRO-GAMING-ASUS-1201.CAP
  • ASUS_PRIME-X470-PRO-4011.CAP
  • Gigabyte_X470AG7W.F40
  • ASUS_PRIME-X370-PRO-3803.CAP
  • ASRock_X370_X370GK45.30
  • ASRock-A520M-HSV-1.31.ROM
  • MSI_X470_E7B77AMS.194
  • ASUS_PRIME-X470-PRO-ASUS-4804.CAP
  • ASUS_PRIME-B350-PLUS-4011.CAP
  • ASUS_ROG-STRIX-X370-F-GAMING-ASUS-4801.CAP
  • ASRock_A320_A32M5.00
  • ASRock_B350_AB35G4_5.70
  • Gigabyte_AX370G3.F31
  • AORUS_X370G5.23d
  • ASUS_B450M_KII_Zen1_ROM_Exploit.rom
  • AORUS_B450AE.F40
  • ASRock_A520M_HVS_1.31.ftpm_with_data.rom
  • Gigabyte_WRX80F2
  • AORUS_X570_X57AOXT2.FCd
  • MSI_X370_E7A33AMS.4I1
  • ASUS_PRIME-B450M-A-ASUS-1201.CAP
  • MSI_B450_E7B86AMS.181
  • Acer_R01-A4.ROM
  • AORUS_X470AG7W.F40
  • ASUS_PRIME-A320M-A-ASUS-4801.CAP
  • MSI_A320_E7A38AMS.2I2
  • Lenovo_Ideapad_5_Pro-16ACH6.rom
  • MSI_B350_E7A34AMS.1O1

@github-actions

Copy link
Copy Markdown

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 4,596
Stderr Lines 834
Total Lines 5,430
Error Ratio 15.36%

PSPTool python library metrics

Status Count Percentage
✓ Successful 33 48.53%
✗ Failed 35 51.47%
Total 68 100%

Failed Files

  • ASUS_ROG-STRIX-X470-F-GAMING-ASUS-4804.CAP
  • ASUS_ROG-STRIX-B450-F-GAMING-ASUS-2301.CAP
  • ASRock_B450_B45P4_3.31
  • TUF-GAMING-A520M-PLUS-WIFI-ASUS-2604.CAP
  • Lenovo_Thinkpad_T14_WinGLC3A106.ROM
  • ASRock_X470_X47GK4_3.31
  • ASUS_ROG-STRIX-B350-F-GAMING-ASUS-4801.CAP
  • ASUS_TUF-B450M-PRO-GAMING-ASUS-1201.CAP
  • ASUS_PRIME-X470-PRO-4011.CAP
  • Gigabyte_X470AG7W.F40
  • ASUS_PRIME-X370-PRO-3803.CAP
  • ASRock_X370_X370GK45.30
  • ASRock-A520M-HSV-1.31.ROM
  • MSI_X470_E7B77AMS.194
  • ASUS_PRIME-X470-PRO-ASUS-4804.CAP
  • ASUS_PRIME-B350-PLUS-4011.CAP
  • ASUS_ROG-STRIX-X370-F-GAMING-ASUS-4801.CAP
  • ASRock_A320_A32M5.00
  • ASRock_B350_AB35G4_5.70
  • Gigabyte_AX370G3.F31
  • AORUS_X370G5.23d
  • ASUS_B450M_KII_Zen1_ROM_Exploit.rom
  • AORUS_B450AE.F40
  • ASRock_A520M_HVS_1.31.ftpm_with_data.rom
  • Gigabyte_WRX80F2
  • AORUS_X570_X57AOXT2.FCd
  • MSI_X370_E7A33AMS.4I1
  • ASUS_PRIME-B450M-A-ASUS-1201.CAP
  • MSI_B450_E7B86AMS.181
  • Acer_R01-A4.ROM
  • AORUS_X470AG7W.F40
  • ASUS_PRIME-A320M-A-ASUS-4801.CAP
  • MSI_A320_E7A38AMS.2I2
  • Lenovo_Ideapad_5_Pro-16ACH6.rom
  • MSI_B350_E7A34AMS.1O1

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Metrics

psptool command line interface metrics

Metric Value
Files Processed 68
Stdout Lines 14,965
Stderr Lines 164
Total Lines 15,129
Error Ratio 1.08%

PSPTool python library metrics

Status Count Percentage
✓ Successful 68 100.0%
✗ Failed 0 0.0%
Total 68 100%

All files parsed successfully!

+ use exact entry for file to be replaced instead of only matching
type in case there are multipe entries with the same type. (removing todo)
+ use entry.file_offset() instead of re-implementing it in
directory.update_entry_fields since it always is linear to
entry.offset anyways
@bird-dancer bird-dancer closed this Oct 6, 2026
@bird-dancer bird-dancer reopened this Oct 6, 2026
@bird-dancer
bird-dancer marked this pull request as ready for review October 6, 2026 20:05
@cwerling

cwerling commented Oct 9, 2026

Copy link
Copy Markdown
Member

Looks good, thanks a lot!

@cwerling
cwerling merged commit 5055403 into PSPReverse:master Oct 9, 2026
16 checks passed
@bird-dancer
bird-dancer deleted the fix-replace branch October 10, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants