예제 #1
0
 public void WriteStrings(StreamFunctionAdd sfa)
 {
     sfa.PositionStream = (long)this.offsetStrings;
     sfa.LengthStream   = (long)this.offsetStrings;
     for (int index = 0; index < this.str.Count; ++index)
     {
         this.str[index].WriteData(sfa);
         if (index > 0)
         {
             uint num1 = this.str[index].offset - this.offsetStrings;
             sfa.PositionStream = (long)(this.str[index].myOffset - 1U);
             if (num1 < 0x10)
             {
                 byte num2 = (byte)(0x10 + num1);
                 sfa.WriteByte(num2);
                 sfa.WriteByte((byte)0);
             }
             else if (num1 < 0x1000)
             {
                 byte num2 = (byte)(0x50 + (num1 >> 8));
                 sfa.WriteByte(num2);
                 byte num3 = (byte)(num1 & (uint)byte.MaxValue);
                 sfa.WriteUInt16((ushort)num3);
             }
             else if (num1 > 0xFFF)
             {
                 sfa.WriteByte(0x90);
                 sfa.WriteUInt16((ushort)num1);
             }
             sfa.PositionStream = sfa.LengthStream;
         }
     }
     sfa.SeekValueWrite(2U);
 }
예제 #2
0
 public void WriteData(StreamFunctionAdd sfa)
 {
     if (typeOffset == OffsetType.LargeOffset && sfa.PositionStream - baseOffset < 4095L)
     {
         while (sfa.PositionStream - baseOffset < 4095L)
         {
             sfa.WriteByte(0);
         }
     }
     offset = (uint)sfa.PositionStream;
     sfa.WriteBytes(data.ToArray());
 }
예제 #3
0
 public void WriteData(StreamFunctionAdd sfa)
 {
     if (this.typeOffset == (byte)3 && sfa.PositionStream - (long)this.baseOffset < 4095L)
     {
         while (sfa.PositionStream - (long)this.baseOffset < 4095L)
         {
             sfa.WriteByte((byte)0);
         }
     }
     this.offset = (uint)sfa.PositionStream;
     sfa.WriteBytes(this.data.ToArray());
 }
