Example #1
0
        /// <summary>
        /// Determine whether the bytes from a Patch's expected data match the contents of the ROM.
        /// </summary>
        private bool ValidateJSRHookBytes(PullJSRHookPatch patch, Stream romStream)
        {
            uint patchLength = patch.Length;
            byte[] buffer = new byte[patchLength];
            if (!this.TryReadBuffer(romStream, patch.StartAddress, buffer))
            {
                Console.Write("tryreadbuffer failed in validatebytes");
                return false;
            }

            //            DumpBuffer("Actual  ", buffer, buffer.Length);
            //            DumpBuffer("Expected", expectedData.Content, buffer.Length);

            //int mismatches = 0;

            for (int index = 0; index < patchLength; index++)
            {
                byte actual = buffer[index];

                if (!patch.MetaCheck((IEnumerable<byte>)buffer))
                {
                    Trace.WriteLine("JSR HOOK FAILED");
                    return false;
                }
            }
            Trace.WriteLine("Valid.");
            return true;
        }
Example #2
0
        /// <summary>
        /// Construct a Pull JSR HOOK patch from the metadata blob.
        /// </summary>
        private bool TrySynthesizePullJsrHookPatch(Blob metadata, out Patch patch, ref int offset, List<Blob> blobs)
        {
            uint address = 0;
            string name;

            if (!metadata.TryGetUInt32(ref address, ref offset))
            {
                throw new InvalidDataException("This patch's metadata contains an incomplete 4-byte patch record (no address).");
            }

            if (!TryReadMetaString(metadata, out name, ref offset))
            {
                Trace.WriteLine("Patch at metadata offset: " + offset + "contains invalid name."); name ="UNKNOWN PATCH";
            }

            byte[] jsrbytes = new byte[] {0xF0,0x48,0x00,0x09};

            patch = new PullJSRHookPatch(name, address, address + 3);

            patch.IsMetaChecked = true;//remove thsi

            patch.Payload = new Blob(patch.StartAddress, jsrbytes);

            //this.blobs.Add(new Blob(address, BitConverter.GetBytes(newValue).Reverse()));
            //this.blobs.Add(new Blob(address + BaselineOffset, BitConverter.GetBytes(oldValue).Reverse()));
            return true;
        }