Difference between revisions of "Talk:SCO"

From GTAMods Wiki
Jump to navigation Jump to search
 
Line 94: Line 94:
 
:Your right those opcodes did need renaming, in fact I've renamed them along the lines of the list that Seemann provided because I think that conforms closer to assemblies produce by the likes of IDA etc. Also I've changed the naming of local variables and global variables to global variables and public variables (as that initially caused me some confusion). High Level Representation will need to be rewritten a bit to accommodate these changes. Also I think that Opcode 79 should be treated as a specific opcode, even though it's not listed in the jumptable, it has a special function which is apparent by the checking if(opcode == 79) in the default segment of that jumptable. --[[User:Sacky|Sacky]]
 
:Your right those opcodes did need renaming, in fact I've renamed them along the lines of the list that Seemann provided because I think that conforms closer to assemblies produce by the likes of IDA etc. Also I've changed the naming of local variables and global variables to global variables and public variables (as that initially caused me some confusion). High Level Representation will need to be rewritten a bit to accommodate these changes. Also I think that Opcode 79 should be treated as a specific opcode, even though it's not listed in the jumptable, it has a special function which is apparent by the checking if(opcode == 79) in the default segment of that jumptable. --[[User:Sacky|Sacky]]
 
::You have to note that in the 360 disassembly, the XLive protect opcodes (76, 77, 78) also result in the same action as of opcode 79. You'll also never see this opcode in any of the compiled scripts. [[User:Aru|Aru]] 14:54, 17 March 2009 (UTC)
 
::You have to note that in the 360 disassembly, the XLive protect opcodes (76, 77, 78) also result in the same action as of opcode 79. You'll also never see this opcode in any of the compiled scripts. [[User:Aru|Aru]] 14:54, 17 March 2009 (UTC)
 
== Decrypting SCO Files ==
 
 
Does anyone have any example code on how to do this. I have the correct key (confirmed), and this is the code I use:
 
<source lang="cpp">FILE* fHandle = NULL;
 
fopen_s(&fHandle,"ambcabaret.sco","r");
 
SCO_HEADER scoHeader;
 
fread(&scoHeader,sizeof(SCO_HEADER),1,fHandle);
 
printf("Read Header\n");
 
uint8* codeBlock = (uint8*) malloc(sizeof(uint8)*scoHeader.codeBytes);
 
memset(codeBlock,0,sizeof(uint8)*scoHeader.codeBytes);
 
fread(codeBlock,sizeof(uint8),scoHeader.codeBytes,fHandle);
 
printf("Read Code Block\n");
 
CRijndael rj;
 
rj.MakeKey((const char*)AESKey,CRijndael::sm_chain0,32,32);
 
printf("Made Key\n");
 
for(uint32 i=0;i<scoHeader.codeBytes/16;i++)
 
{
 
uint8* tmpCodeBlock = codeBlock + (i*16);
 
for(int j=0;j<16;j++)
 
rj.DecryptBlock((const char*)tmpCodeBlock,(char*)tmpCodeBlock);
 
}
 
printf("Decrypted Code Block\n");
 
for(uint32 i=0;i<16;i++)
 
printf("Code Block %d: 0x%X\n",i,codeBlock[i]);</source>
 
 
and this is what I get:
 
 
<div class="NavFrame collapsed"><div class="NavHead"></div><div class="NavContent">
 
<pre>
 
0x3D 0xE1 0x90 0x06 0xFB 0x10 0x8C 0xA4
 
0x48 0x84 0x85 0x21 0x54 0x91 0x13 0xF6
 
->
 
0x2B 0xC1 0x38 0xA0 0xFA 0xFB 0x75 0x2E
 
0xBC 0x2D 0x82 0x2C 0xC1 0x15 0x54 0x71
 
->
 
dup
 
ipush1 97
 
flvar2
 
ipush1 64
 
ipush1 154
 
ipush1 155
 
ipush1 21
 
call
 
ipush1 92
 
native
 
ipush1 34
 
pop
 
ipush1 97
 
fcmpne
 
ipush1 -12
 
ipush1 17</pre></div>
 
 
According to scruff it should be:
 
 
<div class="NavFrame collapsed"><div class="NavHead"></div><div class="NavContent">
 
<pre>
 
.function main (params=0, vars=2, return=0)
 
  PushD 0
 
  PushD 4
 
  LocalVar
 
  RefSet
 
  PushD 1
 
  PushD 5
 
  LocalVar
 
  RefSet
 
  PushD 3
 
  PushD 6
 
  LocalVar
 
  RefSet
 
  PushD 0
 
  PushD 8</pre></div>
 
 
What's gone wrong?
 

Latest revision as of 02:37, 11 April 2009

Maybe it is a silly question, but if there is a push onto the stack, how the numbers are pop'ed back? Since SCO seems to be similar to ASM (I have not yet took a look to scripts, only to this article) I think it is worth to mention this in the article (if there is an awnser, what I hope ^^). --Aschratt 20:17, 5 February 2009 (UTC)

The list of opcodes is incomplete, there are ones that pop numbers back.Seemann 00:05, 6 February 2009 (UTC)
Well, since they only seem to be used as function parameters, there is no real point in popping them from the stack (since called functions do that internally), is there? Although, how are return values handled? Can there be multiple return values? --Steve-m 00:48, 6 February 2009 (UTC)
Steve I don't think there are multiple return values. CallNative opcode has a parameter that specifies the outputs generated by the native, but that seems to be only 0 and 1. Of course you can always create a structure then output a pointer like in C++. --Sacky

Difference Between 'Local' variables and 'Global' variables

Does anyone know it? The only difference I could possibly see between them is a public declaration in the script so other scripts could access it... I don't see how local variables are even used when function locals are supported.

Hmm, Sacky, what you mean by difference? The locals are usable only within one script (from any of its internal functions), whereas the globals are usable from any script. Seemann 10:13, 14 February 2009 (UTC)
So Local Variables can only be accessed by the host script (but are still global from a 1 script only perspective) and Global Variables can be accessed by other scripts? If so how does 1 script access anothers globals? I suppose this would also indicate an access right change so a 'public' declaration should be the proper way to distinguish a global variable from a local variable? Sacky
There is the global variables buffer (only one) where all global variables store their values. Local variables have a number of buffers (a seperate one for each script). So, the globals could be accessed by any script (using specific globals-only opcodes), and the locals could be accessed only by host script containing that buffer using specific locals-only opcodes. That's what I know, but I dunno the real purpose of the global variables container. Seemann 15:10, 14 February 2009 (UTC)

I think we should also clarify the names of opcodes 54 -> 61 and opcode 62. They don't really deal with local variables, but rather with stack variables!. This distinction is quite important as they are really accessing different things. The names LocalVarPtr/LocalVarPtrEx is confusing and should be avoided. Having -Ptr added to the opcode name further adds to the confusion as opcodes 63/64 also push a ptr onto the stack. Since the rest of the opcodes seem to come from the Scruff/SparkIV list, I'm curious to why you renamed these two? Aru 17:02, 24 February 2009 (UTC)

Here's the list of opcodes listener made for his unreleased tool: