streamich / cpuid

cpuid x86 in JavaScript
3 stars 0 forks source link

Guidance for pure JS #1

Open omkumar87 opened 7 years ago

omkumar87 commented 7 years ago

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 commented 7 years ago

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:

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 commented 7 years ago

Hi Sir,

Thank you very much.I appreciate that. Thanks for the efforts in giving me the msg.

I will try out.

Thanks, M.Omkumar

On Sat, Mar 4, 2017 at 8:34 AM, streamich notifications@github.com wrote:

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 https://github.com/streamich/full-js/blob/master/src/lib/static-buffer.js) 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 memoryvar sb = StaticBuffer.alloc(size, 'rwe'); // Write executable code to you sb // Execute the code at offset 0 with no argssb.call(0, []);

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/streamich/cpuid/issues/1#issuecomment-284162842, or mute the thread https://github.com/notifications/unsubscribe-auth/ARTtoFXPWSaIdE1ZsnwDu6XMsrIkqZxbks5riZKigaJpZM4MS7HZ .

adrelanos commented 2 years ago

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