Rizin
unix-like reverse engineering framework and cli tools
test-lz4-list Namespace Reference

Classes

class  NVerboseFileInfo
 
class  TestNonVerbose
 
class  VerboseFileInfo
 
class  TestVerbose
 

Functions

def to_human (size)
 
def log (text)
 
def errout (text, err=1)
 
def execute (command, print_command=True, print_output=False, print_error=True, param_shell=True)
 
def cleanup (silent=False)
 
def datagen (file_name, size)
 
def generate_files ()
 

Variables

list SIZES = [3, 11]
 
int MIB = 1048576
 
string LZ4 = os.path.dirname(os.path.realpath(__file__)) + "/../lz4"
 
 TEMP = tempfile.gettempdir()
 
 verbosity
 
 exit
 
 silent
 

Function Documentation

◆ cleanup()

def test-lz4-list.cleanup (   silent = False)

Definition at line 227 of file test-lz4-list.py.

227 def cleanup(silent=False):
228  for f in glob.glob("{}/test_list*".format(TEMP)):
229  if not silent:
230  log("Deleting {}".format(f))
231  os.unlink(f)
232 
233 
void cleanup(void)
Definition: enough.c:244
Definition: gzlog.c:289

Referenced by generate_files().

◆ datagen()

def test-lz4-list.datagen (   file_name,
  size 
)

Definition at line 234 of file test-lz4-list.py.

234 def datagen(file_name, size):
235  non_sparse_size = size // 2
236  sparse_size = size - non_sparse_size
237  with open(file_name, "wb") as f:
238  f.seek(sparse_size)
239  f.write(os.urandom(non_sparse_size))
240 
241 
def datagen(file_name, size)

Referenced by generate_files().

◆ errout()

def test-lz4-list.errout (   text,
  err = 1 
)

Definition at line 201 of file test-lz4-list.py.

201 def errout(text, err=1):
202  log(text)
203  exit(err)
204 
205 
def errout(text, err=1)

References exit.

Referenced by execute().

◆ execute()

def test-lz4-list.execute (   command,
  print_command = True,
  print_output = False,
  print_error = True,
  param_shell = True 
)

Definition at line 206 of file test-lz4-list.py.

206 def execute(command, print_command=True, print_output=False, print_error=True, param_shell=True):
207  if os.environ.get('QEMU_SYS'):
208  command = "{} {}".format(os.environ['QEMU_SYS'], command)
209  if print_command:
210  log("> " + command)
211  popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=param_shell)
212  stdout_lines, stderr_lines = popen.communicate()
213  stderr_lines = stderr_lines.decode("utf-8")
214  stdout_lines = stdout_lines.decode("utf-8")
215  if print_output:
216  if stdout_lines:
217  print(stdout_lines)
218  if stderr_lines:
219  print(stderr_lines)
220  if popen.returncode is not None and popen.returncode != 0:
221  if stderr_lines and not print_output and print_error:
222  print(stderr_lines)
223  errout("Failed to run: {}\n".format(command, stdout_lines + stderr_lines))
224  return (stdout_lines + stderr_lines).splitlines()
225 
226 
def execute(command, print_command=True, print_output=False, print_error=True, param_shell=True)

References errout().

Referenced by generate_files().

◆ generate_files()

def test-lz4-list.generate_files ( )

Definition at line 242 of file test-lz4-list.py.

242 def generate_files():
243  # file format ~ test_list<frametype>-<no_frames>f<create-args>.lz4 ~
244  # Generate LZ4Frames
245  for i in SIZES:
246  filename = "{}/test_list_{}M".format(TEMP, i)
247  log("Generating {}".format(filename))
248  datagen(filename, i * MIB)
249  for j in ["--content-size", "-BI", "-BD", "-BX", "--no-frame-crc"]:
250  lz4file = "{}-lz4f-1f{}.lz4".format(filename, j)
251  execute("{} {} {} {}".format(LZ4, j, filename, lz4file))
252  # Generate skippable frames
253  lz4file = "{}-skip-1f.lz4".format(filename)
254  skipsize = i * 1024
255  skipbytes = bytes([80, 42, 77, 24]) + skipsize.to_bytes(4, byteorder='little', signed=False)
256  with open(lz4file, 'wb') as f:
257  f.write(skipbytes)
258  f.write(os.urandom(skipsize))
259  # Generate legacy frames
260  lz4file = "{}-legc-1f.lz4".format(filename)
261  execute("{} -l {} {}".format(LZ4, filename, lz4file))
262 
263  # Concatenate --content-size files
264  file_list = glob.glob("{}/test_list_*-lz4f-1f--content-size.lz4".format(TEMP))
265  with open("{}/test_list_{}M-lz4f-2f--content-size.lz4".format(TEMP, sum(SIZES)), 'ab') as outfile:
266  for fname in file_list:
267  with open(fname, 'rb') as infile:
268  outfile.write(infile.read())
269 
270  # Concatenate all files
271  file_list = glob.glob("{}/test_list_*.lz4".format(TEMP))
272  with open("{}/test_list_concat-all.lz4".format(TEMP), 'ab') as outfile:
273  for fname in file_list:
274  with open(fname, 'rb') as infile:
275  outfile.write(infile.read())
276 
277 
static ut8 bytes[32]
Definition: asm_arc.c:23
def generate_files()

