Advertisement
FlyFar

instruction_set_macros.inc

Jul 27th, 2023
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 3.04 KB | Cybersecurity | 0 0
  1. macro addnumber BigNum*
  2. {
  3. ;    CreateAnIntron
  4.     AlreadyStarted=0
  5.     if BigNum<25
  6.     repeat BigNum
  7.         _add0001
  8.     end repeat
  9.     else
  10.     _pushall
  11.     _push  ; BC1 to stack
  12.     _save
  13. ;        CreateAnIntron
  14.     _xor   ; BC1=0
  15.     _add0001
  16.     _save
  17.     _sub0001 ; BC1=0, BC2=1
  18. ;        CreateAnIntron
  19.     irp num, 0x8000'0000,0x4000'0000,0x2000'0000,0x1000'0000,0x800'0000,0x400'0000,0x200'0000,0x100'0000,0x80'0000,0x40'0000,0x20'0000,0x10'0000,0x8'0000,0x4'0000,0x2'0000,0x1'0000,0x8000,0x4000,0x2000,0x1000,0x800,0x400,0x200,0x100,0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1
  20.     \{
  21.         if AlreadyStarted=1
  22.         _shl
  23.         end if
  24.         if (BigNum AND num)>0
  25.         _add0001
  26.         AlreadyStarted=1
  27.         end if
  28.     \} ; BC1=BigNum
  29. ;        CreateAnIntron
  30.     _save       ; BC2=BigNum
  31.     _pop        ; restore BC1
  32.     _addsaved   ; BC1=BC1+BigNum
  33.     _nopdC      ; Save in RegC
  34.     _popall     ; Restore all registers
  35.     _nopsC      ; BC1=BC1+BigNum
  36. ;        CreateAnIntron
  37.     _pushall    ; Restore ZF
  38.     _save
  39.     _and
  40.     _popall
  41.     end if
  42. ;    CreateAnIntron
  43.  
  44. }
  45.  
  46.  
  47. macro GetAddress address
  48. {
  49.     _getDO
  50. ;    CreateAnIntron
  51.     addnumber (address-DataOffset)
  52. }
  53.  
  54.  
  55.  
  56. macro CallAPI APIName
  57. {
  58. ;    CreateAnIntron
  59.     _getDO
  60.     addnumber (APIName-DataOffset)
  61.     _getdata
  62.     _call
  63. ;    CreateAnIntron
  64. }
  65.  
  66.  
  67.  
  68. macro CalcNewRandNumberAndSaveIt
  69. {
  70.     GetAddress RandomNumber
  71. ;        CreateAnIntron
  72.     _saveWrtOff
  73.     _getdata
  74.     _nopdA           ; eax=[RandomNumber]
  75.  
  76.     _zer0 0
  77.     addnumber 1103515245
  78. ;        CreateAnIntron
  79.     _mul             ; eax*=1103515245 % 2^32
  80.  
  81.     _zer0 0
  82.     addnumber 12345
  83.     _save
  84. ;        CreateAnIntron
  85.     _nopsA
  86.     _addsaved        ; eax+=12345 % 2^32
  87.  
  88.     _writeDWord      ; mov [RandomNumber], ebx
  89. }
  90.  
  91.  
  92. macro _nopdC
  93. {
  94.     _pushall        ; save all registers
  95.     _push           ; save BC1
  96. ;        CreateAnIntron
  97.     _getDO          ; For code-optimization, RegC is at DataOffset+0x0. But could be anywhere as _add0001 exists.
  98. ;        CreateAnIntron
  99.     _saveWrtOff     ; BA1=RegC
  100.     _pop
  101.     _writeDWord     ; mov dword[RegC], BC1
  102.     _popall         ; restore all registers
  103. }
  104.  
  105.  
  106. macro _nopsC
  107. {
  108.     _getDO          ; For code-optimization, RegC is at DataOffset+0x0. But could be anywhere as _add0001 exists.
  109.     _getdata
  110. ;        CreateAnIntron
  111.     display '.'
  112. }
  113.  
  114.  
  115. macro _zer0 SaveBC2*
  116. {
  117. ; Simulate _zer0 instruction.
  118. ; The argument tells wheter BC2 should be restored or not.
  119.  
  120.     if SaveBC2<>0
  121.     _pushall
  122. ;        CreateAnIntron
  123.     end if
  124.  
  125. ;        CreateAnIntron
  126.     _save       ; BC2=BC1
  127.     _xor        ; BC1=BC1 XOR BC2 = 0
  128.  
  129.  
  130.     if SaveBC2<>0
  131.     _nopdC
  132.     _popall
  133.     _nopsC
  134.     end if
  135. }
  136.  
  137.  
  138. macro _subsaved SaveBC2*
  139. {
  140. ; Simulate _subsaved instruction.
  141. ; The argument tells wheter BC2 should be restored or not.
  142.  
  143.     if SaveBC2<>0
  144.     _pushall
  145. ;        CreateAnIntron
  146.     end if
  147.  
  148. ;         CreateAnIntron
  149.     _push       ; save BC1
  150.     _zer0 1     ; BC1=0
  151.     _sub0001    ; BC1=0xFFFF'FFFF
  152. ;        CreateAnIntron
  153.     _xor        ; BC1=0xFFFF'FFFF XOR BC2
  154.     _add0001    ; BC1=-BC2
  155.     _save       ; BC2=-BC2
  156.     _pop        ; restore BC1
  157.     _addsaved   ; BC1=BC1+(-BC2)
  158. ;        CreateAnIntron
  159.  
  160.     if SaveBC2<>0
  161.     _nopdC
  162.     _popall
  163.     _nopsC
  164. ;        CreateAnIntron
  165.     _pushall    ; Restore ZF
  166.     _save
  167.     _and
  168.     _popall
  169.     end if
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement