summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/stage4/lib/native_ptr.js56
-rw-r--r--src/stage4/main.js31
2 files changed, 55 insertions, 32 deletions
diff --git a/src/stage4/lib/native_ptr.js b/src/stage4/lib/native_ptr.js
index 8c11306..47d23ca 100644
--- a/src/stage4/lib/native_ptr.js
+++ b/src/stage4/lib/native_ptr.js
@@ -1,28 +1,24 @@
class native_ptr {
// constructor(addy, size = 4, buf_to_obj = u8x4_to_u32) {
constructor() {
- this.addy = arguments[0];
+ this.addy = arguments[1];
+ this.count = arguments[0];
var our_proto = Object.getPrototypeOf(this);
p0laris_log(JSON.stringify(Object.getPrototypeOf(this)));
if (our_proto.predef == true) {
- p0laris_log("lol");
this.size = our_proto.size;
this.buf_to_obj = our_proto.buf_to_obj;
this.obj_to_buf = our_proto.obj_to_buf;
} else {
- this.size = arguments[1];
- this.buf_to_obj = arguments[2];
- this.obj_to_buf = arguments[3];
+ this.size = arguments[2];
+ this.buf_to_obj = arguments[3];
+ this.obj_to_buf = arguments[4];
}
- if (this.addy === undefined) {
- this.addy = shit_heap(this.size);
- }
-
- if (our_proto.predef == true) {
- return;
+ if (this.count === undefined) {
+ this.count = 1;
}
if (this.size === undefined) {
@@ -32,9 +28,14 @@ class native_ptr {
if (this.buf_to_obj === undefined) {
this.buf_to_obj = u8x4_to_u32;
}
+
if (this.obj_to_buf === undefined) {
this.obj_to_buf = u32_to_u8x4;
}
+
+ if (this.addy === undefined) {
+ this.addy = shit_heap(this.size * this.count);
+ }
}
deref() {
@@ -94,6 +95,37 @@ function mach_msg_ool_ports_descriptor_t_buf_to_obj(buf) {
return ret;
}
+function mach_msg_ool_ports_descriptor_t_obj_to_buf(obj) {
+ var ret = new Uint8Array(12);
+ var tmp;
+
+ tmp = u32_to_u8x4(obj.address);
+
+ ret[0] = tmp[0];
+ ret[1] = tmp[1];
+ ret[2] = tmp[2];
+ ret[3] = tmp[3];
+
+ tmp = u32_to_u8x4(obj.count);
+
+ ret[0 + 4] = tmp[0];
+ ret[1 + 4] = tmp[1];
+ ret[2 + 4] = tmp[2];
+ ret[3 + 4] = tmp[3];
+
+ if (typeof obj.deallocate === 'boolean') {
+ ret[8] = obj.deallocate ? 1 : 0;
+ } else {
+ ret[8] = obj.deallocate;
+ }
+
+ ret[9] = obj.copy;
+ ret[10] = obj.disposition;
+ ret[11] = obj.type;
+
+ return ret;
+}
+
var mach_msg_ool_ports_descriptor_t = native_ptr_type(12,
mach_msg_ool_ports_descriptor_t_buf_to_obj,
- function(){}); \ No newline at end of file
+ mach_msg_ool_ports_descriptor_t_obj_to_buf); \ No newline at end of file
diff --git a/src/stage4/main.js b/src/stage4/main.js
index 1420246..d04e4f2 100644
--- a/src/stage4/main.js
+++ b/src/stage4/main.js
@@ -55,26 +55,17 @@ function main() {
sym_cache["JSContextGetGlobalObject"] = JSContextGetGlobalObject + dyld_shc_slide;
prep_shit();
- var np = new native_ptr(UNSLID_BASE + (get_our_slide() << 12));
- var native_ptr_u16 = native_ptr_type(2, u8x2_to_u16, u16_to_u8x2);
- var native_ptr_u32 = native_ptr_type(4, u8x4_to_u32, u32_to_u8x4);
- var native_ptr_u16_2 = native_ptr_type(2, u8x2_to_u16, u16_to_u8x2);
-
- var np1 = new native_ptr_u16(UNSLID_BASE + (get_our_slide() << 12));
- var np2 = new native_ptr_u32(UNSLID_BASE + (get_our_slide() << 12));
- var np3 = new native_ptr_u16_2(UNSLID_BASE + (get_our_slide() << 12));
-
- var np4 = new mach_msg_ool_ports_descriptor_t();
- var addy = np4.addy;
- write_u32(addy, 0x41414141);
- write_u32(addy + 4, 0x42424242);
- write_u32(addy + 8, ((19 << 16) + (MACH_MSG_OOL_PORTS_DESCRIPTOR << 24)));
- p0laris_log("%s", JSON.stringify(np4.deref()));
-
-// p0laris_log("%s", Proxy.toString());
- p0laris_log("%x %x %x %x", np1.deref(), np2.deref(), np3.deref());
-
-// reboot();
+ var init_port_set = new mach_msg_ool_ports_descriptor_t();
+ var addy = init_port_set.addy;
+ var init_port_set_obj = init_port_set.deref();
+ init_port_set_obj.address = 0x41414141;
+ init_port_set_obj.count = 0x42424242;
+ init_port_set_obj.disposition = 19;
+ init_port_set_obj.deallocate = false;
+ init_port_set_obj.type = MACH_MSG_OOL_PORTS_DESCRIPTOR;
+ p0laris_log("%x", addy);
+ init_port_set.write(init_port_set_obj);
+ p0laris_log("%s", JSON.stringify(init_port_set.deref()));
// var tfp0 = get_kernel_task();