Custom field in file version in C++ project - visual-c++

Hi
is there a way to create a custom field in the file version for a C++ project. So that we can see these fields along with file version, company name, etc. I would like to create fields like
revision = 1000
Customization = OEM1
.
Thanks
John

You can add extra fields to the version information in your .rc file. You can't add numeric fields, but you can add localized string fields. I have never tried to do this with the GUI, but I know you can do it by changing the file directly.
In Visual C++, right click on your .rc file and click "View Code." Somewhere in there, you will find a section that starts with:
BLOCK "StringFileInfo"
That block probably only has one sub-block:
BLOCK "0409904b0"
That number is the numeric version of the locale descriptor for en_us. This block contains several VALUE entries such as:
VALUE "FileVersion", "1, 0, 0, 0"
VALUE "OriginalFilename", "MyProjectName"
You can add any field you want to this section and it will show up on the version tab of the properties dialog for the executable.
If you need to be able to read these values at runtime, you can use GetFileVersionInfo like this:
wchar_t myModululeName[MAX_PATH];
GetModuleFileName(NULL,myModuleName,MAX_PATH);
DWORD dummy;
DWORD versionSize=GetFileVersionInfoSize(myModuleName,&dummy);
//I don't remember why I added extra space to these
void * versionInfo=malloc(versionSize+10);
GetFileVersionInfo(myModuleName,0,versionSize+1,versionInfo);
//This part is optional
//The VS_FIXEDFILEINFO contains information from the non-localized parts of
//the "StringFileInfo" block in the .rc file
VS_FIXEDFILEINFO * fixedFileInfo;
UINT fixedFileSize;
VerQueryValue(versionInfo,L"\\",(void **)(&fixedFileInfo),&fixedFileSize);
//This will retrieve the local codes that are defined in the StringFileInfo block
WORD * translationTable;
UINT translationSize;
VerQueryValue(verionInfo,L"\\VarFileInfo\\Translation",(void **)(&translationTable),&translationTableSize);
//This always uses the first locale, you could examine translationTable
//if you need to for other codes
wchar_t mySpecialQuery[128];
sprintf_s(mySpecialQuery,L"\\StringFileInfo\\%04x%04x\\MySpecialVersionInfo",translationTable[0],translationTable[1]);
wchar_t * mySpecialValue;
UINT mySpecialValueSize;
VerQueryValue(versionInfo,mySpecialQuery,(void **)(&mySpecialValue),&mySpecialValueSize);
//you can now do whatever you need to do with mySpecialValue, including using _wtoi()
//and query for more values
free(versionInfo);

Related

Extend section in Mach-O file

