I'm trying to convert Delphi code to vb.net and I'm not sure about this line:
stream.Seek($42, soFromBeginning);
I'm familiar with using seek on filestreams (in vb.net) but I'm not sure about the $42.
I'm assuming that corresponds to a position, but how does that translate to vb.net?
$ is the prefix for a hexadecimal constant. In VB.NET, that's &H, so you would write &H42.
The code required for VB.net is almost identical:
stream.Seek(&H42, SeekOrigin.Begin)
The points of note here are:
$ in Delphi is the prefix for hexadecimal.
The soFromBeginning corresponds to SeekOrigin.Begin.
The $42 value is the offset from the beginning of the stream.
In VB.NET that would be :
reader.BaseStream.Seek(66, IO.SeekOrigin.Begin)
Related
I had a program with code conversion VB6 (on WinXP 32bit) which sends command to RS232 radio modem.
I rewrite the code into VB.NET (WinX 64bit) but the output string to serial port is different.
For example:
VB6 code:
Chr$(193)
Output is:
VB.NET code:
Convert.ToChar(193)
Output is:
I think this has something to do with character tables but cannot find any solution
Thanks for any info
According to this link from Microsoft, Convert.toChar(...) does this:
Converts the value of the specified object to a Unicode character.
My guess is you're getting a unicode, since instead of C1, you're getting C3 81 (Unicode can take 1-4 bytes per char). Perhaps something like this answer would help:
((char)0x00C1).ToString();
I have made a program which takes a 1000 digit number as input.
It is fixed, so I put this input into the code file itself.
I would obviously be storing it as Integer type, but how do I do it?
I have tried the program by having 1000 digits in the same line. I know this is the worst possible code format! But it works.
How can assign the variable this number, and split its lines. I read somewhere something about eos? Ruby, end of what?
I was thinking that something similar to comments could be used here.
Help will be appreciated.
the basic idea is to make this work:
a=3847981438917489137897491412341234
983745893289572395725258923745897232
instead of something like this:
a=3847981438917489137897491412341234983745893289572395725258923745897232
Haskell doesn't have a way to split (non-String) literals across multiple lines. Since Strings are an exception, we can shoehorn in other literals by parsing a multiline String:
v = read
"32456\
\23857\
\23545" :: Integer
Alternately, you can use list syntax if you think it's prettier:
v = read . concat $
["32456"
,"24357"
,"23476"
] :: Integer
The price you pay for this is that some work will be done (once) at runtime, namely, the parsing (e.g. read).
I am trying out a classic format string vulnerability. I want to know how exactly the following format string works:
"%NNN$hhn" where 'N' is any number.
E.g: printf("%144$hhn",....);
How does it work and how do I use this to overwrite any address I want with arbitrary value?
Thanks and Regards,
Hrishikesh Murali
It's a POSIX extension (not found in C99) which will simply allow you to select which argument from the argument list to use for the source of the data.
With regular printf, each % format specifier grabs the current argument from the list and advances the "pointer" to the next one. That means if you want to print a single value in two different ways, you need something like:
printf ("%c %d\n", chVal, chVal);
By using positional specifiers, you can do this as:
printf ("%1$c %1$d\n", chVal);
because both format strings will use the first argument as their source.
Another example on the wikipedia page is:
printf ("%2$d %2$#x; %1$d %1$#x",16,17);
which will give you the output:
17 0x11; 16 0x10
It basically allows you to disconnect the order of the format specifiers from the provided values, letting you bounce around the argument list in any way you want, using the values over and over again, in any arbitrary order.
Now whether you can use this as an user attack vector, I'm doubtful, since it only adds a means for the programmer to change the source of the data, not where the data is sent to.
It's no less secure than the regular style printf and I can see no real vulnerabilities unless you have the power to change the format string somehow. But, if you could do that, the regular printf would also be wide open to abuse.
I'm trying to, given a unicode character, find out the "CharCode" for that char.
What is the opposite of ChrW in vb.net (or other code which doesnt bruteforce it)?
You need AscW - documentation here.
I've made some good progress with my first attempt at a program, but have hit another road block. I'm taking standard output (as a string) froma console CMD window (results of dsquery piped to dsget) and have found small rectangles in the output. I tried using Regex to clean the little bastards but it seems they are related to the _ (underscore), which I need to keep (to return 2000/NT logins). Odd thing is - when I copy the caharcter and paste it into VS2K10 Express it acts like a carrige return??
Any ideas on finding out what these little SOB's are -- and how to remove them?
Going to try using /U or /A CMD switch next..
The square is often just used whenever a character is not displayable. The character could very well be a CR. You can use a Regular Expression to just get normal characters or remove the CR LF characters using string.replace.
You mentioned that you are using the string.replace function, and I am wondering if you are replacing the wrong character or something like that. If all your trying to do is remove a carriage return I would skip the regular expressions and stick with the string.replace.
Something like this should work...
strInputString = strInputString.replace(chr(13), "")
If not could you post a line or two of code.
On a side note, this might give some other examples....
Character replacement in strings in VB.NET