Information Gathering

Hardcodes – Find Hardcoded Strings From Source Code

Hardcodes - Find Hardcoded Strings From Source Code


hardcodes is a utility for searching strings hardcoded by developers in programs. It uses a modular tokenizer that can handle comments, any number of backslashes & nearly any syntax you throw at it.
Yes, it is designed to process any syntax and following languages are officially supported:

ada, applescript, c, c#, c++, coldfusion, golang, haskell, html, java, javascript,
jsp, lua, pascal, perl, php, powershell, python, ruby, scala, sql, swift, xml


with pip

pip3 install hardcodes

or build from source

git clone && cd hardcodes && python3 install

For Developers
The sample program below demonstrates usage of hardcodes library

from hardcodes import search
string = "console.log('hello there')"
result = search(string, lang="common", comments="parse")
Output: ['hello there']

The arguments lang and comments are optional. Their use is explained below in the user documentation section.

For Users provides a grep-like command line interface to hardcodes library. You will need to install the library first to use it.

Find strings in a file

python /path/to/file.ext

Find strings in a directory, recursively

python -r /path/to/dir

Hide paths from output

python -o /path/to/file.ext

Specify programming language
Specifying a language is optional and should be used only when the programming language of source is already known.

python -l 'golang' /path/to/file.go

Specify comment behaviour
With -c option, you can specify

  • ignore ignore the comments completely
  • parse parse the comments like code
  • string add comments to list of hardcoded strings

python -o /path/to/file.ext


About the author

Mazen Elzanaty

Add Comment

Click here to post a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: