Created
November 9, 2013 17:48
-
-
Save schcriher/7387907 to your computer and use it in GitHub Desktop.
Parche para al archivo "nppdf.so"
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
#!/usr/bin/env python3 | |
#-*- coding: utf-8 -*- | |
# | |
# Copyright (C) 2013 Cristian Hernán Schmidt <[email protected]> | |
# | |
# delete_nppdf32Log.py is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# delete_nppdf32Log.py is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with delete_nppdf32Log.py. If not, see <http://www.gnu.org/licenses/>. | |
r""" | |
Parche para al archivo "nppdf.so" del paquete "mozilla-acroread" (Debian) | |
para que no genere en el home el archivo 'C:\nppdf32Log\debuglog.txt', | |
la información de este archivo es redireccionada a /dev/null | |
Inspiración: | |
https://bugs.launchpad.net/ubuntu/+source/acroread/+bug/986841/comments/21 | |
""" | |
import os | |
import sys | |
import mmap | |
from subprocess import PIPE, Popen | |
if os.geteuid() != 0: | |
raise RuntimeError('Se necesitan privilegios de root') | |
flog = r"C:\nppdf32Log\debuglog.txt" | |
find = r"find {} -name '{}' -type f -print0" | |
find_l = find.format('/lib /usr/lib /usr/local/lib', 'nppdf.so') | |
find_f = find.format('/home -maxdepth 4', flog.replace('\\', '\\\\')) | |
backup = "/root/backup.nppdf.so" | |
target = flog.encode() | |
replacement = b"/dev/null" | |
nfill = len(target) - len(replacement) | |
if nfill >= 0: | |
replacement += b'\0' * nfill | |
else: | |
raise RuntimeError('len(replacement) <= len(target) (¡modificó el script!)') | |
if not os.path.isdir(backup): | |
os.makedirs(backup) | |
print('Comenzando busqueda...') | |
libs, err = Popen(find_l, stdout=PIPE, stderr=PIPE, shell=True).communicate() | |
if err: | |
raise OSError(err) | |
elif libs: | |
for lib in libs.decode().split('\0'): | |
if os.path.isfile(lib): | |
sys.stdout.write(' {}'.format(lib)) | |
sys.stdout.flush() | |
with open(lib, 'r+') as f: | |
code = mmap.mmap(f.fileno(), 0) | |
offset = code.find(target) | |
if offset != -1: | |
_lib = os.path.join(backup, lib.replace('/', '|')) | |
os.system('cp "{}" "{}"'.format(lib, _lib)) | |
code[offset:offset+len(target)] = replacement | |
sys.stdout.write(' INSULTO ARREGLADO\n') | |
sys.stdout.write(' BACKUP: {} -> {}\n'.format(lib, _lib)) | |
elif code.find(replacement) != -1: | |
sys.stdout.write(' YA FUE ARREGLADO\n') | |
else: | |
sys.stdout.write(' NADA QUE HACER\n') | |
sys.stdout.flush() | |
else: | |
print("No se encontró la libreria 'nppdf.so' en su sistema") | |
print('Comenzando limpieza...') | |
files, err = Popen(find_f, stdout=PIPE, stderr=PIPE, shell=True).communicate() | |
if err: | |
raise OSError(err) | |
elif files: | |
for file in files.decode().split('\0'): | |
if os.path.isfile(file): | |
os.remove(file) | |
print(' {} ELIMINADO'.format(file)) | |
print("Parche aplicado y /home limpio.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment