How does this asm code setup SEH? - exception

I grabbed some code from internet, that supposed to handle exceptions with SEH,
ASSUME FS:NOTHING
PUSH OFFSET Handler
PUSH FS:[0]
MOV FS:[0], ESP
...
But the FS:[0] should be holding the address of handler instead right?
So mov fs:[0], esp is wrong, because esp currently pointed to the original fs:[0]:
The stack is like this:
-----------
| fs:[0] | <-- ESP
-----------
| handler |
-----------
So, shouldn't that be esp + 4 like stuff? I'm obviously wrong, but I don't get why.

[fs:0] points to the last element in the linked list of exception handlers.
Each element contains two things:
the address of the next/previous element
the address of a handler/function
The code that you presented creates another element, links it to the current/last element, and makes the new element the current/last one.
Look up Matt Pietrek's articles on SEH. This stuff is described there in greater detail.

Related

Passing a list as the parameter of a template

I have created a Template in my MediaWiki which I want to pass "free text" to. To keep it simple, imagine it as a table in which the first named parameter goes into cell 1 and the other named parameter goes into cell 2.
Writing the Template itself seemed easy enough, but I keep stumbling into errors when I try to pass certain structures in the arguments. My first issue was with a code block: if I wrote
{{MyTemplate|first=
// code...
|other=
// other code instead...
}}
then the wiki thought that the pipe character was part of the preformatted text block, and in the end I ended up without a second parameter. This issue was solved using <pre></pre>, but I thought it was more of a workaround than a solution.
Now I'm in trouble again when I try to pass a list:
{{MyTemplate|first=
* Item 1a
* Item 2a
|other=
* Item 1b
* Item 2b
}}
Again, I end up with the first item (Item 1a) ignored (not rendered as a list item), the second rendered ok (Item 2a, as a list item), then a double pipe, an asterisk and "Item 1b", then the list goes on with "Item 2b".
I am clearly doing something wrong, but I have no idea what to do, nor I could find any useful example in the docs. Please help me understand how to correctly pass any text (which may include lists or other markdown constructs) as a template argument.
EDIT
Here is the code of my Template:
{|
!First !!Other
|-
|{{{first|}}} ||{{{other|}}}
|}
Also, I'm sorry, but I typed the usage wrong: the four more spaces were a leftover from the snippet above. I've fixed that.
#Ivanhercaz I've tried your suggestion (which only differs from mine for the empty lines), and still got the same result.
In this case I have to suppose how is the template you created, because you didn't shared the structure, just how you call and two parameters. Because of this reason I am going to suppose that you create a template as:
{{{first|}}}
{{{other|}}}
About your first question, you can use {{!}} to escape the pipe character (|). From the version 1.24 this is a magic word, but before the solution to this issue was to create a template with a pipe and then replace the | by {{!}}. The use of the magic word is the same, but you is unnecessary to create the template.
About your second question, taking in account that you have a similar structure to what I wrote at the top of this answer, if I wrote a page with this:
{{MyTemplate|first=
* Item 1a
* Item 2a
|other=
* Item 1b
* Item 2b
}}
I get a two lists and two code blocks: list one with "Item 1a" and the first code block with * Item 2a; list two with "Item 2a" and the second code block with * Item 2b. It doesn't seem to what you get rendered:
the first item (Item 1a) ignored (not rendered as a list item), the second rendered ok (Item 2a, as a list item), then a double pipe, an asterisk and "Item 1b", then the list goes on with "Item 2b". This happened due to the extra space before the * in the parameters.
So I recommend to you to share the code of the template to check and answer to you better. Of course, if what you want is to pass two different lists in each parameter you could make something like:
{{Test|first=
* Item 1a
* Item 2a
|other=
* Item 1b
* Item 2b
}}
This structure solved the problem I mentioned. But I wait your comment to be sure and edit my answer if it is necessary.
Edit
Now, with the code of the template I understand your problem. To work correctly and without problems with templates, tables and lists you have to consider that the * need to have an line break after the | and ||. What I recommend to you is insert this line breaks
{|
! Wikitext !! Rendering
|-
|
{{{first|}}}
||
{{{other|}}}
|}
I think it is an easy and clean way to do what you are trying. So, if you use the template in this way:
{{Test
|first=* Item 1a
* Item 2a
|other=* Item 1b
* Item 2b
}}
Or in this other way:
{{Test
|first=
* Item 1a
* Item 2a
|other=
* Item 1b
* Item 2b
}}
You will have a table like that (I add a class=wikitable to have a more beautiful table to show):
I hope this trick has been helpful.

