• About TV's server
  • New in version 3.10
  • About the source code
  • About protocols/plugins
  • TV's server API
  • Protocol Initialisation
  • Protocol binding
  • Protocol Listening and handling
  • Protocol data storage
  • Control panel
  • Multi column list
  • Time and date
  • Http protocol functions
  • Unimplemented and/or replaced functions
  • Source code

    index About source code
    TV's server is written in assembler and was last successfully compiled with Flat Assembler (Fasm) version 1.73.09. The source is written to be able to be compiled for intel x86 and amd64 (read macros for more information about how this is done). The source is written for windows, however, all the windows API calls are made in source files in directory 'windows' to be able to be ported to other systems in the furture.

    Macros
    The source is written for both intel x86 and AMD64 processors. This was possible because of some macros created for this project. These macros are defined in file "Use32.inc" (32-bit macros) and "Use64.inc" (64-bit macros), located in the "windows" directory. The following macro's are located in these files:
    Macro, constant or function32-bit meaning64-bit meaning
    is64--Makes it possible to use "if used is64" macro to enter specific x64 code.
    is32Makes it possible to use "if used is32" macro to enter specific x86 code.--
    StartProc--Writes parameters passed through a function, called with the Windows calling convention x64, on stack.
    MakeStack--Creates free space on stack and rounds stack up to 16 bytes to be able to call a function with the Windows calling convention x64.
    argpushPushes parameters on stack to be able to call a function with the Windows calling convention x86Writes a parameter to register or on stack to be able to call a function with the Windows calling convention x64.
    denterThis is a function and is used to start an internal function, it saves the following registers on stack: ESP, EDI, ESI, EBX, EDX, ECX en EBP and moves esp to ebp after one push (first parameter on stack will be on EBP+0x8). This is an internal function and is used to start an function, it saves the following registers on stack: RSP, RDI, RSI, RBX, RDX, RCX, R12, R13, R14, R15 and RBP and moves rsp to rbp after one push (first parameter on stack will be on RBP+0x10).
    dleaveThis is a function and restores the registers pushed on stack by denter.This is a function and restores the registers pushed on stack by denter.
    lodsp, stosp, movsp, scasp and jpcxzWill be replaced with instructions: lodsd, stosd, movsd, scasd and jecxz.Will be replaced with instruction lodsq, stosq, movsq, scasq, jrcxz.
    peax, pecx, pebx, pedx, pedi, pesi, pesi, pebp and pespWill be replaced with registers: eax, ecx, ebx, edx, edi, esi, esi, ebp and esp.Will be replaced with registers: rax, rcx, rbx, rdx, rdi, rsi, rsi, rbp and rsp.
    ClearSpaceForAPI0The size used on stack by macro MakeStack, which is 8*16 bytes.
    UsedSizeBydEnterThe size used by function denter to place the registers on stack. This is 20 bytes.The size used by function denter to place the registers on stack. This is 72 bytes.
    FunctionReturnFactorThe size that need to be cleared from stack when returning a Windows calling convention x86 function. This is 4 bytes per parameter.The size that need to be cleared from stack when returning a Windows calling convention x64 function. This is 0 bytes per parameter.
    psizeThe size of a pointer, 4 bytes.The size of a pointer, 8 bytes.
    pointerThe name in fasm to create a dword (4 bytes), 'dd'.The name in fasm to create a qword (8 bytes), 'dq'.
    pdwordThe name in fasm to identify a dword, 'dword'.The name in fasm to identify a qword, 'qword'.

    Calling conventions
    There are more than one calling convention in this project, however, there is one commonly used calling convention: This calling convention can be recognized by the following block of comments above a function.


    The first parameter that needs to be pushed on stack before calling this function is number 6 "error code" and the last parameter to push on stack is number 1 "ProtocolSession". If another calling convention is used it is clearly explained how to call this function. The example below shows it needs input on register EAX and 1 parameter on stack. Output of this function will be on register EDX and EBX.


    Memory mangement
    TV's server has thee different memory mangement modes that can be set in file windows/modulefunctions.inc. Please recompile all the files in the project when switching to an other mode, it effects them all.
    ModeUsageMeaning
    VirtualVery quick, but memory consumingAll memory is requested by calling VirtualAlloc. The smallest amount of memory it returns is ~4K. This means that if you require 10 bytes, you get 4K.
    Virtual DividerSlower than Virtual, but AL LOT less memory consuming.This will allocate memory though VirtualAlloc and divides it over multple requests. The overhead for every peace of memory is 0x10 bytes and all memory is rounded up by 0x10.
    Virtual Thread DividerA litle bit more memory consuming than Virtual divider, but a lot quicker.It's basicly the same as Virtual Divider, with the difference that every thread divides there own peace of memory, instead of centralizing it. This means that different threads don't have to wait on each other, which is a hugh win in time. The pointer that holds the allocated memory is placed in the TEB.

    Path structure
    FolderContents
    .Contains assembly files from TV's server and it's plugin's, compiled files and an install and uninstall script.
    windowsContains source that calls and uses Windows API.
    test protocolsPlug-ins that where build to test the functionality of TV's server. Run "register_x86.reg" or "register_x64.reg" to register these plug-ins (edit the correct path in these files before running).
    include_tvs_server_plugin_tcp_protocolAssembly files for the TCP/IP protocol, included by the tvs_server_plugin_tcp_protocol_x**.asm file.
    include_tvs_server_plugin_httpAssembly files for the HTTP protocol, included by the tvs_server_plugin_http_x**.asm file.
    include_tvs_server_plugin_control_panelAssembly files for Control panel protocol, included by the tvs_server_plugin_control_panel_x**.asm file.
    include_plugin_generalAssembly files included by all plug-ins.
    include_http_protocolAssembly files included by the http protocol DLL used by the control panel and HTTP plugin-protocol.
    includeAssembly files included mostly by the base and some files are also included by some protocols.
    controlpanelHtml pages that are used by the control panel plugin to build the user interface.