예제 #4
0
        private static void AddBytes(string fileName, string[] args)
        {
            int result = 0;

            Console.ForegroundColor = ConsoleColor.Red;
            for (int index = 0; index < args.Length; ++index)
            {
                if (args[index] == "-as")
                {
                    Console.WriteLine(" -Activate add bytes to start.");
                    int.TryParse(args[index + 1], out result);
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            StreamFunctionAdd streamFunctionAdd1 = new StreamFunctionAdd();
            StreamFunctionAdd streamFunctionAdd2 = new StreamFunctionAdd(fileName);

            if (flag2)
            {
                streamFunctionAdd2.PositionStream = streamFunctionAdd2.LengthStream;
                streamFunctionAdd2.SeekValueWrite(16U);
            }
            if (!flag1)
            {
                return;
            }
            StreamFunctionAdd destination = new StreamFunctionAdd();

            for (int index = 0; index < result; ++index)
            {
                destination.WriteByte((byte)0);
            }
            streamFunctionAdd2.PositionStream = 0L;
            streamFunctionAdd2.CopyPartTo(destination, (int)streamFunctionAdd2.LengthStream);
            streamFunctionAdd2.Dispose();
            destination.SaveToFile(fileName);
        }
예제 #5
0
        public void WriteStrings(StreamFunctionAdd sfa, bool dedup = false)
        {
            sfa.PositionStream = offsetStrings;
            sfa.LengthStream   = offsetStrings;
            List <int> failedMediumStrings = new List <int>();
            List <int> failedShortStrings  = new List <int>();
            uint       lastShortLength     = 0;
            uint       lastMediumLength    = 0;
            long       realPos             = 0;
            bool       matched             = false;

            for (int index = 0; index < fileStrings.Count; ++index)
            {
                if (dedup)
                {
                    for (int index1 = index - 1; index1 >= 0; --index1)
                    {
                        if (index == 0)
                        {
                            break;
                        }
                        if (fileStrings[index].data.Count == fileStrings[index1].data.Count)
                        {
                            if (System.Linq.Enumerable.SequenceEqual(fileStrings[index].data, fileStrings[index1].data))
                            {
                                realPos = sfa.PositionStream;
                                fileStrings[index].offset = fileStrings[index1].offset;
                                matched = true;
                                break;
                            }
                        }
                    }

                    if (!matched)
                    {
                        fileStrings[index].WriteData(sfa);
                    }
                }
                else
                {
                    fileStrings[index].WriteData(sfa);
                }

                if (index > 0)
                {
                    uint num1 = fileStrings[index].offset - offsetStrings;
                    sfa.PositionStream = fileStrings[index].myOffset - 1U;
                    if (num1 < 0x10 && fileStrings[index].typeOffset == sceStrings.OffsetType.ShortOffset)
                    {
                        byte num2 = (byte)(0x10 + num1);
                        sfa.WriteByte(num2);
                        sfa.WriteByte(0);
                    }
                    else if (num1 < 0x1000 && fileStrings[index].typeOffset == sceStrings.OffsetType.MediumOffset)
                    {
                        byte num2 = (byte)(0x50 + (num1 >> 8));
                        sfa.WriteByte(num2);
                        byte num3 = (byte)(num1 & byte.MaxValue);
                        sfa.WriteUInt16(num3);
                    }
                    else if (num1 < 0x10000 && fileStrings[index].typeOffset == sceStrings.OffsetType.LargeOffset)
                    {
                        sfa.WriteByte(0x90);
                        sfa.WriteUInt16((ushort)num1);
                    }
                    else
                    {
                        Console.OutputEncoding = System.Text.Encoding.UTF8;
                        if (Program.verbose)
                        {
                            MiscUtils.Warn("Can't fit desired pointer in the available space...");
                            MiscUtils.Warn("- Failed at block: " + index + ", around line " + lineNumberList[index]);
                            MiscUtils.Warn("- String: " + plainStringList[index]);
                            //MiscUtils.Warn("- Intended offset: " + num1);
                            MiscUtils.Warn(string.Format("- Position: 0x{0:X6}", fileStrings[index].offset));
                            MiscUtils.Warn("- Pointer type: " + fileStrings[index].typeOffset);
                            MiscUtils.Warn("Continuing insertion, but leaving pointer unchanged, expect text errors!");
                            Console.WriteLine();
                            //Console.ReadKey();
                            //throw new InvalidOperationException();
                        }

                        if (fileStrings[index].typeOffset == sceStrings.OffsetType.MediumOffset)
                        {
                            failedMediumStrings.Add(index);
                            lastMediumLength = num1;
                        }
                        else
                        {
                            failedShortStrings.Add(index);
                            lastShortLength = num1;
                        }
                    }

                    if (matched)
                    {
                        sfa.PositionStream = realPos;
                        matched            = false;
                        continue;
                    }
                    sfa.PositionStream = sfa.LengthStream;
                }
            }

            if (failedShortStrings.Count != 0 || failedMediumStrings.Count != 0)
            {
                MiscUtils.Warn("Couldn't insert all lines due to pointer size issues");
                MiscUtils.Warn("Inserted the other lines, but left the faulty ones untouched, expect text errors!");
                Console.WriteLine();

                if (failedShortStrings.Count != 0)
                {
                    MiscUtils.Info("Found " + failedShortStrings.Count + " strings over the 16 line");
                    MiscUtils.Info("Remove " + (lastShortLength - 16) + " bytes before line "
                                   + lineNumberList[failedShortStrings[0]] + " to get them back to a valid position");
                    MiscUtils.Info("Line " + lineNumberList[failedShortStrings[0]] + " for reference:");
                    MiscUtils.Info("\"" + plainStringList[failedShortStrings[0]] + "\"");
                    Console.WriteLine();
                }

                if (failedMediumStrings.Count != 0)
                {
                    MiscUtils.Info("Found " + failedMediumStrings.Count + " strings over the 4096 line");
                    MiscUtils.Info("Remove " + (lastMediumLength - 4096) + " bytes before line "
                                   + lineNumberList[failedMediumStrings[0]] + " to get them back to a valid position");
                    MiscUtils.Info("Line " + lineNumberList[failedMediumStrings[0]] + " for reference:");
                    MiscUtils.Info("\"" + plainStringList[failedMediumStrings[0]] + "\"");
                    Console.WriteLine();
                }
            }

            sfa.SeekValueWrite(2U);
        }