Last active
June 2, 2016 07:35
-
-
Save hasherezade/e539cc05fb55426b3b1965b7de9c679f to your computer and use it in GitHub Desktop.
Converts wide string to string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# CC-BY: hasherezade | |
"""Convert wchar string to char string""" | |
import argparse | |
def convert(data): | |
maxlen = len(data) | |
decoded = bytearray() | |
i = 0 | |
while i < maxlen: | |
dec = data[i] | |
decoded.append(dec) | |
i += 2 | |
return decoded | |
def main(): | |
parser = argparse.ArgumentParser(description="Converts wchar string to char string") | |
parser.add_argument('--file', dest="file", default=None, help="Input file", required=True) | |
args = parser.parse_args() | |
fp = open(args.file, 'rb') | |
if fp is None: | |
print "[-] Failed to open file" | |
return (-1) | |
data = fp.read() | |
fp.close() | |
decoded = convert(data) | |
print decoded | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment