def __init__(self, use_dx): """Constructor for the runner with host compilation. Args: use_dx: boolean, if True use dx rather than jack """ self._jack_args = ['-cp', GetJackClassPath(), '--output-dex', '.', 'Test.java'] self._use_dx = use_dx
def __init__(self, extra_args=None): """Constructor for the Art on host tester. Args: extra_args: list of strings, extra arguments for dalvikvm """ self._art_cmd = ['/bin/bash', 'art', '-cp', 'classes.dex'] if extra_args is not None: self._art_cmd += extra_args self._art_cmd.append('Test') self._jack_args = [ '-cp', GetJackClassPath(), '--output-dex', '.', 'Test.java' ]
def __init__(self, device, extra_args=None): """Constructor for the Art on target tester. Args: device: string, target device serial number (or None) extra_args: list of strings, extra arguments for dalvikvm """ self._test_env = DeviceTestEnv('jfuzz_', specific_device=device) self._dalvik_cmd = ['dalvikvm'] if extra_args is not None: self._dalvik_cmd += extra_args self._device = device self._jack_args = [ '-cp', GetJackClassPath(), '--output-dex', '.', 'Test.java' ] self._device_classpath = None
def CompileOnHost(self): """Compiles Test.java into classes.dex using either javac/dx,d8 or jack. Raises: FatalError: error when compilation fails """ if self._dexer == 'dx' or self._dexer == 'd8': dbg = '-g' if self._debug_info else '-g:none' if RunCommand(['javac', '--release=8', dbg, 'Test.java'], out=None, err='jerr.txt', timeout=30) != RetCode.SUCCESS: print('Unexpected error while running javac') raise FatalError('Unexpected error while running javac') cfiles = glob('*.class') dx = 'dx' if self._dexer == 'dx' else 'd8-compat-dx' if RunCommand([dx, '--dex', '--output=classes.dex'] + cfiles, out=None, err='dxerr.txt', timeout=30) != RetCode.SUCCESS: print('Unexpected error while running dx') raise FatalError('Unexpected error while running dx') # Cleanup on success (nothing to see). for cfile in cfiles: os.unlink(cfile) os.unlink('jerr.txt') os.unlink('dxerr.txt') elif self._dexer == 'jack': jack_args = [ '-cp', GetJackClassPath(), '--output-dex', '.', 'Test.java' ] if RunCommand( ['jack'] + jack_args, out=None, err='jackerr.txt', timeout=30) != RetCode.SUCCESS: print('Unexpected error while running Jack') raise FatalError('Unexpected error while running Jack') # Cleanup on success (nothing to see). os.unlink('jackerr.txt') else: raise FatalError('Unknown dexer: ' + self._dexer)
def GenerateJFuzzPrograms(self): """Generates JFuzz programs. Raises: FatalError: error when generation fails """ os.chdir(self._inputs_dir) for i in range(1, self._num_inputs + 1): jack_args = [ '-cp', GetJackClassPath(), '--output-dex', '.', 'Test.java' ] if RunCommand(['jfuzz'], out='Test.java', err=None) != RetCode.SUCCESS: raise FatalError('Unexpected error while running JFuzz') if RunCommand( ['jack'] + jack_args, out=None, err='jackerr.txt', timeout=30) != RetCode.SUCCESS: raise FatalError('Unexpected error while running Jack') shutil.move('Test.java', '../Test' + str(i) + '.java') shutil.move('classes.dex', 'classes' + str(i) + '.dex') os.unlink('jackerr.txt')
def CompileOnHost(self): """Compiles Test.java into classes.dex using either javac/dx or jack. Raises: FatalError: error when compilation fails """ if self._use_dx: if RunCommand( ['javac', 'Test.java'], out=None, err='jerr.txt', timeout=30) != RetCode.SUCCESS: print('Unexpected error while running javac') raise FatalError('Unexpected error while running javac') cfiles = glob('*.class') if RunCommand(['dx', '--dex', '--output=classes.dex'] + cfiles, out=None, err='dxerr.txt', timeout=30) != RetCode.SUCCESS: print('Unexpected error while running dx') raise FatalError('Unexpected error while running dx') # Cleanup on success (nothing to see). for cfile in cfiles: os.unlink(cfile) os.unlink('jerr.txt') os.unlink('dxerr.txt') else: jack_args = [ '-cp', GetJackClassPath(), '--output-dex', '.', 'Test.java' ] if RunCommand( ['jack'] + jack_args, out=None, err='jackerr.txt', timeout=30) != RetCode.SUCCESS: print('Unexpected error while running Jack') raise FatalError('Unexpected error while running Jack') # Cleanup on success (nothing to see). os.unlink('jackerr.txt')