References bytes, cleanup(), datagen(), and execute().

◆ log()

def test-lz4-list.log (   text)

Definition at line 197 of file test-lz4-list.py.

197 def log(text):
198  print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text)
199 
200 
def log(text)

Referenced by core_cmd_tsrzcmd(), and gzlog_open().

◆ to_human()

def test-lz4-list.to_human (   size)

Definition at line 189 of file test-lz4-list.py.

189 def to_human(size):
190  for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']:
191  if size < 1024.0:
192  break
193  size /= 1024.0
194  return "{:.2f}{}".format(size, unit)
195 
196 
def to_human(size)

Referenced by test-lz4-list.TestNonVerbose.test_compressed_size(), and test-lz4-list.TestNonVerbose.test_uncompressed_size().

Variable Documentation

◆ exit

test-lz4-list.exit

Definition at line 281 of file test-lz4-list.py.

Referenced by __panels_process(), analysis_get_function_in(), badusage(), bail(), bochs_open(), bye(), clusterInit(), clusterLoadConfig(), clusterSaveConfigOrDie(), cmd_Quit(), compare_zip(), build_mig_index.convert(), cs_driver_hello(), do_extract_currentfile(), encode(), error(), errout(), file_create(), file_finish(), fileCheck(), flirt_parse_version(), fullSpeedBench(), FUZ_AddressOverflow(), FUZ_test(), get_block_size(), handle_redirection_proc(), help(), iob_pipe_write(), list_zip(), loadFile(), local_LZ4F_decompress(), local_LZ4F_decompress_followHint(), local_LZ4F_decompress_noHint(), lzmainfo(), main(), open_compressed(), open_file(), parse_args(), parse_options(), quit(), read_bin(), read_int(), redirect_socket_to_pty(), remove_sock(), roundTripCheck(), run_screaming(), rz_analysis_function_all_opcode_stat_handler(), rz_analysis_function_xrefs_handler(), rz_bv_mul(), rz_core_analysis_hint_set_offset(), rz_main_rizin(), rz_run_config_env(), rz_run_start(), rz_sign_flirt_parse_compressed_pattern_from_buffer(), rz_sign_flirt_parse_header_compressed_pattern_from_buffer(), rz_socket_proc_open(), rz_socket_spawn(), rz_sys_cmdbg(), rz_sys_exit(), rz_sys_run(), rz_sys_run_rop(), rz_test_main(), rzpipe_open(), safe_fwrite(), seek_bin(), show_usage_and_exit(), socket_http_answer(), spp_help(), terminate(), test_compress(), test_decompress(), TGZnotfound(), ts_calloc_default(), ts_malloc_default(), ts_realloc_default(), tuklib_exit(), tuklib_open_stdxxx(), uncompress(), usage(), UTIL_getOpenFileSize(), write_abc(), write_bin(), and write_int().

◆ LZ4

string test-lz4-list.LZ4 = os.path.dirname(os.path.realpath(__file__)) + "/../lz4"

Definition at line 11 of file test-lz4-list.py.

◆ MIB

int test-lz4-list.MIB = 1048576

Definition at line 10 of file test-lz4-list.py.

◆ silent

◆ SIZES

list test-lz4-list.SIZES = [3, 11]

Definition at line 9 of file test-lz4-list.py.

◆ TEMP

test-lz4-list.TEMP = tempfile.gettempdir()

Definition at line 14 of file test-lz4-list.py.

◆ verbosity

test-lz4-list.verbosity

Definition at line 281 of file test-lz4-list.py.