We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › cannot find combination from binary code
Page Index Toggle Pages: 1
cannot find combination from binary code (Read 2105 times)
cannot find combination from binary code
Nov 16th, 2009, 3:36pm
 
I have a document where i have to rename a lot of things.
Atm i got names like:
A.1
A.2
A.3
~
A.100

If i open it in notepad then the things i want to rename are:
čA.1
ĺ
čA.2ĺ
čA.3ĺ
~
čA.100
ĺ

surrounded by other chars..
What i want to do is check every byte to see if it's an 'č'.
If it is I want to check the next byte to see if it's an 'A'.
I can find the 'č' but i never can find a situation where a 'A' follows?
Someone has a idea how that becomes?


Code:
char find = 'A';
char replace = 'B';

int ic = 0;//initial count

byte b[] = loadBytes("slices_t_A.vfb");
byte[] output = new byte[b.length];

for (int i = 0; i < b.length; i++) {
if(b[i] == -24){
println(char(b[i]));// č like it supposed to
println(b[i+1]+" "+char(b[i+1]));// never a 'A'
if(b[i+1] == byte(find)){// no results
println(ic);
ic ++;
}
}
output[i] = b[i];
}

saveBytes("slices_t_B.vfb", output);


////čA.20
ĺ

//č -24
//A 65
//. 46
//2 50
//0 48
//
ĺ -27
Re: cannot find combination from binary code
Reply #1 - Nov 16th, 2009, 4:13pm
 
Well, .vfb files seems to be Outlook free/busy files (there are other formats using this extension but this one seems to be a good candidate).
Knowing Microsoft, I suppose it is a proprietary, binary format.
Tampering with such data is often a bad idea...
Now, if you just want to replace a letter with another, it should be pretty safe.

But we need more information than given with a cursory look with a calamitous text editor that probably hides controls chars... I suggest you look at your file with a good hex editor (there are lot of free ones, my current favorite is HxD) so you can be sure of what is before your A.
Re: cannot find combination from binary code
Reply #2 - Nov 17th, 2009, 2:47am
 
It's a fontlab format for a font aplication.
I tried HxD for mac but it's so old that it won't run on intel machines.
Also i tried hex editor, but i don't understand it, here a screen:

...

Does someone know a good hex editor for mac?

Here is the file, maybe it helps
http://xyz.lockecole.ath.cx/temp/slices_t_A.vfb

it's not about:
Code:
sub A by A.1;
sub A A' by A.2;
sub A A A' by A.3;
sub A A A A' by A.4;
sub A A A A A' by A.5;
sub A A A A A A' by A.6;
sub A A A A A A A' by A.7;
sub A A A A A A A A' by A.8;
sub A A A A A A A A A' by A.9;
sub A A A A A A A A A A' by A.10;


but it's about the A.# that comes after the big list that looks like čA.1ĺ in my notepad for example.

hope you can help
Re: cannot find combination from binary code
Reply #3 - Nov 17th, 2009, 5:18am
 
I was confused. You mentioned Notepad, I thought you were on Windows, hence the (wrong) deductions... Although most of my answer still applies!

Indeed, VFB as font file seems to be the second main choice for this extension.

Just out of curiosity, what does this change will do

Curiously, the fragment you show looks like plain text. Your hex editor looks fine.
Ah, I just noticed you give a link to such file. Good idea. So it is mostly binary, indeed.
Perhaps your text editor believes it is UTF-8 data and tries to make characters out of random bytes...

If I search A.100 I find it preceded by 0x07 0x01 0x01 0x90
A.3 is preceded by 0x07 0x01 0x01 0x8F. Same for A.3n (31, 32, etc.). Same for A.4n. Same for A.1n except A.1 which is preceded by 0x07 0x01 0x01 0x8E

Looks like there is a scheme, but a slightly variable one...
In this file (not sure about other files), the schema seems to be a sequence of 01 09 07 01 01 then a semi-random byte then A.nnn (1 to 3 n) then 08 8C FF 00 00 etc.
Re: cannot find combination from binary code
Reply #4 - Nov 17th, 2009, 9:14am
 
Sorry i ment teksteditor.

