Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

654 Zeilen
15 KiB

  1. #!/usr/bin/env perl
  2. #
  3. # ====================================================================
  4. # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
  5. # project. The module is, however, dual licensed under OpenSSL and
  6. # CRYPTOGAMS licenses depending on where you obtain it. For further
  7. # details see http://www.openssl.org/~appro/cryptogams/.
  8. # ====================================================================
  9. #
  10. # July 2004
  11. #
  12. # 2.22x RC4 tune-up:-) It should be noted though that my hand [as in
  13. # "hand-coded assembler"] doesn't stand for the whole improvement
  14. # coefficient. It turned out that eliminating RC4_CHAR from config
  15. # line results in ~40% improvement (yes, even for C implementation).
  16. # Presumably it has everything to do with AMD cache architecture and
  17. # RAW or whatever penalties. Once again! The module *requires* config
  18. # line *without* RC4_CHAR! As for coding "secret," I bet on partial
  19. # register arithmetics. For example instead of 'inc %r8; and $255,%r8'
  20. # I simply 'inc %r8b'. Even though optimization manual discourages
  21. # to operate on partial registers, it turned out to be the best bet.
  22. # At least for AMD... How IA32E would perform remains to be seen...
  23. # November 2004
  24. #
  25. # As was shown by Marc Bevand reordering of couple of load operations
  26. # results in even higher performance gain of 3.3x:-) At least on
  27. # Opteron... For reference, 1x in this case is RC4_CHAR C-code
  28. # compiled with gcc 3.3.2, which performs at ~54MBps per 1GHz clock.
  29. # Latter means that if you want to *estimate* what to expect from
  30. # *your* Opteron, then multiply 54 by 3.3 and clock frequency in GHz.
  31. # November 2004
  32. #
  33. # Intel P4 EM64T core was found to run the AMD64 code really slow...
  34. # The only way to achieve comparable performance on P4 was to keep
  35. # RC4_CHAR. Kind of ironic, huh? As it's apparently impossible to
  36. # compose blended code, which would perform even within 30% marginal
  37. # on either AMD and Intel platforms, I implement both cases. See
  38. # rc4_skey.c for further details...
  39. # April 2005
  40. #
  41. # P4 EM64T core appears to be "allergic" to 64-bit inc/dec. Replacing
  42. # those with add/sub results in 50% performance improvement of folded
  43. # loop...
  44. # May 2005
  45. #
  46. # As was shown by Zou Nanhai loop unrolling can improve Intel EM64T
  47. # performance by >30% [unlike P4 32-bit case that is]. But this is
  48. # provided that loads are reordered even more aggressively! Both code
  49. # pathes, AMD64 and EM64T, reorder loads in essentially same manner
  50. # as my IA-64 implementation. On Opteron this resulted in modest 5%
  51. # improvement [I had to test it], while final Intel P4 performance
  52. # achieves respectful 432MBps on 2.8GHz processor now. For reference.
  53. # If executed on Xeon, current RC4_CHAR code-path is 2.7x faster than
  54. # RC4_INT code-path. While if executed on Opteron, it's only 25%
  55. # slower than the RC4_INT one [meaning that if CPU µ-arch detection
  56. # is not implemented, then this final RC4_CHAR code-path should be
  57. # preferred, as it provides better *all-round* performance].
  58. # March 2007
  59. #
  60. # Intel Core2 was observed to perform poorly on both code paths:-( It
  61. # apparently suffers from some kind of partial register stall, which
  62. # occurs in 64-bit mode only [as virtually identical 32-bit loop was
  63. # observed to outperform 64-bit one by almost 50%]. Adding two movzb to
  64. # cloop1 boosts its performance by 80%! This loop appears to be optimal
  65. # fit for Core2 and therefore the code was modified to skip cloop8 on
  66. # this CPU.
  67. # May 2010
  68. #
  69. # Intel Westmere was observed to perform suboptimally. Adding yet
  70. # another movzb to cloop1 improved performance by almost 50%! Core2
  71. # performance is improved too, but nominally...
  72. # May 2011
  73. #
  74. # The only code path that was not modified is P4-specific one. Non-P4
  75. # Intel code path optimization is heavily based on submission by Maxim
  76. # Perminov, Maxim Locktyukhin and Jim Guilford of Intel. I've used
  77. # some of the ideas even in attempt to optmize the original RC4_INT
  78. # code path... Current performance in cycles per processed byte (less
  79. # is better) and improvement coefficients relative to previous
  80. # version of this module are:
  81. #
  82. # Opteron 5.3/+0%(*)
  83. # P4 6.5
  84. # Core2 6.2/+15%(**)
  85. # Westmere 4.2/+60%
  86. # Sandy Bridge 4.2/+120%
  87. # Atom 9.3/+80%
  88. #
  89. # (*) But corresponding loop has less instructions, which should have
  90. # positive effect on upcoming Bulldozer, which has one less ALU.
  91. # For reference, Intel code runs at 6.8 cpb rate on Opteron.
  92. # (**) Note that Core2 result is ~15% lower than corresponding result
  93. # for 32-bit code, meaning that it's possible to improve it,
  94. # but more than likely at the cost of the others (see rc4-586.pl
  95. # to get the idea)...
  96. $flavour = shift;
  97. $output = shift;
  98. if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
  99. $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
  100. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  101. ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
  102. ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
  103. die "can't locate x86_64-xlate.pl";
  104. open OUT,"| \"$^X\" $xlate $flavour $output";
  105. *STDOUT=*OUT;
  106. $dat="%rdi"; # arg1
  107. $len="%rsi"; # arg2
  108. $inp="%rdx"; # arg3
  109. $out="%rcx"; # arg4
  110. {
  111. $code=<<___;
  112. .text
  113. .extern OPENSSL_ia32cap_P
  114. .globl asm_RC4
  115. .type asm_RC4,\@function,4
  116. .align 16
  117. asm_RC4:
  118. or $len,$len
  119. jne .Lentry
  120. ret
  121. .Lentry:
  122. push %rbx
  123. push %r12
  124. push %r13
  125. .Lprologue:
  126. mov $len,%r11
  127. mov $inp,%r12
  128. mov $out,%r13
  129. ___
  130. my $len="%r11"; # reassign input arguments
  131. my $inp="%r12";
  132. my $out="%r13";
  133. my @XX=("%r10","%rsi");
  134. my @TX=("%rax","%rbx");
  135. my $YY="%rcx";
  136. my $TY="%rdx";
  137. $code.=<<___;
  138. xor $XX[0],$XX[0]
  139. xor $YY,$YY
  140. lea 8($dat),$dat
  141. mov -8($dat),$XX[0]#b
  142. mov -4($dat),$YY#b
  143. cmpl \$-1,256($dat)
  144. je .LRC4_CHAR
  145. mov OPENSSL_ia32cap_P(%rip),%r8d
  146. xor $TX[1],$TX[1]
  147. inc $XX[0]#b
  148. sub $XX[0],$TX[1]
  149. sub $inp,$out
  150. movl ($dat,$XX[0],4),$TX[0]#d
  151. test \$-16,$len
  152. jz .Lloop1
  153. bt \$30,%r8d # Intel CPU?
  154. jc .Lintel
  155. and \$7,$TX[1]
  156. lea 1($XX[0]),$XX[1]
  157. jz .Loop8
  158. sub $TX[1],$len
  159. .Loop8_warmup:
  160. add $TX[0]#b,$YY#b
  161. movl ($dat,$YY,4),$TY#d
  162. movl $TX[0]#d,($dat,$YY,4)
  163. movl $TY#d,($dat,$XX[0],4)
  164. add $TY#b,$TX[0]#b
  165. inc $XX[0]#b
  166. movl ($dat,$TX[0],4),$TY#d
  167. movl ($dat,$XX[0],4),$TX[0]#d
  168. xorb ($inp),$TY#b
  169. movb $TY#b,($out,$inp)
  170. lea 1($inp),$inp
  171. dec $TX[1]
  172. jnz .Loop8_warmup
  173. lea 1($XX[0]),$XX[1]
  174. jmp .Loop8
  175. .align 16
  176. .Loop8:
  177. ___
  178. for ($i=0;$i<8;$i++) {
  179. $code.=<<___ if ($i==7);
  180. add \$8,$XX[1]#b
  181. ___
  182. $code.=<<___;
  183. add $TX[0]#b,$YY#b
  184. movl ($dat,$YY,4),$TY#d
  185. movl $TX[0]#d,($dat,$YY,4)
  186. movl `4*($i==7?-1:$i)`($dat,$XX[1],4),$TX[1]#d
  187. ror \$8,%r8 # ror is redundant when $i=0
  188. movl $TY#d,4*$i($dat,$XX[0],4)
  189. add $TX[0]#b,$TY#b
  190. movb ($dat,$TY,4),%r8b
  191. ___
  192. push(@TX,shift(@TX)); #push(@XX,shift(@XX)); # "rotate" registers
  193. }
  194. $code.=<<___;
  195. add \$8,$XX[0]#b
  196. ror \$8,%r8
  197. sub \$8,$len
  198. xor ($inp),%r8
  199. mov %r8,($out,$inp)
  200. lea 8($inp),$inp
  201. test \$-8,$len
  202. jnz .Loop8
  203. cmp \$0,$len
  204. jne .Lloop1
  205. jmp .Lexit
  206. .align 16
  207. .Lintel:
  208. test \$-32,$len
  209. jz .Lloop1
  210. and \$15,$TX[1]
  211. jz .Loop16_is_hot
  212. sub $TX[1],$len
  213. .Loop16_warmup:
  214. add $TX[0]#b,$YY#b
  215. movl ($dat,$YY,4),$TY#d
  216. movl $TX[0]#d,($dat,$YY,4)
  217. movl $TY#d,($dat,$XX[0],4)
  218. add $TY#b,$TX[0]#b
  219. inc $XX[0]#b
  220. movl ($dat,$TX[0],4),$TY#d
  221. movl ($dat,$XX[0],4),$TX[0]#d
  222. xorb ($inp),$TY#b
  223. movb $TY#b,($out,$inp)
  224. lea 1($inp),$inp
  225. dec $TX[1]
  226. jnz .Loop16_warmup
  227. mov $YY,$TX[1]
  228. xor $YY,$YY
  229. mov $TX[1]#b,$YY#b
  230. .Loop16_is_hot:
  231. lea ($dat,$XX[0],4),$XX[1]
  232. ___
  233. sub RC4_loop {
  234. my $i=shift;
  235. my $j=$i<0?0:$i;
  236. my $xmm="%xmm".($j&1);
  237. $code.=" add \$16,$XX[0]#b\n" if ($i==15);
  238. $code.=" movdqu ($inp),%xmm2\n" if ($i==15);
  239. $code.=" add $TX[0]#b,$YY#b\n" if ($i<=0);
  240. $code.=" movl ($dat,$YY,4),$TY#d\n";
  241. $code.=" pxor %xmm0,%xmm2\n" if ($i==0);
  242. $code.=" psllq \$8,%xmm1\n" if ($i==0);
  243. $code.=" pxor $xmm,$xmm\n" if ($i<=1);
  244. $code.=" movl $TX[0]#d,($dat,$YY,4)\n";
  245. $code.=" add $TY#b,$TX[0]#b\n";
  246. $code.=" movl `4*($j+1)`($XX[1]),$TX[1]#d\n" if ($i<15);
  247. $code.=" movz $TX[0]#b,$TX[0]#d\n";
  248. $code.=" movl $TY#d,4*$j($XX[1])\n";
  249. $code.=" pxor %xmm1,%xmm2\n" if ($i==0);
  250. $code.=" lea ($dat,$XX[0],4),$XX[1]\n" if ($i==15);
  251. $code.=" add $TX[1]#b,$YY#b\n" if ($i<15);
  252. $code.=" pinsrw \$`($j>>1)&7`,($dat,$TX[0],4),$xmm\n";
  253. $code.=" movdqu %xmm2,($out,$inp)\n" if ($i==0);
  254. $code.=" lea 16($inp),$inp\n" if ($i==0);
  255. $code.=" movl ($XX[1]),$TX[1]#d\n" if ($i==15);
  256. }
  257. RC4_loop(-1);
  258. $code.=<<___;
  259. jmp .Loop16_enter
  260. .align 16
  261. .Loop16:
  262. ___
  263. for ($i=0;$i<16;$i++) {
  264. $code.=".Loop16_enter:\n" if ($i==1);
  265. RC4_loop($i);
  266. push(@TX,shift(@TX)); # "rotate" registers
  267. }
  268. $code.=<<___;
  269. mov $YY,$TX[1]
  270. xor $YY,$YY # keyword to partial register
  271. sub \$16,$len
  272. mov $TX[1]#b,$YY#b
  273. test \$-16,$len
  274. jnz .Loop16
  275. psllq \$8,%xmm1
  276. pxor %xmm0,%xmm2
  277. pxor %xmm1,%xmm2
  278. movdqu %xmm2,($out,$inp)
  279. lea 16($inp),$inp
  280. cmp \$0,$len
  281. jne .Lloop1
  282. jmp .Lexit
  283. .align 16
  284. .Lloop1:
  285. add $TX[0]#b,$YY#b
  286. movl ($dat,$YY,4),$TY#d
  287. movl $TX[0]#d,($dat,$YY,4)
  288. movl $TY#d,($dat,$XX[0],4)
  289. add $TY#b,$TX[0]#b
  290. inc $XX[0]#b
  291. movl ($dat,$TX[0],4),$TY#d
  292. movl ($dat,$XX[0],4),$TX[0]#d
  293. xorb ($inp),$TY#b
  294. movb $TY#b,($out,$inp)
  295. lea 1($inp),$inp
  296. dec $len
  297. jnz .Lloop1
  298. jmp .Lexit
  299. .align 16
  300. .LRC4_CHAR:
  301. add \$1,$XX[0]#b
  302. movzb ($dat,$XX[0]),$TX[0]#d
  303. test \$-8,$len
  304. jz .Lcloop1
  305. jmp .Lcloop8
  306. .align 16
  307. .Lcloop8:
  308. mov ($inp),%r8d
  309. mov 4($inp),%r9d
  310. ___
  311. # unroll 2x4-wise, because 64-bit rotates kill Intel P4...
  312. for ($i=0;$i<4;$i++) {
  313. $code.=<<___;
  314. add $TX[0]#b,$YY#b
  315. lea 1($XX[0]),$XX[1]
  316. movzb ($dat,$YY),$TY#d
  317. movzb $XX[1]#b,$XX[1]#d
  318. movzb ($dat,$XX[1]),$TX[1]#d
  319. movb $TX[0]#b,($dat,$YY)
  320. cmp $XX[1],$YY
  321. movb $TY#b,($dat,$XX[0])
  322. jne .Lcmov$i # Intel cmov is sloooow...
  323. mov $TX[0],$TX[1]
  324. .Lcmov$i:
  325. add $TX[0]#b,$TY#b
  326. xor ($dat,$TY),%r8b
  327. ror \$8,%r8d
  328. ___
  329. push(@TX,shift(@TX)); push(@XX,shift(@XX)); # "rotate" registers
  330. }
  331. for ($i=4;$i<8;$i++) {
  332. $code.=<<___;
  333. add $TX[0]#b,$YY#b
  334. lea 1($XX[0]),$XX[1]
  335. movzb ($dat,$YY),$TY#d
  336. movzb $XX[1]#b,$XX[1]#d
  337. movzb ($dat,$XX[1]),$TX[1]#d
  338. movb $TX[0]#b,($dat,$YY)
  339. cmp $XX[1],$YY
  340. movb $TY#b,($dat,$XX[0])
  341. jne .Lcmov$i # Intel cmov is sloooow...
  342. mov $TX[0],$TX[1]
  343. .Lcmov$i:
  344. add $TX[0]#b,$TY#b
  345. xor ($dat,$TY),%r9b
  346. ror \$8,%r9d
  347. ___
  348. push(@TX,shift(@TX)); push(@XX,shift(@XX)); # "rotate" registers
  349. }
  350. $code.=<<___;
  351. lea -8($len),$len
  352. mov %r8d,($out)
  353. lea 8($inp),$inp
  354. mov %r9d,4($out)
  355. lea 8($out),$out
  356. test \$-8,$len
  357. jnz .Lcloop8
  358. cmp \$0,$len
  359. jne .Lcloop1
  360. jmp .Lexit
  361. ___
  362. $code.=<<___;
  363. .align 16
  364. .Lcloop1:
  365. add $TX[0]#b,$YY#b
  366. movzb $YY#b,$YY#d
  367. movzb ($dat,$YY),$TY#d
  368. movb $TX[0]#b,($dat,$YY)
  369. movb $TY#b,($dat,$XX[0])
  370. add $TX[0]#b,$TY#b
  371. add \$1,$XX[0]#b
  372. movzb $TY#b,$TY#d
  373. movzb $XX[0]#b,$XX[0]#d
  374. movzb ($dat,$TY),$TY#d
  375. movzb ($dat,$XX[0]),$TX[0]#d
  376. xorb ($inp),$TY#b
  377. lea 1($inp),$inp
  378. movb $TY#b,($out)
  379. lea 1($out),$out
  380. sub \$1,$len
  381. jnz .Lcloop1
  382. jmp .Lexit
  383. .align 16
  384. .Lexit:
  385. sub \$1,$XX[0]#b
  386. movl $XX[0]#d,-8($dat)
  387. movl $YY#d,-4($dat)
  388. mov (%rsp),%r13
  389. mov 8(%rsp),%r12
  390. mov 16(%rsp),%rbx
  391. add \$24,%rsp
  392. .Lepilogue:
  393. ret
  394. .size asm_RC4,.-asm_RC4
  395. ___
  396. }
  397. $idx="%r8";
  398. $ido="%r9";
  399. $code.=<<___;
  400. .globl asm_RC4_set_key
  401. .type asm_RC4_set_key,\@function,3
  402. .align 16
  403. asm_RC4_set_key:
  404. lea 8($dat),$dat
  405. lea ($inp,$len),$inp
  406. neg $len
  407. mov $len,%rcx
  408. xor %eax,%eax
  409. xor $ido,$ido
  410. xor %r10,%r10
  411. xor %r11,%r11
  412. mov OPENSSL_ia32cap_P(%rip),$idx#d
  413. bt \$20,$idx#d # RC4_CHAR?
  414. jc .Lc1stloop
  415. jmp .Lw1stloop
  416. .align 16
  417. .Lw1stloop:
  418. mov %eax,($dat,%rax,4)
  419. add \$1,%al
  420. jnc .Lw1stloop
  421. xor $ido,$ido
  422. xor $idx,$idx
  423. .align 16
  424. .Lw2ndloop:
  425. mov ($dat,$ido,4),%r10d
  426. add ($inp,$len,1),$idx#b
  427. add %r10b,$idx#b
  428. add \$1,$len
  429. mov ($dat,$idx,4),%r11d
  430. cmovz %rcx,$len
  431. mov %r10d,($dat,$idx,4)
  432. mov %r11d,($dat,$ido,4)
  433. add \$1,$ido#b
  434. jnc .Lw2ndloop
  435. jmp .Lexit_key
  436. .align 16
  437. .Lc1stloop:
  438. mov %al,($dat,%rax)
  439. add \$1,%al
  440. jnc .Lc1stloop
  441. xor $ido,$ido
  442. xor $idx,$idx
  443. .align 16
  444. .Lc2ndloop:
  445. mov ($dat,$ido),%r10b
  446. add ($inp,$len),$idx#b
  447. add %r10b,$idx#b
  448. add \$1,$len
  449. mov ($dat,$idx),%r11b
  450. jnz .Lcnowrap
  451. mov %rcx,$len
  452. .Lcnowrap:
  453. mov %r10b,($dat,$idx)
  454. mov %r11b,($dat,$ido)
  455. add \$1,$ido#b
  456. jnc .Lc2ndloop
  457. movl \$-1,256($dat)
  458. .align 16
  459. .Lexit_key:
  460. xor %eax,%eax
  461. mov %eax,-8($dat)
  462. mov %eax,-4($dat)
  463. ret
  464. .size asm_RC4_set_key,.-asm_RC4_set_key
  465. ___
  466. # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
  467. # CONTEXT *context,DISPATCHER_CONTEXT *disp)
  468. if ($win64) {
  469. $rec="%rcx";
  470. $frame="%rdx";
  471. $context="%r8";
  472. $disp="%r9";
  473. $code.=<<___;
  474. .extern __imp_RtlVirtualUnwind
  475. .type stream_se_handler,\@abi-omnipotent
  476. .align 16
  477. stream_se_handler:
  478. push %rsi
  479. push %rdi
  480. push %rbx
  481. push %rbp
  482. push %r12
  483. push %r13
  484. push %r14
  485. push %r15
  486. pushfq
  487. sub \$64,%rsp
  488. mov 120($context),%rax # pull context->Rax
  489. mov 248($context),%rbx # pull context->Rip
  490. lea .Lprologue(%rip),%r10
  491. cmp %r10,%rbx # context->Rip<prologue label
  492. jb .Lin_prologue
  493. mov 152($context),%rax # pull context->Rsp
  494. lea .Lepilogue(%rip),%r10
  495. cmp %r10,%rbx # context->Rip>=epilogue label
  496. jae .Lin_prologue
  497. lea 24(%rax),%rax
  498. mov -8(%rax),%rbx
  499. mov -16(%rax),%r12
  500. mov -24(%rax),%r13
  501. mov %rbx,144($context) # restore context->Rbx
  502. mov %r12,216($context) # restore context->R12
  503. mov %r13,224($context) # restore context->R13
  504. .Lin_prologue:
  505. mov 8(%rax),%rdi
  506. mov 16(%rax),%rsi
  507. mov %rax,152($context) # restore context->Rsp
  508. mov %rsi,168($context) # restore context->Rsi
  509. mov %rdi,176($context) # restore context->Rdi
  510. jmp .Lcommon_seh_exit
  511. .size stream_se_handler,.-stream_se_handler
  512. .type key_se_handler,\@abi-omnipotent
  513. .align 16
  514. key_se_handler:
  515. push %rsi
  516. push %rdi
  517. push %rbx
  518. push %rbp
  519. push %r12
  520. push %r13
  521. push %r14
  522. push %r15
  523. pushfq
  524. sub \$64,%rsp
  525. mov 152($context),%rax # pull context->Rsp
  526. mov 8(%rax),%rdi
  527. mov 16(%rax),%rsi
  528. mov %rsi,168($context) # restore context->Rsi
  529. mov %rdi,176($context) # restore context->Rdi
  530. .Lcommon_seh_exit:
  531. mov 40($disp),%rdi # disp->ContextRecord
  532. mov $context,%rsi # context
  533. mov \$154,%ecx # sizeof(CONTEXT)
  534. .long 0xa548f3fc # cld; rep movsq
  535. mov $disp,%rsi
  536. xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
  537. mov 8(%rsi),%rdx # arg2, disp->ImageBase
  538. mov 0(%rsi),%r8 # arg3, disp->ControlPc
  539. mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
  540. mov 40(%rsi),%r10 # disp->ContextRecord
  541. lea 56(%rsi),%r11 # &disp->HandlerData
  542. lea 24(%rsi),%r12 # &disp->EstablisherFrame
  543. mov %r10,32(%rsp) # arg5
  544. mov %r11,40(%rsp) # arg6
  545. mov %r12,48(%rsp) # arg7
  546. mov %rcx,56(%rsp) # arg8, (NULL)
  547. call *__imp_RtlVirtualUnwind(%rip)
  548. mov \$1,%eax # ExceptionContinueSearch
  549. add \$64,%rsp
  550. popfq
  551. pop %r15
  552. pop %r14
  553. pop %r13
  554. pop %r12
  555. pop %rbp
  556. pop %rbx
  557. pop %rdi
  558. pop %rsi
  559. ret
  560. .size key_se_handler,.-key_se_handler
  561. .section .pdata
  562. .align 4
  563. .rva .LSEH_begin_asm_RC4
  564. .rva .LSEH_end_asm_RC4
  565. .rva .LSEH_info_asm_RC4
  566. .rva .LSEH_begin_asm_RC4_set_key
  567. .rva .LSEH_end_asm_RC4_set_key
  568. .rva .LSEH_info_asm_RC4_set_key
  569. .section .xdata
  570. .align 8
  571. .LSEH_info_asm_RC4:
  572. .byte 9,0,0,0
  573. .rva stream_se_handler
  574. .LSEH_info_asm_RC4_set_key:
  575. .byte 9,0,0,0
  576. .rva key_se_handler
  577. ___
  578. }
  579. sub reg_part {
  580. my ($reg,$conv)=@_;
  581. if ($reg =~ /%r[0-9]+/) { $reg .= $conv; }
  582. elsif ($conv eq "b") { $reg =~ s/%[er]([^x]+)x?/%$1l/; }
  583. elsif ($conv eq "w") { $reg =~ s/%[er](.+)/%$1/; }
  584. elsif ($conv eq "d") { $reg =~ s/%[er](.+)/%e$1/; }
  585. return $reg;
  586. }
  587. $code =~ s/(%[a-z0-9]+)#([bwd])/reg_part($1,$2)/gem;
  588. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  589. print $code;
  590. close STDOUT;