@@ -43,7 +43,8 @@ Builder::Builder(Binary* binary) :
43
43
build_relocations_{false },
44
44
build_tls_{false },
45
45
build_resources_{false },
46
- build_overlay_{true }
46
+ build_overlay_{true },
47
+ build_dos_stub_{true }
47
48
{}
48
49
49
50
@@ -76,6 +77,11 @@ Builder& Builder::build_overlay(bool flag) {
76
77
return *this ;
77
78
}
78
79
80
+ Builder& Builder::build_dos_stub (bool flag) {
81
+ this ->build_dos_stub_ = flag;
82
+ return *this ;
83
+ }
84
+
79
85
80
86
void Builder::write (const std::string& filename) const {
81
87
std::ofstream output_file{filename, std::ios::out | std::ios::binary | std::ios::trunc };
@@ -459,6 +465,14 @@ Builder& Builder::operator<<(const DosHeader& dos_header) {
459
465
460
466
this ->ios_ .seekp (0 );
461
467
this ->ios_ .write (reinterpret_cast <const uint8_t *>(&dosHeader), sizeof (pe_dos_header));
468
+ if (this ->binary_ ->dos_stub ().size () > 0 and this ->build_dos_stub_ ) {
469
+
470
+ if (sizeof (pe_dos_header) + this ->binary_ ->dos_stub ().size () > dos_header.addressof_new_exeheader ()) {
471
+ LOG (WARNING) << " Inconsistent 'addressof_new_exeheader' (0x" << std::hex << dos_header.addressof_new_exeheader ();
472
+ }
473
+ this ->ios_ .write (this ->binary_ ->dos_stub ());
474
+ }
475
+
462
476
return *this ;
463
477
}
464
478
@@ -542,12 +556,13 @@ Builder& Builder::operator<<(const Section& section) {
542
556
std::ostream& operator <<(std::ostream& os, const Builder& b) {
543
557
os << std::left;
544
558
os << std::boolalpha;
545
- os << std::setw (20 ) << " Builde imports:" << b.build_imports_ << std::endl;
546
- os << std::setw (20 ) << " Patch imports:" << b.patch_imports_ << std::endl;
547
- os << std::setw (20 ) << " Builde relocations:" << b.build_relocations_ << std::endl;
548
- os << std::setw (20 ) << " Builde TLS:" << b.build_tls_ << std::endl;
549
- os << std::setw (20 ) << " Builder resources:" << b.build_resources_ << std::endl;
550
- os << std::setw (20 ) << " Builder overlay:" << b.build_overlay_ << std::endl;
559
+ os << std::setw (20 ) << " Build imports:" << b.build_imports_ << std::endl;
560
+ os << std::setw (20 ) << " Patch imports:" << b.patch_imports_ << std::endl;
561
+ os << std::setw (20 ) << " Build relocations:" << b.build_relocations_ << std::endl;
562
+ os << std::setw (20 ) << " Build TLS:" << b.build_tls_ << std::endl;
563
+ os << std::setw (20 ) << " Build resources:" << b.build_resources_ << std::endl;
564
+ os << std::setw (20 ) << " Build overlay:" << b.build_overlay_ << std::endl;
565
+ os << std::setw (20 ) << " Build dos stub:" << b.build_dos_stub_ << std::endl;
551
566
return os;
552
567
}
553
568
0 commit comments