I'm create a special font where eah character has 100 versions (maybe 200 or more if possible).
The difference between [A.1 - A.100] and the [B.1 - B.100] is that the B version is 13degrees rotated. This rotation can be done in fontlab with an action where i can choose to apply it on the entire font (it's rotating all or just 1, no other options).

Here a screen of fontlab with empty characters since i just wanted to show u quick:
...

As you can see here are the names but in order to rename them i have to rename them 1 by 1. So let's say 2600 renames, quite a shitty job.

That's why i want to load the bytes in processing, make the name adjustments and save those bytes. I believe teksteditor opens it as 'Western (mac os roman)' cause it shows that when i try to save it.
If i try to open it as a UTF-8 data in tekstedit then i get an error telling me it's probably something else. There is no hex option, only asci but that doesnt work.

I don't know what to do with the 0x07 etc, cause processing doesnt show it like that.

How can i continue?
Re: cannot find combination from binary code
Reply #5 - Nov 17th, 2009, 12:35pm
 
Well, if that's useful, I just used HxD's replace feature to change all A. to B. after the first text part. You can find the file at http://filebin.ca/grkxdu/slices_t_B.vfb
I found that faster than coding the sketch... Smiley

But if you need to do that regularly, you will need the code.

Quote:
cause processing doesnt show it like that

Number representation is what you ask Processing to show...
Re: cannot find combination from binary code
Reply #6 - Nov 17th, 2009, 1:50pm
 
thx a lot for the file

only i need to do it regulary so i will need to code.
(and it helps improving my coding skills).

Quote:
Number representation is what you ask Processing to show...


how can i get that? (also with the x in it or isn't that necassary).
Re: cannot find combination from binary code
Reply #7 - Nov 18th, 2009, 9:30am
 
OK, here is the program, I tried to make it relatively flexible.
It is brittle as I rely on observation of one file only, not on file spec!
But well, since we create a copy, errors are not a major problem.
Code:
final byte find = (byte) 'A';
final byte replace = (byte) 'B';

final int minNameLength = 3; // Change if needed
final int maxNameLength = 10; // Increase as needed

// These bytes are found to be stable before a name in the given file:
// the signature can break in another file!
final byte[] sigBefore =
{
(byte) 0x01,
(byte) 0x09,
(byte) 0x07,
(byte) 0x01,
(byte) 0x01
};
final byte[] sigAfter =
{
(byte) 0x08,
(byte) 0x8C,
(byte) 0xFF,
(byte) 0x00,
(byte) 0x00
};

String currentName;

void setup()
{
byte[] originalBytes = loadBytes("slices_t_A.vfb");
byte[] alteredBytes = Arrays.copyOf(originalBytes, originalBytes.length);

int maxPos = originalBytes.length - sigBefore.length - 1 - maxNameLength - sigAfter.length;

for (int i = 0; i < maxPos; i++)
{
if (CheckSignature(originalBytes, i, sigBefore))
{
i += sigBefore.length + 1; // Skip the variable byte...
if (originalBytes[i] == find)
{
int found = i;
i += GetName(originalBytes, i, sigAfter);
boolean bChange = i - found >= minNameLength;
if (bChange)
{
alteredBytes[found] = replace;
}
println(hex(found) + " " + currentName + (bChange ? "" : " (skipped)"));
}
}
}

saveBytes("slices_t_B.vfb", alteredBytes);

exit();
}

boolean CheckSignature(byte[] buffer, int offset, byte[] signature)
{
for (int i = 0, o = offset; i < signature.length; i++, o++)
{
if (signature[i] != buffer[o])
return false;
}
return true;
}

// Only for debug/verification purpose
int GetName(byte[] buffer, int offset, byte[] signature)
{
int i = 0;
StringBuilder name = new StringBuilder();
while (i < maxNameLength)
{
if (buffer[offset + i] == signature[0])
{
if (CheckSignature(buffer, offset + i, signature))
{
// Found
currentName = name.toString();
return i;
}
}
else
{
name.append((char) buffer[offset + i]);
}
i++;
}
currentName = "!!!";
return 0;
}
Re: cannot find combination from binary code
Reply #8 - Nov 18th, 2009, 9:39am
 
thank you so much!!!!
It works perfect, how long does this take for you to code?
And how many years experience do you have?

If processing ever gets a donation fuction then you should earn a part aswell, your helping so many people!
Re: cannot find combination from binary code
Reply #9 - Nov 18th, 2009, 10:18am
 
I don't know, perhaps half an hour, with testing and small improvements.
I program since I am 18, more or less, so that's some 30 years of programming... Smiley
And well, for those feeling generous (entirely optional!), I have an Amazon wish list on my site (look at English part)... :-P It has mostly programming books...
I got a number of books from generous people I helped in the past.
Re: cannot find combination from binary code
Reply #10 - Nov 18th, 2009, 5:59pm
 
It's 2.55 am right now and i'm kinda tired so i will check the amazon asap, you meight get lucky if there is something not to expencive (i'm a student Smiley ).

I prepered the file where i needed it to work on but it doesnt work anymore. Sad
Everything gets skipped.

I uploaded the new file in the hope you can fix it one more time
http://xyz.lockecole.ath.cx/temp/SL_A.vfb

Re: cannot find combination from binary code
Reply #11 - Nov 19th, 2009, 1:08am
 
Don't worry, I have put cheaper items in my list on purpose: I am not wealthy myself, so I don't ask anything (but appreciate gestures Smiley).

As I feared, the signature has changed. I was looking too deep after the name. Just change this:
Code:
final byte[] sigAfter  =
{
 (byte) 0x08,
 (byte) 0x8C
};
and it will work (for this file...). Thanks for the magic of avoiding hard-coded numbers as much as possible... Cool
Re: cannot find combination from binary code
Reply #12 - Nov 20th, 2009, 6:52am
 
haha 'wish list' seems to be the only english on your site Smiley
Where do you live? cause i tried to buy you something but it couldn't be shipped to your adress or whatever the error was.

Thx to you i was able to make this font:
On the left i typed A to Z and then AA BB CC to ZZ and then AAA BBB to ZZZ. On the right it's just some text, you can see good how the 'e' is the most frequent letter.

...
Re: cannot find combination from binary code
Reply #13 - Nov 20th, 2009, 8:12am
 
Cool application of your fonts!

clankill3r wrote on Nov 20th, 2009, 6:52am:
haha 'wish list' seems to be the only english on your site Smiley

I plan to redo the home page back to bi-lingual version, or to auto-detect language of visitor. Currently, you have to click on the little flags on top-right corner of the home page to get the English version, which is, as you shown, less than obvious. I fear it drives most visitors away.
Note that the Amazon Wish List of the English version is different from the one in the French version! Smiley They don't ship hardware stuff (even an USB key!) but they ship books.
Thanks for trying...  Roll Eyes
Page Index Toggle Pages: 1