We have a number of Lanier MFPs that use the scan-to-folder option to allow people to get their documents, and we are starting to implement more security measures on the AD passwords they use by forcing a password reset.
Unfortunately, the Laniers use a proprietary encryption for the passwords. I've managed to get a functional Java command that will encrypt passwords into this format. The problem I've been encountering is that I then have to get this encoded password into PowerShell to pass it to the scanner.
I can run the Java command through a command line, but can't pass the encrypted password back into PowerShell as a string that the printer will accept (it needs to be in Base64). If I do pass the encoded password back into PowerShell, then run it through PowerShell's Base64 creation process, it is, obviously, changed too much for the scanner to use it.
What I need to determine is whether there's a way for me to take the following command line command, and get it to run in PowerShell, then provide me its output so I can pass this to the printer.
java -cp ./commons-codec-1.10.jar;. cdm.GwpwesCharacterEncoding %pass% "gwpwes002"
The Java command outputs a Base64 string based on the following line:
return new String(Base64.encodeBase64((byte[])encrypt));
As an example, if I pass the text 'Test' into that, I get the string "HVhcmtla25meHVncHQ=="
This is useless to me, though, as I can't then get this back into PowerShell to pass through to the printer, and if I encode it as Base64 with PowerShell, it comes out as "MgBoAHMAWgBtADkAegBjADIAQgBxAGUAMABKAHgAWgBYAGgAbgBiAG0AMAB3AD0A".
Can anyone help?
Revised code after some assistance:
$pass1 = "test"
$path = "c:\Test\printercreds"
$encode = "gwpwes002"
cd $path
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pInfo.FileName = 'java'
$pInfo.Arguments = "-jar .\commons-codec-1.10.jar cdm.GwpwesCharacterEncoding $pass1 $encode"
$pInfo.UseShellExecute = $false
$pInfo.RedirectStandardOutput = $true
$pInfo.RedirectStandardError = $true
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $pInfo
[void]$process.Start()
$passsec = $process.StandardOutput.ReadtoEnd()
$process.WaitforExit()
write-host $passsec
Please try this. Its the encoding for GWPWES002. I found a old java version here.
https://www.dropbox.com/s/3324g84x0l4bnon/GwpwesCharacterEncoding.java?dl=0
There is a weakness in this "encoding". The front part of the encoding is just random padding. the pack part is where the actual string is stored. Running the script on the same string just a few times points out this error.
encodeGwpwes002 -code "a"
generated this hashes
np6eWFieWJ6eWA==
np6eWJ5YWFieWA==
WFienlhYnlieWA==
nlhYnp5Ynp6eWA==
nlieWFieWJ6eWA==
everything up until eWA== is just random padding mean "eWA==" == "a"
same for "aaaaaaaa"
np5YWJ5YnlieWFhYWFhYWFg=
np5Ynp6eWJ6eWFhYWFhYWFg=
nlienp6eWJ6eWFhYWFhYWFg=
WJ5YWJ6enlieWFhYWFhYWFg=
Meaning that
"eWFhYWFhYWFg=" Is "aaaaaaaa".
the password you provided as "test", A example of manipulation would be :
HVhcmtla25meHVncHQ== IS "test" :: 29 88 92 154 217 90 219 153 158 29 89 220 29
HVhcmtla25meFVncHQ== IS "Test" :: 29 88 92 154 217 90 219 153 158 21 89 220 29
Here is the powershell I have translated below
#private static String encodeGwpwes002(String code, int codeSize) {
function encodeGwpwes002([string]$code, [int]$codeSize = 0){
#byte[] protectCode;
[byte]$protectCode | Out-Null
#try {
try{
#protectCode = code.getBytes("UTF-8");
$protectCode = [System.Text.Encoding]::UTF8.GetBytes($code)
#}catch (Throwable e) {
}catch{
#return null;
return $null
#}
}
#int encodeSize = codeSize;
[int]$encodeSize = $codeSize
#if (protectCode.length >= codeSize) {
if(($protectCode.length) -ge $codeSize){
#encodeSize = protectCode.length + 9;
$encodeSize = ($protectCode.length) + 9
#}
}
#byte[] simple = new byte[encodeSize];
[byte[]]$simple = New-Object byte[] $encodeSize
#int diffuseCnt = 0;
[int]$diffuseCnt = 0
#int simpleCnt = 0;
[int]$simpleCnt = 0
#if (protectCode.length < encodeSize - 1) {
if(($protectCode.length) -lt ($encodeSize - 1)){
#for (diffuseCnt = 0; diffuseCnt < encodeSize - 1 - protectCode.length; ++diffuseCnt) {
for($diffuseCnt = 0; $diffuseCnt -lt ($encodeSize - 1 - ($protectCode.length)); $diffuseCnt++){
#simple[diffuseCnt] = (byte)(Math.random() * 25.0 + 97.0);
$simple[$diffuseCnt] = [byte] (Get-Random -Maximum 0.9 -Minimum 0.1) * 25.0 + 97.0
#}
}
#}
}
#simple[diffuseCnt++] = 122;
$simple[$diffuseCnt++] = 122
#for (simpleCnt = diffuseCnt; simpleCnt < protectCode.length + diffuseCnt; ++simpleCnt) {
for($simpleCnt = $diffuseCnt; $simpleCnt -lt ($protectCode.length) + $diffuseCnt; $simpleCnt++){
#simple[simpleCnt] = protectCode[simpleCnt - diffuseCnt];
$simple[$simpleCnt] = $protectCode[$simpleCnt - $diffuseCnt];
#}
}
#byte[] encrypt = new byte[simpleCnt];
[byte[]] $encrypt = New-Object byte[] $simpleCnt
#for (int i = 0; i < simpleCnt; ++i) {
for([int]$i=0; $i -lt $simpleCnt; $i++) {
#byte work = 0;
[byte]$work = 0
#work = (byte)((simple[i] & 192) >>> 6 | (simple[i] & 63) << 2);
$work = [byte](($simple[$i] -band 192) -shr 6 -bor ($simple[$i] -band 63) -shl 2)
#encrypt[i] = (byte)((work & 240) >>> 4 | (work & 15) << 4);
$encrypt[$i] = [byte](($work -band 240) -shr 4 -bor ($work -band 15) -shl 4)
#}
}
#return new String(Base64.encodeBase64((byte[])encrypt));
return [string]([System.Convert]::ToBase64String([byte[]]$encrypt))
#}
}
encodeGwpwes002TEST -code "Test"
Related
error --> error picture
When ı try to process my model ı have an error " java.lang.IncompatibleClassChangeError: Found interface org.tensorflow.lite.Tensor, but class was expected"
I have a mobilenet tflite model which is I trained, and I created a function to convert bitmap to bytebuffe and ı try to process my model but ı had this error and ı can't solve it, can you help me to solve this ?
the error is on this line "val outputs = model.process(inputFeature0)"
a part of outputgenerator func code --> you can click and see the line which causes this error
val byteBuffer = convertBitmapToByteBuffer(bitmap)
byteBuffer!!.rewind()
bitmap.copyPixelsToBuffer(byteBuffer)
val inputFeature0 =
TensorBuffer.createFixedSize(intArrayOf(1, 224, 224, 3), DataType.FLOAT32)
inputFeature0.loadBuffer(byteBuffer)
val outputs = model.process(inputFeature0)
val outputFeature0 = outputs.outputFeature0AsTensorBuffer
convertBitmapToByteBuffer function
val byteBuffer =
ByteBuffer.allocateDirect( 4 * 1 * 224 * 224 * 3)
byteBuffer.order(ByteOrder.nativeOrder())
val intValues = IntArray(224 * 224 )
bitmap.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
var pixel = 0
for (i in 0 until 224) {
for (j in 0 until 224) {
val `val` = intValues[pixel++]
byteBuffer.putFloat(((`val` shr 16 and 0xFF) - 1) / 255.0f)
byteBuffer.putFloat(((`val` shr 8 and 0xFF) - 1) / 255.0f)
byteBuffer.putFloat(((`val` and 0xFF) - 1) / 255.0f)
}
}
return byteBuffer
}
In my case, it was related to having an old version of support and metadata apis.
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
updating from 0.1.0 to 0.4.3 solved the problem.
In general, This could happen when your runtime classpath is different than your compile time classpath.
I have an issue where I read a bytestream from a big file ~ (100MB) and after some integers I get the value 0 (but only with sbt run ). When I hit the play button on IntelliJ I get the value I expected > 0.
My guess was that the environment is somehow different. But I could not spot the difference.
// DemoApp.scala
import java.nio.{ByteBuffer, ByteOrder}
object DemoApp extends App {
val inputStream = getClass.getResourceAsStream("/HandRanks.dat")
val handRanks = new Array[Byte](inputStream.available)
inputStream.read(handRanks)
inputStream.close()
def evalCard(value: Int) = {
val offset = value * 4
println("value: " + value)
println("offset: " + offset)
ByteBuffer.wrap(handRanks, offset, handRanks.length - offset).order(ByteOrder.LITTLE_ENDIAN).getInt
}
val cards: List[Int] = List(51, 45, 14, 2, 12, 28, 46)
def eval(cards: List[Int]): Unit = {
var p = 53
cards.foreach(card => {
println("p = " + evalCard(p))
p = evalCard(p + card)
})
println("result p: " + p);
}
eval(cards)
}
The HandRanks.dat can be found here: (I put it inside a directory called resources)
https://github.com/Robert-Nickel/scala-texas-holdem/blob/master/src/main/resources/HandRanks.dat
build.sbt is:
name := "LoadInts"
version := "0.1"
scalaVersion := "2.13.4"
On my windows machine I use sbt 1.4.6 with Oracle Java 11
You will see that the evalCard call will work 4 times but after the fifth time the return value is 0. It should be higher than 0, which it is when using IntelliJ's play button.
You are not reading a whole content. This
val handRanks = new Array[Byte](inputStream.available)
allocates only as much as InputStream buffer and then you read the amount in buffer with
inputStream.read(handRanks)
Depending of defaults you will process different amount but they will never be 100MB of data. For that you would have to read data into some structure in the loop (bad idea) or process it in chunks (with iterators, stream, etc).
import scala.util.Using
// Using will close the resource whether error happens or not
Using(getClass.getResourceAsStream("/HandRanks.dat")) { inputStream =>
def readChunk(): Option[Array[Byte]] = {
// can be done better, but that's not the point here
val buffer = new Array[Byte](inputStream.available)
val bytesRead = inputStream.read(buffer)
if (bytesRead >= 0) Some(buffer.take(bytesRead))
else None
}
#tailrec def process(): Unit = {
readChunk() match {
case Some(chunk) =>
// do something
process()
case None =>
// nothing to do - EOF reached
}
}
process()
}
So basically what I want: find and replace strings in a .jar file whatever length it is. It works for me fine except I need to have the same length of the replaced variable as the variable. I want that the length doesn't matter. Does anyone know how to help me?
PHP code:
<?php
$search1 = '%%__NONCE__%%';
$replace1 = 'ME_0000000001';
$search2 = '%%__USER__%%';
$replace2 = '000000000001';
$search3 = '%%__RESOURCE__%%';
$replace3 = '1';
function modifyzip($archive, $search, $replace) {
$zip = new ZipArchive();
$status = $zip->open($archive);
// echo $status;
if ($status == true) {
/* Get the count of files BEFORE the loop */
$filecount = $zip->numFiles;
// echo $filecount;
for ($i=0; $i < $filecount; $i++) {
$name = $zip->getNameIndex($i);
$content = $zip->getFromName($name);
$edited = str_replace($search, $replace, $content);
if ($edited != $content) {
// echo $edited;
// echo $edited . "\n\n";
}
$zip->deleteName($name);
$zip->addFromString($name, $edited);
}
}
$zip->close();
}
$templateFilename = 'zips/a.jar';
$inputFilename = 'zips/b.jar';
if (!copy($templateFilename, $inputFilename)) {
die("Could not copy '$templateFilename' to '$inputFilename'");
}
call_user_func('modifyzip', $inputFilename, $search1, $replace1);
call_user_func('modifyzip', $inputFilename, $search2, $replace2);
call_user_func('modifyzip', $inputFilename, $search3, $replace3);
//echo file_get_contents($templateFilename);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$inputFilename");
header("Content-Type: application/java-archive");
header("Content-Transfer-Encoding: binary");
// read the file from disk
readfile($inputFilename);
unlink($inputFilename);
Java Luyten error:
java.lang.IllegalArgumentException: Argument 'value' must be in the range [1, 18], but value was: 0.
at com.strobel.core.VerifyArgument.inRange(VerifyArgument.java:346)
at com.strobel.assembler.ir.ConstantPool$Tag.fromValue(ConstantPool.java:532)
at com.strobel.assembler.ir.ConstantPool.read(ConstantPool.java:362)
at com.strobel.assembler.metadata.JarTypeLoader.getInternalNameFromClassFile(JarTypeLoader.java:105)
at com.strobel.assembler.metadata.JarTypeLoader.tryLoadType(JarTypeLoader.java:78)
at us.deathmarine.luyten.LuytenTypeLoader.tryLoadType(LuytenTypeLoader.java:25)
at com.strobel.assembler.metadata.MetadataSystem.resolveType(MetadataSystem.java:120)
at com.strobel.assembler.metadata.MetadataSystem.lookupTypeCore(MetadataSystem.java:81)
at com.strobel.assembler.metadata.MetadataResolver.lookupType(MetadataResolver.java:46)
at us.deathmarine.luyten.Model.openEntryByTreePath(Model.java:338)
at us.deathmarine.luyten.Model$TreeListener$1.run(Model.java:266)
$startCount = 5;
$processors = Get-WmiObject -Class Win32_ComputerSystem | select -
ExpandProperty "NumberOfLogicalProcessors";
$perInstance = $processors / $startCount;
$affinityloop = 1;
$affinityvalue = 0;
for($i=1; $i -le $startCount; $i++) {
$affinityvalue = 0;
for($u=1; $u -le $perInstance ; $u++) {
$affinityvalue = $affinityvalue + $affinityloop;
$affinityloop = $affinityloop * 2;
}
$ps = new-object System.Diagnostics.Process;
$ps.StartInfo.Filename = "C:\jdk\bin\java.exe";
$ps.StartInfo.Arguments = " -server -Xms10240m -Xmx10240m -XX:+UseG1GC -cp `".;*`" Worker";
$ps.start();
Write-Host $affinityvalue ;
$ps.ProcessorAffinity = [Convert]::ToString($affinityvalue, 16);
}
I am trying to start a Windows Java application on two different NUMA nodes. Has anyone able to accomplish this with Diagnostics.Process format? This code does work fine, but all applications created are on the same NUMA node and hence only using 50% power.
I tried codes such as $mod = ($i % 2); to help prepare for some way to alternate the NUMA node but unsure how to specify it within the script.
EDIT
Tried to load balance with ProcessorAffinity and I get crashes due to Double unable to convert to IntPtr
EDIT 2
So it looks like Windows Groups the processors past 64 into Groups. Can't seem to find a way to alter that like ProcessAffinity. I guess its just not that common. You can easily do it in Task manager, just need to find a way to do it in Powershell or similar.
I'm using Message Broker 8 and MQ 7. When I try to use a Mapping Node in my message flow I get a java.lang.RuntimeException.
Here is what the event viewer shows:
( BROKER8.default ) The map script generation for QName ''{practica}:CambioFecha'' has failed, with the following details: ''java.lang.RuntimeException: ''.
The generation of the map has failed.
Review and resolve the problems indicated in the message from the map generation.
The full exception stack is:
ExceptionList: ( ['MQROOT' : 0xe052600]
(0x01000000:Name):RecoverableException = (
(0x03000000:NameValue):File = 'F:\build\S000_P\src\DataFlowEngine\PluginInterface\ImbJniNode.cpp' (CHARACTER)
(0x03000000:NameValue):Line = 1170 (INTEGER)
(0x03000000:NameValue):Function = 'ImbJniNode::evaluate' (CHARACTER)
(0x03000000:NameValue):Type = 'ComIbmMSLMappingNode' (CHARACTER)
(0x03000000:NameValue):Name = 'practica/DATAGRAMA#FCMComposite_1_7' (CHARACTER)
(0x03000000:NameValue):Label = 'practica.DATAGRAMA.Cambio Formato Fecha' (CHARACTER)
(0x03000000:NameValue):Catalog = 'BIPmsgs' (CHARACTER)
(0x03000000:NameValue):Severity = 3 (INTEGER)
(0x03000000:NameValue):Number = 2230 (INTEGER)
(0x03000000:NameValue):Text = 'Caught exception and rethrowing' (CHARACTER)
(0x01000000:Name ):RecoverableException = (
(0x03000000:NameValue):File = 'MbErrorHandler.java' (CHARACTER)
(0x03000000:NameValue):Line = 146 (INTEGER)
(0x03000000:NameValue):Function = 'evaluate' (CHARACTER)
(0x03000000:NameValue):Type = '' (CHARACTER)
(0x03000000:NameValue):Name = '' (CHARACTER)
(0x03000000:NameValue):Label = '' (CHARACTER)
(0x03000000:NameValue):Catalog = 'BIPmsgs' (CHARACTER)
(0x03000000:NameValue):Severity = 3 (INTEGER)
(0x03000000:NameValue):Number = 3946 (INTEGER)
(0x03000000:NameValue):Text = 'Caught BrokerXCIStaticException' (CHARACTER)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = '{practica}:CambioFecha' (CHARACTER)
)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'java.lang.RuntimeException: ' (CHARACTER)
)
(0x01000000:Name ):RecoverableException = (
(0x03000000:NameValue):File = 'MbErrorHandler.java' (CHARACTER)
(0x03000000:NameValue):Line = 310 (INTEGER)
(0x03000000:NameValue):Function = 'throwableToMbException' (CHARACTER)
(0x03000000:NameValue):Type = '' (CHARACTER)
(0x03000000:NameValue):Name = '' (CHARACTER)
(0x03000000:NameValue):Label = '' (CHARACTER)
(0x03000000:NameValue):Catalog = 'BIPmsgs' (CHARACTER)
(0x03000000:NameValue):Severity = 3 (INTEGER)
(0x03000000:NameValue):Number = 3949 (INTEGER)
(0x03000000:NameValue):Text = 'Caught BrokerXCIStaticException' (CHARACTER)
(0x01000000:Name ):Insert = (
(0x03000000:NameValue):Type = 5 (INTEGER)
(0x03000000:NameValue):Text = 'java.lang.RuntimeException:
' (CHARACTER)
)
)
)
)
)
The entire message flow was working fine. So, I think it is not an error of the mapping node. Another detail, in others flows the mapping node doesn't work at all and gives the same error. I don't know what could be the problem. Maybe a JRE error?
Any idea?
Thanks!
Josué
This is most probably due to the large Java heap size on 64 bit machines, as all the references are 4 bytes larger. To make it work, you could simply run it on a 32 bit broker or try any of the following -
Use Xcompressedrefs (the explanation about it is here -
http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.doc.diagnostics.60%2Fdiag%2Funderstanding%2Fmm_compressed_references.html)
a) Execute the following command in the broker prompt
mqsichangeproperties --broker name-- -e --EG name-- -o
ComIbmJVMManager -n jvmSystemProperty -v \"-Xcompressedrefs\"
b) Verify that the JVM option is successfully applied
mqsireportproperties --broker name-- -e --EG name-- -o
ComIbmJVMManager -n jvmSystemProperty
The system should display -
-Xcompressedrefs
c) Restart the Execution Group
Increase the JVM memory, the default is 256MB
a) Execute the following command
mqsichangeproperties --broker name-- -e --EG name-- -o
ComIbmJVMManager -n jvmMaxHeapSize -v 536870912
b) Verify that the JVM option is successfully applied
mqsireportproperties --broker name-- -e --EG name-- -o
ComIbmJVMManager -n jvmMaxHeapSize
c) Restart the Execution Group
Hope this helps