fork download
  1. #include "dasm_proto.h"
  2. #include "ex5_labels_x64.h"
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <windows.h>
  8.  
  9. void* link(Dst_DECL) {
  10. size_t size = 0;
  11. int linkStatus = dasm_link(Dst, &size);
  12. if (linkStatus != DASM_S_OK) {
  13. fprintf(stderr, "link error\n");
  14. exit(1);
  15. }
  16.  
  17. void* mem = VirtualAlloc(0, size + sizeof(size_t), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  18. if (mem == 0) {
  19. fprintf(stderr, "allocation error\n");
  20. exit(2);
  21. }
  22.  
  23. *(size_t*)mem = size;
  24. void *ret = (char*)mem + sizeof(size_t);
  25.  
  26. dasm_encode(Dst, ret);
  27.  
  28. //FlushInstructionCache(GetCurrentProcess(), ret, size);
  29.  
  30. DWORD oldProt = 0;
  31. BOOL st = VirtualProtect(mem, size, PAGE_EXECUTE_READ, &oldProt);
  32. if (st != TRUE) {
  33. VirtualFree(mem, 0, MEM_RELEASE);
  34. fprintf(stderr, "error while changing memory protection");
  35. exit(3);
  36. }
  37.  
  38. return ret;
  39. }
  40.  
  41. void* globalTbl[GLOB__MAX == 0 ? 1 : GLOB__MAX];
  42.  
  43. void* generate(Dst_DECL, int nopCount) {
  44. dasm_init(Dst, 1);
  45.  
  46. dasm_setupglobal(Dst, globalTbl, GLOB__MAX);
  47. dasm_setup(Dst, actions);
  48.  
  49. dasm_growpc(Dst, 1);
  50.  
  51. dynasmGenerator(Dst, nopCount);
  52.  
  53. return link(Dst);
  54. }
  55.  
  56. int main(int argc, char **argv)
  57. {
  58. dasm_State *dasmState;
  59.  
  60. uint64_t (*fptr)() = ((uint64_t(*)()) generate(&dasmState, 4 * 1024 * 1024 + 1));
  61. uint64_t result = fptr();
  62.  
  63. printf ("%llx\n", result);
  64. return 0;
  65. }
  66.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:24: fatal error: dasm_proto.h: No such file or directory
compilation terminated.
stdout
Standard output is empty