<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Packet template &#x27;alignment&#x27; issue]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I'm evaluating the usage of IO Ninja as a COM sniffer between 2 processors. I'm trying to create a Packet template in order to quickly parse packets. I'm using the help provided in <a href="https://ioninja.com/doc/developer-manual/tutorial-ias-packet.html" rel="nofollow ugc">https://ioninja.com/doc/developer-manual/tutorial-ias-packet.html</a>. However, when i add the 'alignment(1);' line at the beginning of the new template i'm writing and click 'OK' i get the following error <img src="/forum/assets/uploads/files/1678185312545-io_ninja_templatepacket_error.jpg" alt="IO_Ninja_TemplatePacket_Error.jpg" class=" img-responsive img-markdown" width="655" height="580" /> (attached), am i doing something wrong ?<br />
Note, if i remove the 'alignment' line, the parser jumps bytes from field to field...<br />
Please help<br />
Thanks!</p>
]]></description><link>http://64.23.185.212/forum/topic/71/packet-template-alignment-issue</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 22:14:17 GMT</lastBuildDate><atom:link href="http://64.23.185.212/forum/topic/71.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Mar 2023 10:35:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Wed, 19 Apr 2023 03:55:41 GMT]]></title><description><![CDATA[<p dir="auto">Hi again, Chaim,</p>
<p dir="auto">From the first screenshot, I assume, you are running on Windows, correct? Then I will use Windows-style paths and declarations in the samples below.</p>
<ol>
<li>Command line</li>
</ol>
<p dir="auto">Yes. You can open the necessary plugin(s) and start capturing from the command line. There are multiple ways of achieving that, and the easiest would be this.</p>
<p dir="auto">First, configure the session the way you need -- i.e., start the main plugin (e.g., Serial Tap), attach required analyzer plugins (e.g., Modbus RTU, or your own analyzer), and configure all the necessary settings using the UI. Then, save the session somewhere (e.g., <code>C:/Projects/playground/ioninja/my-analyzer-session/my-analyzer-session.njssn</code>)</p>
<p dir="auto">Now, you can start IO Ninja passing it a path to <code>.njssn</code> to automatically open this session. To automatically start capturing, also pass <code>-c</code> (i.e., connect):</p>
<pre><code>ioninja -c &lt;path-to-njssn&gt;
</code></pre>
<ol start="2">
<li>FFI (Foreign Function Interface)</li>
</ol>
<p dir="auto">Yes. One of Jancy design goals was easy and efficient interoperability with C/C++ code. Again, multiple ways of calling external code exist, the most straightforward would be declaring an interface to your C/C++ library via the <code>dynamiclib</code> construct.</p>
<p dir="auto">Let's say, you have a library called <code>my_lib.dll</code> with the following exported C function:</p>
<pre><code>extern "C"
__declspec(dllexport) 
size_t 
my_inverse(
	void* out,
	size_t outSize,
	const void* in,
	size_t inSize
) {
	// inverse the in-buffer and write it to out-buffer
}
</code></pre>
<p dir="auto">In your Jancy code, declare an interface to this library like this:</p>
<pre><code>pragma(ThinPointers, true);

dynamiclib MyLib {
	size_t 
	my_inverse(
		void* out,
		size_t outSize,
		const void* in,
		size_t inSize
	);
}

