Esempio n. 1
0
        public static List <arg_t> POCKETSPHINX_DEBUG_OPTIONS()
        {
            List <arg_t> args = new List <arg_t>();

            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-logfn"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("File to write log messages in")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-mfclogdir"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Directory to log feature files to")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-rawlogdir"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Directory to log raw audio files to")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-senlogdir"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Directory to log senone score files to")
            });
            return(args);
        }
Esempio n. 2
0
        /// <summary>
        /// Obtains the memory address of an assembly.
        /// </summary>
        /// <param name="name">The name of the assembly to find the address of.</param>
        public uint GetProcAddress(string name)
        {
            unsafe
            {
                IntPtr codeBase = module.codeBase;
                int    idx      = -1;
                uint   i;
                IMAGE_DATA_DIRECTORY directory = module.headers.OptionalHeader.DataDirectory[0];
                if (directory.Size == 0)
                {
                    return(0);
                }
                var exports = PointerHelpers.ToStruct <IMAGE_EXPORT_DIRECTORY>(codeBase, directory.VirtualAddress);
                var nameRef = (uint *)new IntPtr(codeBase.ToInt32() + exports.AddressOfNames);
                var ordinal = (ushort *)new IntPtr(codeBase.ToInt32() + exports.AddressOfNameOrdinals);
                for (i = 0; i < exports.NumberOfNames; i++, nameRef++, ordinal++)
                {
                    var    str = codeBase + (int)(*nameRef);
                    string tmp = Marshal.PtrToStringAnsi(str);
                    if (tmp == name)
                    {
                        idx = *ordinal;
                        break;
                    }
                }

                var tmpaa = (uint *)(codeBase.ToInt32() + (exports.AddressOfFunctions + (idx * 4)));
                var addr  = (uint)((codeBase.ToInt32()) + (*tmpaa));
                return(addr);
            }
        }
        public static trigger_adapter trigger_create(string modelDir, string dictionaryFile, bool verboseLogging)
        {
            //printf("            creating recognizer\n");

            Pointer <ps_decoder_t> ps     = PointerHelpers.NULL <ps_decoder_t>();
            Pointer <cmd_ln_t>     config = PointerHelpers.NULL <cmd_ln_t>();

            config = cmd_ln.cmd_ln_init(config, pocketsphinx.ps_args(), 1,
                                        "-hmm", modelDir,
                                        "-dict", dictionaryFile,
                                        "-verbose", "y");

            ps = pocketsphinx.ps_init(config);

            cmd_ln.cmd_ln_free_r(config);

            trigger_adapter adapter = new trigger_adapter();

            adapter.ps = ps;
            adapter.user_is_speaking = false;
            adapter.last_hyp         = PointerHelpers.Malloc <byte>(512);
            adapter.last_hyp[0]      = 0;

            return(adapter);
        }
Esempio n. 4
0
        public static void ps_expand_file_config(Pointer <ps_decoder_t> ps, Pointer <byte> arg, Pointer <byte> extra_arg,
                                                 Pointer <byte> hmmdir, Pointer <byte> file)
        {
            Pointer <byte> val;

            if ((val = cmd_ln.cmd_ln_str_r(ps.Deref.config, arg)).IsNonNull)
            {
                cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, val);
            }
            else if (hmmdir.IsNull)
            {
                cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, PointerHelpers.NULL <byte>());
            }
            else
            {
                string         path = System.IO.Path.Combine(cstring.FromCString(hmmdir), cstring.FromCString(file));
                Pointer <byte> tmp  = cstring.ToCString(path);
                if (FILE.file_exists(tmp))
                {
                    cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, tmp);
                }
                else
                {
                    cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, PointerHelpers.NULL <byte>());
                }
                ckd_alloc.ckd_free(tmp);
            }
        }
