Beispiel #1
0
 def add_name(self, name):
     name = name_to_bytes(name)
     if data_null + name + data_null in self.content:
         return self.content.find(name)
     idx = len(self.content)
     self.content[idx] = name + data_null
     for sh in self.parent.shlist:
         if sh.sh.offset > self.sh.offset:
             sh.sh.offset += len(name) + 1
     return idx
Beispiel #2
0
 def add_name(self, name):
     name = name_to_bytes(name)
     if data_null + name + data_null in self.content:
         return self.content.find(name)
     data = self.content
     if type(data) != str: data = data.pack()
     idx = len(data)
     self.content = data + name + data_null
     for sh in self.parent.shlist:
         if sh.sh.offset > self.sh.offset:
             sh.sh.offset += len(name) + 1
     return idx
Beispiel #3
0
 def mod_name(self, idx, name):
     name = name_to_bytes(name)
     n = self.content[idx:self.content.find(data_null, idx)]
     data = self.content
     if type(data) != str: data = data.pack()
     data = data[:idx] + name + data[idx + len(n):]
     dif = len(name) - len(n)
     if dif != 0:
         for sh in self.parent.shlist:
             if sh.sh.name_idx > idx:
                 sh.sh.name_idx += dif
             if sh.sh.offset > self.sh.offset:
                 sh.sh.offset += dif
     return idx
Beispiel #4
0
 def set_sectname(self, val):
     padding = self._namelen - len(val)
     if (padding < 0):
         raise ValueError("sectname is too long for the structure")
     self.pad_sectname = name_to_bytes(val) + data_null * padding