@@ -885,6 +885,10 @@ ok_error_t Binary::shift(size_t value) {
885
885
}
886
886
887
887
shift_command (value, loadcommands_end);
888
+ const uint64_t loadcommands_end_va = loadcommands_end + load_cmd_segment->virtual_address ();
889
+
890
+ LIEF_DEBUG (" loadcommands_end: 0x{:016x}" , loadcommands_end);
891
+ LIEF_DEBUG (" loadcommands_end_va: 0x{:016x}" , loadcommands_end_va);
888
892
889
893
// Shift Segment and sections
890
894
// ==========================
@@ -904,19 +908,23 @@ ok_error_t Binary::shift(size_t value) {
904
908
}
905
909
}
906
910
} else {
911
+ if (segment->virtual_address () >= loadcommands_end_va) {
912
+ segment->virtual_address (segment->virtual_address () + value);
913
+ }
914
+
907
915
if (segment->file_offset () >= loadcommands_end) {
908
916
segment->file_offset (segment->file_offset () + value);
909
- segment->virtual_address (segment->virtual_address () + value);
910
917
}
911
918
912
919
for (const std::unique_ptr<Section>& section : segment->sections_ ) {
913
- if (section->offset () >= loadcommands_end) {
914
- section->offset (section->offset () + value);
920
+ if (section->virtual_address () >= loadcommands_end_va ||
921
+ section->type () == Section::TYPE::ZEROFILL)
922
+ {
915
923
section->virtual_address (section->virtual_address () + value);
916
924
}
917
925
918
- if (section->type () == Section::TYPE::ZEROFILL ) {
919
- section->virtual_address (section->virtual_address () + value);
926
+ if (section->offset () >= loadcommands_end_va ) {
927
+ section->offset (section->offset () + value);
920
928
}
921
929
}
922
930
}
0 commit comments