What does this code do? String questions

A little bit of a backstory....I am making a program in Visual Basic. The program basically opens up a compressed archive, finds a file inside it and then I THINK it modifies some data at a byte level(either a 4-byte or an 2-byte unsigned shorts), but I cannot be certain. Anyways, I have the program with a working implementation of what I am wanting to do (its in C++ and I am using Visual Basic, thus I need to convert the code and I can't copy/paste) and I have the code pulled up.

For the past several days I have been pouring over the code, going line by line commenting out what I am pretty sure the code is doing. It's odd because I can tell what the code is doing but I don't know how or why it does this. I have the binary of the file the code is for pulled up so I am able to locate where I think the data is being copied, replaced, assigned...etc. Also, not quite sure why some values and parameters are used. Mainly the issue is with the way the string class is used in the code.

My skills are extremely limited and I am learning....I'm afraid I don't understand the string class at all. I need help figuring out what the following 4 lines of code are doing. This code is fragmented and taken completely out of context so if I have missing information please let me know.

1
2
3
4
5
6
7
  //Variables:
     std::string sBuffer
     char *srcScen
     DWORD dwSrcSize
     size_t strPos
     unsigned short strCount
     int strSize


The following is the codes with a brief description of what I think it is doing.

1.sBuffer.assign(srcScen, dwSrcSize)
This appears to assign the value of dwSrcSize to srcScen? How can this even be possible? DWORD is an typedef of INT and srcScen is a char???

2.strPos = sBuffer.find ("LSX ")
Is it safe to assume that each time strPos is used, it calls the .find string method and always searches for "LSX "? Also, it appears to be searching for a string of text/characters, why then is strPos size_t...shouldn't it be some sort of char/string?

3.sBuffer.copy((char*)&strCount, 2, strPos+8)
As far as I can tell, it finds a location at strPos+8, copies 2 characaters(bytes, in this case....i think), and stores the value in the strCount pointer? Also, strCount is an unsigned short....how can it be a reference to a pointer char?

4. sBuffer.replace(strPos+4, 4, (char*)&strSize, 4)
Really uncertain here. The only thing I may know for certain, is that the number 4 being used is because these are 4bytes of data.
Last edited on
ill preface this with bytes is bytes :) you can jack 4 ascii letters into a 32 bit int if you want. The int value is largely meaningless, but you can DO it if you cast and shove. SO its possible to store chars in a short.

Most of this is libarary calls, so you should read your library reference (looks like Microsoft GUI code). That will tell you what each routine does. The exact type of sbuffer is needed to be sure what these things do.

#2 is standard string find and it returns the index value (integer) where the letter "L" resides in your string and that L is part of LSX.







Last edited on
Topic archived. No new replies allowed.