Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
86f2d65e
Commit
86f2d65e
authored
Jul 05, 2021
by
Aniket-Engg
Committed by
Aniket
Jul 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle npm imports for Slither
parent
2d6f0ca8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
5 deletions
+42
-5
slitherClient.ts
libs/remixd/src/services/slitherClient.ts
+42
-5
No files found.
libs/remixd/src/services/slitherClient.ts
View file @
86f2d65e
...
...
@@ -2,7 +2,7 @@
import
*
as
WS
from
'ws'
// eslint-disable-line
import
{
PluginClient
}
from
'@remixproject/plugin'
import
{
existsSync
,
readFileSync
}
from
'fs'
import
{
existsSync
,
readFileSync
,
readdirSync
}
from
'fs'
import
{
OutputStandard
}
from
'../types'
// eslint-disable-line
const
{
spawn
,
execSync
}
=
require
(
'child_process'
)
...
...
@@ -24,6 +24,31 @@ export class SlitherClient extends PluginClient {
this
.
currentSharedFolder
=
currentSharedFolder
}
mapNpmDepsDir
(
list
)
{
const
remixNpmDepsPath
=
`
${
this
.
currentSharedFolder
}
/.deps/npm`
const
localNpmDepsPath
=
`
${
this
.
currentSharedFolder
}
/node_modules`
const
npmDepsExists
=
existsSync
(
remixNpmDepsPath
)
const
nodeModulesExists
=
existsSync
(
localNpmDepsPath
)
let
isLocalDep
=
false
,
isRemixDep
=
false
let
allowPathString
=
''
,
remapString
=
''
for
(
const
e
of
list
)
{
const
importPath
=
e
.
replace
(
/import
[
'"
]
/g
,
''
).
trim
()
const
packageName
=
importPath
.
split
(
'/'
)[
0
]
if
(
nodeModulesExists
&&
readdirSync
(
localNpmDepsPath
).
includes
(
packageName
))
{
isLocalDep
=
true
remapString
+=
`
${
packageName
}
=./node_modules/
${
packageName
}
`
}
else
if
(
npmDepsExists
&&
readdirSync
(
remixNpmDepsPath
).
includes
(
packageName
))
{
isRemixDep
=
true
remapString
+=
`
${
packageName
}
=./.deps/npm/
${
packageName
}
`
}
}
if
(
isLocalDep
)
allowPathString
+=
'./node_modules,'
if
(
isRemixDep
)
allowPathString
+=
'./.deps/npm,'
return
{
remapString
,
allowPathString
}
}
transform
(
detectors
:
Record
<
string
,
any
>
[]):
OutputStandard
[]
{
const
standardReport
:
OutputStandard
[]
=
[]
for
(
const
e
of
detectors
)
{
...
...
@@ -85,10 +110,22 @@ export class SlitherClient extends PluginClient {
}
else
console
.
log
(
'
\
x1b[32m%s
\
x1b[0m'
,
'[Slither Analysis]: Compiler version is same as installed solc version'
)
}
const
outputFile
:
string
=
'remix-slitherReport_'
+
Date
.
now
()
+
'.json'
const
optimizeOption
:
string
=
optimize
?
'--optimize '
:
''
const
evmOption
:
string
=
evmVersion
?
`--evm-version
${
evmVersion
}
`
:
''
const
solcArgs
:
string
=
optimizeOption
||
evmOption
?
`--solc-args '
${
optimizeOption
}${
evmOption
}
'`
:
''
const
cmd
:
string
=
`slither
${
filePath
}
${
solcArgs
}
--json
${
outputFile
}
`
const
fileContent
=
readFileSync
(
`
${
this
.
currentSharedFolder
}
/
${
filePath
}
`
,
'utf8'
)
const
importsArr
=
fileContent
.
match
(
/import
[
'"
][^
.|..
](
.+
?)[
'"
]
;/g
)
let
allowPaths
=
''
,
remaps
=
''
if
(
importsArr
?.
length
)
{
const
{
remapString
,
allowPathString
}
=
this
.
mapNpmDepsDir
(
importsArr
)
allowPaths
=
allowPathString
remaps
=
remapString
.
trim
()
}
const
allowPathsOption
:
string
=
allowPaths
?
`--allow-paths
${
allowPaths
}
`
:
''
const
optimizeOption
:
string
=
optimize
?
' --optimize '
:
''
const
evmOption
:
string
=
evmVersion
?
` --evm-version
${
evmVersion
}
`
:
''
const
solcArgs
:
string
=
optimizeOption
||
evmOption
||
allowPathsOption
?
`--solc-args '
${
allowPathsOption
}${
optimizeOption
}${
evmOption
}
'`
:
''
const
solcRemaps
=
remaps
?
`--solc-remaps "
${
remaps
}
"`
:
''
const
cmd
:
string
=
`slither
${
filePath
}
${
solcArgs
}
${
solcRemaps
}
--json
${
outputFile
}
`
console
.
log
(
'command--->'
,
cmd
)
console
.
log
(
'
\
x1b[32m%s
\
x1b[0m'
,
'[Slither Analysis]: Running Slither...'
)
const
child
=
spawn
(
cmd
,
options
)
const
response
=
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment