示例#1
0
    def compileInstrumentedFile(self):
        source = self.getCodeFileNameIfExists()
        # Copy original command
        new_cmd = [COMPILER_NAME, '-include', FPCHECKER_RUNTIME
                   ] + self.parameters
        # Replace file by instrumented file
        for i in range(len(new_cmd)):
            p = new_cmd[i]
            if p == source:
                new_cmd[i] = self.instrumentedFile
                break

        # Change output file
        if not self.outputFile:
            fileName, ext = os.path.splitext(source)
            newOutputFile = fileName + '.o'
            new_cmd = new_cmd + ['-o', newOutputFile]

        # Compile
        try:
            if verbose(): prGreen('Compiling: ' + ' '.join(new_cmd))
            cmdOutput = subprocess.run(' '.join(new_cmd),
                                       shell=True,
                                       check=True)
        except Exception as e:
            if verbose():
                prRed(e)
                logMessage(str(e))
                message = 'Could not compile instrumented file'
                logMessage(message)
            raise CompileException(message) from e
示例#2
0
def start_chat(spy):
    spy.name = spy.salutation + " " + spy.name
    if spy.age > 12 and spy.age < 50:
        print "Authentication complete. Welcome " + spy.name + " age: " \
              + str(spy.age) + " and rating of: " + str(spy.rating) + " Proud to have you onboard"
        show_menu = True
        #To Display SpyChat Menu
        while show_menu:
            menu_choices = "What do you want to do? \n 1. Add a status update \n 2. Add a friend \n 3. Send a secret message \n 4. Read a secret message \n 5. Read Chats from a user \n 6. Close Application \n"
            menu_choice = raw_input(menu_choices)
            if len(menu_choice) > 0:
                menu_choice = int(menu_choice)
                if menu_choice == 1:
                    spy.current_status_message = add_status()
                elif menu_choice == 2:
                    number_of_friends = add_friend()
                    prGreen('You have %d friends' % (number_of_friends))
                elif menu_choice == 3:
                    send_message()
                elif menu_choice == 4:
                    read_message()
                elif menu_choice == 5:
                    read_chat_history()
                else:
                    show_menu = False
    else:
        print 'Sorry you are not of the correct age to be a spy'
示例#3
0
    def executePreprocessor(self):
        source = self.getCodeFileNameIfExists()

        # Copy the command parameters
        newParams = self.parameters.copy()

        outputFile = self.getOutputFileIfExists()
        if outputFile:
            self.preprocessedFile = outputFile + '.ii'
            for i in range(len(newParams)):
                p = self.parameters[i]
                if p == '-o' or p == '--output-file':
                    newParams[i + 1] = self.preprocessedFile
                    break
        else:
            self.preprocessedFile = source + '.ii'
            newParams.append('-o')
            newParams.append(self.preprocessedFile)

        new_cmd = [COMPILER_NAME, '-E'] + newParams
        try:
            if verbose(): prGreen(' '.join(new_cmd))
            cmdOutput = subprocess.run(' '.join(new_cmd),
                                       shell=True,
                                       check=True)
        except Exception as e:
            message = 'Could not execute pre-processor'
            if verbose():
                prRed(e)
                logMessage(str(e))
                logMessage(message)
            raise RuntimeError(message) from e

        return True
示例#4
0
文件: tracing.py 项目: LLNL/FPChecker
  def writeToFile(self):
    fileNameRaw = './raw_traces.txt'
    prGreen('Saving raw traces in '+fileNameRaw)
    fd = open(fileNameRaw, 'w')
    for line in self.traced_commands:
      fd.write(line+'\n')
    fd.close()

    fileNameExec = './executable_traces.txt'
    prGreen('Saving executable traces in '+fileNameExec)
    fd = open(fileNameExec, 'w')
    for line in self.traced_commands:
      line = line.split(', [')[1:]
      line = ' '.join(line).split(']')[0]
      line = line.replace(',','')
      line = line.replace('"', '')
      line = line.replace('\\', '')
      if '/sh -c' in line:
        line = ' '.join(line.split()[2:]) # remove /bin/sh -c

      if '-E ' in line: # Remove commands that only run the preprocessor with -E
        continue

      fd.write(line+'\n')
    fd.close()
示例#5
0
    def printTrace(lineNumber: int):
        TraceBackCommand.checkDirectory()

        if int(lineNumber) < 1:
            raise SystemExit('Error: command ID must be >= 1')

        lineNumber = int(lineNumber)
        prGreen('Recreating traces for command: ' + str(lineNumber))

        tracesFile = TRACES_DIR + '/raw_traces.txt'
        if not os.path.isfile(tracesFile):
            raise SystemExit(
                'Error ' + tracesFile +
                ' does not exist. Please record build traces again.')

        trace = None
        with open(tracesFile, 'r') as fd:
            i = 0
            for line in fd:
                i += 1
                if i == lineNumber:
                    trace = ast.literal_eval(line)[1]

        if trace:
            print('Low-level command:')
            print(trace.strip() + '\n')
            print('It may take a few minutes...')
            fileName = TraceBackCommand.getFile(trace)
            #print(fileName)
            if fileName:
                TraceBackCommand.printTree(fileName)
        else:
            raise SystemExit(
                'Error: could not find the command in the trace file')
示例#6
0
    def writeToFile(self):
        fileNameRaw = TRACES_DIR + '/raw_traces.txt'
        prGreen('Saving raw traces in ' + fileNameRaw)
        fd = open(fileNameRaw, 'w')
        for line in self.traced_commands:
            fd.write(str(line) + '\n')
        fd.close()

        fileNameExec = TRACES_DIR + '/executable_traces.txt'
        prGreen('Saving executable traces in ' + fileNameExec)
        fd = open(fileNameExec, 'w')

        for l in self.traced_commands:
            #line = l[1]
            cwd, line = l
            #if l[0] != '':
            #  cwd = l[0].split('"')[1]
            #else:
            #  cwd = '.'

            if cwd != '':
                cwd = cwd.split('"')[1]
            else:
                cwd = '.'

            line = self.formatCommandForExecution(cwd, line)

            fd.write(line + '\n')
        fd.close()
示例#7
0
 def analyzeTraces(self):
     #prveTreeTraversal(root_file)
     prGreen('Searching root PID...')
     root_file = self.getRootFile()
     print('root:', root_file)
     prGreen('Analyzing traces...')
     self.recursiveTreeTraversal(root_file, '')
示例#8
0
def get_recent_like(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/likes') % (media_id)
    payload = {"access_token": APP_ACCESS_TOKEN}
    print 'POST request url : %s\n' % (request_url)
    post_a_like = requests.post(request_url, payload).json()
    if post_a_like['meta']['code'] == 200:
        prGreen('Like was successful!')
    else:
        prRed('Your like was unsuccessful. Try again!')
示例#9
0
def punkty_krzywej(A, B, p):
    warunek = 0
    while warunek != 1:
        punkt_x = randint(0, p - 1)  # Losowanie punktu
        f = (punkt_x**3 + A * punkt_x + B) % p  # Obliczenie F
        warunek = pow(f, (p - 1) // 2, p)  # Czy jest spełniony warunek

    punkt_y = pow(f, (p + 1) // 4, p)
    prGreen("{Obliczony punkt P: " + f"{(punkt_x, punkt_y)}")
    sprawdzenie_oraz_wypisanie_E(A, B, p, punkt_y, punkt_x)
    return (punkt_x, punkt_y)
示例#10
0
def get_comment_list(insta_username):
    media_id = get_post_id(insta_username)
    request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (media_id, APP_ACCESS_TOKEN)
    print 'GET request url : %s \n' % (request_url)
    comment_info = requests.get(request_url).json()

    if comment_info['meta']['code'] == 200:
        if len(comment_info['data']):
            for x in range(0, len(comment_info['data'])):
                comment_id = comment_info['data'][x]['id']
                comment_text = comment_info['data'][x]['text']
                print comment_text
            prGreen('Successfully generated COMMENTS')
        else:
            prRed('No comments found')
示例#11
0
def execTraces():
    checkTraceFileExists()
    fileName = getTraceFileName()
    prGreen('Executing commands from ' + fileName)
    fd = open(fileName, 'r')
    allLines = fd.readlines()
    fd.close()

    i = 1
    total = str(len(allLines))
    for cmd in allLines:
        try:
            print(str(i) + '/' + total + ': ' + cmd[:-1])
            cmdOutput = subprocess.check_output(cmd,
                                                stderr=subprocess.STDOUT,
                                                shell=True)
        except subprocess.CalledProcessError as e:
            sys.exit('FPCHECKER: error: ' + cmd)
        i = i + 1
示例#12
0
def generuj_krzywa_eliptyczna(len):
    Delta = 0
    while Delta == 0:
        p = losowanie_liczby_p(len)
        prGreen("{Wylosowana liczba p: " + f"{p}")
        A = randint(0, p - 1)
        prGreen("{Wylosowana liczba A: " + f"{A}")
        B = randint(0, p - 1)
        prGreen("{Wylosowana liczba B: " + f"{B}")
        Delta = (4 * (A**3) + 27 * B**2) % p
        prGreen("{Delta: " + f"{Delta}")

    return (A, B, p)
示例#13
0
def sprawdzenie_oraz_wypisanie_E(A, B, p, punkt_y, punkt_x):
    lewa = (punkt_y**2) % p
    prawa = ((punkt_x**3) + A * punkt_x + B) % p
    prGreen("{Obliczone E: " + f"{lewa}" + " = " + f"{prawa}")
示例#14
0
        help=
        'Do not rollback to compiling with nvcc if clang failes to compile CUDA.'
    )
    parser.add_argument('--replay-command',
                        type=int,
                        metavar='N',
                        help='Replay a given command')
    parser.add_argument('--debug-command',
                        type=int,
                        metavar='N',
                        help='Print trace of specific command')
    args = parser.parse_args()
    #print(args)
    #exit()

    prGreen('FPChecker')

    loadConfigFile()

    if args.no_rollback:
        ROLLBACK_TO_NVCC = False

    if args.no_clang:
        USE_EXPR_PARSER = True

    if args.no_subnormal:
        NVCC_ADDED_FLAGS.append('-DFPC_DISABLE_SUBNORMAL')

    if args.no_warnings:
        NVCC_ADDED_FLAGS.append('-DFPC_DISABLE_WARNINGS')
示例#15
0
文件: tracing.py 项目: LLNL/FPChecker
 def printStdOut(self, line):
   if 'write(1' in line:
     if 'Building' in line or 'Linking' in line:
       l = line.split(', ')[1].replace('"','')
       prGreen(l)