├── tests ├── crc32_output ├── shellcode_output ├── rc4_output ├── crc32.c ├── string_output ├── args_output ├── vm.c ├── shift_output ├── rc4.c ├── mul64_output ├── fortress_input ├── div64_output ├── string.c ├── pi_output ├── mul64.c ├── div64.c ├── pi.c ├── sploit_mmap.c └── shellcode.c ├── docs ├── images │ └── icons │ │ ├── tip.png │ │ ├── note.png │ │ ├── caution.png │ │ ├── example.png │ │ ├── warning.png │ │ └── important.png ├── strlen.txt ├── breakpoint.txt ├── atoi.txt ├── puts.txt ├── chdir.txt ├── getpid.txt ├── getppid.txt ├── Makefile ├── crc32.txt ├── close.txt ├── byteswap.txt ├── dup.txt ├── exit.txt ├── end.txt ├── max.txt ├── min.txt ├── free.txt ├── fchdir.txt ├── time.txt ├── abs.txt ├── rmdir.txt ├── unlink.txt ├── memset.txt ├── getpgid.txt ├── getpgrp.txt ├── munmap.txt ├── alarm.txt ├── getsockopt.txt ├── setsockopt.txt ├── chmod.txt ├── getcwd.txt ├── fgetc.txt ├── getuid.txt ├── rename.txt ├── fchmod.txt ├── getgid.txt ├── pipe.txt ├── strcmp.txt ├── strdup.txt ├── getegid.txt ├── geteuid.txt ├── getsockname.txt ├── rdtsc.txt ├── fputc.txt ├── getpeername.txt ├── rdtsc_high.txt ├── rdtsc_low.txt ├── fputs.txt ├── kill.txt ├── alloca.txt ├── link.txt ├── mkdir.txt ├── malloc.txt ├── sprintf.txt ├── symlink.txt ├── memmove.txt ├── strchr.txt ├── strrchr.txt ├── truncate.txt ├── fchown.txt ├── packed.txt ├── ftruncate.txt ├── setsid.txt ├── shm_unlink.txt ├── sysctl.txt ├── dup2.txt ├── setpgid.txt ├── rc4_init.txt ├── memcpy.txt ├── setgid.txt ├── setuid.txt ├── tgkill.txt ├── setegid.txt ├── seteuid.txt ├── snprintf.txt ├── strncpy.txt ├── sh.txt ├── strcat.txt ├── printf.txt ├── strcpy.txt ├── bash.txt ├── getitimer.txt ├── fchflags.txt ├── lseek.txt ├── listen.txt ├── rc4_output.txt ├── chown.txt ├── getgroups.txt ├── shutdown.txt ├── wait.txt ├── lchown.txt ├── next_arg.txt ├── system.txt ├── waitpid.txt ├── rc4_crypt.txt ├── signal.txt ├── prev_arg.txt ├── fprintf.txt ├── chflags.txt ├── vsprintf.txt ├── interactive_sh.txt ├── readlink.txt ├── lchflags.txt ├── mprotect.txt ├── accept.txt ├── interactive_bash.txt ├── redirect_io.txt ├── setreuid.txt ├── setregid.txt ├── accept4.txt ├── send_all.txt ├── sendfile.txt ├── socketpair.txt ├── vsnprintf.txt ├── vprintf.txt ├── fork.txt ├── getdents.txt ├── nanosleep.txt ├── send_string.txt ├── recv_all.txt ├── socket.txt ├── open.txt ├── create_tcp6_connection.txt ├── create_udp6_connection.txt ├── quark_exec.txt ├── vfprintf.txt ├── fgets.txt ├── fdopen.txt ├── setitimer.txt ├── sigaction.txt ├── gettimeofday.txt ├── create_tcp4_connection.txt ├── create_udp4_connection.txt ├── getdirentries.txt ├── execve.txt ├── syscall.txt ├── fstat.txt ├── read.txt ├── write.txt ├── shm_open.txt ├── format.txt ├── connect.txt ├── fcntl.txt ├── noreturn.txt ├── stat.txt ├── execl.txt ├── bind.txt ├── lstat.txt ├── syscall2.txt ├── undefined.txt ├── send.txt ├── recv.txt ├── lib │ └── xhtml11-quirks.css ├── select.txt ├── mmap.txt ├── recvfrom.txt ├── index.txt └── rc4_overview.txt ├── .gitmodules ├── .gitignore ├── make.bat ├── runtime ├── aarch64 │ └── defines.h ├── linux │ ├── aarch64 │ │ ├── file.h │ │ ├── stat.c │ │ ├── file.c │ │ ├── stat.h │ │ ├── process.c │ │ ├── memory.h │ │ └── memory.c │ ├── defines.h │ ├── arm │ │ ├── memory.h │ │ ├── file.h │ │ ├── file.c │ │ ├── stat.c │ │ └── memory.c │ ├── ppc │ │ ├── memory.h │ │ ├── file.h │ │ ├── file.c │ │ ├── stat.c │ │ └── memory.c │ ├── x64 │ │ ├── memory.h │ │ ├── file.h │ │ ├── file.c │ │ ├── memory.c │ │ └── stat.c │ ├── x86 │ │ ├── memory.h │ │ ├── file.h │ │ ├── file.c │ │ ├── stat.c │ │ └── memory.c │ └── mips │ │ ├── memory.h │ │ ├── file.h │ │ ├── stat.c │ │ ├── file.c │ │ └── memory.c ├── end.c ├── end.h ├── mac │ ├── defines.h │ └── memory.c ├── freebsd │ ├── defines.h │ ├── memory.c │ └── time.c ├── arm │ └── defines.h ├── ppc │ └── defines.h ├── x86 │ └── defines.h ├── mips │ └── defines.h ├── quark │ └── defines.h ├── x64 │ └── defines.h ├── windows │ ├── defines.h │ └── memory.c ├── crc32.h ├── quark_vm.h ├── posix │ ├── shell.h │ └── memory.h ├── net.h ├── defines.h ├── rc4.h └── byteswap.h ├── .gitattributes ├── OutputX64.h ├── OutputX86.h ├── X64SymInstr.h ├── X86SymInstr.h ├── OutputX64.cpp ├── OutputX86.cpp ├── ElfOutput.h ├── MachOOutput.h ├── PeOutput.h ├── genlibrary.py ├── Token.cpp ├── BitVector.h ├── Optimize.h ├── Token.h ├── Scope.h ├── LICENSE.txt ├── Enum.h ├── codegen ├── Token.cpp └── Match.cpp ├── README.md └── TreeBlock.h /tests/crc32_output: -------------------------------------------------------------------------------- 1 | 36d2651d 2 | -------------------------------------------------------------------------------- /tests/shellcode_output: -------------------------------------------------------------------------------- 1 | The quick brown fox jumps over the lazy dog. 2 | -------------------------------------------------------------------------------- /tests/rc4_output: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vector35/scc/HEAD/tests/rc4_output -------------------------------------------------------------------------------- /docs/images/icons/tip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vector35/scc/HEAD/docs/images/icons/tip.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "asmx86"] 2 | path = asmx86 3 | url = git@github.com:Vector35/asmx86.git 4 | -------------------------------------------------------------------------------- /docs/images/icons/note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vector35/scc/HEAD/docs/images/icons/note.png -------------------------------------------------------------------------------- /docs/images/icons/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vector35/scc/HEAD/docs/images/icons/caution.png -------------------------------------------------------------------------------- /docs/images/icons/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vector35/scc/HEAD/docs/images/icons/example.png -------------------------------------------------------------------------------- /docs/images/icons/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vector35/scc/HEAD/docs/images/icons/warning.png -------------------------------------------------------------------------------- /docs/images/icons/important.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vector35/scc/HEAD/docs/images/icons/important.png -------------------------------------------------------------------------------- /tests/crc32.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | char* msg = "OMGitsfullofAAAAAAAAs"; 4 | printf("%x\n", crc32(msg, strlen(msg))); 5 | return 0; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | scc 2 | scc.exe 3 | Obj 4 | *.pyc 5 | .gdb_history 6 | .DS_Store 7 | Makefile 8 | CMakeFiles 9 | CMakeCache.txt 10 | cmake_install.cmake 11 | -------------------------------------------------------------------------------- /tests/string_output: -------------------------------------------------------------------------------- 1 | 44 2 | 2 3 | 0 4 | 43 5 | 33 6 | 0 7 | 43 8 | quickuick brown fox jumps over the lazy dog! 9 | quickuick bbrownfox jumps over the lazy dog! 10 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat" 3 | set PATH=%~dp0\buildenv\msys\bin;%PATH% 4 | make.exe %* 5 | -------------------------------------------------------------------------------- /runtime/aarch64/defines.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBC__ARCH_DEFINES_H__ 2 | #define __LIBC__ARCH_DEFINES_H__ 3 | 4 | #define ARM64 5 | #define AARCH64 6 | #define __64BIT 7 | 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /tests/args_output: -------------------------------------------------------------------------------- 1 | 59 2 | 18787 3 | 605032630 4 | 323853555 5 | 79 6 | 8502 7 | 580453365 8 | 950068688 9 | zero 10 | nonzero 11 | 3 12 | ENOENT 13 | 59 14 | 61 40 15 | 131 16 | 133 97 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.exe -crlf -diff -merge 2 | *.dll -crlf -diff -merge 3 | *.a -crlf -diff -merge 4 | *.la -crlf -diff -merge 5 | *.o -crlf -diff -merge 6 | *.ico -crlf -diff -merge 7 | yacc.c -crlf 8 | -------------------------------------------------------------------------------- /tests/vm.c: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | int fd = open("Obj/test", O_RDONLY, 0); 4 | void* buf = malloc(1048576); 5 | read(fd, buf, 1048576); 6 | close(fd); 7 | 8 | quark_exec(buf); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /OutputX64.h: -------------------------------------------------------------------------------- 1 | #ifndef __OUTPUTX64_H__ 2 | #define __OUTPUTX64_H__ 3 | 4 | #define OUTPUT_CLASS_NAME OutputX64 5 | #define OUTPUT64 6 | #include "OutputX86Common.h" 7 | #undef OUTPUT_CLASS_NAME 8 | #undef OUTPUT64 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /OutputX86.h: -------------------------------------------------------------------------------- 1 | #ifndef __OUTPUTX86_H__ 2 | #define __OUTPUTX86_H__ 3 | 4 | #define OUTPUT_CLASS_NAME OutputX86 5 | #define OUTPUT32 6 | #include "OutputX86Common.h" 7 | #undef OUTPUT_CLASS_NAME 8 | #undef OUTPUT32 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /tests/shift_output: -------------------------------------------------------------------------------- 1 | 68 2 | 7 3 | -2 4 | 6868 5 | 1695 6 | -133 7 | 68686868 8 | 75757575 9 | -1325758 10 | -923152612 11 | 1855785166 12 | -1292902690 13 | 842557957 14 | 1919088941 15 | 987766 16 | -509078528 17 | 1874110 18 | 964 19 | -------------------------------------------------------------------------------- /X64SymInstr.h: -------------------------------------------------------------------------------- 1 | #ifndef __X64SYMINSTR_H__ 2 | #define __X64SYMINSTR_H__ 3 | 4 | #define X86_SYMINSTR_PREFIX X64Sym 5 | #define OUTPUT64 6 | #include "X86SymInstrCommon.h" 7 | #undef X86_SYMINSTR_PREFIX 8 | #undef OUTPUT64 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /X86SymInstr.h: -------------------------------------------------------------------------------- 1 | #ifndef __X86SYMINSTR_H__ 2 | #define __X86SYMINSTR_H__ 3 | 4 | #define X86_SYMINSTR_PREFIX X86Sym 5 | #define OUTPUT32 6 | #include "X86SymInstrCommon.h" 7 | #undef X86_SYMINSTR_PREFIX 8 | #undef OUTPUT32 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /docs/strlen.txt: -------------------------------------------------------------------------------- 1 | strlen 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | size_t strlen(const char* str); 7 | --------------------------------------------- 8 | 9 | Returns the length of the string `str`. 10 | 11 | -------------------------------------------------------------------------------- /tests/rc4.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | rc4_state_t rc4; 4 | char* key = "thereisnocowlevel"; 5 | rc4_init(&rc4, key, strlen(key)); 6 | char* str = "pwniesinstead"; 7 | size_t len = strlen(str); 8 | rc4_crypt(&rc4, str, len); 9 | write(1, str, len); 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /OutputX64.cpp: -------------------------------------------------------------------------------- 1 | #define OUTPUT_CLASS_NAME OutputX64 2 | #define OUTPUT64 3 | 4 | #define DEFAULT_STACK_POINTER SYMREG_NATIVE_REG(REG_ESP) 5 | #define DEFAULT_FRAME_POINTER SYMREG_NATIVE_REG(REG_EBP) 6 | #define DEFAULT_BASE_POINTER SYMREG_NONE 7 | 8 | #include "OutputX86Common.cpp" 9 | 10 | -------------------------------------------------------------------------------- /docs/breakpoint.txt: -------------------------------------------------------------------------------- 1 | breakpoint 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | __breakpoint() 7 | --------------------------------------------- 8 | 9 | Emits the breakpoint instruction for the target architecture. 10 | 11 | -------------------------------------------------------------------------------- /docs/atoi.txt: -------------------------------------------------------------------------------- 1 | atoi 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int atoi(const char* str); 7 | --------------------------------------------- 8 | 9 | Converts a decimal string `str` to an integer, and returns the integer value. 10 | 11 | -------------------------------------------------------------------------------- /docs/puts.txt: -------------------------------------------------------------------------------- 1 | puts 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int puts(const char* str); 7 | --------------------------------------------- 8 | 9 | Writes the string `str` to standard output. 10 | 11 | See also 12 | -------- 13 | link:fputs.html[fputs] 14 | -------------------------------------------------------------------------------- /docs/chdir.txt: -------------------------------------------------------------------------------- 1 | chdir 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int chdir(const char* path); 7 | --------------------------------------------- 8 | 9 | Changes the current directory to `path`. 10 | 11 | See also 12 | -------- 13 | link:getcwd.html[getcwd] 14 | -------------------------------------------------------------------------------- /docs/getpid.txt: -------------------------------------------------------------------------------- 1 | getpid 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t getpid(void); 7 | --------------------------------------------- 8 | 9 | Gets the process ID of the current process. 10 | 11 | See also 12 | -------- 13 | link:getppid.html[getppid] 14 | -------------------------------------------------------------------------------- /docs/getppid.txt: -------------------------------------------------------------------------------- 1 | getppid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t getppid(void); 7 | --------------------------------------------- 8 | 9 | Gets the process ID of the parent process. 10 | 11 | See also 12 | -------- 13 | link:getpid.html[getpid] 14 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | HTML := $(patsubst %.txt,%.html,$(wildcard *.txt)) 3 | TXT := $(wildcard *.txt) 4 | 5 | all: $(HTML) 6 | .PHONY: all clean 7 | 8 | $(HTML): %.html: %.txt docs.conf Makefile 9 | asciidoc -b html5 --conf-file=docs.conf -a stylesheet="$(CURDIR)/lib/v35.css" -a icons $< 10 | 11 | clean: 12 | rm -f *.html 13 | 14 | -------------------------------------------------------------------------------- /docs/crc32.txt: -------------------------------------------------------------------------------- 1 | crc32 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | uint32_t crc32(const void* data, size_t len); 7 | --------------------------------------------- 8 | 9 | Computes the CRC32 hash of the buffer `data` with length of `len` bytes. Returns the hash. 10 | 11 | -------------------------------------------------------------------------------- /OutputX86.cpp: -------------------------------------------------------------------------------- 1 | #include "SymInstr.h" 2 | 3 | #define OUTPUT_CLASS_NAME OutputX86 4 | #define OUTPUT32 5 | 6 | #define DEFAULT_STACK_POINTER SYMREG_NATIVE_REG(REG_ESP) 7 | #define DEFAULT_FRAME_POINTER SYMREG_NATIVE_REG(REG_EBP) 8 | #define DEFAULT_BASE_POINTER SYMREG_NATIVE_REG(REG_EBX) 9 | 10 | #include "OutputX86Common.cpp" 11 | 12 | -------------------------------------------------------------------------------- /tests/mul64_output: -------------------------------------------------------------------------------- 1 | 000000000000db5a 2 | 5f5f5f5f5f5f57a1 3 | 447bb2ea21588fc7 4 | 000000000000db5a 5 | ffffffffffff24a6 6 | ffffffffffff24a6 7 | 000000000000db5a 8 | 5f5f5f5f5f5f57a1 9 | a0a0a0a0a0a0a85f 10 | a0a0a0a0a0a0a85f 11 | 5f5f5f5f5f5f57a1 12 | 447bb2ea21588fc7 13 | bb844d15dea77039 14 | bb844d15dea77039 15 | 447bb2ea21588fc7 16 | -------------------------------------------------------------------------------- /docs/close.txt: -------------------------------------------------------------------------------- 1 | close 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int close(int fd); 7 | --------------------------------------------- 8 | 9 | Closes the file handle `fd`. 10 | 11 | See also 12 | -------- 13 | link:dup.html[dup], 14 | link:dup2.html[dup2], 15 | link:open.html[open] 16 | -------------------------------------------------------------------------------- /docs/byteswap.txt: -------------------------------------------------------------------------------- 1 | __byteswap 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | uint16_t __byteswap(uint16 n); 7 | uint32_t __byteswap(uint32 n); 8 | uint64_t __byteswap(uint64 n); 9 | --------------------------------------------- 10 | 11 | Swaps the byte ordering of the value `n`. 12 | 13 | -------------------------------------------------------------------------------- /docs/dup.txt: -------------------------------------------------------------------------------- 1 | dup 2 | === 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int dup(int fd); 7 | --------------------------------------------- 8 | 9 | Duplicates the file handle `fd` and returns the new file handle. 10 | 11 | See also 12 | -------- 13 | link:close.html[close], 14 | link:dup2.html[dup2] 15 | -------------------------------------------------------------------------------- /docs/exit.txt: -------------------------------------------------------------------------------- 1 | exit 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void exit(int result) __noreturn; 7 | --------------------------------------------- 8 | 9 | Exits the current process with exit code `result`. Does not return. 10 | 11 | See also 12 | -------- 13 | link:undefined.html[undefined] 14 | -------------------------------------------------------------------------------- /docs/end.txt: -------------------------------------------------------------------------------- 1 | __end 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | uint8_t __end[]; 7 | --------------------------------------------- 8 | 9 | This variable references the end of the output. This is commonly used to append data or code to the end of the 10 | output and reference it from the code. 11 | 12 | -------------------------------------------------------------------------------- /docs/max.txt: -------------------------------------------------------------------------------- 1 | __max 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | __max(...); 7 | --------------------------------------------- 8 | 9 | Returns the maximum value in the list of parameters. Return value is the same type 10 | as the parameters. 11 | 12 | See also 13 | -------- 14 | link:min.html[min] 15 | -------------------------------------------------------------------------------- /docs/min.txt: -------------------------------------------------------------------------------- 1 | __min 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | __min(...); 7 | --------------------------------------------- 8 | 9 | Returns the minimum value in the list of parameters. Return value is the same type 10 | as the parameters. 11 | 12 | See also 13 | -------- 14 | link:max.html[max] 15 | -------------------------------------------------------------------------------- /docs/free.txt: -------------------------------------------------------------------------------- 1 | free 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void free(void* ptr); 7 | --------------------------------------------- 8 | 9 | Frees the buffer pointed to by `ptr`. The provided buffer must have been allocated with `malloc`. 10 | 11 | See also 12 | -------- 13 | link:malloc.html[malloc] 14 | -------------------------------------------------------------------------------- /docs/fchdir.txt: -------------------------------------------------------------------------------- 1 | fchdir 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fchdir(int fd); 7 | --------------------------------------------- 8 | 9 | Changes the current directory to an open directory with file handle `fd`. 10 | 11 | See also 12 | -------- 13 | link:chdir.html[chdir], 14 | link:getcwd.html[getcwd] 15 | -------------------------------------------------------------------------------- /docs/time.txt: -------------------------------------------------------------------------------- 1 | time 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | time_t time(time_t* t); 7 | --------------------------------------------- 8 | 9 | Returns the current time. If `t` is not `NULL`, the time is also stored into the pointer `t`. 10 | 11 | See also 12 | -------- 13 | link:gettimeofday.html[gettimeofday] 14 | -------------------------------------------------------------------------------- /docs/abs.txt: -------------------------------------------------------------------------------- 1 | abs 2 | === 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | abs(n); 7 | --------------------------------------------- 8 | 9 | Computes the absolute value of `n`, which must be a numeric type. The return value is the same type as `n`. 10 | 11 | See also 12 | -------- 13 | link:min.html[min], 14 | link:max.html[max] 15 | -------------------------------------------------------------------------------- /docs/rmdir.txt: -------------------------------------------------------------------------------- 1 | rmdir 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int rmdir(const char* path); 7 | --------------------------------------------- 8 | 9 | Removes the directory at `path`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:mkdir.html[mkdir] 14 | -------------------------------------------------------------------------------- /docs/unlink.txt: -------------------------------------------------------------------------------- 1 | unlink 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int unlink(const char* path); 7 | --------------------------------------------- 8 | 9 | Deletes the file at `path`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:rename.html[rename] 14 | -------------------------------------------------------------------------------- /tests/fortress_input: -------------------------------------------------------------------------------- 1 | 1 2 | 6 3 | 3 4 | 1 5 | Smith 6 | 1337 Leet Ave 7 | Pwnville, NC 8 | 1337 9 | 2 10 | 2 11 | 78000 12 | 1 13 | 2 14 | 1 15 | 3 16 | 2 17 | Acme ROP Gadgets, Inc. 18 | 4141 Read Loop 19 | Stack's End, NY 20 | 7331 21 | 235198 22 | 1 23 | 2 24 | 2 25 | 4 26 | 1 27 | 223123 28 | 1 29 | 5 30 | 1 31 | 209887 32 | 6 33 | 1 34 | 5 35 | 1 36 | 77121 37 | 6 38 | 1 39 | 7 40 | -------------------------------------------------------------------------------- /docs/memset.txt: -------------------------------------------------------------------------------- 1 | memset 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* memset(void* dest, uint8_t value, size_t len); 7 | --------------------------------------------- 8 | 9 | Sets `len` bytes in `dest` to the value `value`. Returns the pointer `dest`. 10 | 11 | See also 12 | -------- 13 | link:memcpy.html[memcpy] 14 | -------------------------------------------------------------------------------- /docs/getpgid.txt: -------------------------------------------------------------------------------- 1 | getpgid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t getpgid(pid_t pid); 7 | --------------------------------------------- 8 | 9 | Returns the process group ID for process `pid`. 10 | 11 | See also 12 | -------- 13 | link:getpgrp.html[getpgrp], 14 | link:setpgid.html[setpgid], 15 | link:setsid.html[setsid] 16 | -------------------------------------------------------------------------------- /docs/getpgrp.txt: -------------------------------------------------------------------------------- 1 | getpgrp 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t getpgrp(void); 7 | --------------------------------------------- 8 | 9 | Returns the process group ID for the current process. 10 | 11 | See also 12 | -------- 13 | link:getpgid.html[getpgid], 14 | link:setpgid.html[setpgid], 15 | link:setsid.html[setsid] 16 | -------------------------------------------------------------------------------- /docs/munmap.txt: -------------------------------------------------------------------------------- 1 | munmap 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* munmap(void* addr, size_t len); 7 | --------------------------------------------- 8 | 9 | Unmaps a region of virtual address space. The region unmapped starts at `addr` and is `len` bytes in length. 10 | 11 | See also 12 | -------- 13 | link:mmap.html[mmap] 14 | -------------------------------------------------------------------------------- /runtime/linux/aarch64/file.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBC__LINUX_ARCH_FILE_H__ 2 | #define __LIBC__LINUX_ARCH_FILE_H__ 3 | 4 | #define AT_FDCWD -100 5 | #define AT_SYMLINK_NOFOLLOW 0x100 6 | #define AT_REMOVEDIR 0x200 7 | #define AT_SYMLINK_FOLLOW 0x400 8 | 9 | #define O_DIRECTORY 0x4000 10 | #define O_NOFOLLOW 0x8000 11 | #define O_DIRECT 0x10000 12 | #define O_LARGEFILE 0x20000 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /docs/alarm.txt: -------------------------------------------------------------------------------- 1 | alarm 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | unsigned int alarm(unsigned int seconds); 7 | --------------------------------------------- 8 | 9 | Delivers the signal `SIGALRM` after `seconds` seconds. If `seconds` is zero, any previously set alarm is cleared. 10 | 11 | See also 12 | -------- 13 | link:kill.html[kill] 14 | -------------------------------------------------------------------------------- /runtime/linux/aarch64/stat.c: -------------------------------------------------------------------------------- 1 | int fstat(int fd, struct stat* buf) 2 | { 3 | return __syscall(SYS_fstat, fd, buf); 4 | } 5 | 6 | int stat(const char* path, struct stat* buf) 7 | { 8 | return __syscall(SYS_fstatat, AT_FDCWD, path, buf, 0); 9 | } 10 | 11 | int lstat(const char* path, struct stat* buf) 12 | { 13 | return __syscall(SYS_fstatat, AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /docs/getsockopt.txt: -------------------------------------------------------------------------------- 1 | getsockopt 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int getsockopt(int fd, int level, int optname, void* optval, socklen_t* optlen); 7 | --------------------------------------------- 8 | 9 | Retrieves the value of an option for socket `fd`. 10 | 11 | See also 12 | -------- 13 | link:setsockopt.html[setsockopt] 14 | -------------------------------------------------------------------------------- /docs/setsockopt.txt: -------------------------------------------------------------------------------- 1 | setsockopt 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setsockopt(int fd, int level, int optname, const void* optval, socklen_t optlen); 7 | --------------------------------------------- 8 | 9 | Sets the value of an option for socket `fd`. 10 | 11 | See also 12 | -------- 13 | link:getsockopt.html[getsockopt] 14 | -------------------------------------------------------------------------------- /ElfOutput.h: -------------------------------------------------------------------------------- 1 | #ifndef __ELFOUTPUT_H__ 2 | #define __ELFOUTPUT_H__ 3 | 4 | #include "Output.h" 5 | #include "Settings.h" 6 | 7 | bool GenerateElfFile(OutputBlock* output, const Settings& settings, OutputBlock* codeSection, OutputBlock* dataSection); 8 | uint64_t AdjustBaseForElfFile(uint64_t fileBase, const Settings& settings); 9 | uint64_t AdjustDataSectionBaseForElfFile(uint64_t base); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /docs/chmod.txt: -------------------------------------------------------------------------------- 1 | chmod 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int chmod(const char* path, mode_t mode); 7 | --------------------------------------------- 8 | 9 | Changes the file permissions for `path` to `mode`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:fchmod.html[fchmod] 14 | -------------------------------------------------------------------------------- /docs/getcwd.txt: -------------------------------------------------------------------------------- 1 | getcwd 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* getcwd(char* buf, size_t size); 7 | --------------------------------------------- 8 | 9 | Gets the current working directory and places it into `buf`, with maximum length `size`. Returns a 10 | pointer to `buf`. 11 | 12 | See also 13 | -------- 14 | link:chdir.html[chdir] 15 | -------------------------------------------------------------------------------- /runtime/linux/aarch64/file.c: -------------------------------------------------------------------------------- 1 | int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout) 2 | { 3 | struct timespec t; 4 | t.tv_sec = timeout->tv_sec; 5 | t.tv_nsec = timeout->tv_usec * 1000; 6 | return __syscall(SYS_pselect6, nfds, readfds, writefds, errorfds, &t, NULL); 7 | } 8 | 9 | int pipe(int* fds) 10 | { 11 | return __syscall(SYS_pipe2, fds, 0); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /docs/fgetc.txt: -------------------------------------------------------------------------------- 1 | fgetc 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fgetc(FILE* fp); 7 | --------------------------------------------- 8 | 9 | Reads the next byte from the file stream `fp`. If the current position was at the end of the file, `EOF` is returned. 10 | 11 | See also 12 | -------- 13 | link:fdopen.html[fdopen], 14 | link:fgets.html[fgets] 15 | -------------------------------------------------------------------------------- /docs/getuid.txt: -------------------------------------------------------------------------------- 1 | getuid 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | gid_t getuid(void); 7 | --------------------------------------------- 8 | 9 | Returns the real user ID of the current process. 10 | 11 | See also 12 | -------- 13 | link:geteuid.html[geteuid], 14 | link:setuid.html[setuid], 15 | link:seteuid.html[seteuid], 16 | link:setreuid.html[setreuid] 17 | -------------------------------------------------------------------------------- /docs/rename.txt: -------------------------------------------------------------------------------- 1 | rename 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int rename(const char* oldpath, const char* newpath); 7 | --------------------------------------------- 8 | 9 | Renames the file at `oldpath` to `newpath`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:unlink.html[unlink] 14 | -------------------------------------------------------------------------------- /MachOOutput.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACHOOUTPUT_H__ 2 | #define __MACHOOUTPUT_H__ 3 | 4 | #include "Output.h" 5 | #include "Settings.h" 6 | 7 | bool GenerateMachOFile(OutputBlock* output, const Settings& settings, OutputBlock* codeSection, OutputBlock* dataSection); 8 | uint64_t AdjustBaseForMachOFile(uint64_t fileBase, const Settings& settings); 9 | uint64_t AdjustDataSectionBaseForMachOFile(uint64_t base); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /docs/fchmod.txt: -------------------------------------------------------------------------------- 1 | fchmod 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fchmod(int fd, mode_t mode); 7 | --------------------------------------------- 8 | 9 | Changes the file permissions for the file handle `fd` to `mode`. Returns zero on success, or the 10 | negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:chmod.html[chmod] 15 | -------------------------------------------------------------------------------- /docs/getgid.txt: -------------------------------------------------------------------------------- 1 | getgid 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | gid_t getgid(void); 7 | --------------------------------------------- 8 | 9 | Returns the real group ID of the current process. 10 | 11 | See also 12 | -------- 13 | link:getegid.html[getegid], 14 | link:setgid.html[setgid], 15 | link:setegid.html[setegid], 16 | link:setregid.html[setregid] 17 | -------------------------------------------------------------------------------- /docs/pipe.txt: -------------------------------------------------------------------------------- 1 | pipe 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int pipe(int fds[2]); 7 | --------------------------------------------- 8 | 9 | Creates a new pipe. The first file handle is the "read" end, and the second file handle is the "write" end. 10 | 11 | See also 12 | -------- 13 | link:close.html[close], 14 | link:dup.html[dup], 15 | link:dup2.html[dup2] 16 | -------------------------------------------------------------------------------- /docs/strcmp.txt: -------------------------------------------------------------------------------- 1 | strcmp 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int strcmp(const char* a, const char* b); 7 | --------------------------------------------- 8 | 9 | Compares two strings `a` and `b`. Returns one of the following: 10 | 11 | * `a` < `b`: Returns less than zero 12 | * `a` == `b`: Returns zero 13 | * `a` > `b`: Returns greater than zero 14 | 15 | -------------------------------------------------------------------------------- /docs/strdup.txt: -------------------------------------------------------------------------------- 1 | strdup 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* strdup(const char* str); 7 | --------------------------------------------- 8 | 9 | Duplicates the string `str` on the heap, and returns a pointer to the new string. 10 | 11 | See also 12 | -------- 13 | link:free.html[free], 14 | link:malloc.html[malloc], 15 | link:strcpy.html[strcpy] 16 | -------------------------------------------------------------------------------- /docs/getegid.txt: -------------------------------------------------------------------------------- 1 | getegid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | gid_t getegid(void); 7 | --------------------------------------------- 8 | 9 | Returns the effective group ID of the current process. 10 | 11 | See also 12 | -------- 13 | link:getgid.html[getgid], 14 | link:setgid.html[setgid], 15 | link:setegid.html[setegid], 16 | link:setregid.html[setregid] 17 | -------------------------------------------------------------------------------- /docs/geteuid.txt: -------------------------------------------------------------------------------- 1 | geteuid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | gid_t geteuid(void); 7 | --------------------------------------------- 8 | 9 | Returns the effective user ID of the current process. 10 | 11 | See also 12 | -------- 13 | link:getuid.html[getuid], 14 | link:setuid.html[setuid], 15 | link:seteuid.html[seteuid], 16 | link:setreuid.html[setreuid] 17 | -------------------------------------------------------------------------------- /docs/getsockname.txt: -------------------------------------------------------------------------------- 1 | getsockname 2 | =========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int getsockname(int sockfd, struct sockaddr* addr, socklen_t* addrlen); 7 | --------------------------------------------- 8 | 9 | Fills the `addr` structure with the address associated with the socket `sockfd`. 10 | 11 | See also 12 | -------- 13 | link:getpeername.html[getpeername] 14 | -------------------------------------------------------------------------------- /docs/rdtsc.txt: -------------------------------------------------------------------------------- 1 | __rdtsc 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | uint64_t __rdtsc(); 7 | --------------------------------------------- 8 | 9 | Reads the time stamp counter on the x86 architecture. Returns the time stamp counter as a single 64-bit integer. 10 | 11 | See also 12 | -------- 13 | link:rdtsc_low.html[rdtsc_low], 14 | link:rdtsc_high.html[rdtsc_high] 15 | -------------------------------------------------------------------------------- /docs/fputc.txt: -------------------------------------------------------------------------------- 1 | fputc 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fputc(int ch, FILE* fp); 7 | --------------------------------------------- 8 | 9 | Writes the byte `ch` to the file stream `fp`. Returns the number of bytes written, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:fdopen.html[fdopen], 14 | link:fputs.html[fputs] 15 | -------------------------------------------------------------------------------- /docs/getpeername.txt: -------------------------------------------------------------------------------- 1 | getpeername 2 | =========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int getpeername(int sockfd, struct sockaddr* addr, socklen_t* addrlen); 7 | --------------------------------------------- 8 | 9 | Fills the `addr` structure with the address to which socket `sockfd` is connected to. 10 | 11 | See also 12 | -------- 13 | link:getsockname.html[getsockname] 14 | -------------------------------------------------------------------------------- /docs/rdtsc_high.txt: -------------------------------------------------------------------------------- 1 | __rdtsc_high 2 | ============ 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | uint32_t __rdtsc_high(); 7 | --------------------------------------------- 8 | 9 | Reads the time stamp counter on the x86 architecture. Returns the upper 32 bits of the time stamp counter. 10 | 11 | See also 12 | -------- 13 | link:rdtsc.html[rdtsc], 14 | link:rdtsc_low.html[rdtsc_low] 15 | -------------------------------------------------------------------------------- /docs/rdtsc_low.txt: -------------------------------------------------------------------------------- 1 | __rdtsc_low 2 | =========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | uint32_t __rdtsc_low(); 7 | --------------------------------------------- 8 | 9 | Reads the time stamp counter on the x86 architecture. Returns the lower 32 bits of the time stamp counter. 10 | 11 | See also 12 | -------- 13 | link:rdtsc.html[rdtsc], 14 | link:rdtsc_high.html[rdtsc_high] 15 | -------------------------------------------------------------------------------- /docs/fputs.txt: -------------------------------------------------------------------------------- 1 | fputs 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fputs(const char* str, FILE* fp); 7 | --------------------------------------------- 8 | 9 | Writes the string `str` to the file stream `fp`. Returns the number of bytes written, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:fdopen.html[fdopen], 14 | link:fputc.html[fputc] 15 | -------------------------------------------------------------------------------- /docs/kill.txt: -------------------------------------------------------------------------------- 1 | kill 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int kill(pid_t pid, int sig); 7 | --------------------------------------------- 8 | 9 | Sends the signal `sig` to process `pid`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:fork.html[fork], 14 | link:wait.html[wait], 15 | link:waitpid.html[waitpid] 16 | -------------------------------------------------------------------------------- /docs/alloca.txt: -------------------------------------------------------------------------------- 1 | alloca 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* alloca(size_t size); 7 | --------------------------------------------- 8 | 9 | Allocates `size` bytes on the current stack frame, and returns a pointer to the new buffer. The returned buffer 10 | is no longer valid after the current function returns. 11 | 12 | See also 13 | -------- 14 | link:malloc.html[malloc] 15 | -------------------------------------------------------------------------------- /docs/link.txt: -------------------------------------------------------------------------------- 1 | link 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int link(const char* target, const char* path); 7 | --------------------------------------------- 8 | 9 | Creates a hard link at `path` that points to `target`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:readlink.html[readlink], 14 | link:symlink.html[symlink] 15 | -------------------------------------------------------------------------------- /docs/mkdir.txt: -------------------------------------------------------------------------------- 1 | mkdir 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int mkdir(const char* path, mode_t mode); 7 | --------------------------------------------- 8 | 9 | Creates a new directory at `path` with file access set to `mode`. Returns zero on success, or the negation of the error 10 | code on error. 11 | 12 | See also 13 | -------- 14 | link:chdir.html[chdir], 15 | link:rmdir.html[rmdir] 16 | -------------------------------------------------------------------------------- /docs/malloc.txt: -------------------------------------------------------------------------------- 1 | malloc 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* malloc(size_t len); 7 | --------------------------------------------- 8 | 9 | Allocates `len` bytes from the heap, and returns a pointer to the new buffer. The buffer is aligned to the 10 | size of a pointer, and is always executable. 11 | 12 | See also 13 | -------- 14 | link:alloca.html[alloca], 15 | link:free.html[free] 16 | -------------------------------------------------------------------------------- /docs/sprintf.txt: -------------------------------------------------------------------------------- 1 | sprintf 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int sprintf(char* out, const char* fmt, ...); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to the string `out`. See the link:format.html[format specifier reference] 10 | for the supported format specifiers. 11 | 12 | See also 13 | -------- 14 | link:snprintf.html[snprintf] 15 | -------------------------------------------------------------------------------- /docs/symlink.txt: -------------------------------------------------------------------------------- 1 | symlink 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int symlink(const char* target, const char* path); 7 | --------------------------------------------- 8 | 9 | Creates a symbolic link at `path` that points to `target`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:link.html[link], 14 | link:readlink.html[readlink] 15 | -------------------------------------------------------------------------------- /docs/memmove.txt: -------------------------------------------------------------------------------- 1 | memmove 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* memmove(void* dest, const void* src, size_t len); 7 | --------------------------------------------- 8 | 9 | Copies `len` bytes from `src` to `dest`. Returns a pointer to `dest`. This function accounts for the 10 | possibility of overlapping source and destination. 11 | 12 | See also 13 | -------- 14 | link:memcpy.html[memcpy] 15 | -------------------------------------------------------------------------------- /docs/strchr.txt: -------------------------------------------------------------------------------- 1 | strchr 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* strchr(const char* str, char ch); 7 | --------------------------------------------- 8 | 9 | Finds the first occurrence of the character `ch` in string `str`, and returns a pointer to the character. If the 10 | character does not occur in the string, `NULL` is returned. 11 | 12 | See also 13 | -------- 14 | link:strrchr.html[strrchr] 15 | -------------------------------------------------------------------------------- /docs/strrchr.txt: -------------------------------------------------------------------------------- 1 | strrchr 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* strrchr(const char* str, char ch); 7 | --------------------------------------------- 8 | 9 | Finds the last occurrence of the character `ch` in string `str`, and returns a pointer to the character. If the 10 | character does not occur in the string, `NULL` is returned. 11 | 12 | See also 13 | -------- 14 | link:strchr.html[strchr] 15 | -------------------------------------------------------------------------------- /docs/truncate.txt: -------------------------------------------------------------------------------- 1 | truncate 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int truncate(const char* path, int64_t length); 7 | --------------------------------------------- 8 | 9 | Sets the length of the file at `path` to `length` bytes. Returns zero on success, or the negation 10 | of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:ftruncate.html[ftruncate], 15 | link:lseek.html[lseek] 16 | -------------------------------------------------------------------------------- /PeOutput.h: -------------------------------------------------------------------------------- 1 | #ifndef __PEOUTPUT_H__ 2 | #define __PEOUTPUT_H__ 3 | 4 | #include "Output.h" 5 | #include "Settings.h" 6 | #include "Linker.h" 7 | 8 | bool GeneratePeFile(OutputBlock* output, const Settings& settings, OutputBlock* codeSection, OutputBlock* dataSection, 9 | std::map& imports); 10 | uint64_t AdjustBaseForPeFile(uint64_t fileBase, const Settings& settings); 11 | uint64_t AdjustDataSectionBaseForPeFile(uint64_t base); 12 | 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /docs/fchown.txt: -------------------------------------------------------------------------------- 1 | fchown 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fchown(int fd, uid_t owner, gid_t group); 7 | --------------------------------------------- 8 | 9 | Changes the owner to `owner` and group to `group` for the file handle `fd`. Returns zero on success, or the negation 10 | of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:chown.html[chown], 15 | link:lchown.html[lchown] 16 | -------------------------------------------------------------------------------- /docs/packed.txt: -------------------------------------------------------------------------------- 1 | __packed 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | struct type __packed 7 | { 8 | int member; 9 | ... 10 | }; 11 | --------------------------------------------- 12 | 13 | The `__packed` keyword disables alignment restrictions on a structure. No padding will be added between members. 14 | 15 | IMPORTANT: Be careful with this keyword on architectures that require aligned memory access. 16 | 17 | -------------------------------------------------------------------------------- /docs/ftruncate.txt: -------------------------------------------------------------------------------- 1 | ftruncate 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int ftruncate(int fd, int64_t length); 7 | --------------------------------------------- 8 | 9 | Sets the length of the file referenced by file handle `fd` to `length` bytes. Returns zero on success, or the negation 10 | of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:lseek.html[lseek], 15 | link:truncate.html[truncate] 16 | -------------------------------------------------------------------------------- /docs/setsid.txt: -------------------------------------------------------------------------------- 1 | setsid 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t setsid(void); 7 | --------------------------------------------- 8 | 9 | Creates a new session for the current process by setting the process group ID to the current process ID. Returns 10 | the new process group ID. 11 | 12 | See also 13 | -------- 14 | link:getpgid.html[getpgid], 15 | link:getpgrp.html[getpgrp], 16 | link:setpgid.html[setpgid] 17 | -------------------------------------------------------------------------------- /docs/shm_unlink.txt: -------------------------------------------------------------------------------- 1 | shm_unlink 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int shm_unlink(const char* path); 7 | --------------------------------------------- 8 | 9 | Deletes the shared memory page denoted by `path`. Returns zero on success, or the negation of the error code on error. 10 | 11 | WARNING: This function is not yet available on Linux. 12 | 13 | See also 14 | -------- 15 | link:shm_open.html[shm_open] 16 | -------------------------------------------------------------------------------- /docs/sysctl.txt: -------------------------------------------------------------------------------- 1 | sysctl 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int sysctl(const int* name, size_t namelen, void* oldp, size_t* oldlenp, const void* newp, size_t newlen); 7 | --------------------------------------------- 8 | 9 | Retrieves system information. The information is OS dependent. See the documentation for the target platform. 10 | 11 | IMPORTANT: This function is only available on FreeBSD and Mac OS X. 12 | -------------------------------------------------------------------------------- /docs/dup2.txt: -------------------------------------------------------------------------------- 1 | dup2 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int dup2(int oldFd, int newFd); 7 | --------------------------------------------- 8 | 9 | Duplicates the file handle `oldFd` such that the new file handle is `newFd`. If file handle `newFd` is 10 | already open, the existing file handle is closed. Returns the new file handle. 11 | 12 | See also 13 | -------- 14 | link:close.html[close], 15 | link:dup.html[dup] 16 | -------------------------------------------------------------------------------- /docs/setpgid.txt: -------------------------------------------------------------------------------- 1 | setpgid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setpgid(pid_t pid, pid_t pgid); 7 | --------------------------------------------- 8 | 9 | Sets the process group ID for process `pid` to `pgid`. Returns zero on success, or the negation of the error 10 | code on failure. 11 | 12 | See also 13 | -------- 14 | link:getpgid.html[getpgid], 15 | link:getpgrp.html[getpgrp], 16 | link:setsid.html[setsid] 17 | -------------------------------------------------------------------------------- /docs/rc4_init.txt: -------------------------------------------------------------------------------- 1 | rc4_init 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void rc4_init(rc4_state_t* state, void* key, size_t keylen); 7 | --------------------------------------------- 8 | 9 | Initializes the RC4 state in `state` with the key of length `keylen` pointed to by `key`. 10 | 11 | See also 12 | -------- 13 | link:rc4_overview.html[RC4 overview], 14 | link:rc4_crypt.html[rc4_crypt], 15 | link:rc4_output.html[rc4_output] 16 | -------------------------------------------------------------------------------- /docs/memcpy.txt: -------------------------------------------------------------------------------- 1 | memcpy 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* memcpy(void* dest, const void* src, size_t len); 7 | --------------------------------------------- 8 | 9 | Copies `len` bytes from `src` to `dest`. Returns a pointer to `dest`. 10 | 11 | IMPORTANT: If the source and destination might overlap, use `memmove` instead. 12 | 13 | See also 14 | -------- 15 | link:memmove.html[memmove], 16 | link:memset.html[memset] 17 | -------------------------------------------------------------------------------- /docs/setgid.txt: -------------------------------------------------------------------------------- 1 | setgid 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setgid(gid_t id); 7 | -------------------------------------------- 8 | 9 | Sets the real group ID of the current process to `id`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:getegid.html[getegid], 14 | link:getgid.html[getgid], 15 | link:setegid.html[setegid], 16 | link:setregid.html[setregid] 17 | -------------------------------------------------------------------------------- /docs/setuid.txt: -------------------------------------------------------------------------------- 1 | setuid 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setuid(gid_t id); 7 | -------------------------------------------- 8 | 9 | Sets the real user ID of the current process to `id`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:geteuid.html[geteuid], 14 | link:getuid.html[getuid], 15 | link:seteuid.html[seteuid], 16 | link:setreuid.html[setreuid] 17 | -------------------------------------------------------------------------------- /docs/tgkill.txt: -------------------------------------------------------------------------------- 1 | tgkill 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int tgkill(int tgid, int tid, int sig); 7 | --------------------------------------------- 8 | 9 | Sends the signal `sig` to thread `tid`, which is part of process `tgid`. Returns zero on success, or the negation 10 | of the error code on error. 11 | 12 | IMPORTANT: This function is only available on Linux. 13 | 14 | See also 15 | -------- 16 | link:kill.html[kill] 17 | -------------------------------------------------------------------------------- /docs/setegid.txt: -------------------------------------------------------------------------------- 1 | setegid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setegid(gid_t id); 7 | --------------------------------------------- 8 | 9 | Sets the effective group ID of the current process to `id`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:getegid.html[getegid], 14 | link:getgid.html[getgid], 15 | link:setgid.html[setgid], 16 | link:setregid.html[setregid] 17 | -------------------------------------------------------------------------------- /docs/seteuid.txt: -------------------------------------------------------------------------------- 1 | seteuid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int seteuid(gid_t id); 7 | --------------------------------------------- 8 | 9 | Sets the effective user ID of the current process to `id`. Returns zero on success, or the negation of the error code on error. 10 | 11 | See also 12 | -------- 13 | link:geteuid.html[geteuid], 14 | link:getuid.html[getuid], 15 | link:setuid.html[setuid], 16 | link:setreuid.html[setreuid] 17 | -------------------------------------------------------------------------------- /docs/snprintf.txt: -------------------------------------------------------------------------------- 1 | snprintf 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int snprintf(char* out, size_t len, const char* fmt, ...); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to the string `out`, with maximum length `len`. See 10 | the link:format.html[format specifier reference] for the supported format specifiers. 11 | 12 | See also 13 | -------- 14 | link:sprintf.html[sprintf] 15 | -------------------------------------------------------------------------------- /docs/strncpy.txt: -------------------------------------------------------------------------------- 1 | strncpy 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* strncpy(char* dest, const char* src, size_t len); 7 | --------------------------------------------- 8 | 9 | Copies a null-terminated string from `src` into `dest`, with maximum length `len`. Returns a 10 | pointer to the destination string. 11 | 12 | See also 13 | -------- 14 | link:strcat.html[strcat], 15 | link:strcpy.html[strcpy], 16 | link:strdup.html[strdup] 17 | -------------------------------------------------------------------------------- /docs/sh.txt: -------------------------------------------------------------------------------- 1 | sh 2 | == 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void sh(); 7 | --------------------------------------------- 8 | 9 | Executes the `sh` shell. No arguments are provided to `sh`. This function does not return if the command 10 | executes successfully. 11 | 12 | See also 13 | -------- 14 | link:bash.html[bash], 15 | link:interactive_bash.html[interactive_bash], 16 | link:interactive_sh.html[interactive_sh], 17 | link:system.html[system] 18 | -------------------------------------------------------------------------------- /docs/strcat.txt: -------------------------------------------------------------------------------- 1 | strcat 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* strcat(char* dest, const char* src); 7 | --------------------------------------------- 8 | 9 | Appends the null-terminated string `src` to `dest`. The maximum length 10 | of the string is not bounded. Returns a pointer to the destination string. 11 | 12 | See also 13 | -------- 14 | link:strcpy.html[strcpy], 15 | link:strdup.html[strdup], 16 | link:strncpy.html[strncpy] 17 | -------------------------------------------------------------------------------- /docs/printf.txt: -------------------------------------------------------------------------------- 1 | printf 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int printf(const char* fmt, ...); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to standard output. See the link:format.html[format specifier reference] 10 | for the supported format specifiers. 11 | 12 | See also 13 | -------- 14 | link:fprintf.html[fprintf], 15 | link:vfprintf.html[vfprintf], 16 | link:vprintf.html[vprintf], 17 | -------------------------------------------------------------------------------- /docs/strcpy.txt: -------------------------------------------------------------------------------- 1 | strcpy 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* strcpy(char* dest, const char* src); 7 | --------------------------------------------- 8 | 9 | Copies a null-terminated string from `src` into `dest`. The maximum length 10 | of the string is not bounded. Returns a pointer to the destination string. 11 | 12 | See also 13 | -------- 14 | link:strcat.html[strcat], 15 | link:strdup.html[strdup], 16 | link:strncpy.html[strncpy] 17 | -------------------------------------------------------------------------------- /docs/bash.txt: -------------------------------------------------------------------------------- 1 | bash 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void bash(); 7 | --------------------------------------------- 8 | 9 | Executes the `bash` shell. No arguments are provided to `bash`. This function does not return if the command 10 | executes successfully. 11 | 12 | See also 13 | -------- 14 | link:interactive_bash.html[interactive_bash], 15 | link:interactive_sh.html[interactive_sh], 16 | link:sh.html[sh], 17 | link:system.html[system] 18 | -------------------------------------------------------------------------------- /docs/getitimer.txt: -------------------------------------------------------------------------------- 1 | getitimer 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | nt getitimer(int which, struct itimerval* value); 7 | --------------------------------------------- 8 | 9 | Gets the current value of interval timer `which` and places the result in `value`. The `which` parameter can be one 10 | of `ITIMER_REAL`, `ITIMER_VIRTUAL`, or `ITIMER_PROF`. 11 | 12 | See also 13 | -------- 14 | link:alarm.html[alarm], 15 | link:setitimer.html[setitimer] 16 | -------------------------------------------------------------------------------- /docs/fchflags.txt: -------------------------------------------------------------------------------- 1 | fchflags 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fchflags(int fd, int flags); 7 | --------------------------------------------- 8 | 9 | Sets the FreeBSD file flags of the file handle `fd` to `flags`. The FreeBSD macros, such as `UF_IMMUTABLE`, are 10 | available. Returns zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:chflags.html[chflags], 15 | link:lchflags.html[lchflags] 16 | -------------------------------------------------------------------------------- /docs/lseek.txt: -------------------------------------------------------------------------------- 1 | lseek 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | size_t lseek(int fd, int64_t offset, int whence); 7 | --------------------------------------------- 8 | 9 | Changes the file position of the file handle `fd`. The `whence` argument can be `SEEK_SET`, `SEEK_CUR`, or `SEEK_END`. 10 | Returns the new location relative to the start of the file. 11 | 12 | See also 13 | -------- 14 | link:ftruncate.html[ftruncate], 15 | link:truncate.html[truncate] 16 | -------------------------------------------------------------------------------- /docs/listen.txt: -------------------------------------------------------------------------------- 1 | listen 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int listen(int sockfd, int backlog); 7 | --------------------------------------------- 8 | 9 | Listens for new connections on socket `sockfd`. The maximum number of queued connections is `backlog`. Returns 10 | zero on success, or the negation of the error code on failure. 11 | 12 | See also 13 | -------- 14 | link:accept.html[accept], 15 | link:bind.html[bind], 16 | link:socket.html[socket] 17 | -------------------------------------------------------------------------------- /docs/rc4_output.txt: -------------------------------------------------------------------------------- 1 | rc4_output 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | uint8_t rc4_output(rc4_state_t* state); 7 | --------------------------------------------- 8 | 9 | Returns the next byte of the RC4 key stream. The `state` structure can be initialized with the 10 | link:rc4_init.html[rc4_init] function. 11 | 12 | See also 13 | -------- 14 | link:rc4_overview.html[RC4 overview], 15 | link:rc4_crypt.html[rc4_crypt], 16 | link:rc4_init.html[rc4_init] 17 | -------------------------------------------------------------------------------- /docs/chown.txt: -------------------------------------------------------------------------------- 1 | chown 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int chown(const char* path, uid_t owner, gid_t group); 7 | --------------------------------------------- 8 | 9 | Changes the owner to `owner` and group to `group` for the file at `path`. If `path` is a symbolic link, the link is 10 | followed. Returns zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:fchown.html[fchown], 15 | link:lchown.html[lchown] 16 | -------------------------------------------------------------------------------- /docs/getgroups.txt: -------------------------------------------------------------------------------- 1 | getgroups 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int getgroups(int size, gid_t* groups); 7 | --------------------------------------------- 8 | 9 | Obtains the list of groups the current process is a member of. Up to `size` entires may be placed into the `groups` array. 10 | Returns the number of groups, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:getegid.html[getegid], 15 | link:getgid.html[getgid] 16 | -------------------------------------------------------------------------------- /docs/shutdown.txt: -------------------------------------------------------------------------------- 1 | shutdown 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int shutdown(int sockfd, int how); 7 | --------------------------------------------- 8 | 9 | Shuts down the socket `sockfd`. The `how` parameter can be one of `SHUT_RD`, `SHUT_WR`, or `SHUT_RDWR`. Returns 10 | zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:bind.html[bind], 15 | link:connect.html[connect], 16 | link:socket.html[socket] 17 | -------------------------------------------------------------------------------- /docs/wait.txt: -------------------------------------------------------------------------------- 1 | wait 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t wait(int* status); 7 | --------------------------------------------- 8 | 9 | Waits for a child process to complete. If `status` is not `NULL`, the exit status of the child process that 10 | has been completed is written to the pointer. Returns the process ID of the child process that exited, or 11 | the negation of the error code on error. 12 | 13 | See also 14 | -------- 15 | link:waitpid.html[waitpid] 16 | -------------------------------------------------------------------------------- /docs/lchown.txt: -------------------------------------------------------------------------------- 1 | lchown 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int lchown(const char* path, uid_t owner, gid_t group); 7 | --------------------------------------------- 8 | 9 | Changes the owner to `owner` and group to `group` for the file at `path`. If `path` is a symbolic link, the link 10 | itself is modified. Returns zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:fchown.html[fchown], 15 | link:lchown.html[lchown] 16 | -------------------------------------------------------------------------------- /docs/next_arg.txt: -------------------------------------------------------------------------------- 1 | __next_arg 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* __next_arg(void* ptr, size_t size); 7 | --------------------------------------------- 8 | 9 | Returns a pointer to the next argument given the pointer to the current argument, `ptr`, and 10 | the size of the current argument, `size`. This intrinsic can be used to find the next 11 | argument regardless of the direction of stack growth. 12 | 13 | See also 14 | -------- 15 | link:prev_arg.html[prev_arg] 16 | -------------------------------------------------------------------------------- /docs/system.txt: -------------------------------------------------------------------------------- 1 | system 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int system(const char* cmd); 7 | --------------------------------------------- 8 | 9 | Executes the command `cmd` within a new shell process. Returns the exit status of the command. 10 | 11 | See also 12 | -------- 13 | link:bash.html[bash], 14 | link:execve.html[execve], 15 | link:fork.html[fork], 16 | link:interactive_bash.html[interactive_bash], 17 | link:interactive_sh.html[interactive_sh], 18 | link:sh.html[sh] 19 | -------------------------------------------------------------------------------- /docs/waitpid.txt: -------------------------------------------------------------------------------- 1 | waitpid 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t waitpid(pid_t pid, int* status, int options); 7 | --------------------------------------------- 8 | 9 | Waits for the child process `pid` to complete. If `status` is not `NULL`, the exit status of the process 10 | is written to the pointer. Returns the process ID of the child process that exited, or the negation of 11 | the error code on error. 12 | 13 | See also 14 | -------- 15 | link:wait.html[wait] 16 | -------------------------------------------------------------------------------- /docs/rc4_crypt.txt: -------------------------------------------------------------------------------- 1 | rc4_crypt 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void rc4_crypt(rc4_state_t* state, void* data, size_t len); 7 | --------------------------------------------- 8 | 9 | Encrypts or decrypts `len` bytes pointed to by `data`. The `state` structure can be initialized with 10 | the link:rc4_init.html[rc4_init] function. 11 | 12 | See also 13 | -------- 14 | link:rc4_overview.html[RC4 overview], 15 | link:rc4_init.html[rc4_init], 16 | link:rc4_output.html[rc4_output] 17 | -------------------------------------------------------------------------------- /docs/signal.txt: -------------------------------------------------------------------------------- 1 | signal 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | sig_t signal(int sig, sig_t func); 7 | --------------------------------------------- 8 | 9 | Sets the signal handler for `sig` to `func`. The `func` parameter can be `SIG_DFL` for the default handler, or `SIG_IGN` to 10 | ignore the signal. 11 | 12 | WARNING: Setting a handler other than `SIG_DFL` or `SIG_IGN` is not yet supported on 64-bit platforms. 13 | 14 | See also 15 | -------- 16 | link:sigaction.html[sigaction] 17 | -------------------------------------------------------------------------------- /docs/prev_arg.txt: -------------------------------------------------------------------------------- 1 | __prev_arg 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* __prev_arg(void* ptr, size_t size); 7 | --------------------------------------------- 8 | 9 | Returns a pointer to the previous argument given the pointer to the current argument, `ptr`, and 10 | the size of the previous argument, `size`. This intrinsic can be used to find the previous 11 | argument regardless of the direction of stack growth. 12 | 13 | See also 14 | -------- 15 | link:next_arg.html[next_arg] 16 | -------------------------------------------------------------------------------- /docs/fprintf.txt: -------------------------------------------------------------------------------- 1 | fprintf 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fprintf(FILE* fp, const char* fmt, ...); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to the file stream `fp`. See the link:format.html[format specifier reference] 10 | for the supported format specifiers. 11 | 12 | See also 13 | -------- 14 | link:fdopen.html[fdopen], 15 | link:printf.html[printf], 16 | link:vfprintf.html[vfprintf], 17 | link:vprintf.html[vprintf] 18 | -------------------------------------------------------------------------------- /docs/chflags.txt: -------------------------------------------------------------------------------- 1 | chflags 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int chflags(const char* path, int flags); 7 | --------------------------------------------- 8 | 9 | Sets the FreeBSD file flags of `path` to `flags`. If `path` is a symbolic link, the link is followed. The FreeBSD 10 | macros, such as `UF_IMMUTABLE`, are available. Returns zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:fchflags.html[fchflags], 15 | link:lchflags.html[lchflags] 16 | -------------------------------------------------------------------------------- /docs/vsprintf.txt: -------------------------------------------------------------------------------- 1 | vsprintf 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int vsprintf(char* out, const char* fmt, va_list va); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to the string `out`. Uses the argument list `va` as the source of arguments 10 | referenced by the format string. See the link:format.html[format specifier reference] 11 | for the supported format specifiers. 12 | 13 | See also 14 | -------- 15 | link:vsnprintf.html[vsnprintf] 16 | -------------------------------------------------------------------------------- /docs/interactive_sh.txt: -------------------------------------------------------------------------------- 1 | interactive_sh 2 | ============== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void interactive_sh(); 7 | --------------------------------------------- 8 | 9 | Executes the `sh` shell. The "`-i`" argument is provided to `sh` so that it is started in interactive mode. 10 | This function does not return if the command executes successfully. 11 | 12 | See also 13 | -------- 14 | link:bash.html[bash], 15 | link:interactive_bash.html[interactive_bash], 16 | link:sh.html[sh], 17 | link:system.html[system] 18 | -------------------------------------------------------------------------------- /docs/readlink.txt: -------------------------------------------------------------------------------- 1 | readlink 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t readlink(const char* path, char* buf, size_t size); 7 | --------------------------------------------- 8 | 9 | Reads the symbolic link at `path` and stores the target at `buf`, with maximum length `size`. Returns the size of 10 | the link in bytes on success, or the negation of the error code on error. 11 | 12 | IMPORTANT: The result buffer is not null terminated. 13 | 14 | See also 15 | -------- 16 | link:symlink.html[symlink] 17 | -------------------------------------------------------------------------------- /docs/lchflags.txt: -------------------------------------------------------------------------------- 1 | lchflags 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int lchflags(const char* path, int flags); 7 | --------------------------------------------- 8 | 9 | Sets the FreeBSD file flags of `path` to `flags`. If `path` is a symbolic link, the link itself is modified. The FreeBSD 10 | macros, such as `UF_IMMUTABLE`, are available. Returns zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:chflags.html[chflags], 15 | link:fchflags.html[fchflags] 16 | -------------------------------------------------------------------------------- /docs/mprotect.txt: -------------------------------------------------------------------------------- 1 | mprotect 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int mprotect(void* addr, size_t len, int prot); 7 | --------------------------------------------- 8 | 9 | Changes the protection on a block of memory of `len` bytes starting at `addr` to `prot`. 10 | 11 | The protection flags in `prot` can include one or more of `PROT_READ`, `PROT_WRITE`, and `PROT_EXEC`. 12 | 13 | Returns zero on success, or the negation of the error code on failure. 14 | 15 | See also 16 | -------- 17 | link:mmap.html[mmap] 18 | -------------------------------------------------------------------------------- /docs/accept.txt: -------------------------------------------------------------------------------- 1 | accept 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen); 7 | --------------------------------------------- 8 | 9 | Accepts a new connection on socket `sockfd`. If `addr` is not `NULL`, the address of the peer is stored. 10 | The handle of the connected socket is returned on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:bind.html[bind], 15 | link:listen.html[listen], 16 | link:socket.html[socket] 17 | -------------------------------------------------------------------------------- /docs/interactive_bash.txt: -------------------------------------------------------------------------------- 1 | interactive_bash 2 | ================ 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void interactive_bash(); 7 | --------------------------------------------- 8 | 9 | Executes the `bash` shell. The "`-i`" argument is provided to `bash` so that it is started in interactive mode. 10 | This function does not return if the command executes successfully. 11 | 12 | See also 13 | -------- 14 | link:bash.html[bash], 15 | link:interactive_sh.html[interactive_sh], 16 | link:sh.html[sh], 17 | link:system.html[system] 18 | -------------------------------------------------------------------------------- /docs/redirect_io.txt: -------------------------------------------------------------------------------- 1 | redirect_io 2 | =========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void redirect_io(int fd); 7 | --------------------------------------------- 8 | 9 | Redirects standard input, standard output, and standard error to the file handle `fd`. This is commonly used to redirect 10 | a command to an open socket. 11 | 12 | See also 13 | -------- 14 | link:bash.html[bash], 15 | link:execve.html[execve], 16 | link:interactive_bash.html[interactive_bash], 17 | link:interactive_sh.html[interactive_sh], 18 | link:sh.html[sh] 19 | -------------------------------------------------------------------------------- /docs/setreuid.txt: -------------------------------------------------------------------------------- 1 | setreuid 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setreuid(uid_t rid, uid_t eid); 7 | --------------------------------------------- 8 | 9 | Sets the real user ID to `rid` and the effective user ID to `eid`. If either parameter is zero, the corresponding ID 10 | is not set. Returns zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:geteuid.html[geteuid], 15 | link:getuid.html[getuid], 16 | link:setuid.html[setuid], 17 | link:seteuid.html[seteuid] 18 | -------------------------------------------------------------------------------- /docs/setregid.txt: -------------------------------------------------------------------------------- 1 | setregid 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setregid(uid_t rid, uid_t eid); 7 | --------------------------------------------- 8 | 9 | Sets the real group ID to `rid` and the effective group ID to `eid`. If either parameter is zero, the corresponding ID 10 | is not set. Returns zero on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:getegid.html[getegid], 15 | link:getgid.html[getgid], 16 | link:setgid.html[setgid], 17 | link:setegid.html[setegid] 18 | -------------------------------------------------------------------------------- /docs/accept4.txt: -------------------------------------------------------------------------------- 1 | accept4 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int accept4(int sockfd, struct sockaddr* addr, socklen_t* addrlen, int flags); 7 | --------------------------------------------- 8 | 9 | Accepts a new connection on socket `sockfd`. If `addr` is not `NULL`, the address of the peer is stored. 10 | The handle of the connected socket is returned on success, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:bind.html[bind], 15 | link:listen.html[listen], 16 | link:socket.html[socket] 17 | -------------------------------------------------------------------------------- /docs/send_all.txt: -------------------------------------------------------------------------------- 1 | send_all 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t send_all(int fd, const void* buf, size_t n, int flags); 7 | --------------------------------------------- 8 | 9 | Sends `n` bytes from `buf` to socket handle `fd`. Does not return until all `n` bytes have been sent, or there 10 | is an error. Returns the number of bytes sent, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:recv_all.html[recv_all], 15 | link:send.html[send], 16 | link:send_string.html[send_string] 17 | -------------------------------------------------------------------------------- /docs/sendfile.txt: -------------------------------------------------------------------------------- 1 | sendfile 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t sendfile(int outFd, int inFd, size_t* offset, size_t count); 7 | --------------------------------------------- 8 | 9 | Sends `count` bytes from the file `inFd` to the socket `outFd`. If `offset` is provided, first seeks to the 10 | location provided relative to the start of the file. Returns the number of bytes sent, or the negation of 11 | the error code on error. 12 | 13 | See also 14 | -------- 15 | link:read.html[read], 16 | link:write.html[write] 17 | -------------------------------------------------------------------------------- /docs/socketpair.txt: -------------------------------------------------------------------------------- 1 | socketpair 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int socketpair(int domain, int type, int protocol, int fds[2]); 7 | --------------------------------------------- 8 | 9 | Creates two connected sockets of the given type. 10 | 11 | IMPORTANT: The `domain` parameter must use the `PF_*` family of constants. The `AF_*` family of constants do not 12 | have the correct value for the `socket` function on BSD. This is to facilitate cross-platform code. 13 | 14 | See also 15 | -------- 16 | link:socket.html[socket] 17 | -------------------------------------------------------------------------------- /docs/vsnprintf.txt: -------------------------------------------------------------------------------- 1 | vsnprintf 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int vsnprintf(char* out, size_t len, const char* fmt, va_list va); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to the string `out`, with maximum length `len`. Uses the argument 10 | list `va` as the source of arguments referenced by the format string. See the link:format.html[format specifier reference] 11 | for the supported format specifiers. 12 | 13 | See also 14 | -------- 15 | link:vsprintf.html[vsprintf] 16 | -------------------------------------------------------------------------------- /docs/vprintf.txt: -------------------------------------------------------------------------------- 1 | vprintf 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int vprintf(const char* fmt, va_list va); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to standard output. Uses the argument list `va` as the source of arguments 10 | referenced by the format string. See the link:format.html[format specifier reference] 11 | for the supported format specifiers. 12 | 13 | See also 14 | -------- 15 | link:fprintf.html[fprintf], 16 | link:printf.html[printf], 17 | link:vfprintf.html[vfprintf] 18 | -------------------------------------------------------------------------------- /docs/fork.txt: -------------------------------------------------------------------------------- 1 | fork 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | pid_t fork(void); 7 | --------------------------------------------- 8 | 9 | Forks the current process. Returns zero in the child process, and returns the PID of the child 10 | in the parent process. 11 | 12 | CAUTION: If the signal `SIGCHLD` is not ignored, child processes will become zombies on exit if 13 | `wait` or `waitpid` is not issued by the parent for the child process. 14 | 15 | See also 16 | -------- 17 | link:exit.html[exit], 18 | link:wait.html[wait], 19 | link:waitpid.html[waitpid] 20 | -------------------------------------------------------------------------------- /docs/getdents.txt: -------------------------------------------------------------------------------- 1 | getdents 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int getdents(int fd, struct dirent* dirp, size_t count); 7 | --------------------------------------------- 8 | 9 | Get `count` directory entries from the open directory handle `fd`. The `struct dirent` structure varies by 10 | platform, but always contains the `d_name` field, which holds the name of the file. Returns the number of 11 | bytes of directory entries read, or the negation of the error code on error. 12 | 13 | See also 14 | -------- 15 | link:getdirentries.html[getdirentries] 16 | -------------------------------------------------------------------------------- /docs/nanosleep.txt: -------------------------------------------------------------------------------- 1 | nanosleep 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int nanosleep(const struct timespec* amount, struct timespec* unslept); 7 | --------------------------------------------- 8 | 9 | Sleeps for the interval defined by `amount`. If the time requested elapses without interruption, the function 10 | returns zero. If the call is interrupted, the return value is the negation of the error code, and `unslept` 11 | is filled in with the time left to sleep if `unslept` is not `NULL`. 12 | 13 | See also 14 | -------- 15 | link:alarm.html[alarm] 16 | -------------------------------------------------------------------------------- /docs/send_string.txt: -------------------------------------------------------------------------------- 1 | send_string 2 | =========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t send_string(int fd, const char* str); 7 | --------------------------------------------- 8 | 9 | Sends the string `str` over the socket handle `fd`. The null terminator is not sent. Does not return until 10 | the entire string has been sent, or there is an error. Returns the number of bytes sent, or the negation 11 | of the error code on error. 12 | 13 | See also 14 | -------- 15 | link:recv_all.html[recv_all], 16 | link:send.html[send], 17 | link:send_all.html[send_all] 18 | -------------------------------------------------------------------------------- /docs/recv_all.txt: -------------------------------------------------------------------------------- 1 | recv_all 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t recv_all(int fd, void* buf, size_t n, int flags); 7 | --------------------------------------------- 8 | 9 | Receives `n` bytes from socket handle `fd` and places the result into `buf`. Does not return until all `n` bytes 10 | have been received, or there is an error. Returns the number of bytes received, or the negation of the error 11 | code on error. 12 | 13 | See also 14 | -------- 15 | link:recv.html[recv], 16 | link:send_all.html[send_all], 17 | link:send_string.html[send_string] 18 | -------------------------------------------------------------------------------- /docs/socket.txt: -------------------------------------------------------------------------------- 1 | socket 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int socket(int domain, int type, int protocol); 7 | --------------------------------------------- 8 | 9 | Creates a new socket of the given type. 10 | 11 | IMPORTANT: The `domain` parameter must use the `PF_*` family of constants. The `AF_*` family of constants do not 12 | have the correct value for the `socket` function on BSD. This is to facilitate cross-platform code. 13 | 14 | See also 15 | -------- 16 | link:bind.html[bind], 17 | link:connect.html[connect], 18 | link:socketpair.html[socketpair] 19 | -------------------------------------------------------------------------------- /genlibrary.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | 4 | data = open(sys.argv[1], 'rb').read() 5 | fout = open(sys.argv[2], 'w') 6 | 7 | name = sys.argv[3].replace("/", "_").replace("\\", "_").replace(".", "_") 8 | 9 | fout.write("unsigned char %s[] = {" % name) 10 | 11 | for i in range(0, len(data)): 12 | if ((i % 16) == 0) and (i > 0): 13 | fout.write("\n") 14 | val = data[i] 15 | if type(val) is not int: 16 | val = ord(data[i]) 17 | fout.write("0x%.2x" % val) 18 | if (i + 1) < len(data): 19 | fout.write(", ") 20 | 21 | fout.write("};\n") 22 | fout.write("unsigned int %s_len = %d;\n" % (name, len(data))) 23 | fout.close() 24 | -------------------------------------------------------------------------------- /docs/open.txt: -------------------------------------------------------------------------------- 1 | open 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int open(const char* file, int flags, int mode); 7 | --------------------------------------------- 8 | 9 | Opens the file at `path`. The `flags` argument is typically `O_RDONLY`, `O_WRONLY`, or `O_RDWR`. The `mode` 10 | argument specifies the file permissions if the file is created. 11 | 12 | IMPORTANT: The `mode` parameter must always be specified for this runtime, even when not creating a file. Use 13 | zero or the `__undefined` intrinsic when not creating a file. 14 | 15 | See also 16 | -------- 17 | link:close.html[close] 18 | -------------------------------------------------------------------------------- /docs/create_tcp6_connection.txt: -------------------------------------------------------------------------------- 1 | create_tcp6_connection 2 | ====================== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int create_tcp6_connection(const void* ip, uint16_t port); 7 | --------------------------------------------- 8 | 9 | Creates a new TCP connection on port `port` to IPv6 address `ip`. Returns an open socket handle, or the 10 | negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:create_tcp4_connection.html[create_tcp4_connection], 15 | link:create_udp4_connection.html[create_udp4_connection], 16 | link:create_udp6_connection.html[create_udp6_connection] 17 | -------------------------------------------------------------------------------- /docs/create_udp6_connection.txt: -------------------------------------------------------------------------------- 1 | create_udp6_connection 2 | ====================== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int create_udp6_connection(const void* ip, uint16_t port); 7 | --------------------------------------------- 8 | 9 | Creates a new TCP connection on port `port` to IPv6 address `ip`. Returns an open socket handle, or the 10 | negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:create_tcp4_connection.html[create_tcp4_connection], 15 | link:create_tcp6_connection.html[create_tcp6_connection], 16 | link:create_udp4_connection.html[create_udp4_connection] 17 | -------------------------------------------------------------------------------- /docs/quark_exec.txt: -------------------------------------------------------------------------------- 1 | quark_exec 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void quark_exec(void* buf, ...) __noreturn; 7 | --------------------------------------------- 8 | 9 | Executes a block of Quark VM code. Does not return. Quark VM code can be generated by running the Shellcode Compiler with 10 | the "`quark`" architecture option ("`--arch`"). Any extra parameters passed to this function will be forwarded to the 11 | `main` function in the VM code. 12 | 13 | IMPORTANT: As the Quark VM instruction set is 32-bit only, the VM interpreter is only available on 32-bit platforms. 14 | 15 | -------------------------------------------------------------------------------- /docs/vfprintf.txt: -------------------------------------------------------------------------------- 1 | vfprintf 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int vfprintf(FILE* fp, const char* fmt, va_list va); 7 | --------------------------------------------- 8 | 9 | Writes a formatted string with format `fmt` to the file stream `fp`. Uses the argument list `va` as the source of arguments 10 | referenced by the format string. See the link:format.html[format specifier reference] 11 | for the supported format specifiers. 12 | 13 | See also 14 | -------- 15 | link:fdopen.html[fdopen], 16 | link:fprintf.html[fprintf], 17 | link:printf.html[printf], 18 | link:vprintf.html[vprintf] 19 | -------------------------------------------------------------------------------- /tests/div64_output: -------------------------------------------------------------------------------- 1 | 000000000000001f 2 | 0000000000000023 3 | 000225e5827e6104 4 | 00000000000006bd 5 | 0000000000000009 6 | 0202020202020202 7 | 000000000000001f 8 | 0000000000000023 9 | ffffffffffffffe1 10 | ffffffffffffffdd 11 | ffffffffffffffe1 12 | 0000000000000023 13 | 000000000000001f 14 | ffffffffffffffdd 15 | 000225e5827e6104 16 | 00000000000006bd 17 | fffdda1a7d819efc 18 | fffffffffffff943 19 | fffdda1a7d819efc 20 | 00000000000006bd 21 | 000225e5827e6104 22 | fffffffffffff943 23 | 0000000000000009 24 | 0202020202020202 25 | fffffffffffffff7 26 | fdfdfdfdfdfdfdfe 27 | fffffffffffffff7 28 | 0202020202020202 29 | 0000000000000009 30 | fdfdfdfdfdfdfdfe 31 | -------------------------------------------------------------------------------- /docs/fgets.txt: -------------------------------------------------------------------------------- 1 | fgets 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | char* fgets(char* result, int size, FILE* fp); 7 | --------------------------------------------- 8 | 9 | Reads the next line from the file stream `fp` and stores the result in `result`. The maximum number of characters 10 | read is `size`. The newline character is included in the string, unless there are more characters than `size` present 11 | on the current line. Returns a pointer to `result`, or NULL on failure or at the end of the file. 12 | 13 | See also 14 | -------- 15 | link:fdopen.html[fdopen], 16 | link:fgetc.html[fgetc] 17 | -------------------------------------------------------------------------------- /docs/fdopen.txt: -------------------------------------------------------------------------------- 1 | fdopen 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | FILE* fdopen(int fd); 7 | --------------------------------------------- 8 | 9 | Opens a file stream using file handle `fd`. Returns the file stream. 10 | 11 | TIP: File stream pointers (`FILE*`) are actually just file handles cast to a pointer type. The implementation 12 | of this function is actually a simple macro with a direct cast to the `FILE*` type. 13 | 14 | See also 15 | -------- 16 | link:fgetc.html[fgetc], 17 | link:fgets.html[fgets], 18 | link:fprintf.html[fprintf], 19 | link:fputc.html[fputc], 20 | link:fputs.html[fputs] 21 | -------------------------------------------------------------------------------- /docs/setitimer.txt: -------------------------------------------------------------------------------- 1 | setitimer 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int setitimer(int which, const struct itimerval* value, struct itimerval* old); 7 | --------------------------------------------- 8 | 9 | Sets the interval timer `which` to `value`. The `which` parameter can be one of `ITIMER_REAL`, `ITIMER_VIRTUAL`, 10 | or `ITIMER_PROF`. The old timer value is stored in `old` if it is not `NULL`. 11 | 12 | Setting the `ITIMER_REAL` interval timer can produce the same results as the `alarm` function. 13 | 14 | See also 15 | -------- 16 | link:alarm.html[alarm], 17 | link:getitimer.html[getitimer] 18 | -------------------------------------------------------------------------------- /docs/sigaction.txt: -------------------------------------------------------------------------------- 1 | sigaction 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int sigaction(int sig, const struct sigaction* act, struct sigaction* old); 7 | --------------------------------------------- 8 | 9 | Sets the signal handler for `sig` to `act`, and stores the old signal handler information in `old` if not `NULL`. 10 | The `sa_handler` field in `act` can be `SIG_DFL` for the default handler, or `SIG_IGN` to ignore the signal. 11 | 12 | WARNING: Setting a handler other than `SIG_DFL` or `SIG_IGN` is not yet supported on 64-bit platforms. 13 | 14 | See also 15 | -------- 16 | link:signal.html[signal] 17 | -------------------------------------------------------------------------------- /tests/string.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | char* str = "The quick brown fox jumps over the lazy dog!"; 4 | printf("%d\n", strlen(str)); 5 | printf("%d\n", strchr(str, 'e') - str); 6 | printf("%d\n", strchr(str, 'T') - str); 7 | printf("%d\n", strchr(str, '!') - str); 8 | printf("%d\n", strrchr(str, 'e') - str); 9 | printf("%d\n", strrchr(str, 'T') - str); 10 | printf("%d\n", strrchr(str, '!') - str); 11 | 12 | if (strchr(str, '@')) 13 | printf("strchr bad\n"); 14 | if (strrchr(str, '@')) 15 | printf("strrchr bad\n"); 16 | 17 | memmove(str, &str[4], 5); 18 | printf("%s\n", str); 19 | 20 | memmove(&str[11], &str[10], 5); 21 | printf("%s\n", str); 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /docs/gettimeofday.txt: -------------------------------------------------------------------------------- 1 | gettimeofday 2 | ============ 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int gettimeofday(struct timeval* t, struct timezone* tz); 7 | --------------------------------------------- 8 | 9 | Gets the current time and places it into the structure `t`. The `tz` parameter can be `NULL`. The two structures 10 | are as defined below: 11 | 12 | --------------------------------------------- 13 | struct timeval 14 | { 15 | time_t tv_sec; 16 | size_t tv_usec; 17 | }; 18 | 19 | struct timezone 20 | { 21 | int tz_minuteswest; 22 | int tz_dsttime; 23 | }; 24 | --------------------------------------------- 25 | 26 | See also 27 | -------- 28 | link:time.html[time] 29 | -------------------------------------------------------------------------------- /Token.cpp: -------------------------------------------------------------------------------- 1 | #include "Token.h" 2 | #include "Struct.h" 3 | 4 | using namespace std; 5 | 6 | 7 | Token::Token(TokenClass type): m_type(type) 8 | { 9 | } 10 | 11 | 12 | Token::Token(TokenClass type, const string& str): m_type(type), m_string(str) 13 | { 14 | } 15 | 16 | 17 | Token::~Token() 18 | { 19 | } 20 | 21 | 22 | void Token::Serialize(OutputBlock* output) 23 | { 24 | output->WriteInteger(m_type); 25 | output->WriteString(m_string); 26 | } 27 | 28 | 29 | Token* Token::Deserialize(InputBlock* input) 30 | { 31 | uint32_t type; 32 | string str; 33 | 34 | if (!input->ReadUInt32(type)) 35 | return NULL; 36 | if (!input->ReadString(str)) 37 | return NULL; 38 | 39 | return new Token((TokenClass)type, str); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /docs/create_tcp4_connection.txt: -------------------------------------------------------------------------------- 1 | create_tcp4_connection 2 | ====================== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int create_tcp4_connection(uint32_t ip, uint16_t port); 7 | --------------------------------------------- 8 | 9 | Creates a new TCP connection on port `port` to IPv4 address `ip`. The `IPV4_ADDR` macro can be used to construct 10 | an IP address from four octets easily. Returns an open socket handle, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:create_tcp6_connection.html[create_tcp6_connection], 15 | link:create_udp4_connection.html[create_udp4_connection], 16 | link:create_udp6_connection.html[create_udp6_connection] 17 | -------------------------------------------------------------------------------- /docs/create_udp4_connection.txt: -------------------------------------------------------------------------------- 1 | create_udp4_connection 2 | ====================== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int create_udp4_connection(uint32_t ip, uint16_t port); 7 | --------------------------------------------- 8 | 9 | Creates a new UDP connection on port `port` to IPv4 address `ip`. The `IPV4_ADDR` macro can be used to construct 10 | an IP address from four octets easily. Returns an open socket handle, or the negation of the error code on error. 11 | 12 | See also 13 | -------- 14 | link:create_tcp4_connection.html[create_tcp4_connection], 15 | link:create_tcp6_connection.html[create_tcp6_connection], 16 | link:create_udp6_connection.html[create_udp6_connection] 17 | -------------------------------------------------------------------------------- /docs/getdirentries.txt: -------------------------------------------------------------------------------- 1 | getdirentries 2 | ============= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int getdirentries(int fd, struct dirent* dirp, size_t count, ssize_t* basep); 7 | --------------------------------------------- 8 | 9 | Get `count` directory entries from the open directory handle `fd`. The `struct dirent` structure varies by 10 | platform, but always contains the `d_name` field, which holds the name of the file. If `basep` is not 11 | `NULL`, the new location in the directory stream is stored into `basep`. Returns the number of 12 | bytes of directory entries read, or the negation of the error code on error. 13 | 14 | See also 15 | -------- 16 | link:getdents.html[getdents] 17 | -------------------------------------------------------------------------------- /BitVector.h: -------------------------------------------------------------------------------- 1 | #ifndef __BITVECTOR_H__ 2 | #define __BITVECTOR_H__ 3 | 4 | #include 5 | #include 6 | 7 | 8 | class BitVector 9 | { 10 | uint32_t* m_data; 11 | size_t m_size; 12 | 13 | public: 14 | BitVector(); 15 | BitVector(const BitVector& v); 16 | ~BitVector(); 17 | 18 | BitVector& operator=(const BitVector& v); 19 | bool operator==(const BitVector& v); 20 | bool operator!=(const BitVector& v); 21 | 22 | void Reset(size_t size, bool value); 23 | 24 | bool GetBit(size_t bit) const; 25 | void SetBit(size_t bit, bool value); 26 | 27 | size_t GetSize() const; 28 | 29 | void Union(const BitVector& v); 30 | void Intersection(const BitVector& v); 31 | void Difference(const BitVector& v); 32 | }; 33 | 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /Optimize.h: -------------------------------------------------------------------------------- 1 | #ifndef __OPTIMIZE_H__ 2 | #define __OPTIMIZE_H__ 3 | 4 | #include "Function.h" 5 | #include "Linker.h" 6 | 7 | class Optimize 8 | { 9 | Linker* m_linker; 10 | Settings m_settings; 11 | 12 | public: 13 | Optimize(Linker* linker); 14 | 15 | void PerformControlFlowAnalysis(Function* func); 16 | void PerformDataFlowAnalysis(Function* func); 17 | bool ConsolidateBasicBlocks(Function* func); 18 | bool OptimizeForNoReturnCalls(Function* func); 19 | bool FoldConstants(Function* func); 20 | 21 | void InlineFunction(Function* func, Function* target); 22 | 23 | void RemoveUnreferencedSymbols(Function* protectedFunction = NULL); 24 | void PerformGlobalOptimizations(); 25 | bool OptimizeFunction(Function* func); 26 | }; 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /Token.h: -------------------------------------------------------------------------------- 1 | #ifndef __TOKEN_H__ 2 | #define __TOKEN_H__ 3 | 4 | #include 5 | #include "RefCountObject.h" 6 | #include "Output.h" 7 | 8 | 9 | enum TokenClass 10 | { 11 | TOKEN_BASIC, 12 | TOKEN_ID, 13 | TOKEN_LPAREN, 14 | TOKEN_RPAREN, 15 | TOKEN_COMMA, 16 | TOKEN_PASTE 17 | }; 18 | 19 | class Token: public RefCountObject 20 | { 21 | TokenClass m_type; 22 | std::string m_string; 23 | 24 | public: 25 | Token(TokenClass type); 26 | Token(TokenClass type, const std::string& str); 27 | virtual ~Token(); 28 | 29 | TokenClass GetType() const { return m_type; } 30 | const std::string& GetString() const { return m_string; } 31 | 32 | void Serialize(OutputBlock* output); 33 | static Token* Deserialize(InputBlock* input); 34 | }; 35 | 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /docs/execve.txt: -------------------------------------------------------------------------------- 1 | execve 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int execve(const char* filename, const char** argv, const char** envp); 7 | --------------------------------------------- 8 | 9 | Starts a new program. The program started is given by `filename` and passed the argument array `argv`. 10 | The environment variables are given by `envp`, or the default environment if `envp` is NULL. 11 | 12 | This function does not return if successful. Returns the negation of the error code on error. 13 | 14 | See also 15 | -------- 16 | link:bash.html[bash], 17 | link:execl.html[execl], 18 | link:interactive_bash.html[interactive_bash], 19 | link:interactive_sh.html[interactive_sh], 20 | link:sh.html[sh], 21 | link:system.html[system] 22 | -------------------------------------------------------------------------------- /docs/syscall.txt: -------------------------------------------------------------------------------- 1 | __syscall 2 | ========= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | long __syscall(long num, ...); 7 | --------------------------------------------- 8 | 9 | Issues system call number `num` on the target platform. Any additional arguments are passed directly 10 | to the system call. Returns the result of the system call. 11 | 12 | IMPORTANT: On platforms that set a processor flag on error, such as FreeBSD, the `__syscall` function 13 | will return the negation of the error code on error. This is to allow for unified behaviour across 14 | different platforms. For example, checking the result of the `open` call for `-ENOENT` will work 15 | across all supported UNIX-based platforms. 16 | 17 | See also 18 | -------- 19 | link:syscall2.html[syscall2] 20 | -------------------------------------------------------------------------------- /runtime/linux/aarch64/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBC__ARM_STAT_H__ 2 | #define __LIBC__ARM_STAT_H__ 3 | 4 | struct stat 5 | { 6 | uint64_t st_dev; 7 | uint64_t st_ino; 8 | 9 | uint32_t st_mode; 10 | uint32_t st_nlink; 11 | 12 | uint32_t st_uid; 13 | uint32_t st_gid; 14 | 15 | uint64_t st_rdev; 16 | uint64_t __pad1; 17 | 18 | uint64_t st_size; 19 | uint32_t st_blksize; 20 | uint32_t __pad2; 21 | 22 | uint64_t st_blocks; 23 | 24 | uint64_t st_atime; 25 | uint64_t st_atime_nsec; 26 | uint64_t st_mtime; 27 | uint64_t st_mtime_nsec; 28 | uint64_t st_ctime; 29 | uint64_t st_ctime_nsec; 30 | 31 | uint32_t __unused4; 32 | uint32_t __unused5; 33 | }; 34 | 35 | int fstat(int fd, struct stat* buf); 36 | int stat(const char* path, struct stat* buf); 37 | int lstat(const char* path, struct stat* buf); 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /docs/fstat.txt: -------------------------------------------------------------------------------- 1 | fstat 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fstat(int fd, struct stat* buf); 7 | --------------------------------------------- 8 | 9 | Gets information about the file handle `fd` and places it into `buf`. The contents of the `struct stat` 10 | structure vary by platform, but share many common fields: 11 | 12 | * `st_uid`: User that owns the file 13 | * `st_gid`: Group that owns the file 14 | * `st_mode`: File access rights 15 | * `st_size`: Size of file in bytes 16 | 17 | The standard C runtime macros for checking `st_mode`, such as `S_ISDIR`, exist for all supported POSIX platforms. 18 | 19 | Returns zero on success, or the negation of the error code on error. 20 | 21 | See also 22 | -------- 23 | link:lstat.html[lstat], 24 | link:stat.html[stat] 25 | -------------------------------------------------------------------------------- /docs/read.txt: -------------------------------------------------------------------------------- 1 | read 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t read(int fd, void* buf, size_t count); 7 | --------------------------------------------- 8 | 9 | Reads `count` bytes from the file handle `fd`, and places the result in `buf`. Returns the number of bytes read, or 10 | the negation of the error code on error. It is possible for the number of bytes read to be smaller than the number 11 | of bytes requested. 12 | 13 | IMPORTANT: If the system call is interrupted, this function will return `-EINTR`. This differs from most C runtimes, 14 | where `-1` is returned with `errno` set to `EINTR`. As this runtime does not have `errno`, callers should check 15 | for `-EINTR` and a result less than zero in the error checking code. 16 | 17 | See also 18 | -------- 19 | link:write.html[write] 20 | -------------------------------------------------------------------------------- /runtime/linux/aarch64/process.c: -------------------------------------------------------------------------------- 1 | pid_t wait(int* status) 2 | { 3 | return __syscall(SYS_wait4, -1, status, 0, NULL); 4 | } 5 | 6 | pid_t waitpid(pid_t pid, int* status, int options) 7 | { 8 | return __syscall(SYS_wait4, pid, status, options, NULL); 9 | } 10 | 11 | sig_t signal(int sig, sig_t func) 12 | { 13 | // FIXME: Handlers do not work because there is no way to force the correct calling convention. Special 14 | // values such as SIG_IGN do work. 15 | struct sigaction act, old; 16 | memset(&act, 0, sizeof(act)); 17 | act.sa_handler = func; 18 | 19 | int result = sigaction(sig, &act, &old); 20 | if (result < 0) 21 | return (sig_t)result; 22 | return old.sa_handler; 23 | } 24 | 25 | int sigaction(int sig, const struct sigaction* act, struct sigaction* old) 26 | { 27 | return __syscall(SYS_rt_sigaction, sig, act, old, sizeof(sigset_t)); 28 | } 29 | 30 | -------------------------------------------------------------------------------- /docs/write.txt: -------------------------------------------------------------------------------- 1 | write 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t write(int fd, const void* buf, size_t count); 7 | --------------------------------------------- 8 | 9 | Writes `count` bytes from the buffer `buf` to the file handle `fd`. Returns the number of bytes written, or 10 | the negation of the error code on error. It is possible for the number of bytes written to be smaller than the number 11 | of bytes requested. 12 | 13 | IMPORTANT: If the system call is interrupted, this function will return `-EINTR`. This differs from most C runtimes, 14 | where `-1` is returned with `errno` set to `EINTR`. As this runtime does not have `errno`, callers should check 15 | for `-EINTR` and a result less than zero in the error checking code. 16 | 17 | See also 18 | -------- 19 | link:read.html[read] 20 | -------------------------------------------------------------------------------- /docs/shm_open.txt: -------------------------------------------------------------------------------- 1 | shm_open 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int shm_open(const char* path, int oflags, mode_t mode); 7 | --------------------------------------------- 8 | 9 | Opens a shared memory page with the name specified by at `path`. The `flags` argument is typically `O_RDONLY`, `O_WRONLY`, 10 | or `O_RDWR`. The `mode` argument specifies the file permissions if the file is created. 11 | 12 | IMPORTANT: The `path` parameter must be prefixed with a '/' (forward slash). 13 | 14 | IMPORTANT: The `mode` parameter must always be specified for this runtime, even when not creating a file. Use 15 | zero or the `__undefined` intrinsic when not creating a file. 16 | 17 | WARNING: This function is not yet available on Linux. 18 | 19 | See also 20 | -------- 21 | link:shm_unlink.html[shm_unlink] 22 | -------------------------------------------------------------------------------- /docs/format.txt: -------------------------------------------------------------------------------- 1 | Format specifier reference 2 | ========================== 3 | :title: Shellcode Compiler Runtime 4 | 5 | The Shellcode Compiler supports a subset of the standard `printf` format specifiers. The following 6 | specifiers are supported: 7 | 8 | * `%s`: String argument 9 | * `%d`: 32-bit signed integer argument (decimal) 10 | * `%u`: 32-bit unsigned integer argument (decimal) 11 | * `%x`: Native integer in lowercase hexadecimal 12 | * `%X`: Native integer in uppercase hexadecimal 13 | 14 | Field width specifiers are supported, along with the "`-`" sign for left alignment. No other modifiers are supported. 15 | 16 | See also 17 | -------- 18 | link:fprintf.html[fprintf], 19 | link:printf.html[printf], 20 | link:sprintf.html[sprintf], 21 | link:snprintf.html[snprintf], 22 | link:vfprintf.html[vfprintf], 23 | link:vsprintf.html[vfprintf], 24 | link:vsnprintf.html[vfprintf] 25 | -------------------------------------------------------------------------------- /docs/connect.txt: -------------------------------------------------------------------------------- 1 | connect 2 | ======= 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen); 7 | --------------------------------------------- 8 | 9 | Connects the socket `sockfd` to the address `addr`. The following address types are supported: 10 | 11 | --------------------------------------------- 12 | struct sockaddr_in; 13 | struct sockaddr_in6; 14 | struct sockaddr_un; 15 | --------------------------------------------- 16 | 17 | IMPORTANT: The socket family member of the address structure must use the `AF_*` constants. The 18 | `PF_*` constants must only be used when creating sockets. This is to automatically set the length 19 | field present only on BSD. The length fields are not explicitly present in this runtime. 20 | 21 | See also 22 | -------- 23 | link:socket.html[socket] 24 | -------------------------------------------------------------------------------- /docs/fcntl.txt: -------------------------------------------------------------------------------- 1 | fcntl 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int fcntl(int fd, int cmd, size_t arg); 7 | --------------------------------------------- 8 | 9 | Issues a file descriptor command. The available commands vary by platform, but the most common commands, such as `F_SETFL`, are 10 | available on all platforms. Returns the result of the command, the meaning of which varies by the command sent. 11 | 12 | IMPORTANT: In the standard C runtime implementation of this function, the `arg` parameter is optional. This runtime always 13 | requires the third argument. For commands that do not need the `arg` parameter, it will be ignored. The `__undefined` 14 | intrinsic can be used for ignored parameters. 15 | 16 | See also 17 | -------- 18 | link:dup2.html[dup2], 19 | link:open.html[open], 20 | link:pipe.html[pipe], 21 | link:socket.html[socket] 22 | -------------------------------------------------------------------------------- /docs/noreturn.txt: -------------------------------------------------------------------------------- 1 | __noreturn 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void example_function(void) __noreturn; 7 | --------------------------------------------- 8 | 9 | The `__noreturn` modifier can be placed immediately after a function type declaration to specify that 10 | a function can never return. For example, the `exit` function is marked with `__noreturn`. 11 | 12 | It is not necessary for functions that call `__noreturn` functions such as `exit` to explicitly specify 13 | that they cannot return. The compiler will automatically determine that such functions are `__noreturn`. 14 | This attribute is usually only necessary with functions that issue system calls that cause the 15 | process to exit, or to transition to a new codebase (such as `execve`). 16 | 17 | See also 18 | -------- 19 | link:exit.html[exit], 20 | link:execve.html[execve] 21 | -------------------------------------------------------------------------------- /docs/stat.txt: -------------------------------------------------------------------------------- 1 | stat 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int stat(const char* path, struct stat* buf); 7 | --------------------------------------------- 8 | 9 | Gets information about the file at path `path` and places it into `buf`. If the file referenced is a symbolic 10 | link, the lnk will be followed. The contents of the `struct stat` structure vary by platform, but share many common fields: 11 | 12 | * `st_uid`: User that owns the file 13 | * `st_gid`: Group that owns the file 14 | * `st_mode`: File access rights 15 | * `st_size`: Size of file in bytes 16 | 17 | The standard C runtime macros for checking `st_mode`, such as `S_ISDIR`, exist for all supported POSIX platforms. 18 | 19 | Returns zero on success, or the negation of the error code on error. 20 | 21 | See also 22 | -------- 23 | link:fstat.html[fstat], 24 | link:lstat.html[lstat] 25 | -------------------------------------------------------------------------------- /docs/execl.txt: -------------------------------------------------------------------------------- 1 | execl 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int execl(const char* filename, const char* arg0, ...); 7 | --------------------------------------------- 8 | 9 | Starts a new program. The program started is given by `filename` and passed the arguments given. 10 | The list of arguments is terminated by a `NULL` parameter. The default environment is used. 11 | 12 | This function does not return if successful. Returns the negation of the error code on error. 13 | 14 | WARNING: Do not use this function with the `--stack-grows-up` option. Use `execve` or the 15 | built-in shell spawning functions if this option is desired. 16 | 17 | See also 18 | -------- 19 | link:bash.html[bash], 20 | link:execve.html[execve], 21 | link:interactive_bash.html[interactive_bash], 22 | link:interactive_sh.html[interactive_sh], 23 | link:sh.html[sh], 24 | link:system.html[system] 25 | -------------------------------------------------------------------------------- /docs/bind.txt: -------------------------------------------------------------------------------- 1 | bind 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen); 7 | --------------------------------------------- 8 | 9 | Binds the socket `sockfd` to the address `addr`. The following address types are supported: 10 | 11 | --------------------------------------------- 12 | struct sockaddr_in; 13 | struct sockaddr_in6; 14 | struct sockaddr_un; 15 | --------------------------------------------- 16 | 17 | IMPORTANT: The socket family member of the address structure must use the `AF_*` constants. The 18 | `PF_*` constants must only be used when creating sockets. This is to automatically set the length 19 | field present only on BSD. The length fields are not explicitly present in this runtime. 20 | 21 | See also 22 | -------- 23 | link:accept.html[accept], 24 | link:listen.html[listen], 25 | link:socket.html[socket] 26 | -------------------------------------------------------------------------------- /docs/lstat.txt: -------------------------------------------------------------------------------- 1 | lstat 2 | ===== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int lstat(const char* path, struct stat* buf); 7 | --------------------------------------------- 8 | 9 | Gets information about the file at path `path` and places it into `buf`. If the file referenced is a 10 | symbolic link, this function will obtain the information about the link itself. The contents of the `struct stat` 11 | structure vary by platform, but share many common fields: 12 | 13 | * `st_uid`: User that owns the file 14 | * `st_gid`: Group that owns the file 15 | * `st_mode`: File access rights 16 | * `st_size`: Size of file in bytes 17 | 18 | The standard C runtime macros for checking `st_mode`, such as `S_ISDIR`, exist for all supported POSIX platforms. 19 | 20 | Returns zero on success, or the negation of the error code on error. 21 | 22 | See also 23 | -------- 24 | link:fstat.html[fstat], 25 | link:stat.html[stat] 26 | -------------------------------------------------------------------------------- /docs/syscall2.txt: -------------------------------------------------------------------------------- 1 | __syscall2 2 | ========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | long __syscall2(long& ret2, long num, ...); 7 | --------------------------------------------- 8 | 9 | Issues system call number `num` on the target platform, expecting two return values instead of one. 10 | Any additional arguments are passed directly to the system call. Returns the first half of the result 11 | of the system call, with the second half of the result placed into the `ret2` variable. 12 | 13 | IMPORTANT: On platforms that set a processor flag on error, such as FreeBSD, the `__syscall` function 14 | will return the negation of the error code on error. This is to allow for unified behaviour across 15 | different platforms. For example, checking the result of the `open` call for `-ENOENT` will work 16 | across all supported UNIX-based platforms. 17 | 18 | See also 19 | -------- 20 | link:syscall.html[syscall] 21 | -------------------------------------------------------------------------------- /tests/pi_output: -------------------------------------------------------------------------------- 1 | 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257 2 | -------------------------------------------------------------------------------- /docs/undefined.txt: -------------------------------------------------------------------------------- 1 | __undefined 2 | =========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | __undefined; 7 | --------------------------------------------- 8 | 9 | This intrinsic can be used in place of any value. It gives undefined results, usually by omitting 10 | code. The runtime result will vary based on the choices of the optimizer and code generator. The compiler 11 | will typically leave the register or memory location being targeted in its original state, completely 12 | omitting any instructions that would have been required to update it. Any arithmetic performed with 13 | `__undefined` as part of the computation will optimized down to a single usage of the `__undefined` 14 | intrinsic, as the results are by definition undefined. 15 | 16 | One of the most common uses of this intrinsic is to exit the program while treating the exit code as 17 | a "don't care" value, using `exit(__undefined)`. A `main` function that returns `void` implicitly 18 | does this. 19 | 20 | -------------------------------------------------------------------------------- /docs/send.txt: -------------------------------------------------------------------------------- 1 | send 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t send(int fd, const void* buf, size_t n, int flags); 7 | --------------------------------------------- 8 | 9 | Sends `n` bytes from the buffer `buf` over the socket `fd`. Returns the number of bytes sent, or 10 | the negation of the error code on error. It is possible for the number of bytes sent to be smaller than the number 11 | of bytes requested. 12 | 13 | IMPORTANT: If the system call is interrupted, this function will return `-EINTR`. This differs from most C runtimes, 14 | where `-1` is returned with `errno` set to `EINTR`. As this runtime does not have `errno`, callers should check 15 | for `-EINTR` and a result less than zero in the error checking code. 16 | 17 | See also 18 | -------- 19 | link:recv.html[recv], 20 | link:recv_all.html[recv_all], 21 | link:recvfrom.html[recvfrom], 22 | link:send_all.html[send_all], 23 | link:send_string.html[send_string], 24 | link:sendto.html[sendto] 25 | -------------------------------------------------------------------------------- /docs/recv.txt: -------------------------------------------------------------------------------- 1 | recv 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t recv(int fd, void* buf, size_t n, int flags); 7 | --------------------------------------------- 8 | 9 | Reads `n` bytes from the socket `fd`, and places the result in `buf`. Returns the number of bytes read, or 10 | the negation of the error code on error. It is possible for the number of bytes read to be smaller than the number 11 | of bytes requested. 12 | 13 | IMPORTANT: If the system call is interrupted, this function will return `-EINTR`. This differs from most C runtimes, 14 | where `-1` is returned with `errno` set to `EINTR`. As this runtime does not have `errno`, callers should check 15 | for `-EINTR` and a result less than zero in the error checking code. 16 | 17 | See also 18 | -------- 19 | link:recv_all.html[recv_all], 20 | link:recvfrom.html[recvfrom], 21 | link:send.html[send], 22 | link:send_all.html[send_all], 23 | link:send_string.html[send_string], 24 | link:sendto.html[sendto] 25 | -------------------------------------------------------------------------------- /docs/lib/xhtml11-quirks.css: -------------------------------------------------------------------------------- 1 | /* Workarounds for IE6's broken and incomplete CSS2. */ 2 | 3 | div.sidebar-content { 4 | background: #ffffee; 5 | border: 1px solid silver; 6 | padding: 0.5em; 7 | } 8 | div.sidebar-title, div.image-title { 9 | color: #527bbd; 10 | font-family: sans-serif; 11 | font-weight: bold; 12 | margin-top: 0.0em; 13 | margin-bottom: 0.5em; 14 | } 15 | 16 | div.listingblock div.content { 17 | border: 1px solid silver; 18 | background: #f4f4f4; 19 | padding: 0.5em; 20 | } 21 | 22 | div.quoteblock-attribution { 23 | padding-top: 0.5em; 24 | text-align: right; 25 | } 26 | 27 | pre.verseblock-content { 28 | font-family: inherit; 29 | } 30 | div.verseblock-attribution { 31 | padding-top: 0.75em; 32 | text-align: left; 33 | } 34 | 35 | div.exampleblock-content { 36 | border-left: 3px solid #dddddd; 37 | padding-left: 0.5em; 38 | } 39 | 40 | div.imageblock.latex div.image-title { margin-top: 0.5em; } 41 | 42 | /* IE6 sets dynamically generated links as visited. */ 43 | div#toc a:visited { color: blue; } 44 | -------------------------------------------------------------------------------- /Scope.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCOPE_H__ 2 | #define __SCOPE_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "Type.h" 8 | #include "Variable.h" 9 | 10 | 11 | class Scope 12 | { 13 | Scope* m_root; 14 | Scope* m_parent; 15 | std::vector< Ref > m_vars; 16 | std::map< std::string, Ref > m_currentScopeVars; 17 | 18 | public: 19 | Scope(Scope* parent, bool newContext); 20 | 21 | Scope* Duplicate(DuplicateContext& dup); 22 | 23 | Scope* GetParent() const { return m_parent; } 24 | Scope* GetRoot() const { return m_root; } 25 | const std::vector< Ref >& GetVariables() { return m_vars; } 26 | 27 | bool IsVariableDefined(const std::string& name) const; 28 | bool IsVariableDefinedInCurrentScope(const std::string& name) const; 29 | Variable* GetVariable(const std::string& name) const; 30 | Variable* DefineVariable(VariableClass cls, Type* type, const std::string& name); 31 | void DefineVariable(Variable* var); 32 | 33 | void Serialize(OutputBlock* output); 34 | bool Deserialize(InputBlock* input); 35 | }; 36 | 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /tests/mul64.c: -------------------------------------------------------------------------------- 1 | void print64(uint64_t a) 2 | { 3 | uint32_t high = (uint32_t)(a >> 32); 4 | uint32_t low = (uint32_t)a; 5 | printf("%.8x%.8x\n", high, low); 6 | } 7 | 8 | void test_unsigned(uint64_t a, uint64_t b) 9 | { 10 | uint64_t c = a * b; 11 | print64(c); 12 | } 13 | 14 | void test_signed(int64_t a, int64_t b) 15 | { 16 | int64_t c = a * b; 17 | print64(c); 18 | } 19 | 20 | int main() 21 | { 22 | test_unsigned(1337, 42); 23 | test_unsigned(0x4141414141414141, 7777); 24 | test_unsigned(0x4141414141414141, 0x0707070707070707); 25 | test_signed(1337, 42); 26 | test_signed(-1337, 42); 27 | test_signed(1337, -42); 28 | test_signed(-1337, -42); 29 | test_signed(0x4141414141414141, 7777); 30 | test_signed(-0x4141414141414141, 7777); 31 | test_signed(0x4141414141414141, -7777); 32 | test_signed(-0x4141414141414141, -7777); 33 | test_signed(0x4141414141414141, 0x0707070707070707); 34 | test_signed(-0x4141414141414141, 0x0707070707070707); 35 | test_signed(0x4141414141414141, -0x0707070707070707); 36 | test_signed(-0x4141414141414141, -0x0707070707070707); 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /docs/select.txt: -------------------------------------------------------------------------------- 1 | select 2 | ====== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout); 7 | --------------------------------------------- 8 | 9 | Waits for one or more of the file handles in `readfs`, `writefds`, or `errorfds` to become available. Returns 10 | early if `timeout` expires. The `nfds` parameter must be set to one more than the maximum file handle 11 | present. 12 | 13 | On return, the sets are updated to include only the file handles that are ready. The return value is the total number 14 | of file handles that are ready, or zero on timeout. On error, the negation of the error code is returned. 15 | 16 | The following macros can be used to manipulate sets of file handles: 17 | --------------------------------------------- 18 | FD_ZERO(&set); 19 | FD_SET(fd, &set); 20 | FD_CLR(fd, &set); 21 | FD_ISSET(fd, &set); 22 | --------------------------------------------- 23 | 24 | See also 25 | -------- 26 | link:read.html[read], 27 | link:write.html[write] 28 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2025 Vector 35 Inc 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /docs/mmap.txt: -------------------------------------------------------------------------------- 1 | mmap 2 | ==== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset); 7 | --------------------------------------------- 8 | 9 | Maps a block of memory of `len` bytes with page protection `prot`. If `addr` is `NULL`, the system 10 | automatically picks a free virtual address. If `addr` is not `NULL`, the provided address is mapped 11 | (existing mappings will be overridden). 12 | 13 | The protection flags in `prot` can include one or more of `PROT_READ`, `PROT_WRITE`, and `PROT_EXEC`. 14 | 15 | The `flags` parameter must contain one of `MAP_SHARED` or `MAP_PRIVATE`. Additional flags include 16 | `MAP_ANONYMOUS`, which maps a region backed by RAM instead of a file. The `fd` parameter should be 17 | `-1` when mapping anonymous pages. If the region is to be backed by a file, the `fd` and `offset` 18 | parameters specify the file handle and offset within the file of the beginning of the mapping. 19 | 20 | Returns a pointer to the mapped region. 21 | 22 | See also 23 | -------- 24 | link:munmap.html[munmap] 25 | -------------------------------------------------------------------------------- /docs/recvfrom.txt: -------------------------------------------------------------------------------- 1 | recvfrom 2 | ======== 3 | :title: Shellcode Compiler Runtime 4 | 5 | --------------------------------------------- 6 | ssize_t recvfrom(int fd, void* buf, size_t n, int flags, struct sockaddr* addr, socklen_t* addrlen); 7 | --------------------------------------------- 8 | 9 | Reads `n` bytes from the socket `fd`, and places the result in `buf`. If `addr` is not `NULL`, fills in the address 10 | from which the data was received. Returns the number of bytes read, or the negation of the error code on error. It 11 | is possible for the number of bytes read to be smaller than the number of bytes requested. 12 | 13 | IMPORTANT: If the system call is interrupted, this function will return `-EINTR`. This differs from most C runtimes, 14 | where `-1` is returned with `errno` set to `EINTR`. As this runtime does not have `errno`, callers should check 15 | for `-EINTR` and a result less than zero in the error checking code. 16 | 17 | See also 18 | -------- 19 | link:recv.html[recv], 20 | link:recv_all.html[recv_all], 21 | link:send.html[send], 22 | link:send_all.html[send_all], 23 | link:send_string.html[send_string], 24 | link:sendto.html[sendto] 25 | -------------------------------------------------------------------------------- /tests/div64.c: -------------------------------------------------------------------------------- 1 | void print64(uint64_t a) 2 | { 3 | uint32_t high = (uint32_t)(a >> 32); 4 | uint32_t low = (uint32_t)a; 5 | printf("%.8x%.8x\n", high, low); 6 | } 7 | 8 | void test_unsigned(uint64_t a, uint64_t b) 9 | { 10 | uint64_t c = a / b; 11 | uint64_t d = a % b; 12 | print64(c); 13 | print64(d); 14 | } 15 | 16 | void test_signed(int64_t a, int64_t b) 17 | { 18 | int64_t c = a / b; 19 | int64_t d = a % b; 20 | print64(c); 21 | print64(d); 22 | } 23 | 24 | int main() 25 | { 26 | test_unsigned(1337, 42); 27 | test_unsigned(0x4141414141414141, 7777); 28 | test_unsigned(0x4141414141414141, 0x0707070707070707); 29 | test_signed(1337, 42); 30 | test_signed(-1337, 42); 31 | test_signed(1337, -42); 32 | test_signed(-1337, -42); 33 | test_signed(0x4141414141414141, 7777); 34 | test_signed(-0x4141414141414141, 7777); 35 | test_signed(0x4141414141414141, -7777); 36 | test_signed(-0x4141414141414141, -7777); 37 | test_signed(0x4141414141414141, 0x0707070707070707); 38 | test_signed(-0x4141414141414141, 0x0707070707070707); 39 | test_signed(0x4141414141414141, -0x0707070707070707); 40 | test_signed(-0x4141414141414141, -0x0707070707070707); 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /runtime/end.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | uint8_t __end[0]; 22 | 23 | -------------------------------------------------------------------------------- /tests/pi.c: -------------------------------------------------------------------------------- 1 | char* pi(int n) 2 | { 3 | int digits = n; 4 | int dec = 8; 5 | int extraDigits = dec + 8; 6 | int totalDigits = digits + extraDigits; 7 | int decimalIndex = totalDigits - dec; 8 | 9 | char* result = (char*)malloc(totalDigits); 10 | memset(result, 0, totalDigits); 11 | result[decimalIndex] = 4; 12 | 13 | int k = digits * 4; 14 | for (int i = 0; i < digits * 4; i++) 15 | { 16 | int carry = 0; 17 | for (int j = 0; j < totalDigits; j++) 18 | { 19 | int n = (result[j] * k) + carry; 20 | carry = n / 10; 21 | result[j] = (char)(n % 10); 22 | } 23 | 24 | carry = 0; 25 | int num = 2 * k + 1; 26 | for (int j = totalDigits - 1; j >= 0; j--) 27 | { 28 | int n = (result[j] + (carry * 10)) / num; 29 | carry = (result[j] + (carry * 10)) - (n * num); 30 | result[j] = (char)n; 31 | } 32 | 33 | result[decimalIndex] += 2; 34 | k--; 35 | } 36 | 37 | char* s = (char*)malloc(totalDigits); 38 | s[0] = '0' + result[decimalIndex]; 39 | s[1] = '.'; 40 | k = 2; 41 | for (int i = decimalIndex - 1; i >= 0; i--, k++) 42 | s[k] = '0' + result[i]; 43 | s[k] = 0; 44 | return s; 45 | } 46 | 47 | int main() 48 | { 49 | puts(pi(1000)); 50 | puts("\n"); 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /runtime/end.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__END_H__ 22 | #define __LIBC__END_H__ 23 | 24 | extern uint8_t __end[0]; 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /runtime/mac/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__MAC_DEFINES_H__ 22 | #define __LIBC__MAC_DEFINES_H__ 23 | 24 | #define MACOSX 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /runtime/linux/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_DEFINES_H__ 22 | #define __LIBC__LINUX_DEFINES_H__ 23 | 24 | #define LINUX 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /runtime/freebsd/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__FREEBSD_DEFINES_H__ 22 | #define __LIBC__FREEBSD_DEFINES_H__ 23 | 24 | #define FREEBSD 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /runtime/arm/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__ARCH_DEFINES_H__ 22 | #define __LIBC__ARCH_DEFINES_H__ 23 | 24 | #define ARM 25 | #define __32BIT 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /runtime/ppc/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__ARCH_DEFINES_H__ 22 | #define __LIBC__ARCH_DEFINES_H__ 23 | 24 | #define PPC 25 | #define __32BIT 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /runtime/x86/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__ARCH_DEFINES_H__ 22 | #define __LIBC__ARCH_DEFINES_H__ 23 | 24 | #define i386 25 | #define __32BIT 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /runtime/mips/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__ARCH_DEFINES_H__ 22 | #define __LIBC__ARCH_DEFINES_H__ 23 | 24 | #define MIPS 25 | #define __32BIT 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /runtime/quark/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__ARCH_DEFINES_H__ 22 | #define __LIBC__ARCH_DEFINES_H__ 23 | 24 | #define QUARK 25 | #define __32BIT 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /runtime/x64/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__ARCH_DEFINES_H__ 22 | #define __LIBC__ARCH_DEFINES_H__ 23 | 24 | #define x86_64 25 | #define __64BIT 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /runtime/windows/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__WINDOWS_DEFINES_H__ 22 | #define __LIBC__WINDOWS_DEFINES_H__ 23 | 24 | #define WIN32 25 | #define WINDOWS 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /runtime/crc32.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__CRC32_H__ 22 | #define __LIBC__CRC32_H__ 23 | 24 | uint32_t crc32(const void* data, size_t len); 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /runtime/quark_vm.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__VM_H__ 22 | #define __LIBC__VM_H__ 23 | 24 | #ifdef __32BIT 25 | void quark_exec(void* buf, ...) __noreturn; 26 | #endif 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /tests/sploit_mmap.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void main() 22 | { 23 | void* buffer = mmap(NULL, 65536, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 24 | read(0, buffer, 65536); 25 | goto *buffer; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /tests/shellcode.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int main() 22 | { 23 | char buffer[128]; 24 | int fd = open("tests/shellcode_output", O_RDONLY, 0); 25 | int bytes = read(fd, buffer, 128); 26 | write(1, buffer, bytes); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /runtime/posix/shell.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__SHELL_H__ 22 | #define __LIBC__SHELL_H__ 23 | 24 | void sh(); 25 | void interactive_sh(); 26 | void bash(); 27 | void interactive_bash(); 28 | 29 | int system(const char* cmd); 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /runtime/linux/arm/memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_ARM_MEMORY_H__ 22 | #define __LIBC__LINUX_ARM_MEMORY_H__ 23 | 24 | #define PROT_SEM 8 25 | #define MAP_ANON 0x20 26 | #define MAP_ANONYMOUS 0x20 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /runtime/linux/ppc/memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_X86_MEMORY_H__ 22 | #define __LIBC__LINUX_X86_MEMORY_H__ 23 | 24 | #define PROT_SEM 8 25 | #define MAP_ANON 0x20 26 | #define MAP_ANONYMOUS 0x20 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /runtime/linux/x64/memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_X64_MEMORY_H__ 22 | #define __LIBC__LINUX_X64_MEMORY_H__ 23 | 24 | #define PROT_SEM 8 25 | #define MAP_ANON 0x20 26 | #define MAP_ANONYMOUS 0x20 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /runtime/linux/x86/memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_X86_MEMORY_H__ 22 | #define __LIBC__LINUX_X86_MEMORY_H__ 23 | 24 | #define PROT_SEM 8 25 | #define MAP_ANON 0x20 26 | #define MAP_ANONYMOUS 0x20 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /runtime/linux/aarch64/memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_ARM_MEMORY_H__ 22 | #define __LIBC__LINUX_ARM_MEMORY_H__ 23 | 24 | #define PROT_SEM 8 25 | #define MAP_ANON 0x20 26 | #define MAP_ANONYMOUS 0x20 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /runtime/linux/mips/memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_MIPS_MEMORY_H__ 22 | #define __LIBC__LINUX_MIPS_MEMORY_H__ 23 | 24 | #define PROT_SEM 0x10 25 | #define MAP_ANON 0x800 26 | #define MAP_ANONYMOUS 0x800 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /runtime/linux/arm/file.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_ARCH_FILE_H__ 22 | #define __LIBC__LINUX_ARCH_FILE_H__ 23 | 24 | #define O_DIRECTORY 0x4000 25 | #define O_NOFOLLOW 0x8000 26 | #define O_DIRECT 0x10000 27 | #define O_LARGEFILE 0x20000 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/ppc/file.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_ARCH_FILE_H__ 22 | #define __LIBC__LINUX_ARCH_FILE_H__ 23 | 24 | #define O_DIRECTORY 0x4000 25 | #define O_NOFOLLOW 0x8000 26 | #define O_DIRECT 0x10000 27 | #define O_LARGEFILE 0x20000 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/x64/file.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_ARCH_FILE_H__ 22 | #define __LIBC__LINUX_ARCH_FILE_H__ 23 | 24 | #define O_DIRECT 0x4000 25 | #define O_LARGEFILE 0x8000 26 | #define O_DIRECTORY 0x10000 27 | #define O_NOFOLLOW 0x20000 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/x86/file.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_ARCH_FILE_H__ 22 | #define __LIBC__LINUX_ARCH_FILE_H__ 23 | 24 | #define O_DIRECT 0x4000 25 | #define O_LARGEFILE 0x8000 26 | #define O_DIRECTORY 0x10000 27 | #define O_NOFOLLOW 0x20000 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/mips/file.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__LINUX_ARCH_FILE_H__ 22 | #define __LIBC__LINUX_ARCH_FILE_H__ 23 | 24 | #define O_DIRECT 0x4000 25 | #define O_LARGEFILE 0x8000 26 | #define O_DIRECTORY 0x10000 27 | #define O_NOFOLLOW 0x20000 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /Enum.h: -------------------------------------------------------------------------------- 1 | #ifndef __ENUM_H__ 2 | #define __ENUM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "RefCountObject.h" 9 | 10 | 11 | struct EnumMember 12 | { 13 | std::string name; 14 | uint32_t value; 15 | bool isDefault; 16 | }; 17 | 18 | 19 | struct OutputBlock; 20 | struct InputBlock; 21 | class Struct; 22 | struct DuplicateContext; 23 | 24 | class Enum: public RefCountObject 25 | { 26 | std::string m_name; 27 | std::vector m_members; 28 | uint32_t m_nextValue; 29 | bool m_fullyDefined; 30 | 31 | size_t m_serializationIndex; 32 | bool m_serializationIndexValid; 33 | static size_t m_nextSerializationIndex; 34 | static std::map< size_t, Ref > m_serializationMap; 35 | 36 | public: 37 | Enum(); 38 | 39 | Enum* Duplicate(DuplicateContext& dup); 40 | 41 | void ReplaceWith(Enum* e); 42 | 43 | bool IsFullyDefined() const { return m_fullyDefined; } 44 | void Complete() { m_fullyDefined = true; } 45 | 46 | void SetName(const std::string& name) { m_name = name; } 47 | const std::string& GetName() const { return m_name; } 48 | 49 | const std::vector& GetMembers() const { return m_members; } 50 | uint32_t GetNextValue() const { return m_nextValue; } 51 | 52 | void AddMember(const std::string& name, uint32_t value); 53 | 54 | void Serialize(OutputBlock* output); 55 | static Enum* Deserialize(InputBlock* input); 56 | }; 57 | 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /runtime/linux/x64/file.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout) 22 | { 23 | return __syscall(SYS_select, nfds, readfds, writefds, errorfds, timeout); 24 | } 25 | 26 | int pipe(int* fds) 27 | { 28 | return __syscall(SYS_pipe, fds); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /codegen/Token.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include "Token.h" 22 | 23 | using namespace std; 24 | 25 | 26 | Token::Token(TokenClass type): m_type(type) 27 | { 28 | } 29 | 30 | 31 | Token::Token(TokenClass type, const string& str): m_type(type), m_string(str) 32 | { 33 | } 34 | 35 | 36 | Token::~Token() 37 | { 38 | } 39 | 40 | -------------------------------------------------------------------------------- /runtime/linux/arm/file.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout) 22 | { 23 | return __syscall(SYS__newselect, nfds, readfds, writefds, errorfds, timeout); 24 | } 25 | 26 | int pipe(int* fds) 27 | { 28 | return __syscall(SYS_pipe, fds); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/ppc/file.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout) 22 | { 23 | return __syscall(SYS__newselect, nfds, readfds, writefds, errorfds, timeout); 24 | } 25 | 26 | int pipe(int* fds) 27 | { 28 | return __syscall(SYS_pipe, fds); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/x86/file.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout) 22 | { 23 | return __syscall(SYS__newselect, nfds, readfds, writefds, errorfds, timeout); 24 | } 25 | 26 | int pipe(int* fds) 27 | { 28 | return __syscall(SYS_pipe, fds); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /docs/index.txt: -------------------------------------------------------------------------------- 1 | Description 2 | =========== 3 | :title: Shellcode Compiler Runtime 4 | 5 | The Shellcode Compiler is a C compiler designed to output standalone code that will be injected into other 6 | running processes. It contains a small, lightweight runtime that is designed to generate small code. The 7 | runtime has absolutely no external dependencies other than the target operating system kernel, so the 8 | generated code is not dependent on the target system's configuration. It contains advanced features for 9 | customizing the code generation to satisfy constraints and make code that is harder to reverse engineer. 10 | 11 | * C syntax. 12 | * Runtime is built-in to the compiler executable and does not need to be installed. 13 | * Able to output ELF, Mach-O, and PE binaries in addition to flat position-independent binary blobs. 14 | * Targets Linux, FreeBSD, Mac OS X, and Windows. 15 | * Supports both 32-bit and 64-bit x86 architectures on all supported platforms. 16 | * (Planned feature, only applies to padding currently) Blacklist any byte value, and the compiler will generate code that does not use it. For example, it 17 | can generate code that does not have null bytes. 18 | * (Partially implemented, register and basic block ordering) Polymorphic code generation can generate different code each time it is compiled. 19 | * Calling conventions (including the choice of stack pointer register) are highly customizable. 20 | * Python bindings for dynamic generation of code from scripts. 21 | -------------------------------------------------------------------------------- /runtime/freebsd/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | return (void*)__syscall(SYS_mmap, addr, len, prot, flags, fd, offset); 24 | } 25 | 26 | void* munmap(void* addr, size_t len) 27 | { 28 | return (void*)__syscall(SYS_munmap, addr, len); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/x64/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | return (void*)__syscall(SYS_mmap, addr, len, prot, flags, fd, offset); 24 | } 25 | 26 | void* munmap(void* addr, size_t len) 27 | { 28 | return (void*)__syscall(SYS_munmap, addr, len); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /runtime/linux/aarch64/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | return (void*)__syscall(SYS_mmap, addr, len, prot, flags, fd, offset); 24 | } 25 | 26 | void* munmap(void* addr, size_t len) 27 | { 28 | return (void*)__syscall(SYS_munmap, addr, len); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /codegen/Match.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #include "Match.h" 22 | 23 | using namespace std; 24 | 25 | 26 | Match::Match(const string& file, int line, TreeNode* match, TreeNode* result, const vector< Ref >& temp, CodeBlock* code): 27 | m_fileName(file), m_line(line), m_match(match), m_result(result), m_temps(temp), m_code(code) 28 | { 29 | } 30 | 31 | -------------------------------------------------------------------------------- /runtime/net.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__NET_H__ 22 | #define __LBIC__NET_H__ 23 | 24 | #define INADDR_ANY 0 25 | #define INADDR_LOOPBACK 0x7f000001 26 | #define INADDR_BROADCAST 0xffffffff 27 | #define INADDR_NONE 0xffffffff 28 | 29 | #define IPV4_ADDR(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /runtime/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__GLOBAL_DEFINES_H__ 22 | #define __LIBC__GLOBAL_DEFINES_H__ 23 | 24 | #define NULL 0 25 | 26 | #define offset_of(type, member) ((size_t)&(((type*)0)->member)) 27 | #define container_of(ptr, type, member) ((type*)(((size_t)(ptr)) - offset_of(type, member))) 28 | 29 | #define __SCC__ 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /runtime/linux/x64/stat.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int fstat(int fd, struct stat* buf) 22 | { 23 | return __syscall(SYS_fstat, fd, buf); 24 | } 25 | 26 | int stat(const char* path, struct stat* buf) 27 | { 28 | return __syscall(SYS_stat, path, buf); 29 | } 30 | 31 | int lstat(const char* path, struct stat* buf) 32 | { 33 | return __syscall(SYS_lstat, path, buf); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /runtime/linux/arm/stat.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int fstat(int fd, struct stat* buf) 22 | { 23 | return __syscall(SYS_fstat64, fd, buf); 24 | } 25 | 26 | int stat(const char* path, struct stat* buf) 27 | { 28 | return __syscall(SYS_stat64, path, buf); 29 | } 30 | 31 | int lstat(const char* path, struct stat* buf) 32 | { 33 | return __syscall(SYS_lstat64, path, buf); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /runtime/linux/mips/stat.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int fstat(int fd, struct stat* buf) 22 | { 23 | return __syscall(SYS_fstat64, fd, buf); 24 | } 25 | 26 | int stat(const char* path, struct stat* buf) 27 | { 28 | return __syscall(SYS_stat64, path, buf); 29 | } 30 | 31 | int lstat(const char* path, struct stat* buf) 32 | { 33 | return __syscall(SYS_lstat64, path, buf); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /runtime/linux/ppc/stat.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int fstat(int fd, struct stat* buf) 22 | { 23 | return __syscall(SYS_fstat64, fd, buf); 24 | } 25 | 26 | int stat(const char* path, struct stat* buf) 27 | { 28 | return __syscall(SYS_stat64, path, buf); 29 | } 30 | 31 | int lstat(const char* path, struct stat* buf) 32 | { 33 | return __syscall(SYS_lstat64, path, buf); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /runtime/linux/x86/stat.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int fstat(int fd, struct stat* buf) 22 | { 23 | return __syscall(SYS_fstat64, fd, buf); 24 | } 25 | 26 | int stat(const char* path, struct stat* buf) 27 | { 28 | return __syscall(SYS_stat64, path, buf); 29 | } 30 | 31 | int lstat(const char* path, struct stat* buf) 32 | { 33 | return __syscall(SYS_lstat64, path, buf); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /docs/rc4_overview.txt: -------------------------------------------------------------------------------- 1 | RC4 overview 2 | ============ 3 | :title: Shellcode Compiler Runtime 4 | 5 | To use the RC4 encryption functions, first call link:rc4_init.html[rc4_init] with the desired key to initialize 6 | the cipher state. RC4 can use the same functions for both encryption and decryption. Once initialized, the 7 | link:rc4_crypt.html[rc4_crypt] function can be called to encrypt or decrypt data. Alternatively, the 8 | link:rc4_output.html[rc4_output] function can be used to directly access the key stream (XOR each byte with 9 | the output of this function to encrypt or decrypt data). 10 | 11 | IMPORTANT: It is recommended that the first bytes of the key stream for RC4 is discarded. To do this, call 12 | the link:rc4_output.html[rc4_output] a number of times. Ensure that the same number of bytes is discarded 13 | on both sides of the communication. 14 | 15 | WARNING: Do not encrypt multiple sessions using the same key. RC4 is very vulnerable to cryptography attacks 16 | if the same key is used to encrypt two different streams (this is why WEP is so easy to break). 17 | 18 | Example 19 | ------- 20 | The following example will set up an RC4 cipher context and encrypt a string. 21 | 22 | ------------------------------------------- 23 | void main() 24 | { 25 | rc4_state_t rc4; 26 | char* key = "thereisnocowlevel"; 27 | rc4_init(&rc4, key, strlen(key)); 28 | char* str = "pwniesinstead"; 29 | size_t len = strlen(str); 30 | rc4_crypt(&rc4, str, len); 31 | write(1, str, len); 32 | } 33 | ------------------------------------------- 34 | -------------------------------------------------------------------------------- /runtime/linux/mips/file.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout) 22 | { 23 | return __syscall(SYS__newselect, nfds, readfds, writefds, errorfds, timeout); 24 | } 25 | 26 | int pipe(int* fds) 27 | { 28 | int a, b; 29 | a = (int)__syscall2(b, SYS_pipe); 30 | fds[0] = a; 31 | fds[1] = b; 32 | return a; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /runtime/mac/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | size_t shiftedOffset = (size_t)(offset >> 12); 24 | return (void*)__syscall(SYS_mmap, addr, len, prot, flags, fd, shiftedOffset); 25 | } 26 | 27 | void* munmap(void* addr, size_t len) 28 | { 29 | return (void*)__syscall(SYS_munmap, addr, len); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /runtime/rc4.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__RC4_H__ 22 | #define __LIBC__RC4_H__ 23 | 24 | typedef struct 25 | { 26 | uint8_t s[256]; 27 | uint8_t i; 28 | uint8_t j; 29 | } rc4_state_t; 30 | 31 | void rc4_init(rc4_state_t* state, void* key, size_t keylen); 32 | uint8_t rc4_output(rc4_state_t* state); 33 | void rc4_crypt(rc4_state_t* state, void* data, size_t len); 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /runtime/linux/arm/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | size_t shiftedOffset = (size_t)(offset >> 12); 24 | return (void*)__syscall(SYS_mmap2, addr, len, prot, flags, fd, shiftedOffset); 25 | } 26 | 27 | void* munmap(void* addr, size_t len) 28 | { 29 | return (void*)__syscall(SYS_munmap, addr, len); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /runtime/linux/ppc/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | size_t shiftedOffset = (size_t)(offset >> 12); 24 | return (void*)__syscall(SYS_mmap2, addr, len, prot, flags, fd, shiftedOffset); 25 | } 26 | 27 | void* munmap(void* addr, size_t len) 28 | { 29 | return (void*)__syscall(SYS_munmap, addr, len); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /runtime/linux/x86/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | size_t shiftedOffset = (size_t)(offset >> 12); 24 | return (void*)__syscall(SYS_mmap2, addr, len, prot, flags, fd, shiftedOffset); 25 | } 26 | 27 | void* munmap(void* addr, size_t len) 28 | { 29 | return (void*)__syscall(SYS_munmap, addr, len); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /runtime/linux/mips/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset) 22 | { 23 | size_t shiftedOffset = (size_t)(offset >> 12); 24 | return (void*)__syscall(SYS_mmap2, addr, len, prot, flags, fd, shiftedOffset); 25 | } 26 | 27 | void* munmap(void* addr, size_t len) 28 | { 29 | return (void*)__syscall(SYS_munmap, addr, len); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /runtime/windows/memory.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2014 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | void* malloc(size_t len) 22 | { 23 | return HeapAlloc(GetProcessHeap(), 0, len); 24 | } 25 | 26 | void free(void* ptr) 27 | { 28 | if (ptr == NULL) 29 | return; 30 | HeapFree(GetProcessHeap(), 0, ptr); 31 | } 32 | 33 | char* strdup(const char* str) 34 | { 35 | char* dest = (char*)malloc(strlen(str) + 1); 36 | strcpy(dest, str); 37 | return dest; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /runtime/posix/memory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__MEMORY_H__ 22 | #define __LIBC__MEMORY_H__ 23 | 24 | void* malloc(size_t len); 25 | void free(void* ptr); 26 | 27 | char* strdup(const char* str); 28 | 29 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, uint64_t offset); 30 | void* munmap(void* addr, size_t len); 31 | int mprotect(void* addr, size_t len, int prot); 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shellcode Compiler 2 | 3 | The Shellcode Compiler started its life as an internal CTF tool before it was re-purposed to be the compiler integrated into Binary Ninja. 4 | 5 | With the 5.0 release of [Binary Ninja](https://binary.ninja/), this repository was open-sourced. In the future, it's likely that SCC may be migrated into the main [binaryninja-api](https://github.com/Vector35/binaryninja-api/) repository. 6 | 7 | Long-term our plan is to replace scc with a version of LLVM using the appropriate compiler flags for minimal shellcode-style codegen. (We're already embedding multiple copies of LLVM -- one for the type parse and one for the debugger, so this need not be as much of a burden as it might sound.) 8 | 9 | Note that scc is not being actively maintained, however pull-requests and [issues](https://github.com/Vector35/binaryninja-api/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22Component%3A%20SCC%22) are welcome. 10 | 11 | ## Documentation 12 | 13 | Online documentation is available at: [https://scc.binary.ninja/](https://scc.binary.ninja/) 14 | 15 | ## Usage and Build Instructions 16 | 17 | The build system uses cmake: 18 | 19 | ``` 20 | $ git clone --recursive https://github.com/vector35/scc 21 | $ cd scc 22 | $ cmake -S . -B build 23 | ... 24 | $ cmake --build build 25 | ``` 26 | 27 | ## Licensing 28 | 29 | Some components may be released under compatible but slightly different open source licenses and should have their own LICENSE file as appropriate. 30 | 31 | Remaining components are released under an [MIT](https://github.com/Vector35/scc/blob/dev/LICENSE.txt) license. 32 | -------------------------------------------------------------------------------- /runtime/freebsd/time.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | time_t time(time_t* t) 22 | { 23 | struct timeval tv; 24 | gettimeofday(&tv, NULL); 25 | if (t) 26 | *t = tv.tv_sec; 27 | return tv.tv_sec; 28 | } 29 | 30 | int gettimeofday(struct timeval* t, struct timezone* tz) 31 | { 32 | return __syscall(SYS_gettimeofday, t, tz); 33 | } 34 | 35 | int nanosleep(const struct timespec* amount, struct timespec* unslept) 36 | { 37 | return __syscall(SYS_nanosleep, amount, unslept); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /runtime/byteswap.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011-2012 Rusty Wagner 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | #ifndef __LIBC__BYTESWAP_H__ 22 | #define __LIBC__BYTESWAP_H__ 23 | 24 | #ifdef LITTLE_ENDIAN 25 | #define htons(x) __byteswap((uint16_t)(x)) 26 | #define htonl(x) __byteswap((uint32_t)(x)) 27 | #define ntohs(x) __byteswap((uint16_t)(x)) 28 | #define ntohl(x) __byteswap((uint32_t)(x)) 29 | #else 30 | #define htons(x) ((uint16_t)(x)) 31 | #define htonl(x) ((uint32_t)(x)) 32 | #define ntohs(x) ((uint16_t)(x)) 33 | #define ntohl(x) ((uint32_t)(x)) 34 | #endif 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /TreeBlock.h: -------------------------------------------------------------------------------- 1 | #ifndef __TREEBLOCK_H__ 2 | #define __TREEBLOCK_H__ 3 | 4 | #include "TreeNode.h" 5 | #include "ILBlock.h" 6 | #include "Settings.h" 7 | #include "Struct.h" 8 | #include "Variable.h" 9 | 10 | 11 | struct VariableAssignments; 12 | class Output; 13 | 14 | class TreeBlock: public RefCountObject 15 | { 16 | ILBlock* m_source; 17 | size_t m_index; 18 | std::vector< Ref > m_nodes; 19 | size_t m_errors; 20 | TreeNodeType m_ptrType; 21 | 22 | bool GetMemberVariableAndOffset(ILParameter& operand, Variable*& var, size_t& offset, Type*& type); 23 | TreeNodeType GetPtrType(); 24 | TreeNodeType VariableTypeToNodeType(Type* type); 25 | TreeNodeType OperandToNodeType(ILParameter& operand); 26 | TreeNode* OperandToNode(const VariableAssignments& vars, ILParameter& operand); 27 | TreeNode* OperandRefToNode(const VariableAssignments& vars, ILParameter& operand); 28 | void StoreToOperand(const VariableAssignments& vars, ILParameter& dest, TreeNode* value); 29 | TreeNode* ConstantMultiplyNode(TreeNode* val, uint64_t mult); 30 | TreeNode* ConstantDivideNode(TreeNode* val, uint64_t div); 31 | TreeNodeType DoubleTypeSize(TreeNodeType type); 32 | 33 | public: 34 | TreeBlock(ILBlock* source, size_t idx); 35 | 36 | ILBlock* GetSource() const { return m_source; } 37 | size_t GetIndex() const { return m_index; } 38 | 39 | void AddNode(TreeNode* node); 40 | const std::vector< Ref >& GetNodes() const { return m_nodes; } 41 | 42 | bool GenerateFromILBlock(ILBlock* il, std::vector< Ref >& blocks, const VariableAssignments& vars, 43 | const Settings& settings, Output* output); 44 | 45 | void Print() const; 46 | }; 47 | 48 | 49 | #endif 50 | 51 | --------------------------------------------------------------------------------