diff --git a/librz/egg/emit/x86.c b/librz/egg/emit/x86.c index d84b4ff458..417d074a8b 100644 --- a/librz/egg/emit/x86.c +++ b/librz/egg/emit/x86.c @@ -173,13 +173,15 @@ static void emit_string(RzEgg *egg, const char *dstvar, const char *str, int j) #define M32(x) (unsigned int)((x) & 0xffffffff) /* XXX: Assumes sizeof(ut32) == 4 */ for (i = 4; i <= oj; i += 4) { - /* XXX endian issues (non-portable asm) */ - ut32 *n = (ut32 *)(s + i - 4); + /* x86 is always little-endian: read the chunk as LE so the emitted + * immediate (and thus the assembled bytes) does not depend on the + * host endianness. */ + ut32 n = rz_read_le32(s + i - 4); p = rz_egg_lang_mkvar(egg, str2, dstvar, i + BPOFF); if (attsyntax) { - rz_egg_printf(egg, " movl $0x%x, %s\n", M32(*n), p); + rz_egg_printf(egg, " movl $0x%x, %s\n", M32(n), p); } else { - rz_egg_printf(egg, " mov dword %s, 0x%x\n", p, M32(*n)); + rz_egg_printf(egg, " mov dword %s, 0x%x\n", p, M32(n)); } free(p); j -= 4; diff --git a/test/db/tools/rz_gg b/test/db/tools/rz_gg index 69ed196f78..5513a45e5c 100644 --- a/test/db/tools/rz_gg +++ b/test/db/tools/rz_gg @@ -93,17 +93,16 @@ EOF RUN NAME=rz-gg -k linux -a x86 -b32 simple_cmp.r -BROKEN=1 TOOL=rz-gg ARGS=-k linux -a x86 -b32 bins/other/rz-gg/simple_cmp.r EXPECT=<