Skip to content

Commit d2b8884

Browse files
committed
cli: pure js impl for searching in binary
1 parent 6f1a7cf commit d2b8884

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cli/src/index.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -1505,9 +1505,23 @@ async function checkSolanaBinary(binary: string, wormhole: string, providedProgr
15051505
const wormholeHex = new PublicKey(wormhole).toBuffer().toString("hex");
15061506
const providedProgramIdHex = new PublicKey(providedProgramId).toBuffer().toString("hex");
15071507

1508-
execSync(`xxd -p ${binary} | tr -d '\n' | grep ${wormholeHex}`);
1509-
execSync(`xxd -p ${binary} | tr -d '\n' | grep ${providedProgramIdHex}`);
1508+
if (!searchHexInBinary(binary, wormholeHex)) {
1509+
console.error(`Wormhole address not found in binary: ${wormhole}`);
1510+
process.exit(1);
1511+
}
1512+
if (!searchHexInBinary(binary, providedProgramIdHex)) {
1513+
console.error(`Provided program ID not found in binary: ${providedProgramId}`);
1514+
process.exit(1);
1515+
}
1516+
}
1517+
1518+
// not the most efficient, but at least it's definitely portable
1519+
function searchHexInBinary(binaryPath: string, searchHex: string) {
1520+
const buffer = fs.readFileSync(binaryPath);
1521+
const hexString = buffer.toString('hex');
1522+
const found = hexString.includes(searchHex);
15101523

1524+
return found;
15111525
}
15121526

15131527
export function ensureNttRoot(pwd: string = ".") {

0 commit comments

Comments
 (0)