Code Monkey home page Code Monkey logo

Comments (2)

tremalrik avatar tremalrik commented on June 9, 2024

These examples indicate that it's not just the encoder that's mishandling 16-bit address truncation, but the formatter as well.

While displacements can always be treated as signed in x86, address truncation is unsigned. Also - and this is the part that Zydis doesn't appear to handle correctly - the 67h prefix overrides not just address calculation width but address truncation width as well.

As a result:

  • in 32-bit mode, decoding 67 00 3e 00 ff as add byte ptr ds:[0x0000FF00],bh is correct - in this case, the 67h prefix overrides truncation width from 32-bit down to 16-bit, and the resulting memory access goes to ds:[0x0000FF00], not ds:[0xFFFFFF00]. As a result, re-encoding 00 3d 00 ff ff ff into 67 00 3e 00 ff is not correct, but it would have been correct to re-encode 00 3d 00 ff 00 00 into 67 00 3e 00 ff.
  • in 16-bit mode, decoding 67 3a 05 00 1e 57 1a as cmp al, byte ptr ds:[0x1E00] is NOT correct! The 67h prefix will, in this case, override address truncation width from 16-bit to 32-bit, so the memory access will go to address ds:[0x1a571e00], not ds:[0x1e00]. As such, the correct decoding is cmp al, byte ptr ds:[0x1a571e00] - which is what e.g. XED outputs. (Attempting to access address ds:[0x1a571e00] in 16-bit mode will normally cause a #GP, due to the data segment size normally being 64K in 16-bit mode, however it is perfectly possible to set up a big 32-bit data segment for unreal-mode or 16-bit protected-mode, in which case such an instruction will execute just fine in 16-bit mode.)

from zydis.

mappzor avatar mappzor commented on June 9, 2024

@tremalrik I've addressed this already in #472 :)

Separate PR will soon address rest of the issues.

from zydis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.