Sorry, I have almost 20 years without touching C/C++
.
I Would like translate this code to Java 8, I found this Reference Manual. I was reading that in this link.
You can read...
Binary Templates are easy to write and look similar to C/C++ structs except they may contain if, for, or while statements as well as functions or complex expressions.
Powerful enough to parse almost any binary file format.
Can be set to run automatically when files are opened.
Templates may be shared and a list of templates for download is available in our Template Repository.
I begins and in the line 2063
I found (sorry, I could only translate, sad 4 lines :(! ).
APFS apfs(0);
I was reading C - function inside struct but looks, so many different!
Reviewing I jump to the line 1994
, it looks like a structure with a function call, instead of having attributes!!!.
typedef struct APFS(uint64 apfs_offset) {
DefineApfsContainer(apfs_offset);
} ;
Inmediatly you can see in the line 1998
void DefineApfsContainer(uint64 apfs_offset) {
Apfs_Offset = apfs_offset;
FSeek(Apfs_Offset);
if (!CheckApfsAndSetBlockSize()) {
Printf("\nError, starting point not an APFS container superblock. Set the 'Apfs_Offset' variable to correct value!");
Exit(1);
}
obj csb;//container super block in block zero
SeekBlock(csb.body.xp_desc_base);
CheckpointDesc cp(csb.body.xp_desc_blocks);
//SeekBlock(csb.body.xp_data_base);
//obj checkpoint_data_nx[csb.body.xp_data_blocks] <optimize=false>;
// Checkpoint processing
local uint i = 0;
local uint64 max_xid = 0;
local uint64 max_xid_block_pos = 0;
SeekBlock(csb.body.xp_desc_base);
local uint64 base_pos = FTell();
local uint64 pos = 0;
for (i=0; i< csb.body.xp_desc_blocks; ++i) { // assuming cont. blocks
if (cp.checkpoint_desc_nx[i].hdr.type == obj_type_container_superblock) {
if (cp.checkpoint_desc_nx[i].hdr.xid >= max_xid) {
// validate it
pos = base_pos + (i * Block_Size);
if (fletcher64(pos, Block_Size) == 0) {
max_xid = cp.checkpoint_desc_nx[i].hdr.xid;
max_xid_block_pos = pos;
}
}
}
}
if (max_xid > csb.hdr.xid)
Printf("\nFound newer xid=%Lu @ offset 0x%Lu. Using this Container superblock.", max_xid, pos);
FSeek(pos);
obj valid_csb;
BookmarkVolumes(valid_csb);
if (valid_csb.body.efi_jumpstart) {
SeekBlock(valid_csb.body.efi_jumpstart);
obj efi_info;
}
/*if (valid_csb.body.keylocker_block_count) {
SeekBlock(valid_csb.body.keylocker_paddr);
obj keybag; // This is encrypted!
}*/
}
I need to understand what does that (I don't mean the code, but the way of coding), in order to translate. How should I understand this code (a function as a structure or a structure from a function)?
The nugget of subject. How should I translate it to Java?