9 Replies - 5294 Views - Last Post: 12 July 2011 - 01:15 PM Rate Topic: -----

#1 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Removing Excess Null Characters

Posted 10 July 2011 - 08:53 PM

I have a hex dump with information I need read. Problem is there are way to many NULLs in the information. How would I go about ignoring the NULLs?

Quote

43 00 61 00 6c 00 6c 00 20 00 Lk..O.C. a.l.l. .

00000560 23 00 46 00 31 00 31 00 31 00 38 00 38 00 30 00 #.F.1.1. 1.8.8.0.

00000570 33 00 32 00 35 00 20 00 68 00 61 00 73 00 20 00 3.2.5. . h.a.s. .

00000580 62 00 65 00 65 00 6e 00 20 00 61 00 73 00 73 00 b.e.e.n. .a.s.s.

00000590 69 00 67 00 6e 00 65 00 64 00 20 00 20 00 20 00 i.g.n.e. d. . . .

000005A0 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . .

000005B0 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . .


Is This A Good Question/Topic? 0
  • +

Replies To: Removing Excess Null Characters

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Removing Excess Null Characters

Posted 10 July 2011 - 08:56 PM

You could put the hex dump into a character array, then loop through the array and push bytes into a vector<unsigned char>, skipping the bytes that are 0.
Was This Post Helpful? 0
  • +
  • -

#3 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Removing Excess Null Characters

Posted 10 July 2011 - 09:07 PM

sorry Im self taught so I will have to go do some research. Thank you for a least giving me an avenue to search.

Im also working in C if that matters.
Was This Post Helpful? 0
  • +
  • -

#4 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Removing Excess Null Characters

Posted 10 July 2011 - 09:08 PM

Yeah, there are no vectors in C. It gets more interesting then, you'll have to use a second char array.
Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Removing Excess Null Characters

Posted 10 July 2011 - 09:49 PM

If I had to guess I would say that you hex dump there is of Unicode. So the question is: do you really WANT to ignore the "nulls" which are not really "nulls" they are data.

kind of think of it this way. if you want to talk about the number 100 you need two zero's... if we were to "ignore the zeros" we would only ever see 1... 200 would be 2 but there is a BIG difference between 1 and 100, 2 and 200.

Just as there is a difference between ASCII (1 byte) and 16bit Unicode (2 bytes).

Now if all you are really interested in is the ASCII values (i.e. you will never have chars such as Ģ, , ȩ, ξ, or ഇ.

You may want to work with the wchar_t data type (C++ anyway) and see if that helps any.

else you can technically read the data as a short (rather than char) and then cast to a char looking at only the lower bits.
Was This Post Helpful? 0
  • +
  • -

#6 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Removing Excess Null Characters

Posted 10 July 2011 - 10:25 PM

There is no need for any special characters. What you see in the dump is what Im trying to get. The problem is the 00 between every byte later in the packet. All info is showing up as 2 characters to create the single byte. That said I do know packet uses UTF-8
Was This Post Helpful? 0
  • +
  • -

#7 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Removing Excess Null Characters

Posted 10 July 2011 - 10:37 PM

That means it's Unicode.
union Byte {
    wchar_t unicode;
    unsigned char bytes[2];
} *byte_array;
// read file into unsigned char array called data
byte_array = (Byte*)malloc(filesize / 2 * sizeof(Byte));
for (int i = 0; i < filesize; ++i) {
    byte_array[i].bytes[0] = data[i++];
    byte_array[i].bytes[1] = data[i];
}
for (int i = 0; i < filesize / 2; ++i) {
    printf("%c", byte_array.unicode); // not sure if this is correct
}
free(byte_array);
Something like that should work.

This post has been edited by PlasticineGuy: 10 July 2011 - 10:40 PM

Was This Post Helpful? 0
  • +
  • -

#8 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Removing Excess Null Characters

Posted 11 July 2011 - 08:58 AM

how would you work the solution into this code

{
        u_int i=0;
    char *searcher = 0;
    char c;
    int j;
    int locflag;
	static int locationtripped = 0;

        static char currentline[256]; 
    static int currentlinepos = 0;
    static char lastdispatched[256];
    static char dispatchstring[256];

    char betastring[256];

    static int a = 0;
    static int ab = 0;
    static int e = 0;
    static int eb = 0; 
    static int md = 0;
    static int hc = 0;
    static int hsc = 0;

    static int pulse = 0;

    static char location[128];
    static char type[16];
    static char area[16]; 

    static FILE *fp;
    static int printoutscanning = 0;
    static char printoutID[20];
    static char printoutfileID[32];

    static FILE *dbg;

    if(pulse) {
        if(pulse == 80) {
            sprintf(betastring, "beta a a a");
            printf("betastring: \"%s\"\n", betastring);
            system(betastring);
            pulse = 0; 
        } else
            pulse++;
    }

        if(header->len > 96) {
            for(i=55; (i < header->caplen + 1 ) ; i++) {
                c = pkt_data[i-1];

            if(c == 13 || c == 10) {
                currentline[currentlinepos] = 0;
                currentlinepos = 0;
                j = strlen(currentline);
                if(j && (j > 1)) { 
                    if(strlen(printoutfileID) && printoutscanning) {
                        dbg = fopen(printoutfileID, "a");
                        fprintf(dbg, "%s\n", currentline); 
                        fclose(dbg);
                    }
  

Was This Post Helpful? -1
  • +
  • -

#9 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Removing Excess Null Characters

Posted 11 July 2011 - 05:46 PM

Sorry, that's C++ anyway because it uses wchar_t.
I have no idea and I can't be bothered figuring out what on earth your code does. The code needs the size of the file in bytes, and the contents dumped to an array.

I told you how to implement it and gave you example code. You dumped me with your code and expected me to implement it for you. That's not happening.

This post has been edited by PlasticineGuy: 12 July 2011 - 12:51 AM

Was This Post Helpful? 0
  • +
  • -

#10 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Removing Excess Null Characters

Posted 12 July 2011 - 01:15 PM

As I have said numerous times I am completely self taught and left with a program I didnt write. I came here for guidance and help if you dont have time that is understandable there is absolutely no need to be ignorant or short with someone who is a novice and not and expert as yourself. My field of expertise is not programming so I am sorry. I will seek your help no further.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1