예제 #1
0
        public Int32 GetSize()
        {
            switch (Type)
            {
            case OperandType.Byte:
            case OperandType.SByte:
                return(1);

            case OperandType.UInt16:
            case OperandType.Int16:
                return(2);

            case OperandType.UInt32:
            case OperandType.Int32:
            case OperandType.InstructionOffset:
            case OperandType.BattleOffset:
                return(4);

            case OperandType.Instruction:
                return(GetValue <Instruction>().GetSize());

            case OperandType.Expression:
                return(GetValue <Expression>().GetSize());

            case OperandType.Operation:
                return(GetValue <Operation>().GetSize());

            case OperandType.String:
                return(EncodedStringUtil.GetSize(GetValue <String>()));

            case OperandType.None:
            default:
                throw new Exception();
            }
        }
예제 #2
0
        public Int32 Write(Encoding encoding, Byte[] buffer, Int32 offset)
        {
            Assert.IsNotNull(encoding, nameof(encoding));
            Assert.IsNotNull(buffer, nameof(buffer));

            switch (Type)
            {
            case OperandType.Byte:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Byte>());
                return(1);

            case OperandType.SByte:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <SByte>());
                return(1);

            case OperandType.UInt16:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <UInt16>());
                return(2);

            case OperandType.Int16:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Int16>());
                return(2);

            case OperandType.UInt32:
            case OperandType.InstructionOffset:
            case OperandType.BattleOffset:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <UInt32>());
                return(4);

            case OperandType.Int32:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Int32>());
                return(4);

            case OperandType.Instruction:
                return(GetValue <Instruction>().Write(encoding, buffer, offset));

            case OperandType.Expression:
                return(GetValue <Expression>().Write(encoding, buffer, offset));

            case OperandType.Operation:
                return(GetValue <Operation>().Write(encoding, buffer, offset));

            case OperandType.String:
                var bytes = EncodedStringUtil.GetBytes(GetValue <String>(), encoding);
                Array.Copy(bytes, 0, buffer, offset, bytes.Length);
                return(bytes.Length);

            case OperandType.None:
            default:
                throw new Exception();
            }
        }
        static void UpdateEboot(Iso9660.IsoImage iso, String ebootpath)
        {
            Assert.IsNotNull(iso, nameof(iso));
            Assert.IsValidString(ebootpath, nameof(ebootpath));

            var patches = BuildEbootPatches();
            var file    = iso.GetFile(@"PSP_GAME\SYSDIR\EBOOT.BIN");
            var buffer  = File.ReadAllBytes(ebootpath);

            foreach (var patch in patches)
            {
                if (patch.Type == BinaryPatchType.Clear)
                {
                    for (var i = 0; i != patch.Count; ++i)
                    {
                        buffer[patch.Offset + i] = 0;
                    }
                }

                if (patch.Type == BinaryPatchType.Overwrite)
                {
                    if (patch.Buffer != null)
                    {
                        Array.Copy(patch.Buffer, 0, buffer, patch.Offset, patch.Buffer.Length);
                    }

                    if (patch.Text != null)
                    {
                        var stringbytes = EncodedStringUtil.GetBytes(patch.Text, Encodings.ShiftJIS);
                        Array.Copy(stringbytes, 0, buffer, patch.Offset, stringbytes.Length);
                    }
                }
            }

            UpdateFileData(iso, file, buffer);
        }