Skip to content

Commit

Permalink
Replace std::endl with \n
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed May 5, 2024
1 parent 2a26324 commit b2b56a7
Show file tree
Hide file tree
Showing 61 changed files with 491 additions and 491 deletions.
2 changes: 1 addition & 1 deletion doc/sphinx/_static/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MyClass {
public:
MyClass(void) : message_{"hello"} {};
MyClass(const std::string& message) : message_{message} {};
void say_hello(void) { std::cout << this->message_<< std::endl; }
void say_hello(void) { std::cout << this->message_<< '\n'; }

private:
std::string message_;
Expand Down
16 changes: 8 additions & 8 deletions doc/sphinx/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ C++
std::unique_ptr<LIEF::OAT::File> vdex = LIEF::VDEX::Parser::parse("classes.vdex");
std::unique_ptr<LIEF::OAT::File> art = LIEF::ART::Parser::parse("boot.art");
std::cout << *elf << std::endl;
std::cout << *pe << std::endl;
std::cout << *macho << std::endl;
std::cout << *oat << std::endl;
std::cout << *dex << std::endl;
std::cout << *vdex << std::endl;
std::cout << *art << std::endl;
std::cout << *elf << '\n';
std::cout << *pe << '\n';
std::cout << *macho << '\n';
std::cout << *oat << '\n';
std::cout << *dex << '\n';
std::cout << *vdex << '\n';
std::cout << *art << '\n';
}
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/elf_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int main(int argc, char **argv) {
//std::cout << "== Symbols Version Requirement ==" << '\n';
//std::vector<SymbolVersionRequirement> *symR = binary->get_symbol_version_requirement();
//for (SymbolVersionRequirement &symbolR : *symR) {
// std::cout << symbolR << '\n' << std::endl;
// std::cout << symbolR << '\n' << '\n';
// auto symAux = symbolR.get_auxiliary_symbols();
// for (auto &symbolAux : symAux) {
// std::cout << *symbolAux << '\n';
Expand Down
12 changes: 6 additions & 6 deletions package/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ C++
// ELF
try {
std::unique_ptr<LIEF::ELF::Binary> elf = LIEF::ELF::Parser::parse("/bin/ls");
std::cout << *elf << std::endl;
std::cout << *elf << '\n';
} catch (const LIEF::exception& err) {
std::cerr << err.what() << std::endl;
std::cerr << err.what() << '\n';
}
// PE
try {
std::unique_ptr<LIEF::PE::Binary> pe = LIEF::PE::Parser::parse("C:\\Windows\\explorer.exe");
std::cout << *pe << std::endl;
std::cout << *pe << '\n';
} catch (const LIEF::exception& err) {
std::cerr << err.what() << std::endl;
std::cerr << err.what() << '\n';
}
// Mach-O
try {
std::unique_ptr<LIEF::MachO::FatBinary> macho = LIEF::MachO::Parser::parse("/bin/ls");
std::cout << *macho << std::endl;
std::cout << *macho << '\n';
} catch (const LIEF::exception& err) {
std::cerr << err.what() << std::endl;
std::cerr << err.what() << '\n';
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion profiling/oat_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <oat>" << std::endl;
std::cerr << "Usage: " << argv[0] << " <oat>" << '\n';
}
std::unique_ptr<LIEF::OAT::Binary> binary{LIEF::OAT::Parser::parse(argv[1])};
return 0;
Expand Down
40 changes: 20 additions & 20 deletions src/ART/Header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,39 +122,39 @@ void Header::accept(Visitor& visitor) const {
std::ostream& operator<<(std::ostream& os, const Header& hdr) {
static constexpr size_t WIDTH = 33;
os << std::hex << std::left << std::showbase;
os << std::setw(WIDTH) << std::setfill(' ') << "Magic: " << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Version: " << std::dec << hdr.version() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Magic: " << '\n';
os << std::setw(WIDTH) << std::setfill(' ') << "Version: " << std::dec << hdr.version() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Image Begin: " << std::hex << hdr.image_begin() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Image Size: " << std::hex << hdr.image_size() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Image Begin: " << std::hex << hdr.image_begin() << '\n';
os << std::setw(WIDTH) << std::setfill(' ') << "Image Size: " << std::hex << hdr.image_size() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Checksum: " << std::hex << hdr.oat_checksum() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Checksum: " << std::hex << hdr.oat_checksum() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "OAT File Begin: " << std::hex << hdr.oat_file_begin() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "OAT File End:" << std::hex << hdr.oat_file_end() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "OAT File Begin: " << std::hex << hdr.oat_file_begin() << '\n';
os << std::setw(WIDTH) << std::setfill(' ') << "OAT File End:" << std::hex << hdr.oat_file_end() << '\n';


os << std::setw(WIDTH) << std::setfill(' ') << "OAT Data Begin: " << std::hex << hdr.oat_data_begin() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "OAT Data End:" << std::hex << hdr.oat_data_end() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "OAT Data Begin: " << std::hex << hdr.oat_data_begin() << '\n';
os << std::setw(WIDTH) << std::setfill(' ') << "OAT Data End:" << std::hex << hdr.oat_data_end() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Patch Delta:" << std::dec << hdr.patch_delta() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Patch Delta:" << std::dec << hdr.patch_delta() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Pointer Size:" << std::dec << hdr.pointer_size() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Pointer Size:" << std::dec << hdr.pointer_size() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Compile pic:" << std::boolalpha << hdr.compile_pic() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Compile pic:" << std::boolalpha << hdr.compile_pic() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Number of sections:" << std::dec << hdr.nb_sections() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Number of methods:" << std::dec << hdr.nb_methods() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Number of sections:" << std::dec << hdr.nb_sections() << '\n';
os << std::setw(WIDTH) << std::setfill(' ') << "Number of methods:" << std::dec << hdr.nb_methods() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Boot Image Begin:" << std::hex << hdr.boot_image_begin() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Boot Image Size:" << std::hex << hdr.boot_image_size() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Boot Image Begin:" << std::hex << hdr.boot_image_begin() << '\n';
os << std::setw(WIDTH) << std::setfill(' ') << "Boot Image Size:" << std::hex << hdr.boot_image_size() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Boot OAT Begin:" << std::hex << hdr.boot_oat_begin() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Boot OAT Size:" << std::hex << hdr.boot_oat_size() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Boot OAT Begin:" << std::hex << hdr.boot_oat_begin() << '\n';
os << std::setw(WIDTH) << std::setfill(' ') << "Boot OAT Size:" << std::hex << hdr.boot_oat_size() << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Storage Mode:" << to_string(hdr.storage_mode()) << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Storage Mode:" << to_string(hdr.storage_mode()) << '\n';

os << std::setw(WIDTH) << std::setfill(' ') << "Data Size:" << std::hex << hdr.data_size() << std::endl;
os << std::setw(WIDTH) << std::setfill(' ') << "Data Size:" << std::hex << hdr.data_size() << '\n';

return os;
}
Expand Down
46 changes: 23 additions & 23 deletions src/ART/Parser.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Parser::parse_sections() {
using jclass_t = typename ART_T::template jclass_t<>;
using jobject_t = typename ART_T::template jobject_t<>;

VLOG(VDEBUG) << "Parsing Image Sections" << std::endl;
VLOG(VDEBUG) << "Parsing Image Sections" << '\n';
size_t nb_sections = file_->header().nb_sections_;

const art_header_t& hdr = stream_->peek<art_header_t>(0);
Expand All @@ -81,7 +81,7 @@ void Parser::parse_sections() {
jarray_offset = align(jarray_offset, sizeof(uint64_t));
//jarray_offset = 0x700e1db0 - imagebase_;
}
std::cout << "addr:" << std::hex << imagebase_ + jarray_offset << std::endl;
std::cout << "addr:" << std::hex << imagebase_ + jarray_offset << '\n';

const jarray_t* array = reinterpret_cast<const jarray_t*>(stream_->read(jarray_offset, sizeof(jarray_t)));
uint64_t elements_offset = jarray_offset + offsetof(jarray_t, elements);
Expand All @@ -92,11 +92,11 @@ void Parser::parse_sections() {
<< " --> " << (section_header.offset + section_header.size)
<< " #" << std::dec << array->length;

std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset) << std::endl;
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + sizeof(uint32_t)) << std::endl;
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + 2 * sizeof(uint32_t)) << std::endl;
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + 3 * sizeof(uint32_t)) << std::endl;
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + 4 * sizeof(uint32_t)) << std::endl;
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset) << '\n';
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + sizeof(uint32_t)) << '\n';
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + 2 * sizeof(uint32_t)) << '\n';
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + 3 * sizeof(uint32_t)) << '\n';
std::cout << std::hex << stream_->read_integer<uint32_t>(jarray_offset + 4 * sizeof(uint32_t)) << '\n';


