Exemplo n.º 1
0
        public void Start(bool useUsb, Action <string> consoleCallback)
        {
            string serial = "";             // Only when using USB do you need an actual 'serial' name.
            int    ret;

            if (useUsb || !string.IsNullOrEmpty(package))
            {
                Console.WriteLine("Waiting for Vita to connect...");
                ScePsmDevice?vita = null;
                for (; ;)
                {
                    ScePsmDevice[] deviceArray;
                    PSMFunctions.ListDevices(out deviceArray);
                    foreach (ScePsmDevice dev in deviceArray)
                    {
                        if (dev.online > 0)
                        {
                            vita = dev;
                            break;
                        }
                    }
                    if (vita != null)
                    {
                        break;
                    }
                }
                Guid devId = vita.Value.guid;
                serial = new string(vita.Value.deviceID, 0, 17);
                Console.WriteLine("Found Vita {0}, serial: {1}", devId, serial);
                if ((ret = PSMFunctions.Connect(devId)) < 0)
                {
                    Console.WriteLine("Error connecting to Vita: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
                this.handle = devId;

                // request version or other calls will fail
#if USE_UNITY
                string devagentver      = null;
                string hosttransportver = null;
                if ((ret = PSMFunctions.GetAgentVersion(this.handle, ref devagentver, ref hosttransportver)) != 0)
                {
                    Console.WriteLine("Error getting version: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
                Console.WriteLine("Connected agent version: {0}, transport version: {1}", devagentver, hosttransportver);
#else
                PSMFunctions.Version(this.handle);
#endif

#if USE_APP_KEY
                byte[] buffer = File.ReadAllBytes("kdev.p12");

                if ((ret = PSMFunctions.ExistAppExeKey(this.handle, DRMFunctions.ReadAccountIdFromKdevP12(buffer), "*", "np")) != 1)
                {
                    Console.WriteLine("Setting app key to: {0}", appkeypath);
                    if ((ret = PSMFunctions.SetAppExeKey(this.handle, appkeypath)) != 0)
                    {
                        Console.WriteLine("Error setting key: 0x{0:X}", ret);
                        throw new IOException("Cannot set app key.");
                    }
                }
#endif
            }

            if (!string.IsNullOrEmpty(package))
            {
                Console.WriteLine("Installing package {0} as {1}.", package, name);
                if ((ret = PSMFunctions.Install(this.handle, package, name)) != 0)
                {
                    Console.WriteLine("Error installing package: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }

                Console.WriteLine("Successfully installed package.");

                Thread.Sleep(500);
                                #if !USE_ANDROID
                if (Program.exitAfterInstall)
                {
                    Environment.Exit(0);
                }
                                #endif
            }

            if (useUsb)
            {
                callback = new PsmDeviceConsoleCallback(consoleCallback);
                Console.WriteLine("Setting console callback.");
                PSMFunctions.SetConsoleWrite(this.handle, Marshal.GetFunctionPointerForDelegate(callback));

                Console.WriteLine("Launching {0}.", name);
#if USE_UNITY
                if ((ret = PSMFunctions.LaunchUnity(this.handle, name, 0, new string[] { })) != 0)
                {
                    Console.WriteLine("Error running application: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
#else
                if ((ret = PSMFunctions.Launch(this.handle, name, true, false, false, false, "")) != 0)
                {
                    Console.WriteLine("Error running application: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
#endif
            }

            Console.WriteLine("Connecting debugger.");
            conn = getconn(serial);
            conn.EventHandler  = new ConnEventHandler();
            conn.ErrorHandler += HandleConnErrorHandler;
            conn.Connect(out reciever);

            Console.WriteLine("Waiting for app to start up...");
#if !USE_UNITY
            conn.VM_Resume();
#endif
            Thread.Sleep(2000);
            Console.WriteLine("Getting variables.");
            rootdomain = conn.RootDomain;
            corlibid   = conn.Domain_GetCorlib(rootdomain);
            assid      = conn.Domain_GetEntryAssembly(rootdomain);
            foreach (long thread in conn.VM_GetThreads())
            {
                if (conn.Thread_GetName(thread) == "")
                {
                    threadid = thread;
                }
            }
            //Console.WriteLine ("Root Domain: {0}\nCorlib: {1}\nExeAssembly: {2}\nThread: {3}", rootdomain, corlibid, assid, threadid);
            Console.WriteLine("Ready for hacking.");
        }
Exemplo n.º 2
0
        public void Start(Action <string> consoleCallback)
        {
            Console.WriteLine("Waiting for Vita to connect...");
            ScePsmDevice?vita = null;
            int          ret;

            for (; ;)
            {
                ScePsmDevice[] deviceArray;
                PSMFunctions.ListDevices(out deviceArray);
                foreach (ScePsmDevice dev in deviceArray)
                {
                    if (dev.online > 0)
                    {
                        vita = dev;
                        break;
                    }
                }
                if (vita != null)
                {
                    break;
                }
            }
            Guid   devId  = vita.Value.guid;
            string serial = new string(vita.Value.deviceID, 0, 17);

            Console.WriteLine("Found Vita {0}, serial: {1}", devId, serial);
            if ((ret = PSMFunctions.Connect(devId)) < 0)
            {
                Console.WriteLine("Error connecting to Vita: 0x{0:X}", ret);
                throw new IOException("Cannot connect to Vita.");
            }
            this.handle = devId;

            // request version or other calls will fail
            PSMFunctions.Version(this.handle);

#if USE_APP_KEY
            byte[] buffer = File.ReadAllBytes("kdev.p12");

            if ((ret = PSMFunctions.ExistAppExeKey(this.handle, DRMFunctions.ReadAccountIdFromKdevP12(buffer), "*", "np")) != 1)
            {
                Console.WriteLine("Setting app key to: {0}", appkeypath);
                if ((ret = PSMFunctions.SetAppExeKey(this.handle, appkeypath)) != 0)
                {
                    Console.WriteLine("Error setting key: 0x{0:X}", ret);
                    throw new IOException("Cannot set app key.");
                }
            }
#endif

#if !NO_INSTALL_PACKAGE
            Console.WriteLine("Installing package {0} as {1}.", package, name);
            if ((ret = PSMFunctions.Install(this.handle, package, name)) != 0)
            {
                Console.WriteLine("Error installing package: 0x{0:X}", ret);
                throw new IOException("Cannot connect to Vita.");
            }
#endif

            callback = new PsmDeviceConsoleCallback(consoleCallback);
            Console.WriteLine("Setting console callback.");
            PSMFunctions.SetConsoleWrite(this.handle, Marshal.GetFunctionPointerForDelegate(callback));

            Console.WriteLine("Launching {0}.", name);
            if ((ret = PSMFunctions.Launch(this.handle, name, true, false, false, false, "")) != 0)
            {
                Console.WriteLine("Error running application: 0x{0:X}", ret);
                throw new IOException("Cannot connect to Vita.");
            }

            Console.WriteLine("Connecting debugger.");
            string port = TransportFunctions.GetVitaPortWithSerial(serial);
            if (port == null)
            {
                Console.WriteLine("Cannot find serial port for {0}", serial);
                throw new IOException("Cannot find serial port.");
            }
            conn = new VitaConnection(port);
            conn.EventHandler  = new ConnEventHandler();
            conn.ErrorHandler += HandleConnErrorHandler;
            conn.Connect(out reciever);

            Console.WriteLine("Waiting for app to start up...");
            conn.VM_Resume();
            Thread.Sleep(5000);
            Console.WriteLine("Getting variables.");
            rootdomain = conn.RootDomain;
            corlibid   = conn.Domain_GetCorlib(rootdomain);
            assid      = conn.Domain_GetEntryAssembly(rootdomain);
            foreach (long thread in conn.VM_GetThreads())
            {
                if (conn.Thread_GetName(thread) == "")
                {
                    threadid = thread;
                }
            }
            //Console.WriteLine ("Root Domain: {0}\nCorlib: {1}\nExeAssembly: {2}\nThread: {3}", rootdomain, corlibid, assid, threadid);
            Console.WriteLine("Ready for hacking.");
        }