pragma(ThinPointers, default);
</code></pre>
<p dir="auto">Basically, function declarations are the same as in C/C++; you only have to make sure to use "thin" pointers.</p>
<p dir="auto">Jancy pointers are "fat" -- they include extra information about region, type, etc. To achieve ABI compatibility with C/C++, we need to explicitly declare pointers as "thin", like this:</p>
<pre><code>char thin* p;
</code></pre>
<p dir="auto">If there could be many FFI declarations -- like in an interface to a C/C++ library -- it may be more convenient to implicitly treat ALL pointers as "thin" using <code>pragma(ThinPointers, true)</code>.</p>
<p dir="auto">Now, when you need to call your library, load and call it like this:</p>
<pre><code>MyLib myLib;
myLib.open("path-to-your-lib/my_lib.dll");
myLib.lib.my_inverse(p1, size1, p2, size2);
</code></pre>
<p dir="auto"><img src="/forum/assets/uploads/files/1681875800845-24879c37-2205-4342-ba63-fd938d4f9633-image.png" alt="24879c37-2205-4342-ba63-fd938d4f9633-image.png" class=" img-responsive img-markdown" width="1217" height="799" /></p>
<ol start="3">
<li>Creating an external process is possible, too, of course. However, passing binary data to a process via the command line -- and especially getting an answer back -- would be much less convenient and efficient. If you need to perform some data processing in external code, I strongly recommend using the method shown above, i.e., create a C/C++ library and call it from Jancy. It's both easy to implement and as efficient as it gets in runtime.</li>
</ol>
<p dir="auto">Hope this helps!</p>
]]></description><link>http://64.23.185.212/forum/post/345</link><guid isPermaLink="true">http://64.23.185.212/forum/post/345</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Wed, 19 Apr 2023 03:55:41 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Sun, 16 Apr 2023 12:19:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi Again,<br />
Thanks for the above scripts it really works great !!!<br />
I've presented the protocol analyzer i did to a big forum in out company, and a few question came up.</p>
<ol>
<li>We would like to add this tool as part of our nightly build and validation process. Once a new build is created and deployed to a target, we'd like a way to run the IONinja via a batch file (running some command lines), load the protocol analyzer open the port and start recording the session.  Is it possible to run the IONinja tool via an external API /commandline ? if so, can you send me an example how ?</li>
<li>The protocol analyzer is written in Jancy language. Is there an ability to access in Jancy APIs from DLLs created in C++ or Python ?</li>
<li>Can you activate in Jancy a batch file and do some manipulation on the bytes received ? i.e. pass the received bytes as an argument to a batch file, and get an answer from the batch file ?<br />
Many thanks<br />
Chaim</li>
</ol>
]]></description><link>http://64.23.185.212/forum/post/342</link><guid isPermaLink="true">http://64.23.185.212/forum/post/342</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Sun, 16 Apr 2023 12:19:03 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Thu, 23 Mar 2023 06:54:23 GMT]]></title><description><![CDATA[<p dir="auto">No prob:  <a href="/forum/assets/uploads/files/1679553615392-log_representstruct.jnc">log_RepresentStruct.jnc</a></p>
<p dir="auto"><img src="/forum/assets/uploads/files/1679554419874-241412c7-4af0-4a5b-a23f-8b6603ce643b-image.png" alt="241412c7-4af0-4a5b-a23f-8b6603ce643b-image.png" class=" img-responsive img-markdown" width="1294" height="838" /></p>
<p dir="auto">Just FYI, here's the added part (special handling for struct fields):</p>
<pre><code>/// ...
		if (field.m_type.m_typeKind == jnc.TypeKind.Struct) {
			representation.addHyperText($"%1%2:\t"(indent.m_sz, displayName));
			representStruct(
				representation,
				dynamic (jnc.StructType*)field.m_type,
				displayName,,
				p + field.m_offset,
				baseOffset + field.m_offset,
				0, 0, // no [+/-] header, always expanded
				indentLevel + 1
			);

			continue;
		}
