Skip to content

Guidance for pure JS #1

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

Open
omkumar87 opened this issue Mar 4, 2017 · 3 comments
Open

Guidance for pure JS #1

omkumar87 opened this issue Mar 4, 2017 · 3 comments

Comments

@omkumar87
Copy link

Hi ,
Thanks for this wonderful app for reading device via node

I am looking for similiar approach with pure JS instead of Node.
Is there any way to use this code.
Also In order to detect VM, Testing the virtual BIOS DMI information and the hypervisor port
becomes necessary apart from getting CPU ID
Do you have code to get those in the jskernel lib?
If possible can you give your contact email id.

@streamich
Copy link
Owner

streamich commented Mar 4, 2017

Also In order to detect VM, Testing the virtual BIOS DMI information and the hypervisor port
becomes necessary apart from getting CPU ID
Do you have code to get those in the jskernel lib?

Nope

I am looking for similiar approach with pure JS instead of Node.

Yes, you can run this function without Node.js, you just need a way to execute machine code from JavaScript.

In full-js project I do it using a thing called StaticBuffer, which is just like Node's Buffer but has a call function that can execute the machine code that is written to the buffer buffer.call().

full-js creates the StaticBuffer constructor automatically given some low level dependencies are provided by the JavaScript runtime, here is how I do it for V8 and Duktape:

Those basically implement the below methods for V8 and Duktape, respectively:

  • process.syscall(number, ...args): number
  • process.syscall64(number, ...args): number
  • process.asyscall(number, ...args, callback)
  • process.asyscall64(number, ...args, callback)
  • process.frame(address, size): StaticArrayBuffer
  • process.call(addr: any, offset?: number, args?: number[]): number
  • process.errno(): number

For just running cpuid, you need process.syscall, process.frame and process.call.

process.syscall to allocate executable memory, process.frame to wrap that memory block into a Buffer and process.call to execute the machine code in that block.

The StaticBuffer class (which you can find here) does all of that for you, just include it and its dependencies and it will work like this:

// Allocate r - readable, w - writable, e - executable memory
var sb = StaticBuffer.alloc(size, 'rwe');

// Write executable code to your sb

// Execute the code at offset 0 with no args
sb.call(0, []);

If possible can you give your contact email id.

Write me at peefour.team at gmail.

@omkumar87
Copy link
Author

omkumar87 commented Mar 7, 2017 via email

@adrelanos
Copy link

Did you manage to run this without Node.js and could you share the source code please?

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

3 participants