Skip to content

Commit dbc28c8

Browse files
authored
Merge pull request #5 from fireeye/feature/file-size-limit
Updated to version 1.0.0. Added the ability to specify how many byte…
2 parents 3f4e8cc + f75eeb5 commit dbc28c8

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

CHANGE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Version 1.0.0
2+
- Changed parameters for submit_file function. Eliminated the "body" parameter since it isn't needed, added "file_name" parameter to name the file, and added parameter "contents" to put the binary contents of the file.
3+
- Added an option to the submit_file function to specify how many bytes from the beginning of a file to send to the detection service. Default is the first 32 MB, but is configurable to any positive integer.

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ To obtain a free trial API key, subscribe on the [AWS Marketplace](https://aws.a
4040

4141
### Upload A File
4242
```python
43-
response = detection.submit_file(
44-
files={
45-
"file": ('filename', open('./path/to/filename', 'rb'))
46-
}
47-
)
43+
response = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"))
44+
```
45+
By default, submit_file() will only send the first 32 MB (32,000,000 bytes) of a file, which is the API limit, but this can be configured by setting the "file_size_limit" option to any positive integer, where the unit is bytes. While you can send more than 32 MB, the API will only use the first 32 MB itself, so this option will save network bandwidth.
46+
```
47+
# Send the first 10 MB of the file
48+
result = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"), file_size_limit=10000000)
4849
```
4950

5051
### Retrieve File Report

fireeyepy/__init__.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import requests
66
import logging
77

8-
__version__ = "0.1.0"
8+
__version__ = "1.0.2"
99
logger = logging.getLogger("fireeye")
1010

1111
class Detection:
@@ -26,11 +26,13 @@ class Detection:
2626
2727
detection = fireeyepy.Detection(key="yourapikeyhere")
2828
29-
result = detection.submit_file(
30-
files={
31-
"file": ("filenamehere.txt", open("path/to/filenamehere.txt", "rb"))
32-
}
33-
)
29+
result = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"))
30+
```
31+
32+
By default, submit_file() will only send the first 32 MB (32,000,000 bytes) of a file, which is the API limit, but this can be configured by setting the "file_size_limit" option to any positive integer, where the unit is bytes. While you can send more than 32 MB, the API will only use the first 32 MB itself, so this option will save network bandwidth.
33+
```
34+
# Send the first 10 MB of the file
35+
result = detection.submit_file(file_name="myfile.txt", contents=open("path/to/myfile.txt", "rb"), file_size_limit=10000000)
3436
```
3537
------------------------------
3638
@@ -72,17 +74,23 @@ def __init__(self,key=None):
7274
self.headers = {"User-Agent": user_agent, "feye-auth-key": key}
7375
self.session = requests.Session()
7476

75-
def submit_file(self, body=None, files=None):
76-
"""Allows you to submit a file object for malware analysis.
77+
def submit_file(self, file_name, contents, file_size_limit=32000000):
78+
"""Allows you to submit a binary file object for malware analysis.
7779
7880
Keyword Arguments:
79-
body {dict} -- The body of your http request. This is optional. (default: {None})
80-
files {io.TextIOWrapper} -- The file you will be submitting for analysis. (default: {None})
81+
file_name {string} -- The name of the file
82+
contents {io.BufferedIOBase} -- The contents of the file in binary
83+
file_size_limit {integer} -- The number of bytes to send to the detection service from the beginning of the file. Files that are smaller than the limit will be sent in their entirety. Files that are larger than this limit will only have the first 'n' bytes sent. Default is 32 MB (32,000,000 bytes).
8184
8285
Returns:
8386
dict -- Returns a dict of the http response.
8487
"""
85-
return self.post(self.api_host, "/files", body, files)
88+
contents.seek(0) # Make sure the file handler is at byte 0 so we can read the next 'n' bytes
89+
files = {
90+
"file": (file_name, contents.read(file_size_limit))
91+
}
92+
93+
return self.post(self.api_host, "/files", None, files)
8694

8795
def get_report(self, report_id, extended=False):
8896
"""Allows you to get the report details for a file or hash submission.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="fireeyepy",
9-
version="0.1.0",
9+
version="1.0.2",
1010
description="FireEye Client Library for Python",
1111
long_description=long_description,
1212
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)