/// ...
</code></pre>
<p dir="auto">Having sub-fields collapsible is theoretically possible but won't scale well -- we have 32 total fold-flags per record, so it's better to assign those statically (rather than from a loop in a recursive function). But I think having struct fields always expanded should be good enough in most cases.</p>
]]></description><link>http://64.23.185.212/forum/post/310</link><guid isPermaLink="true">http://64.23.185.212/forum/post/310</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Thu, 23 Mar 2023 06:54:23 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Mon, 20 Mar 2023 12:21:33 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I tried to modify the 'scripts/common/log_RepresentStruct.jnc' to support nested structures with no success.<br />
Can you please send me a modified version of 'scripts/common/log_RepresentStruct.jnc' that supports nested structures.<br />
It will be a big help.<br />
Thanks</p>
]]></description><link>http://64.23.185.212/forum/post/308</link><guid isPermaLink="true">http://64.23.185.212/forum/post/308</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Mon, 20 Mar 2023 12:21:33 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Sun, 19 Mar 2023 13:00:35 GMT]]></title><description><![CDATA[<p dir="auto">Hello Chaim,</p>
<p dir="auto">Glad to hear you've made some good progress with your protocol analyzer!</p>
<p dir="auto">Yes, <code>log.representStruct</code> should simplify and at the same time "standardize" representation of binary-based packets. And yes, you are right -- at the moment, it doesn't recursively represent all the nested structs. That's because this functionality was never required in the stock protocol analyzers in IO Ninja -- we use "layered" representation rather than "nested" because (a) this makes resulting tables more compact and easier to navigate, and (b) allows us to colorize layers using different colors. But there's nothing that prevents adding the support for nesting to <code>log.representStruct</code>; I think we can add that to the upcoming release.</p>
<p dir="auto">How deep is the nesting in your case? Could you please provide definitions of the packet structs in your protocol?</p>
<p dir="auto">Just FYI, the implementation of <code>log.representStruct</code> is in <code>scripts/common/log_RepresentStruct.jnc</code>; you can try experimenting with it by yourself until the official release.</p>
]]></description><link>http://64.23.185.212/forum/post/305</link><guid isPermaLink="true">http://64.23.185.212/forum/post/305</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Sun, 19 Mar 2023 13:00:35 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Sun, 19 Mar 2023 09:35:24 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
Thanks for your reply, indeed i had a parsing bug in my code... fixed it and now i'm able to see parsed packets in the log <img src="http://64.23.185.212/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f60a.png?v=miq4h6da9ug" class="not-responsive emoji emoji-android emoji--blush" title=":blush:" alt="😊" />.<br />
I'm using the log.representStruct to print a stucture in the log, cool stuff !!!<br />
Say you have a structure that contains another stucture and so on for a few levels. Is there a way to use the 'representStruct' recursively, so all inner struct will be formatted too ?</p>
]]></description><link>http://64.23.185.212/forum/post/303</link><guid isPermaLink="true">http://64.23.185.212/forum/post/303</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Sun, 19 Mar 2023 09:35:24 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Fri, 17 Mar 2023 10:48:11 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">Ok, to me it was very unclear, and took me a while to figure that out...</p>
</blockquote>
<p dir="auto">Installing and configuring NetBeans is an extra step, true. But I thought the explanation on the Download page or the <a href="https://ioninja.com/doc/developer-manual/ide.html" rel="nofollow ugc">dedicated article</a> in the Developer Manual address this issue... If not, how would you rephrase those explanations to make things more clear?</p>
<blockquote>
<p dir="auto">...however, i wasn't able to see the protocol analyzer plugin working</p>
</blockquote>
<p dir="auto">Most likely, something is wrong with the implementation of your protocol analyzer. You didn't describe which protocol you try to parse, how exactly you do that, and which data you feed to the analyzer.</p>
<p dir="auto">If you upload the sources of your protocol analyzer somewhere, we can take a look.</p>
<p dir="auto">BTW, the tutorial has a link to an archive with a working analyzer of a made-up protocol. There are also real-life <a href="/plugins/modbus.html">Modbus Analyzer</a> and <a href="/plugins/df1.html">DF1 Analyzer</a>; all those can be used as a reference when developing one of your own.</p>
]]></description><link>http://64.23.185.212/forum/post/297</link><guid isPermaLink="true">http://64.23.185.212/forum/post/297</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Fri, 17 Mar 2023 10:48:11 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Wed, 15 Mar 2023 13:59:16 GMT]]></title><description><![CDATA[<p dir="auto">Ok, to me it was very unclear, and took me a while to figure that out...</p>
<p dir="auto">In any case, i was able to create a new protocol analyzer according to the help provided in - <a href="https://ioninja.com/doc/developer-manual/tutorial-plugin-analyzer.html" rel="nofollow ugc">https://ioninja.com/doc/developer-manual/tutorial-plugin-analyzer.html</a><br />
I've added the plugin to IO Ninja (using the settings dialog), and add the new plugin as a layer on top of 'Serial Tap'.<br />
We are using a IO Ninja serial Tap device to sniffer serial packets (we use TTL).<br />
I'm able to see the packet flow when the serial tap is connected, however, i wasn't able to see the protocol analyzer plugin working... the plugin parses the incoming data, and when a full packet is completed is sends a formatted string to the logger (just as done in the tutorial).<br />
Is there something i'm missing ?<br />
Many thanks.</p>
]]></description><link>http://64.23.185.212/forum/post/295</link><guid isPermaLink="true">http://64.23.185.212/forum/post/295</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Wed, 15 Mar 2023 13:59:16 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Wed, 15 Mar 2023 01:25:13 GMT]]></title><description><![CDATA[<p dir="auto">Actually, there's no typo; IO Ninja IDE is a set of NetBeans plugins, as explained on the Download page:</p>
<p dir="auto"><img src="/forum/assets/uploads/files/1678843436653-f2c9c960-462d-4064-9844-261f6178ec54-image.png" alt="f2c9c960-462d-4064-9844-261f6178ec54-image.png" class=" img-responsive img-markdown" width="917" height="726" /></p>
]]></description><link>http://64.23.185.212/forum/post/291</link><guid isPermaLink="true">http://64.23.185.212/forum/post/291</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Wed, 15 Mar 2023 01:25:13 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Tue, 14 Mar 2023 15:23:34 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I managed to solve the issue.<br />
There is a typo in the tutorial page (<a href="https://ioninja.com/doc/developer-manual/tutorial-plugin-analyzer.html" rel="nofollow ugc">https://ioninja.com/doc/developer-manual/tutorial-plugin-analyzer.html</a>).<br />
The user should open NetBeans IDE for creating a new project, and not the IO Ninja IDE...<br />
Please update.</p>
]]></description><link>http://64.23.185.212/forum/post/288</link><guid isPermaLink="true">http://64.23.185.212/forum/post/288</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Tue, 14 Mar 2023 15:23:34 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Tue, 14 Mar 2023 08:06:36 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your reply.<br />
I'm looking at the tutorial you pointed to, on how to create a protocol analyzer.<br />
However, i could find in the IO-Ninja IDE how to create a new IONinja project... there is no menu 'File-&gt;New Project' only 'File-&gt;New Session...'. Was the IDE changed recently ? Can you please guide me how to do it with the current IONinja IDE.<br />
Thanks</p>
]]></description><link>http://64.23.185.212/forum/post/287</link><guid isPermaLink="true">http://64.23.185.212/forum/post/287</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Tue, 14 Mar 2023 08:06:36 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Mon, 13 Mar 2023 03:23:08 GMT]]></title><description><![CDATA[<p dir="auto">If you want to parse the captured data streams and inject human-readable messages alongside the original data, you need a protocol analyzer. This is, however, a more challenging task than writing a packet template.</p>
<p dir="auto">IO Ninja features open-source Modbus and DF1 analyzers that could be used as a reference for approaching this task. Also, there's a tutorial in the Developer's Manual:</p>
<p dir="auto"><a href="https://ioninja.com/doc/developer-manual/tutorial-plugin-analyzer.html" rel="nofollow ugc">https://ioninja.com/doc/developer-manual/tutorial-plugin-analyzer.html</a></p>
]]></description><link>http://64.23.185.212/forum/post/282</link><guid isPermaLink="true">http://64.23.185.212/forum/post/282</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Mon, 13 Mar 2023 03:23:08 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Sun, 12 Mar 2023 07:55:24 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your reply.<br />
From what you wrote, i understand i'm using the wrong tool, since i want to analyze incoming packets and log then to a log or display them at runtime, and not build packets before sending them...<br />
Can you please suggest a way to do so, and provide an example i can use ?<br />
Thanks</p>
]]></description><link>http://64.23.185.212/forum/post/278</link><guid isPermaLink="true">http://64.23.185.212/forum/post/278</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Sun, 12 Mar 2023 07:55:24 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Fri, 10 Mar 2023 02:15:50 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">Is it possible to create such a template that can display different data structure according to the packet type</p>
</blockquote>
<p dir="auto">Just to ensure we're on the same page -- packet templates are for <em>editing</em> packets before transmission, not for <em>displaying</em> them in the log. After defining a packet template, you can conveniently prepare it with a property grid before transmission.</p>
<p dir="auto">If that's what you try to do, then the answer is YES, you can define a packet template with a variable-sized payload length and a checksum in the end:</p>
<pre><code>import "crc16.jnc"

