import sys

def extract_strings_from_exe(file_path, offsets):
    strings = []
    for start_offset, end_offset in offsets:
        with open(file_path, 'rb') as f:
            f.seek(start_offset)
            data = f.read(end_offset - start_offset)
        
        current_string = []
        i = 0
        while i < len(data):
            byte = data[i]
            if byte == 0:
                strings.append(''.join(current_string))
                current_string = []
            elif byte == 0x0A and i + 1 < len(data) and data[i + 1] == 0x0D:
                current_string.append('/n/r')
                i += 1  # Skip next byte 0x0D
            elif byte == 0x0A:
                current_string.append('/n')
            elif byte == 0x0D:
                current_string.append('/r')
            else:
                current_string.append(chr(byte))
            i += 1
    return strings

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python extract_strings.py <path_to_exe>")
        sys.exit(1)
    
    file_path = sys.argv[1]
    offsets = [
        (0xa872, 0xa944), (0xaa77, 0xaa7c), (0xaa8f, 0xaa96),
        (0xaaa9, 0xaab3), (0xaac6, 0xaaf5), (0xab09, 0xabe1),
        (0xac76, 0xaf73), (0xb51f, 0xb52e), (0xb541, 0xb57a),
        (0xe9a6, 0xefe8), (0xf124, 0xf7fe)
    ]
    # (0x9cdc, 0x9cf0), (0x9d00, 0xa9d0e), (0x9d33, 0x9d4e)

    strings = extract_strings_from_exe(file_path, offsets)
    
    output_file = file_path + ".txt"
    with open(output_file, 'w', encoding='CP852', errors='ignore') as f:
        for s in strings:
            f.write(s + '\n')
    
    print(f"Extracted strings have been saved to {output_file}")