Skip to content

Commit

Permalink
Fix -shared 2
Browse files Browse the repository at this point in the history
  • Loading branch information
KionX committed Nov 5, 2023
1 parent 2937ad1 commit 3a98335
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand All @@ -462,4 +474,4 @@ int main() {

cout << "Done";
return 0;
}
}

0 comments on commit 3a98335

Please sign in to comment.