Exemplo n.º 1
0
        /// <summary>
        /// use to rebase current meta data to a newer memory address(affects reflexive,extended and data ref fields only)
        /// </summary>
        /// <param name="new_base">the new memory address to which the meta has to rebased</param>
        public void Rebase_meta(int new_base)
        {
            //first rebase reflexive fields
            foreach (int off in ref_reflexive)
            {
                int old_mem_addr = DATA_READ.ReadINT_LE(off + 4, data);
                int new_mem_addr = new_base + (old_mem_addr - mem_off);

                DATA_READ.WriteINT_LE(new_mem_addr, off + 4, data);
            }
            //then we rebase all the dataref fields
            foreach (int off in ref_data)
            {
                int old_mem_addr = DATA_READ.ReadINT_LE(off + 4, data);
                int new_mem_addr = new_base + (old_mem_addr - mem_off);

                DATA_READ.WriteINT_LE(new_mem_addr, off + 4, data);
            }
            //we venture in extended meta if it is even concerned
            if (list_extended != null)
            {
                //for extended meta stuff we are gonna first rebase the extended meta(s) first and set the offsets accordingly
                //well extende meta are gonna follow meta one by one
                int extended_new_base = new_base + size;

                List <int> key_mems = list_extended.Keys.ToList <int>();
                //Rebase extended meta
                foreach (int temp_key in key_mems)
                {
                    extended_meta temp_meta = list_extended[temp_key];
                    temp_meta.Rebase_meta(extended_new_base);

                    extended_new_base += temp_meta.Get_Total_size();
                }
                //now lets update the offsets with the newer values
                List <int> extend_off = ref_extended.Keys.ToList <int>();
                foreach (int temp_off in extend_off)
                {
                    int           extend_mem_addr = ref_extended[temp_off];
                    extended_meta temp_ext        = list_extended[extend_mem_addr];

                    int new_mem_addr = temp_ext.Get_mem_addr();

                    DATA_READ.WriteINT_LE(new_mem_addr, temp_off + 4, data);
                }
            }

            //update the base to which meta has been compiled
            mem_off = new_base;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a full self dependent meta file(except tag refs)
        /// </summary>
        /// <returns></returns>
        public byte[] Generate_meta_file()
        {
            byte[] ret = new byte[this.Get_Total_size()];

            //we first copy the root meta data into it
            DATA_READ.ArrayCpy(ret, data, 0x0, size);

            //now we go for extended meta
            List <int> extend_keys = list_extended.Keys.ToList <int>();

            //here we go
            foreach (int temp_key in extend_keys)
            {
                extended_meta temp_meta = list_extended[temp_key];
                int           start_off = temp_meta.Get_mem_addr() - mem_off;
                DATA_READ.ArrayCpy(ret, temp_meta.Generate_meta_file(), start_off, temp_meta.Get_Total_size());
            }

            return(ret);
        }