I have a file that I am trying to find some items in.
Here is an example extract:
68 65 6C 6C 6F 20 77 6F 72 6C 64 20 68 6F 77 20 61 72 65 20 79 6F 75 20 68 65 6C 6C 6F 20 77 6F 72 6C 64
In my editor it shows up as:
hello world how are you hello world
I used Ctrl + f to bring up Find.
I entered what I was looking for (hello) in Search for and pressed Search. The first result shows up, but my file contains multiple results as you can see above. How do I move to the next result?
I.e. from the first hello, to the second.
For the version of HxD I am using (1.7.7.0), this function is bound to F3. To search in the reverse direction, press Shift+F3.
Alternatively, both options are selectable under 'Search' located on the menu bar.
Related
I want to add a new column with blank fields in my existing CSV data.
My current code is like this:
Dim data As IEnumerable(Of String) =
File.ReadLines(filename,Encoding.GetEncoding("iso-8859-1")).
Select(Function(line, index)
If index = 0 Then
Return "new_column," & line
Else
Return "," & line
End If
End Function)
File.WriteAllLines(savePath, data)
The problem is that "new_column" is being added on the line breaks. So, what I did is to open the CSV file in Excel and used the following steps:
Ctrl + H to open up the Find and Replace dialog box.
On the Find What text box, I used Ctrl + J to enter a line break character. I followed the instructions here
I tried using ReadAllText but the rows are not in the correct order after writing it.
Is there an alternate same way to what I am doing with Excel in VB.NET?
With a CSV file saved from Excel, if there is a line break in a cell then the cell value will be surrounded with double-quotes and the line break is represented by a Chr(10).
For example,
saved as a CSV file and opened in a hex editor gives (note: 10 decimal = 0A hexadecimal)
43 6F 6C 20 41 2C 43 6F 6C 20 42 2C 22 4C 69 6E Col A,Col B,"Lin
65 0A 62 72 65 61 6B 22 2C 43 6F 6C 20 44 0D 0A e·break",Col D··
So you need something which will regard a line break inside a double-quoted string as not being a new line.
The TextFieldParser can be configured to do that by setting the .HasFieldsEnclosedInQuotes property to True.
For example, with the above data,
Option Infer On
Option Strict On
Imports System.IO
Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic.FileIO
Module Module1
Sub Main()
Dim src = "C:\temp\Book1.csv"
Dim dest = "C:\temp\newColumn.csv"
Using tfp As New TextFieldParser(src)
tfp.HasFieldsEnclosedInQuotes = True
tfp.Delimiters = {","}
Dim re As New Regex("[,\n]")
Using sw As New StreamWriter(dest, False, Text.Encoding.GetEncoding("iso-8859-1"))
While Not tfp.EndOfData
Dim thisLine = tfp.ReadFields()
sw.WriteLine("new_column," & String.Join(",", thisLine.Select(Function(p) If(re.IsMatch(p), Chr(34) & p & Chr(34), p))))
End While
End Using
End Using
End Sub
End Module
generates
6E 65 77 5F 63 6F 6C 75 6D 6E 2C 43 6F 6C 20 41 new_column,Col A
2C 43 6F 6C 20 42 2C 22 4C 69 6E 65 0A 62 72 65 ,Col B,"Line·bre
61 6B 22 2C 43 6F 6C 20 44 0D 0A ak",Col D··
Which can be opened in Excel to give:
You may need to make it more robust than putting double-quotes around only entries with a Chr(10), for example entries with a comma in need the delimiters too.
I wrote it to also delimit fields with commas, although that isn't shown in the example data.
Of course, once you have the individual entries from a line in the array thisLine, you could replace the Chr(10) with a space, if desired.
Am I doing something wrong or is this a bug?
When using
var checkSum = crypto.createHash("sha256").update(scriptInnerHTML, "utf-8").digest("base64")
To generate the sha256 for this script tag:
<script>
console.warn("works");
var some code ...
</script>
And using it inside a Content-Security-Policy like this:
<meta http-equiv="Content-Security-Policy" content="script-src 'sha256-8O+YTKIDgMhMvSanTZx1Om5XY2ERB+kIxN8AcO2r6Ok='">
Things works as it should, but however this one, identical except without the warning-log, doesn't work. Notice the couple of new-lines and a tab before the code.
<script>
var some code ...
</script>
It seems as Node interprets tabs (or rather newlines+tab) differently if there is text afterwards. Weird!
Tested both in Safari and Chrome so it should not be a browser issue.
Updates:
I of-course re-generate the hash for each input.
Examples:
(The script tag is at the bottom)
Working hash ('sha256-5++3ItSu+9maCZiuuXH60RG7EugmibMmhxhwpsynAn0='): http://aggressive.se/test/works.html
Not working hash ('sha256-hIRDHGUSaEmjNiVhNabY+8l4GNQdj/PXD4XHA21gdRM='): http://aggressive.se/test/fail.html
SOLVED:
The problem was due to the serialize() function in JSDom which I use to generate the HTML in node. Calling dom.serialize() after calculating the hash, it removed one unnecessary tab which changed the source (in a hard to notice way).
But just so you know, the problem was not due to node nor the crypto module. (Hope someone has use for this)
I am not sure how you obtained the scriptInnerHTML variable, but if I access the innerHTML property of the script of interest in the fail.html example, I get this hexdump:
00000000 0a 0a 0a 09 76 61 72 20 6c 61 79 6f 75 74 20 3d |....var layout =|
00000010 20 6e 65 77 20 41 67 67 72 65 73 73 69 76 65 4c | new AggressiveL|
00000020 61 79 6f 75 74 28 29 3b 0a 09 41 67 67 72 65 73 |ayout();..Aggres|
00000030 73 69 76 65 4c 61 79 6f 75 74 2e 70 72 6f 74 6f |siveLayout.proto|
00000040 74 79 70 65 2e 73 65 74 75 70 46 75 6e 63 74 69 |type.setupFuncti|
00000050 6f 6e 20 3d 20 66 75 6e 63 74 69 6f 6e 28 29 0a |on = function().|
00000060 09 7b 0a 09 09 76 61 72 20 65 6c 65 6d 65 6e 74 |.{...var element|
00000070 20 3d 20 64 6f 63 75 6d 65 6e 74 2e 63 72 65 61 | = document.crea|
00000080 74 65 45 6c 65 6d 65 6e 74 28 22 64 69 76 22 29 |teElement("div")|
00000090 3b 0a 09 09 65 6c 65 6d 65 6e 74 2e 69 6e 6e 65 |;...element.inne|
000000a0 72 48 54 4d 4c 20 3d 20 22 49 74 20 77 6f 72 6b |rHTML = "It work|
000000b0 73 22 3b 0a 09 09 74 68 69 73 2e 65 6c 65 6d 65 |s";...this.eleme|
000000c0 6e 74 73 2e 72 6f 6f 74 45 6c 65 6d 65 6e 74 2e |nts.rootElement.|
000000d0 61 70 70 65 6e 64 43 68 69 6c 64 28 65 6c 65 6d |appendChild(elem|
000000e0 65 6e 74 29 0a 09 7d 0a |ent)..}.|
the corresponding hash of which is bR9Os+NBLWNZ3/wFVRhBilP05u9OeSj0ABRo+T8QF+g=. If I use this hash in the html file, it seems to work...
An example with JSDOM:
const fs = require('fs');
const crypto = require('crypto');
const { JSDOM } = require('jsdom');
const dom = new JSDOM(fs.readFileSync('./fail.html'));
const data = dom.window.document.querySelector('head > script:last-child').innerHTML;
console.log(crypto.createHash('sha256').update(data, 'utf-8').digest('base64'));
//bR9Os+NBLWNZ3/wFVRhBilP05u9OeSj0ABRo+T8QF+g=
I am getting a telnet response as showed below when tried with nodejs code. Actually it is in xml format. When I did directly call the telnet response, the correct xml format is delivering. Can someone plz help, why 'Buffer' response when calling via nodejs.
"Buffer 3c 6e 66 6c 2d 65 76 65 6e 74 3e 0d 0a 20 3c 67 61 6d 65 63 6f 64 65 20
3 6f 64 65 3d 22 32 30 31 37 31 31 33 30 30 30 36 22 20 67 6c 6f 62 61 6c 2d .. "
I am compiling a static site using node.js. I want to compile sass. I required node-sass and called: a.renderSync({data:"body{h1{color:green}}"}).css. This returned <SlowBuffer 62 6f 64 79 20 68 31 20 7b 0a 20 20 63 6f 6c 6f 72 3a 20 67 72 65 65 6e 3b 20 7d 0a>. What is a slowbuffer? I just want my CSS.
Thanks!
SlowBuffer has same methods like Buffer. So to get css string, just call toString():
a.renderSync({data:"body{h1{color:green}}"}).css.toString()
SlowBuffer is used when the buffer operations are passed to native C++ modules instead of JS. More about SlowBuffer is on the doc.
This is an example of my case function:
function SendToScreen(){
echo -e "$*"
}
So I call it by:
SendToScreen "Hello"
And, if I want to add color codes:
VioletForeGroundColor="\033[38;5;99m"
NormalColor="\033[0m"
SendToScreen "Hello"$VioletForeGroundColor" violet "$NormalColor" word."
That gives me a correct:
But the problem comes if I want to send some DOS-type path (including \ slash):
VioletForeGroundColor="\033[38;5;99m"
NormalColor="\033[0m"
MyDOSPath="d:\vivisector"
SendToScreen "Hello"$VioletForeGroundColor" violet "$NormalColor" word. The path is $MyDOSPath"
Because \v is some sort of ANSI code, so this time I obtain:
I need my function to output color text (bold, cursive, underline... etc), so I must use echo -e.
How could I solve the problem with such nagging control codes colliding characters like this \v (I suppose there will be another ones)?
I would like to repair the isssue by modifying the function, but I am not sure this is the proper method.
Thanks.
EDIT-1: We will choose \033 also known as \e as the only ANSI code that needs to remain.
New answer:
function SendToScreen() {
echo -e $(echo "${*//\\/\\\\}" | sed 's/\\\\033\[/\\033\[/g');
}
This one escapes everything, then un-escapes anything that looks like a color sequence (\033[). The possibility of sending filenames as color sequences is greatly reduced. You can reduce it even further by white-listing only those color sequences that you want to allow, and changing the sed command to a sequence of sed commands that un-escapes those exact sequences.
Old answer:
Let's say you want to escape \v and \n, you can do this:
function SendToScreen(){
a="${*//\\v/\\\\v}"
a="${a//\\n/\\\\n}"
echo -e "$a"
}
You can extend this with whatever other escapes you don't want to process.
The echo -e simply interprets sequences starting with backslash, so you simply need to ensure that the $MyDOSPath argument has all backslashes doubled up. That could be:
SendToScreen "Hello ${VioletForeGroundColor}violet${NormalColor} word." \
"The path is ${MyDOSPath//\\/\\\\}"
which uses a 'substitute' parameter expansion. The // means 'change every backslash to double backslash'.
As discussed in various comments, maybe the design of SendToScreen is sub-optimal. One possible alternative design uses:
SendToScreen [-e "string-to-expand"][-p "plain-string"] [-- "plain strings"]
Arguments that need to be expanded are, and those that should not be expanded are not. By default, they're not. So, example usage:
$ VioletForeGroundColor="\033[38;5;99m"
$ NormalColor="\033[0m"
$ MyDOSPath="C:\new\table\value\alert\form\033.txt"
$ echo "$MyDOSPath"
C:\new\table\value\alert\form\033.txt
$ bash SendToScreen.sh -e "${VioletForeGroundColor}violet${NormalColor}" -e "The path is ${MyDOSPath//\\/\\\\}" -p "Or $MyDOSPath" "Plain $MyDOSPath"
violet The path is C:\new\table\value\alert\form\033.txt Or C:\new\table\value\alert\form\033.txt Plain C:\new\table\value\alert\form\033.txt
$ bash SendToScreen.sh -e "${VioletForeGroundColor}violet${NormalColor}" -e "The path is ${MyDOSPath//\\/\\\\}" -p "Or $MyDOSPath" -e "Oops! $MyDOSPath" "Plain $MyDOSPath"
violet The path is C:\new\table\value\alert\form\033.txt Or C:\new\table\value\alert\form\033.txt Oops! C: ew able
aluelert
orm.txt Plain C:\new\table\value\alert\form\033.txt
$
A hex dump of the last lot of output was:
0x0000: 1B 5B 33 38 3B 35 3B 39 39 6D 76 69 6F 6C 65 74 .[38;5;99mviolet
0x0010: 1B 5B 30 6D 20 54 68 65 20 70 61 74 68 20 69 73 .[0m The path is
0x0020: 20 43 3A 5C 6E 65 77 5C 74 61 62 6C 65 5C 76 61 C:\new\table\va
0x0030: 6C 75 65 5C 61 6C 65 72 74 5C 66 6F 72 6D 5C 30 lue\alert\form\0
0x0040: 33 33 2E 74 78 74 20 4F 72 20 43 3A 5C 6E 65 77 33.txt Or C:\new
0x0050: 5C 74 61 62 6C 65 5C 76 61 6C 75 65 5C 61 6C 65 \table\value\ale
0x0060: 72 74 5C 66 6F 72 6D 5C 30 33 33 2E 74 78 74 20 rt\form\033.txt
0x0070: 4F 6F 70 73 21 20 43 3A 20 65 77 20 61 62 6C 65 Oops! C: ew able
0x0080: 0B 61 6C 75 65 07 6C 65 72 74 0C 6F 72 6D 1B 2E .alue.lert.orm..
0x0090: 74 78 74 20 50 6C 61 69 6E 20 43 3A 5C 6E 65 77 txt Plain C:\new
0x00A0: 5C 74 61 62 6C 65 5C 76 61 6C 75 65 5C 61 6C 65 \table\value\ale
0x00B0: 72 74 5C 66 6F 72 6D 5C 30 33 33 2E 74 78 74 0A rt\form\033.txt.
0x00C0:
You'll have to take my word for it that violet appeared in violet.
Clearly, the user (caller) of SendToScreen has to know which arguments should be expanded and which should not. However, it makes it very explicit.
Here's the code I used as a script. Repackaging as a function is left as an exercise for the reader. Extending it to add -c colour (or maybe -f foreground and -b background) is an exercise for the reader.
#!/bin/bash
output=()
while getopts "p:e:" opt
do
case "$opt" in
(e) output+=( $(echo -e "$OPTARG") );;
(p) output+=( "$OPTARG" );;
esac
done
shift $(($OPTIND - 1))
echo "${output[#]}" "$#"
Have fun!