Guest User

Untitled

a guest
Jul 10th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.79 KB | None | 0 0
  1. #!/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my %ERROR_MESSAGES;
  6. $ERROR_MESSAGES{"invalid_stack_type"} = "invalid stack type. Only 7 and 17 are allowed, atm\n";
  7.  
  8. # cli parameters
  9. my $gosub_offset;
  10. my $stack_type;
  11. my $target_offset; # offset you want to start the target mission at
  12.  
  13. my $useful_code_size; # for name_thread, etc
  14. my $filler_code_size; # nops(0000) and alignment(FF05 FF)
  15.  
  16. my $filler_code;
  17. my $thread_name_code;
  18. my $gosub_code;
  19. my $wait_code;
  20.  
  21.  
  22. print STDERR "THREAD NAME STUFF IS FOR SA, ATM (rest is compatible with vc).\n";
  23.  
  24. ($stack_type, $gosub_offset) = stack_stuff();
  25. $target_offset = shift @ARGV;
  26.  
  27. $useful_code_size = 0;
  28. $wait_code = "wait 0";
  29. $useful_code_size += 4;
  30.  
  31. $gosub_code = "gosub \@loop\n:loop";
  32. $useful_code_size += 7;
  33.  
  34. $thread_name_code = "03A4: 'perfect'";
  35. $useful_code_size += 11;
  36.  
  37.  
  38. $filler_code_size = $target_offset - $useful_code_size;
  39. if( $filler_code_size % 2 == 1 ) {
  40.     # needs alignment
  41.     $filler_code = "9905 FF " . "00" x ($filler_code_size - 3);
  42. }else{
  43.     $filler_code = "00" x $filler_code_size;
  44. }
  45.  
  46.  
  47. #################
  48. #Finally ;), print the code
  49. #################
  50. if( $stack_type eq "name_thread" ) {
  51.     print "$thread_name_code\n";
  52.     print "$gosub_code\n";
  53. }elsif( $stack_type eq "immediate" ) {
  54.     print "$gosub_code\n";
  55.     print "$thread_name_code\n";
  56. }else{
  57.     die $ERROR_MESSAGES{"invalid_stack_type"};
  58. }
  59. print "
  60. hex
  61. $filler_code
  62. end
  63.  
  64. $wait_code
  65. jump \@loop
  66. ";
  67.  
  68.  
  69.  
  70.  
  71.  
  72. sub stack_stuff {
  73.     if(@ARGV == 2) {
  74.         $gosub_offset = shift @ARGV;
  75.         if($gosub_offset == 7) {
  76.             $stack_type = "immediate";
  77.         }elsif($gosub_offset == 17) {
  78.             $stack_type = "name_thread";
  79.         }else{
  80.             die $ERROR_MESSAGES{"invalid_stack_type"};
  81.         }
  82.     }else{
  83.         $stack_type = "name_thread";
  84.         $gosub_offset = 17;
  85.     }
  86.     return ($stack_type, $gosub_offset);
  87. }
Add Comment
Please, Sign In to add comment