123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- try:
- from cStringIO import StringIO
- except ImportError:
- from io import StringIO
- import traceback, errno, string, re, sys, time, readelf;
- def GetLoadSymbolCommand(EnclaveFile, Base):
- text = readelf.ReadElf(EnclaveFile)
- if text == None:
- return -1
- SegsFile = StringIO(text)
- try:
- FileList = SegsFile.readlines()
- n=4;
- m=100;
- Out = [[[] for ni in range(n)] for mi in range(m)]
- i=0;
- Out[99][2] = '0';
-
-
- for line in FileList:
- list = line.split();
- if(len(list) > 0):
- SegOffset = -1;
-
-
-
- if(re.match('\[\s*[0-9]+\]',list[0])):
- SegOffset = 0;
- if(re.match('\s*[0-9]+\]',list[1])):
- SegOffset = 1;
- if(SegOffset != -1):
- if (list[SegOffset+1][0] == '.'):
-
-
-
- if(list[SegOffset+1].find(".text") != -1):
- Out[99][0] = "-s";
- Out[99][1] = list[SegOffset+1];
- Out[99][2] = str(int(list[SegOffset+3], 16) + int(Base, 10));
- Out[99][3] = " ";
- elif(int(list[SegOffset+3], 16) != 0):
- Out[i][0] = "-s";
- Out[i][1] = list[SegOffset+1];
- Out[i][2] = str(int(list[SegOffset+3], 16) + int(Base, 10));
- Out[i][3] = " ";
- i = i+1;
- if('0' != Out[99][2]):
-
- Out[i-1][3] = '';
-
-
-
- gdbcmd = "add-symbol-file '" + EnclaveFile + "' " + '%(Location)#08x' % {'Location':int(Out[99][2])} + " -readnow "
- for j in range(i):
- gdbcmd += Out[j][0] + " " + Out[j][1] + " " + '%(Location)#08x' % {'Location' : int(Out[j][2])} + " " + Out[j][3]
- else:
- return -1
- return gdbcmd
- except:
- print ("Error parsing enclave file. Check format of file.")
- return -1
- def GetUnloadSymbolCommand(EnclaveFile, Base):
- text = readelf.ReadElf(EnclaveFile)
- if text == None:
- return -1
- SegsFile = StringIO(text)
- try:
- FileList = SegsFile.readlines()
-
-
- for line in FileList:
- list = line.split();
- if(len(list) > 0):
- SegOffset = -1;
-
-
-
- if(re.match('\[\s*[0-9]+\]',list[0])):
- SegOffset = 0;
- if(re.match('\s*[0-9]+\]',list[1])):
- SegOffset = 1;
- if(SegOffset != -1):
- if (list[SegOffset+1][0] == '.'):
-
- if(list[SegOffset+1].find(".text") != -1):
- return "remove-symbol-file -a " + str(int(list[SegOffset+3], 16) + int(Base, 10))
- except:
- print ("Error parsing enclave file. Check format of file.")
- return -1
|