<div dir="ltr">These three programs print 12345679 when you pipe packinput to pack to packoutput as shown in the comment for packoutput.c.<br><br>/* packinput.c */<br>#include <unistd.h><br><br>int main(void)<br>{<br>
int i = 0x12345678;<br><br> return write(STDOUT_FILENO, &i, sizeof i) != sizeof i;<br>}<br><br>#! /opt/local/bin/perl -w<br># pack<br><br>use strict;<br><br>&go;<br><br>sub go {<br> # read "packed" binary data<br>
my $data = do { local $/; <STDIN> };<br> <br> my $i = unpack("i", $data);<br> print pack("i", $i + 1);<br>}<br><br>/* packoutput.c<br>(set -xe<br> for i in in out; do<br> gcc -Wall -W pack${i}put.c -o pack${i}put<br>
done<br>./packinput | ./pack | ./packoutput)<br> */<br>#include <stdio.h><br>#include <stdlib.h><br>#include <unistd.h><br><br>int main(void)<br>{<br> int i;<br><br> if (read(STDIN_FILENO, &i, sizeof i) == sizeof i)<br>
printf("%x\n", i);<br> else<br> exit(EXIT_FAILURE);<br> return 0;<br>}<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 15, 2013 at 9:32 AM, Geoffrey Myers <span dir="ltr"><<a href="mailto:lists@serioustechnology.com" target="_blank">lists@serioustechnology.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So I'm trying to modify a binary file with perl. All is going well except one issue. I need to change an integer value. I can successfully retrieve the value by using:<br>
<br>
unpack("S", $var);<br>
<br>
I assumed, incorrectly that I could do this to reset the value:<br>
<br>
pack("S", $newvar);<br>
<br>
Not working. Suggestions?<br>
<br>
--<br>