Esempio n. 5
0
 public static void ps_search_base_reinit(ps_search_t search, Pointer <dict_t> dictionary,
                                          Pointer <dict2pid_t> d2p)
 {
     dict.dict_free(search.dict);
     dict2pid.dict2pid_free(search.d2p);
     /* FIXME: _retain() should just return NULL if passed NULL. */
     if (dictionary.IsNonNull)
     {
         search.dict        = dict.dict_retain(dictionary);
         search.start_wid   = dict.dict_startwid(dictionary);
         search.finish_wid  = dict.dict_finishwid(dictionary);
         search.silence_wid = dict.dict_silwid(dictionary);
         search.n_words     = dict.dict_size(dictionary);
     }
     else
     {
         search.dict      = PointerHelpers.NULL <dict_t>();
         search.start_wid = search.finish_wid = search.silence_wid = -1;
         search.n_words   = 0;
     }
     if (d2p.IsNonNull)
     {
         search.d2p = dict2pid.dict2pid_retain(d2p);
     }
     else
     {
         search.d2p = PointerHelpers.NULL <dict2pid_t>();
     }
 }
Esempio n. 6
0
        public static int ps_set_keyphrase(Pointer <ps_decoder_t> ps, Pointer <byte> name, Pointer <byte> keyphrase)
        {
            ps_search_t search;

            search = kws_search.kws_search_init(name, keyphrase, PointerHelpers.NULL <byte>(), ps.Deref.config, ps.Deref.acmod, ps.Deref.dict, ps.Deref.d2p);
            return(set_search_internal(ps, search));
        }
Esempio n. 7
0
        public static List <arg_t> POCKETSPHINX_DICT_OPTIONS()
        {
            List <arg_t> args = new List <arg_t>();

            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-dict"),
                type  = cmd_ln.REQARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Main pronunciation dictionary (lexicon) input file")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-fdict"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Noise word pronunciation dictionary input file")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-dictcase"),
                type  = cmd_ln.ARG_BOOLEAN,
                deflt = cstring.ToCString("no"),
                doc   = cstring.ToCString("Dictionary is case sensitive (NOTE: case insensitivity applies to ASCII characters only)")
            });
            return(args);
        }
