Created
July 29, 2014 04:04
-
-
Save fffonion/ab1807ab5cb646023896 to your computer and use it in GitHub Desktop.
ELF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
import struct | |
import os | |
fuckfile = r'z:\libGame.so' | |
total = os.stat(fuckfile).st_size | |
print('totle file size is 0x%x' % total) | |
f = open(fuckfile, 'rb') | |
l1 = f.read(16) | |
l2 = f.read(16) | |
l3 = f.read(16) | |
l3 = l3[:-2] + b'\x28\x00' #e_shentsize = 0x28 | |
l4 = f.read(16) | |
l = f.read() | |
max_section_cnt, e_shnum_result, output = 0, 0, '' | |
def make_one(e_shnum): | |
_l3 = struct.pack('<I12s', (total - e_shnum * 0x28), struct.unpack('<I12s', l3)[1]) | |
#print hex(struct.unpack('<I12s', _l3)[0]) | |
_l4 = struct.pack('<H14s', e_shnum, struct.unpack('<H14s', l4)[1]) | |
print hex(struct.unpack('<H14s', _l4)[0]) | |
open(r'test.so', 'wb').write(l1 + l2 + _l3 + _l4 + l) | |
def check(): | |
p = Popen('readelf -S test.so', shell = True, stdout = PIPE, stderr = PIPE) | |
s = p.communicate() | |
return s | |
for i in range(0x16): | |
make_one(i) | |
raw_input(check()[0]) | |
# section_cnt = len(s[0].split('\n')) | |
# if section_cnt >= max_section_cnt: | |
# print('new max 0x%x' % e_shnum) | |
# max_section_cnt = section_cnt | |
# e_shnum_result = e_shnum | |
# output = s[0] | |
# print('\n'.join((str(max_section_cnt), hex(e_shnum_result), output))) | |
# print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment