PyInstaller创建一个标记为特洛伊木马的exe

2024-09-30 16:29:09 发布

您现在位置:Python中文网/ 问答频道 /正文

像往常一样,当我学习一门新的编程语言时,我会做一个愚蠢的游戏,然后用很多不必要的东西来拉皮条。只是为了学习什么是可能的以及语法是如何工作的。在这之后,我正在寻找一种方法来编译成一个.exe文件。完成PyInstaller。.exe可以像预期的那样完美地工作

我将它发送给一个朋友,以检查这个.exe是否独立并且在没有安装Python解释器的情况下工作。他给我发了一张他的windows10的照片,因为它在我的文件中检测到一个特洛伊木马

我检查了我的系统。我这边没有感染。 然后我把.exe上传到Virustotal。结果如下: https://www.virustotal.com/gui/file/3fa6cbe0c5cb154d70d3db1ca3029a9010853a87241a3b52cb30b4c23f55d729/detection

通常我不会在意一个文件在67次点击中有9次上升,其中大部分只是猜测。但在本例中,一个.exe仅用于一个目的。那就是窗户

代码如下:

from random import randint as rInt
import time
import logging

game = {"winNumber": rInt(1, 100), "guessedNumber": 0, "lastGuess": 0, "tries": 8, "triesLeft": 8, "state": "None", "won": 0, "lost": 0, "round": 1, "debugMode": False}

def checkInput(uInput):
    """Checks user Inputs if they are valid numbers. Then a second check if the number is in between 1 and 100. Returns TRUE if successfull"""
    try:
        uInput = int(uInput)
    except ValueError:
        logger.info(f"User has tried to enter: {uInput} and failed.")
        print("This is not a number!")
    else:
        if uInput not in range(1, 101):
            print("With this number you will definitely loose the game, because it is not between 1 and 100")
            logger.info(f"User has entered the Number {uInput}")
        else:
            game["guessedNumber"] = uInput
            return True


def restartGame():
    answer = input ("Do you want to play again? (y/n)")
    if answer.lower() == "y":
        print ("Leeeeet's get ready tooooo guess some numbers!")
        game["triesLeft"] = 8
        game["lastGuess"] = 0
        game["state"] = "begin"
        game["winNumber"] = rInt(1, 100)
        game["guessedNumber"] = 0
        game["round"] += 1
        time.sleep(2)
        theGameItself()
    else:
        logger.info(f'User exits the Game after: Rounds: {game["round"]} Wins: {game["won"]} Losts: {game["lost"]}')
        print ("Have a nice day!")
        time.sleep(2)
        exit()


def turnLogic():
    """ Checks if the next Turn, made by the Player is a legit turn in logical terms"""
    if game["winNumber"] < game["lastGuess"] and game["guessedNumber"] < game["lastGuess"]:
        game["state"] = "Legit Turn"
    elif game["winNumber"] > game["lastGuess"] and game["guessedNumber"] > game["lastGuess"]:
        game["state"] = "Legit Turn"
    elif game["winNumber"] < game["lastGuess"] and game["guessedNumber"] > game["lastGuess"] and game["lastGuess"] != 0:
        game["state"] = "Bad Turn"
        logger.info("User has triggered up 0")
        checkIdiot(0)
    elif game["winNumber"] > game["lastGuess"] and game["guessedNumber"] < game["lastGuess"] and game["lastGuess"] != 0:
        game["state"] = "Bad Turn"
        logger.info("User has triggered up 1")
        checkIdiot(1)
    elif game["guessedNumber"] == game["lastGuess"] and game["lastGuess"] != 0:
        game["state"] = "Bad Turn"
        logger.info("User has triggered up 2")
        checkIdiot(2)


def checkIdiot(up):
    """This function checks if the player don't read the text. It will apply some educative messures"""
    if up == 0:
        print(f'Really? I said the Number must be LOWER then {game["lastGuess"]} and now you come with {game["guessedNumber"]}?')
        print("That misbehavior will be punished with a loss of one additional try. You deserve it!\n")
        game["triesLeft"] -= 1
    elif up == 1:
        print (f'Really? I just told you that the number must be higher after you go for {game["lastGuess"]} and now you try {game["guessedNumber"]}?')
        print ("That misbehavior will be punished with a loss of one additional try. You deserve it!\n")
        game["triesLeft"] -= 1
    elif up == 2:
        print (f'.. yeah.. you guessed {game["guessedNumber"]} and last time you guessed {game["lastGuess"]}. Do you know whats the definiton of insanity?')
        print ("Insanity means doing the same things over and over again and expecting a different result.")
        print ("But you made it. The difference is, you have wasted one try!\n")


def debugMode():
    print(f'DEBUG MODE:\n |'
          f'Last guessed Number: {game["lastGuess"]}.\n |'
          f'New guessed number is: {game["guessedNumber"]}\n |'
          f'Win number is: {game["winNumber"]}\n |'
          f'Game State is: {game["state"]}\n |'
          f'Round: {game["round"]}\n |'
          f'Wins: {game["won"]}\n |'
          f'Losts: {game["lost"]}\n'
          f'{40 * "-"}\n')
    game["triesLeft"] = 999


def theGameItself():
    logger.info("User start a new game..")
    if game["debugMode"] == True:
        logger.info(".. in DEBUG Mode")
    while game["triesLeft"] > 0:
        game["lastGuess"] = game["guessedNumber"]
        riskyInput = input("\nPlease enter a number between 1 and 100: ")
        if checkInput(riskyInput) == False:
            continue
        else:
            print (40 * "-")
            print (f'Thank you for choosing the Number: {game["guessedNumber"]}')
            print(f'\nLet me see if you are correct..')
            print (40 * "-")
            if game["debugMode"] == True:
                debugMode()
            game["triesLeft"] -= 1
            time.sleep(1.5)

            if game["guessedNumber"] > game["winNumber"]:
                turnLogic()
                print ("Sorry, your Number is too big! Please try again!")
                print(f'You have {game["triesLeft"]} tries left!')
                continue

            elif game["guessedNumber"] < game["winNumber"]:
                turnLogic()
                print ("Sorry, the Number you've called is te.. oh wait.. its just to small. But try again!")
                print(f'You have {game["triesLeft"]} tries left!')
                continue

            else:
                print("Congratulations. You made it!")
                game["won"] += 1
                logger.info(f'User won a game. With {game["triesLeft"]} tries left.')
                restartGame()

    if game["triesLeft"] <= 0:
        print(f'It seems that you have lost the game because you are running out of tries. The correct Number was: {game["winNumber"]}')
        game["lost"] += 1
        logger.info(f'User lost a game. Win Number was: {game["winNumber"]}')
        restartGame()

LOG_FORMAT = "%(levelname)s: %(asctime)s - %(message)s"
logging.basicConfig(filename="outputlog.log", level=logging.DEBUG, format=LOG_FORMAT)
logger = logging.getLogger()
theGameItself()

所以,如果我做一些严肃的事情呢。把它寄给顾客。如果客户成为特洛伊木马警告,我的整个公司可能会遇到问题。 这意味着,我需要一个解决方案,然后才能使用Python进行生产

有人有办法吗?提前谢谢


Tags: andtheinfoyougameifislogger