Monday, 3 December 2012

ARM GDB script

GDB is not quite friendly for someone who is used to ollydbg , immunity or ida but GDB script is an amazing tool for analyse code if you know some nifty trick. For some reverse engineering job, I was lucky to have a go at it and here are a few notes for the future me:

#Saving breakpoints
define bsave
    save-breakpoints san.bp
end
#Restore breakpoints
define brestore
  source san.bp
end

#Logging stuffs to a file
define sanLog
  set logging file /var/root/san.out
  set logging on
end
#Logging without stdout
define sanLogNoSTDOUT
  set logging redirect on
  set logging file /var/root/san.out
  set logging on
end

define gothoughAllinstruction
        while(1)
        if ($pc < 0x00C25494)  #size of main code
                p/x $pc
                ni             #next instruction
        else
                n              #if the code is outside of main (import lib for ex) then get past it ASAP
        end
end

define sanMod
#       i reg r0 r1 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 sp lr pc   #print out all registers
        if ($pc == 0x00859fff)   
                printf "something meaningful here:"
                x/s $r0 #print r0 register in string form
                x/x $r1  #print r1 in hex form
        end
        thread apply 1 where   #if there are multiple thread, this would run "where"(similar to "i stacks") on thread 1(eg main thread (you can get this info by running "i threads"))
        printf "\n--------------------------------------------------\n"
end




In IDA, we can use this information to color the code and see which instruction the device goes through:
 

from idautils import *
from idc import *

def main():
#  SetColor(int("0039EAE8",16), CIC_ITEM, 0xF4A430)
  print "Color it up!"
  f = open('c:\\blah\\firstrun.out','r')
  for i in f:
    if (i[0:2] == "0x"):
      SetColor(int(i[2:10],16), CIC_ITEM, 0xF4A430)

if __name__ == '__main__':
  main()

Enable Concurrent Sessions in Windows 7 (x86)+(x64)

Nifty trick to enable multiple mstsc session on a windows 7 machine:
(HxD is best for this sort of job ;) )

x86 Hex edit

find: 
00 3B 86 20 03 00 00 0F ** ** ** **
replace: 
00 B8 00 01 00 00 90 89 86 20 03 00

find: 
FF 43 50 C7
replace: 
FF 90 50 C7

find: 
F8 74 2F 68 ** **
replace: 
F8 E9 2C 00 00 00


x64 Hex edit

find: 
8B 87 38 06 00 00 39 87 ** ** ** ** ** ** ** ** ** **
replace: 
B8 00 01 00 00 90 89 87 38 06 00 00 90 90 90 90 90 90

find: 
60 BB 01 00 00 00
replace: 
60 BB 00 00 00 00

find: 
50 00 74 18 48 8D
replace: 
50 00 EB 18 48 8D

Taken from http://www.winmatrix.com/forums/index.php?//topic/22479-enable-concurrent-sessions-in-windows-7-x86x64/