Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yara-python
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
yara-python
Commits
4182b51b
Commit
4182b51b
authored
Sep 15, 2015
by
Victor M. Alvarez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow building yara-python with libyara statically linked
parent
3a9aaef3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
21 deletions
+131
-21
MANIFEST
MANIFEST
+0
-3
config.h
config.h
+4
-0
setup.cfg
setup.cfg
+3
-0
setup.py
setup.py
+124
-18
No files found.
MANIFEST
deleted
100644 → 0
View file @
3a9aaef3
README
setup.py
yara-python.c
config.h
0 → 100644
View file @
4182b51b
/*
This a dummy file to satisfy some #include "config.h" directives while
building libyara.
*/
setup.cfg
0 → 100644
View file @
4182b51b
[metadata]
description-file = README.md
\ No newline at end of file
setup.py
View file @
4182b51b
...
...
@@ -14,27 +14,133 @@
# limitations under the License.
#
from
distutils.command.build
import
build
from
setuptools
import
setup
,
Extension
import
distutils.errors
import
distutils.ccompiler
import
distutils.sysconfig
import
contextlib
import
os
import
sys
from
distutils.core
import
setup
,
Extension
import
tempfile
import
shutil
import
subprocess
@contextlib.contextmanager
def
muted
(
*
streams
):
"""A context manager to redirect stdout and/or stderr to /dev/null.
Examples:
with muted(sys.stdout):
...
with muted(sys.stderr):
...
with muted(sys.stdout, sys.stderr):
...
"""
devnull
=
open
(
os
.
devnull
,
'w'
)
try
:
old_streams
=
[
os
.
dup
(
s
.
fileno
())
for
s
in
streams
]
for
s
in
streams
:
os
.
dup2
(
devnull
.
fileno
(),
s
.
fileno
())
yield
finally
:
for
o
,
n
in
zip
(
old_streams
,
streams
):
os
.
dup2
(
o
,
n
.
fileno
())
devnull
.
close
()
def
has_function
(
function_name
,
libraries
=
None
):
compiler
=
distutils
.
ccompiler
.
new_compiler
()
with
muted
(
sys
.
stdout
,
sys
.
stderr
):
result
=
compiler
.
has_function
(
function_name
,
libraries
=
libraries
)
return
result
class
BuildCommand
(
build
):
user_options
=
build
.
user_options
+
[
(
'static'
,
's'
,
'build libyara statically into yara-python module'
),
(
'enable-cuckoo'
,
None
,
'enable "cuckoo" module (use with --static)'
),
(
'enable-magic'
,
None
,
'enable "magic" module (use with --static)'
),
(
'enable-profiling'
,
None
,
'enable profiling features'
)]
args
=
sys
.
argv
[
1
:]
macros
=
[
]
boolean_options
=
build
.
boolean_options
+
[
'static'
,
'enable-cuckoo'
,
'enable-magic'
,
'enable-profiling'
]
if
'--with-profiling'
in
args
:
macros
.
append
((
'PROFILING_ENABLED'
,
'1'
))
args
.
remove
(
'--with-profiling'
)
def
initialize_options
(
self
):
build
.
initialize_options
(
self
)
self
.
static
=
None
self
.
enable_magic
=
None
self
.
enable_cuckoo
=
None
self
.
enable_profiling
=
None
setup
(
script_args
=
args
,
name
=
'yara-python'
,
version
=
'3.4.0'
,
author
=
'Victor M. Alvarez'
,
author_email
=
'plusvic@gmail.com;vmalvarez@virustotal.com'
,
ext_modules
=
[
Extension
(
def
finalize_options
(
self
):
build
.
finalize_options
(
self
)
if
self
.
enable_magic
and
not
self
.
static
:
raise
distutils
.
errors
.
DistutilsOptionError
(
'--enable-magic must be used with --static'
)
if
self
.
enable_cuckoo
and
not
self
.
static
:
raise
distutils
.
errors
.
DistutilsOptionError
(
'--enable-cuckoo must be used with --static'
)
def
run
(
self
):
sources
=
[
'./yara-python.c'
]
exclusions
=
[
'pe_utils.c'
]
libraries
=
[
'yara'
]
include_dirs
=
[]
macros
=
[]
if
has_function
(
'memmem'
):
macros
.
append
((
'HAVE_MEMMEM'
,
'1'
))
if
has_function
(
'strlcpy'
):
macros
.
append
((
'HAVE_STRLCPY'
,
'1'
))
if
has_function
(
'strlcat'
):
macros
.
append
((
'HAVE_STRLCAT'
,
'1'
))
if
self
.
enable_profiling
:
macros
.
append
((
'PROFILING_ENABLED'
,
'1'
))
if
self
.
static
:
libraries
=
[]
include_dirs
=
[
'yara/libyara/include'
,
'yara/libyara/'
,
'.'
]
if
self
.
enable_magic
:
macros
.
append
((
'MAGIC'
,
'1'
))
else
:
exclusions
.
append
(
'magic.c'
)
if
self
.
enable_cuckoo
:
macros
.
append
((
'CUCKOO'
,
'1'
))
else
:
exclusions
.
append
(
'cuckoo.c'
)
for
directory
,
_
,
files
in
os
.
walk
(
'yara/libyara/'
):
for
x
in
files
:
if
x
.
endswith
(
'.c'
)
and
x
not
in
exclusions
:
sources
.
append
(
os
.
path
.
join
(
directory
,
x
))
self
.
distribution
.
ext_modules
=
[
Extension
(
name
=
'yara'
,
sources
=
[
'yara-python.c'
],
libraries
=
[
'yara'
],
include_dirs
=
[
'../libyara/include'
],
library_dirs
=
[
'../libyara/.libs'
],
sources
=
sources
,
include_dirs
=
include_dirs
,
libraries
=
libraries
,
define_macros
=
macros
,
extra_compile_args
=
[
'-std=gnu99'
]
)])
extra_compile_args
=
[
'-std=gnu99'
,
'-Wno-deprecated-declarations'
])]
build
.
run
(
self
)
setup
(
name
=
'yara-python'
,
version
=
'3.4.1'
,
author
=
'Victor M. Alvarez'
,
author_email
=
'plusvic@gmail.com;vmalvarez@virustotal.com'
,
url
=
'https://github.com/plusvic/yara-python'
,
cmdclass
=
{
'build'
:
BuildCommand
},
data_files
=
[
'./config.h'
])
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