I know this is not an answer "Reading stp (Designaknit Stitch Pattern)-Files)", but i think it is a way to an answer.
I believe I have the right function found (with ida - i call it testStp), but I do not know exactly what happened. I does not understand Assembler code.
I've attached the beginning of the function and the first jump point.
First, variables are declared at certain positions (var_84D
....) where and why ???
Then the stp file opens.
What makes test esi esi
??? a comparison ?? empty file ???
if ? then jnz short loc_4144FF
otherwise mov ebx, 0FFFFFFFDh
|| jmp loc_414C93
(exit point from the function ???)
fopen
= open filefseek
= set file positionftell
= read current positionfread
= read filefclose
= close file
mov edi, offset AD7c; "D7c"
- 3 bytes read into string ???
(Which means offset ... ??)
mov ecx, 3
???
mov esi, [esp + 34h]
????
repe CMPSB
'compare (apparently on "D7c" - the first 3 bytes in the file)
if ? then jz short loc_41458A
otherwise mov ebx, 0FFFFFFFCh
| jmp loc_414C93
(exit point from the function ???)
Next I have no idea.
I hope someone can help me and tell me what the individual statements do and also mean to say whether I have the right function found. And what do sub_421CF0
do???
Alfred
here are the Begin of the sub and the first jump:
.text:004144A8 align 10h
.text:004144B0
.text:004144B0 ; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B R O U T I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
.text:004144B0
.text:004144B0
.text:004144B0 ; int __cdecl TestSTP(int,int,int,char *,int,int)
.text:004144B0 TestSTP proc near ; CODE XREF: Pattern2Sl4(x,x,x,x,x)+5A1 p
.text:004144B0 ; CB_CurrentPattern(x,x,x,x)+47B p ...
.text:004144B0
.text:004144B0 var_84D = byte ptr -84Dh
.text:004144B0 var_84C = dword ptr -84Ch
.text:004144B0 var_848 = dword ptr -848h
.text:004144B0 var_844 = dword ptr -844h
.text:004144B0 var_840 = dword ptr -840h
.text:004144B0 var_83C = word ptr -83Ch
.text:004144B0 var_838 = dword ptr -838h
.text:004144B0 var_834 = dword ptr -834h
.text:004144B0 var_830 = dword ptr -830h
.text:004144B0 var_82C = dword ptr -82Ch
.text:004144B0 var_828 = dword ptr -828h
.text:004144B0 var_824 = dword ptr -824h
.text:004144B0 var_820 = word ptr -820h
.text:004144B0 var_81C = dword ptr -81Ch
.text:004144B0 var_818 = dword ptr -818h
.text:004144B0 var_814 = dword ptr -814h
.text:004144B0 var_810 = dword ptr -810h
.text:004144B0 var_80C = dword ptr -80Ch
.text:004144B0 var_808 = dword ptr -808h
.text:004144B0 var_804 = dword ptr -804h
.text:004144B0 var_800 = dword ptr -800h
.text:004144B0 var_400 = dword ptr -400h
.text:004144B0 arg_0 = dword ptr 4
.text:004144B0 arg_4 = dword ptr 8
.text:004144B0 arg_8 = dword ptr 0Ch
.text:004144B0 arg_C = dword ptr 10h
.text:004144B0 arg_10 = dword ptr 14h
.text:004144B0 arg_14 = dword ptr 18h
.text:004144B0
.text:004144B0 sub esp, 850h
.text:004144B6 mov [esp+850h+var_818], 1
.text:004144BE push ebx
.text:004144BF push esi
.text:004144C0 push edi
.text:004144C1 push ebp
.text:004144C2 xor edi, edi
.text:004144C4 mov [esp+860h+var_82C], edi
.text:004144C8 mov [esp+860h+var_80C], edi
.text:004144CC cmp [esp+860h+arg_10], edi
.text:004144D3 jnz loc_41455C
.text:004144D9 mov eax, [esp+860h+arg_C]
.text:004144E0 push offset aRb ; "rb"
.text:004144E5 push eax ; char *
.text:004144E6 call ds:fopen
.text:004144EC add esp, 8
.text:004144EF mov esi, eax
.text:004144F1 test esi, esi
.text:004144F3 jnz short loc_4144FF
.text:004144F5 mov ebx, 0FFFFFFFDh
.text:004144FA jmp loc_414C93
.text:004144FF ; ------------------------------------------------
.text:004144FF
.text:004144FF loc_4144FF: ; CODE XREF: TestSTP+43 j
.text:004144FF push 2 ; int
.text:00414501 mov edi, ds:fseek
.text:00414507 push 0 ; __int32
.text:00414509 push esi ; FILE *
.text:0041450A call edi ; fseek
.text:0041450C add esp, 0Ch
.text:0041450F push esi ; FILE *
.text:00414510 call ds:ftell
.text:00414516 add esp, 4
.text:00414519 mov ebp, eax
.text:0041451B push 349h
.text:00414520 push offset aURefKnittingCo ; "U:\\Ref\\Knitting\\Common\\STI.C"
.text:00414525 push ebp
.text:00414526 push 0
.text:00414528 call sub_421CF0
.text:0041452D mov [esp+870h+var_82C], eax
.text:00414531 add esp, 10h
.text:00414534 push 0 ; int
.text:00414536 push 0 ; __int32
.text:00414538 push esi ; FILE *
.text:00414539 call edi ; fseek
.text:0041453B mov eax, [esp+86Ch+var_82C]
.text:0041453F add esp, 0Ch
.text:00414542 push esi ; FILE *
.text:00414543 push 1 ; size_t
.text:00414545 push ebp ; size_t
.text:00414546 push eax ; void *
.text:00414547 call ds:fread
.text:0041454D add esp, 10h
.text:00414550 push esi ; FILE *
.text:00414551 call ds:fclose
.text:00414557 add esp, 4
.text:0041455A jmp short loc_41456E
.text:0041455C ; ------------------------------------------------
.text:0041455C
.text:0041455C loc_41455C: ; CODE XREF: TestSTP+23 j
.text:0041455C mov eax, [esp+860h+arg_10]
.text:00414563 mov ebp, [esp+860h+arg_14]
.text:0041456A mov [esp+860h+var_82C], eax
.text:0041456E
.text:0041456E loc_41456E: ; CODE XREF: TestSTP+AA j
.text:0041456E mov edi, offset aD7c ; "D7c"
.text:00414573 mov ecx, 3
.text:00414578 mov esi, [esp+34h]
.text:0041457C repe cmpsb
.text:0041457E jz short loc_41458A
.text:00414580 mov ebx, 0FFFFFFFCh
.text:00414585 jmp loc_414C93
.text:0041458A ; ------------------------------------------------
.text:0041458A
.text:0041458A loc_41458A: ; CODE XREF: TestSTP+CE j
.text:0041458A mov eax, [esp+860h+var_82C]
.text:0041458E mov ecx, [esp+860h+var_82C]
.text:00414592 mov ax, [eax+5]
.text:00414596 mov dx, [ecx+3]
.text:0041459A mov word ptr [esp+860h+var_84C+2], ax
.text:0041459F mov word ptr [esp+860h+var_84C], dx
.text:004145A4 cmp ax, 46Ah
.text:004145A8 ja loc_414C8E
.text:004145AE cmp dx, 320h
.text:004145B3 ja loc_414C8E
.text:004145B9 mov eax, [esp+860h+var_84C]
.text:004145BD and eax, 0FFFFh
.text:004145C2 mov [esp+860h+var_840], eax
.text:004145C6 mov eax, [esp+860h+var_84C+2]
.text:004145CA and eax, 0FFFFh
.text:004145CF push 363h
.text:004145D4 mov [esp+864h+var_814], eax
.text:004145D8 push offset aURefKnittingCo ; "U:\\Ref\\Knitting\\Common\\STI.C"
.text:004145DD mov eax, [esp+868h+var_840]
.text:004145E1 imul eax, [esp+868h+var_814]
.text:004145E6 mov [esp+868h+var_810], eax
.text:004145EA add eax, 411h
.text:004145EF mov [esp+868h+var_824], eax
.text:004145F3 push eax
.text:004145F4 push 0
.text:004145F6 call sub_421CF0
.text:004145FB mov edx, [esp+870h+var_824]
.text:004145FF mov [esp+870h+var_830], eax
.text:00414603 add esp, 10h
.text:00414606 mov edi, eax
.text:00414608 xor eax, eax
.text:0041460A mov ecx, edx
.text:0041460C shr ecx, 2
.text:0041460F rep stosd
.text:00414611 mov ecx, edx
.text:00414613 and ecx, 3
.text:00414616 rep stosb
.text:00414618 mov dx, word ptr [esp+860h+var_84C+2]
.text:0041461D mov ebx, dword ptr aSti ; "Sti"
.text:00414623 mov eax, [esp+860h+var_830]
.text:00414627 mov ecx, eax
.text:00414629 mov [eax], ebx
.text:0041462B mov [eax+4], dx
.text:0041462F mov edx, [esp+860h+var_82C]
.text:00414633 mov ax, word ptr [esp+860h+var_84C]
.text:00414638 mov [ecx+6], ax
.text:0041463C mov al, [edx+1Fh]
.text:0041463F mov ecx, [esp+860h+var_830]
.text:00414643 test al, al
.text:00414645 jnz short loc_414656
.text:00414647 mov word ptr [ecx+8], 20h
.text:0041464D add ecx, 8
.text:00414650 mov [esp+860h+var_828], ecx
.text:00414654 jmp short loc_414668
.text:00414656 ; ------------------------------------------------
.text:00414656
.text:00414656 loc_414656: ; CODE XREF: TestSTP+195 j
.text:00414656 movsx ax, al
.text:0041465A add ax, 100h
.text:0041465E add ecx, 8
.text:00414661 mov [ecx], ax
.text:00414664 mov [esp+860h+var_828], ecx
.text:00414668
.text:00414668 loc_414668: ; CODE XREF: TestSTP+1A4 j
.text:00414668 mov eax, [esp+860h+var_82C]
.text:0041466C mov al, [eax+2Ch]
.text:0041466F mov byte ptr [esp+860h+var_820], al
.text:00414673 cmp al, 0Eh
.text:00414675 jz short loc_41467F
.text:00414677 cmp al, 0Fh
.text:00414679 mov [esp+860h+var_84D], al
.text:0041467D jnz short loc_414684
.text:0041467F
.text:0041467F loc_41467F: ; CODE XREF: TestSTP+1C5 j
.text:0041467F mov [esp+860h+var_84D], 0
.text:00414684
.text:00414684 loc_414684: ; CODE XREF: TestSTP+1CD j
.text:00414684 mov ecx, [esp+860h+var_830]
.text:00414688 mov al, byte ptr [esp+860h+var_820]
.text:0041468C mov dl, [esp+860h+var_84D]
.text:00414690 add ecx, 410h
.text:00414696 mov ebx, [esp+860h+var_830]
.text:0041469A mov esi, [esp+860h+var_82C]
.text:0041469E add ebx, 10h
.text:004146A1 add esi, 0F8h
.text:004146A7 mov [esp+860h+var_848], ecx
.text:004146AB push offset WindowName
.text:004146B0 mov byte ptr [ecx-406h], 0
.text:004146B7 mov [ecx-405h], al
.text:004146BD mov [ecx-405h], dl
.text:004146C3 mov ecx, [esp+864h+var_82C]
.text:004146C7 push ecx
.text:004146C8 call sub_41D5A0
.text:004146CD mov eax, [esp+868h+var_84C+2]
.text:004146D1 mov [esp+868h+var_808], esi
.text:004146D5 add esp, 8
.text:004146D8 push eax
.text:004146D9 push esi
.text:004146DA call sub_4141D0
.text:004146DF add esp, 8
.text:004146E2 add esi, eax
.text:004146E4 mov eax, [esp+860h+var_84C+2]
.text:004146E8 mov [esp+860h+var_804], esi
.text:004146EC push eax
.text:004146ED push esi
.text:004146EE call sub_4141D0
.text:004146F3 add esp, 8
.text:004146F6 add esi, eax
.text:004146F8 mov al, [esi+6EFh]
.text:004146FE mov [esp+860h+var_834], esi
.text:00414702 add esi, 6EFh
.text:00414708 cmp al, 20h
.text:0041470A mov [esp+860h+var_838], esi
.text:0041470E jnz short loc_414716
.text:00414710 cmp byte ptr [esi+2], 2Eh
.text:00414714 jz short loc_414720
.text:00414716
.text:00414716 loc_414716: ; CODE XREF: TestSTP+25E j
.text:00414716 cmp byte ptr [esi+2], 20h
.text:0041471A jnz short loc_414781
.text:0041471C cmp al, 2Eh
.text:0041471E jnz short loc_414781
.text:00414720
.text:00414720 loc_414720: ; CODE XREF: TestSTP+264 j
.text:00414720 mov [esp+860h+var_81C], 30h
.text:00414728 mov edi, esi
.text:0041472A
.text:0041472A loc_41472A: ; CODE XREF: TestSTP+2CF j
.text:0041472A test byte ptr [edi+1], 3
.text:0041472E jz short loc_414778
.text:00414730 xor eax, eax
.text:00414732 mov al, [edi]
.text:00414734 push eax ; int
.text:00414735 push offset a_gdejziki ; " .âäàåçêèë"
.text:0041473A call ds:__imp_strchr
.text:00414740 add esp, 8
.text:00414743 test eax, eax
.text:00414745 jz short loc_414754
.text:00414747 sub eax, offset a_gdejziki ; " .âäàåçêèë"
.text:0041474C mov al, byte_42EB00[eax]
.text:00414752 mov [edi], al
-------------------------------------------------------------------------------------------------------------------------------
.text:00421CE6 align 10h
.text:00421CF0
.text:00421CF0 ; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B R O U T I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
.text:00421CF0
.text:00421CF0
.text:00421CF0 sub_421CF0 proc near ; CODE XREF: .text:00403D0C p
.text:00421CF0 ; .text:00403E2C p ...
.text:00421CF0
.text:00421CF0 var_4 = dword ptr -4
.text:00421CF0 arg_0 = dword ptr 4
.text:00421CF0 arg_4 = dword ptr 8
.text:00421CF0 arg_8 = dword ptr 0Ch
.text:00421CF0 arg_C = dword ptr 10h
.text:00421CF0
.text:00421CF0 sub esp, 4
.text:00421CF3 push ebx
.text:00421CF4 push esi
.text:00421CF5 mov esi, [esp+0Ch+arg_4]
.text:00421CF9 push edi
.text:00421CFA push ebp
.text:00421CFB cmp esi, 7FFFFFC0h
.text:00421D01 jbe short loc_421D0D
.text:00421D03 xor eax, eax
.text:00421D05 pop ebp
.text:00421D06 pop edi
.text:00421D07 pop esi
.text:00421D08 pop ebx
.text:00421D09 add esp, 4
.text:00421D0C retn
.text:00421D0D ; ------------------------------------------------
.text:00421D0D
.text:00421D0D loc_421D0D: ; CODE XREF: sub_421CF0+11 j
.text:00421D0D mov edi, [esp+14h+arg_0]
.text:00421D11 and edi, 7FFFFFFFh
.text:00421D17 cmp edi, 8
.text:00421D1A jb short loc_421D26
.text:00421D1C xor eax, eax
.text:00421D1E pop ebp
.text:00421D1F pop edi
.text:00421D20 pop esi
.text:00421D21 pop ebx
.text:00421D22 add esp, 4
.text:00421D25 retn
.text:00421D26 ; ------------------------------------------------
.text:00421D26
.text:00421D26 loc_421D26: ; CODE XREF: sub_421CF0+2A j
.text:00421D26 mov eax, edi
.text:00421D28 shl eax, 5
.text:00421D2B lea ebx, dword_429BC8[eax+eax*2]
.text:00421D32 cmp dword ptr [ebx+10h], 0
.text:00421D36 jnz short loc_421D51
.text:00421D38 push 7Fh
.text:00421D3A push 10h
.text:00421D3C push 0FDh
.text:00421D41 push 80000h
.text:00421D46 push 0
.text:00421D48 push ebx
.text:00421D49 call sub_421ED0
.text:00421D4E add esp, 18h
.text:00421D51
.text:00421D51 loc_421D51: ; CODE XREF: sub_421CF0+46 j
.text:00421D51 cmp [ebx+5Ch], esi
.text:00421D54 jnz short loc_421D65
.text:00421D56 push edi
.text:00421D57 push esi
.text:00421D58 push offset aSomeoneTriesTo ; "Someone tries to allocate %u bytes in p"...
.text:00421D5D call sub_420DB0
.text:00421D62 add esp, 0Ch
.text:00421D65
.text:00421D65 loc_421D65: ; CODE XREF: sub_421CF0+64 j
.text:00421D65 lea edi, [esi+2Bh]
.text:00421D68 mov eax, [ebx+58h]
.text:00421D6B shr edi, 5
.text:00421D6E inc edi
.text:00421D6F test eax, eax
.text:00421D71 jz short loc_421D7E
.text:00421D73 push 0FFFFFFFFh ; dwMilliseconds
.text:00421D75 push eax ; hHandle
.text:00421D76 call ds:WaitForSingleObject
.text:00421D7C jmp short loc_421D8A
.text:00421D7E ; ------------------------------------------------
.text:00421D7E
.text:00421D7E loc_421D7E: ; CODE XREF: sub_421CF0+81 j
.text:00421D7E lea eax, [ebx+18h]
.text:00421D81 mov ebp, ds:EnterCriticalSection
.text:00421D87 push eax ; lpCriticalSection
.text:00421D88 call ebp ; EnterCriticalSection
.text:00421D8A
.text:00421D8A loc_421D8A: ; CODE XREF: sub_421CF0+8C j
.text:00421D8A push edi
.text:00421D8B push esi
.text:00421D8C push ebx
.text:00421D8D call sub_421AD0
.text:00421D92 mov [esp+20h+var_4], eax
.text:00421D96 add esp, 0Ch
.text:00421D99 mov eax, [ebx+58h]
.text:00421D9C test eax, eax
.text:00421D9E jz short loc_421DA9
.text:00421DA0 push eax ; hMutex
.text:00421DA1 call ds:ReleaseMutex
.text:00421DA7 jmp short loc_421DB5
.text:00421DA9 ; ------------------------------------------------
.text:00421DA9
.text:00421DA9 loc_421DA9: ; CODE XREF: sub_421CF0+AE j
.text:00421DA9 lea eax, [ebx+18h]
.text:00421DAC mov ebp, ds:LeaveCriticalSection
.text:00421DB2 push eax ; lpCriticalSection
.text:00421DB3 call ebp ; LeaveCriticalSection
.text:00421DB5
.text:00421DB5 loc_421DB5: ; CODE XREF: sub_421CF0+B7 j
.text:00421DB5 cmp [esp+14h+var_4], 0
.text:00421DBA jz short loc_421E18
.text:00421DBC mov edx, [esp+14h+var_4]
.text:00421DC0 mov edi, [esp+14h+var_4]
.text:00421DC4 sub edx, 20h
.text:00421DC7 xor eax, eax
.text:00421DC9 mov ecx, esi
.text:00421DCB shr ecx, 2
.text:00421DCE rep stosd
.text:00421DD0 mov ecx, esi
.text:00421DD2 and ecx, 3
.text:00421DD5 rep stosb
.text:00421DD7 mov ebp, [edx+4]
.text:00421DDA mov eax, [ebx+3Ch]
.text:00421DDD sub ebp, esi
.text:00421DDF mov ch, al
.text:00421DE1 sub ebp, 28h
.text:00421DE4 mov cl, al
.text:00421DE6 mov eax, ecx
.text:00421DE8 mov edi, [esp+14h+var_4]
.text:00421DEC shl eax, 10h
.text:00421DEF add edi, esi
.text:00421DF1 mov ax, cx
.text:00421DF4 mov ecx, ebp
.text:00421DF6 shr ecx, 2
.text:00421DF9 rep stosd
.text:00421DFB mov ecx, ebp
.text:00421DFD and ecx, 3
.text:00421E00 rep stosb
.text:00421E02 mov ebp, [edx+4]
.text:00421E05 mov ecx, [esp+14h+arg_8]
.text:00421E09 mov eax, [esp+14h+arg_C]
.text:00421E0D mov [ebp+edx-8], ecx
.text:00421E11 mov ebp, [edx+4]
.text:00421E14 mov [ebp+edx-4], eax
.text:00421E18
.text:00421E18 loc_421E18: ; CODE XREF: sub_421CF0+CA j
.text:00421E18 mov eax, [esp+14h+var_4]
.text:00421E1C pop ebp
.text:00421E1D pop edi
.text:00421E1E pop esi
.text:00421E1F pop ebx
.text:00421E20 add esp, 4
.text:00421E23 retn
.text:00421E23 sub_421CF0 endp
Update
I think that Guntram Blohm has helped me (for my thanks from Germany - and I hope he help me furthermore) and we are on the right track. That's why I still try around a bit and hope to get a little more clarity. First: older Designaknit-format is *.pat. But i do not know *.sti-format??
The number of pallet data can be more than 48, perhaps, but only these 48 are important because the program has only 48 colors.
The first color (size 25 bytes) starts 325 !! (13 blocks) bytes behind the last data block. Then, the color block 48 used to follow each 25 bytes. Unused colors are marked with the number 0h. Perhaps other color blocks have been reserved (before and after the 48 palette colors) for future updates for more colors ??
The data itself is compressed by a simple run-ength-Encryption. However, the bytes have been encrypted. I made many tests and found out a lot:
Are at the beginning at the bottom left of the image a plurality of identical pixels, so you can calculate the number of this table:
left 4 bits
0 = B
16 = A
32 = 9
48 = 8
64 = F
80 = E
96 = D
112 = C
right 4 bits:
5 = 0
4 = 1
7 = 2
6 = 3
1 = 4
0 = 5
3 = 6
2 = 7
D = 8
C = 9
F = 10
9 = 12
8 = 13
B = 14
A = 15
This means if at position FC in the file z. B. B7 (hex) is so "7 = 2" pixels "B = 0" + a total of 2 same color pixel bottom left available.
This is the same for each file. However, this table thereafter at each pixel changes and is also different from file to file.
The same applies to the palette numbers. In my tests, it looked as if the pallets would thoroughly mixed after each pixel on the system. As an example, were prepared from 1 + 2 = 3 + 4, and from 3 + 4 = + 1 second This then repeated through the whole range. But it can be also mixed different (but still on the system) (Example 1 = 2, 2 = 1, 3 = 4, 4 = 3 ...) or remain the same.
ti mix, but also the change of the number of pixels is probably controlled by a key that is different from file to file changes (data for the key at positions 41h, 60h, 20h (byte), 35h (4 bytes), 39h (4 bytes) , 3dh (2 bytes) and 3fh (2 bytes) -from Guntram) I do not know if I'm right, but maybe sub_41D5A0 a simple RLE-decoding, which then decrypts the data obtained in sub_41cf20 for the key ??
Alfred
UPDATE 2
Hello,
your project is really very, very good and helps me a lot.
I think the second part of the data block is correctly decoded. the same character (solid block of! characters) must always be displayed for jacquards. For hole pattern right / left pattern, cables etc. to change. Then, in the second section various characters appear (z. B. right Decreuse, left Decreuse, double Decreuse, eyelet, right transfer, transfer left ....) The characters are taken out of the font file to indicate this.
I've just tried it and it's like I said. These files are then in the first section only same characters and in the second section of the pattern is present (with different instructions - Reassign - right - left, etc.)
But the Internet almost exclusively in Jacquard stp format are available.
It would be really great I could Assembler. Thy counsel from the first mail.
Thank you very much
Alfred
sub_41D5A0
is not a RLE decoding, the center of its loops arexor
operations that are applied to the file buffer. RLE decoding happens insub_4140F0
.