So without the context, I have a method that returns a table.
Trying to print it out, it seems that the table mainly contains methods to be called.
However not being very knowledgeable in LUA, i have no idea how to properly get some information about these methods i should call.
I tried to get documentation from the creator of the thing, but there is none as far as i know. And since this is inside computercraft (minecraft mod) i don't have a lot of features to rely on either.
So knowing only that it is a table with methods that i can call, how do i properly figure out how to call them, and with what parameters etc. ?
Generally speaking, modules/ libraries always come with docs, or a method to print the docs.
But if this is not the case, here's what you can do:
You can print everything in the table! This is a must, the names of the methods can be very useful
You can seek out help! Find people who have used the same module, and ask them how it works. Why solve something others have already figured out?
Use debug.getinfo and other hacky functions for the debug library! They can provide more info than anything else in the Lua standard libraries!
C-Side coding can reveal what Lua cannot! If you have access to the C-Side you can see exactly what the code is doing (or at least I think so)
Check out the source code! This shows you what the code does and how it does it
And above all else, experiment! Try the methods on different parameters, different values, and identify what it does through continuous testing!
Just knowing the names of the methods is not enough to figure how to call them.
Their names may be a clue, but there is no guarantee.
If the methods are written in Lua, you could use the debug API to discover the names of parameters, which again may just be an indication of how to call the methods.
Bottom line: you need documentation or example code.
I knew this existed, didn't know how it worked. So for future reference:
You can dump your peripherals and methods by doing /op_dump in the minecraft chat.
This generates an XML which writes out all methods it has found in peripherals OR objects/tables.
This means that you have to call every interesting method once, which generates the table as return. And then calling /op_dump will include that newly encountered object with all information about there methods/parameters etc.
Related
I'm still new and learning the way to write checkers for static clang analyzer. I need to do the checker on Linux based, and I've read a lot of materials from blogs and websites, but almost all of them are based on Xcode, and none of them are telling me how to search a specific system call.
I'm trying to write a checker on Linux which can tell users that the system call they are using is dangerous, and showing the reason why it may be leak.
Could anyone tell me if it is possible to do this kind of checker? And if it could be made, how should I do or where can I find these materials to do it?
This guide, How to write a Checker in 24 hours is pretty informative and includes an example of identifying calls to fopen around the 34th slide. I highly recommend looking at it yourself but I'll try and summarize the most relevant parts to get you started.
Each checker registers callback functions that are called to check certain properties. In your case your checker will make use of a call event function:
void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
This member function on your checker will get called every time the static analyzer engine comes across a call event. You simply need to define your function to check if the call event is to the system call your are checking for. In the linked example they are looking for calls to fopen and so the beginning of their checkPostCall function looks something like this:
if(Call.isGlobalCFunction("fopen"))
//do stuff
Hopefully that's enough to help get your started!
Recently i caught with the a thought of changing the implementation of method after deployment
When i googled about objective c runtime and all, came to know about method swizzling methodExchangeImplementations etc.
I know that it could be possible by https://rollout.io/
But my thought is how to do Hot Patching by myself for simple things.
my idea is injecting the code using webservice call.
Webservice should give a replacement for particular method.
That string has to be converted to executable code
What i want to know is ...
How to inject the code in existing method of enterprise application.
For ex:
Consider this method in objective c
-(void)fetchTheResult{
// some code lines
}
After deployment i would like to change the method implementation to
-(void)fetchTheresult{
NSLog(#"test log");
//some Code lines
//some more lines
}
Please guide me the way to achieve this
This is a big question and you've some research to do to figure out an answer. Here as some things you can look into:
First you've referenced Rollout, you could follow the same idea and send your update as JavaScript. You'll need to study how to call JavaScript, swizzle methods, and probably dynamically add methods - more on that in a moment.
An alternative you can investigate is dynamic library loading - you can open, and call code in, a library which your app loads at runtime. So you could look at sending your update as a library. You'll still need to do method swizzling and probably dynamically add methods...
As well as method swizzling you may find you need to dynamically add methods - e.g. so you have something to swap the existing implementation to. A good place to find out how to do that is Mike Ash's writings on KVO - go DuckDuckGo (or Google)
HTH
It is not as easy as you think, at least in Objective C and other similar compiled languages. This kind of runtime changes to the code is only possible in interpreted languages like Javascript.
The basic problem is, the apps are not allowed to change the executable files themselves. The apps on iOS and Android run in a sandboxed environment, and thus have access to limited disk locations only.
Also, after compiling the code, the code does not know where the part of code is converted and stored in machine language. You have to understand the basics of compilers to understand this. There are heavy optimisations happening to your code during this process.
My code is based on the example from this website but the difference is that I want to be able to play two different things: Note objects and Song objects. I think there are two ways for me to do this.
First way I thought of is having two different implementations of the RenderTone method and call the appropriate one based on what I want to play. I don't know if this is possible though and if it is, I don't know how to do it so any suggestions on this are welcome.
The second way I thought of is to have a PlaybackHelper Singleton class (I'll never play more than one thing at the same time) that has a datamember that contains the object I want to play. I could add all the information to this object before the RenderTone method is called, and I could reset everything one playback is finished. I'm not sure if this is a very clean way to do things though. Especially since I won't have a constructor and I'll have to reset everything before and after using the class.
What do you guys think? Any advice or alternative/better suggestions are welcome!
I have been trying to understand the concept of 'hooking' APIs and am currently facing a problem. I hope that experts here can clear it:
By going through a header file I noticed that the LoadLibrary function is actually mapped to one of the following two: LoadLibraryW or LoadLibraryA based on the flag used during compilation (UNICODE or ASCII, respectively). Now, if I have explicitly hooked the API 'LoadLibraryA' then will my hooked function get the control if it is compiled using the UNICODE flag?
It would be great if someone could explain or point me to a link that explains in detail how hooking works in such cases? How do compilation flags, character sets, locale, internationalization, impact hooking of APIs like LoadLibrary or CreateFile?
I'm currently in South Korea (Originally from UK) and for some reason some of my application is not working and I have a demo tomorrow. I presume the above mentioned doubt is the reason for the problem I'm facing.
I think that you need to read carefully this bible of api hooking Hooking in theory which explains everything about hooking like different approaches of hooking, lot of diagrams.... and also this one example. My suggestion is to use LoadLibraryW because it is superset of Acsii.
Bye
What's the best way to set up help (specifically HTML Help) for a Delphi application? I can see several options, all of which has disadvantages. Specifically:
I could set HelpContext in the forms designer wherever appropriate, but then I'm stuck having to track numbers instead of symbolic constants.
I could set HelpContext programmatically. Then I can use symbolic constants, but I'd have more code to keep up with, and I couldn't easily check the text DFMs to see which forms still need help.
I could set HelpKeyword, but since that does a keyword lookup (like Application.HelpKeyword) rather than a topic jump (like Application.HelpJump), I'd have to make sure that each of my help pages has a unique, non-changing, top-level keyword; this seems like extra work. (And there are HelpKeyword-related VCL bugs like this and this.)
I could set HelpKeyword, set an Application.OnHelp handler to convert HelpKeyword requests to HelpJump requests so that I can assign help by topic ID instead of keyword lookup, and add code such as my own help viewer (based on HelpScribble's code) that fixes the VCL bugs and lets HelpJump work with anchors. By this point, though, I feel like I'm working against the VCL rather than with it.
Which approach did you choose for your app?
When I first started researching how to do this several years ago, I first got the "All About help files in Borland Delphi" tutorial from: http://www.ec-software.com/support_tutorials.html
In that document, the section "Preparing a help file for context sensitive help" (which in my version of the document starts on page 28). It describes a nice numbering scheme you can use to organize your numbers into sections, e.g. Starting with 100000 for your main form and continuing with 101000 or 110000 for each secondary form, etc.
But then I wanted to use descriptive string IDs instead of numbers for my Help topics. I started using THelpRouter, which is part of EC Software's free Help Suite at: http://www.ec-software.com/downloads_delphi.html
But then I settled on a Help tool that supported string ID's directly for topics (I use Dr. Explain: http://www.drexplain.com/) so now I simply use HelpJump, e.g.:
Application.HelpJump('UGQuickStart');
I hope that helps.
We use symbolic constants. Yes, it is a bit more work, but it pays off. Especially because some of our dialogs are dynamically built and sometimes require different help IDs.
I create the help file, which gets the help topic ID, and then go around the forms and set their HelpContext values to them. Since the level of maintenance needed is very low - the form is unlikely to change help file context unless something major happens - this works just fine.
We use Help&Manual - its a wonderful tool, outputting almost any format of stuff you could want, doc, rtf, html, pdf - all from the same source. It will even read in (or paste from rtf (eg MSWord). It uses topic ID's (strings) which I just keep a list of and I manually put each one into a form (or class) as it suits me. Sounds difficult but trust me you'll spend far longer hating the wrong authouring tool. I spent years finding it!
Brian