Change byte value in nodes

Asked

Viewed 16 times

0

In php to change the value of certain bytes in the binary file, use a simple replace. For example:

$acc = fread($f5900xt, filesize(public_path("5900xt")));

$demoid = substr($acc, 0, $userlenght);
$demopass = substr($acc, 16, $passlenght);

$acc = str_replace($demoid, $login, $acc);
$acc = str_replace($demopass, $password, $acc);

I tried something similar in nodejs, but replace does not count the required homes in the file.

var accountFileExample = fs.readFileSync('./src/fileUtils/5900xt', 'binary', { enconding: 'utf8'});
    var accountFinally;

    const demoid = accountFileExample.substring(0, loginLength);
    const demopass = accountFileExample.substring(16, passLength);
    accountFinally = accountFileExample.replace(demoid, login)
    accountFinally = accountFinally.replace(demopass, password)
    console.log(accountFileExample);

1 answer

2

Hello,

In Javascript, the replace occurs only in the first item because it uses by default Expressoes Regulares.

To get around this, you can use the following code:

accountFinally = accountFileExample.replace(new RegExp(demoid, 'g'), login);
accountFinally = accountFinally.replace(new RegExp(demopass, 'g'), password);
  • Cool, thanks info. Fill works that way too? I got something like data.fill(login, 0, login.length);
 data.fill(password, 16, password.length); but the second Fill does not work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.