Esempio n. 8
0
        public static int swap_check(FILE fp)
        {
            Pointer <byte> magic_buf = PointerHelpers.Malloc <byte>(4);
            Pointer <uint> magic     = magic_buf.ReinterpretCast <uint>();

            if (fp.fread(magic_buf, 4, 1) != 1)
            {
                err.E_ERROR("Cannot read BYTEORDER MAGIC NO.\n");
                return(-1);
            }

            if (+magic != BYTE_ORDER_MAGIC)
            {
                /* either need to swap or got bogus magic number */
                byteorder.SWAP_INT32(magic);

                if (+magic == BYTE_ORDER_MAGIC)
                {
                    return(1);
                }

                byteorder.SWAP_INT32(magic);
                err.E_ERROR(string.Format("Bad BYTEORDER MAGIC NO: {0:x8}, expecting {1:x8}\n",
                                          magic, BYTE_ORDER_MAGIC));
                return(-1);
            }

            return(0);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the total amount of modules within an assembly.
        /// </summary>
        public int GetModuleCount()
        {
            int    count    = 0;
            IntPtr codeBase = module.codeBase;
            IMAGE_DATA_DIRECTORY directory = module.headers.OptionalHeader.DataDirectory[1];

            if (directory.Size > 0)
            {
                var importDesc = PointerHelpers.ToStruct <IMAGE_IMPORT_DESCRIPTOR>(codeBase, directory.VirtualAddress);
                while (importDesc.Name > 0)
                {
                    var    str    = codeBase + (int)importDesc.Name;
                    string tmp    = Marshal.PtrToStringAnsi(str);
                    int    handle = Win32Imports.LoadLibrary(tmp);

                    if (handle == -1)
                    {
                        break;
                    }
                    count++;
                    importDesc = PointerHelpers.ToStruct <IMAGE_IMPORT_DESCRIPTOR>(codeBase, (uint)(directory.VirtualAddress + (Marshal.SizeOf(typeof(IMAGE_IMPORT_DESCRIPTOR)) * (count))));
                }
            }
            return(count);
        }
Esempio n. 10
0
        public static Pointer <hash_iter_t> hash_table_iter_next(Pointer <hash_iter_t> itor)
        {
            /* If there is an entry, walk down its list. */
            if (itor.Deref.ent.IsNonNull)
            {
                itor.Deref.ent = itor.Deref.ent.Deref.next;
            }

            /* If we got to the end of the chain, or we had no entry, scan
             * forward in the table to find the next non-empty bucket. */
            if (itor.Deref.ent.IsNull)
            {
                while (itor.Deref.idx < itor.Deref.ht.Deref.size &&
                       itor.Deref.ht.Deref.table[itor.Deref.idx].key.IsNull)
                {
                    ++itor.Deref.idx;
                }

                /* If we did not find one then delete the iterator and
                 * return NULL. */
                if (itor.Deref.idx == itor.Deref.ht.Deref.size)
                {
                    hash_table_iter_free(itor);
                    return(PointerHelpers.NULL <hash_iter_t>());
                }
                /* Otherwise use this next entry. */
                itor.Deref.ent = itor.Deref.ht.Deref.table + itor.Deref.idx;
                /* Increase idx for the next time around. */
                ++itor.Deref.idx;
            }
            return(itor);
        }
Esempio n. 11
0
        public static Pointer <gnode_t> hash_table_tolist(Pointer <hash_table_t> h, BoxedValue <int> count)
        {
            Pointer <gnode_t>      g;
            Pointer <hash_entry_t> e;
            int i, j;

            g = PointerHelpers.NULL <gnode_t>();

            j = 0;
            for (i = 0; i < h.Deref.size; i++)
            {
                e = h.Deref.table.Point(i);

                if (e.Deref.key.IsNonNull)
                {
                    g = glist.glist_add_ptr(g, (object)e);
                    j++;

                    for (e = e.Deref.next; e.IsNonNull; e = e.Deref.next)
                    {
                        g = glist.glist_add_ptr(g, (object)e);
                        j++;
                    }
                }
            }

            if (count != null)
            {
                count.Val = j;
            }

            return(g);
        }
Esempio n. 12
0
        public void CopySections(Byte[] data, IMAGE_NT_HEADERS oldHeaders, IntPtr headers, IMAGE_DOS_HEADER dosHeader)
        {
            Int32  i;
            IntPtr codebase = _module.codeBase;
            IMAGE_SECTION_HEADER section = PointerHelpers.ToStruct <IMAGE_SECTION_HEADER>(headers, (UInt32)(24 + dosHeader.e_lfanew + oldHeaders.FileHeader.SizeOfOptionalHeader));

            for (i = 0; i < _module.headers.FileHeader.NumberOfSections; i++)
            {
                IntPtr dest;
                if (section.SizeOfRawData == 0)
                {
                    UInt32 size = oldHeaders.OptionalHeader.SectionAlignment;
                    if (size > 0)
                    {
                        dest = new IntPtr((Win32Imports.VirtualAlloc((UInt32)(codebase.ToInt32() + (Int32)section.VirtualAddress), size, Win32Constants.MEM_COMMIT, Win32Constants.PAGE_READWRITE)));

                        section.PhysicalAddress = (UInt32)dest;
                        IntPtr write = new IntPtr(headers.ToInt32() + (32 + dosHeader.e_lfanew + oldHeaders.FileHeader.SizeOfOptionalHeader) + (Marshal.SizeOf(typeof(IMAGE_SECTION_HEADER)) * (i)));
                        Marshal.WriteInt32(write, (Int32)dest);
                        Byte[] datazz = new Byte[size + 1];
                        Marshal.Copy(datazz, 0, dest, (Int32)size);
                    }
                    section = PointerHelpers.ToStruct <IMAGE_SECTION_HEADER>(headers, (UInt32)((24 + dosHeader.e_lfanew + oldHeaders.FileHeader.SizeOfOptionalHeader) + (Marshal.SizeOf(typeof(IMAGE_SECTION_HEADER)) * (i + 1))));
                    continue;
                }

                dest = new IntPtr((Win32Imports.VirtualAlloc((UInt32)(codebase.ToInt32() + (Int32)section.VirtualAddress), section.SizeOfRawData, Win32Constants.MEM_COMMIT,
                                                             Win32Constants.PAGE_READWRITE)));
                Marshal.Copy(data, (Int32)section.PointerToRawData, dest, (Int32)section.SizeOfRawData);
                section.PhysicalAddress = (UInt32)dest;
                IntPtr write2 = new IntPtr(headers.ToInt32() + (32 + dosHeader.e_lfanew + oldHeaders.FileHeader.SizeOfOptionalHeader) + (Marshal.SizeOf(typeof(IMAGE_SECTION_HEADER)) * (i)));
                Marshal.WriteInt32(write2, (Int32)dest);
                section = PointerHelpers.ToStruct <IMAGE_SECTION_HEADER>(headers, (UInt32)((24 + dosHeader.e_lfanew + oldHeaders.FileHeader.SizeOfOptionalHeader) + (Marshal.SizeOf(typeof(IMAGE_SECTION_HEADER)) * (i + 1))));
            }
        }
Esempio n. 13
0
        public static int bio_fread_1d(BoxedValue <Pointer <byte> > buf, uint el_sz, BoxedValue <uint> n_el, FILE fp, int sw, BoxedValue <uint> ck)
        {
            /* Read 1-d array size */
            Pointer <byte> array_size = PointerHelpers.Malloc <byte>(4);

            if (bio_fread(array_size, 4, 1, fp, sw, ck) != 1)
            {
                err.E_FATAL("fread(arraysize) failed\n");
            }

            n_el.Val = array_size.ReinterpretCast <uint>().Deref;
            if (n_el.Val <= 0)
            {
                err.E_FATAL(string.Format("Bad arraysize: {0}\n", n_el.Val));
            }

            /* Allocate memory for array data */
            buf.Val = ckd_alloc.ckd_calloc <byte>(n_el.Val * el_sz);

            /* Read array data */
            if (bio_fread(buf.Val, (int)el_sz, (int)n_el.Val, fp, sw, ck) != n_el.Val)
            {
                err.E_FATAL("fread(arraydata) failed\n");
            }

            return((int)(n_el.Val));
        }
Esempio n. 14
0
        public Int32 GetModuleCount()
        {
            Int32  count    = 0;
            IntPtr codeBase = this._module.codeBase;
            IMAGE_DATA_DIRECTORY directory = this._module.headers.OptionalHeader.DataDirectory[1];

            if (directory.Size > 0)
            {
                IMAGE_IMPORT_DESCRIPTOR importDesc = PointerHelpers.ToStruct <IMAGE_IMPORT_DESCRIPTOR>(codeBase, directory.VirtualAddress);
                while (importDesc.Name > 0)
                {
                    Int32  str    = codeBase.ToInt32() + (Int32)importDesc.Name;
                    String tmp    = Marshal.PtrToStringAnsi(new IntPtr(str));
                    Int32  handle = Win32Imports.LoadLibrary(tmp);

                    if (handle == -1)
                    {
                        break;
                    }

                    count++;
                    importDesc = PointerHelpers.ToStruct <IMAGE_IMPORT_DESCRIPTOR>(codeBase, (UInt32)(directory.VirtualAddress + (Marshal.SizeOf(typeof(IMAGE_IMPORT_DESCRIPTOR)) * (count))));
                }
            }
            return(count);
        }
Esempio n. 15
0
        public String[] GetProcedures()
        {
            unsafe
            {
                IntPtr codeBase = this._module.codeBase;
                IMAGE_DATA_DIRECTORY directory = this._module.headers.OptionalHeader.DataDirectory[0];
                if (directory.Size == 0)
                {
                    return new String[] { }
                }
                ;

                IMAGE_EXPORT_DIRECTORY exports = PointerHelpers.ToStruct <IMAGE_EXPORT_DIRECTORY>(codeBase, directory.VirtualAddress);
                UInt32 *nameRef = (UInt32 *)new IntPtr(codeBase.ToInt32() + exports.AddressOfNames);
                UInt16 *ordinal = (UInt16 *)new IntPtr(codeBase.ToInt32() + exports.AddressOfNameOrdinals);

                String[] result = new String[exports.NumberOfNames];
                for (UInt32 i = 0; i < exports.NumberOfNames; i++, nameRef++, ordinal++)
                {
                    IntPtr str = new IntPtr(codeBase.ToInt32() + (Int32)(*nameRef));
                    result[i] = Marshal.PtrToStringAnsi(str);
                }
                return(result);
            }
        }
Esempio n. 16
0
        public static void compress_right_context_tree(Pointer <dict2pid_t> d2p,
                                                       Pointer <Pointer <Pointer <ushort> > > rdiph_rc)
        {
            int n_ci;
            int b, l, r;
            Pointer <ushort>     rmap;
            Pointer <ushort>     tmpssid;
            Pointer <short>      tmpcimap;
            Pointer <bin_mdef_t> mdef = d2p.Deref.mdef;
            uint alloc;

            n_ci = mdef.Deref.n_ciphone;

            tmpssid  = ckd_alloc.ckd_calloc <ushort>(n_ci);
            tmpcimap = ckd_alloc.ckd_calloc <short>(n_ci);

            d2p.Deref.rssid =
                (Pointer <Pointer <xwdssid_t> >)ckd_alloc.ckd_calloc <Pointer <xwdssid_t> >(mdef.Deref.n_ciphone);
            alloc = (uint)(mdef.Deref.n_ciphone * 8);

            for (b = 0; b < n_ci; b++)
            {
                d2p.Deref.rssid[b] =
                    (Pointer <xwdssid_t>)ckd_alloc.ckd_calloc_struct <xwdssid_t>(mdef.Deref.n_ciphone);
                alloc += (uint)(mdef.Deref.n_ciphone * 20);

                for (l = 0; l < n_ci; l++)
                {
                    rmap = rdiph_rc[b][l];
                    compress_table(rmap, tmpssid, tmpcimap, mdef.Deref.n_ciphone);

                    for (r = 0; r < mdef.Deref.n_ciphone && tmpssid[r] != s3types.BAD_S3SSID;
                         r++)
                    {
                        ;
                    }

                    if (tmpssid[0] != s3types.BAD_S3SSID)
                    {
                        d2p.Deref.rssid[b][l].ssid = ckd_alloc.ckd_calloc <ushort>(r);
                        tmpssid.MemCopyTo(d2p.Deref.rssid[b][l].ssid, r);
                        d2p.Deref.rssid[b][l].cimap =
                            ckd_alloc.ckd_calloc <short>(mdef.Deref.n_ciphone);
                        tmpcimap.MemCopyTo(d2p.Deref.rssid[b][l].cimap, (mdef.Deref.n_ciphone));
                        d2p.Deref.rssid[b][l].n_ssid = r;
                    }
                    else
                    {
                        d2p.Deref.rssid[b][l].ssid   = PointerHelpers.NULL <ushort>();
                        d2p.Deref.rssid[b][l].cimap  = PointerHelpers.NULL <short>();
                        d2p.Deref.rssid[b][l].n_ssid = 0;
                    }
                }
            }

            err.E_INFO(string.Format("Allocated {0} bytes ({1} KiB) for word-final triphones\n",
                                     (int)alloc, (int)alloc / 1024));
            ckd_alloc.ckd_free(tmpssid);
            ckd_alloc.ckd_free(tmpcimap);
        }
Esempio n. 17
0
        public void TestVoidPointerByteToULong()
        {
            Pointer <byte>  pointer     = PointerHelpers.Malloc <byte>(80);
            Pointer <ulong> voidPointer = pointer.Point(20).ReinterpretCast <ulong>();

            pointer[20] = 80;
            pointer[21] = 226;
            pointer[22] = 182;
            pointer[23] = 173;
            pointer[24] = 76;
            pointer[25] = 82;
            pointer[26] = 0;
            pointer[27] = 0;
            Assert.AreEqual(90489285435984UL, voidPointer[0]);
            Assert.AreEqual(0UL, voidPointer[1]);
            voidPointer[2] = 67823904875254UL;
            Assert.AreEqual(246, pointer[36]);
            Assert.AreEqual(226, pointer[37]);
            Assert.AreEqual(193, pointer[38]);
            Assert.AreEqual(123, pointer[39]);
            Assert.AreEqual(175, pointer[40]);
            Assert.AreEqual(61, pointer[41]);
            Assert.AreEqual(0, pointer[42]);
            Assert.AreEqual(0, pointer[43]);
        }
Esempio n. 18
0
        public static void ErrorRetrievingMethod(
            this Vendors.Serilog.ILogger logger,
            Exception exception,
            long moduleVersionPointer,
            int mdToken,
            int opCode,
            string instrumentedType,
            string methodName,
            string instanceType        = null,
            string[] relevantArguments = null)
        {
            var instrumentedMethod = $"{instrumentedType}.{methodName}(...)";

            if (instanceType != null)
            {
                instrumentedMethod = $"{instrumentedMethod} on {instanceType}";
            }

            if (relevantArguments != null)
            {
                instrumentedMethod = $"{instrumentedMethod} with {string.Join(", ", relevantArguments)}";
            }

            var moduleVersionId = PointerHelpers.GetGuidFromNativePointer(moduleVersionPointer);

            logger.Error(
                exception,
                $"Error (MVID: {moduleVersionId}, mdToken: {mdToken}, opCode: {opCode}) could not retrieve: {instrumentedMethod}");
        }
Esempio n. 19
0
        /* Parse tmat and state.Deref.senone mappings for phone p and fill in structure */
        public static void parse_tmat_senmap(Pointer <mdef_t> m, Pointer <byte> line, long off, int p)
        {
            int            wlen, n, s;
            Pointer <byte> lp;
            Pointer <byte> word = PointerHelpers.Malloc <byte>(1024);

            lp = line + (int)off;

            /* Read transition matrix id */
            if ((stdio.sscanf_d_n(lp, out n, out wlen) != 1) || (n < 0))
            {
                err.E_FATAL(string.Format("Missing or bad transition matrix id: {0}\n", cstring.FromCString(line)));
            }
            m.Deref.phone[p].tmat = n;
            if (m.Deref.n_tmat <= n)
            {
                err.E_FATAL(string.Format("tmat-id({0}) > #tmat in header({1}): {2}\n", n, m.Deref.n_tmat,
                                          cstring.FromCString(line)));
            }
            lp += wlen;

            /* Read senone mappings for each emitting state */
            for (n = 0; n < m.Deref.n_emit_state; n++)
            {
                if ((stdio.sscanf_d_n(lp, out s, out wlen) != 1) || (s < 0))
                {
                    err.E_FATAL(string.Format("Missing or bad state[{0}].Deref.senone mapping: {1}\n", n,
                                              cstring.FromCString(line)));
                }

                if ((p < m.Deref.n_ciphone) && (m.Deref.n_ci_sen <= s))
                {
                    err.E_FATAL(string.Format("CI-senone-id({0}) > #CI-senones({1}): {2}\n", s,
                                              m.Deref.n_ci_sen, cstring.FromCString(line)));
                }
                if (m.Deref.n_sen <= s)
                {
                    err.E_FATAL(string.Format("Senone-id({0}) > #senones({1}): {2}\n", s, m.Deref.n_sen,
                                              cstring.FromCString(line)));
                }

                Pointer <ushort> tmp = m.Deref.sseq[p];
                tmp[n] = (ushort)s;
                lp    += wlen;
            }

            /* Check for the last non-emitting state N */
            if ((stdio.sscanf_s_n(lp, word, out wlen) != 1) || (cstring.strcmp(word, cstring.ToCString("N")) != 0))
            {
                err.E_FATAL(string.Format("Missing non-emitting state spec: {0}\n", cstring.FromCString(line)));
            }
            lp += wlen;

            /* Check for end of line */
            if (stdio.sscanf_s_n(lp, word, out wlen) == 1)
            {
                err.E_FATAL(string.Format("Non-empty beyond non-emitting final state: {0}\n", cstring.FromCString(line)));
            }
        }
Esempio n. 20
0
 public static MethodBuilder <TDelegate> Start(long moduleVersionPtr, int mdToken, int opCode, string methodName)
 {
     return(new MethodBuilder <TDelegate>(
                PointerHelpers.GetGuidFromNativePointer(moduleVersionPtr),
                mdToken,
                opCode,
                methodName));
 }
Esempio n. 21
0
        public void TestPointerToBoolean()
        {
            Pointer <int> ptr = default(Pointer <int>);

            Assert.IsFalse(ptr.IsNonNull);
            ptr = PointerHelpers.Malloc <int>(10);
            Assert.IsTrue(ptr.IsNonNull);
            ptr.Free();
            Assert.IsFalse(ptr.IsNonNull);
        }
Esempio n. 22
0
        internal unsafe Boolean LoadLibrary(Byte[] data)
        {
            //fnDllEntry dllEntry;
            IMAGE_DOS_HEADER dosHeader = PointerHelpers.ToStruct <IMAGE_DOS_HEADER>(data);

            IMAGE_NT_HEADERS oldHeader = PointerHelpers.ToStruct <IMAGE_NT_HEADERS>(data, (UInt32)dosHeader.e_lfanew);

            IntPtr code = (IntPtr)(Win32Imports.VirtualAlloc(oldHeader.OptionalHeader.ImageBase, oldHeader.OptionalHeader.SizeOfImage, Win32Constants.MEM_RESERVE, Win32Constants.PAGE_READWRITE));

            if (code == IntPtr.Zero)
            {
                code = (IntPtr)(Win32Imports.VirtualAlloc((UInt32)code, oldHeader.OptionalHeader.SizeOfImage, Win32Constants.MEM_RESERVE, Win32Constants.PAGE_READWRITE));
            }

            _module = new MEMORYMODULE {
                codeBase = code, numModules = 0, modules = new IntPtr(0), initialized = 0
            };

            Win32Imports.VirtualAlloc((UInt32)code, oldHeader.OptionalHeader.SizeOfImage, Win32Constants.MEM_COMMIT, Win32Constants.PAGE_READWRITE);

            IntPtr headers = (IntPtr)(Win32Imports.VirtualAlloc((UInt32)code, oldHeader.OptionalHeader.SizeOfHeaders, Win32Constants.MEM_COMMIT, Win32Constants.PAGE_READWRITE));

            Marshal.Copy(data, 0, headers, (Int32)(dosHeader.e_lfanew + oldHeader.OptionalHeader.SizeOfHeaders));

            _module.headers = PointerHelpers.ToStruct <IMAGE_NT_HEADERS>(headers, (UInt32)dosHeader.e_lfanew);
            _module.headers.OptionalHeader.ImageBase = (UInt32)code;

            this.CopySections(data, oldHeader, headers, dosHeader);

            UInt32 locationDelta = (UInt32)(code.ToInt32() - oldHeader.OptionalHeader.ImageBase);

            if (locationDelta != 0)
            {
                this.PerformBaseRelocation(locationDelta);
            }

            this.BuildImportTable();
            this.FinalizeSections(headers, dosHeader, oldHeader);

            Boolean success = false;

            try
            {
                fnDllEntry dllEntry =
                    (fnDllEntry)Marshal.GetDelegateForFunctionPointer(
                        new IntPtr(_module.codeBase.ToInt32() + (Int32)_module.headers.OptionalHeader.AddressOfEntryPoint),
                        typeof(fnDllEntry));
                success = dllEntry(code.ToInt32(), 1, (void *)0);
            } catch (Exception exc)
            {
                System.Diagnostics.Trace.WriteLine(exc.Message);
                return(false);
            }
            return(success);
        }
Esempio n. 23
0
        public static void phone_loop_search_free_renorm(phone_loop_search_t pls)
        {
            Pointer <gnode_t> gn;

            for (gn = pls.renorm; gn.IsNonNull; gn = glist.gnode_next(gn))
            {
                ckd_alloc.ckd_free((Pointer <phone_loop_renorm_t>)glist.gnode_ptr(gn));
            }
            glist.glist_free(pls.renorm);
            pls.renorm = PointerHelpers.NULL <gnode_t>();
        }
Esempio n. 24
0
        public static Pointer <byte> cmd_ln_str_r(Pointer <cmd_ln_t> cmdln, Pointer <byte> name)
        {
            Pointer <cmd_ln_val_t> val;

            val = cmd_ln_access_r(cmdln, name);
            if (val.IsNull || val.Deref.val == null)
            {
                return(PointerHelpers.NULL <byte>());
            }
            return((Pointer <byte>)val.Deref.val);
        }
Esempio n. 25
0
        public static object hash_table_replace_bkey(Pointer <hash_table_t> h, Pointer <byte> key, uint len, object val)
        {
            uint           hash;
            Pointer <byte> str;

            str  = makekey(key, len, PointerHelpers.NULL <byte>());
            hash = key2hash(h, str);
            ckd_alloc.ckd_free(str);

            return(enter(h, hash, key, len, val, 1));
        }
Esempio n. 26
0
        public static T hash_table_enter_bkey <T>(Pointer <hash_table_t> h, Pointer <byte> key, uint len, T val)
        {
            uint           hash;
            Pointer <byte> str;

            str  = makekey(key, len, PointerHelpers.NULL <byte>());
            hash = key2hash(h, str);
            ckd_alloc.ckd_free(str);

            return(enter(h, hash, key, len, val, 0));
        }
Esempio n. 27
0
        public void TestPointerIncrement()
        {
            Pointer <int> ptr  = PointerHelpers.Malloc <int>(10);
            Pointer <int> ptr2 = ptr;

            for (int c = 0; c < 10; c++, ptr2++)
            {
                ptr[c] = c;
                Assert.AreEqual(c, ptr2.Deref);
            }
        }
Esempio n. 28
0
        public static object hash_table_delete_bkey(Pointer <hash_table_t> h, Pointer <byte> key, uint len)
        {
            uint           hash;
            Pointer <byte> str;

            str  = makekey(key, len, PointerHelpers.NULL <byte>());
            hash = key2hash(h, str);
            ckd_alloc.ckd_free(str);

            return(delete(h, hash, key, len));
        }
Esempio n. 29
0
        public static Pointer <cmd_ln_val_t> cmd_ln_access_r(Pointer <cmd_ln_t> cmdln, Pointer <byte> name)
        {
            BoxedValue <object> val = new BoxedValue <object>();

            if (hash_table.hash_table_lookup(cmdln.Deref.ht, name, val) < 0)
            {
                err.E_ERROR(string.Format("Unknown argument: {0}\n", cstring.FromCString(name)));
                return(PointerHelpers.NULL <cmd_ln_val_t>());
            }
            return((Pointer <cmd_ln_val_t>)val.Val);
        }
Esempio n. 30
0
        public void TestPointerDeref()
        {
            Pointer <int> ptr = PointerHelpers.Malloc <int>(10);

            Assert.AreEqual(0, +ptr);
            ptr = PointerHelpers.Malloc <int>(0);
            try
            {
                int x = +ptr;
                Assert.Fail("Should have thrown exception");
            }
            catch (Exception) { }
        }