aboutsummaryrefslogtreecommitdiffstats
path: root/examples/addons/commands-flows.py
blob: cebc8f9da2481507166795644ac539af3a6a7545 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import typing

from mitmproxy import command
from mitmproxy import ctx
from mitmproxy import flow


class MyAddon:
    def __init__(self):
        self.num = 0

    @command.command("myaddon.addheader")
    def addheader(self, flows: typing.Sequence[flow.Flow]) -> None:
        for f in flows:
            f.request.headers["myheader"] = "value"
        ctx.log.alert("done")


addons = [
    MyAddon()
]
an> typedef DWORD gDelay; typedef DWORD gTicks; typedef LONG gSemcount; typedef DWORD gThreadreturn; typedef int gThreadpriority; #define DECLARE_THREAD_FUNCTION(fnName, param) gThreadreturn (WINAPI fnName)(void *param) #define DECLARE_THREAD_STACK(name, sz) gU8 name[1]; #define THREAD_RETURN(retval) return retval #define gDelayNone 0 #define gDelayForever INFINITE #define MAX_SEMAPHORE_COUNT ((gSemcount)(((unsigned long)((gSemcount)(-1))) >> 1)) #define gThreadpriorityLow THREAD_PRIORITY_BELOW_NORMAL #define gThreadpriorityNormal THREAD_PRIORITY_NORMAL #define gThreadpriorityHigh THREAD_PRIORITY_ABOVE_NORMAL typedef HANDLE gfxSem; typedef HANDLE gfxMutex; typedef HANDLE gThread; #define gfxExit() ExitProcess(0) #define gfxAlloc(sz) malloc(sz) #define gfxRealloc(p,osz,nsz) realloc(p, nsz) #define gfxFree(ptr) free(ptr) #define gfxSleepMilliseconds(ms) Sleep(ms) #define gfxYield() Sleep(0) #define gfxSystemTicks() GetTickCount() #define gfxMillisecondsToTicks(ms) (ms) #define gfxMutexInit(pmutex) *(pmutex) = CreateMutex(0, FALSE, 0) #define gfxMutexDestroy(pmutex) CloseHandle(*(pmutex)) #define gfxMutexEnter(pmutex) WaitForSingleObject(*(pmutex), INFINITE) #define gfxMutexExit(pmutex) ReleaseMutex(*(pmutex)) #define gfxSemInit(psem, val, limit) *(psem) = CreateSemaphore(0, val, limit, 0) #define gfxSemDestroy(psem) CloseHandle(*(psem)) #define gfxSemWaitI(psem) gfxSemWait((psem), gDelayNone) #define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, 0) #define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, 0) #define gfxThreadMe() GetCurrentThread() #define gfxThreadClose(thread) CloseHandle(thread) /*===========================================================================*/ /* Function declarations. */ /*===========================================================================*/ void gfxHalt(const char *msg); void gfxSleepMicroseconds(gDelay ms); gBool gfxSemWait(gfxSem *psem, gDelay ms); void gfxSystemLock(void); void gfxSystemUnlock(void); gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, DECLARE_THREAD_FUNCTION(*fn,p), void *param); gThreadreturn gfxThreadWait(gThread thread); #endif /* GFX_USE_OS_WIN32 */ #endif /* _GOS_WIN32_H */