use of com.google.security.zynamics.reil.translators.IInstructionTranslator in project binnavi by google.
the class TranslatorARM method translate.
/**
* Translates an ARM or THUMB instruction to REIL code
*
* @param environment A valid translation environment
* @param instruction The ARM or THUMB instruction to translate
*
* @return The list of REIL instruction the ARM instruction was translated to
*
* @throws InternalTranslationException An internal translation error occurred
* @throws IllegalArgumentException Any of the arguments passed to the function are invalid
*
*/
@Override
public List<ReilInstruction> translate(final ITranslationEnvironment environment, final InstructionType instruction, final List<ITranslationExtension<InstructionType>> extensions) throws InternalTranslationException {
Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
Preconditions.checkNotNull(instruction, "Error: Argument instruction can't be null");
final String mnemonic = instruction.getMnemonic();
final long instLength = instruction.getLength();
// TODO: >= 4 is a workaround because IDA merges multiple instructions into 1
final String normalizedMnemonic = instLength >= 4 ? mnemonic : "THUMB" + mnemonic;
final IInstructionTranslator translator = translators.get(normalizedMnemonic);
if (translators.containsKey(normalizedMnemonic)) {
final ArrayList<ReilInstruction> instructions = new ArrayList<ReilInstruction>();
translator.translate(environment, instruction, instructions);
return instructions;
} else if (mnemonic == null) {
return new ArrayList<ReilInstruction>();
} else {
return Lists.newArrayList(ReilHelpers.createUnknown(ReilHelpers.toReilAddress(instruction.getAddress()).toLong()));
}
}
use of com.google.security.zynamics.reil.translators.IInstructionTranslator in project binnavi by google.
the class TranslatorMIPS method translate.
/**
* Translates a MIPS instruction to REIL code
*
* @param environment A valid translation environment
* @param instruction The MIPS instruction to translate
*
* @return The list of REIL instruction the MIPS instruction was translated to
*
* @throws InternalTranslationException An internal translation error occurred
* @throws IllegalArgumentException Any of the arguments passed to the function are invalid
*
*/
@Override
public List<ReilInstruction> translate(final ITranslationEnvironment environment, final InstructionType instruction, final List<ITranslationExtension<InstructionType>> extensions) throws InternalTranslationException {
Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
Preconditions.checkNotNull(instruction, "Error: Argument instruction can't be null");
final String mnemonic = instruction.getMnemonic();
// final long instLength = instruction.getLength();
if (mnemonic == null) {
return new ArrayList<ReilInstruction>();
}
final IInstructionTranslator translator = translators.get(mnemonic.toLowerCase());
if (translators.containsKey(mnemonic.toLowerCase())) {
final ArrayList<ReilInstruction> instructions = new ArrayList<ReilInstruction>();
translator.translate(environment, instruction, instructions);
for (final ITranslationExtension<InstructionType> extension : extensions) {
extension.postProcess(environment, instruction, instructions);
}
return instructions;
} else {
return Lists.newArrayList(ReilHelpers.createUnknown(ReilHelpers.toReilAddress(instruction.getAddress()).toLong()));
}
}
use of com.google.security.zynamics.reil.translators.IInstructionTranslator in project binnavi by google.
the class TranslatorX86 method translate.
/**
* Translates an x86 instruction to REIL code
*
* @param environment A valid translation environment
* @param instruction The x86 instruction to translate
*
* @return The list of REIL instruction the x86 instruction was translated to
*
* @throws InternalTranslationException An internal translation error occured
* @throws IllegalArgumentException Any of the arguments passed to the function are invalid
*
*/
@Override
public List<ReilInstruction> translate(final ITranslationEnvironment environment, final InstructionType instruction, final List<ITranslationExtension<InstructionType>> extensions) throws InternalTranslationException {
Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
Preconditions.checkNotNull(instruction, "Error: Argument instruction can't be null");
final String mnemonic = instruction.getMnemonic();
if (translators.containsKey(mnemonic)) {
final IInstructionTranslator translator = translators.get(mnemonic);
final ArrayList<ReilInstruction> instructions = new ArrayList<ReilInstruction>();
translator.translate(environment, instruction, instructions);
for (final ITranslationExtension<InstructionType> extension : extensions) {
extension.postProcess(environment, instruction, instructions);
}
return instructions;
} else if (mnemonic == null) {
return new ArrayList<ReilInstruction>();
} else {
System.out.println("Unknown mnemonic: " + mnemonic);
return Lists.newArrayList(ReilHelpers.createUnknown(ReilHelpers.toReilAddress(instruction.getAddress()).toLong()));
}
}
use of com.google.security.zynamics.reil.translators.IInstructionTranslator in project binnavi by google.
the class TranslatorPPC method translate.
/**
* Translates an x86 instruction to REIL code
*
* @param environment A valid translation environment
* @param instruction The x86 instruction to translate
*
* @return The list of REIL instruction the x86 instruction was translated to
*
* @throws InternalTranslationException An internal translation error occured
* @throws IllegalArgumentException Any of the arguments passed to the function are invalid
*
*/
@Override
public List<ReilInstruction> translate(final ITranslationEnvironment environment, final InstructionType instruction, final List<ITranslationExtension<InstructionType>> extensions) throws InternalTranslationException {
Preconditions.checkNotNull(environment, "Error: Argument environment can't be null");
Preconditions.checkNotNull(instruction, "Error: Argument instruction can't be null");
final String mnemonic = instruction.getMnemonic();
if (translators.containsKey(mnemonic)) {
final IInstructionTranslator translator = translators.get(mnemonic);
final ArrayList<ReilInstruction> instructions = new ArrayList<ReilInstruction>();
translator.translate(environment, instruction, instructions);
for (final ITranslationExtension<InstructionType> extension : extensions) {
extension.postProcess(environment, instruction, instructions);
}
return instructions;
} else if (mnemonic == null) {
return new ArrayList<ReilInstruction>();
} else {
System.out.println("Unknown mnemonic: " + mnemonic);
return Lists.newArrayList(ReilHelpers.createUnknown(ReilHelpers.toReilAddress(instruction.getAddress()).toLong()));
}
}
Aggregations