mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 11:32:46 +01:00
* Merge #11881: Remove Python2 support1874058
Make base58 python contrib code work with python3 (Evan Klitzke)bc6fdf2
Change all python files to use Python3 (John Newbery) Pull request description: Following discussion here: https://github.com/bitcoin/bitcoin/pull/11843#issuecomment-351033742 It's easier for maintainers if all python tools/scripts support only a single version of Python. There are only a few scripts that aren't explicitly python3 at this point, so this PR changes those remaining scripts to explicitly require python3. Tree-SHA512: 5d38eef6e0fc7d8515e23a1f4c75e8b4160fd0fe23cba52a1f41689b114e54a9e503e0724829e8b41982ef98f2d113df80d9e238213b74f09ceaed0344a19e24 * Merge #12829: Python3 fixupf50975b
[contrib] fixup symbol-check.py Python3 support (John Newbery)5de2b18
[contrib] fixup security-check.py Python3 support (John Newbery) Pull request description: security-check.py and symbol-check.py were broken by #11881. Fix them. Tree-SHA512: 86de3d6dc3292b1ae4cc04c2d7d7dbbf39c9270551d7b224b8d8b19e3184c30c897dbf823200403706d06bb405c0decad5cfd690cb2c0312992a235a4ffcf6bf
This commit is contained in:
parent
4d3518fe04
commit
7cf9572c26
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2015 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
@ -15,29 +15,29 @@ import re
|
||||
|
||||
FOLDER_GREP = 'src'
|
||||
FOLDER_TEST = 'src/test/'
|
||||
CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/%s' % FOLDER_GREP
|
||||
CMD_GREP_ARGS = r"egrep -r -I '(map(Multi)?Args(\.count\(|\[)|Get(Bool)?Arg\()\"\-[^\"]+?\"' %s | grep -v '%s'" % (CMD_ROOT_DIR, FOLDER_TEST)
|
||||
CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' %s" % (CMD_ROOT_DIR)
|
||||
CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/{}'.format(FOLDER_GREP)
|
||||
CMD_GREP_ARGS = r"egrep -r -I '(map(Multi)?Args(\.count\(|\[)|Get(Bool)?Arg\()\"\-[^\"]+?\"' {} | grep -v '{}'".format(CMD_ROOT_DIR, FOLDER_TEST)
|
||||
CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' {}".format(CMD_ROOT_DIR)
|
||||
REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"')
|
||||
REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")')
|
||||
# list unsupported, deprecated and duplicate args as they need no documentation
|
||||
SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay', '-blockminsize'])
|
||||
|
||||
def main():
|
||||
used = check_output(CMD_GREP_ARGS, shell=True)
|
||||
docd = check_output(CMD_GREP_DOCS, shell=True)
|
||||
used = check_output(CMD_GREP_ARGS, shell=True, universal_newlines=True)
|
||||
docd = check_output(CMD_GREP_DOCS, shell=True, universal_newlines=True)
|
||||
|
||||
args_used = set(re.findall(REGEX_ARG,used))
|
||||
args_docd = set(re.findall(REGEX_DOC,docd)).union(SET_DOC_OPTIONAL)
|
||||
args_need_doc = args_used.difference(args_docd)
|
||||
args_unknown = args_docd.difference(args_used)
|
||||
|
||||
print "Args used : %s" % len(args_used)
|
||||
print "Args documented : %s" % len(args_docd)
|
||||
print "Args undocumented: %s" % len(args_need_doc)
|
||||
print args_need_doc
|
||||
print "Args unknown : %s" % len(args_unknown)
|
||||
print args_unknown
|
||||
print("Args used : {}".format(len(args_used)))
|
||||
print("Args documented : {}".format(len(args_docd)))
|
||||
print("Args undocumented: {}".format(len(args_need_doc)))
|
||||
print(args_need_doc)
|
||||
print("Args unknown : {}".format(len(args_unknown)))
|
||||
print(args_unknown)
|
||||
|
||||
exit(len(args_need_doc))
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
#===- clang-format-diff.py - ClangFormat Diff Reformatter ----*- python -*--===#
|
||||
#
|
||||
@ -69,10 +69,10 @@ Example usage for git/svn users:
|
||||
|
||||
import argparse
|
||||
import difflib
|
||||
import io
|
||||
import re
|
||||
import string
|
||||
import subprocess
|
||||
import StringIO
|
||||
import sys
|
||||
|
||||
|
||||
@ -133,9 +133,9 @@ def main():
|
||||
['-lines', str(start_line) + ':' + str(end_line)])
|
||||
|
||||
# Reformat files containing changes in place.
|
||||
for filename, lines in lines_by_file.iteritems():
|
||||
for filename, lines in lines_by_file.items():
|
||||
if args.i and args.verbose:
|
||||
print 'Formatting', filename
|
||||
print('Formatting {}'.format(filename))
|
||||
command = [binary, filename]
|
||||
if args.i:
|
||||
command.append('-i')
|
||||
@ -143,8 +143,11 @@ def main():
|
||||
command.append('-sort-includes')
|
||||
command.extend(lines)
|
||||
command.extend(['-style=file', '-fallback-style=none'])
|
||||
p = subprocess.Popen(command, stdout=subprocess.PIPE,
|
||||
stderr=None, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen(command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=None,
|
||||
stdin=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode != 0:
|
||||
sys.exit(p.returncode)
|
||||
@ -152,11 +155,11 @@ def main():
|
||||
if not args.i:
|
||||
with open(filename) as f:
|
||||
code = f.readlines()
|
||||
formatted_code = StringIO.StringIO(stdout).readlines()
|
||||
formatted_code = io.StringIO(stdout).readlines()
|
||||
diff = difflib.unified_diff(code, formatted_code,
|
||||
filename, filename,
|
||||
'(before formatting)', '(after formatting)')
|
||||
diff_string = string.join(diff, '')
|
||||
diff_string = ''.join(diff)
|
||||
if len(diff_string) > 0:
|
||||
sys.stdout.write(diff_string)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2014-2015 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
@ -10,7 +10,7 @@ import os
|
||||
import sys
|
||||
import subprocess
|
||||
import hashlib
|
||||
from PIL import Image
|
||||
from PIL import Image # pip3 install Pillow
|
||||
|
||||
def file_hash(filename):
|
||||
'''Return hash of raw file contents'''
|
||||
@ -27,7 +27,7 @@ def content_hash(filename):
|
||||
pngcrush = 'pngcrush'
|
||||
git = 'git'
|
||||
folders = ["src/qt/res/movies", "src/qt/res/icons", "src/qt/res/icons/crownium", "src/qt/res/icons/drkblue", "src/qt/res/icons/light", "src/qt/res/icons/light-retro", "src/qt/res/icons/trad", "src/qt/res/images", "src/qt/res/images/crownium", "src/qt/res/images/drkblue", "src/qt/res/images/light", "src/qt/res/images/light-retro", "src/qt/res/images/trad", "share/pixmaps"]
|
||||
basePath = subprocess.check_output([git, 'rev-parse', '--show-toplevel']).rstrip('\n')
|
||||
basePath = subprocess.check_output([git, 'rev-parse', '--show-toplevel'], universal_newlines=True).rstrip('\n')
|
||||
totalSaveBytes = 0
|
||||
noHashChange = True
|
||||
|
||||
@ -37,42 +37,40 @@ for folder in folders:
|
||||
for file in os.listdir(absFolder):
|
||||
extension = os.path.splitext(file)[1]
|
||||
if extension.lower() == '.png':
|
||||
print("optimizing "+file+"..."),
|
||||
print("optimizing {}...".format(file), end =' ')
|
||||
file_path = os.path.join(absFolder, file)
|
||||
fileMetaMap = {'file' : file, 'osize': os.path.getsize(file_path), 'sha256Old' : file_hash(file_path)}
|
||||
fileMetaMap['contentHashPre'] = content_hash(file_path)
|
||||
|
||||
pngCrushOutput = ""
|
||||
try:
|
||||
pngCrushOutput = subprocess.check_output(
|
||||
[pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path],
|
||||
stderr=subprocess.STDOUT).rstrip('\n')
|
||||
subprocess.call([pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
except:
|
||||
print "pngcrush is not installed, aborting..."
|
||||
print("pngcrush is not installed, aborting...")
|
||||
sys.exit(0)
|
||||
|
||||
#verify
|
||||
if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT):
|
||||
print "PNG file "+file+" is corrupted after crushing, check out pngcursh version"
|
||||
if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT, universal_newlines=True):
|
||||
print("PNG file "+file+" is corrupted after crushing, check out pngcursh version")
|
||||
sys.exit(1)
|
||||
|
||||
fileMetaMap['sha256New'] = file_hash(file_path)
|
||||
fileMetaMap['contentHashPost'] = content_hash(file_path)
|
||||
|
||||
if fileMetaMap['contentHashPre'] != fileMetaMap['contentHashPost']:
|
||||
print "Image contents of PNG file "+file+" before and after crushing don't match"
|
||||
print("Image contents of PNG file {} before and after crushing don't match".format(file))
|
||||
sys.exit(1)
|
||||
|
||||
fileMetaMap['psize'] = os.path.getsize(file_path)
|
||||
outputArray.append(fileMetaMap)
|
||||
print("done\n"),
|
||||
print("done")
|
||||
|
||||
print "summary:\n+++++++++++++++++"
|
||||
print("summary:\n+++++++++++++++++")
|
||||
for fileDict in outputArray:
|
||||
oldHash = fileDict['sha256Old']
|
||||
newHash = fileDict['sha256New']
|
||||
totalSaveBytes += fileDict['osize'] - fileDict['psize']
|
||||
noHashChange = noHashChange and (oldHash == newHash)
|
||||
print fileDict['file']+"\n size diff from: "+str(fileDict['osize'])+" to: "+str(fileDict['psize'])+"\n old sha256: "+oldHash+"\n new sha256: "+newHash+"\n"
|
||||
print(fileDict['file']+"\n size diff from: "+str(fileDict['osize'])+" to: "+str(fileDict['psize'])+"\n old sha256: "+oldHash+"\n new sha256: "+newHash+"\n")
|
||||
|
||||
print "completed. Checksum stable: "+str(noHashChange)+". Total reduction: "+str(totalSaveBytes)+" bytes"
|
||||
print("completed. Checksum stable: "+str(noHashChange)+". Total reduction: "+str(totalSaveBytes)+" bytes")
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2015-2016 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
@ -8,7 +8,6 @@ Exit status will be 0 if successful, and the program will be silent.
|
||||
Otherwise the exit status will be 1 and it will log which executables failed which checks.
|
||||
Needs `readelf` (for ELF) and `objdump` (for PE).
|
||||
'''
|
||||
from __future__ import division,print_function,unicode_literals
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
@ -21,38 +20,38 @@ def check_ELF_PIE(executable):
|
||||
'''
|
||||
Check for position independent executable (PIE), allowing for address space randomization.
|
||||
'''
|
||||
p = subprocess.Popen([READELF_CMD, '-h', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen([READELF_CMD, '-h', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode:
|
||||
raise IOError('Error opening file')
|
||||
|
||||
ok = False
|
||||
for line in stdout.split(b'\n'):
|
||||
for line in stdout.splitlines():
|
||||
line = line.split()
|
||||
if len(line)>=2 and line[0] == b'Type:' and line[1] == b'DYN':
|
||||
if len(line)>=2 and line[0] == 'Type:' and line[1] == 'DYN':
|
||||
ok = True
|
||||
return ok
|
||||
|
||||
def get_ELF_program_headers(executable):
|
||||
'''Return type and flags for ELF program headers'''
|
||||
p = subprocess.Popen([READELF_CMD, '-l', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen([READELF_CMD, '-l', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode:
|
||||
raise IOError('Error opening file')
|
||||
in_headers = False
|
||||
count = 0
|
||||
headers = []
|
||||
for line in stdout.split(b'\n'):
|
||||
if line.startswith(b'Program Headers:'):
|
||||
for line in stdout.splitlines():
|
||||
if line.startswith('Program Headers:'):
|
||||
in_headers = True
|
||||
if line == b'':
|
||||
if line == '':
|
||||
in_headers = False
|
||||
if in_headers:
|
||||
if count == 1: # header line
|
||||
ofs_typ = line.find(b'Type')
|
||||
ofs_offset = line.find(b'Offset')
|
||||
ofs_flags = line.find(b'Flg')
|
||||
ofs_align = line.find(b'Align')
|
||||
ofs_typ = line.find('Type')
|
||||
ofs_offset = line.find('Offset')
|
||||
ofs_flags = line.find('Flg')
|
||||
ofs_align = line.find('Align')
|
||||
if ofs_typ == -1 or ofs_offset == -1 or ofs_flags == -1 or ofs_align == -1:
|
||||
raise ValueError('Cannot parse elfread -lW output')
|
||||
elif count > 1:
|
||||
@ -69,9 +68,9 @@ def check_ELF_NX(executable):
|
||||
have_wx = False
|
||||
have_gnu_stack = False
|
||||
for (typ, flags) in get_ELF_program_headers(executable):
|
||||
if typ == b'GNU_STACK':
|
||||
if typ == 'GNU_STACK':
|
||||
have_gnu_stack = True
|
||||
if b'W' in flags and b'E' in flags: # section is both writable and executable
|
||||
if 'W' in flags and 'E' in flags: # section is both writable and executable
|
||||
have_wx = True
|
||||
return have_gnu_stack and not have_wx
|
||||
|
||||
@ -88,17 +87,17 @@ def check_ELF_RELRO(executable):
|
||||
# However, the dynamic linker need to write to this area so these are RW.
|
||||
# Glibc itself takes care of mprotecting this area R after relocations are finished.
|
||||
# See also http://permalink.gmane.org/gmane.comp.gnu.binutils/71347
|
||||
if typ == b'GNU_RELRO':
|
||||
if typ == 'GNU_RELRO':
|
||||
have_gnu_relro = True
|
||||
|
||||
have_bindnow = False
|
||||
p = subprocess.Popen([READELF_CMD, '-d', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen([READELF_CMD, '-d', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode:
|
||||
raise IOError('Error opening file')
|
||||
for line in stdout.split(b'\n'):
|
||||
for line in stdout.splitlines():
|
||||
tokens = line.split()
|
||||
if len(tokens)>1 and tokens[1] == b'(BIND_NOW)' or (len(tokens)>2 and tokens[1] == b'(FLAGS)' and b'BIND_NOW' in tokens[2]):
|
||||
if len(tokens)>1 and tokens[1] == '(BIND_NOW)' or (len(tokens)>2 and tokens[1] == '(FLAGS)' and 'BIND_NOW' in tokens[2]):
|
||||
have_bindnow = True
|
||||
return have_gnu_relro and have_bindnow
|
||||
|
||||
@ -106,13 +105,13 @@ def check_ELF_Canary(executable):
|
||||
'''
|
||||
Check for use of stack canary
|
||||
'''
|
||||
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode:
|
||||
raise IOError('Error opening file')
|
||||
ok = False
|
||||
for line in stdout.split(b'\n'):
|
||||
if b'__stack_chk_fail' in line:
|
||||
for line in stdout.splitlines():
|
||||
if '__stack_chk_fail' in line:
|
||||
ok = True
|
||||
return ok
|
||||
|
||||
@ -122,13 +121,13 @@ def get_PE_dll_characteristics(executable):
|
||||
Returns a tuple (arch,bits) where arch is 'i386:x86-64' or 'i386'
|
||||
and bits is the DllCharacteristics value.
|
||||
'''
|
||||
p = subprocess.Popen([OBJDUMP_CMD, '-x', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen([OBJDUMP_CMD, '-x', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode:
|
||||
raise IOError('Error opening file')
|
||||
arch = ''
|
||||
bits = 0
|
||||
for line in stdout.split('\n'):
|
||||
for line in stdout.splitlines():
|
||||
tokens = line.split()
|
||||
if len(tokens)>=2 and tokens[0] == 'architecture:':
|
||||
arch = tokens[1].rstrip(',')
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2014 Wladimir J. van der Laan
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
@ -11,7 +11,6 @@ Example usage:
|
||||
|
||||
find ../gitian-builder/build -type f -executable | xargs python contrib/devtools/symbol-check.py
|
||||
'''
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
@ -47,28 +46,28 @@ MAX_VERSIONS = {
|
||||
|
||||
# Ignore symbols that are exported as part of every executable
|
||||
IGNORE_EXPORTS = {
|
||||
b'_edata', b'_end', b'_init', b'__bss_start', b'_fini', b'_IO_stdin_used'
|
||||
'_edata', '_end', '_init', '__bss_start', '_fini', '_IO_stdin_used'
|
||||
}
|
||||
READELF_CMD = os.getenv('READELF', '/usr/bin/readelf')
|
||||
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
|
||||
# Allowed NEEDED libraries
|
||||
ALLOWED_LIBRARIES = {
|
||||
# bitcoind and bitcoin-qt
|
||||
b'libgcc_s.so.1', # GCC base support
|
||||
b'libc.so.6', # C library
|
||||
b'libpthread.so.0', # threading
|
||||
b'libanl.so.1', # DNS resolve
|
||||
b'libm.so.6', # math library
|
||||
b'librt.so.1', # real-time (clock)
|
||||
b'ld-linux-x86-64.so.2', # 64-bit dynamic linker
|
||||
b'ld-linux.so.2', # 32-bit dynamic linker
|
||||
'libgcc_s.so.1', # GCC base support
|
||||
'libc.so.6', # C library
|
||||
'libpthread.so.0', # threading
|
||||
'libanl.so.1', # DNS resolve
|
||||
'libm.so.6', # math library
|
||||
'librt.so.1', # real-time (clock)
|
||||
'ld-linux-x86-64.so.2', # 64-bit dynamic linker
|
||||
'ld-linux.so.2', # 32-bit dynamic linker
|
||||
# bitcoin-qt only
|
||||
b'libX11-xcb.so.1', # part of X11
|
||||
b'libX11.so.6', # part of X11
|
||||
b'libxcb.so.1', # part of X11
|
||||
b'libfontconfig.so.1', # font support
|
||||
b'libfreetype.so.6', # font parsing
|
||||
b'libdl.so.2' # programming interface to dynamic linker
|
||||
'libX11-xcb.so.1', # part of X11
|
||||
'libX11.so.6', # part of X11
|
||||
'libxcb.so.1', # part of X11
|
||||
'libfontconfig.so.1', # font support
|
||||
'libfreetype.so.6', # font parsing
|
||||
'libdl.so.2' # programming interface to dynamic linker
|
||||
}
|
||||
|
||||
class CPPFilt(object):
|
||||
@ -78,10 +77,10 @@ class CPPFilt(object):
|
||||
Use a pipe to the 'c++filt' command.
|
||||
'''
|
||||
def __init__(self):
|
||||
self.proc = subprocess.Popen(CPPFILT_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
self.proc = subprocess.Popen(CPPFILT_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
|
||||
|
||||
def __call__(self, mangled):
|
||||
self.proc.stdin.write(mangled + b'\n')
|
||||
self.proc.stdin.write(mangled + '\n')
|
||||
self.proc.stdin.flush()
|
||||
return self.proc.stdout.readline().rstrip()
|
||||
|
||||
@ -95,43 +94,43 @@ def read_symbols(executable, imports=True):
|
||||
Parse an ELF executable and return a list of (symbol,version) tuples
|
||||
for dynamic, imported symbols.
|
||||
'''
|
||||
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode:
|
||||
raise IOError('Could not read symbols for %s: %s' % (executable, stderr.strip()))
|
||||
syms = []
|
||||
for line in stdout.split(b'\n'):
|
||||
for line in stdout.splitlines():
|
||||
line = line.split()
|
||||
if len(line)>7 and re.match(b'[0-9]+:$', line[0]):
|
||||
(sym, _, version) = line[7].partition(b'@')
|
||||
is_import = line[6] == b'UND'
|
||||
if version.startswith(b'@'):
|
||||
if len(line)>7 and re.match('[0-9]+:$', line[0]):
|
||||
(sym, _, version) = line[7].partition('@')
|
||||
is_import = line[6] == 'UND'
|
||||
if version.startswith('@'):
|
||||
version = version[1:]
|
||||
if is_import == imports:
|
||||
syms.append((sym, version))
|
||||
return syms
|
||||
|
||||
def check_version(max_versions, version):
|
||||
if b'_' in version:
|
||||
(lib, _, ver) = version.rpartition(b'_')
|
||||
if '_' in version:
|
||||
(lib, _, ver) = version.rpartition('_')
|
||||
else:
|
||||
lib = version
|
||||
ver = '0'
|
||||
ver = tuple([int(x) for x in ver.split(b'.')])
|
||||
ver = tuple([int(x) for x in ver.split('.')])
|
||||
if not lib in max_versions:
|
||||
return False
|
||||
return ver <= max_versions[lib]
|
||||
|
||||
def read_libraries(filename):
|
||||
p = subprocess.Popen([READELF_CMD, '-d', '-W', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p = subprocess.Popen([READELF_CMD, '-d', '-W', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
|
||||
(stdout, stderr) = p.communicate()
|
||||
if p.returncode:
|
||||
raise IOError('Error opening file')
|
||||
libraries = []
|
||||
for line in stdout.split(b'\n'):
|
||||
for line in stdout.splitlines():
|
||||
tokens = line.split()
|
||||
if len(tokens)>2 and tokens[1] == b'(NEEDED)':
|
||||
match = re.match(b'^Shared library: \[(.*)\]$', b' '.join(tokens[2:]))
|
||||
if len(tokens)>2 and tokens[1] == '(NEEDED)':
|
||||
match = re.match('^Shared library: \[(.*)\]$', ' '.join(tokens[2:]))
|
||||
if match:
|
||||
libraries.append(match.group(1))
|
||||
else:
|
||||
@ -145,18 +144,18 @@ if __name__ == '__main__':
|
||||
# Check imported symbols
|
||||
for sym,version in read_symbols(filename, True):
|
||||
if version and not check_version(MAX_VERSIONS, version):
|
||||
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym).decode('utf-8'), version.decode('utf-8')))
|
||||
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym), version))
|
||||
retval = 1
|
||||
# Check exported symbols
|
||||
for sym,version in read_symbols(filename, False):
|
||||
if sym in IGNORE_EXPORTS:
|
||||
continue
|
||||
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym).decode('utf-8')))
|
||||
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
|
||||
retval = 1
|
||||
# Check dependency libraries
|
||||
for library_name in read_libraries(filename):
|
||||
if library_name not in ALLOWED_LIBRARIES:
|
||||
print('%s: NEEDED library %s is not allowed' % (filename, library_name.decode('utf-8')))
|
||||
print('%s: NEEDED library %s is not allowed' % (filename, library_name))
|
||||
retval = 1
|
||||
|
||||
exit(retval)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2014 Wladimir J. van der Laan
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
@ -15,7 +15,6 @@ It will do the following automatically:
|
||||
TODO:
|
||||
- auto-add new translations to the build system according to the translation process
|
||||
'''
|
||||
from __future__ import division, print_function
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
|
@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2013-2015 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
from __future__ import division,print_function,unicode_literals
|
||||
import biplist
|
||||
from ds_store import DSStore
|
||||
from mac_alias import Alias
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (C) 2011 Patrick "p2k" Schneider <me@p2k-network.org>
|
||||
#
|
||||
@ -203,7 +202,7 @@ def getFrameworks(binaryPath, verbose):
|
||||
if verbose >= 3:
|
||||
print("Inspecting with otool: " + binaryPath)
|
||||
otoolbin=os.getenv("OTOOL", "otool")
|
||||
otool = subprocess.Popen([otoolbin, "-L", binaryPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
otool = subprocess.Popen([otoolbin, "-L", binaryPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||
o_stdout, o_stderr = otool.communicate()
|
||||
if otool.returncode != 0:
|
||||
if verbose >= 1:
|
||||
@ -211,7 +210,7 @@ def getFrameworks(binaryPath, verbose):
|
||||
sys.stderr.flush()
|
||||
raise RuntimeError("otool failed with return code %d" % otool.returncode)
|
||||
|
||||
otoolLines = o_stdout.decode().split("\n")
|
||||
otoolLines = o_stdout.split("\n")
|
||||
otoolLines.pop(0) # First line is the inspected binary
|
||||
if ".framework" in binaryPath or binaryPath.endswith(".dylib"):
|
||||
otoolLines.pop(0) # Frameworks and dylibs list themselves as a dependency.
|
||||
@ -716,22 +715,6 @@ elif config.sign:
|
||||
|
||||
if config.dmg is not None:
|
||||
|
||||
#Patch in check_output for Python 2.6
|
||||
if "check_output" not in dir( subprocess ):
|
||||
def f(*popenargs, **kwargs):
|
||||
if 'stdout' in kwargs:
|
||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
raise CalledProcessError(retcode, cmd)
|
||||
return output
|
||||
subprocess.check_output = f
|
||||
|
||||
def runHDIUtil(verb, image_basename, **kwargs):
|
||||
hdiutil_args = ["hdiutil", verb, image_basename + ".dmg"]
|
||||
if "capture_stdout" in kwargs:
|
||||
@ -749,7 +732,7 @@ if config.dmg is not None:
|
||||
if not value is True:
|
||||
hdiutil_args.append(str(value))
|
||||
|
||||
return run(hdiutil_args)
|
||||
return run(hdiutil_args, universal_newlines=True)
|
||||
|
||||
if verbose >= 2:
|
||||
if fancy is None:
|
||||
@ -791,7 +774,7 @@ if config.dmg is not None:
|
||||
except subprocess.CalledProcessError as e:
|
||||
sys.exit(e.returncode)
|
||||
|
||||
m = re.search("/Volumes/(.+$)", output.decode())
|
||||
m = re.search("/Volumes/(.+$)", output)
|
||||
disk_root = m.group(0)
|
||||
disk_name = m.group(1)
|
||||
|
||||
|
@ -28,7 +28,9 @@ def b58encode(v):
|
||||
"""
|
||||
long_value = 0
|
||||
for (i, c) in enumerate(v[::-1]):
|
||||
long_value += (256**i) * ord(c)
|
||||
if isinstance(c, str):
|
||||
c = ord(c)
|
||||
long_value += (256**i) * c
|
||||
|
||||
result = ''
|
||||
while long_value >= __b58base:
|
||||
@ -41,7 +43,7 @@ def b58encode(v):
|
||||
# leading 0-bytes in the input become leading-1s
|
||||
nPad = 0
|
||||
for c in v:
|
||||
if c == '\0': nPad += 1
|
||||
if c == 0: nPad += 1
|
||||
else: break
|
||||
|
||||
return (__b58chars[0]*nPad) + result
|
||||
@ -50,8 +52,10 @@ def b58decode(v, length = None):
|
||||
""" decode v into a string of len bytes
|
||||
"""
|
||||
long_value = 0
|
||||
for (i, c) in enumerate(v[::-1]):
|
||||
long_value += __b58chars.find(c) * (__b58base**i)
|
||||
for i, c in enumerate(v[::-1]):
|
||||
pos = __b58chars.find(c)
|
||||
assert pos != -1
|
||||
long_value += pos * (__b58base**i)
|
||||
|
||||
result = bytes()
|
||||
while long_value >= 256:
|
||||
@ -62,10 +66,12 @@ def b58decode(v, length = None):
|
||||
|
||||
nPad = 0
|
||||
for c in v:
|
||||
if c == __b58chars[0]: nPad += 1
|
||||
else: break
|
||||
if c == __b58chars[0]:
|
||||
nPad += 1
|
||||
continue
|
||||
break
|
||||
|
||||
result = chr(0)*nPad + result
|
||||
result = bytes(nPad) + result
|
||||
if length is not None and len(result) != length:
|
||||
return None
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2012 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
'''
|
||||
Generate valid and invalid base58 address and private key test vectors.
|
||||
|
||||
Usage:
|
||||
Usage:
|
||||
gen_base58_test_vectors.py valid 50 > ../../src/test/data/base58_keys_valid.json
|
||||
gen_base58_test_vectors.py invalid 50 > ../../src/test/data/base58_keys_invalid.json
|
||||
'''
|
||||
@ -46,8 +46,8 @@ def is_valid(v):
|
||||
if result is None:
|
||||
return False
|
||||
for template in templates:
|
||||
prefix = str(bytearray(template[0]))
|
||||
suffix = str(bytearray(template[2]))
|
||||
prefix = bytearray(template[0])
|
||||
suffix = bytearray(template[2])
|
||||
if result.startswith(prefix) and result.endswith(suffix):
|
||||
if (len(result) - len(prefix) - len(suffix)) == template[1]:
|
||||
return True
|
||||
@ -57,20 +57,23 @@ def gen_valid_vectors():
|
||||
'''Generate valid test vectors'''
|
||||
while True:
|
||||
for template in templates:
|
||||
prefix = str(bytearray(template[0]))
|
||||
payload = os.urandom(template[1])
|
||||
suffix = str(bytearray(template[2]))
|
||||
prefix = bytearray(template[0])
|
||||
payload = bytearray(os.urandom(template[1]))
|
||||
suffix = bytearray(template[2])
|
||||
rv = b58encode_chk(prefix + payload + suffix)
|
||||
assert is_valid(rv)
|
||||
metadata = dict([(x,y) for (x,y) in zip(metadata_keys,template[3]) if y is not None])
|
||||
yield (rv, b2a_hex(payload), metadata)
|
||||
metadata = {x: y for x, y in zip(metadata_keys,template[3]) if y is not None}
|
||||
hexrepr = b2a_hex(payload)
|
||||
if isinstance(hexrepr, bytes):
|
||||
hexrepr = hexrepr.decode('utf8')
|
||||
yield (rv, hexrepr, metadata)
|
||||
|
||||
def gen_invalid_vector(template, corrupt_prefix, randomize_payload_size, corrupt_suffix):
|
||||
'''Generate possibly invalid vector'''
|
||||
if corrupt_prefix:
|
||||
prefix = os.urandom(1)
|
||||
else:
|
||||
prefix = str(bytearray(template[0]))
|
||||
prefix = bytearray(template[0])
|
||||
|
||||
if randomize_payload_size:
|
||||
payload = os.urandom(max(int(random.expovariate(0.5)), 50))
|
||||
@ -80,7 +83,7 @@ def gen_invalid_vector(template, corrupt_prefix, randomize_payload_size, corrupt
|
||||
if corrupt_suffix:
|
||||
suffix = os.urandom(len(template[2]))
|
||||
else:
|
||||
suffix = str(bytearray(template[2]))
|
||||
suffix = bytearray(template[2])
|
||||
|
||||
return b58encode_chk(prefix + payload + suffix)
|
||||
|
||||
|
@ -86,6 +86,11 @@ See detailed [change log](https://github.com/dashpay/dash/compare/v0.12.3.1...da
|
||||
- [`f833e2ed6`](https://github.com/dashpay/dash/commit/f833e2ed6) Bump to 0.12.3.2 (#2173)
|
||||
|
||||
|
||||
Python Support
|
||||
--------------
|
||||
|
||||
Support for Python 2 has been discontinued for all test files and tools.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2012-2016 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
@ -6,7 +6,6 @@
|
||||
Extract _("...") strings for translation and convert to Qt stringdefs so that
|
||||
they can be picked up by Qt linguist.
|
||||
'''
|
||||
from __future__ import division,print_function,unicode_literals
|
||||
from subprocess import Popen, PIPE
|
||||
import operator
|
||||
import os
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2015 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
Loading…
Reference in New Issue
Block a user