Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Byte

I have a programm which makes from any Windows executable a prog.h dos C++ file. The file says:
static BYTE ala(for example) [26680(for example)] = {
When I want to compile it then I get syntax error in Borland C++.
I can't find anything about it in any book. Could somebody help me and tell how to compile a file which says like above? Thank you in advance.
[377 byte] By [stece] at [2007-11-11 7:32:45]
# 1 Re: Byte
typedef unsigned char BYTE is a common hack. The preferred types are now uint8_t (etc) which tell you how big they are. These are from the C99 standard I think?
jonnin at 2007-11-11 21:02:07 >
# 2 Re: Byte
yup, C99 (which is now simply called ANSI C) defines them in <inttypes.h>
Danny at 2007-11-11 21:03:12 >
# 3 Re: Byte
I have included <inttypes.h> in my file but it still says definition syntax error. I still don't know how to compile the file which says :
static BYTE ala [266283] = {
Please help me I don't know the proper syntax for BYTE and I can't find it anywhere.
stece at 2007-11-11 21:04:06 >
# 4 Re: Byte
One last time:
Programmers who don't know the language really well made either a macro or typedef to turn unsigned char into byte. Its just a rename.
jonnin at 2007-11-11 21:05:11 >
# 5 Re: Byte
You tell me very wise things but I still can't compile my file ( obtained for an application) which says:

static BYTE ala [266283] = {

I dont know this syntax and don't know what to put after "{". Please help me.
stece at 2007-11-11 21:06:15 >
# 6 Re: Byte
#define BYTE unsigned char

static BYTE ala...
jonnin at 2007-11-11 21:07:15 >
# 7 Re: Byte
My programm is like that :
#include <inttypes.h>
#include <iosteam.h>
#define BYTE unsigned char
static BYTE ala [266283] = {

I've got 2 errors in the last line, could somebody help me with the syntax of the last line. I don't know how to finish it and what should I put after "= {" in order to compile it successfuly. Thank you in advance.
stece at 2007-11-11 21:08:19 >
# 8 Re: Byte
This line will never compile, no matter how many #include and typedefs you add the program:
static BYTE ala [266283] = {

it's just a broken piece of code, which contains an incomplete initialization list of the array ala. To make the code compile, you can close this line as follows:
NOTICE: this doesn't mean that the code is accurate or that the program will run at all; you simply have to know more about the intent behind ala -- what its elements should contain and such.

//make the code compile
static BYTE ala [266283] = {0};
Danny at 2007-11-11 21:09:17 >
# 9 Re: Byte
OK I'll explain the whole problem. I have an application which :
This program allows you to include binary files into your C++ projects by storing it as an array of bytes. To use this data, just include the header file that is generated by Bin2C++ into your C++ program and make code that writes all of the bytes into a (temporary?) file (in binary mode offcourse).
After decompiling or executing that program I got something like this :
static BYTE ala [266283] = {
and I don't know how to make c++ executable from above line.
Thank you for great help I received so far.
stece at 2007-11-11 21:10:21 >
# 10 Re: Byte
Decompilers are terrible for C++. THAT is your problem -- the decompiler failed to make anything useful. Instead, you should just disassemble the program and work in native assembly code. Its a lot easier that way.

However, writing a binary file and storing the data in an array is trivial. If thats all you need to do, we can get you started.
jonnin at 2007-11-11 21:11:16 >
# 11 Re: Byte
Please tell me how to write a binary file which stores data in an array. The line of array is like this :

static BYTE ala [266283] = {

This is what I receive after running my application which is to include binary files in a new application. The binary is in array (I think so).
stece at 2007-11-11 21:12:15 >
# 12 Re: Byte
Simply change it to:
static char ala [266283];
or unsigned char, depending on what BYTE means. Anyway, as jonnin said (not in these words exactly) this decompiler has to be taken out and shot.
Danny at 2007-11-11 21:13:24 >
# 13 Re: Byte
Simple binary file IO (C, but hey, its late in the day)

#include <cstdlib>
FILE * fp;
fp = fopen("whatever.bin", "wb+");
fwrite(ala,1,266283,fp);
jonnin at 2007-11-11 21:14:20 >
# 14 Re: Byte
The decompiler is on :
http://server1.blueyellow.biz/~novanet/index.php?page=software&cat=util&software=Bin2C.txt
If anybody wishes to diagnose it please do. There is a screen shot too but the generated code contains a syntax which I asked about here. The programm is called Bin2c++.
stece at 2007-11-11 21:15:17 >
# 15 Re: Byte
OK I'll explain the whole problem. I have an application which :
This program allows you to include binary files into your C++ projects by storing it as an array of bytes. To use this data, just include the header file that is generated by Bin2C++ into your C++ program and make code that writes all of the bytes into a (temporary?) file (in binary mode offcourse).
After decompiling or executing that program I got something like this :
static BYTE ala [266283] = {
and I don't know how to make c++ executable from above line.
Thank you for great help I received so far.

So, Bin2C++ simply stopped reading (for some reason) your binary file and gave you an unusable header file. That line should have been followed by a list of byte-sized (8-bit integer) values.

Here's what Bin2C++ does (this is plain C code -- the real source is probably some fancy looking C++ code):

#include <stdio.h>
#include <io.h>

void main(){

FILE *fIn, *fOut;
unsigned char c;
long fSize;

if((fIn = fopen("binary_file", "rb")) != NULL){
if((fOut = fopen("prog.h", "wt")) != NULL){
fSize = _filelength(_fileno(fIn));
fprintf(fOut, "static unsigned char ala[%lu] = {", fSize);
if(fSize > 0L){
fread(&c, 1, 1, fIn);
fprintf(fOut, "%u", c);
while(!feof(fIn)){
fread(&c, 1, 1, fIn);
fprintf(fOut, ",%u", c);
}
}
fprintf(fOut, "}\n");
fclose(fOut);
}
fclose(fIn);
}
} /*main*/

In your case, it must have stopped right after the first fprintf.

I got this code to compile (using VC++ 6.0), I haven't run any tests on it. Feel free to use it (instead of Bin2C++) and change it any way you want.
VictorB at 2007-11-11 21:16:26 >