public override bool Apply(KamekFile file) { if (Address.IsAbsolute && Target.IsAbsolute && file.Contains(Address)) { file.WriteUInt32(Address, GenerateInstruction()); return(true); } return(false); }
public override bool Apply(KamekFile file) { // Do some reasonableness checks. // For now, we'll only work on functions ending in a blr var functionSize = file.QuerySymbolSize(Address); if (functionSize < 4) { throw new InvalidOperationException("Function too small!"); } var functionEnd = Address + (functionSize - 4); if (file.ReadUInt32(functionEnd) != 0x4E800020) { throw new InvalidOperationException("Function does not end in blr"); } // Just to be extra sure, are there any other returns in this function? for (var check = Address; check < functionEnd; check += 4) { var insn = file.ReadUInt32(check); if ((insn & 0xFC00FFFF) == 0x4C000020) { throw new InvalidOperationException("Function contains a return partway through"); } } EndAddress = functionEnd; if (EndAddress.IsAbsolute && Target.IsAbsolute && file.Contains(Address)) { file.WriteUInt32(EndAddress, GenerateInstruction()); return(true); } return(false); }