Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <idc.idc>
- /*
- Project name: MIPS $gp reference fixer 1.1
- Author: fastman92
- Description: this script fixes $gp based offsets in MIPS executable.
- Value of $gp is assumed to be constant within executable code.
- */
- static main()
- {
- Message("Start of MIPS $gp based reference fixer by fastman92\n");
- auto seg, loc;
- auto GP_registerValue = 0x66B1F0; // Our $gp value.
- Message("========================================\n");
- seg = FirstSeg(); // Get address pointed by a first segment
- while(seg != BADADDR )
- {
- Message("----------------------------------------\n");
- loc = SegStart(seg);
- Message("Fixing $gp offsets in segment %s\n", SegName(seg));
- while(loc != BADADDR && loc < SegEnd(seg))
- {
- if(isCode(GetFlags(loc)))
- {
- auto mnem = GetMnem(loc);
- auto stillTry = 1;
- if(mnem == "addiu")
- {
- if(GetOpType(loc, 1) == o_reg && GetOpnd(loc, 1) == "$gp" && GetOpType(loc, 2) == o_imm)
- {
- OpOffEx(loc, 2, REFINFO_NOBASE, -1, GP_registerValue, 0);
- Message("Instruction 0x%X Operand %d\n", loc, 2);
- stillTry = 0;
- }
- }
- if(stillTry)
- {
- auto OpIt;
- for(OpIt = 0; OpIt <= 1; OpIt++)
- {
- auto OpType = GetOpType(loc, OpIt);
- if(OpType != o_displ)
- continue;
- auto Operand = GetOpnd(loc, OpIt);
- auto Part = substr(Operand, strlen(Operand) - 5, -1);
- if(Part != "($gp)")
- continue;
- OpOffEx(loc, OpIt, REFINFO_NOBASE, -1, GP_registerValue, 0);
- Message("Instruction 0x%X Operand %d\n", loc, OpIt);
- }
- }
- }
- loc = NextHead(loc, BADADDR);
- }
- seg = NextSeg(seg); // get address of the next segment
- }
- Message("End of MIPS $gp based reference fixer by fastman92\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement