question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON mode has spurious prints in Python 3

See original GitHub issue

Description

When running CAPA in JSON mode (-j) on a file and redirecting the output to a file, the output contains spurious lines that make the output not valid JSON.

Steps to Reproduce

  1. capa -j <file> > out.json
  2. python -m json.tool out.json

Expected behavior:

Pretty printed JSON.

Actual behavior:

Invalid JSON. The first three lines are:

 is not an ELF
 is not an ELF
 is not an ELF

I think these are from the lief dependency (from SMDA):

https://github.com/lief-project/LIEF/blob/b49786fd039a1cf5173d5e6d02a36481aa730a47/src/ELF/Parser.cpp#L158

Versions

# capa --version
capa 1.4.0

I just built from master (50d55f) so the version string appears wrong.

Additional Information

I think we just need to make sure that LIEF_ERR goes to stderr and not stdout.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jcrussellcommented, Jan 4, 2021

Fixed when using LIEF master. There’s no tagged release yet though so users will encounter this unless they are also using LIEF master.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON mode has spurious prints in Python 3 · Issue #368
When running CAPA in JSON mode ( -j ) on a file and redirecting the output to a file, the output contains spurious...
Read more >
Working With JSON Data in Python
In this tutorial you'll learn how to read and write JSON-encoded data using Python. You'll see hands-on examples of working with Python's built-in...
Read more >
python library 'json' prints everything twice
The program is just this: import json jsonFile = open('TODO.json','r').read() print(jsonFile). This prints the string twice.
Read more >
Pretty Print a JSON File in Python (6 Methods)
Learn how to use Python to pretty print a JSON object, including from a file, from an API, and how to save the...
Read more >
Changelog — Python 3.11.1 documentation
Paths are no longer encoded to UTF-8/strict to avoid encoding errors if it contains surrogate characters (bytes paths are decoded with the surrogateescape...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found