diff --git a/package.json b/package.json index 87c454a..7327444 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,14 @@ "license": "MIT", "devDependencies": { "electron": "1.7.9", - "electron-packager": "^11.0.1" + "electron-packager": "^11.0.1", + "standard": "^11.0.1" }, "dependencies": { "ffi": "^2.2.0", "three": "^0.88.0" + }, + "standard": { + "globals": [ "THREE", "requestAnimationFrame" ] } } diff --git a/src/App.js b/src/App.js index 48830a3..ccbd50e 100644 --- a/src/App.js +++ b/src/App.js @@ -5,10 +5,10 @@ This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ -const Game = require("./Game.js") -const Globals = require("./Globals.js") +const Game = require('./Game.js') +const Globals = require('./Globals.js') -window.addEventListener("load", function () { +window.addEventListener('load', function () { Globals.game = new Game() Globals.game.init() -}) \ No newline at end of file +}) diff --git a/src/Character.js b/src/Character.js index 4c4d42c..4119c85 100644 --- a/src/Character.js +++ b/src/Character.js @@ -5,8 +5,8 @@ This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ -const THREE = require("three") -const Globals = require("./Globals") +const THREE = require('three') +const Globals = require('./Globals') class Character { constructor () { @@ -17,19 +17,19 @@ class Character { this.velocity = new THREE.Vector2(0, 0) this.coordinate = new THREE.Vector2(0, 0) - this.material = new THREE.MeshBasicMaterial( { color: 0xffffff } ) - this.geometry = new THREE.CircleGeometry( 2.5, 32 ) - this.mesh = new THREE.Mesh( this.geometry, this.material ) + this.material = new THREE.MeshBasicMaterial({ color: 0xffffff }) + this.geometry = new THREE.CircleGeometry(2.5, 32) + this.mesh = new THREE.Mesh(this.geometry, this.material) - Globals.scene.add( this.mesh ) + Globals.scene.add(this.mesh) } // click event handler // input: click event position on window - on_click (vec) { + onClick (vec) { this.eases.push([new THREE.Vector2( - Math.atan((vec.x-Globals.width/2)*0.04)*0.03, - Math.atan((-vec.y+Globals.height/2)*0.04)*0.03 + Math.atan((vec.x - Globals.width / 2) * 0.04) * 0.03, + Math.atan((-vec.y + Globals.height / 2) * 0.04) * 0.03 ), this.time]) } @@ -41,8 +41,8 @@ class Character { let coefficient = i[0] let t = this.time - i[1] - 5 - this.velocity.x += coefficient.x / (0.1*t*t + 1) - this.velocity.y += coefficient.y / (0.1*t*t + 1) + this.velocity.x += coefficient.x / (0.1 * t * t + 1) + this.velocity.y += coefficient.y / (0.1 * t * t + 1) } this.velocity.x *= 0.995 @@ -55,4 +55,4 @@ class Character { } } -module.exports = Character \ No newline at end of file +module.exports = Character diff --git a/src/Config.js b/src/Config.js index 3b02ec9..631f375 100644 --- a/src/Config.js +++ b/src/Config.js @@ -1,2 +1,2 @@ module.exports = { -} \ No newline at end of file +} diff --git a/src/Footprints.js b/src/Footprints.js new file mode 100644 index 0000000..b1ca342 --- /dev/null +++ b/src/Footprints.js @@ -0,0 +1,10 @@ +class Footprints { + constructor () { + + } + update () { + + } +} + +module.exports = Footprints diff --git a/src/Game.js b/src/Game.js index 809c3cd..0048323 100644 --- a/src/Game.js +++ b/src/Game.js @@ -5,50 +5,48 @@ This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ -const electron = require('electron') -const win = electron.remote.getCurrentWindow() +const ProcessView = require('./ProcessView') +const ProcessSelect = require('./ProcessSelect') +const Character = require('./Character') +const Footprints = require('./Footprints') -const ProcessView = require("./ProcessView") -const ProcessSelect = require("./ProcessSelect") -const Character = require("./Character") - -const Globals = require("./Globals.js") -const Config = require("./Config.js") +const Globals = require('./Globals.js') class Game { init () { // camera / scene / renderer preparation - Globals.camera = new THREE.OrthographicCamera( Globals.width/-2, Globals.width/2, Globals.height/2, Globals.height/-2, 1, 2000 ) + Globals.camera = new THREE.OrthographicCamera(Globals.width / -2, Globals.width / 2, Globals.height / 2, Globals.height / -2, 1, 2000) Globals.camera.position.z = 500 Globals.scene = new THREE.Scene() - Globals.renderer = new THREE.WebGLRenderer( { antialias: false } ) - Globals.renderer.setSize( Globals.width, Globals.height ) - document.body.appendChild( Globals.renderer.domElement ) + Globals.renderer = new THREE.WebGLRenderer({ antialias: false }) + Globals.renderer.setSize(Globals.width, Globals.height) + document.body.appendChild(Globals.renderer.domElement) // event handlers - window.addEventListener('resize', () => { this.resize() }, false ) + window.addEventListener('resize', () => { this.resize() }, false) - window.addEventListener( 'mousedown', function (ev) { - Globals.character.on_click(new THREE.Vector2(ev.clientX, ev.clientY)) + window.addEventListener('mousedown', function (ev) { + Globals.character.onClick(new THREE.Vector2(ev.clientX, ev.clientY)) }, false) // construct objects Globals.character = new Character() - Globals.process_select = new ProcessSelect() + Globals.processSelect = new ProcessSelect() + Globals.footprints = new Footprints() // call animate func this.last_time = 0 - requestAnimationFrame( (time) => { this.animate(time) } ) + requestAnimationFrame((time) => { this.animate(time) }) } resize () { Globals.renderer.setSize(Globals.width, Globals.height) - Globals.camera.left = Globals.width/-2 - Globals.camera.right = Globals.width/2 - Globals.camera.top = Globals.height/2 - Globals.camera.bottom = Globals.height/-2 + Globals.camera.left = Globals.width / -2 + Globals.camera.right = Globals.width / 2 + Globals.camera.top = Globals.height / 2 + Globals.camera.bottom = Globals.height / -2 Globals.camera.updateProjectionMatrix() } @@ -56,26 +54,27 @@ class Game { Globals.delta = time - this.last_time this.last_time = time - Globals.renderer.render( Globals.scene, Globals.camera ) + Globals.renderer.render(Globals.scene, Globals.camera) Globals.camera.position.x = Globals.character.coordinate.x Globals.camera.position.y = Globals.character.coordinate.y Globals.character.update() + Globals.footprints.update() - if (Globals.process_select.finished == false) { - Globals.process_select.update() + if (Globals.processSelect.finished === false) { + Globals.processSelect.update() } - if (Globals.process_select.selected == true) { - if (Globals.process_view === undefined) { - Globals.process_view = new ProcessView(Globals.process_select.pid) + if (Globals.processSelect.selected === true) { + if (Globals.processView === undefined) { + Globals.processView = new ProcessView(Globals.processSelect.pid) } - Globals.process_view.update() + Globals.processView.update() } - requestAnimationFrame( (time) => { this.animate(time) } ) + requestAnimationFrame((time) => { this.animate(time) }) } } -module.exports = Game \ No newline at end of file +module.exports = Game diff --git a/src/Globals.js b/src/Globals.js index 2620899..54e3c52 100644 --- a/src/Globals.js +++ b/src/Globals.js @@ -11,13 +11,14 @@ module.exports = { camera: undefined, renderer: undefined, game: undefined, - process_select: undefined, - process_view: undefined, + processSelect: undefined, + processView: undefined, character: undefined, + footprints: undefined, get width () { return window.innerWidth }, get height () { return window.innerHeight } -} \ No newline at end of file +} diff --git a/src/MacMemory.js b/src/MacMemory.js index 8900c41..2db4d53 100644 --- a/src/MacMemory.js +++ b/src/MacMemory.js @@ -5,86 +5,89 @@ This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ -const ref = require('ref'); -const ffi = require('ffi'); -const Struct = require('ref-struct'); +const ref = require('ref') +const ffi = require('ffi') +const Struct = require('ref-struct') let RegionInfo = Struct({ - 'protection': 'uint32', - 'max_protection': 'uint32', - 'inheritance': 'uint32', - 'shared': 'uint32', - 'reserved': 'uint32', - 'offset': 'ulonglong', - 'behavior': 'uint32', + 'protection': 'uint32', + 'max_protection': 'uint32', + 'inheritance': 'uint32', + 'shared': 'uint32', + 'reserved': 'uint32', + 'offset': 'ulonglong', + 'behavior': 'uint32', 'user_wired_count': 'ushort' -}); +}) -let RegionInfoPtr = ref.refType(RegionInfo); +let RegionInfoPtr = ref.refType(RegionInfo) -let libc = ffi.Library("libc", { - "mach_task_self": ["uint", []], - "task_for_pid": ["int", ["uint", "int", "*uint"]], - "mach_vm_region": ["int", ["uint", "*ulong", "*ulong", "int", RegionInfoPtr, "*uint32", "*uint32"]], - "mach_vm_read": ["int", ["uint", "ulonglong", "ulonglong", "*void", "*uint32"]] +let libc = ffi.Library('libc', { + 'mach_task_self': ['uint', []], + 'task_for_pid': ['int', ['uint', 'int', '*uint']], + 'mach_vm_region': ['int', ['uint', '*ulong', '*ulong', 'int', RegionInfoPtr, '*uint32', '*uint32']], + 'mach_vm_read': ['int', ['uint', 'ulonglong', 'ulonglong', '*void', '*uint32']] }) class Memory { - constructor(pid) { - let task_ref = ref.alloc("uint", 0) + constructor (pid) { + let taskRef = ref.alloc('uint', 0) let mytask = libc.mach_task_self() - let ret = libc.task_for_pid(mytask, pid, task_ref) - if (ret != 0) { - throw new Error("task_for_pid error " + ret); + let ret = libc.task_for_pid(mytask, pid, taskRef) + if (ret !== 0) { + throw new Error('task_for_pid error ' + ret) } - this.task = task_ref.deref() + this.task = taskRef.deref() } - - get_regions() { + + getRegions () { let regions = [] - let address = ref.alloc("ulong", 0) - let mapsize = ref.alloc("ulong", 0) - let name = ref.alloc("uint32", 0) - let count = ref.alloc("uint32", RegionInfo.size / 4) - let info = new RegionInfo() - + let address = ref.alloc('ulong', 0) + let mapsize = ref.alloc('ulong', 0) + let name = ref.alloc('uint32', 0) + let count = ref.alloc('uint32', RegionInfo.size / 4) + let info = new RegionInfo() + while (true) { let ret = libc.mach_vm_region(this.task, address, mapsize, 9, info.ref(), count, name) - if (ret == 1) { - break; + if (ret === 1) { + break } - if (ret != 0) { - throw new Error("mach_vm_region error " + ret) + if (ret !== 0) { + throw new Error('mach_vm_region error ' + ret) } - + regions.push([address.deref(), mapsize.deref()]) - + address.writeUInt64LE(address.deref() + mapsize.deref()) } - - return regions; + + return regions } - read(address, length) { - let detaref = ref.alloc("*void") - let cnt = ref.alloc("uint32", 0) + read (address, length) { + let detaref = ref.alloc('*void') + let cnt = ref.alloc('uint32', 0) let ret = libc.mach_vm_read(this.task, address, length, detaref, cnt) - if (ret != 0) { - throw new Error("mach_vm_read error " + ret) + if (ret !== 0) { + throw new Error('mach_vm_read error ' + ret) } return detaref.readPointer(0, length) } - read_async(address, length) { - let detaref = ref.alloc("*void") - let cnt = ref.alloc("uint32", 0) + readAsync (address, length) { + let detaref = ref.alloc('*void') + let cnt = ref.alloc('uint32', 0) return new Promise((resolve, reject) => { libc.mach_vm_read.async(this.task, address, length, detaref, cnt, (err, ret) => { - if (ret != 0) { - reject("mach_vm_read error " + ret) + if (err) { + reject(new Error('mach_vm_read error ' + err)) + } + if (ret !== 0) { + reject(new Error('mach_vm_read error ' + ret)) } resolve(detaref.readPointer(0, length)) }) @@ -92,4 +95,4 @@ class Memory { } } -module.exports = Memory \ No newline at end of file +module.exports = Memory diff --git a/src/Memory.js b/src/Memory.js index bcdc89c..5ce32f4 100644 --- a/src/Memory.js +++ b/src/Memory.js @@ -1,9 +1,9 @@ -if (process.platform == "darwin") { - module.exports = require("./MacMemory") -} else if (process.platform == "linux") { - throw new Error("not yet inplemented on linux") -} else if (process.platform == "win32") { - throw new Error("not yet inplemented on windows") +if (process.platform === 'darwin') { + module.exports = require('./MacMemory') +} else if (process.platform === 'linux') { + throw new Error('not yet inplemented on linux') +} else if (process.platform === 'win32') { + throw new Error('not yet inplemented on windows') } else { - throw new Error("not yet inplemented on your operating system") -} \ No newline at end of file + throw new Error('not yet inplemented on your operating system') +} diff --git a/src/Pid.js b/src/Pid.js index b172758..3f334af 100644 --- a/src/Pid.js +++ b/src/Pid.js @@ -5,22 +5,24 @@ This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ -module.exports = { - get_pids () { - if (process.platform == "darwin") { - return require("child_process") +class Pid { + static getPids () { + if (process.platform === 'darwin') { + return require('child_process') .execSync('ps -A') .toString() - .split("\n") - .map ( ( x ) => { return x.match(" *(\\d+)") } ) - .filter ( ( x ) => { return x != null } ) - .map ( ( x ) => { return parseInt(x[1]) } ) - } else if (process.platform == "linux") { - throw new Error("not yet inplemented on linux") - } else if (process.platform == "win32") { - throw new Error("not yet inplemented on windows") + .split('\n') + .map((x) => { return x.match(' *(\\d+)') }) + .filter((x) => { return x != null }) + .map((x) => { return parseInt(x[1]) }) + } else if (process.platform === 'linux') { + throw new Error('not yet inplemented on linux') + } else if (process.platform === 'win32') { + throw new Error('not yet inplemented on windows') } else { - throw new Error("not yet inplemented on your operating system") + throw new Error('not yet inplemented on your operating system') } } -} \ No newline at end of file +} + +module.exports = Pid diff --git a/src/ProcessSelect.js b/src/ProcessSelect.js index f9cc5fa..c8d8e2d 100644 --- a/src/ProcessSelect.js +++ b/src/ProcessSelect.js @@ -5,23 +5,23 @@ This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ -const Pid = require("./Pid") -const suji = require("./suji.json") -const Globals = require("./Globals") -const Memory = require("./Memory") +const Pid = require('./Pid') +const suji = require('./suji.json') +const Globals = require('./Globals') +const Memory = require('./Memory') let width = 90 let height = 90 -let interval_x = 150 -let interval_y = 150 +let intervalX = 150 +let intervalY = 150 let font = new THREE.Font(suji) class ProcessSelect { constructor () { - this.pids = Pid.get_pids().filter( + this.pids = Pid.getPids().filter( (x) => { try { - new Memory(x).get_regions() + new Memory(x).getRegions() return true } catch (e) { return false @@ -38,12 +38,12 @@ class ProcessSelect { // create overwrap block { - let geometry = new THREE.PlaneGeometry( width - 2, height - 2, 1, 1 ) - let material = new THREE.MeshBasicMaterial( { color: 0xff0000 } ) - let mesh = new THREE.Mesh( geometry, material ) + let geometry = new THREE.PlaneGeometry(width - 2, height - 2, 1, 1) + let material = new THREE.MeshBasicMaterial({ color: 0xff0000 }) + let mesh = new THREE.Mesh(geometry, material) mesh.visible = false mesh.position.z = 1 - Globals.scene.add( mesh ) + Globals.scene.add(mesh) this.overwrap = mesh } @@ -52,43 +52,43 @@ class ProcessSelect { this.blocks = [] this.labels = [] for (let i in this.pids) { - let x = (i % this.cols - this.cols / 2 + 0.5) * interval_x - let y = (Math.floor(i / this.cols) - Math.floor(this.pids.length / this.cols)) * interval_y + let x = (i % this.cols - this.cols / 2 + 0.5) * intervalX + let y = (Math.floor(i / this.cols) - Math.floor(this.pids.length / this.cols)) * intervalY // block { - let geometry = new THREE.PlaneGeometry( width, height, 1, 1 ) - let material = new THREE.MeshBasicMaterial( { color: 0xffffff } ) - let mesh = new THREE.Mesh( geometry, material ) + let geometry = new THREE.PlaneGeometry(width, height, 1, 1) + let material = new THREE.MeshBasicMaterial({ color: 0xffffff }) + let mesh = new THREE.Mesh(geometry, material) mesh.position.x = x mesh.position.y = y mesh.position.z = 0 - Globals.scene.add( mesh ) + Globals.scene.add(mesh) - this.blocks.push( mesh ) + this.blocks.push(mesh) } // label { - let geometry = new THREE.TextGeometry( this.pids[i].toString(), { + let geometry = new THREE.TextGeometry(this.pids[i].toString(), { font: font, size: 10 }) - let material = new THREE.MeshBasicMaterial( { color: 0x052344 } ) - let mesh = new THREE.Mesh( geometry, material ) + let material = new THREE.MeshBasicMaterial({ color: 0x052344 }) + let mesh = new THREE.Mesh(geometry, material) mesh.position.x = x - width / 2 + 5 mesh.position.y = y - height / 2 + 5 mesh.position.z = 2 - Globals.scene.add( mesh ) + Globals.scene.add(mesh) - this.labels.push( mesh ) + this.labels.push(mesh) } } } update () { - if (this.finished == true) { + if (this.finished === true) { return } @@ -119,13 +119,13 @@ class ProcessSelect { if (this.progress >= 1) { // make sure that pid is correct try { - new Memory(this.pid).get_regions() + new Memory(this.pid).getRegions() } catch (e) { this.progress = 0 return } - - // fade blocks + + // fade blocks for (let m of this.blocks) { m.material.opacity -= 0.015 m.material.transparent = true @@ -142,7 +142,6 @@ class ProcessSelect { let overwrap = this.overwrap if (index !== null) { - let mesh = this.blocks[index] overwrap.position.x = mesh.position.x @@ -150,26 +149,23 @@ class ProcessSelect { overwrap.visible = true - overwrap.geometry = new THREE.PlaneGeometry((width - 2)*this.progress, height - 2) + overwrap.geometry = new THREE.PlaneGeometry((width - 2) * this.progress, height - 2) overwrap.material.color = new THREE.Color( - 1 + (0.054 - 1)*this.progress, - 1 + (0.364 - 1)*this.progress, - 1 + (0.698 - 1)*this.progress) + 1 + (0.054 - 1) * this.progress, + 1 + (0.364 - 1) * this.progress, + 1 + (0.698 - 1) * this.progress) this.pid = this.pids[index] this.progress += 0.005 - } else { - overwrap.visible = false this.progress = 0 this.pid = undefined - } } } -module.exports = ProcessSelect \ No newline at end of file +module.exports = ProcessSelect diff --git a/src/ProcessView.js b/src/ProcessView.js index 0c6c756..1355225 100644 --- a/src/ProcessView.js +++ b/src/ProcessView.js @@ -5,23 +5,23 @@ This software is released under the MIT License. http://opensource.org/licenses/mit-license.php */ -const Memory = require("./Memory") -const Globals = require("./Globals") +const Memory = require('./Memory') +const Globals = require('./Globals') // mathematical modulo let mod = function (n, m) { - return ((n % m) + m) % m; + return ((n % m) + m) % m } // choose one element randomly from array let choice = function (arr) { - return arr[Math.floor(Math.random() * arr.length)]; + return arr[Math.floor(Math.random() * arr.length)] } let MAX_POINTS = 1600 class ProcessView { - constructor(pid) { + constructor (pid) { this.tickcount = 0 this.rows = 20 // the number of tiles / 2 this.tilesize = Math.floor(Globals.width / this.rows / 2) @@ -29,34 +29,34 @@ class ProcessView { this.mem = new Memory(pid) while (true) { - this.region = choice(this.mem.get_regions()) + this.region = choice(this.mem.getRegions()) this.world_size = this.region[1] this.world_width = this.world_height = Math.floor(Math.sqrt(this.world_size)) this.getAddress_offset_x = Math.floor(this.world_width / 2) this.getAddress_offset_y = Math.floor(this.world_height / 2) - - let sum = 0; + + let sum = 0 for (let i = 0; i < 10; i++) { for (let j = 0; j < 10; j++) { - sum += this.getByteSync(i,j); + sum += this.getByteSync(i, j) } } if (sum > 1000) { - break; + break } } this.world_geometry = new THREE.BufferGeometry() - this.world_geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( MAX_POINTS * 3 ), 3 ) ) - this.world_geometry.addAttribute( 'color' , new THREE.BufferAttribute( new Float32Array( MAX_POINTS * 3 ), 3 ) ) + this.world_geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(MAX_POINTS * 3), 3)) + this.world_geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(MAX_POINTS * 3), 3)) - this.world_material = new THREE.PointsMaterial( { vertexColors: true, size: Math.floor(this.tilesize*0.90), sizeAttenuation: false } ) - this.world_points = new THREE.Points( this.world_geometry, this.world_material ) - Globals.scene.add( this.world_points ) + this.world_material = new THREE.PointsMaterial({ vertexColors: true, size: Math.floor(this.tilesize * 0.90), sizeAttenuation: false }) + this.world_points = new THREE.Points(this.world_geometry, this.world_material) + Globals.scene.add(this.world_points) } - getAddress(x, y) { + getAddress (x, y) { x += this.getAddress_offset_x y += this.getAddress_offset_y x = mod(x, this.world_width) @@ -64,7 +64,7 @@ class ProcessView { return this.region[0] + x + y * this.world_width } - getByteSync(x, y) { + getByteSync (x, y) { try { return this.mem.read(this.getAddress(x, y), 1)[0] } catch (e) { @@ -80,9 +80,11 @@ class ProcessView { this.world_points.position.y = cy * this.tilesize let position = this.world_geometry.attributes.position.array - let array = this.world_geometry.attributes.color.array + let array = this.world_geometry.attributes.color.array - let pos_index = 0, col_index = 0, vert_index = 0 + let posIndex = 0 + let colIndex = 0 + let vertIndex = 0 for (let i = -this.rows; i < this.rows + 2; i++) { for (let j = -this.rows; j < this.rows; j++) { @@ -92,25 +94,25 @@ class ProcessView { let col = this.getByteSync(x, y) / 255 if (col != 0) { - position[pos_index++] = i * this.tilesize - position[pos_index++] = j * this.tilesize - position[pos_index++] = 0 + position[posIndex++] = i * this.tilesize + position[posIndex++] = j * this.tilesize + position[posIndex++] = 0 - array[col_index++] = col - array[col_index++] = col - array[col_index++] = col + array[colIndex++] = col + array[colIndex++] = col + array[colIndex++] = col - vert_index++ + vertIndex++ } } } this.world_geometry.attributes.position.needsUpdate = true - this.world_geometry.attributes.color .needsUpdate = true - this.world_geometry.setDrawRange( 0, vert_index ) + this.world_geometry.attributes.color.needsUpdate = true + this.world_geometry.setDrawRange(0, vertIndex) this.tickcount++ } } -module.exports = ProcessView \ No newline at end of file +module.exports = ProcessView