Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I process opcodes stored in a binary file in Perl?
    primarykey
    data
    text
    <p><em><a href="http://packetstormsecurity.org/files/105938/Abstract-Processor.pdf" rel="nofollow">Creating Your Own Abstract Processor</a></em> is a quick paper on what I am trying to do.</p> <p><a href="http://malcon.org/ctm.rar" rel="nofollow">http://malcon.org/ctm.rar</a> is the exact specifications on what the emulator should be.</p> <p>I am writing a sort of an emulator in Perl. This program will read in a binary file and process the hex of the binary into actions, how a processor works, but software based with different opcodes. Just a challenge thing.</p> <p>Anyhow, I am not entirely sure how to read the binary file into an array and then assign the hex from the array to the opcodes. This is part of my code:</p> <pre><code>my $opcode=''; my $file= "path/to/file"; my $IP=0; my $SP=0; my $FLAG=0; my $A=0; my $B=0; my $X=0; my @STACK=(0); open(F, "&lt;".$file) || die("Could not open file"); binmode(F); my @ROM = &lt;F&gt;; close(F); while($IP &gt;= 0) { $opcode="$ROM[$IP]"; if ($opcode eq 11) { $A = $STACK[$SP]; $IP++; } if ($opcode eq 12) { $B = $STACK[$SP]; $IP++; } if ($opcode eq 13) { $A = $B; $IP++; } if ($opcode eq 14) { $B = $A; $IP++; } </code></pre> <p>This is just the part of the code I need help with. If you need to see more of it for some reason, just let me know.</p> <p>So I changed my code to reflect an answer above, my code now looks like this:</p> <pre><code>my $opcode=''; my $file= "CTM-bootrom"; my $IP=0; my $SP=0; my $FLAG=0; my $A=0; my $B=0; my $X=0; my @STACK=(0); open my $ROM, '&lt;:raw', $file or die "Cannot open '$file': $!"; { local $/ = \1; # Read one byte at a time while (my $byte = &lt;$ROM&gt;){ while($IP &gt;= 0) { $opcode=$ROM[$IP]; if ($opcode eq 11) { $A = $STACK[$SP]; $IP++; } if ($opcode eq 12) { $B = $STACK[$SP]; $IP++; } if ($opcode eq 13) { $A = $B; $IP++; } </code></pre> <p>But now I get an error:</p> <blockquote> <p>Use of uninitialized value $opcode in string eq at Aod8.pl line 73,</p> </blockquote> <p>&lt;$ROM> to me it looks like opcode is initialized... How can I fix this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload