Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
args = parser.parse_args()
file_type = None
filename = args.file[0]
error = ''
try:
fe = pefile.PE(filename)
file_type = 'PE'
except Exception as e:
error = str(e)
pass
if not file_type:
try:
fe = macholib.MachO.MachO(filename)
file_type = 'MACHO'
except Exception:
error = str(e)
pass
if not file_type:
sys.stderr.write("[*] Error with %s - not a PE or Mach-O\n" % sys.argv[1])
sys.exit(1)
if file_type == 'PE':
try:
if args.sig_title and len(args.sig_title) > 0:
print "[%s]" %(args.sig_title)
if args.linker:
self.includes.add('pkg_resources')
self.eggs = pkg_resources.require(self.distribution.install_requires)
# Setuptools/distribute style namespace packages uses
# __import__('pkg_resources'), and that import isn't detected at the
# moment. Forcefully include pkg_resources.
self.includes.add('pkg_resources')
dylib_excludes = fancy_split(self.dylib_excludes)
self.dylib_excludes = []
for fn in dylib_excludes:
try:
res = macholib.dyld.framework_find(fn)
except ValueError:
try:
res = macholib.dyld.dyld_find(fn)
except ValueError:
res = fn
self.dylib_excludes.append(res)
self.resources = fancy_split(self.resources)
frameworks = fancy_split(self.frameworks)
self.frameworks = []
for fn in frameworks:
try:
res = macholib.dyld.framework_find(fn)
except ValueError:
res = macholib.dyld.dyld_find(fn)
while res in self.dylib_excludes:
self.dylib_excludes.remove(res)
self.frameworks.append(res)
if not self.plist:
self.plist = {}
print
print 'MachO Headers Eraser'
print
print 'This script may cause some unpredictable issues, try delete things in the safe list if your program doesn\'t work after patched.'
print
print '[+]Checking if patched'
rawFile = open(executableName, 'r')
rawFile.seek(-4, 2)
if cmp(rawFile.read(),'BOOM') == 0:
print '#Error: Executable has been patched'
exit()
print '[+]Making backup'
os.system('cp %s %s_bak' % (executableName, executableName))
print '[+]Reading raw executable'
machoHeader = MachO.MachO(executableName)
print '[+]%s readed' % machoHeader.filename
for header in machoHeader.headers:
eraseLoadCommandInHeader(header)
print '[+]Generating new executable'
spliceHeadersAndRawStuff(machoHeader, executableName)
print '[+]New executable generated'
print '[+]Overwriting raw executable'
os.system('mv %s_tmp %s' % (executableName, executableName))
#Insert SYMTAB Operations Here
pathname = os.path.dirname(sys.argv[0])
Command= pathname+'/SymbolCleaner '+executableName+" "+str(SYMTAB["symoff"])+" "+str(SYMTAB["nsyms"])+" 0 0 "+executableName+"NoSymbol"+" 32"
system(str(Command))
sz = '64-bit'
else:
sz = '32-bit'
print >>fp, ' [%s endian=%r size=%r arch=%r]' % (header.__class__.__name__,
header.endian, sz, ARCH_MAP[(header.endian, sz)])
for idx, name, other in header.walkRelocatables():
if other not in seen:
seen.add(other)
print >>fp, '\t' + other
if __name__ == '__main__':
try:
sys.exit(main(print_file))
except KeyboardInterrupt:
pass
self.dylib_excludes = []
for fn in dylib_excludes:
try:
res = macholib.dyld.framework_find(fn)
except ValueError:
try:
res = macholib.dyld.dyld_find(fn)
except ValueError:
res = fn
self.dylib_excludes.append(res)
self.resources = fancy_split(self.resources)
frameworks = fancy_split(self.frameworks)
self.frameworks = []
for fn in frameworks:
try:
res = macholib.dyld.framework_find(fn)
except ValueError:
res = macholib.dyld.dyld_find(fn)
while res in self.dylib_excludes:
self.dylib_excludes.remove(res)
self.frameworks.append(res)
if not self.plist:
self.plist = {}
if isinstance(self.plist, basestring):
self.plist = plistlib.Plist.fromFile(self.plist)
if isinstance(self.plist, plistlib.Dict):
self.plist = dict(self.plist.__dict__)
else:
self.plist = dict(self.plist)
self.set_undefined_options('bdist',
('dist_dir', 'dist_dir'),
# included by apptemplate
self.excludes.add('site')
if getattr(self.distribution, 'install_requires', None):
self.includes.add('pkg_resources')
self.eggs = pkg_resources.require(self.distribution.install_requires)
# Setuptools/distribute style namespace packages uses
# __import__('pkg_resources'), and that import isn't detected at the
# moment. Forcefully include pkg_resources.
self.includes.add('pkg_resources')
dylib_excludes = fancy_split(self.dylib_excludes)
self.dylib_excludes = []
for fn in dylib_excludes:
try:
res = macholib.dyld.framework_find(fn)
except ValueError:
try:
res = macholib.dyld.dyld_find(fn)
except ValueError:
res = fn
self.dylib_excludes.append(res)
self.resources = fancy_split(self.resources)
frameworks = fancy_split(self.frameworks)
self.frameworks = []
for fn in frameworks:
try:
res = macholib.dyld.framework_find(fn)
except ValueError:
res = macholib.dyld.dyld_find(fn)
while res in self.dylib_excludes:
self.dylib_excludes.remove(res)
def standaloneApp(path):
if not os.path.isdir(path) and os.path.exists(
os.path.join(path, 'Contents')):
raise SystemExit('%s: %s does not look like an app bundle'
% (sys.argv[0], path))
files = MachOStandalone(path).run()
strip_files(files)
def standaloneApp(path):
if not (os.path.isdir(path) and os.path.exists(
os.path.join(path, 'Contents'))):
print('%s: %s does not look like an app bundle'
% (sys.argv[0], path))
sys.exit(1)
files = MachOStandalone(path).run()
strip_files(files)
def standaloneApp(path):
if not (os.path.isdir(path) and os.path.exists(
os.path.join(path, 'Contents'))):
print('%s: %s does not look like an app bundle'
% (sys.argv[0], path))
sys.exit(1)
files = MachOStandalone(path).run()
strip_files(files)
def standaloneApp(path):
if not os.path.isdir(path) and os.path.exists(
os.path.join(path, 'Contents')):
raise SystemExit('%s: %s does not look like an app bundle'
% (sys.argv[0], path))
files = MachOStandalone(path).run()
strip_files(files)