Beispiel #1
0
        //public static void WriteHexDumpFromFile(string filename)
        //{
        //    try
        //    {
        //        File file = new File(filename);

        //        RandomAccessFile stream = new RandomAccessFile(file, "r");

        //        sbyte[] bytes = new sbyte[stream.length()];

        //        stream.read(bytes);

        //        stream.close();

        //        System.Console.WriteLine("dump of [" + file + "]");
        //        Console.WriteHexDump(bytes);
        //    }
        //    catch (Exception exc)
        //    {

        //        Console.WriteThrowable(exc);
        //    }


        //}

        /// <summary>
        /// writes bytes to file
        /// </summary>
        /// <param name="cdata"></param>
        /// <param name="p"></param>
        public static void WriteBytes(sbyte[] cdata, string filename, bool utf8)
        {
            try
            {
                File f = new File(filename);

                if (f.exists())
                {
                    f.delete();
                }

                RandomAccessFile stream = new RandomAccessFile(filename, "rw");

                if (utf8)
                {
                    stream.writeByte(0xEF);
                    stream.writeByte(0xBB);
                    stream.writeByte(0xBF);
                }

                stream.write(cdata);

                stream.close();
            }
            catch
            {
            }
        }
        private void @lock()
        {
            RandomAccessFile randomAccessFile = new RandomAccessFile(PooledBatchManager.lockFile, "rw");

            this._lock = randomAccessFile.getChannel().@lock();
            randomAccessFile.close();
        }
Beispiel #3
0
 /**
  * close the db
  *
  * @
  */
 public void close()
 {
     HeaderSip = null;    //let gc do its work
     HeaderPtr = null;
     dbBinStr  = null;
     raf.close();
 }
Beispiel #4
0
        public virtual ByteBuffer decrypt(ByteBuffer f)
        {
            if (f.capacity() == 0)
            {
                return(null);
            }

            CryptoEngine crypto = new CryptoEngine();

            sbyte[] inBuf;
            if (f.hasArray() && f.position() <= PSP_HEADER_SIZE)
            {
                inBuf = f.array();
            }
            else
            {
                int currentPosition = f.position();
                f.position(currentPosition - PSP_HEADER_SIZE);
                inBuf = new sbyte[f.remaining()];
                f.get(inBuf);
                f.position(currentPosition);
            }

            int inSize = inBuf.Length;

            sbyte[] elfBuffer = crypto.PRXEngine.DecryptAndUncompressPRX(inBuf, inSize);

            if (elfBuffer == null)
            {
                return(null);
            }

            if (CryptoEngine.ExtractEbootStatus)
            {
                try
                {
                    string ebootPath = Settings.Instance.DiscTmpDirectory;
                    System.IO.Directory.CreateDirectory(ebootPath);
                    RandomAccessFile raf = new RandomAccessFile(ebootPath + "EBOOT.BIN", "rw");
                    raf.write(elfBuffer);
                    raf.close();
                }
                catch (IOException)
                {
                    // Ignore.
                }
            }

            return(ByteBuffer.wrap(elfBuffer));
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void close() throws java.io.IOException
        public override void close()
        {
            base.close();

            if (sectorDevice != null)
            {
                sectorDevice.close();
                sectorDevice = null;
            }

            writeToc();

            tocFile.close();
            tocFile = null;

            toc = null;
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            try
            {
                RandomAccessFile inToc  = new RandomAccessFile("tmp/umdbuffer.toc", "r");
                RandomAccessFile inIso  = new RandomAccessFile("tmp/umdbuffer.iso", "r");
                RandomAccessFile outIso = new RandomAccessFile("tmp/umd.iso", "rw");

                int numSectors = inToc.readInt();
                Console.WriteLine(string.Format("numSectors={0:D}", numSectors));
                sbyte[] buffer = new sbyte[sectorLength];
                for (int i = 4; i < inToc.Length(); i += 8)
                {
                    int sectorNumber         = inToc.readInt();
                    int bufferedSectorNumber = inToc.readInt();
                    inIso.seek(bufferedSectorNumber * (long)sectorLength);
                    inIso.readFully(buffer);

                    outIso.seek(sectorNumber * (long)sectorLength);
                    outIso.write(buffer);
                }
                inToc.close();
                inIso.close();
                outIso.close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
Beispiel #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void close() throws java.io.IOException
        public virtual void close()
        {
            fileAccess.close();
            fileAccess = null;
        }
        public void TestReadWrite()
        {
            var outputRecord = new VariableLengthRecord();

            outputRecord.AppendValue(100);               // unsigned int value
                outputRecord.AppendValue(200.0F);        // float value
                outputRecord.AppendValue(300.0);         // double value
                outputRecord.AppendValue('a');           // unsigned char value
                outputRecord.AppendValue("Testing");     //string value
                outputRecord.AppendValue(true);          // boolean value

            var dateValue = new Date(31, Date.Month.DECEMBER, 2100);

            outputRecord.AppendValue(dateValue);

            var dateTimeValue = new Diary.DateTime(new Date(6, Date.Month.SEPTEMBER, 1950), 12, 15);

            outputRecord.AppendValue(dateTimeValue);

            String persistenceFilePath = String.Concat(ConfigurationManager.AppSettings["PersistenceFolderPath"], "/TestFile.txt");
            var    folder = Path.GetDirectoryName(persistenceFilePath);

            // Create the persistence directory if it doesn't exist.
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            var outputStream = new RandomAccessFile(persistenceFilePath);

            outputRecord.Serialize(outputStream);
            outputStream.close();

            var inputRecord = new VariableLengthRecord();

            using (var inputStream = new RandomAccessFile(persistenceFilePath))
            {
                Assert.IsTrue(inputRecord.Deserialize(inputStream));
                Assert.AreEqual(inputRecord.GetCount(), 8, "Count");

                int value0 = 0;
                Assert.IsTrue(inputRecord.GetValue(0, ref value0));
                Assert.AreEqual(value0, 100);

                float value1 = 0.0F;
                Assert.IsTrue(inputRecord.GetValue(1, ref value1));
                Assert.AreEqual(value1, 200.0F, 0.001F);

                double value2 = 0.0;
                Assert.IsTrue(inputRecord.GetValue(2, ref value2));
                Assert.AreEqual(value2, 300.0, 0.001);

                char value3 = ' ';
                Assert.IsTrue(inputRecord.GetValue(3, ref value3));
                Assert.AreEqual(value3, 'a');

                String value4 = "";
                Assert.IsTrue(inputRecord.GetValue(4, ref value4));
                Assert.IsTrue(value4.CompareTo("Testing") == 0);

                bool value5 = false;
                Assert.IsTrue(inputRecord.GetValue(5, ref value5));
                Assert.AreEqual(value5, true);

                var value6 = new Date();
                Assert.IsTrue(inputRecord.GetValue(6, ref value6), "Date");
                Assert.AreEqual(Helper.ToString(dateValue), Helper.ToString(value6));

                var value7 = new Diary.DateTime();
                Assert.IsTrue(inputRecord.GetValue(7, ref value7), "DateTime");
                Assert.AreEqual(Helper.ToString(dateTimeValue), Helper.ToString(value7));

                inputStream.close();
            }
        }
Beispiel #9
0
 public void Close()
 {
     _file.close();
 }
Beispiel #10
0
 public void close()
 {
     dataFile.close();
 }
Beispiel #11
0
        public static void Main(string[] args)
        {
            File fileToc1 = new File("tmp/umdbuffer1.toc");
            File fileIso1 = new File("tmp/umdbuffer1.iso");
            File fileToc2 = new File("tmp/umdbuffer2.toc");
            File fileIso2 = new File("tmp/umdbuffer2.iso");
            File fileToc  = new File("tmp/umdbuffer.toc");
            File fileIso  = new File("tmp/umdbuffer.iso");

            try
            {
                System.IO.FileStream fosToc  = new System.IO.FileStream(fileToc, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                System.IO.FileStream fosIso  = new System.IO.FileStream(fileIso, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                System.IO.FileStream fisToc1 = new System.IO.FileStream(fileToc1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.FileStream fisIso1 = new System.IO.FileStream(fileIso1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.FileStream fisToc2 = new System.IO.FileStream(fileToc2, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                DataOutput           toc     = new DataOutputStream(fosToc);
                DataOutput           iso     = new DataOutputStream(fosIso);
                DataInput            toc1    = new DataInputStream(fisToc1);
                DataInput            iso1    = new DataInputStream(fisIso1);
                DataInput            toc2    = new DataInputStream(fisToc2);
                RandomAccessFile     iso2    = new RandomAccessFile(fileIso2, "r");

                int numSectors      = toc1.readInt();
                int numSectorsMerge = toc2.readInt();
                toc.writeInt(System.Math.Max(numSectors, numSectorsMerge));

                Dictionary <int, int> tocHashMap = new Dictionary <int, int>();
                for (int i = 4; i < fileToc1.Length(); i += 8)
                {
                    int sectorNumber         = toc1.readInt();
                    int bufferedSectorNumber = toc1.readInt();
                    tocHashMap[sectorNumber] = bufferedSectorNumber;
                    toc.writeInt(sectorNumber);
                    toc.writeInt(bufferedSectorNumber);
                }

                sbyte[] buffer = new sbyte[sectorLength];
                for (int i = 0; i < fileIso1.Length(); i += buffer.Length)
                {
                    iso1.readFully(buffer);
                    iso.write(buffer);
                }

                int nextFreeBufferedSectorNumber = (int)(fileIso1.Length() / sectorLength);
                for (int i = 4; i < fileToc2.Length(); i += 8)
                {
                    int sectorNumber         = toc2.readInt();
                    int bufferedSectorNumber = toc2.readInt();
                    if (!tocHashMap.ContainsKey(sectorNumber))
                    {
                        iso2.seek(bufferedSectorNumber * (long)sectorLength);
                        iso2.readFully(buffer);
                        iso.write(buffer);

                        toc.writeInt(sectorNumber);
                        toc.writeInt(nextFreeBufferedSectorNumber);
                        tocHashMap[sectorNumber] = nextFreeBufferedSectorNumber;
                        nextFreeBufferedSectorNumber++;
                    }
                }

                fosToc.Close();
                fosIso.Close();
                fisToc1.Close();
                fisIso1.Close();
                fisToc2.Close();
                iso2.close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
Beispiel #12
0
        /**
         * make the Db file
         *
         * @param	dbFile target output file path
         * @
         */
        public void make(String dbFile)
        {
            //check and load the gloabl region
            if (globalRegionFile != null)
            {
                Console.WriteLine("+-Try to load the global region data ...");
                BufferedReader greader = new BufferedReader(new FileReader(globalRegionFile));
                String         gline   = null;
                while ((gline = greader.readLine()) != null)
                {
                    String[] p = gline.split(",");
                    if (p.Length != 5)
                    {
                        continue;
                    }

                    //push the mapping
                    globalRegionMap.put(p[2], Int32.Parse(p[0]));
                }

                greader.close();
                Console.WriteLine("|--[Ok]");
            }

            //alloc the header size
            BufferedReader   reader = new BufferedReader(new FileReader(this.ipSrcFile));
            RandomAccessFile raf    = new RandomAccessFile(dbFile, "rw");

            //init the db file
            initDbFile(raf);
            Console.WriteLine("+-Db file initialized.");

            //analysis main loop
            Console.WriteLine("+-Try to write the data blocks ... ");
            String line = null;

            while ((line = reader.readLine()) != null)
            {
                line = line.trim();
                if (line.length() == 0)
                {
                    continue;
                }
                if (line.charAt(0) == '#')
                {
                    continue;
                }

                //1. get the start ip
                int sIdx = 0, eIdx = 0;
                if ((eIdx = line.indexOf('|', sIdx + 1)) == -1)
                {
                    continue;
                }
                String startIp = line.substring(sIdx, eIdx);

                //2. get the end ip
                sIdx = eIdx + 1;
                if ((eIdx = line.indexOf('|', sIdx + 1)) == -1)
                {
                    continue;
                }
                String endIp = line.substring(sIdx, eIdx);

                //3. get the region
                sIdx = eIdx + 1;
                String region = line.substring(sIdx);

                Console.WriteLine("+-Try to process item " + line);
                addDataBlock(raf, startIp, endIp, region);
                Console.WriteLine("|--[Ok]");
            }
            Console.WriteLine("|--Data block flushed!");
            Console.WriteLine("|--Data file pointer: " + raf.getFilePointer() + "\n");

            //write the index bytes
            Console.WriteLine("+-Try to write index blocks ... ");

            //record the start block
            IndexBlock  indexBlock = null;
            HeaderBlock hb         = null;

            indexBlock = indexPool.getFirst();
            long indexStartIp = indexBlock.getStartIp(),
                 indexStratPtr = raf.getFilePointer(), indexEndPtr;

            headerPool.add(new HeaderBlock(indexStartIp, (int)(indexStratPtr)));

            int blockLength = IndexBlock.getIndexBlockLength();
            int counter = 0, shotCounter = (dbConfig.getIndexBlockSize() / blockLength) - 1;

            //var indexIt = indexPool.iterator();
            //while (indexIt.hasNext())
            foreach (var indexIt in indexPool.iterator())
            {
                indexBlock = indexIt;
                if (++counter >= shotCounter)
                {
                    hb = new HeaderBlock(
                        indexBlock.getStartIp(),
                        (int)raf.getFilePointer()
                        );

                    headerPool.add(hb);
                    counter = 0;
                }

                //write the buffer
                raf.write(indexBlock.getBytes());
            }

            //record the end block
            if (counter > 0)
            {
                indexBlock = indexPool.getLast();
                hb         = new HeaderBlock(
                    indexBlock.getStartIp(),
                    ((int)raf.getFilePointer()) - IndexBlock.getIndexBlockLength()
                    );

                headerPool.add(hb);
            }

            indexEndPtr = raf.getFilePointer();
            Console.WriteLine("|--[Ok]");

            //write the super blocks
            Console.WriteLine("+-Try to write the super blocks ... ");
            raf.seek(0L);   //reset the file pointer
            byte[] superBuffer = new byte[8];
            Util.writeIntLong(superBuffer, 0, indexStratPtr);
            Util.writeIntLong(superBuffer, 4, indexEndPtr - blockLength);
            raf.write(superBuffer);
            Console.WriteLine("|--[Ok]");

            //write the header blocks
            Console.WriteLine("+-Try to write the header blocks ... ");
            //var headerIt = headerPool.iterator();
            //while (headerIt.hasNext())
            //{
            //    HeaderBlock headerBlock = headerIt.next();
            //    raf.write(headerBlock.getBytes());
            //}
            foreach (var headerBlock in headerPool.iterator())
            {
                raf.write(headerBlock.getBytes());
            }

            //write the copyright and the release timestamp info
            Console.WriteLine("+-Try to write the copyright and release date info ... ");
            raf.seek(raf.length());
            //Calendar cal = Calendar.getInstance();
            //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
            String copyright = "Created by lionsoul at " + DateTime.Now.ToString("yyyy/MM/dd"); //dateFormat.format(cal.getTime());
            var    timestamp = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;

            raf.write((Int32)timestamp);   //the unix timestamp
            raf.write(copyright.getBytes());
            Console.WriteLine("|--[Ok]");

            reader.close();
            raf.close();
        }
Beispiel #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void runFile(String fileName) throws Throwable
        protected internal virtual void runFile(string fileName)
        {
            File file = new File(fileName);

            reset();

            try
            {
                RandomAccessFile raf = new RandomAccessFile(file, "r");
                try
                {
                    FileChannel roChannel = raf.Channel;
                    try
                    {
                        ByteBuffer readbuffer = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int)roChannel.size());
                        {
                            //module =
                            emulator.load(file.Path, readbuffer);
                        }
                    }
                    finally
                    {
                        roChannel.close();
                    }
                }
                finally
                {
                    raf.close();
                }
            }
            catch (FileNotFoundException)
            {
            }

            RuntimeContext.IsHomebrew = true;

            UmdIsoReader umdIsoReader = new UmdIsoReader(rootDirectory + "/input/cube.cso");

            Modules.IoFileMgrForUserModule.IsoReader = umdIsoReader;
            Modules.sceUmdUserModule.IsoReader       = umdIsoReader;
            Modules.IoFileMgrForUserModule.setfilepath(file.Parent);

            debug(string.Format("Running: {0}...", fileName));
            {
                RuntimeContext.IsHomebrew = false;

                HLEModuleManager.Instance.startModules(false);
                Modules.sceDisplayModule.UseSoftwareRenderer = true;
                {
                    emulator.RunEmu();

                    long startTime = DateTimeHelper.CurrentUnixTimeMillis();
                    while (!Emulator.pause)
                    {
                        Modules.sceDisplayModule.step();
                        if (DateTimeHelper.CurrentUnixTimeMillis() - startTime > FAIL_TIMEOUT * 1000)
                        {
                            throw (new TimeoutException());
                        }
                        Thread.Sleep(1);
                    }
                }
                HLEModuleManager.Instance.stopModules();
            }
        }