diff --git a/main.cpp b/main.cpp index 9b54bb94..8095942d 100644 --- a/main.cpp +++ b/main.cpp @@ -391,8 +391,11 @@ int main() { } } + PEFile sf("build/section.pe"); + size_t ssize = sf.sects.back().VOffset + sf.sects.back().VSize - sf.sects[0].VOffset; + pld << " " << newsect << " 0x" << hex << nf.imgbase + newVOffset << ": {\n\ - build/section.pe\n *(.data)\n *(.bss)\n *(.rdata)\n }\n"; + . = . + "+ to_string(ssize) +";\n *(.data)\n *(.bss)\n *(.rdata)\n }\n"; pld << " /DISCARD/ : {\n *(.text)\n *(.text.startup)\n\ *(.rdata$zzz)\n *(.eh_frame)\n *(.ctors)\n *(.reloc)\n }\n}"; pld.close(); @@ -423,6 +426,7 @@ int main() { PESect* nsect = &nf.sects.back(); nsect->VOffset = newVOffset; nsect->FOffset = newFOffset; + nsect->Flags = 0xE0000060; if (sectsize > 0) { if (sectsize < sect->FSize) { ErrLog(" -> Section size too small. Required: 0x" << hex << sect->FSize); @@ -437,6 +441,14 @@ int main() { nf.seekp(nsect->FOffset); nf.write(buf, sect->FSize); free(buf); + for (auto &s : sf.sects) { + char* buf = (char*)malloc(s.FSize); + sf.seekp(s.FOffset); + sf.read(buf, s.FSize); + nf.seekp(nsect->FOffset + s.VOffset - sf.sects[0].VOffset); + nf.write(buf, s.FSize); + free(buf); + } nf.Save(); pf.close(); @@ -462,4 +474,4 @@ int main() { cout << "Done"; return 0; -} +} \ No newline at end of file