I am trying to use the Debug API's to solve some specific problem and I track the LOAD_DLL_DEBUG_EVENT to be informed if a specific dll module is loaded, (the dll module actually is an exe file).
I use:
GetModuleFileNameEx(
hCurrentProcess,
(HMODULE)pDebugEv->u.LoadDll.lpBaseOfDll,
szModuleFileName,
sizeof(szModuleFileName) / sizeof(TCHAR)
);
in order to obtain the loaded module's filename.
To my surprise what I get instead are multiple references to cryptbase.dll being loaded, each on a different tid, but not the module in question.
I don't want to go the hard way of hooking cryptbase.dll and its associated import calls so is there an easier solution to obtain the loaded module's filename ?
Related
the project I involved has composer require fengqi/hanzi into the vendor folder, which is used to convert simplified Chinese and traditional Chinese
For people who want to take a look at the package https://github.com/fengqi/hanzi
Inside the vendor folder, the package has the following example directory structure:
vendor/
--hanzi/
----src/
------Hanzi.php
------HanziDict.php
------Pinyin.php
The specific file HanziDict.php I want to modify has a really simple code structure:
<?php namespace fengqi\Hanzi;
return array (
'啊' => '啊',
...
...
'sample char A'=>'sample char B'
);
The github repository of the package suggested that I can insert any "char C => char D" inside the php file if I found the certain chars are missing from the dictionary.
But I believe I should not directly put the code inside vendor folder since it will be override after update.
So, my problem is how I can properly override/extend this file in Laravel (such as insert "char C => char D" into the array).
I already read and know how to properly extend class outside of vendor folder but did not find any useful information about other types of php files. I wonder if there is certain ways or rules to do with this kinds of files.
Ideally I want to achieve something like:
outside of the vendor folder, I have an expanded ExtraHanziDict.php. So it can always build upon the vendor dict.php.
The following links is the vendor class code (only fewer simple functions to read the dict and convert character)
https://github.com/fengqi/hanzi/blob/master/src/Hanzi.php (apology for throwing the code)
Unfortunately, in this case, there's no easy way to change the dictionary. As you correctly guessed you should never change the content of the vendor folder as it's not committed to version control.
In your specific case what you can do is:
Ask the repository mantainer to add an api that allows you to add new dictionaries at runtime.
Fork the repository, change what you need, and use that instead (see loading a custom git repository with composer). If you think your changes can be useful to others open a Pull request on the original repository.
There's no much logic on the repository you linked. Each package you add to your composer.json file is a burden, code that doesn't belongs to you and you MUST blindly thrust (what if at some point the repository is hacked and some malicious code hidden into it?). Just create your own service to do such a simple task.
I am trying to optimize a RequireJS project first for HTTP/2 and SPDY, and secondly for HTTP/1.x. Rather than concatenating all of my RequireJS modules into one big file, I am hacking r.js to resave the modules that would have been concatenated as separate files. This will be better for the new protocols, because each file will be cached individually, and a change to one file won't invalidate the caches of all the other files. For the old protocols, I will pay a penalty in additional HTTP requests, but I can at least avoid subsequent rounds of requests by appending revision hashes to my files (i.e. "module.js" becomes "module.89abcdef.js") and setting a long max-age on them, so I want to do that.
r.js adds names to previously-anonymous modules. That means that the file "module.js" with this definition:
define(function () { ... })
Becomes this:
define("module.js", function () { ... })
I want this, because I will be loading some of my modules via <script> elements (to prevent RequireJS HTTP requests acting as a bottleneck to dependency resolution; I can instead utilize r.js's topological sorting to generate <script> elements which the browser can start loading as soon as it parses them). However, I also plan to load some modules dynamically (i.e., via RequireJS's programmatic insertion of <script> elements). This means RequireJS may at some point request a module via a URL.
Here is the problem I have run into: I am generating a RequireJS map configuration object to map my modules' original module IDs to their revision-hashed module IDs, so that when RequireJS loads a module dynamically, it requests the revision-hashed file name. But the modules it loads, which are now named modules thanks to r.js, have the un-revisioned name of the module, because I don't revision the files until after I minify them, which I only do after r.js generates them (thus r.js doesn't know about the revisions).
So the file "module.89abcdef.js" contains the module:
define("module.js", function () { ... })
When these named modules execute, define will register a module with the wrong name. When other modules require "module.js", this name will be mapped to "module.89abcdef.js" (thanks to the map configuration), but since a module with that name was not actually defined after the onload event of a <script> with the src attribute "module.89abcdef.js" fired, the module they receive is undefined.
To be faithful to the new file name, the file "module.89abcdef.js" should probably instead contain the definition:
define("module.89abcdef.js", function () { ... })
So, I believe the solution to my problem will be to replace the unrevisioned name of the module in the r.js-generated file with the revisioned name. However, this means the hash of the file is now invalidated. My question: In this situation, does it matter that the hash of the file is invalid?
I think it's impossible that the module name in the source code could be faithful to the file name, because if the module name had a hash, well, then the hash of the file would be different, so the module name would become the new hash, and so on recursively.
I fear there might be a case where the unfaithful hash would cause the file to still be cached even when it'd actually changed, but I cannot think of one. It seems that appending the same hash for the file's original contents to the file's name and the module's name should always still result in a unique file.
(My lengthy explanation is an attempt to eliminate certain "workaround"-type answers. If I weren't loading modules dynamically, then I wouldn't need to use map and I wouldn't have a file-name-vs-module-name mismatch; but I do load modules dynamically, so that workaround won't work. I also believe I would not need to revision files if I were only serving clients on newer protocols [I could just use ETags as there would be no additional overhead to make the comparison], but I do serve clients on the older protocols, so that workaround doesn't work either. And finally, I don't want to run r.js after revisioning files, because I only want to revision after minifying the files, in case minification maps two sources to the same output, in which case I could avoid an unnecessary cache invalidation.)
As the title suggests my question is pretty simple.
Is there a way to count the total number of active module instances of a specific type/kind in Joomla (with a specific module name)?
I know how to count modules in a specific module position using JModuleHelper::getModules, but that is not what I want.
I simply need to count all active modules instances of a specific type/kind.
Does anyone know how to do this (without having to do a manual MySQL query)?
I do not know if there is an official joomla way, but you can do it by having an sql query looking at
#__modules
table.
Check out this table and you will find out how easy it is.
An example sql would be:
select count(id) from #__modules where module = 'mod_login'
As far as i know there is no joomla method for this. I would recommend (if it has to be done) either
using a crawler to go through all pages of the site counting the instances.
or using a script which goes through the template php files and the database to find all active instances.
Both these methods might not be 100% reliable due to unexpected circumstances (like module being included in article or module included only after a button is clicked on) but could work if you know your site well enough.
Unfortunately there does not seem to be such a function in Joomla.
In my case I needed this to tell me whether or not a instances of this module was > 0 or not.. and my alternative solution was to simply make a module-specific function and then in the module php file check if function is already loaded.
My setup
I have two modules installed:
one takes an id and builds a product collection from this using the id to lookup an attribute-value pair (mod1)
The other offers a way of narrowing a search down (mod2)
The true url I am on is /mod1/page/view/id/<id#>
Desired outcome
To be able to pass the attribute-value as a hidden field to the second module
Question
How do I access the object and functions from mod1 when I'm in the layout file for mod2?
If more information is required, please let me know.
The way the module needed to be loaded was as follows:
Mage::registry('mod1_type');
Where in the controller this had been set:
$mod1Type = Mage::getModel('mod1/type')->setStoreId(Mage::app()->getStore()->getId())->load($mod1TypeId);
Mage::register('mod1_type', $mod1Type);
Then I could use the defined methods normally.
This may be an overly specific issue, should I just delete the question?
I have an addon that every 5 minuets or so checks an rss feed for a new post, and if there is one, it displays an alert(). Problem is, I'm afraid that if the user opens multiple windows, that when there's a new post a millions of alerts will popup saying the same thing. Is there anyway to have just one "brain" running at a time?
Thanks in advance!
Look up something called "Javascript shared code modules" or JSMs.
Primary docs are here:
https://developer.mozilla.org/En/Using_JavaScript_code_modules
Each .js file in your addon that needs shared memory will open with the following line:
Components.utils.import("resource://xxxxxxxx/modules/[yourFilenameHere].jsm", com.myFirefoxAddon.shared);
The above line opens [yourFilenameHere].jsm and loads its exported (see below) functions and variables into the com.myFirefoxAddon.shared object. Each instance of that object loaded will point to the same instance in memory.
Note that if you want to have any hope of you addon making it past moderation, you will need to write all your code in a com.myFirefoxAddon.* type object as the goons at AMO are preventing approval of addons that do not Respect the Global Namespace
The biggest caveat for JSM is that you need to manually export each function that you want to be available to the rest of your code... since JS doesn't support public/private type stuff this strikes me as a sort of poor-man's "public" support... in any case, you will need to create an EXPORTED_SYMBOLS array somewhere in your JSM file and name out each function or object that you want to export, like this:
var EXPORTED_SYMBOLS = [
/* CONSTANTS */
"SERVER_DEBUG",
"SERVER_RELEASE",
"LIST_COUNTRIES",
"LIST_TERRITORIES_NOEX",
/* GLOBAL VARIABLES */
/* note: primitive type variables need to be stored in the globals object */
"urlTable",
"globals",
/* INTERFACES */
"iStrSet",
/* FUNCTIONS */
"globalStartup",
/* OBJECTS */
"thinger",
"myObject"
]
[edited] Modules are not the right solution to this problem, since the code will still be imported into every window and the whatever listeners/timers you set up will run in every window. You should be careful with using modules for this -- all the timers/callbacks must be set up in the module code (not just using the observer object defined in the module) and you shouldn't use any references to the window in the module.
The right way to do this is I would prefer to write an XPCOM component (in JS). It's somewhat complicated, yes and I don't have a handy link explaining how to do it. One thing: implementing it using XPCOMUtils is easier, older documentation will throw lots of boilerplate code on you.