Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jmp imm bug #129

Closed
blackchicken20 opened this issue Jun 7, 2024 · 4 comments
Closed

jmp imm bug #129

blackchicken20 opened this issue Jun 7, 2024 · 4 comments

Comments

@blackchicken20
Copy link

Snipaste_2024-06-07_13-27-47
My target address is 0x347486 (0x224AB8A1486), but the generated assembly instruction's target address is 0x347485 (0x224AB8A1485). Is this a bug?

    zasm::Program program(zasm::MachineMode::AMD64);
    zasm::x86::Assembler assembler(program);

    assembler.jmp(zasm::Imm(instr.jmp_rva));

    zasm::Serializer serializer{};
    auto res = serializer.serialize(program, instr.rva);
    if (res == zasm::ErrorCode::None) {
      auto ptr = serializer.getCode();
      auto size = serializer.getCodeSize();
      std::memcpy(reinterpret_cast<void *>(base.module_base + instr.rva),
                  serializer.getCode(), serializer.getCodeSize());
     }
     
@ZehMatt
Copy link
Collaborator

ZehMatt commented Jun 7, 2024

I've created a small test function using the information you provided.

    TEST(SerializationTests, Issue_129)
    {
        int64_t rva = 0x3471fe;
        int64_t jmp_rva = 0x347486;

        Program program(zasm::MachineMode::AMD64);
        x86::Assembler assembler(program);

        assembler.jmp(zasm::Imm(jmp_rva));

        zasm::Serializer serializer{};
        auto res = serializer.serialize(program, rva);
        if (res == zasm::ErrorCode::None)
        {
            auto ptr = serializer.getCode();
            auto size = serializer.getCodeSize();

            ASSERT_EQ(size, 5);

            auto decoder = zasm::Decoder(zasm::MachineMode::AMD64);
            auto decoded = decoder.decode(ptr, size, rva);

            auto& op0 = decoded->getOperand<Imm>(0);
            ASSERT_EQ(op0.value<int64_t>(), jmp_rva);
        }
    }

This test however passes on my end, the immediate has the expected value 0x347486. Are you using the latest commit?

@blackchicken20
Copy link
Author

blackchicken20 commented Jun 8, 2024

I've created a small test function using the information you provided.

    TEST(SerializationTests, Issue_129)
    {
        int64_t rva = 0x3471fe;
        int64_t jmp_rva = 0x347486;

        Program program(zasm::MachineMode::AMD64);
        x86::Assembler assembler(program);

        assembler.jmp(zasm::Imm(jmp_rva));

        zasm::Serializer serializer{};
        auto res = serializer.serialize(program, rva);
        if (res == zasm::ErrorCode::None)
        {
            auto ptr = serializer.getCode();
            auto size = serializer.getCodeSize();

            ASSERT_EQ(size, 5);

            auto decoder = zasm::Decoder(zasm::MachineMode::AMD64);
            auto decoded = decoder.decode(ptr, size, rva);

            auto& op0 = decoded->getOperand<Imm>(0);
            ASSERT_EQ(op0.value<int64_t>(), jmp_rva);
        }
    }

This test however passes on my end, the immediate has the expected value 0x347486. Are you using the latest commit?

yes,i use latest commit.

Snipaste_2024-06-08_10-09-10

@blackchicken20
Copy link
Author

I created a new project, pulled the commit again, recompiled, and the issue was resolved.
thks @ZehMatt .

ZehMatt added a commit that referenced this issue Jun 8, 2024
ZehMatt added a commit that referenced this issue Jun 8, 2024
@ZehMatt
Copy link
Collaborator

ZehMatt commented Jun 8, 2024

Glad it worked out, for good measure I added a new test #130 based on this to prevent such an issue in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants