Skip to content

Commit fe73257

Browse files
idlebergCopilotCopilotkichik
authored
feat: update language features (#3)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Amir Szekely <kichik@gmail.com>
1 parent c0fc22c commit fe73257

25 files changed

+1578
-4
lines changed

examples/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# build artifacts
2+
*.exe
3+
*.nsi

examples/Test.nsl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
12
OutFile("Test.exe");
23
ShowInstDetails("show");
34
XPStyle("on");
45
RequestExecutionLevel("admin");
56

7+
// Manifest attributes
8+
// ManifestGdiScaling(false);
9+
ManifestDPIAware(true);
10+
ManifestLongPathAware(true);
11+
ManifestSupportedOS("Win7", "Win8", "Win10");
12+
ManifestAppendCustomString("/assembly/compatibility/application", "<supportedOS Id=\"{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}\"/>");
13+
614
section Test()
715
{
8-
}
16+
CallInstDLL("user32.dll", "MessageBoxA");
17+
$R0 = ReadMemory(0x400000, 4);
18+
$1 = ReadMemory($R0, 8);
19+
}

examples/Unicode.nsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OutFile("UnicodeTest.exe");
2+
ShowInstDetails("show");
3+
Unicode(true);
4+
5+
section Test()
6+
{
7+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* CallInstDLLInstruction.java
3+
*/
4+
5+
package nsl.instruction;
6+
7+
import java.io.IOException;
8+
import java.util.ArrayList;
9+
import java.util.EnumSet;
10+
import nsl.*;
11+
import nsl.expression.*;
12+
13+
/**
14+
* @author Jan
15+
*/
16+
public class CallInstDLLInstruction extends AssembleExpression
17+
{
18+
public static final String name = "CallInstDLL";
19+
private final Expression dllPath;
20+
private final Expression function;
21+
22+
/**
23+
* Class constructor.
24+
* @param returns the number of values to return
25+
*/
26+
public CallInstDLLInstruction(int returns)
27+
{
28+
if (!SectionInfo.in() && !FunctionInfo.in())
29+
throw new NslContextException(EnumSet.of(NslContext.Section, NslContext.Function), name);
30+
if (returns > 0)
31+
throw new NslReturnValueException(name);
32+
33+
ArrayList<Expression> paramsList = Expression.matchList();
34+
if (paramsList.size() != 2)
35+
throw new NslArgumentException(name, 2);
36+
37+
this.dllPath = paramsList.get(0);
38+
this.function = paramsList.get(1);
39+
}
40+
41+
/**
42+
* Assembles the source code.
43+
*/
44+
@Override
45+
public void assemble() throws IOException
46+
{
47+
Expression varOrDllPath = AssembleExpression.getRegisterOrExpression(this.dllPath);
48+
Expression varOrFunction = AssembleExpression.getRegisterOrExpression(this.function);
49+
ScriptParser.writeLine(name + " " + varOrDllPath + " " + varOrFunction);
50+
varOrDllPath.setInUse(false);
51+
varOrFunction.setInUse(false);
52+
}
53+
54+
/**
55+
* Assembles the source code.
56+
* @param var the variable to assign the value to
57+
*/
58+
@Override
59+
public void assemble(Register var) throws IOException
60+
{
61+
throw new UnsupportedOperationException("Not supported.");
62+
}
63+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* ExecShellWaitInstruction.java
3+
*/
4+
5+
package nsl.instruction;
6+
7+
import java.io.IOException;
8+
import java.util.ArrayList;
9+
import java.util.EnumSet;
10+
import nsl.*;
11+
import nsl.expression.*;
12+
13+
/**
14+
* @author Jan
15+
*/
16+
public class ExecShellWaitInstruction extends AssembleExpression
17+
{
18+
public static final String name = "ExecShellWait";
19+
private final Expression action;
20+
private final Expression command;
21+
private final Expression parameters;
22+
private final Expression show;
23+
24+
/**
25+
* Class constructor.
26+
* @param returns the number of values to return
27+
*/
28+
public ExecShellWaitInstruction(int returns)
29+
{
30+
if (!SectionInfo.in() && !FunctionInfo.in())
31+
throw new NslContextException(EnumSet.of(NslContext.Section, NslContext.Function), name);
32+
if (returns > 1)
33+
throw new NslReturnValueException(name, 0, 1);
34+
35+
ArrayList<Expression> paramsList = Expression.matchList();
36+
int paramsCount = paramsList.size();
37+
if (paramsCount < 2 || paramsCount > 4)
38+
throw new NslArgumentException(name, 2, 4);
39+
40+
this.action = paramsList.get(0);
41+
42+
this.command = paramsList.get(1);
43+
44+
if (paramsCount > 2)
45+
{
46+
this.parameters = paramsList.get(2);
47+
48+
if (paramsCount > 3)
49+
this.show = paramsList.get(3);
50+
else
51+
this.show = null;
52+
}
53+
else
54+
{
55+
this.parameters = null;
56+
this.show = null;
57+
}
58+
}
59+
60+
/**
61+
* Assembles the source code.
62+
*/
63+
@Override
64+
public void assemble() throws IOException
65+
{
66+
Expression varOrAction = AssembleExpression.getRegisterOrExpression(this.action);
67+
Expression varOrCommand = AssembleExpression.getRegisterOrExpression(this.command);
68+
if (this.parameters != null)
69+
{
70+
AssembleExpression.assembleIfRequired(this.parameters);
71+
if (this.show != null)
72+
{
73+
AssembleExpression.assembleIfRequired(this.show);
74+
ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters + " " + this.show);
75+
}
76+
else
77+
{
78+
ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters);
79+
}
80+
}
81+
else
82+
{
83+
ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand);
84+
}
85+
varOrAction.setInUse(false);
86+
varOrCommand.setInUse(false);
87+
}
88+
89+
/**
90+
* Assembles the source code.
91+
* @param var the variable to assign the value to
92+
*/
93+
@Override
94+
public void assemble(Register var) throws IOException
95+
{
96+
Expression varOrAction = AssembleExpression.getRegisterOrExpression(this.action);
97+
Expression varOrCommand = AssembleExpression.getRegisterOrExpression(this.command);
98+
if (this.parameters != null)
99+
{
100+
AssembleExpression.assembleIfRequired(this.parameters);
101+
if (this.show != null)
102+
{
103+
AssembleExpression.assembleIfRequired(this.show);
104+
ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters + " " + this.show + " " + var);
105+
}
106+
else
107+
{
108+
ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters + " " + var);
109+
}
110+
}
111+
else
112+
{
113+
ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + var);
114+
}
115+
varOrAction.setInUse(false);
116+
varOrCommand.setInUse(false);
117+
}
118+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* FileReadUTF16LEInstruction.java
3+
*/
4+
5+
package nsl.instruction;
6+
7+
import java.io.IOException;
8+
import java.util.ArrayList;
9+
import java.util.EnumSet;
10+
import nsl.*;
11+
import nsl.expression.*;
12+
13+
/**
14+
* @author Jan
15+
*/
16+
public class FileReadUTF16LEInstruction extends AssembleExpression
17+
{
18+
public static final String name = "FileReadUTF16LE";
19+
private final Expression handle;
20+
private final Expression maxLen;
21+
22+
/**
23+
* Class constructor.
24+
* @param returns the number of values to return
25+
*/
26+
public FileReadUTF16LEInstruction(int returns)
27+
{
28+
if (!SectionInfo.in() && !FunctionInfo.in())
29+
throw new NslContextException(EnumSet.of(NslContext.Section, NslContext.Function), name);
30+
if (returns != 1)
31+
throw new NslReturnValueException(name, 1);
32+
33+
ArrayList<Expression> paramsList = Expression.matchList();
34+
int paramsCount = paramsList.size();
35+
if (paramsCount < 1 || paramsCount > 2)
36+
throw new NslArgumentException(name, 1, 2);
37+
38+
this.handle = paramsList.get(0);
39+
if (!this.handle.getType().equals(ExpressionType.Register))
40+
throw new NslArgumentException(name, 1, ExpressionType.Register);
41+
42+
if (paramsCount > 1)
43+
this.maxLen = paramsList.get(1);
44+
else
45+
this.maxLen = null;
46+
}
47+
48+
/**
49+
* Assembles the source code.
50+
*/
51+
@Override
52+
public void assemble() throws IOException
53+
{
54+
throw new UnsupportedOperationException("Not supported.");
55+
}
56+
57+
/**
58+
* Assembles the source code.
59+
* @param var the variable to assign the value to
60+
*/
61+
@Override
62+
public void assemble(Register var) throws IOException
63+
{
64+
AssembleExpression.assembleIfRequired(this.handle);
65+
if (this.maxLen == null)
66+
{
67+
ScriptParser.writeLine(name + " " + this.handle + " " + var);
68+
}
69+
else
70+
{
71+
AssembleExpression.assembleIfRequired(this.maxLen);
72+
ScriptParser.writeLine(name + " " + this.handle + " " + var + " " + this.maxLen);
73+
}
74+
}
75+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* FileReadWordInstruction.java
3+
*/
4+
5+
package nsl.instruction;
6+
7+
import java.io.IOException;
8+
import java.util.ArrayList;
9+
import java.util.EnumSet;
10+
import nsl.*;
11+
import nsl.expression.*;
12+
13+
/**
14+
* @author Jan
15+
*/
16+
public class FileReadWordInstruction extends AssembleExpression
17+
{
18+
public static final String name = "FileReadWord";
19+
private final Expression handle;
20+
21+
/**
22+
* Class constructor.
23+
* @param returns the number of values to return
24+
*/
25+
public FileReadWordInstruction(int returns)
26+
{
27+
if (!SectionInfo.in() && !FunctionInfo.in())
28+
throw new NslContextException(EnumSet.of(NslContext.Section, NslContext.Function), name);
29+
if (returns != 1)
30+
throw new NslReturnValueException(name, 1);
31+
32+
ArrayList<Expression> paramsList = Expression.matchList();
33+
int paramsCount = paramsList.size();
34+
if (paramsCount != 1)
35+
throw new NslArgumentException(name, 1);
36+
37+
this.handle = paramsList.get(0);
38+
if (!this.handle.getType().equals(ExpressionType.Register))
39+
throw new NslArgumentException(name, 1, ExpressionType.Register);
40+
}
41+
42+
/**
43+
* Assembles the source code.
44+
*/
45+
@Override
46+
public void assemble() throws IOException
47+
{
48+
throw new UnsupportedOperationException("Not supported.");
49+
}
50+
51+
/**
52+
* Assembles the source code.
53+
* @param var the variable to assign the value to
54+
*/
55+
@Override
56+
public void assemble(Register var) throws IOException
57+
{
58+
AssembleExpression.assembleIfRequired(this.handle);
59+
ScriptParser.writeLine(name + " " + this.handle + " " + var);
60+
}
61+
}

0 commit comments

Comments
 (0)