ripgrep search
Tested against Windows / Python 3.11 / Anaconda
pip install rgsucher
from rgsucher import rg_search
import numpy as np
# searching in a folder
wholeregex = r"\d+"
imagefile = r"C:\Users\hansc\Documents\fubax\Disable-IPv6\common" # folder
server_ip = rg_search(
regex=wholeregex,
file_or_folder=imagefile,
rgexe=r"C:\ProgramData\chocolatey\bin\rg.exe",
binary=True,
multiline_dotall=False,
multiline=False,
ignore_case=False,
invert_match=False,
case_sensitive=False,
crlf=False,
word_regexp=False,
fixed_strings=False,
)
# searching in a file
allregex = [
r"""\s*<string name=\"server_ip\">\d{3}.\d{3}.\d{3}.\d{3}</string>""",
r"""\s*<string name=\"Defaultserver\">\d{3}.\d{3}.\d{3}.\d{3}</string>""",
r"""\s*<string name=\"server_port\">\d{5}</string>""",
r"""\s*<int name=\"Defaultport\" value=\"\d{5}\" />""",
]
wholeregex = r"(?:(?:" + ")|(?:".join(allregex) + "))"
imagefile = r"C:\ProgramData\BlueStacks_nxt\Engine\Rvc64_42\Data.vhdx" #file
server_ip = rg_search(
regex=wholeregex,
file_or_folder=imagefile,
rgexe=r"C:\ProgramData\chocolatey\bin\rg.exe",
binary=True,
multiline_dotall=False,
multiline=False,
ignore_case=False,
invert_match=False,
case_sensitive=False,
crlf=False,
word_regexp=False,
fixed_strings=False,
add_to_cmd="",
)
# replacing the matches using numpy
import re
print(server_ip)
myip = "112.112.131.121"
myport = "55164"
with open(imagefile, "rb") as f:
imagedata = f.read()
nparray = np.frombuffer(imagedata, dtype=np.uint8).copy()
for k, v in server_ip.items():
for submatch in v["submatches"]:
print(submatch)
original = submatch[0]
new = re.sub(r">\d{3}.\d{3}.\d{3}.\d{3}<", rf">{myip}<", original)
new = re.sub(r">\d{4,5}<", rf">{myport}<", new)
if len(new) > len(original):
new = new[1:]
new = re.sub(r'"\d{4,5}"', rf'"{myport}"', new)
if len(new) > len(original):
new = new[1:]
print(new, original)
replacem = new.encode()
replacemint = list(replacem)
coun = 0
for i in range(submatch[1], submatch[2]):
nparray[i] = replacemint[coun]
coun += 1
with open(imagefile, "wb") as f:
f.write(nparray.tobytes())
Metadata
Release files for rgsucher 0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rgsucher-0.11.tar.gz | 8.0 kB | Without provenance | Details for rgsucher-0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rgsucher-0.11-py3-none-any.whl | Python 3 | none | any | Details for rgsucher-0.11-py3-none-any.whl |
Total release size: 16.7 kB
Release files / rgsucher-0.11.tar.gz
| Download URL | rgsucher-0.11.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0369a418b59c4f57c8713a53b800ef03743adf86597298c2483c48e5cb9b5946
|
|
BLAKE2b-256 checksum How to use checksums |
5b32fb9ff0bef19c05c2782a0e2a25c2b6ab82d49811b1a22135db9007bd815e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / rgsucher-0.11-py3-none-any.whl
| Download URL | rgsucher-0.11-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
32217e9c45212999d1699776d2a0b635d7438f5d2f5bd4a4fe969f1952bf6a85
|
|
BLAKE2b-256 checksum How to use checksums |
408a13aa5319dc69246374f96102ddda6f8ec6d68c6c17f117773d07cde82506
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for rgsucher 0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.