Skip to content

Commit

Permalink
Resolve #925
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Aug 19, 2023
1 parent 1f3b19e commit 1f21f7b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
9 changes: 8 additions & 1 deletion include/LIEF/iostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ class vector_iostream {

vector_iostream& put(uint8_t c);
vector_iostream& write(const uint8_t* s, std::streamsize n);
vector_iostream& write(span<const uint8_t> sp);
vector_iostream& write(span<const uint8_t> sp) {
return write(sp.data(), sp.size());
}

vector_iostream& write(span<uint8_t> sp) {
return write(sp.data(), sp.size());
}

vector_iostream& write(std::vector<uint8_t> s);
vector_iostream& write(const std::string& s);
vector_iostream& write(size_t count, uint8_t value);
Expand Down
4 changes: 0 additions & 4 deletions src/iostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ vector_iostream& vector_iostream::write(std::vector<uint8_t> s) {
return *this;
}

vector_iostream& vector_iostream::write(span<const uint8_t> s) {
return write(s.data(), s.size());
}

vector_iostream& vector_iostream::write_sized_int(uint64_t value, size_t size) {
const uint64_t stack_val = value;
return write(reinterpret_cast<const uint8_t*>(&stack_val), size);
Expand Down
13 changes: 13 additions & 0 deletions tests/pe/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,16 @@ def test_imports_notepadpp(tmp_path):
stdout, _ = kproc.communicate()
print(stdout)
assert kproc.returncode == 0


def test_issue_952(tmp_path):
pe = lief.PE.parse(get_sample("PE/PE32_x86_binary_HelloWorld.exe"))
stub = bytes(pe.dos_stub)
assert not all(x == 0 for x in stub)

out = tmp_path / "out.exe"
pe.write(out.as_posix())

new = lief.PE.parse(out.as_posix())
print(bytes(new.dos_stub))
assert bytes(new.dos_stub) == stub

0 comments on commit 1f21f7b

Please sign in to comment.