From: Wilhansen Li Date: Mon, 26 Dec 2016 17:30:22 +0000 (+0800) Subject: id attribs should be swapped regardless of endianness X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=99c6487a6eaa2ef00dbce12a450fac84c13abdcc;p=GitHub%2FLineageOS%2FG12%2Fandroid_hardware_amlogic_tools_dtbtool.git id attribs should be swapped regardless of endianness --- diff --git a/dtbSplit.cpp b/dtbSplit.cpp index 80af0d6..c92dea7 100644 --- a/dtbSplit.cpp +++ b/dtbSplit.cpp @@ -74,6 +74,12 @@ void trimSpace(char *b, const int len) { b[len - 1] = 0; } } +uint32_t swap_bytes_u32(uint32_t b) { + return ((b & 0xFF000000) >> 24) | + ((b & 0x00FF0000) >> 8) | + ((b & 0x0000FF00) << 8) | + (b << 24); +} template void dumpData(const uint32_t entries, const string &dest, ifstream &dtb) { typedef HeaderEntry HeaderType; @@ -93,9 +99,9 @@ void dumpData(const uint32_t entries, const string &dest, ifstream &dtb) { auto u32plat = reinterpret_cast(h.plat); auto u32vari = reinterpret_cast(h.vari); for ( uint32_t j = 0; j < ID_SIZE/sizeof(uint32_t); ++j ) { - *(u32soc + j) = ntohl(*(u32soc + j)); - *(u32plat + j) = ntohl(*(u32plat + j)); - *(u32vari + j) = ntohl(*(u32vari + j)); + *(u32soc + j) = swap_bytes_u32(*(u32soc + j)); + *(u32plat + j) = swap_bytes_u32(*(u32plat + j)); + *(u32vari + j) = swap_bytes_u32(*(u32vari + j)); } trimSpace(h.soc, ID_SIZE); trimSpace(h.plat, ID_SIZE);