Re: How do I use chr inside a regex?
Hi, El sáb., 2 feb. 2019 a las 7:48, ToddAndMargo via perl6-users (< perl6-users@perl.org>) escribió: > Hi All, > > How do I use chr inside a regex. In the below, how > do I get rid of $y? > > $ p6 'my Str $x=chr(0x66)~chr(0x77); my Str $y=chr(0x66)~chr(0x77); > $x~~s/ $y /xy/; say $x;' > > If what you want to do is precisely what you are doing, you don't even need to use chr: my $x = "\x66\x77"; $x ~~ s/\x66\x77/xy/; say $x # OUTPUT: «xy» (See the document on quoting: https://docs.perl6.org/language/quoting#Interpolation:_qq) However, if what you want to do is what you _say_ you are doing, my $x = "\x66\x77"; $x ~~ s/$(chr(0x66)~chr(0x77))/xy/; say $x; # OUTPUT: «xy» $() interpolates within a regex, as indicated in the documentation: https://docs.perl6.org/language/regexes#index-entry-regex__Regex_Interpolation-Regex_interpolation Cheers JJ
How do I use chr inside a regex?
Hi All, How do I use chr inside a regex. In the below, how do I get rid of $y? $ p6 'my Str $x=chr(0x66)~chr(0x77); my Str $y=chr(0x66)~chr(0x77); $x~~s/ $y /xy/; say $x;' xy Many thanks, -T
Re: binary test and position?
On 2/1/19 8:26 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 8:07 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote: > On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users > wrote: >> >> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: >>> Hi All, >>> >>> On a type Buf, what do I use to check for the >>> position of a byte pattern? >>> >>> >>> Many thanks, >>> -T >> >> >> Basically, what am I doing wrong here? >> >> $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= >> $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 >> ) {say "y";} else {say "n"}; $handle.close;' >> Buf[uint8]:0x<4D 5A 90 00 03> >> (144 0 3) >> y >> >> >> I am testing to see if the pattern 0x90 0x00 0x04 exists, >> which is does not. On 2/1/19 7:57 PM, Brad Gilbert wrote: `eq` is string equality `==` is numeric equality a Buf is neither. You want `eqv` (equivalent) $b[2..4] eqv (0x90,0x00,0x04) That was it. Thank you! $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x03) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> y $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x04) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> n How do I find the position of a pattern in a Buf? Need `pos` for Buf Actually I do believe it is the binary equivalent of `index` I am looking for -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: binary test and position?
On 2/1/19 8:07 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote: > On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users > wrote: >> >> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: >>> Hi All, >>> >>> On a type Buf, what do I use to check for the >>> position of a byte pattern? >>> >>> >>> Many thanks, >>> -T >> >> >> Basically, what am I doing wrong here? >> >> $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= >> $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 >> ) {say "y";} else {say "n"}; $handle.close;' >> Buf[uint8]:0x<4D 5A 90 00 03> >> (144 0 3) >> y >> >> >> I am testing to see if the pattern 0x90 0x00 0x04 exists, >> which is does not. On 2/1/19 7:57 PM, Brad Gilbert wrote: `eq` is string equality `==` is numeric equality a Buf is neither. You want `eqv` (equivalent) $b[2..4] eqv (0x90,0x00,0x04) That was it. Thank you! $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x03) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> y $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x04) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> n How do I find the position of a pattern in a Buf? Need `pos` for Buf
Re: binary test and position?
On 2/1/19 8:03 PM, ToddAndMargo via perl6-users wrote: > On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users > wrote: >> >> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: >>> Hi All, >>> >>> On a type Buf, what do I use to check for the >>> position of a byte pattern? >>> >>> >>> Many thanks, >>> -T >> >> >> Basically, what am I doing wrong here? >> >> $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= >> $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 >> ) {say "y";} else {say "n"}; $handle.close;' >> Buf[uint8]:0x<4D 5A 90 00 03> >> (144 0 3) >> y >> >> >> I am testing to see if the pattern 0x90 0x00 0x04 exists, >> which is does not. On 2/1/19 7:57 PM, Brad Gilbert wrote: `eq` is string equality `==` is numeric equality a Buf is neither. You want `eqv` (equivalent) $b[2..4] eqv (0x90,0x00,0x04) That was it. Thank you! $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x03) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> y $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x04) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> n How do I find the position of a pattern in a Buf?
Re: binary test and position?
> On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users > wrote: >> >> On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: >>> Hi All, >>> >>> On a type Buf, what do I use to check for the >>> position of a byte pattern? >>> >>> >>> Many thanks, >>> -T >> >> >> Basically, what am I doing wrong here? >> >> $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= >> $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 >> ) {say "y";} else {say "n"}; $handle.close;' >> Buf[uint8]:0x<4D 5A 90 00 03> >> (144 0 3) >> y >> >> >> I am testing to see if the pattern 0x90 0x00 0x04 exists, >> which is does not. On 2/1/19 7:57 PM, Brad Gilbert wrote: `eq` is string equality `==` is numeric equality a Buf is neither. You want `eqv` (equivalent) $b[2..4] eqv (0x90,0x00,0x04) That was it. Thank you! $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x03) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> y $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] eqv (0x90,0x00,0x04) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> n -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: binary test and position?
`eq` is string equality `==` is numeric equality a Buf is neither. You want `eqv` (equivalent) $b[2..4] eqv (0x90,0x00,0x04) On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users wrote: > > On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: > > Hi All, > > > > On a type Buf, what do I use to check for the > > position of a byte pattern? > > > > > > Many thanks, > > -T > > > Basically, what am I doing wrong here? > > $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= > $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 > ) {say "y";} else {say "n"}; $handle.close;' > Buf[uint8]:0x<4D 5A 90 00 03> > (144 0 3) > y > > > I am testing to see if the pattern 0x90 0x00 0x04 exists, > which is does not.
Re: binary test and position?
On 2/1/19 7:37 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: Hi All, On a type Buf, what do I use to check for the position of a byte pattern? Many thanks, -T Basically, what am I doing wrong here? $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> (144 0 3) y I am testing to see if the pattern 0x90 0x00 0x04 exists, which is does not. Okya, no error now, but the WRONG answer: $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; if ( $b[2..4] == Buf.new(0x90,0x00,0x04) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> y -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: binary test and position?
> > On Fri, Feb 1, 2019 at 9:22 PM ToddAndMargo via perl6-users > wrote: >> >> Hi All, >> >> On a type Buf, what do I use to check for the >> position of a byte pattern? >> >> >> Many thanks, >> -T On 2/1/19 7:35 PM, Brad Gilbert wrote: This would work: my $b = Buf.new( 0,0,0, 1, 2, 0 ); my $match = Buf.new( 1, 2 ); $b.rotor( $match.elems => 1 - $match.elems ).grep(* eqv $match.List, :k) If you only need the first one, swap out `grep` for `first` Another iffy option is to decode it as latin1 $b.decode('latin1').index($match.decode('latin1')) I am trying to avoid decoding. match is giving me a fit about not being an Any: $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; say $b[2..4]; if ( $b.match( 0x90,0x00,0x04 ) ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> (144 0 3) Invocant of method 'match' must be a type object of type 'Any', not an object instance of type 'Buf[uint8]'. Did you forget a 'multi'? in block at -e line 1 -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: binary test and position?
On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: Hi All, On a type Buf, what do I use to check for the position of a byte pattern? Many thanks, -T Basically, what am I doing wrong here? $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq 0x90,0x00,0x04 ) {say "y";} else {say "n"}; $handle.close;' Buf[uint8]:0x<4D 5A 90 00 03> (144 0 3) y I am testing to see if the pattern 0x90 0x00 0x04 exists, which is does not.
Re: binary test and position?
This would work: my $b = Buf.new( 0,0,0, 1, 2, 0 ); my $match = Buf.new( 1, 2 ); $b.rotor( $match.elems => 1 - $match.elems ).grep(* eqv $match.List, :k) If you only need the first one, swap out `grep` for `first` Another iffy option is to decode it as latin1 $b.decode('latin1').index($match.decode('latin1')) On Fri, Feb 1, 2019 at 9:22 PM ToddAndMargo via perl6-users wrote: > > Hi All, > > On a type Buf, what do I use to check for the > position of a byte pattern? > > > Many thanks, > -T
binary test and position?
Hi All, On a type Buf, what do I use to check for the position of a byte pattern? Many thanks, -T
Re: filever.exe sub?
On 2/1/19 6:24 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 4:26 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 10:02 AM, Timo Paulssen wrote: On 01/02/2019 01:33, Bruce Gray wrote: To call those Windows APIs in Perl 6, you would use NativeCall. Don't forget that Todd wanted to use this on non-windows with not-wine. NativeCall on linux won't run windows code all by itself. That said, wine is still a good source for info on how windows things work internally (though of course they only reverse-engineered how windows things work, so there's often still differences in the exact behaviour). Here's their implementation of the version info code: https://source.winehq.org/git/wine.git/blob/908903b7f105c62061d62959fd8d8c866095dcdc:/dlls/version/info.c and the corresponding header file (i think?) https://source.winehq.org/git/wine.git/blob/c84b7d33dd18651057a80f609e11f809cc7f4bd0:/include/winver.h Normally I'd just say "good luck and have fun!", but that whole file is very big and doesn't seem very self-explanatory at all. I don't have time right now to go through it, but if you want to give understanding it a try, here's a link to wine's "cross-referenced source browser" thingie where most keywords are clickable so you can directly find other header files, or where and how symbols/types that are used in the code are defined: https://source.winehq.org/source/dlls/version/version.c Sorry for not giving a super simple solution. Perhaps there's something on the net for "PE metadata parser" or "PE file parser" or whatever. Hope that gets you closer to your goal! - Timo I am hopeless when it comes to C. I am still trying to figure out where the information is located in the exe Figured out one of my problems. Oe of the test exe I was using did not have a revision. If it has a revision, it will have the following: 001500E0 36 00 0B 00 01 00 46 00 69 00 6C 00 65 00 56 00 6.F.i.l.e.V. 001500F0 65 00 72 00 73 00 69 00 6F 00 6E 00 00 00 00 00 e.r.s.i.o.n. 00150100 37 00 2E 00 30 00 2E 00 38 00 30 00 30 00 2E 00 7...0...8.0.0... 00150110 31 00 35 00 00 00 00 00 3A 00 0D 00 01 00 46 00 1.5.:.F. 00 The revision is 7.0.800.15 Question: What is the best way to test for a series of bytes is a Buf? I want to find 46 00 69 00 6C 00 65 00 56 00 65 00 72 00 73 00 69 00 6F 00 6E The terminator is OD in the forth line. So I want everything after the above test up to OD
Re: filever.exe sub?
On 2/1/19 4:26 PM, ToddAndMargo via perl6-users wrote: On 2/1/19 10:02 AM, Timo Paulssen wrote: On 01/02/2019 01:33, Bruce Gray wrote: To call those Windows APIs in Perl 6, you would use NativeCall. Don't forget that Todd wanted to use this on non-windows with not-wine. NativeCall on linux won't run windows code all by itself. That said, wine is still a good source for info on how windows things work internally (though of course they only reverse-engineered how windows things work, so there's often still differences in the exact behaviour). Here's their implementation of the version info code: https://source.winehq.org/git/wine.git/blob/908903b7f105c62061d62959fd8d8c866095dcdc:/dlls/version/info.c and the corresponding header file (i think?) https://source.winehq.org/git/wine.git/blob/c84b7d33dd18651057a80f609e11f809cc7f4bd0:/include/winver.h Normally I'd just say "good luck and have fun!", but that whole file is very big and doesn't seem very self-explanatory at all. I don't have time right now to go through it, but if you want to give understanding it a try, here's a link to wine's "cross-referenced source browser" thingie where most keywords are clickable so you can directly find other header files, or where and how symbols/types that are used in the code are defined: https://source.winehq.org/source/dlls/version/version.c Sorry for not giving a super simple solution. Perhaps there's something on the net for "PE metadata parser" or "PE file parser" or whatever. Hope that gets you closer to your goal! - Timo I am hopeless when it comes to C. I am still trying to figure out where the information is located in the exe Figured out one of my problems. Oe of the test exe I was using did not have a revision. If it has a revision, it will have the following: 001500E0 36 00 0B 00 01 00 46 00 69 00 6C 00 65 00 56 00 6.F.i.l.e.V. 001500F0 65 00 72 00 73 00 69 00 6F 00 6E 00 00 00 00 00 e.r.s.i.o.n. 00150100 37 00 2E 00 30 00 2E 00 38 00 30 00 30 00 2E 00 7...0...8.0.0... 00150110 31 00 35 00 00 00 00 00 3A 00 0D 00 01 00 46 00 1.5.:.F. 00 The revision is 7.0.800.15 Question: What is the best way to test for a series of bytes is a Buf? I want to find 46 00 69 00 6C 00 65 00 56 00 65 00 72 00 73 00 69 00 6F 00 6E
Re: filever.exe sub?
On 2/1/19 10:02 AM, Timo Paulssen wrote: On 01/02/2019 01:33, Bruce Gray wrote: To call those Windows APIs in Perl 6, you would use NativeCall. Don't forget that Todd wanted to use this on non-windows with not-wine. NativeCall on linux won't run windows code all by itself. That said, wine is still a good source for info on how windows things work internally (though of course they only reverse-engineered how windows things work, so there's often still differences in the exact behaviour). Here's their implementation of the version info code: https://source.winehq.org/git/wine.git/blob/908903b7f105c62061d62959fd8d8c866095dcdc:/dlls/version/info.c and the corresponding header file (i think?) https://source.winehq.org/git/wine.git/blob/c84b7d33dd18651057a80f609e11f809cc7f4bd0:/include/winver.h Normally I'd just say "good luck and have fun!", but that whole file is very big and doesn't seem very self-explanatory at all. I don't have time right now to go through it, but if you want to give understanding it a try, here's a link to wine's "cross-referenced source browser" thingie where most keywords are clickable so you can directly find other header files, or where and how symbols/types that are used in the code are defined: https://source.winehq.org/source/dlls/version/version.c Sorry for not giving a super simple solution. Perhaps there's something on the net for "PE metadata parser" or "PE file parser" or whatever. Hope that gets you closer to your goal! - Timo I am hopeless when it comes to C. I am still trying to figure out where the information is located in the exe -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: filever.exe sub?
On 01/02/2019 01:33, Bruce Gray wrote: > To call those Windows APIs in Perl 6, you would use NativeCall. > Don't forget that Todd wanted to use this on non-windows with not-wine. NativeCall on linux won't run windows code all by itself. That said, wine is still a good source for info on how windows things work internally (though of course they only reverse-engineered how windows things work, so there's often still differences in the exact behaviour). Here's their implementation of the version info code: https://source.winehq.org/git/wine.git/blob/908903b7f105c62061d62959fd8d8c866095dcdc:/dlls/version/info.c and the corresponding header file (i think?) https://source.winehq.org/git/wine.git/blob/c84b7d33dd18651057a80f609e11f809cc7f4bd0:/include/winver.h Normally I'd just say "good luck and have fun!", but that whole file is very big and doesn't seem very self-explanatory at all. I don't have time right now to go through it, but if you want to give understanding it a try, here's a link to wine's "cross-referenced source browser" thingie where most keywords are clickable so you can directly find other header files, or where and how symbols/types that are used in the code are defined: https://source.winehq.org/source/dlls/version/version.c Sorry for not giving a super simple solution. Perhaps there's something on the net for "PE metadata parser" or "PE file parser" or whatever. Hope that gets you closer to your goal! - Timo