How to use GetSystemTimeAsFileTime method in pytest-benchmark

Best Python code snippet using pytest-benchmark

date_spoof.py

Source:date_spoof.py Github

copy

Full Screen

1# Script to spoof the date and time of a selected application2# Works by intercepting calls to GetSystemTimeAsFileTime and instead returning our spoofed time3import datetime4import frida5import os6import psutil7import tkinter as tk8from subprocess import Popen9from threading import Lock, Thread10from time import localtime, sleep, time11from tkinter import filedialog12# file dialog window13root = tk.Tk()14root.withdraw()15# user input16# convert iso date input into datetime17target = datetime.datetime.fromisoformat(input("Date String (ISO 8601): "))18# open file dialog to select application19print("Select Application")20target_path = filedialog.askopenfilename()21# split path into application and directory22target_application = target_path.split("/")[-1]23target_dir = target_path.replace(target_application,"")24# move to the directory of the application before running25os.chdir(target_dir)26# ask for debug information27debug = int(input("Debug? (1/0): "))28# run application29Popen(target_path)30# check for daylight savings time31ts = time()32dst = localtime().tm_isdst33# get the users timezone offset from utc34utc_offset = (datetime.datetime.fromtimestamp(ts) - datetime.datetime.utcfromtimestamp(ts))35# windows FILETIME epoch 36epoch = datetime.datetime(1601,1,1) + utc_offset37# convert to nanoseconds/100 (highest precision possible)38ns = ((target-epoch) / datetime.timedelta(microseconds=1)) * 1039# account for dst40ns += 10000000 * 60 * 60 * dst41# convert from float to int42ns = int(ns)43print(ns)44# set up lock45lock_session = Lock() 46def GetSystemTimeAsFileTime_hook(session):47 # listen for GetSystemTimeAsFileTime48 # on call, get the address for the FILETIME object, write our spoofed time to its location49 script = session.create_script("""50 var GetSystemTimeAsFileTime = Module.findExportByName("kernel32.dll", 'GetSystemTimeAsFileTime') // exporting the function51 Interceptor.attach(GetSystemTimeAsFileTime, { // get our pointer52 onEnter: function (args) {53 this.pointer = args[0];54 },55 onLeave: function (args) { // write our spoofed time56 send(this.pointer.writeU64(""" + str(ns) + """));57 }58 });59 """)60 # if called run log function61 script.on('message', log)62 script.load()63def log(message, data):64 # this runs whenever the application calls GetSystemTimeAsFileTime65 # print address FILETIME object66 if debug:67 print(message['payload'])68def wait_for_application():69 while True:70 # find the process71 if (target_application in (p.name() for p in psutil.process_iter())) and not lock_session.locked():72 lock_session.acquire() # Locking the thread73 print("process found")74 attach_and_hook()75 sleep(0.5)76 elif (not target_application in (p.name() for p in psutil.process_iter())) and lock_session.locked():77 lock_session.release()78 print("process is dead releasing lock")79 else:80 pass81 sleep(0.5)82def attach_and_hook():83 try:84 # attaching to the process85 print("trying to attach to process")86 session = frida.attach(target_application)87 print("attached successfully")88 # hook GetSystemTimeAsFileTime89 GetSystemTimeAsFileTime_hook(session)90 except Exception as e:91 print(str(e))92if __name__ == "__main__":93 thread = Thread(target=wait_for_application)...

Full Screen

Full Screen

ctypes_cfunctype_promptt0.6000000000000001_pp1.0_fp1.0_11.py

Source:ctypes_cfunctype_promptt0.6000000000000001_pp1.0_fp1.0_11.py Github

copy

Full Screen

1import ctypes2# Test ctypes.CFUNCTYPE()3#4# Let's try to call the Win32 GetSystemTimeAsFileTime() function, which5# has the following signature:6#7# void GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)8#9# where FILETIME is defined as:10#11# typedef struct _FILETIME {12# DWORD dwLowDateTime;13# DWORD dwHighDateTime;14# } FILETIME, *PFILETIME;15#16# NOTE: The lpSystemTimeAsFileTime parameter is a pointer to the above17# structure, so we'll need to pass a pointer to a FILETIME structure.18# OTOH, the GetSystemTimeAsFileTime() function has no return value, so19# we'll use the ctypes.Void pointer type.20#21# NOTE: We need to use the ctypes.Structure class to create the FILETIME22# structure. In addition, we need to use the ctypes.Union class to create23# the LPFILETIME pointer. We'll define both classes below.24#...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful