Small fix
[ida.git] / process_offset.py
blob3860c1aaac276deb2115ab6ccbdb7bbf61772f99
1 import sys, string, utility
2 from process_line import extract_data
4 def process_offset(original_line, tokens, offsets):
5 uses_offset = False
7 i = 0
8 while i < len(tokens):
9 token = tokens[i]
10 if token == 'offset':
11 uses_offset = True
12 tokens = tokens[0 : i] + tokens[i + 1 : ]
13 offset_target = tokens[i]
14 try:
15 address = offsets[offset_target]
16 except KeyError:
17 print 'Error: Unable to process offset in "%s"' % original_line
18 sys.exit(1)
19 tokens[i] = '0%sh' % address
20 i += 1
22 return uses_offset, string.join(tokens)
24 def extract_offsets(lines):
25 keywords = ['proc', 'db', 'dw', 'dd']
26 offsets = {}
27 for line in lines:
28 if len(line) < 15:
29 continue
30 section, address, line = extract_data(line)
31 line = utility.shrink(line)
32 tokens = line.split(' ')
33 if len(tokens) >= 2 and tokens[1] in keywords:
34 name = tokens[0]
35 offsets[name] = address
36 print 'Parsed %d offsets' % len(offsets)
37 return offsets