ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • PE Viewer Python 오픈소스
    Python 2015. 8. 6. 20:10
    import pefile
    import os
    
    print """
        #
        ##
        ###
        ####
         #####
         #######
          #######
          ########
          ########
          #########
          ##########
         ############
        ##############
        ################
        ################
         ##############
          ##############                                              ####
          ##############                                           #####
           ##############                                      #######
           ##############                                 ###########
           ###############                              #############
           ################                           ##############
          #################      #                  ################
          ##################     ##    #           #################
         ####################   ###   ##          #################
              ################  ########          #################
               ################  #######         ###################
                 #######################       #####################
                  #####################       ###################
                    ############################################
                     ###########################################
                     ##########################################
                      ########################################
                      ########################################
                       ######################################
                       ######################################
                        ##########################      #####
                        ###  ###################           ##
                        ##    ###############
                        #     ##  ##########   dD
                                  ##    ###
                                        ###
              The DoubleS               ##
              System Project Team       # 
              """
    
    def file_header(command):
        if(command == "machine"):
            print pe.FILE_HEADER.Machine
    
        elif(command == "numsection"):
            print pe.FILE_HEADER.NumberOfSections
    
        elif(command == "timestamp"):
            print pe.FILE_HEADER.TimeDateStamp
    
        elif(command == "szoption"):
            print pe.FILE_HEADER.SizeOfOptionalHeader
    
        else:
            optional_header(command)
    
    
    def optional_header(command):
        if(command == "szcode"):
            print pe.OPTIONAL_HEADER.SizeOfCode
    
        elif(command == "epaddr"):
            print pe.OPTIONAL_HEADER.AddressOfEntryPoint
    
        elif(command == "imgbase"):
            print pe.OPTIONAL_HEADER.ImageBase
        elif(command == "dllchar"):
            print pe.OPTIONAL_HEADER.DllCharacteristics
        else:
            section_header(command)
    
    
    def section_header(command):
        if(command == "secname"):
            for section in pe.sections:
                print section.Name
    
        elif(command == "secva"):
            for section in pe.sections:
                print section.Name, hex(section.VirtualAddress)
    
        elif(command == "secraw"):
            for section in pe.sections:
                print section.Name, section.SizeOfRawData
    
        else:
            fix(command)
    
    
    def fix(command):
        if(command == "fiximg"):
            imagebase = raw_input("Input Value: ")
            pe.OPTIONAL_HEADER.ImageBase = imagebase
    
        elif(command == "fixepaddr"):
            epaddr = raw_input("Input Value: ")
            pe.OPTIONAL_HEADER.AddressOfEntryPoint = epaddr
    
        else:
            etc(command)
    
    
    def etc(command):
        if(command == "exit"):
            exit()
    
        elif(command == "clear"):
            os.system("clear")
    
        elif(command == "cls"):
            os.system("cls")
        elif(command == "dump"):
            print pe.dump_info()
        elif(command == "textdump"):
            print pe.get_memory_mapped_image()
        elif(command == "help"):
            print """
            ----------------------------------------------------------
            |      Command                        Comment            |
            ----------------------------------------------------------
            |                  IMAGE_FILE_HEADER                     |
            ----------------------------------------------------------
            |    machine                    Show SizeOfCode          |
            |    numsection                 Show NumberOfSections    |
            |    timestamp                  Show TimeDateStamp       |
            |    szoption                   Show SizeOfOptionalHeader|
            ----------------------------------------------------------
            |                IMAGE_OPTIONAL_HEADER                   |                             
            ----------------------------------------------------------
            |    szcode                     Show SizeOfCode          |                                   
            |    epaddr                     Show AddressOfEP         |
            |    imgbase                    Show ImageBase           |
            |    dllchar                    Show DllCharacteristics  |
            ----------------------------------------------------------
            |                 IMAGE_SECTION_HEADER                   |
            ----------------------------------------------------------
            |    secname                    Show Name of Sections    |
            |    secva                      Show VA of Sections      |
            |    secraw                     Show SizeOfRawData       |
            ----------------------------------------------------------
            |                          Fix                           |
            ----------------------------------------------------------
            |    fiximg                     fix Value of ImageBase   |
            |    fixepaddr                  fix Value of EP Address  |
            ----------------------------------------------------------  
            |                          Etc                           |
            ----------------------------------------------------------
            |    clear                      Linux User clear         |
            |    cls                        Windows User clear       |
            |    exit                       Exit the program         |
            |    help                       Show Command             |
            ----------------------------------------------------------"""
    
        elif(len(command) == 0):
            pass
    
        else:
            print "DoubleS:" +"'"+command+"'"+" Command is not found"
    
    
    selectpro = raw_input("Input ProgramName: ")
    pe = pefile.PE(selectpro)
    
    while(1):
        command = raw_input("DoubleS@PE:")
        file_header(command)


    'Python' 카테고리의 다른 글

    명령실행후 결과값 split하기  (0) 2015.09.06
    Python <<< redirect error  (0) 2015.09.03
    DLL Injector  (4) 2015.01.28
    Download from URL  (0) 2015.01.22
    Python PortScanner  (0) 2015.01.22

    댓글

Designed by Tistory.