diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/stage4/lib/native_ptr.js | 88 | ||||
| -rw-r--r-- | src/stage4/main.js | 40 |
2 files changed, 124 insertions, 4 deletions
diff --git a/src/stage4/lib/native_ptr.js b/src/stage4/lib/native_ptr.js index 1ae7644..e6248e1 100644 --- a/src/stage4/lib/native_ptr.js +++ b/src/stage4/lib/native_ptr.js @@ -31,6 +31,11 @@ class native_ptr { this.obj_to_buf = u32_to_u8x4; } + if (Object.getPrototypeOf(this).deref_all != undefined) { + this.size *= this.count; + p0laris_log("get lucky %d", this.size); + } + if (this.addy === undefined) { this.addy = shit_heap(this.size * this.count); } @@ -38,12 +43,11 @@ class native_ptr { deref() { var n = arguments[0]; + if (n === undefined) { n = 0; } - var buf_yahtzee = read_buf(this.addy + (n * this.size), this.size); - return this.buf_to_obj(read_buf(this.addy + (n * this.size), this.size)); } @@ -190,13 +194,89 @@ function mach_msg_header_t_obj_to_buf(obj) { return ret; } +function mach_msg_body_t_buf_to_obj(buf) { + var ret = {}; + + ret.msgh_descriptor_count = u32_to_u8x4(buf); + + return ret; +} + +function mach_msg_body_t_obj_to_buf(obj) { + var ret = u8x4_to_u32(obj.msgh_descriptor_count); + + return ret; +} + function Request_sp_buf_to_obj(buf) { -// var arr = [buf.msg] + var ret = {}; + p0laris_log("w00t %d %s", buf.length, Object.getOwnPropertyNames(Object.getPrototypeOf(buf)).toString()); + var Head_buf = buf.subarray(0, 24); + p0laris_log("w00t"); + var msgh_body_buf = buf.subarray(24, 28); + p0laris_log("w00t"); + var init_port_set_buf = buf.subarray(28); + p0laris_log("w00t"); + ret.Head = mach_msg_header_t_buf_to_obj(Head_buf); + p0laris_log("w00t"); + ret.msgh_body = mach_msg_body_t_buf_to_obj(msgh_body_buf); + p0laris_log("w00t"); + ret.init_port_set = new Array(); + + for (var i = 0; i < (buf.length - 28) / 28; i++) { + p0laris_log("%d", i); + var init_port_set_buf = buf.subarray((i * 28) + 28); + ret.init_port_set.push(mach_msg_header_t_buf_to_obj(init_port_set_buf)); + } + + return ret; +} + +function Request_sp_obj_to_buf(obj) { + var ret = new Uint8Array(this.size * this.count); + var tmp = mach_msg_header_t_obj_to_buf(obj.Head); + var begin = 0; + p0laris_log("w00t"); + var i = 0; + + begin = i; + + for (; i < 24; i++) { + ret[i] = tmp[i - begin]; + } + + p0laris_log("w00t"); + begin = i; + + var tmp = mach_msg_body_t_obj_to_buf(obj.msgh_body); + + for (; i < 28; i++) { + ret[i] = tmp[i - begin]; + } + + p0laris_log("w00t"); + begin = i; + + for (var i = 0; i < obj.init_port_set.length; i++) { + var tmp = mach_msg_ool_ports_descriptor_t_obj_to_buf(obj.init_port_set[i]); + for (var j = 0; j < tmp.length; j++) { + ret[begin + (i * 12) + j] = tmp[j]; + } + } + p0laris_log("w00t"); + return ret; } var mach_msg_header_t = native_ptr_type(24, mach_msg_header_t_buf_to_obj, mach_msg_header_t_obj_to_buf); +var mach_msg_body_t = native_ptr_type(4, + mach_msg_body_t_buf_to_obj, + mach_msg_body_t_obj_to_buf); var mach_msg_ool_ports_descriptor_t = native_ptr_type(12, mach_msg_ool_ports_descriptor_t_buf_to_obj, - mach_msg_ool_ports_descriptor_t_obj_to_buf);
\ No newline at end of file + mach_msg_ool_ports_descriptor_t_obj_to_buf); +var Request_sp = native_ptr_type(24 + 4 + 12, + Request_sp_buf_to_obj, + Request_sp_obj_to_buf); +Request_sp.prototype.deref_all = true;
\ No newline at end of file diff --git a/src/stage4/main.js b/src/stage4/main.js index ce470f9..541dc44 100644 --- a/src/stage4/main.js +++ b/src/stage4/main.js @@ -82,6 +82,46 @@ function main() { Head.write(Head_obj); p0laris_log("%s", JSON.stringify(Head.deref())); + p0laris_log("here"); + + var req = new Request_sp(4); + p0laris_log("here"); + var addy = req.addy; + p0laris_log("here"); + var req_obj = req.deref(); + p0laris_log("here"); + + req_obj.msgh_body.msgh_descriptor_count = 4; + p0laris_log("here"); + for (var i = 0; i < 4; i++) { + req_obj.init_port_set[i].address = 0x1234; + req_obj.init_port_set[i].count = 0x1235; + req_obj.init_port_set[i].disposition = 19; + req_obj.init_port_set[i].deallocate = false; + req_obj.init_port_set[i].type = MACH_MSG_OOL_PORTS_DESCRIPTOR; + } + + p0laris_log("here"); + req_obj.Head.msgh_bits = MACH_MSGH_BITS_COMPLEX | MACH_MSGH_BITS(19, MACH_MSG_TYPE_MAKE_SEND_ONCE); + p0laris_log("here"); + req_obj.Head.msgh_remote_port = 0x41424344; + p0laris_log("here"); + req_obj.Head.msgh_local_port = 0x45464748; + p0laris_log("here"); + req_obj.Head.msgh_id = 1337; + + p0laris_log("here"); + req.write(req_obj); + p0laris_log("here"); + p0laris_log("%s", JSON.stringify(req.deref(), function (key, value) { + if (typeof value === 'number') { + return "0x" + value.toString(16); + } + + return value; + }, "\t")); + p0laris_log("here"); + // var tfp0 = get_kernel_task(); syslog(LOG_SYSLOG, "__p0laris_LOG_END__"); |
