Windbg script fails at alias expansion - windbg

The below windbg script always fails. I couldn't figure out what I am doing wrong.
$$
$$ print all imported function names. ${$arg1} base address of a loaded image
$$
.block {
.expr /s c++
r $t1 = ${$arg1} + ((ntdll32!_IMAGE_DOS_HEADER*)${$arg1})->e_lfanew
r $t1 = ${$arg1} + ((ntdll32!_IMAGE_NT_HEADERS*)#$t1)->OptionalHeader.DataDirectory[1].VirtualAddress
r $t0 = 0
aS ${curImpDesc} ((Mydll_00!_IMAGE_IMPORT_DESCRIPTOR*)#$t1)[#$t0]
.while (${curImpDesc}.Name != 0) {
.printf "\n Imported Image: %ma\n", (${$arg1} + ${curImpDesc}.Name)
r $t2 = 0
r $t3 = ${$arg1} + ${curImpDesc}.OriginalFirstThunk
aS ${curThunkData} ((Mydll_00!_IMAGE_THUNK_DATA32*)#$t3)[#$t2]
.while (${curThunkData}.u1.AddressOfData != 0) {
r $t4 = ${$arg1} + ${curThunkData}.u1.AddressOfData
da &(((Mydll_00!_IMAGE_IMPORT_BY_NAME*)#$t4)->Name)
r $t2 = #$t2 + 1
}
r $t0 = #$t0 + 1
}
ad ${curImpDesc}
ad ${curThunkData}
}
I wrote this script to print the imported image name , followed by all the imported function names. If I run this script line-by-line all going fine and I get the expected output. But if I run it as script file, then I am getting error
0:065:x86> $$>a< "D:\import.wds" 0x74e70000
Unexpected character in '${curImpDesc}.Name != 0) {;....

Related

QUICBASIC 4.5 Program now in QB64

I took a QB45 application and produced a QB64 application from it over 100,000 lines of code. All the pricing was hard coded in the program so I started reading from CSV files but now I need the date from the CSV file without putting a directory to a text file and reading for the date. I found this code below
The problem when I run it is that the assembler is for 16 bit registers and I am using 32 or 64 with windows 7 and i5 core. Can anyone help me to figure out how the date will be returned in a longer int value from the register?
'===========================================================================
' Subject: GET/SET FILE DATE/TIME Date: Unknown Date (00:00)
' Author: Matt Hart Code: QB, PDS
' Keys: GET,SET,FILE,DATE,TIME Packet: DOS.ABC
'===========================================================================
' FILEDATE.BAS by Matt Hart
'
' Gets or sets a file date/time
'
' GetFileDateTime returns the Date in MM-DD-YYYY format
' and the Time in HH:MM:SS
' SetFileDateTime expects the Date and Time in the same formats
'$INCLUDE: 'QB.BI' ' Use your path to QB or QBX.BI
DEFINT A-Z
DECLARE SUB GetFileDateTime (F$, Dat$, Tim$, Ecode%)
DECLARE SUB SetFileDateTime (F$, Dat$, Tim$, Ecode%)
' ------------------------- Sample code
F$ = LTRIM$(RTRIM$(COMMAND$))
CALL GetFileDateTime(F$, Dat$, Tim$, Ecode)
IF NOT Ecode THEN
PRINT F$; " date is "; Dat$
PRINT F$; " time is "; Tim$
ELSE
PRINT "1 Error = "; Ecode
END
END IF
NewTim$ = "01:01:02"
NewDat$ = "02-02-1980"
CALL SetFileDateTime(F$, NewDat$, NewTim$, Ecode)
IF Ecode THEN
PRINT "2 Error = "; Ecode
END
END IF
CALL GetFileDateTime(F$, Dat$, Tim$, Ecode)
IF Ecode THEN
PRINT "3 Error = "; Ecode
END
END IF
PRINT F$; " new date is "; Dat$
PRINT F$; " new time is "; Tim$
CALL SetFileDateTime(F$, Dat$, Tim$, Ecode)
IF Ecode THEN
PRINT "4 Error = "; Ecode
END
END IF
END
' ------------------------------------
SUB GetFileDateTime (F$, Dat$, Tim$, Ecode)
Ecode = 0
DIM InRegs AS RegTypeX
DIM OutRegs AS RegTypeX
InRegs.ax = &H3D00 ' Open file function
DIM FileName AS STRING * 128 ' Use fixed length
FileName = F$ + CHR$(0) ' Must be ASCIIZ string
InRegs.ds = VARSEG(FileName) ' Fixed length makes these
InRegs.dx = VARPTR(FileName) ' come out right
CALL INTERRUPTX(&H21, InRegs, OutRegs) ' Open the file
IF NOT OutRegs.flags THEN ' No error
Handle = OutRegs.ax ' Save DOS file handle
InRegs.ax = &H5700 ' Get date/time function
InRegs.bx = Handle
CALL INTERRUPTX(&H21, InRegs, OutRegs)
HMS& = OutRegs.cx ' Use long integer for
IF HMS& < 0& THEN HMS& = 65536 + HMS& ' positive numbers
Hours = HMS& \ 2048& ' Hours is first 5 bits
Minutes = (HMS& AND 2047&) \ 31& ' Minutes is next 6 bits
Seconds = HMS& AND 31& ' Seconds is last 5 bits
H$ = LTRIM$(STR$(Hours))
M$ = LTRIM$(STR$(Minutes)): IF LEN(M$) = 1 THEN M$ = "0" + M$
S$ = LTRIM$(STR$(Seconds)): IF LEN(S$) = 1 THEN S$ = "0" + S$
Tim$ = H$ + ":" + M$ + ":" + S$
YMD& = OutRegs.dx ' Long int here too
IF YMD& < 0 THEN YMD& = 65536 + YMD& ' Convert to + if needed
Year = 1980& + YMD& \ 512& ' Year is first 7 bits
Month = (YMD& AND 511&) \ 31& ' Month is next 4 bits
Day = YMD& AND 31& ' Day is last 5 bits
Y$ = LTRIM$(STR$(Year))
M$ = LTRIM$(STR$(Month))
D$ = LTRIM$(STR$(Day)): IF LEN(D$) = 1 THEN D$ = "0" + D$
Dat$ = M$ + "-" + D$ + "-" + Y$
InRegs.ax = &H3E00 ' Close file function
InRegs.bx = Handle
CALL INTERRUPTX(&H21, InRegs, OutRegs) ' Close it
ELSE
Ecode = OutRegs.flags ' Otherwise return error flags
END IF
END SUB
SUB SetFileDateTime (F$, Dat$, Tim$, Ecode)
Ecode = 0
DIM InRegs AS RegTypeX
DIM OutRegs AS RegTypeX
InRegs.ax = &H3D00
DIM FileName AS STRING * 128
FileName = F$ + CHR$(0)
InRegs.ds = VARSEG(FileName)
InRegs.dx = VARPTR(FileName)
CALL INTERRUPTX(&H21, InRegs, OutRegs)
IF NOT OutRegs.flags THEN
Handle = OutRegs.ax
InRegs.ax = &H5701
InRegs.bx = Handle
Hours& = VAL(LEFT$(Tim$, 2)) * 2048&
Minutes& = VAL(MID$(Tim$, 4, 2)) * 32&
Seconds& = VAL(RIGHT$(Tim$, 2)) \ 2
HMS& = Hours& + Minutes& + Seconds&
IF HMS& > 65536 THEN
InRegs.cx = 65536 - HMS&
ELSE
InRegs.cx = HMS&
END IF
Year& = (VAL(RIGHT$(Dat$, 4)) - 1980&) * 512&
Month& = VAL(LEFT$(Dat$, 2)) * 32&
Day& = VAL(MID$(Dat$, 4, 2))
YMD& = Year& + Month& + Day&
IF YMD& > 65536 THEN
InRegs.dx = 65536 - YMD&
ELSE
InRegs.dx = YMD&
END IF
CALL INTERRUPTX(&H21, InRegs, OutRegs)
InRegs.ax = &H3E00
InRegs.bx = Handle
CALL INTERRUPTX(&H21, InRegs, OutRegs)
ELSE
Ecode = OutRegs.flags
END IF
END SUB

QBASIC Decimal to Binary conversion

I have converted a decimal number to binary using STR$() in QBASIC. But I need a way to convert decimal number to binary without using string functions. Thanks.
My Code :
CLS
INPUT N
WHILE N <> 0
E = N MOD 2
B$ = STR$(E)
N = FIX(N / 2)
C$ = B$ + C$
WEND
PRINT "Output "; C$
END
This code sample converts a numeric value to a binary string in Basic.
PRINT "Enter value";
INPUT Temp#
Out3$ = ""
IF Temp# >= False THEN
Digits = False
DO
IF 2 ^ (Digits + 1) > Temp# THEN
EXIT DO
END IF
Digits = Digits + 1
LOOP
FOR Power = Digits TO 0 STEP -1
IF Temp# - 2 ^ Power >= False THEN
Temp# = Temp# - 2 ^ Power
Out3$ = Out3$ + "1"
ELSE
Out3$ = Out3$ + "0"
END IF
NEXT
END IF
PRINT Out3$
END
When you want to display an integer value as binary, it seems logical to me to store it in a string variable, because it's only for display. So I'm not really sure what you are trying to do here.
Maybe you were looking for LTRIM$ so you would get outputs like 11010 instead of 1 1 0 1 0 ?
You could store it in an integer value like in the code below. But, although the integer value will look the same as the string variable, it will in fact be a completely different value.
CLS
INPUT "Type a decimal number:", N
S$ = ""
I = 0
P = 1
WHILE (N <> 0)
' get right most bit and shift right
E = N AND 1
N = INT(N / 2) ' bit shift right
' format for dsplay
S$ = LTRIM$(STR$(E)) + S$
I = I + (E * P)
P = P * 10
WEND
PRINT "Binary as string="; S$
PRINT "Binary as int="; I
END

Getting error from: dlen = uint32(0) ;

I don't know why but I am getting this error:
Error in mr_lsbpex (line 3)
dlen = uint32(0) ;
Output argument "a" (and maybe others) not assigned during call to "E:\path\mr_lsbpex.m>mr_lsbpex"
I have tested "dlen = uint32(0) ;" in matlab enviorment (outside of this function) and everything was OK. Here is my code:
function a = mr_lsbpex ( r, p )
% extract from an array
dlen = uint32(0) ;
s = size (r) ;
rnd = rand (s(1),s(2)) ;
rd = 32 ;
rl = s(2) ;
for i=1:s(2)
if rnd(1,i)<rd/rl
d = bitget (round(r(1,i)/p),1);
dlen = bitset (dlen,rd,d);
rd = rd -1 ;
end
rl = rl -1 ;
end
if (dlen > 10000000 )
clear a ;
return ;
end
a = uint8(zeros(dlen,1)) ;
rd = double(dlen * 8) ;
rl = double(s(1)*s(2)-s(2)) ;
for i=2:s(1)
for j=1:s(2)
if rnd(i,j)<rd/rl
d = bitget (round(r(i,j)/p) ,1) ;
a = z_set_bit (a,rd,d) ;
rd = rd - 1 ;
end
rl = rl - 1 ;
end
end
Remember: a needs to be returned ALLWAYS!
The error is not in that specific line, but in the "whole" function itself.
Your problem is that Matlab thinks that a its not going to be created. And actually in some case it may not be created.
The following line in the beginning of your function should do the trick
a=0; % well, or a=NaN; or whatever you want to return
Additionally, don't clear a in if (dlen > 10000000 ).

Simulation in verilog using $monitor

I've been trying to implement full adder in Verilog. I have implemented it and it is also showing results on Isim. Only problem is that when I try to see the simulation using $monitor command, it is showing me only 1 result, not all simulation results. Here is testbench code:
module Full_adder_s2_testbench;
// Inputs
reg a;
reg b;
reg cin;
// Outputs
wire sum;
wire cout;
// Instantiate the Unit Under Test (UUT)
Full_adder_s2 uut (
.a(a),
.b(b),
.cin(cin),
.sum(sum),
.cout(cout)
);
integer i;
initial begin
// Initialize Inputs
a = 0;
b = 0;
cin = 0;
// Wait 100 ns for global reset to finish
#100;
end
always # ( a, b, cin )
begin
// generate truth table
for ( i = 0; i < 8; i = i + 1 )
// every 10 ns set a, b, and cin to the binary rep. of i
#10 {a, b, cin} = i;
$monitor( "%d ns: a + b + cin = %b + %b + %b = cout sum = %b %b",
$time, a, b, cin, cout, sum );
// stop 10ns after last change of inputs
#10 $stop;
end
endmodule
And here is result in ISIM:
# run 1000 ns
Simulator is doing circuit initialization process.
Finished circuit initialization process.
400 ns: a + b + cin = 1 + 1 + 1 = cout sum = 1 1
Stopped at time : 410 ns : in File "E:/Namal/FYP/My work/XILINX/Full_adder_s2/Full_adder_s2_testbench.v" Line 66
$monitor is only meant to be setup once and will trigger every time a signal changes, try using $display since you already have the statement inside of your always #*.
While learning Verilog I would encourage you to use begin end liberally. The issue is that only 1 line was in the for loop, the $display/$monitor was outside and so only executed once at the start.
always #* begin
// generate truth table
for ( i = 0; i < 8; i = i + 1 ) begin //<-- Added begin
// every 10 ns set a, b, and cin to the binary rep. of i
#10 {a, b, cin} = i;
$display( "%d ns: a + b + cin = %b + %b + %b = cout sum = %b %b", $time, a, b, cin, cout, sum );
end //<--Added end
// stop 10ns after last input
#10 $stop;
end
Full example on EDA Playground.
NB: it is best not to use manual sensitivity lists any more replace always # ( a, b, cin ) with always #*. This will result in quicker refactoring and lowering the chance of RTL to gates simulation mismatch.

Perl Win32::API() call() function

Dear all,
I am trying to get the value of char pointer or string in the return of call() function for my dll.
my dll is having a function RandomDec(long , int*) and returns a string. so what will be my call using Win32::API(). I have tried this and didn't succeed. plz help
use Win32::API;
my #lpBuffer = " " x 20;
my $pp= \#lpBuffer;
my $xy=0;
my $ff= \$xy;
my $fun2 = new Win32::API('my.dll','RandomDec','NP','**P**')or die $^E;
$pp = $fun2->Call(4,$ff);
how to get using $pp ?
There are multiple errors in your code.
my #lpBuffer = " " x 20; my $pp= \#lpBuffer;
=> my $pp = " " x 20;
You are mixing arrays with strings, and you don't need a perl ref for a c ptr.
Similar for the int*.
N is for number not long. L would be unsigned, you need signed, so l.
use Win32::API;
my $pp = " " x 20; # alloc a string
my $xy = 0; # alloc an int
my $fun2 = new Win32::API('my.dll','RandomDec','lP','P') or die $^E;
$pp = $fun2->Call(4,$xy);
I haven't check if Win32::API can do lvalue assignment to char*. Normally not, so $pp will be a foreign pointer to some string after the call, and the prev. PV slot for $pp will be lost, and inaccessible from perl.
With FFI's and the WinAPI also you usually return int, not strings.
Strings only via sideeffects, as function arg.