I am trying to extract libraries from the Dyld_shared_cache, and need to fix in external references.
For example, the pointers in the __DATA.__objc_selrefs section usually point to data outside the mach-o file, to fix that I would have to copy the corresponding c-string from the dyld and append it to the __TEXT.__objc_methname section.
Though from my understanding of the Mach-O file format, this extension of the __TEXT.__objc_methname would shift all the sections after it and would force me to fix all the offsets and pointers that reference them. Is there a way to add data to a section without breaking a lot of things?
Thanks!
Thanks to #Kamil.S for the idea about adding a new load command and section.
One way to achieve adding more data to a section is to create a duplicate segment and section and insert it before the __LINKEDIT segment.
Slide the __LINKEDIT segment so we have space to add the new section.
define the slide amount, this must be page-aligned, so I choose 0x4000.
add the slide amount to the relevant load commands, this includes but is not limited to:
__LINKEDIT segment (duh)
dyld_info_command
symtab_command
dysymtab_command
linkedit_data_commands
physically move the __LINKEDIT in the file.
duplicate the section and change the following1
size, should be the length of your new data.
addr, should be in the free space.
offset, should be in the free space.
duplicate the segment and change the following1
fileoff, should be the start of the free space.
vmaddr, should be the start of the free space.
filesize, anything as long as it is bigger than your data.
vmsize, must be identical to filesize.
nsects, change to reflect how many sections your adding.
cmdsize, change to reflect the size of the segment command and its section commands.
insert the duplicated segment and sections before the __LINKEDIT segment
update the mach_header
ncmds
sizeofcmds
physically write the extra data in the file.
you can optionally change the segname and sectname fields, though it isn't necessary. thanks Kamil.S!
UPDATE
After clarifing with OP that extension of __TEXT.__objc_methname would happen during Mach-O post processing of an existing executable I had a fresh look on the problem.
Another take would be to create a new load command LC_SEGMENT_64 with a new __TEXT_EXEC.__objc_methname segment / section entry (normally __TEXT_EXEC is used for some kernel stuff but essentially it's the same thing as __TEXT). Here's a quick POC to ilustrate the concept:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
printf("%lx",[NSObject new]);
}
return 0;
}
Compile like this:
gcc main.m -c -o main.o
ld main.o -rename_section __TEXT __objc_methname __TEXT_EXEC __objc_methname -lobjc -lc
Interestingly only ld up to High Sierra 10.14.6 generates __TEXT.__objc_methname, no trace of it on Catalina, it's done differently.
UPDATE2.
Playing around with it, I noticed execution rights for __TEXT segment (and __TEXT_EXEC for that matter) are not required for __objc_methname to work.
Even better specific segment & section names are not required:
I could pull off:
__DATA.__objc_methname
__DATA_CONST.__objc_methname
__ARBITRARY.__arbitrary
or in my case last __DATA section
__DATA.__objc_classrefs where the original the data got concatenated by the selector name.
It's all fine as long as a proper null terminated C-string with the selector name is there. If I intentionally break the "new\0" in hex editor or MachOView I'll get
"+[NSObject ne]: unrecognized selector sent to instance ..."
upon launching my POC executable so the value is used for sure.
So to sum __TEXT.__objc_methname section itself is likely some debugger hint made by the linker. The app runtime seems to only need selector names as char* anywhere in memory.

IBM Domino xpage - parse iCalendar summary with new lines manually/ical4j

So far I was parsing the NotesCalendarEntry ics manually and overwriting certain properties, and it worked fine. Today i stumbled upon a problem, where a long summary name of the appointment gets split into multiple lines, and my parsing goes wrong, it replaces the part up to the first line break and the old part is still there.
Here's how I do this "parsing":
NotesCalendarEntry calEntry = cal.getEntryByUNID(apptuid);
String iCalE = calEntry.read();
StringBuilder sb = new StringBuilder(iCalE);
int StartIndex = iCalE.indexOf("BEGIN:VEVENT"); // care only about vevent
tmpIndex = sb.indexOf("SUMMARY:") + 8;
LineBreakIndex = sb.indexOf(Character.toString('\n'), tmpIndex);
if(sb.charAt(LineBreakIndex-1) == '\r') // take \r\n into account if exists
LineBreakIndex--;
sb.delete(tmpIndex, LineBreakIndex); // delete old content
sb.insert(tmpIndex, subject); // put my new content
It works when line breaks are where they are supposed to be, but somehow with long summary name, line breaks are put into the summary (not literal \r\n characters, but real line breaks).
I split the iCalE string by \r\n and got this (only a part obviously):
SEQUENCE:6
ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED;CN="test/Test";RSVP=FALSE:
mailto:test#test.test
ATTENDEE;CUTYPE=ROOM;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED
;CN="Room 2/Test";RSVP=TRUE:mailto:room2#test.test
CLASS:PUBLIC
DESCRIPTION:Test description\n
SUMMARY:Very long name asdjkasjdklsjlasdjlasjljraoisjroiasjroiasjoriasoiruasoiruoai Mee
ting long name
LOCATION:Room 2/Test
ORGANIZER;CN="test/Test":mailto:test#test.test
Each line is one array element from iCalE.split("\\r\\n");. As you can see, the Summary field got split into 2 lines, and a space was added after the line break.
Now I have no idea how to parse this correctly, I thought about finding the index of next : instead of a new line break, and then finding the first line break before that : character, but that wouldn't work if the summary also contained a : after the injected line-break, and also wouldn't work on fields like that ORGANIZER;CN= as it doesn't use : but ;
I tried importing external ical4j jar into my xpage to overcome this problem, and while everything is recognized in Domino Designer it resulted in lots of NoClassDefFound exceptions after trying to reach my xpage service, despite the jars being in the build path and all.
java.lang.NoClassDefFoundError: net.fortuna.ical4j.data.CalendarBuilder
How can I safely parse this manually, or how can I properly import ical4j jar to my xpage? I just want to modify 3 fields, the DTSTART, DTEND and SUMMARY, with the dates I had no problems so far. Fields like Description are using literal \n string to mark new lines, it should be the same in other fields...
Update
So I have read more about iCalendar, and it seems that there is a standard for this called line folds, these are crlf line endings followed by a space. I made a while loop checking until the last line-break not followed by a space, and it works great so far. Will use this unless there's a better solution (ical4j is one, but I can't get it working with Domino)

