What parsing of the block do you require?Quote:
Now, I only need to add the function of process that will parse each block within the while loop rigth?
I'd like to parse each block using regex.
Printable View
What parsing of the block do you require?Quote:
Now, I only need to add the function of process that will parse each block within the while loop rigth?
I'd like to parse each block using regex.
Hello AceInfinity,
Thanks for try to help me too. I'll test your code either.
Hello 2kaud,
For each block I'd like first to extract some patterns with 2 regex below.
Regex1: (.{6,18})(532064[^f]*).(814[^f]*)
Regex2: ff79(0080.{4}c906)?.*?05(9.{32,34}.*?)940e(.{28})
Regex1 matches string in red
Regex2 matches string in blue
Regex1 works to extract data from the beginning of the block, for block 2 Regex1 would get:Code:00000253206445018934551f81474554768fffff0015000a4800015a00024200016000013300013600013700015b00016600
016500017700017800017e00016900006a00007900009300012200002100010900010a001260001020001040001050001060
0011000010800012b00002c00012d00012e00015500015600072a00002f0000300000310000ff7900800932c90688888000a
000800935c90600008000000080093cc90688888000000800943c90688888000800005900f0102000000308147526905ffff
ff00910f01020000013a81475269559fffff009310010c0000009f8147526905ffffff0101960f010e000000eb8147526959
6fffff00970f0100006f69981475269563fffff00940e0001000001000100ffff0000010195060003790001ea05820037060
10000010065000000020000020018000000030000030017000000040000040001000000050000050015000000a00ffff0065
00000007802ec918009181475269539fffffff009181475269539fffff000103ca030808fecb0a00000000000000000000cc
0101811bc90b009181475269567fffffffca06000000000000cb0103cc0101
but since I'm grouping with backreference, this string would be splitted like thisCode:00000253206445018934551f81474554768
to finally treat as hex the first group and print as decimal, leaving group 2 and group 3 without change as below.Code:000002,53206445018934551,81474554768
For Regex2, I'm using backreference too, since I only want to extract the group 2 and 3 from Regex2. But theCode:2,53206445018934551,81474554768
parsing of string got from Regex 2 is more complicated. So, Initially I'd like to know how to apply regex on each
block.
Many thanks for the help
regex is part of c++11
http://www.cplusplus.com/reference/regex/
Hello 2kaud,
Thanks for that.
I've tried to add <regex> header but I receive error. I've read that maybe with visual studio compiler could work.
I've downloaded and installed a visual C++ 2012 compiler version but I'm no able to make that works with netbeans nor Dev C++.
Does accepts for you the regex header? Which IDE and compiler are you using?
Thanks in advance
I'm using VS 2013 and am able to use the <regex> header with this setup. Dev C++ is old (assuming you're using bloodshed's, and not orwells), and if so, you should abandon it.
Thanks for the answer.
I'm testing with netbeans and Orwells Dev C++.
Since MSVS is payed, do you know another IDE or compiler that let me use regex?
Thanks again
Hello Ace
I've installed MSVS 2013 and I've been trying to test regex using the example for the below page, bu I get errors when
compile.
http://en.cppreference.com/w/cpp/reg...ax_option_type
I'm not sure why, I did this: New project --> Visual C++-->CLR-->CLR Console Application.
CLR, why do you want that? Try "Win32 Project" instead. What errors are you getting? You just posted a reference link, but nothing that describes the errors.
gcc is free and is c++11 compliantQuote:
Since MSVS is payed, do you know another IDE or compiler that let me use regex?
http://gcc.gnu.org/
(see top of news left hand side regarding support for regex!)
Hello 2kaud
I've been searching and it seems gcc doesn't support yet regex :(. It seems only basic things.
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/onlinedocs/libstd...tatus.iso.200x
I found that clang is full C++11, but it seems it works for linux. I'll continue searching.
Hello 2kaud again,
I see that each block is printed in the for loop using "display(bv)", but I'd like to store in a single string each block
to be able to process it. I'd like to modificate the display function in order to have in a string each block, something like
below but I don't know how would be the correct way and how to retrieve that string in main function.
I hopw you can help me with this.Code:void display(const bVec bv)
{
for (int i = 0; i < bv.size(); i++)
//cout << setw(2) << setfill('0') << hex << (int)bv[i];
Block= Block + (int)bv[i];
}
Thanks in advance.
bv is a vector of BYTE (unsigned char) that can be processed. If you want a string of hex equivalent then one way is
Code:void display(const bVec& bv)
{
for (int i = 0; i < bv.size(); i++)
cout << setw(2) << setfill('0') << hex << (int)bv[i];
cout << endl << endl;
}
void conString(const bVec& bv, string& block)
{
ostringstream ss;
for (int i = 0; i < bv.size(); i++)
ss << setw(2) << setfill('0') << hex << (int)bv[i];
block = ss.str();
}
int main()
{
FileFields ff;
bVec bv;
int blk = 0;
string block;
if (!ff.open("binary.txt")) {
cout << "Cannot open file!" << endl;
return 1;
}
while (ff.getField(bv)) {
cout << "block " << blk++ << endl;
//display(bv);
conString(bv, block);
cout << block << endl << endl;
}
return 0;
}
Hello 2kaud,
Thanks for your help. Ive tried but in compilation I get the error:
I've added "std::" but the same error.Code:[Error] aggregate 'std::ostringstream ss' has incomplete type and cannot be defined