pull/1398/head
aniket-engg 3 years ago committed by Aniket
parent c9c9f6da7d
commit 040a8a913b
  1. 44
      libs/remixd/src/services/slitherClient.ts

@ -24,17 +24,17 @@ export class SlitherClient extends PluginClient {
this.currentSharedFolder = currentSharedFolder this.currentSharedFolder = currentSharedFolder
} }
transform (detectors) { transform (detectors: Record<string, any>[]): OutputStandard[] {
const standardReport = [] const standardReport: OutputStandard[] = []
for (const e of detectors) { for (const e of detectors) {
const obj = {} const obj = {} as OutputStandard
obj['description'] = e['description'] obj.description = e.description
obj['title'] = e.check obj.title = e.check
obj['confidence'] = e.confidence obj.confidence = e.confidence
obj['severity'] = e.impact obj.severity = e.impact
obj['sourceMap'] = e.elements.map((element) => { obj.sourceMap = e.elements.map((element) => {
delete element.source_mapping['filename_used'] delete element.source_mapping.filename_used
delete element.source_mapping['filename_absolute'] delete element.source_mapping.filename_absolute
return element return element
}) })
standardReport.push(obj) standardReport.push(obj)
@ -42,35 +42,35 @@ export class SlitherClient extends PluginClient {
return standardReport return standardReport
} }
analyse (filePath: string, compilerConfig) { analyse (filePath: string, compilerConfig: Record<string, any>) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.readOnly) { if (this.readOnly) {
const errMsg = '[Slither Analysis]: Cannot analyse in read-only mode' const errMsg: string = '[Slither Analysis]: Cannot analyse in read-only mode'
return reject(new Error(errMsg)) return reject(new Error(errMsg))
} }
const options = { cwd: this.currentSharedFolder, shell: true } const options = { cwd: this.currentSharedFolder, shell: true }
const { currentVersion, optimize, evmVersion } = compilerConfig const { currentVersion, optimize, evmVersion } = compilerConfig
if (currentVersion) { if (currentVersion) {
const versionString = currentVersion.substring(0, currentVersion.indexOf('+commit') + 16) const versionString: string = currentVersion.substring(0, currentVersion.indexOf('+commit') + 16)
const solcOutput = execSync('solc --version', options) const solcOutput: Buffer = execSync('solc --version', options)
if (!solcOutput.toString().includes(versionString)) { if (!solcOutput.toString().includes(versionString)) {
const version = versionString.substring(0, versionString.indexOf('+commit')) const version: string = versionString.substring(0, versionString.indexOf('+commit'))
const solcSelectInstalledVersions = execSync('solc-select versions', options) const solcSelectInstalledVersions: Buffer = execSync('solc-select versions', options)
if (!solcSelectInstalledVersions.toString().includes(version)) { if (!solcSelectInstalledVersions.toString().includes(version)) {
execSync(`solc-select install ${version}`, options) execSync(`solc-select install ${version}`, options)
} }
execSync(`solc-select use ${version}`, options) execSync(`solc-select use ${version}`, options)
} }
} }
const outputFile = 'remix-slitherReport_' + Date.now() + '.json' const outputFile: string = 'remix-slitherReport_' + Date.now() + '.json'
const optimizeOption = optimize ? '--optimize ' : '' const optimizeOption: string = optimize ? '--optimize ' : ''
const evmOption = evmVersion ? `--evm-version ${evmVersion}` : '' const evmOption: string = evmVersion ? `--evm-version ${evmVersion}` : ''
const solcArgs = optimizeOption || evmOption ? `--solc-args '${optimizeOption}${evmOption}'` : '' const solcArgs: string = optimizeOption || evmOption ? `--solc-args '${optimizeOption}${evmOption}'` : ''
const cmd = `slither ${filePath} ${solcArgs} --json ${outputFile}` const cmd: string = `slither ${filePath} ${solcArgs} --json ${outputFile}`
const child = spawn(cmd, options) const child = spawn(cmd, options)
const response = {} const response = {}
child.on('close', () => { child.on('close', () => {
const outputFileAbsPath = `${this.currentSharedFolder}/${outputFile}` const outputFileAbsPath: string = `${this.currentSharedFolder}/${outputFile}`
if (existsSync(outputFileAbsPath)) { if (existsSync(outputFileAbsPath)) {
let report = readFileSync(outputFileAbsPath, 'utf8') let report = readFileSync(outputFileAbsPath, 'utf8')
report = JSON.parse(report) report = JSON.parse(report)

Loading…
Cancel
Save