MFC Accelerator resource ID conflicts?

Someone change the numerical value of one of the accelerator in the resource.h file and because of that the accelerator stopped working.
(old value that was working)
#define IDR_DELETE_FROM_ACCELERATOR 32873
(new value that is not working)
#define IDR_DELETE_FROM_ACCELERATOR 22873
related code :
ON_COMMAND( IDR_DELETE_FROM_ACCELERATOR, OnDeleteFromAccelerator )
void CMyViewClass::OnDeleteFromAccelerator()
{
///....
}
In both cases, the numerical values are unique (no conflict).
From MSDN, It seems that both numerical values should be valid.
Am I reading/understanding this correctly?
I can simply renumber the value to the one that worked, but I would like to understand why it stopped working.
Thanks,
Max.
Read the TN020 paying more attention.
On the table it is stated:
ID_ commands 0x8000 through 0xDFFF
0x8000 in decimal is 32768.
22873 is lower than that.

Xcode4 - Check if translated value is used in project

is it possible to check if a translated value is used in my project.
For example, I want to check automatically if e.g.
/*
Localizable.strings
*/
"THOUSAND"="Thousand";
"VALUE"="value"
...
is used somewhere in my project (in the following macro: NSLocalizedString(#"THOUSAND",#"");)?
I can do this by search value after value, but let's say there are 1000 values? So automatically do that would save much time :-D
BR & THX,
mybecks

Unicode strings not showing in Win32 ComboBoxEx

I am creating a WC_COMBOBOXEX on Windows Vista and adding strings to it, but they don't show up in the control. The same strings show up fine if I use the old WC_COMBOBOX with CB_ADDSTRING.
I am calling InitCommonControlsEx with ICC_USEREX_CLASSES and creating the comboboxex using CreateWindowEx with style WS_CHILD|WS_CLIPSIBLINGS|CBS_SIMPLE|CBS_SORT|CBS_HASSTRINGS (no extended styles). I am adding the strings using
COMBOBOXEXITEM cbem = {0};
cbem.mask = CBEIF_TEXT;
cbem.iItem = -1;
cbem.pszText = L"hello";
SendMessage(hWnd_, CBEM_INSERTITEM, 0, TOLPARAM(&cbem));
The combobox comes up empty but when I move the cursor up and down in the editcontrol/listbox, I see funny block characters sometimes.
Eventually, I want to add it as a CBS_DROPDOWNLIST to a rebar control but I read somewhere that comboboxex works a lot better in there than the old combobox.
Thanks.
From MSDN:
ComboBoxEx controls support only the following ComboBox styles:
CBS_SIMPLE
CBS_DROPDOWN
CBS_DROPDOWNLIST
WS_CHILD
So CBS_SORT and CBS_HASSTRINGS may be messing up the style bits.
Does it help if you send CBEM_SETUNICODEFORMAT?

Resources