pragma(Alignment, 1)

struct FE_BE_Packet {
	uint8_t StartOfPacket;
	uint16_t Length;
	uint8_t MessageID;
	uint16_t GlobalSequenceNumber;
	uint16_t MessageSequenceNumber;

	[ 	
		userAction = "Update checksum",
		autorun = "Auto-update checksum" 
	]
	void updateChecksum() {
		size_t size = dynamic sizeof(this) - sizeof(uint16_t); // without checksum
		uint16_t* checksum = (uint16_t*)((char*)this + size);
		*checksum = crc16_ansi(this, size, -1); // Modbus CRC
	}
}
</code></pre>
<p dir="auto">Here is a quick rundown of what's happening here.</p>
<p dir="auto">The structure definition itself is for the fixed-size header -- the header fields can be edited with a property grid. Beyond this header, you can enter a variable-sized payload in the hex editor.</p>
<p dir="auto">Now, to the interesting part. We want to auto-update the checksum every time the user changes any fields in the header (or the payload itself). To achieve that, I create a method called <code>updateChecksum()</code>, mark it as <code>userAction</code> (so it's user-accessible via a hyperlink) and <code>autorun</code> (execute on every data change) using function attributes <code>[...]</code>, and inside this method, I calculate a checksum and write it to <em>the last two bytes</em> of the packet. In my example, I use the Modbus checksum (CRC16-ANSI with the seed of <code>0xffff</code>), but feel free to update it according to your needs.</p>
<p dir="auto">Hope this helps!</p>
]]></description><link>http://64.23.185.212/forum/post/272</link><guid isPermaLink="true">http://64.23.185.212/forum/post/272</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Fri, 10 Mar 2023 02:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Thu, 09 Mar 2023 08:00:51 GMT]]></title><description><![CDATA[<p dir="auto">Thank you very much, it works now with the updated syntax. Would be great if the tutorial would be updated too :-)...<br />
In the protocol we are trying to trace with the IO Ninja, each packet has a different size. According to the packet type/size the data structure is different. Is it possible to create such a template that can display different data structure according to the packet type ?<br />
If so, can you send me an example of such a template.<br />
If not, is there a way to do ?</p>
<p dir="auto">Here is how out packet looks like:<br />
pragma(Alignment, 1)</p>
<p dir="auto">struct FE_BE_Packet<br />
{<br />
uint8_t StartOfPacket;<br />
uint16_t Length;<br />
uint8_t MessageID;<br />
uint16_t GlobalSequenceNumber;<br />
uint16_t MessageSequenceNumber;<br />
char MessageData[70];<br />
uint16_t CheckSumData;<br />
}<br />
The 'MessageData' is the one that keeps changes (size and content)</p>
]]></description><link>http://64.23.185.212/forum/post/262</link><guid isPermaLink="true">http://64.23.185.212/forum/post/262</guid><dc:creator><![CDATA[Chaim Cohen]]></dc:creator><pubDate>Thu, 09 Mar 2023 08:00:51 GMT</pubDate></item><item><title><![CDATA[Reply to Packet template &#x27;alignment&#x27; issue on Wed, 08 Mar 2023 02:25:22 GMT]]></title><description><![CDATA[<p dir="auto">The syntax of structure packing has changed since we published the tutorial (yes, the tutorial needs to be updated).</p>
<p dir="auto">The new syntax is:</p>
<pre><code>pragma(Alignment, 1)
</code></pre>
<p dir="auto">For an explanation for jumping bytes and how packing and alignment affect the memory layout, please refer to this Wikipedia article: <a href="https://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86" rel="nofollow ugc">https://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86</a></p>
]]></description><link>http://64.23.185.212/forum/post/261</link><guid isPermaLink="true">http://64.23.185.212/forum/post/261</guid><dc:creator><![CDATA[Vladimir]]></dc:creator><pubDate>Wed, 08 Mar 2023 02:25:22 GMT</pubDate></item></channel></rss>