# Hardcodes | Find Hardcoded Strings From Source Code

**URL:** <https://onehack.st/t/hardcodes-find-hardcoded-strings-from-source-code/105119>\
**Category:** Tools & Scripts\
**Tags:** programming\
**Created:** [September 7, 2020, 1:46pm UTC](https://onehack.st/t/hardcodes-find-hardcoded-strings-from-source-code/105119 "2020-09-07T13:46:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prometheus](https://onehack.st/user_avatar/onehack.st/prometheus/32/34950_2.png) [@Prometheus](https://onehack.st/u/Prometheus)\
**Post date:** [September 7, 2020, 1:46pm UTC](https://onehack.st/t/hardcodes-find-hardcoded-strings-from-source-code/105119/1 "2020-09-07T13:46:04Z")

</div>

![image](https://onehack.st/uploads/default/original/3X/c/2/c288eb07154e4e8217b309b59ad7388defba8abf.png)

**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:

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

```

**Installation**

**with pip**

```auto
pip3 install hardcodes

```

**or build from source**

```auto
git clone https://github.com/s0md3v/hardcodes && cd hardcodes && python3 setup.py install

```

**For Developers**  
The sample program below demonstrates usage of `hardcodes` library

```auto
from hardcodes import searchstring = "console.log('hello there')"result = search(string, lang="common", comments="parse")print(result)

```

```auto
Output: ['hello there']

```

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

**For Users**  
`cli.py` 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**

```auto
python cli.py /path/to/file.ext

```

**Find strings in a directory, recursively**

```auto
python cli.py -r /path/to/dir

```

**Hide paths from output**

```auto
python cli.py -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.

```auto
python cli.py -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 cli.py -o /path/to/file.ext`

## GitHub:

> **[GitHub - s0md3v/hardcodes: find hardcoded strings from source code](https://github.com/s0md3v/hardcodes)**
>
> find hardcoded strings from source code
