Article may be outdated

This article is 5 days old. Some details may have changed since publication.

Hacker News·5 min read·hard

Paths in Pieces

A
acossta
✦AI Summary

This technical analysis explains why standard binary auditing tools fail to detect absolute paths in C++ binaries compiled with modern GCC versions. The compiler optimizes string handling by vectorizing data, which obscures the original file paths from simple string-searching utilities.

Why it matters

Understanding these compiler optimizations is critical for developers and security researchers who rely on binary analysis for debugging and auditing software distribution.

✦Dive DeeperCreate a free account to unlock

Many [1] [2] [3] [4] [5] [6] [7] [8] [9] Linux distributions and package managers audit just-built binaries for non-relocatable absolute paths. If a binary contains a path /path/from/build/machine , it might not run on the end-user's machine.

Now, a basic grep on the binary, or a slightly more sophisticated

$ strings bin/app | grep /path/from/build/machine using GNU binutils's strings will detect these paths, right?

The answer is no , at least when using GCC and targeting x86-64 : you should not assume that string constants end up literally in the binary.

In this C++ source we create a std::string from a string constant:

#include <iostream> #include <string> #define PREFIX "/home/linuxbrew/.linuxbrew" int main() { std::string prefix{PREFIX}; std::cout << prefix << '\n'; } Compile with GCC 12 or later and run, which prints the path:

Continue reading on Headlinne

Create a free account to read the full article.

Read full article →
technologyscience
✦

Get smarter about the news

Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.

Create free account

Already have an account? Sign in