feat: add replace and remove extensions (#50)

This commit is contained in:
bogadana 2022-06-24 18:47:37 +02:00 committed by GitHub
parent 070c09cf71
commit 92ac5e4dc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,6 +23,18 @@ fun MutableMethodImplementation.addInstructions(index: Int, instructions: List<B
} }
} }
fun MutableMethodImplementation.replaceInstructions(index: Int, instructions: List<BuilderInstruction>) {
for (i in instructions.lastIndex downTo 0) {
this.replaceInstruction(index + i, instructions[i])
}
}
fun MutableMethodImplementation.removeInstructions(index: Int, count: Int) {
for (i in count downTo 0) {
this.removeInstruction(index + i)
}
}
/** /**
* Compare a method to another, considering constructors and parameters. * Compare a method to another, considering constructors and parameters.
* @param otherMethod The method to compare against. * @param otherMethod The method to compare against.
@ -66,13 +78,28 @@ internal fun Method.clone(
} }
/** /**
* Add smali instructions to the method. * Add a smali instruction to the method.
* @param index The index to insert the instructions at. * @param index The index to insert the instruction at.
* @param instruction The smali instruction to add. * @param instruction The smali instruction to add.
*/ */
fun MutableMethod.addInstruction(index: Int, instruction: String) = fun MutableMethod.addInstruction(index: Int, instruction: String) =
this.implementation!!.addInstruction(index, instruction.toInstruction(this)) this.implementation!!.addInstruction(index, instruction.toInstruction(this))
/**
* Replace a smali instruction within the method.
* @param index The index to replace the instruction at.
* @param instruction The smali instruction to place.
*/
fun MutableMethod.replaceInstruction(index: Int, instruction: String) =
this.implementation!!.replaceInstruction(index, instruction.toInstruction(this))
/**
* Remove a smali instruction within the method.
* @param index The index to delete the instruction at.
*/
fun MutableMethod.removeInstruction(index: Int) =
this.implementation!!.removeInstruction(index)
/** /**
* Add smali instructions to the method. * Add smali instructions to the method.
* @param index The index to insert the instructions at. * @param index The index to insert the instructions at.
@ -81,6 +108,22 @@ fun MutableMethod.addInstruction(index: Int, instruction: String) =
fun MutableMethod.addInstructions(index: Int, instructions: String) = fun MutableMethod.addInstructions(index: Int, instructions: String) =
this.implementation!!.addInstructions(index, instructions.toInstructions(this)) this.implementation!!.addInstructions(index, instructions.toInstructions(this))
/**
* Replace smali instructions within the method.
* @param index The index to replace the instructions at.
* @param instructions The smali instructions to place.
*/
fun MutableMethod.replaceInstructions(index: Int, instructions: String) =
this.implementation!!.replaceInstructions(index, instructions.toInstructions(this))
/**
* Remove smali instructions from the method.
* @param index The index to remove the instructions at.
* @param count The amount of instructions to remove.
*/
fun MutableMethod.removeInstructions(index: Int, count: Int) =
this.implementation!!.removeInstructions(index, count)
/** /**
* Clones the method. * Clones the method.
* @param registerCount This parameter allows you to change the register count of the method. * @param registerCount This parameter allows you to change the register count of the method.