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

define_user_symbol in Rust API broken on Linux #4774

Closed
greaka opened this issue Nov 25, 2023 · 3 comments
Closed

define_user_symbol in Rust API broken on Linux #4774

greaka opened this issue Nov 25, 2023 · 3 comments
Assignees
Labels
Component: Rust API Issue needs changes to the Rust API Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround Type: Bug Issue is a non-crashing bug with repro steps
Milestone

Comments

@greaka
Copy link

greaka commented Nov 25, 2023

Version and Platform (required):

  • Binary Ninja Version: Version 3.6.4658-dev Personal (2023-11-24 20:35:59)
  • OS: Arch Linux
  • OS Version: 6.6.1-arch1-1
  • CPU Architecture: x64

Bug Description:
binaryview.define_user_symbol() creates garbled output on Linux. Windows works fine. Not tested on Mac.

Steps To Reproduce:

  1. install rust
  2. compile the code snippet provided in additional information
  3. load the plugin in binja
  4. open a x86 project
  5. run the test function
  6. jump to the function
  7. check the name in linear view

Expected Behavior:
I expect to see my defined name in binja.

image
Test code run on Windows

Actual Behavior:
I see garbled text.

image
Test code run on Linux

Additional Information:

Loading the broken bndb on windows shows the same garbled text.

Test Code
use binaryninja::{
    binaryview::{BinaryView, BinaryViewExt},
    command::{register, Command},
    logger,
    string::BnString,
    symbol::Symbol,
};
use log::{info, LevelFilter};


struct TestCommand;

impl Command for TestCommand {
    fn action(&self, view: &BinaryView) {
        if let Some(func) = view.functions().iter().next() {
            info!("setting fn {:#x}", func.symbol().address());
            let bn_full_name = BnString::new("bn_full_name");
            let bn_short_name = BnString::new("bn_short_name");
            let symbol = Symbol::builder(
                func.symbol().sym_type(),
                func.symbol().raw_name(),
                func.symbol().address(),
            )
                .full_name(bn_full_name)
                .short_name(bn_short_name)
                .create();

            view.define_user_symbol(&symbol);
        }
    }

    fn valid(&self, _view: &BinaryView) -> bool {
        true
    }
}

#[no_mangle]
#[allow(non_snake_case)]
pub extern "C" fn CorePluginInit() -> bool {
    logger::init(LevelFilter::Info).expect("failed to initialize logging");

    register("Diff\\Test", "Test", TestCommand);

    true
}
@psifertex psifertex added the Component: Rust API Issue needs changes to the Rust API label Nov 25, 2023
@psifertex
Copy link
Member

I assume this issue is only in the Rust API, did you happen to test it in python as well? I'll take a look next week if not to confirm.

@greaka
Copy link
Author

greaka commented Nov 25, 2023

Assuming this code is equivalent, only the rust api is affected

image

@xusheng6 xusheng6 changed the title Define user symbol broken on Linux define_user_symbol in Rust API broken on Linux Nov 27, 2023
@xusheng6 xusheng6 added Type: Bug Issue is a non-crashing bug with repro steps Effort: Low Issue should take < 1 week Effort: Medium Issue should take < 1 month labels Nov 27, 2023
@plafosse plafosse added this to the Dorsai milestone Nov 28, 2023
@plafosse plafosse added Impact: Medium Issue is impactful with a bad, or no, workaround and removed Effort: Medium Issue should take < 1 month labels Nov 28, 2023
@ElykDeer
Copy link
Member

ElykDeer commented Dec 5, 2023

While I was in there, I changed the APIs to use &strs instead, per #4625...so you may need to update your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Rust API Issue needs changes to the Rust API Effort: Low Issue should take < 1 week Impact: Medium Issue is impactful with a bad, or no, workaround Type: Bug Issue is a non-crashing bug with repro steps
Projects
None yet
Development

No branches or pull requests

5 participants