uint32_t parent = array->object.klass - imagebase_;
Expand Down Expand Up @@ -145,7 +145,7 @@ void Parser::parse_sections() {
template<typename ART_T, typename PTR_T>
void Parser::parse_roots() {
using jarray_t = typename ART_T::template jarray_t<>;
VLOG(VDEBUG) << "Parsing Image Roots" << std::endl;
VLOG(VDEBUG) << "Parsing Image Roots" << '\n';
using IMAGE_ROOTS = typename ART_T::IMAGE_ROOTS;

uint32_t image_root_offset = file_->header().image_roots_ - file_->header().image_begin_;
Expand All @@ -154,7 +154,7 @@ void Parser::parse_roots() {
VLOG(VDEBUG) << "Image root offset: " << std::hex << std::showbase << image_root_offset;

const jarray_t* array = reinterpret_cast<const jarray_t*>(stream_->read(image_root_offset, sizeof(jarray_t)));
std::cout << "Nb elements: " << array->length << std::endl;
std::cout << "Nb elements: " << array->length << '\n';

const uint32_t* array_values = reinterpret_cast<const uint32_t*>(
stream_->read(
Expand All @@ -166,9 +166,9 @@ void Parser::parse_roots() {
for (size_t i = 0; i < ART_T::nb_image_roots; ++i) {
IMAGE_ROOTS type = static_cast<IMAGE_ROOTS>(i);
uint64_t struct_offset = array_values[i] - imagebase_;
std::cout << std::hex << struct_offset << std::endl;
std::cout << std::hex << struct_offset << '\n';
const jarray_t* array = reinterpret_cast<const jarray_t*>(stream_->read(struct_offset, sizeof(jarray_t)));
std::cout << "Nb elements: " << std::dec << array->length << std::endl;
std::cout << "Nb elements: " << std::dec << array->length << '\n';
switch (type) {
case IMAGE_ROOTS::DEX_CACHES:
{
Expand Down Expand Up @@ -202,7 +202,7 @@ template<typename ART_T, typename PTR_T>
void Parser::parse_class_roots(size_t offset, size_t size) {
using jclass_t = typename ART_T::template jclass_t<>;
using jstring_t = typename ART_T::template jstring_t<>;
VLOG(VDEBUG) << "Parsing Class Roots" << std::endl;
VLOG(VDEBUG) << "Parsing Class Roots" << '\n';

for (size_t i = 0; i < size; ++i) {
uint32_t object_offset = stream_->read_integer<uint32_t>(offset + i * sizeof(uint32_t)) - imagebase_;
Expand All @@ -223,15 +223,15 @@ template<typename ART_T, typename PTR_T>
void Parser::parse_jstring(size_t offset) {
using jstring_t = typename ART_T::template jstring_t<>;
const jstring_t* jstring = reinterpret_cast<const jstring_t*>(stream_->read(offset, sizeof(jstring_t)));
//std::cout << "Class leng: " << std::dec << jstring->count << std::endl;
//std::cout << "Class leng: " << std::dec << jstring->count << '\n';

uint64_t value_offset = offset + offsetof(jstring_t, value);

std::u16string str = {
reinterpret_cast<const char16_t*>(stream_->read(value_offset, static_cast<uint16_t>(jstring->count) * sizeof(char16_t))),
static_cast<uint16_t>(jstring->count)
};
std::cout << u16tou8(str) << std::endl;
std::cout << u16tou8(str) << '\n';
}

template<typename ART_T, typename PTR_T>
Expand All @@ -242,7 +242,7 @@ void Parser::parse_dex_caches(size_t offset, size_t size) {
using jstring_t = typename ART_T::template jstring_t<>;
using jdex_cache_t = typename ART_T::template jdex_cache_t<>;

VLOG(VDEBUG) << "Parsing Dex Cache" << std::endl;
VLOG(VDEBUG) << "Parsing Dex Cache" << '\n';

for (size_t i = 0; i < size; ++i) {
uint32_t object_offset = stream_->read_integer<uint32_t>(offset + i * sizeof(uint32_t)) - imagebase_;
Expand All @@ -266,14 +266,14 @@ void Parser::parse_dex_cache(size_t object_offset) {
reinterpret_cast<const char*>(stream_->read(name_offset, static_cast<uint16_t>(len) * sizeof(char))),
len
};
std::cout << location_string << std::endl;
std::cout << location_string << '\n';
} else {

std::u16string location_string = {
reinterpret_cast<const char16_t*>(stream_->read(name_offset, static_cast<uint16_t>(location->count) * sizeof(char16_t))),
static_cast<uint16_t>(location->count)
};
std::cout << u16tou8(location_string) << std::endl;
std::cout << u16tou8(location_string) << '\n';
}
}

Expand All @@ -282,7 +282,7 @@ void Parser::parse_methods() {
using art_header_t = typename ART_T::art_header_t;
using IMAGE_METHODS = typename ART_T::IMAGE_METHODS;

VLOG(VDEBUG) << "Parsing Image Methods" << std::endl;
VLOG(VDEBUG) << "Parsing Image Methods" << '\n';


const art_header_t* hdr = reinterpret_cast<const art_header_t*>(stream_->read(0, sizeof(art_header_t)));
Expand All @@ -304,26 +304,26 @@ void Parser::parse_objects(size_t offset, size_t size) {
using jclass_t = typename ART_T::template jclass_t<>;
using jstring_t = typename ART_T::template jstring_t<>;

VLOG(VDEBUG) << "Paring objects at " << std::hex << offset << std::endl;
VLOG(VDEBUG) << "Paring objects at " << std::hex << offset << '\n';
//const jarray_t* array = reinterpret_cast<const jarray_t*>(stream_->read(offset, sizeof(jarray_t)));
//std::cout << std::dec << "nb elements " << array->length << std::endl;;
//std::cout << std::dec << "nb elements " << array->length << '\n';;
}


template<typename ART_T, typename PTR_T>
void Parser::parse_art_fields(size_t offset, size_t size) {
VLOG(VDEBUG) << "Paring ART Fields at " << std::hex << offset << std::endl;
VLOG(VDEBUG) << "Paring ART Fields at " << std::hex << offset << '\n';
}

template<typename ART_T, typename PTR_T>
void Parser::parse_art_methods(size_t offset, size_t size) {
VLOG(VDEBUG) << "Paring ART Methods at " << std::hex << offset << std::endl;
VLOG(VDEBUG) << "Paring ART Methods at " << std::hex << offset << '\n';
// 0x6ff99db0: long[] length:65533
const PTR_T* methods = reinterpret_cast<const PTR_T*>(stream_->read(offset, size));
// 26740: 0x70a7ea60
PTR_T get_device_id = methods[26740];

std::cout << std::hex << "Get device ID " << get_device_id << std::endl;
std::cout << std::hex << "Get device ID " << get_device_id << '\n';
}

template<typename ART_T, typename PTR_T>
Expand Down
10 changes: 5 additions & 5 deletions src/Abstract/Header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ std::ostream& operator<<(std::ostream& os, const Header& hdr) {
bitness = "64";
}

os << std::setw(33) << std::setfill(' ') << "Architecture:" << to_string(hdr.architecture()) << "_" << modes << std::endl;
os << std::setw(33) << std::setfill(' ') << "Entrypoint:" << "0x" << hdr.entrypoint() << std::endl;
os << std::setw(33) << std::setfill(' ') << "Object type:" << to_string(hdr.object_type()) << std::endl;
os << std::setw(33) << std::setfill(' ') << "32/64 bits:" << bitness << std::endl;
os << std::setw(33) << std::setfill(' ') << "Architecture:" << to_string(hdr.architecture()) << "_" << modes << '\n';
os << std::setw(33) << std::setfill(' ') << "Entrypoint:" << "0x" << hdr.entrypoint() << '\n';
os << std::setw(33) << std::setfill(' ') << "Object type:" << to_string(hdr.object_type()) << '\n';
os << std::setw(33) << std::setfill(' ') << "32/64 bits:" << bitness << '\n';

os << std::setw(33) << std::setfill(' ') << "Endianness:" << to_string(hdr.endianness()) << std::endl;
os << std::setw(33) << std::setfill(' ') << "Endianness:" << to_string(hdr.endianness()) << '\n';
return os;
}

Expand Down
14 changes: 7 additions & 7 deletions src/DEX/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,21 +536,21 @@ std::ostream& operator<<(std::ostream& os, const File& file) {
if (!file.location().empty()) {
os << " - " << file.location();
}
os << std::endl;
os << '\n';

os << "Header" << std::endl;
os << "======" << std::endl;
os << "Header" << '\n';
os << "======" << '\n';

os << file.header();

os << std::endl;
os << '\n';

os << "Map" << std::endl;
os << "===" << std::endl;
os << "Map" << '\n';
os << "===" << '\n';

os << file.map();

os << std::endl;
os << '\n';
return os;
}

Expand Down
4 changes: 2 additions & 2 deletions src/DEX/Header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
#include <sstream>

#define PRINT_FIELD(name,attr) \
os << std::setw(WIDTH) << std::setfill(' ') << name << std::hex << attr << std::endl
os << std::setw(WIDTH) << std::setfill(' ') << name << std::hex << attr << '\n'

#define PRINT_LOCATION(name,attr) \
os << std::setw(WIDTH) << std::setfill(' ') << name << std::hex << attr.first \
<< std::dec << " (#" << attr.second << ")" << std::endl
<< std::dec << " (#" << attr.second << ")" << '\n'

namespace LIEF {
namespace DEX {
Expand Down
2 changes: 1 addition & 1 deletion src/DEX/MapList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void MapList::accept(Visitor& visitor) const {

std::ostream& operator<<(std::ostream& os, const MapList& mlist) {
for (const MapItem& item : mlist.items()) {
os << item << std::endl;
os << item << '\n';
}
return os;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DEX/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ INST_FORMATS inst_format_from_opcode(OPCODES op) {

auto it = size_map.find(op);
//if (it == std::end(size_map)) {
// std::cout << std::hex << "OP: " << op << std::endl;
// std::cout << std::hex << "OP: " << op << '\n';
//}
return it == size_map.end() ? INST_FORMATS::F_00x : it->second;
}
Expand Down

0 comments on commit b2b56a7

Please sign in to comment.