| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import * as vscode from 'vscode'; |
| const fs = require('fs'); |
| import {println} from '../logger'; |
| import {commandHistory} from '../commandUtils'; |
| import {systemSyncLogIfFailure} from '../utils'; |
| import {buildFuzzersFromWorkspace} from '../ossfuzzWrappers'; |
| import {extensionConfig} from '../config'; |
| const readline = require('readline'); |
|
|
| export async function cmdInputCollectorReproduceTestcase() { |
| |
| const crashFileInput = await vscode.window.showInputBox({ |
| value: '', |
| placeHolder: 'The ID of the testcase.', |
| }); |
| if (!crashFileInput) { |
| return; |
| } |
| |
| const args = new Object({ |
| crashFile: crashFileInput.toString(), |
| }); |
|
|
| const commandObject = new Object({ |
| commandType: 'oss-fuzz.ReproduceFuzzer', |
| Arguments: args, |
| dispatcherFunc: cmdDispatchReproduceTestcase, |
| }); |
| commandHistory.push(commandObject); |
|
|
| await cmdDispatchReproduceTestcase(args); |
| return true; |
| } |
|
|
| async function cmdDispatchReproduceTestcase(args: any) { |
| await reproduceTestcase(args.crashFile); |
| } |
|
|
| export async function reproduceTestcase(crashInfoFileInput: string) { |
| println('Reproducing testcase for ' + crashInfoFileInput); |
| println('Checking directory: ' + extensionConfig.crashesDirectory); |
|
|
| const crashInfoFile = |
| extensionConfig.crashesDirectory + '/' + crashInfoFileInput + '.info'; |
| println(crashInfoFile); |
| try { |
| if (fs.existsSync(crashInfoFile)) { |
| println('File exists'); |
| } else { |
| println('Crash file does not exist'); |
| return; |
| } |
| } catch (err) { |
| console.error(err); |
| return; |
| } |
|
|
| |
| const r = readline.createInterface({ |
| input: fs.createReadStream(crashInfoFile), |
| }); |
|
|
| let targetProject = 'N/A'; |
| let targetFuzzer = 'N/A'; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| r.on('line', (text: string) => { |
| println(text); |
| if (text.startsWith('Project: ')) { |
| println('Starts with project'); |
| println(text.split('Project: ').toString()); |
| targetProject = text.split('Project: ')[1]; |
| } else if (text.startsWith('Fuzzing Engine: ')) { |
| println('Starts with fuzzing engine'); |
| } else if (text.startsWith('Fuzz Target:')) { |
| println('Starts with Fuzz Target'); |
| targetFuzzer = text.split('Fuzz Target: ')[1]; |
| } else if (text.startsWith('Job Type:')) { |
| println('Starts with Job Type'); |
| } |
| }); |
|
|
| r.on('close', async () => { |
| println('Target project: ' + targetProject); |
| println('Target fuzzer: ' + targetFuzzer); |
|
|
| |
| const buildResult: boolean = await buildFuzzersFromWorkspace( |
| targetProject, |
| '', |
| true |
| ); |
| if (!buildResult) { |
| println('Failed to build fuzzers'); |
| return false; |
| } |
|
|
| |
| const crashInputTestCase = |
| extensionConfig.crashesDirectory + |
| '/' + |
| 'clusterfuzz-testcase-minimized-' + |
| targetFuzzer + |
| '-' + |
| crashInfoFileInput; |
| |
| |
| const cmdToExec = 'python3'; |
| const args = [ |
| extensionConfig.ossFuzzPepositoryWorkPath + '/infra/helper.py', |
| 'reproduce', |
| targetProject, |
| targetFuzzer, |
| crashInputTestCase, |
| ]; |
| if (!(await systemSyncLogIfFailure(cmdToExec, args))) { |
| println('Failed to reproduce testcase'); |
| } |
|
|
| return true; |
| }); |
| } |
|
|