How to use Wikipedia's API to scrape only the template:Infobox Automobile

I'm trying to scrape the helpful Infobox from most Automobile pages, however I'm messing up the syntax. From other helpful SO posts, I've found a handy method of scraping a standard Infobox template (the example given was for hydrogen):
https://en.m.wikipedia.org/w/index.php?action=raw&title=Template:Infobox%20hydrogen
I can use a similar process to pull the Ford Pinto page (using this as it only has a single Infobox, as there was only one, infamous, model generation):
https://en.m.wikipedia.org/w/index.php?action=raw&title=Ford_Pinto
This page, and most automobile pages, used one of the vehicle-specific Infobox templates, in this case "Infobox automobile" (sorry for the massive block, I'm going to edit this once it's posted as I'm on mobile and I read up on SO formatting):
{{Infobox automobile
| name = Ford Pinto
| image = Ford Pinto.jpg
| caption = Ford Pinto
| manufacturer = [[Ford Motor Company|Ford]]
| aka = Mercury Bobcat
| production = September 1970–1980
| model_years = 1971–1980 (Pinto)<br> 1974–1980 (Bobcat)
| assembly = '''United States:''' {{ubl|[[Edison, New Jersey]] ([[Edison Assembly]])|[[Milpitas, California]] ([[San Jose Assembly Plant|San Jose Assembly]])}}'''Canada:''' {{ubl|[[Southwold, Ontario]] ([[St. Thomas Assembly]])}}
| designer = Robert Eidschun (1968)<ref name=bbw20091030>
...
Snipped some useless stuff
...
</ref>
| class = [[Subcompact car]]
| body_style = 2-door [[Sedan (automobile)|sedan]]<br/>2-door [[sedan delivery]]<br/>2-door [[station wagon]]<br/> 3-door [[hatchback]]
| related = [[Ford Pinto#Mercury Bobcat (1974–1980)|Mercury Bobcat]]<br>[[Ford Mustang (second generation)|Ford Mustang II]]<br> [[Pangra]]
| layout = [[Front-engine, rear-wheel-drive layout|FR layout]]
| engine = {{unbulleted list
| 1.6L ''[[Ford Kent engine|Kent]]'' I4
| 2.0L ''[[Ford Pinto engine|EAO]]'' I4
| 2.3L ''[[Ford Pinto engine|OHC]]'' I4
| 2.8L ''[[Ford Cologne engine|Cologne]]'' V6
}}
| transmission = {{unbulleted list
| 4-speed manual
| 3-speed ''[[Ford C3 transmission|C3/"Selectshift/Cruise-O-Matic"]]'' automatic
...
Snipped
...
</ref>
|wheelbase = {{convert|94.0|in|mm|abbr=on}}<ref>
...
Snipped
...
}}
| wheelbase = {{convert|94.0|in|mm|abbr=on}}<ref>
...
Snipped
...
</ref>
| length = {{convert|163|in|mm|abbr=on}}
| width = {{convert|69.4|in|mm|abbr=on}}
| height = {{convert|50|in|mm|abbr=on}}
| weight = {{convert|2015|–|2270|lb|abbr=on}} (1971)
| predecessor = [[Ford Cortina|Ford Cortina (captive import)]]
| successor = [[Ford Escort (North America)|Ford Escort]]
}}
Though not as pretty as the above, another alternative is to use the REST API and slim the page down to just the article, in HTML, which will let me use a standard HTML parser to pull just the Infobox HTML table (link should work in chrome, but will definitely work on an Android device):
view-source:https://en.wikipedia.org/api/rest_v1/page/html/Ford_Pinto
<table class="infobox hproduct" style="width:22em" about="#mwt7" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Infobox automobile\n","href":"./Template:Infobox_automobile"}
I can handle parsing either of these for the information I want, namely performance information - model, years, drivetrain layout, engines, transmissions, wheelbase, weight - however despite trying various API/other urls, I've yet been unable to directly scrape just the Infobox using the API alone. Also, I'm not exactly sure what the difference is between using an api.php? action=parse url vs an index.php? action=raw - any clarification here is welcome, though I don't think directly relevant. Here are some unsuccessful examples of what I have tried, each with different errors/results:
https://en.wikipedia.org/w/ <- append the following to this base link as I can't post a bunch of links
api.php?action=parse&page=Template:Infobox%20automobile%20Ford_Pinto&format=json
api.php?action=query&titles=Template:Infobox%20automobile%20Ford%20Pinto&prop=revisions&rvprop=content&format=json&formatversion=2
api.php?action=query&titles=Template:Infobox%20automobile%20Ford_Pinto&prop=revisions&rvprop=content&format=json&formatversion=2
index.php?action=raw&title=Template:Infobox%20automobile%20Ford_Pinto
index.php?action=raw&title=Template:Infobox%20automobile%20Ford%20Pinto
index.php?action=raw&titles=Template:Infobox%20automobile%20Ford_Pinto
index.php?action=raw&titles=Template:Infobox%20automobile%20Ford%20Pinto
This is different from various other Infobox scraping questions as these articles use a specific Infobox template that prevents me from using the very successful API url I've posted above, although I'm sure this is user error and a simple fix. Thank you for your time in reading and assisting!
Edit: the suggested page is the way I'm already trying, and failing. Per that page, I am attempting the 'wrong' way until someone, including myself, figures out what I'm doing wrong - assuming there is a right way for the non standardized/base Infobox Templates. Failing any new information in a day or so, I'll just accept the currently suggested answer to reward that user's helpfulness - but I really hoped I'd get a few more attempts, which is why I created an account and asked the hive mind after searching and failing to find an answer from the many other questions I checked. By the way, any attention is good attention, so thank you kindly for taking the time to look over this!
Wikipedia infoboxes are not designed to be scrapeable. They are primarily a (front-end!) templating mechanism; the fact that they sometimes contain structured data is incidental.
The difference between action=raw and action=parse is simply that raw gives you the original wikitext (like you'd see if you clicked the "Edit" link on the article), and parse gives you the rendered HTML. Neither of these is likely to be much use for your purposes.
Your best bet will be to use data from a downstream project like DBpedia which has already done the dirty work of parsing these articles. For instance, here's their parsed data for the Ford Pinto:
http://dbpedia.org/snorql/?describe=http%3A//dbpedia.org/resource/Ford_Pinto
You could use the Parsoid output of the page https://en.wikipedia.org/api/rest_v1/page/html/Ford_Pinto, which has a table with class infobox and a data-mw with some JSON encoded data.
I would look for the infoboxes (CSS selector table.infobox) and run a JSON.parse on the data-mw value. Check if the infobox has href ./Template:Infobox_automobile then look for the right parameter (in the params field).
Here's a sample request:
curl -X GET --header 'Accept: text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/1.6.1"' 'https://en.wikipedia.org/api/rest_v1/page/html/Ford_Pinto'
In addition to the Accept header it's also good to set the User-Agent header to a unique string.

SSRS Trying to add a page break between 2 Subreports which are grouped in parent.rdl

So I have a report that I was able to get almost exactly how I wanted it, but I can't manage to get a page break between the 2 subreports. Help would be highly appreciated.
I have 3 reports
PARENT.rdl
SUBREPORT_1.rdl
SUBREPORT_2.rdl
SUBREPORT_1 and SUBREPORT_2 share a common field (for example city) so I'm able to group them inside the PARENT.rdl so it has this type of format:
What I have looks like this:
SUBREPORT_1: MIAMI
SUBREPORT_2: MIAMI
----- page break ------
SUBREPORT_1: ORLANDO
SUBREPORT_2: ORLANDO
----- page break ------
SUBREPORT_1: TAMPA
SUBREPORT_2: TAMPA
I have all of this working perfectly, my only problem is I'd like to add a page break between SUBREPORT_1 and SUBREPORT_2. There is already a page break at the end of the City grouping. I want it to look like:
SUBREPORT_1: MIAMI
-- page break -- << add this
SUBREPORT_2: MIAMI
----- page break ------
SUBREPORT_1: ORLANDO
-- page break -- << add this
SUBREPORT_2: ORLANDO
----- page break ------
SUBREPORT_1: TAMPA
-- page break -- << add this
SUBREPORT_2: TAMPA
I've tried putting the subreports in rectangles inside of the tablix cells, but no luck. I'm assuming because of the PARENT tablix can't be broken up mid-tablix ?
Any help with this would be great, of if there is a better solution than the subreport method. That is what I found in my research.
Thanks
When you placed your subreport inside the rectangle did you check the subreport properties to make sure the Parent under the "other" in properties was the rectangle? If it isnt you'll need to drag the subreport out of the rectangle and then back into it so it becomes the parent item then set the rectangle to have a page break.

In a Sublime Text 2 snippet, how do I transform a user entered parameter ${1:Param/^\w/\u$&/}?

I am trying to make a ST2 snippet to insert a comment "section" in my PHP code. I am attempting to achieve something like the following:
// --------------------------------------------------
// ${1:Enter section title here/^(.*)$/\U\1/}
// --------------------------------------------------
So that when the snippet is triggered, a user might enter "dumb loop" as $1, and it would be transformed to "DUMB LOOP".
The problem is, I am getting errors when I try to do this. Am I correct in assuming ST2 doesn't support this? The best I am able to do to achieve this right now is:
// --------------------------------------------------
// ${1/^(.*)$/\U\1/}
// --------------------------------------------------
// DELETE THIS LINE: $1
Which more or less enters junk text into the snippet because that last line is only needed to "create" parameter 1, so that it can be correctly transformed and placed where it should go.
Is there any way to transform a snippet parameter in the same place it is defined/located?! Thanks!!

How do I remove the last item of an array?

I have an array of questions for an interactive quiz game. When you answer a question, functionally I want that question to be removed from the array (cat4Questions) so that it won't come back for the player so I tried to splice it.
I wasn't sure if it was working so I traced the array. While I was expecting "question1, question2, question3, question4" to be traced, "question1, question2, question3, question4, question5" was the result of my trace.
This is the line of code where I try to splice the array:
cat4Questions.splice(cat4Questions.length,1);
trace(cat4Questions);
You should take a look at shift() and pop() array methods.
shift()
Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.
pop()
Removes the last element from an array and returns the value of that element.
In your case, you probably need the pop() function to remove the last element of the array.
Arrays are zero-indexed, so you should use Array.length-1; to get the index position of the array.
cat4Questions.splice(cat4Questions.length-1,1);
trace(cat4Questions);
trace now.
You are probably going to remove items other than the last item in the array. If for example the user answers another question.
You can use this code to remove any question:
cat4Questions.splice(cat4Questions.indexOf(question), 1);
Edit
As I said in the comments below, you don't really have to look at the performance of this. But here is how to use pop instead of splice.
cat4Questions[cat4Questions.indexOf(question)] = cat4Questions.pop();
You can also remove the calls to pop and indexOf because they are not efficient either
lastQuestion = cat4Questions[--numQuestions];
cat4Questions[question.index] = lastQuestion;
lastQuestion.index = question.index;
Where question is the question to be removed, index is the index of the question (you have to keep track of that) and numQuestions is the total number of questions. This way, you never use length, indexOf, pop, splice, ...